admin.module

  1. 5.x modules/admin/admin.module
  2. 4.x modules/admin/admin.module

The administrative configurations for FlightPath.

Functions & methods

NameDescription
admin_advising_settings_formThis is a systems settings form, which lets the user edit advising variabled for FlightPath.
admin_apply_draft_changes_formThis form lets the user apply draft changes (if they can supply the passcode)
admin_apply_draft_changes_form_submitHandles the actual moving of draft courses into production.
admin_display_mainThis is the "main" page for the admin module. It's what the user first sees when the click to go to the Admin page.
admin_display_watchdogDisplays recent watchdog entries, from the watchdog table
admin_display_watchdog_entryDisplay the details of a particular watchdog entry, specified by its table id.
admin_duplicate_year_formThis form will allow the user to duplicate an entire year's worth of data to a new catalog year.
admin_duplicate_year_form_submitThis function should perform the actual copy of data!
admin_get_de_catalog_yearGet the "de_catalog_year" from the REQUEST. If it's not there or invalid, pull it from our system settings.
admin_get_semester_nameConvienence function to get semester's default regular name.
admin_menuImplementation of hook_menu
admin_menu_handle_replacement_patternThis is an implementation of hook_menu_handle_replacement_pattern. It will search for and replace replacement patterns which we are aware of it in $str.
admin_perm
admin_urgent_message_formMeant to be fed into "fp_system_settings_form()", this function returns an array which will automatically save values to our "variables" table.

File

modules/admin/admin.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * The administrative configurations for FlightPath.
  5. *
  6. *
  7. */
  8. /**
  9. * Implementation of hook_menu
  10. *
  11. */
  12. function admin_menu() {
  13. $items = array();
  14. $items["admin-tools/admin"] = array(
  15. "title" => "FlightPath Admin Console",
  16. "page_callback" => "admin_display_main",
  17. "access_arguments" => array("can_access_admin"),
  18. "tab_family" => "admin",
  19. "page_settings" => array(
  20. "page_has_search" => FALSE,
  21. "page_banner_is_link" => TRUE,
  22. "page_hide_report_error" => TRUE,
  23. "target" => "_blank",
  24. ),
  25. "type" => MENU_TYPE_TAB,
  26. );
  27. $items["admin/config/urgent-message"] = array(
  28. "title" => "Edit urgent message",
  29. "description" => "Set a message which will be displayed to all users on every page",
  30. "page_callback" => "fp_render_form",
  31. "page_arguments" => array("admin_urgent_message_form", "system_settings"),
  32. "access_arguments" => array("can_edit_urgent_message"),
  33. "page_settings" => array(
  34. "page_has_search" => FALSE,
  35. "menu_icon" => fp_get_module_path('admin') . "/icons/error.png",
  36. "page_banner_is_link" => TRUE,
  37. "page_hide_report_error" => TRUE,
  38. "menu_links" => array(
  39. 0 => array(
  40. "text" => "Back to main menu",
  41. "path" => "admin-tools/admin",
  42. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  43. ),
  44. ),
  45. ),
  46. "type" => MENU_TYPE_NORMAL_ITEM,
  47. "tab_parent" => "admin-tools/admin",
  48. );
  49. $items["admin/config/watchdog"] = array(
  50. "title" => "Watchdog (logs)",
  51. "description" => "View log messages from throughout the system",
  52. "page_callback" => "admin_display_watchdog",
  53. "access_arguments" => array("display_watchdog"),
  54. "page_settings" => array(
  55. "page_has_search" => FALSE,
  56. "menu_icon" => fp_get_module_path('system') . "/icons/application_view_list.png",
  57. "page_show_title" => TRUE,
  58. "page_banner_is_link" => TRUE,
  59. "page_hide_report_error" => TRUE,
  60. "menu_links" => array(
  61. 0 => array(
  62. "text" => "Back to main menu",
  63. "path" => "admin-tools/admin",
  64. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  65. ),
  66. ),
  67. ),
  68. "type" => MENU_TYPE_NORMAL_ITEM,
  69. "tab_parent" => "admin-tools/admin",
  70. );
  71. $items["admin/config/watchdog/%"] = array(
  72. "title" => "View Watchdog Entry",
  73. "page_callback" => "admin_display_watchdog_entry",
  74. "page_arguments" => array(3),
  75. "access_arguments" => array("display_watchdog"),
  76. "page_settings" => array(
  77. "page_has_search" => FALSE,
  78. "page_show_title" => TRUE,
  79. "page_banner_is_link" => TRUE,
  80. "page_hide_report_error" => TRUE,
  81. "menu_links" => array(
  82. 0 => array(
  83. "text" => "Back to main menu",
  84. "path" => "admin-tools/admin",
  85. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  86. ),
  87. 1 => array(
  88. "text" => "Back to watchdog",
  89. "path" => "admin/config/watchdog",
  90. "query" => "de_catalog_year=%DE_CATALOG_YEAR%&sev_filter=%SEV_FILTER%&page=%PAGE%&type_filter=%TYPE_FILTER%",
  91. ),
  92. ),
  93. ),
  94. "type" => MENU_TYPE_CALLBACK,
  95. "tab_parent" => "admin-tools/admin",
  96. );
  97. $items["admin/duplicate-year"] = array(
  98. "title" => "Duplicate entire catalog year",
  99. "page_callback" => "fp_render_form",
  100. "page_arguments" => array("admin_duplicate_year_form"),
  101. "access_arguments" => array("can_edit_data_entry"),
  102. "page_settings" => array(
  103. "page_has_search" => FALSE,
  104. "page_banner_is_link" => TRUE,
  105. "page_hide_report_error" => TRUE,
  106. "menu_links" => array(
  107. 0 => array(
  108. "text" => "Back to main menu",
  109. "path" => "admin-tools/admin",
  110. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  111. ),
  112. ),
  113. ),
  114. "type" => MENU_TYPE_NORMAL_ITEM,
  115. "tab_parent" => "admin-tools/admin",
  116. );
  117. $items["admin/edit-advising-settings"] = array(
  118. "title" => "Edit advising settings",
  119. "page_callback" => "fp_render_form",
  120. "page_arguments" => array("admin_advising_settings_form", "system_settings"),
  121. "access_arguments" => array("can_edit_advising_settings"),
  122. "page_settings" => array(
  123. "page_has_search" => FALSE,
  124. "page_banner_is_link" => TRUE,
  125. "page_hide_report_error" => TRUE,
  126. "menu_links" => array(
  127. 0 => array(
  128. "text" => "Back to main menu",
  129. "path" => "admin-tools/admin",
  130. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  131. ),
  132. ),
  133. ),
  134. "type" => MENU_TYPE_NORMAL_ITEM,
  135. "tab_parent" => "admin-tools/admin",
  136. );
  137. $items["admin/apply-draft-changes"] = array(
  138. "title" => "Apply draft changes",
  139. "page_callback" => "fp_render_form",
  140. "page_arguments" => array("admin_apply_draft_changes_form"),
  141. "access_arguments" => array("can_apply_draft_changes"),
  142. "page_settings" => array(
  143. "page_has_search" => FALSE,
  144. "page_banner_is_link" => TRUE,
  145. "page_hide_report_error" => TRUE,
  146. "menu_links" => array(
  147. 0 => array(
  148. "text" => "Back to main menu",
  149. "path" => "admin-tools/admin",
  150. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  151. ),
  152. ),
  153. ),
  154. "type" => MENU_TYPE_NORMAL_ITEM,
  155. "tab_parent" => "admin-tools/admin",
  156. );
  157. ///////////////////////////////////////////////////////
  158. ////////////////////// Degree Editing ///////////////////
  159. $items["admin/degrees"] = array(
  160. "title" => "Degrees",
  161. "page_callback" => "admin_display_degrees",
  162. "access_arguments" => array("can_access_data_entry"),
  163. "page_settings" => array(
  164. "page_has_search" => FALSE,
  165. "page_banner_is_link" => TRUE,
  166. "page_hide_report_error" => TRUE,
  167. "menu_links" => array(
  168. 0 => array(
  169. "text" => "Back to main menu",
  170. "path" => "admin-tools/admin",
  171. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  172. ),
  173. ),
  174. ),
  175. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  176. "type" => MENU_TYPE_TAB,
  177. "tab_family" => "admin_degrees",
  178. );
  179. /* OLD - marked for deletion
  180. $items["admin/degrees/edit-degree"] = array(
  181. "title" => "Edit Degree",
  182. "page_callback" => "admin_display_edit_degree",
  183. "access_arguments" => array("can_edit_data_entry"),
  184. "page_settings" => array(
  185. "page_has_search" => FALSE,
  186. "page_banner_is_link" => TRUE,
  187. "page_hide_report_error" => TRUE,
  188. "menu_links" => array(
  189. 0 => array(
  190. "text" => "Back to main menu",
  191. "path" => "admin-tools/admin",
  192. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  193. ),
  194. 1 => array(
  195. "text" => "Back to Degrees list",
  196. "path" => "admin/degrees",
  197. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  198. ),
  199. ),
  200. ),
  201. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  202. "type" => MENU_TYPE_NORMAL_ITEM,
  203. "tab_parent" => "admin/degrees",
  204. );
  205. */
  206. $items["admin/degrees/edit-degree/%/%"] = array(
  207. "title" => "Edit Degree",
  208. "page_callback" => "fp_render_form",
  209. "page_arguments" => array("admin_edit_degree_form", "normal", 3, 4),
  210. "access_arguments" => array("can_edit_data_entry"),
  211. "page_settings" => array(
  212. "page_has_search" => FALSE,
  213. "page_banner_is_link" => TRUE,
  214. "page_hide_report_error" => TRUE,
  215. "menu_links" => array(
  216. 0 => array(
  217. "text" => "Back to main menu",
  218. "path" => "admin-tools/admin",
  219. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  220. ),
  221. 1 => array(
  222. "text" => "Back to Degrees list",
  223. "path" => "admin/degrees",
  224. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  225. ),
  226. ),
  227. ),
  228. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  229. "type" => MENU_TYPE_NORMAL_ITEM,
  230. "tab_parent" => "admin/degrees",
  231. );
  232. /* OLD - marked for deletion
  233. $items["admin/degrees/handle-edit-degree-submit"] = array(
  234. "page_callback" => "admin_handle_edit_degree_submit",
  235. "access_arguments" => array("can_edit_data_entry"),
  236. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  237. "type" => MENU_TYPE_CALLBACK,
  238. );
  239. */
  240. $items["admin/degrees/popup-add-group"] = array(
  241. "title" => "Add Group",
  242. "page_callback" => "admin_display_degrees_popup_add_group",
  243. "access_arguments" => array("can_edit_data_entry"),
  244. "page_settings" => array(
  245. "page_has_search" => FALSE,
  246. "page_is_popup" => TRUE,
  247. "page_hide_report_error" => TRUE,
  248. ),
  249. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  250. "type" => MENU_TYPE_CALLBACK,
  251. );
  252. $items["admin/degrees/popup-add-group2"] = array(
  253. "title" => "Add Group",
  254. "page_callback" => "admin_display_degrees_popup_add_group2",
  255. "access_arguments" => array("can_edit_data_entry"),
  256. "page_settings" => array(
  257. "page_has_search" => FALSE,
  258. "page_is_popup" => TRUE,
  259. "page_hide_report_error" => TRUE,
  260. ),
  261. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  262. "type" => MENU_TYPE_CALLBACK,
  263. );
  264. $items["admin/degrees/add-degree"] = array(
  265. "title" => "Add Degree",
  266. "page_callback" => "fp_render_form",
  267. "page_arguments" => array("admin_add_degree_form"),
  268. "access_arguments" => array("can_edit_data_entry"),
  269. "page_settings" => array(
  270. "page_has_search" => FALSE,
  271. "page_banner_is_link" => TRUE,
  272. "page_hide_report_error" => TRUE,
  273. "menu_links" => array(
  274. 0 => array(
  275. "text" => "Back to main menu",
  276. "path" => "admin-tools/admin",
  277. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  278. ),
  279. 1 => array(
  280. "text" => "Back to Degrees list",
  281. "path" => "admin/degrees",
  282. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  283. ),
  284. ),
  285. ),
  286. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  287. "type" => MENU_TYPE_NORMAL_ITEM,
  288. "tab_parent" => "admin/degrees",
  289. );
  290. $items["admin/degrees/copy-degree"] = array(
  291. "title" => "Copy Degree",
  292. "page_callback" => "fp_render_form",
  293. "page_arguments" => array("admin_copy_degree_form"),
  294. "access_arguments" => array("can_edit_data_entry"),
  295. "page_settings" => array(
  296. "page_has_search" => FALSE,
  297. "page_banner_is_link" => TRUE,
  298. "page_hide_report_error" => TRUE,
  299. "menu_links" => array(
  300. 0 => array(
  301. "text" => "Back to main menu",
  302. "path" => "admin-tools/admin",
  303. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  304. ),
  305. 1 => array(
  306. "text" => "Back to Degrees list",
  307. "path" => "admin/degrees",
  308. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  309. ),
  310. ),
  311. ),
  312. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  313. "type" => MENU_TYPE_CALLBACK,
  314. "tab_parent" => "admin/degrees",
  315. );
  316. ///////////////////////////////////////////////////////
  317. ////////////////////// Group Editing ///////////////////
  318. $items["admin/groups"] = array(
  319. "title" => "Groups",
  320. "page_callback" => "admin_display_groups",
  321. "access_arguments" => array("can_access_data_entry"),
  322. "page_settings" => array(
  323. "page_has_search" => FALSE,
  324. "page_banner_is_link" => TRUE,
  325. "page_hide_report_error" => TRUE,
  326. "menu_links" => array(
  327. 0 => array(
  328. "text" => "Back to main menu",
  329. "path" => "admin-tools/admin",
  330. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  331. ),
  332. ),
  333. ),
  334. "file" => menu_get_module_path("admin") . "/admin.groups.inc",
  335. "type" => MENU_TYPE_TAB,
  336. "tab_family" => "admin_groups",
  337. );
  338. $items["admin/groups/edit-group"] = array(
  339. "title" => "Edit Group",
  340. "page_callback" => "fp_render_form",
  341. "page_arguments" => array("admin_edit_group_form"),
  342. "access_arguments" => array("can_edit_data_entry"),
  343. "page_settings" => array(
  344. "page_has_search" => FALSE,
  345. "page_banner_is_link" => TRUE,
  346. "page_hide_report_error" => TRUE,
  347. "menu_links" => array(
  348. 0 => array(
  349. "text" => "Back to main menu",
  350. "path" => "admin-tools/admin",
  351. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  352. ),
  353. 1 => array(
  354. "text" => "Back to Groups list",
  355. "path" => "admin/groups",
  356. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  357. ),
  358. ),
  359. ),
  360. "file" => menu_get_module_path("admin") . "/admin.groups.inc",
  361. "type" => MENU_TYPE_NORMAL_ITEM,
  362. "tab_parent" => "admin/groups",
  363. );
  364. $items["admin/groups/popup-select-icon"] = array(
  365. "title" => "Select Icon",
  366. "page_callback" => "admin_display_groups_popup_select_icon",
  367. "access_arguments" => array("can_edit_data_entry"),
  368. "page_settings" => array(
  369. "page_has_search" => FALSE,
  370. "page_is_popup" => TRUE,
  371. "page_hide_report_error" => TRUE,
  372. ),
  373. "file" => menu_get_module_path("admin") . "/admin.groups.inc",
  374. "type" => MENU_TYPE_CALLBACK,
  375. );
  376. $items["admin/groups/popup-edit-definition"] = array(
  377. "title" => "Edit Definition",
  378. "page_callback" => "admin_display_groups_popup_edit_definition",
  379. "access_arguments" => array("can_edit_data_entry"),
  380. "page_settings" => array(
  381. "page_has_search" => FALSE,
  382. "page_is_popup" => TRUE,
  383. "page_hide_report_error" => TRUE,
  384. ),
  385. "file" => menu_get_module_path("admin") . "/admin.groups.inc",
  386. "type" => MENU_TYPE_CALLBACK,
  387. );
  388. $items["admin/groups/popup-show-group-use"] = array(
  389. "title" => "Group Use",
  390. "page_callback" => "admin_display_groups_popup_show_group_use",
  391. "access_arguments" => array("can_edit_data_entry"),
  392. "page_settings" => array(
  393. "page_has_search" => FALSE,
  394. "page_is_popup" => TRUE,
  395. "page_hide_report_error" => TRUE,
  396. ),
  397. "file" => menu_get_module_path("admin") . "/admin.groups.inc",
  398. "type" => MENU_TYPE_CALLBACK,
  399. );
  400. $items["admin/groups/process-all-definitions"] = array(
  401. "title" => "Process all Definitions",
  402. "page_callback" => "fp_render_form",
  403. "page_arguments" => array("admin_process_all_definitions_form"),
  404. "access_arguments" => array("can_edit_data_entry"),
  405. "page_settings" => array(
  406. "page_has_search" => FALSE,
  407. "page_banner_is_link" => TRUE,
  408. "page_hide_report_error" => TRUE,
  409. "menu_links" => array(
  410. 0 => array(
  411. "text" => "Back to main menu",
  412. "path" => "admin-tools/admin",
  413. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  414. ),
  415. 1 => array(
  416. "text" => "Back to Groups list",
  417. "path" => "admin/groups",
  418. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  419. ),
  420. ),
  421. ),
  422. "file" => menu_get_module_path("admin") . "/admin.groups.inc",
  423. "type" => MENU_TYPE_NORMAL_ITEM,
  424. "tab_parent" => "admin/groups",
  425. );
  426. /////////////////////////////////////////////////
  427. /////////////////// Courses editing ////////////////
  428. $items["admin/courses"] = array(
  429. "title" => "Courses",
  430. "page_callback" => "admin_display_courses",
  431. "access_arguments" => array("can_access_data_entry"),
  432. "page_settings" => array(
  433. "page_has_search" => FALSE,
  434. "page_banner_is_link" => TRUE,
  435. "page_hide_report_error" => TRUE,
  436. "menu_links" => array(
  437. 0 => array(
  438. "text" => "Back to main menu",
  439. "path" => "admin-tools/admin",
  440. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  441. ),
  442. ),
  443. ),
  444. "file" => menu_get_module_path("admin") . "/admin.courses.inc",
  445. "type" => MENU_TYPE_TAB,
  446. "tab_family" => "admin_courses",
  447. );
  448. $items["admin/courses/edit-course"] = array(
  449. "title" => "Edit Course",
  450. "page_callback" => "fp_render_form",
  451. "page_arguments" => array("admin_edit_course_form"),
  452. "access_arguments" => array("can_edit_data_entry"),
  453. "page_settings" => array(
  454. "page_has_search" => FALSE,
  455. "page_banner_is_link" => TRUE,
  456. "page_hide_report_error" => TRUE,
  457. "menu_links" => array(
  458. 0 => array(
  459. "text" => "Back to main menu",
  460. "path" => "admin-tools/admin",
  461. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  462. ),
  463. 1 => array(
  464. "text" => "Back to Courses list",
  465. "path" => "admin/courses",
  466. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  467. ),
  468. ),
  469. ),
  470. "file" => menu_get_module_path("admin") . "/admin.courses.inc",
  471. "type" => MENU_TYPE_NORMAL_ITEM,
  472. "tab_parent" => "admin/courses",
  473. );
  474. return $items;
  475. }
  476. /**
  477. * This form will allow the user to duplicate an entire year's worth of data to a new
  478. * catalog year.
  479. *
  480. */
  481. function admin_duplicate_year_form() {
  482. $form = array();
  483. $m = 0;
  484. $form["mark" . $m++] = array(
  485. "value" => "<p>" . t("This form will allow you to duplicate an entire year's worth of data
  486. (courses, degrees, groups) into a new year. This is used to create a new
  487. year of data, based on the previous year, for example. <b>It will completely
  488. delete the 'destination' year data, if it already exists!</b> Use carefully.
  489. <br><br>
  490. The new year will be placed in DRAFT, and will not be visible in FlightPath
  491. until draft changes are applied.
  492. <br><br>
  493. <u>It would be wise</u> to back up your database before proceeding.") . "</p><hr>",
  494. );
  495. $form["source_year"] = array(
  496. "type" => "textfield",
  497. "label" => t("Source year:"),
  498. "size" => 10,
  499. "required" => TRUE,
  500. "description" => t("Enter the 4-digit source year you are copying FROM. For example,
  501. 2007. If you are copying from '2007-2008' then just enter
  502. 2007."),
  503. );
  504. $form["destination_year"] = array(
  505. "type" => "textfield",
  506. "label" => t("Destination year:"),
  507. "size" => 10,
  508. "required" => TRUE,
  509. "description" => t("Enter the 4-digit source year you are copying TO. <b><u>If this year
  510. all ready exists in the system, all data for this year will be DELETED.</u></b>
  511. If you are copying to '2009-2010' then just enter
  512. 2009."),
  513. );
  514. $form["passcode"] = array(
  515. "type" => "password",
  516. "label" => t("For added security, you must enter the Apply Draft Changes password:"),
  517. "required" => TRUE,
  518. "description" => t("This is a password set up in FlightPath's settings, to provide an extra layer
  519. of security for this powerful action. Draft changes will not actually be applied,
  520. this is simply used as an added layer of security."),
  521. );
  522. $form["submit"] = array(
  523. "type" => "submit",
  524. "value" => t("Submit"),
  525. "description" => t("This action may take several minutes to complete! Click only ONCE!"),
  526. "prefix" => "<hr>",
  527. );
  528. return $form;
  529. }
  530. /**
  531. * This function should perform the actual copy of data!
  532. *
  533. * @param unknown_type $form
  534. * @param unknown_type $form_state
  535. */
  536. function admin_duplicate_year_form_submit($form, &$form_state) {
  537. $values = $form_state["values"];
  538. // Check to make sure they entered the transfer passcode correctly.
  539. $db = get_global_database_handler();
  540. if ($values["passcode"] != variable_get("admin_transfer_passcode", "h24897Ewujflnb7 wy2896432hke w490ukj")) {
  541. form_error("passcode", t("Error! The password you entered is not correct. Check with the FlightPath administrator
  542. (or check the admin settings pages) to learn the password."));
  543. return;
  544. }
  545. // Okay, we made it this far, let's proceed with the copy!
  546. $new_year = $values["destination_year"];
  547. $old_year = $values["source_year"];
  548. $form_state['duplication']['src_catalog_year'] = $old_year;
  549. $form_state['duplication']['dest_catalog_year'] = $new_year;
  550. /////////////////////////////////////////////////////////////////////
  551. // We must first begin by deleting any entries for the new_year
  552. // from our tables. This is because we may have to run the parser
  553. // more than once while debugging and such.
  554. $res = db_query("DELETE FROM draft_courses WHERE `catalog_year`= ? ", $new_year);
  555. $res = db_query("DELETE FROM draft_degree_tracks WHERE `catalog_year` = ? ", $new_year);
  556. // For degrees, we first need to select all of the new_year degrees.
  557. $res = db_query("SELECT * FROM draft_degrees WHERE `catalog_year` = ? ", $new_year);
  558. while ($cur = db_fetch_array($res)) {
  559. $res2 = db_query("DELETE FROM draft_degree_requirements WHERE `degree_id`='{$cur["degree_id"]}' ");
  560. }
  561. $res = db_query("DELETE FROM draft_degrees WHERE `catalog_year`=? ", $new_year);
  562. // For groups, begin by selecting all the groups in that year...
  563. $res = db_query("SELECT * FROM draft_groups WHERE `catalog_year`=? ", $new_year);
  564. while ($cur = db_fetch_array($res))
  565. {
  566. // Now, select all the requirements and see if there are any sub groups...
  567. $res2 = db_query("SELECT * FROM draft_group_requirements WHERE `group_id`='{$cur["group_id"]}' ");
  568. while ($cur2 = db_fetch_array($res2))
  569. {
  570. if ($cur2["child_group_id"] > 0)
  571. {
  572. // Delete the child group.
  573. $res3 = db_query("DELETE FROM draft_group_requirements WHERE `group_id`='{$cur2["child_group_id"]}' ");
  574. }
  575. }
  576. // Now, delete the original requirement.
  577. $res3 = db_query("DELETE FROM draft_group_requirements WHERE `group_id`='{$cur["group_id"]}' ");
  578. }
  579. $res = db_query("DELETE FROM draft_groups WHERE `catalog_year`=? ", $new_year);
  580. //////////////////////////////////////////////////////////////////////////
  581. // Okay, we have deleted any possible old entries for the new year.
  582. /////////////////////////////////////////////////////////////////////////
  583. // Our first step is to copy all of the courses from the old_year to the new_year.
  584. $res = db_query("SELECT * FROM draft_courses WHERE `catalog_year`=? ", $old_year);
  585. while ($cur = db_fetch_array($res))
  586. {
  587. extract($cur, 3, "db");
  588. $course = new Course($db_course_id, false, $db, false, $old_year);
  589. $course->subject_id = $db_subject_id;
  590. $course->course_num = $db_course_num;
  591. $course->db_exclude = $db_exclude;
  592. $course->min_hours = $db_min_hours;
  593. $course->max_hours = $db_max_hours;
  594. $course->repeat_hours = $db_repeat_hours;
  595. // Now, duplicate it for the new_year.
  596. $db->duplicate_course_for_year($course, $new_year);
  597. // Store what courses we are working on, for other modules.
  598. $form_state['courses'][] = $db_course_id;
  599. }
  600. $group_id_array = array();
  601. $subgroup_id_array = array();
  602. //////////////////////////////////////////////////////////////////////////
  603. // Now, let's copy over the groups.
  604. $res = db_query("SELECT * FROM draft_groups WHERE `catalog_year`=? ", $old_year);
  605. while ($cur = db_fetch_array($res))
  606. {
  607. extract($cur, 3, "db");
  608. // First, let's request a new group ID for this new group.
  609. $new_group_id = $db->request_new_group_id();
  610. $group_id_array[$db_group_id] = $new_group_id;
  611. //$db_data_entry_comment = mysql_real_escape_string($db_data_entry_comment);
  612. // Now, let's insert this top-level group back into the table
  613. // as the new_year, with the new_group_id.
  614. $query = "INSERT INTO draft_groups(`group_id`,`group_name`,
  615. `title`,`definition`,`icon_filename`,`catalog_year`,
  616. `priority`,`delete_flag`,`data_entry_comment`, `catalog_repeat`)
  617. VALUES ('?','?','?','?','?','?','?','?','?','?') ";
  618. $res2 = db_query($query, $new_group_id,$db_group_name,$db_title,
  619. $db_definition,$db_icon_filename,$new_year,
  620. $db_priority,$db_delete_flag,$db_data_entry_comment,$db_catalog_repeat);
  621. // Okay, now we need to go through the requirements for the group, and copy
  622. // those over to the new_year.
  623. $res3 = db_query("SELECT * FROM draft_group_requirements
  624. WHERE `group_id`='$db_group_id' ");
  625. while($cur3 = db_fetch_array($res3))
  626. {
  627. extract($cur3, 3, "db3");
  628. $child_group_id = 0;
  629. // Was there a child_group (a branch)? If so, we need to copy that
  630. // over too, with a new child_group_id.
  631. if ($db3_child_group_id > 0)
  632. {
  633. // First, create the child group...
  634. $new_sub_group_id = $db->request_new_group_id();
  635. $subgroup_id_array[$db3_child_group_id] = $new_sub_group_id;
  636. $res4 = db_query("SELECT * FROM draft_group_requirements
  637. WHERE `group_id`='$db3_child_group_id' ");
  638. while($cur4 = db_fetch_array($res4))
  639. {
  640. extract($cur4, 3, "db4");
  641. $res5 = db_query("INSERT INTO draft_group_requirements
  642. (`group_id`,`course_id`,`course_min_grade`,
  643. `course_repeats`,`data_entry_value`)
  644. VALUES ('?','?','?','?','?') ",
  645. $new_sub_group_id,$db4_course_id,
  646. $db4_course_min_grade,$db4_course_repeats,
  647. $db4_data_entry_value);
  648. }
  649. // Now, add the replace the db3_child_group_id with this new id
  650. // so it will get added as a requirement.
  651. $child_group_id = $new_sub_group_id;
  652. }
  653. // Add the row into the table...
  654. $res5 = db_query("INSERT INTO draft_group_requirements
  655. (`group_id`,`course_id`,`course_min_grade`,
  656. `course_repeats`,`data_entry_value`,`child_group_id`)
  657. VALUES ('?','?','?','?','?','?') ",
  658. $new_group_id,$db3_course_id,
  659. $db3_course_min_grade,$db3_course_repeats,
  660. $db3_data_entry_value,$child_group_id);
  661. }
  662. }
  663. // Store what groups we are working on, for other modules.
  664. $form_state['groups'] = $group_id_array;
  665. /////////////////////////////////////////////////////////////////////
  666. // Now, on to transfering the degrees.
  667. // We will have to use the groupIDArray we constructed earlier, which
  668. // looks like $arr[old_id] = new_id.
  669. // Do the tracks first, since they are easier and straight forward...
  670. $res = db_query("SELECT * FROM draft_degree_tracks WHERE `catalog_year`='$old_year' ");
  671. while ($cur = db_fetch_array($res))
  672. {
  673. extract($cur, 3, "db");
  674. $res2 = db_query("INSERT INTO draft_degree_tracks
  675. (`catalog_year`,`major_code`,`track_code`,`track_title`,
  676. `track_short_title`,`track_description`)
  677. VALUES
  678. ('?','?','?','?','?','?') ",
  679. $new_year,$db_major_code,$db_track_code,$db_track_title,
  680. $db_track_short_title,$db_track_description);
  681. }
  682. // Now, let's do the degrees themselves.
  683. $res = db_query("SELECT * FROM draft_degrees WHERE `catalog_year`='$old_year' ");
  684. while ($cur = db_fetch_array($res))
  685. {
  686. extract($cur, 3, "db");
  687. $new_degree_id = $db->request_new_degree_id();
  688. // Store what degrees we are working on, for other modules.
  689. $form_state['degrees'][] = array(
  690. 'src' => $db_degree_id,
  691. 'src_catalog_year' => $old_year,
  692. 'dest' => $new_degree_id,
  693. 'dest_major_code' => $db_major_code,
  694. 'dest_catalog_year' => $new_year,
  695. );
  696. // add in the top-level degree to the table.
  697. $res2 = db_query("INSERT INTO draft_degrees
  698. (degree_id, major_code, degree_type, degree_level, degree_class, title,
  699. semester_titles_csv, catalog_year, exclude, public_note,
  700. allow_dynamic, advising_weight, override_degree_hours, min_tracks, max_tracks, default_tracks, track_selection_config)
  701. VALUES
  702. (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  703. ", $new_degree_id,$db_major_code,$db_degree_type, $db_degree_level, $db_degree_class, $db_title,
  704. $db_semester_titles_csv, $new_year, $db_exclude, $db_public_note,
  705. $db_allow_dynamic, $db_advising_weight, $db_override_degree_hours, $db_min_tracks, $db_max_tracks, $db_default_tracks, $db_track_selection_config);
  706. // now, pull out all of the degree_requirements.
  707. $res3 = db_query("SELECT * FROM draft_degree_requirements
  708. WHERE `degree_id`='$db_degree_id' ");
  709. while($cur3 = db_fetch_array($res3))
  710. {
  711. extract($cur3, 3, "db3");
  712. // If there is a required group, we must convert it to the
  713. // new groupID !
  714. $required_group_id = $db3_group_id;
  715. if ($db3_group_id > 0)
  716. {
  717. $required_group_id = $group_id_array[$db3_group_id];
  718. if ($required_group_id < 1 || $required_group_id == "")
  719. {
  720. die("could not find group new group for $old_year $db3_group_id !");
  721. }
  722. }
  723. $res4 = db_query("INSERT INTO draft_degree_requirements
  724. (degree_id, semester_num, group_id, group_requirement_type,
  725. group_hours_required, group_min_hours_allowed, group_min_grade, course_id,
  726. course_min_grade, course_requirement_type, data_entry_value)
  727. VALUES
  728. (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  729. ", $new_degree_id, $db3_semester_num, $required_group_id, $db3_group_requirement_type,
  730. $db3_group_hours_required, $db3_group_min_hours_allowed, $db3_group_min_grade, $db3_course_id,
  731. $db3_course_min_grade, $db3_course_requirement_type, $db3_data_entry_value);
  732. }
  733. }
  734. fp_add_message(t("The copy operation is now completed. You may view the new year
  735. by using the Data Entry links on the admin main menu. Remember, you must
  736. apply draft changes before they will be visible in FlightPath."));
  737. }
  738. /**
  739. * This is a systems settings form, which lets
  740. * the user edit advising variabled for FlightPath.
  741. */
  742. function admin_advising_settings_form() {
  743. $form = array();
  744. $settings = fp_get_system_settings();
  745. /*
  746. $mark = "";
  747. // TODO: This needs to become genericized! If it can't be, it should just be taken out.
  748. $sems = array(40,41, 60,81,82);
  749. for($t = $settings["current_catalog_year"]; $t <= $settings["current_catalog_year"] + 2; $t++) {
  750. $mark .= "<div style='padding-left: 15px;'>";
  751. foreach($sems as $sm) {
  752. $try_year = $t . $sm;
  753. $course = new Course();
  754. $course->term_id = $try_year;
  755. $mark .= "" . $course->get_term_description(true) . ": <b>$course->term_id</b>, &nbsp; &nbsp; &nbsp;";
  756. }
  757. $mark .= "</div>";
  758. }
  759. $form["mark" . $m++] = array(
  760. "type" => "markup",
  761. "value" => t("Term ID Quick Reference:") . $mark,
  762. );
  763. */
  764. $form["available_advising_term_ids"] = array(
  765. "type" => "textfield",
  766. "label" => t("Available advising term id's"),
  767. "value" => variable_get("available_advising_term_ids", ""),
  768. "description" => t("These are the terms for which advisors may advise a student to take
  769. a course. They should follow the structure established on the
  770. school data settings page.
  771. Separate term id's by commas. Ex: 200940, 200941, 200960. Make sure to enter
  772. in the order that they should appear in FlightPath."),
  773. );
  774. $form["advising_term_id"] = array(
  775. "type" => "textfield",
  776. "label" => t("Default advising term id"),
  777. "value" => variable_get("advising_term_id", ""),
  778. "description" => t("Of the available term ids above, this is the default that FlightPath
  779. is set to when an advisor logs in. Ex: 200940."),
  780. );
  781. $form["current_catalog_year"] = array(
  782. "type" => "textfield",
  783. "size" => 10,
  784. "label" => t("Current catalog year"),
  785. "value" => variable_get("current_catalog_year", ""),
  786. "description" => t("This is the year which What If loads degrees from, as well as other important functions.
  787. Only change this once you have fully loaded a new catalog year."),
  788. );
  789. $form["current_draft_catalog_year"] = array(
  790. "type" => "textfield",
  791. "size" => 10,
  792. "label" => t("Current DRAFT catalog year"),
  793. "value" => variable_get("current_draft_catalog_year", ""),
  794. "description" => t("While in Draft mode, this is the year which Blank Degree Search loads degrees from. What If
  795. mode will always use the Current catalog year, set above.
  796. You may change this while working on a new catalog. It will not affect any other
  797. users of the system. While not working on a new catalog, set this
  798. to the same as the Current catalog year."),
  799. );
  800. $form["not_released_grades_terms"] = array(
  801. "type" => "textfield",
  802. "label" => t("NOT released grades terms"),
  803. "value" => variable_get("not_released_grades_terms", ""),
  804. "description" => t("Enter the term_id's, separated by commas,
  805. which are NOT released and should NOT be visible to either advisors or students.
  806. Coures in these terms will only show midterm grades or no grades at all.
  807. Ex: 201240, 201240:S1") . "<br>" . t("If left blank, grades will be visible to
  808. students and advisors as soon as they appear in the database."),
  809. );
  810. return $form;
  811. }
  812. /**
  813. * Convienence function to get semester's default regular name.
  814. */
  815. function admin_get_semester_name($semester_num) {
  816. $semester = new Semester($semester_num);
  817. $title = $semester->title;
  818. /**
  819. $ar = array(t("Freshman Year"), t("Sophomore Year"), t("Junior Year"), t("Senior Year"));
  820. $s = $ar[$semester_num];
  821. if ($s == "")
  822. {
  823. $s = t("Year") . " " . ($semester_num + 1);
  824. }
  825. */
  826. return $title;
  827. }
  828. /**
  829. * This form lets the user apply draft changes (if they can supply the passcode)
  830. */
  831. function admin_apply_draft_changes_form() {
  832. $form = array();
  833. $m = 0;
  834. $form["mark" . $m++] = array(
  835. "type" => "markup",
  836. "value" => t("You can use this form to apply your draft changes to the production database, making changes
  837. to degrees, courses, and groups visible to all users of the system."),
  838. );
  839. $form["passcode"] = array(
  840. "type" => "password",
  841. "label" => t("For added security, you must enter the Apply Draft Changes password:"),
  842. "required" => TRUE,
  843. "description" => t("This is a password set up in FlightPath's settings, to provide an extra layer
  844. of security for this powerful action."),
  845. );
  846. $form["submit"] = array(
  847. "type" => "submit",
  848. "value" => t("Submit"),
  849. "description" => t("This action may take several seconds to complete! Click only ONCE!"),
  850. "prefix" => "<hr>",
  851. );
  852. return $form;
  853. }
  854. /**
  855. * Handles the actual moving of draft courses into production.
  856. */
  857. function admin_apply_draft_changes_form_submit($form, $form_submit) {
  858. $values = $form_submit["values"];
  859. $db = get_global_database_handler();
  860. $de_catalog_year = admin_get_de_catalog_year();
  861. // Check to make sure they entered the transfer passcode correctly.
  862. if ($values["passcode"] != variable_get("admin_transfer_passcode", "h24897Ewujflnb7 wy2896432hke w490ukj")) {
  863. form_error("passcode", t("Error! The password you entered is not correct. Check with the FlightPath administrator
  864. (or check the admin settings pages) to learn the password."));
  865. return;
  866. }
  867. // First, set maintenance mode...
  868. variable_set("maintenance_mode", TRUE);
  869. // Okay, so what we gotta do is truncate the production tables,
  870. // then copy the draft tables in.
  871. $table_array = array(
  872. "courses",
  873. "degree_requirements",
  874. "degree_tracks",
  875. "degrees",
  876. "group_requirements",
  877. "groups",
  878. );
  879. foreach($table_array as $table_name) {
  880. $draft_table_name = "draft_$table_name";
  881. // First, truncate existing...
  882. $query = "truncate table `$table_name`";
  883. $res = db_query($query);
  884. // Now, copy in draft changes...
  885. $query = "INSERT INTO `$table_name`
  886. SELECT * FROM `$draft_table_name` ";
  887. $res = db_query($query);
  888. }
  889. $db2 = new DatabaseHandler();
  890. // Now, we need to go through the draft_instructions table,
  891. // and perform each instruction one at a time.
  892. $res = db_query("SELECT * FROM draft_instructions
  893. ORDER BY `id` ");
  894. while($cur = db_fetch_array($res))
  895. {
  896. $instruction = trim($cur["instruction"]);
  897. $temp = explode(",",$instruction);
  898. if (trim($temp[0]) == "update_course_id") {
  899. $db2->update_course_id(trim($temp[1]), trim($temp[2]));
  900. }
  901. if (trim($temp[0]) == "update_course_requirement_from_name") {
  902. $db2->update_course_requirement_from_name(trim($temp[1]), trim($temp[2]), trim($temp[3]));
  903. }
  904. // TODO: Maybe invoke another hook here, to let other modules act on the instruction?
  905. }
  906. // Once this is done, truncate the draft_instructions table.
  907. $res = db_query("TRUNCATE TABLE draft_instructions");
  908. // Invoke a hook to allow other modules to apply_draft_changes as well
  909. invoke_hook("apply_draft_changes");
  910. // And we are done! Set maintenance mode back to none
  911. variable_set("maintenance_mode", FALSE);
  912. // Send emails to notify programmers...
  913. $notify = variable_get("notify_apply_draft_changes_email_address", "");
  914. if ($notify != "") {
  915. mail($notify, "FlightPath Apply Draft Changes", "Someone has applied draft changes to FlightPath, which updated degree plans, groups, and courses.");
  916. }
  917. fp_add_message(t("Successfully updated the production database with draft changes. Your changes are now live and visible on production for all users."));
  918. watchdog("admin", "Draft changes applied.");
  919. }
  920. /**
  921. * Get the "de_catalog_year" from the REQUEST.
  922. * If it's not there or invalid, pull it from our system settings.
  923. */
  924. function admin_get_de_catalog_year($bool_set_earliest_if_blank = TRUE) {
  925. $settings = fp_get_system_settings();
  926. $de_catalog_year = @$_REQUEST["de_catalog_year"];
  927. if ($bool_set_earliest_if_blank) {
  928. if (!$de_catalog_year || $de_catalog_year < $settings["earliest_catalog_year"]) {
  929. $de_catalog_year = $settings["earliest_catalog_year"];
  930. }
  931. }
  932. return $de_catalog_year;
  933. }
  934. /**
  935. * This is an implementation of hook_menu_handle_replacement_pattern.
  936. * It will search for and replace replacement patterns which we are aware of it in $str.
  937. */
  938. function admin_menu_handle_replacement_pattern($str) {
  939. if (strpos($str, "%DE_CATALOG_YEAR%") !== 0) {
  940. // It contains this replacement pattern!
  941. $str = str_replace("%DE_CATALOG_YEAR%", admin_get_de_catalog_year(), $str);
  942. }
  943. if (strpos($str, "%SEV_FILTER%") !== 0) {
  944. // It contains this replacement pattern!
  945. $str = str_replace("%SEV_FILTER%", @$_GET["sev_filter"], $str);
  946. }
  947. if (strpos($str, "%TYPE_FILTER%") !== 0) {
  948. // It contains this replacement pattern!
  949. $str = str_replace("%TYPE_FILTER%", @$_GET["type_filter"], $str);
  950. }
  951. if (strpos($str, "%PAGE%") !== 0) {
  952. // It contains this replacement pattern!
  953. $str = str_replace("%PAGE%", @$_GET["page"], $str);
  954. }
  955. return $str;
  956. }
  957. function admin_perm() {
  958. return array(
  959. "can_access_admin" => array(
  960. "title" => t("Access administrative console"),
  961. "description" => t("This is a powerful permission! This allows a
  962. user to access the 'admin console' for FlightPath."),
  963. ),
  964. "can_edit_urgent_message" => array(
  965. "title" => t("Edit urgent message"),
  966. "description" => t("The user may edit the 'Urgent Message' which appears at the top of every page, if set."),
  967. ),
  968. "can_access_data_entry" => array(
  969. "title" => t("Access Data Entry"),
  970. "description" => t("The user can access (view) the data-entry portion of the admin console. Degree plans, groups, and courses."),
  971. ),
  972. "can_edit_data_entry" => array(
  973. "title" => t("Edit Data Entry"),
  974. "description" => t("This is a powerful permission! The user can edit degree plans, groups, and courses."),
  975. ),
  976. "can_delete_data_entry" => array(
  977. "title" => t("Delete Data Entry items"),
  978. "description" => t("This is a VERY powerful permission! The user can delete degree plans, groups, and courses."),
  979. ),
  980. "can_view_advanced" => array(
  981. "title" => t("View advanced"),
  982. "description" => t("The user may see advanced information on-screen, for example, internal ID numbers for degrees and courses."),
  983. ),
  984. "can_apply_draft_changes" => array(
  985. "title" => t("Apply draft changes"),
  986. "description" => t("The user may move draft changes into production."),
  987. ),
  988. "can_edit_advising_settings" => array(
  989. "title" => t("Edit advising settings"),
  990. "description" => t("The user may edit advising settings, like available term IDs and the current catalog year."),
  991. ),
  992. "display_watchdog" => array(
  993. "title" => t("View watchdog (log) entries"),
  994. "description" => t("The user may view the recent watchdog log entries. This represents a security concern, so give this only to trusted users."),
  995. ),
  996. );
  997. }
  998. /**
  999. * Meant to be fed into "fp_system_settings_form()", this function
  1000. * returns an array which will automatically save values to our "variables" table.
  1001. */
  1002. function admin_urgent_message_form() {
  1003. $form = array();
  1004. $form["mark_top"] = array(
  1005. "type" => "markup",
  1006. "value" => "<p>" . t("Any message you enter here will be displayed at the top of every page <b>for all users</b> in the system.
  1007. This is used to alert users that the system is about to be taken offline, or any other urgently-needed information.") . "</p>",
  1008. );
  1009. $form["urgent_msg"] = array(
  1010. "type" => "textarea",
  1011. "label" => "Global Urgent Message:",
  1012. "value" => variable_get("urgent_msg", ""),
  1013. 'description' => t("To delete this message, simple delete all the text in this box and save."),
  1014. );
  1015. return $form;
  1016. }
  1017. /**
  1018. * Display the details of a particular watchdog entry, specified by its table id.
  1019. */
  1020. function admin_display_watchdog_entry($wid) {
  1021. $rtn = "";
  1022. fp_add_css(fp_get_module_path("admin") . '/css/admin.css');
  1023. $severity_array = array(
  1024. 5 => "notice",
  1025. 1 => "alert",
  1026. 3 => "error",
  1027. 7 => "debug",
  1028. );
  1029. $res = db_query("SELECT * FROM watchdog WHERE wid = '?' ", $wid);
  1030. $cur = db_fetch_object($res);
  1031. $msg = t($cur->message, unserialize($cur->variables));
  1032. $severity = $severity_array[$cur->severity];
  1033. $when = format_date($cur->timestamp, "short");
  1034. // Display
  1035. $rtn .= "
  1036. <br>
  1037. <div class='watchdog-entry'>
  1038. <div class='watchdog-field'>
  1039. <label>ID:</label>
  1040. $cur->wid
  1041. </div>
  1042. <div class='watchdog-field'>
  1043. <label>Type:</label>
  1044. $cur->type
  1045. </div>
  1046. <div class='watchdog-field'>
  1047. <label>Time:</label>
  1048. $when ($cur->timestamp)
  1049. </div>
  1050. <div class='watchdog-field'>
  1051. <label>Severity:</label>
  1052. $severity
  1053. </div>
  1054. <div class='watchdog-field'>
  1055. <label>User:</label>
  1056. $cur->user_name | id: $cur->user_id | cwid: $cur->cwid | is_student: $cur->is_student | is_faculty: $cur->is_faculty
  1057. </div>
  1058. <div class='watchdog-field'>
  1059. <label>IP:</label>
  1060. $cur->ip
  1061. </div>
  1062. <div class='watchdog-field'>
  1063. <label>Location:</label>
  1064. $cur->location
  1065. </div>
  1066. <div class='watchdog-field'>
  1067. <label>Ref:</label>
  1068. $cur->referer
  1069. </div>
  1070. <hr>
  1071. <div class='watchdog-field'>
  1072. <label class='block'>Message:</label>
  1073. $msg
  1074. </div>
  1075. <div class='watchdog-field'>
  1076. <label class='block'>Extra:</label>
  1077. $cur->extra_data
  1078. </div>
  1079. </div>
  1080. ";
  1081. return $rtn;
  1082. }
  1083. /**
  1084. * Displays recent watchdog entries, from the watchdog table
  1085. *
  1086. */
  1087. function admin_display_watchdog() {
  1088. fp_add_css(fp_get_module_path("admin") . '/css/admin.css');
  1089. $rtn = "";
  1090. $rtn .= "<p>View recent watchdog entries</p>";
  1091. $severity_array = array(
  1092. 5 => "notice",
  1093. 1 => "alert",
  1094. 3 => "error",
  1095. 7 => "debug",
  1096. );
  1097. $results_per_page = 50;
  1098. $type_line = $severity_line = $limit_start = "";
  1099. @$sev_filter = $_GET["sev_filter"];
  1100. @$type_filter = $_GET["type_filter"];
  1101. @$page = $_GET["page"];
  1102. $limit_start = 0;
  1103. if ($page != "" && is_numeric($page)) {
  1104. $limit_start = $results_per_page * ($page - 1);
  1105. }
  1106. else {
  1107. $page = 1;
  1108. }
  1109. // Filters:
  1110. $rtn .= "<form method='GET' action='" . fp_url("admin/config/watchdog") . "' class='watchdog-filters'>
  1111. ";
  1112. $rtn .= "Filter by:
  1113. <span class='type-filter'>
  1114. Type:
  1115. <select name='type_filter'>
  1116. <option value=''>-Any-</option>";
  1117. $res = db_query("SELECT distinct(type) as type FROM watchdog ORDER BY type");
  1118. while ($cur = db_fetch_object($res)) {
  1119. $sel = ($type_filter == $cur->type) ? "selected" : "";
  1120. $rtn .= "<option value='$cur->type' $sel>$cur->type</option>";
  1121. }
  1122. $rtn .= "</select>
  1123. </span>";
  1124. $rtn .= "
  1125. <span class='severity-filter'>
  1126. Severity:
  1127. <select name='sev_filter'>
  1128. <option value=''>-Any-</option>";
  1129. foreach ($severity_array as $key => $value) {
  1130. $sel = "";
  1131. if ($sev_filter == $key) $sel = "selected";
  1132. $rtn .= "<option value='$key' $sel>$value</option>";
  1133. }
  1134. $rtn .= "</select>
  1135. </span>";
  1136. $rtn .= "<input type='submit' value='-&gt;'>";
  1137. // Hack if clean URLs are not enabled:
  1138. $rtn .= "<input type='hidden' name='q' value='admin/config/watchdog'>";
  1139. $rtn .= "</form>";
  1140. $params = array();
  1141. if (@$_GET["type_filter"] != "") {
  1142. //$type_line = " AND type = '" . mysql_real_escape_string($_GET["type_filter"]) . "' ";
  1143. $type_line = " AND `type` = :type ";
  1144. $params[":type"] = $_GET["type_filter"];
  1145. }
  1146. if (@$_GET["sev_filter"] != "") {
  1147. //$severity_line = " AND severity = '" . mysql_real_escape_string($_GET["sev_filter"]) . "' ";
  1148. $severity_line = " AND severity = :sev ";
  1149. $params[":sev"] = $_GET["sev_filter"];
  1150. }
  1151. $pol = "even";
  1152. $rtn .= "<table class='watchdog-table' cellspacing='0' cellpadding='4'>
  1153. <tr>
  1154. <th>ID</th>
  1155. <th>When</th>
  1156. <th>Type</th>
  1157. <th>Msg</th>
  1158. <th>User</th>
  1159. </tr>";
  1160. // Okay, let's display the recent watchdog entries.
  1161. $query = "SELECT * FROM watchdog
  1162. WHERE 1
  1163. $type_line
  1164. $severity_line
  1165. ORDER BY wid DESC
  1166. ";
  1167. $res = db_query($query . " LIMIT $limit_start, $results_per_page", $params);
  1168. while ($cur = db_fetch_object($res)) {
  1169. $pol = ($pol == "even") ? "odd" : "even";
  1170. $o_msg = t($cur->message, unserialize($cur->variables));
  1171. $o_type = $cur->type;
  1172. // shorten msg if necessary
  1173. $msg = substr($o_msg, 0, 120);
  1174. if ($msg != $o_msg) {
  1175. $msg = trim($msg) . "...";
  1176. }
  1177. $type = substr($o_type, 0, 15);
  1178. if ($type != $o_type) {
  1179. $type = trim($type) . "...";
  1180. }
  1181. $severity = $severity_array[$cur->severity];
  1182. $when = format_date($cur->timestamp, "short");
  1183. $rtn .= "
  1184. <tr class='row-$pol row-$severity'>
  1185. <td valign='top'>" . l($cur->wid, "admin/config/watchdog/$cur->wid", "sev_filter=$sev_filter&type_filter=$type_filter&page=$page") . "</td>
  1186. <td valign='top'>$when</td>
  1187. <td valign='top'>$type</td>
  1188. <td valign='top'>$msg</td>
  1189. <td valign='top'>$cur->user_name</td>
  1190. </tr>
  1191. ";
  1192. }
  1193. $rtn .= "</table>";
  1194. // Now, do the page
  1195. // Figure out the total number of results
  1196. $total = db_result(db_query("SELECT count(wid) as count
  1197. FROM watchdog WHERE 1 $type_line $severity_line", $params));
  1198. // Now, divide by the number of results per page.
  1199. $pages = ceil($total / $results_per_page);
  1200. $base_query = "sev_filter=$sev_filter&type_filter=$type_filter";
  1201. $rtn .= "<div class='fp-pager'>";
  1202. if ($page > 1) {
  1203. $rtn .= "<span class='pager-link pager-first'>" . l("&laquo; first", "admin/config/watchdog", $base_query . "&page=1") . "</span>";
  1204. $rtn .= "<span class='pager-link pager-prev'>" . l("&lt; prev", "admin/config/watchdog", $base_query . "&page=" . ($page - 1)) . "</span>";
  1205. }
  1206. else {
  1207. $rtn .= "<span class='pager-link pager-first'>&laquo; first</span>";
  1208. $rtn .= "<span class='pager-link pager-prev'>&lt; prev</span>";
  1209. }
  1210. // page numbers here
  1211. // Let's get the previous X page numbers, and next X (if possible)
  1212. $start_page_num = $page - 5;
  1213. if ($start_page_num < 1) $start_page_num = 1;
  1214. $end_page_num = $page + 5;
  1215. if ($end_page_num > $pages) $end_page_num = $pages;
  1216. if ($start_page_num > 1) {
  1217. $rtn .= "<span class='pager-elip'>...</span>";
  1218. }
  1219. for ($t = $start_page_num; $t <= $end_page_num; $t++) {
  1220. if ($page == $t) {
  1221. // current page
  1222. $rtn .= "<span class='pager-link pager-number pager-current'>$t</span>";
  1223. }
  1224. else {
  1225. $rtn .= "<span class='pager-link pager-number'>" . l($t, "admin/config/watchdog", $base_query . "&page=$t") . "</span>";
  1226. }
  1227. }
  1228. if ($end_page_num < $pages) {
  1229. $rtn .= "<span class='pager-elip'>...</span>";
  1230. }
  1231. if ($page < $pages) {
  1232. $rtn .= "<span class='pager-link pager-next'>" . l("next &gt;", "admin/config/watchdog", $base_query . "&page=" . ($page + 1)) . "</span>";
  1233. $rtn .= "<span class='pager-link pager-last'>" . l("last &raquo;", "admin/config/watchdog", $base_query . "&page=$pages") . "</span>";
  1234. }
  1235. else {
  1236. $rtn .= "<span class='pager-link pager-next'>next &gt;</span>";
  1237. $rtn .= "<span class='pager-link pager-last'>last &raquo;</span>";
  1238. }
  1239. $rtn .= "</div>";
  1240. return $rtn;
  1241. }
  1242. /**
  1243. * This is the "main" page for the admin module. It's what the user
  1244. * first sees when the click to go to the Admin page.
  1245. */
  1246. function admin_display_main() {
  1247. $de_catalog_year = admin_get_de_catalog_year(FALSE);
  1248. // Has the system cron been run recently?
  1249. $cron_last_run = variable_get("cron_last_run", 0);
  1250. if ($cron_last_run < strtotime("-7 DAY")) {
  1251. // Warn admin that they need to have cron set up! It's been over a week!
  1252. fpm(t("Your system's cron process hasn't run in over a week. In order for FlightPath
  1253. to continue to function properly, a cron process much be configured.
  1254. You may @run_link or see the @status_link page for instructions.",
  1255. array("@status_link" => l(t("System status"), "admin/config/status"),
  1256. "@run_link" => l(t("run cron now"), "admin/config/run-cron"))));
  1257. }
  1258. $rtn = "";
  1259. fp_add_css(fp_get_module_path("admin") . "/css/admin.css");
  1260. fp_add_js(fp_get_module_path("admin") . "/js/admin.js");
  1261. $rtn .= "<h2>" . t("FlightPath Admin Console - Main Menu") . "</h2>";
  1262. $rtn .= "<table class='fp-semester-table' cellpadding='5'>
  1263. <tr>
  1264. <td valign='top' width='50%'>
  1265. " . fp_render_menu_block(t("System Configuration"), "admin/config") . "
  1266. </td>
  1267. <td valign='top' width='50%'>
  1268. ";
  1269. // Advising Settings
  1270. $rtn .= fp_render_curved_line("Advising Settings");
  1271. $rtn .= "<div class='admin-advising-settings'>
  1272. <ul>
  1273. <li>" . t("Available terms for advising: %v", array("%v" => variable_get("available_advising_term_ids", ""))) . "</li>
  1274. <li>" . t("Default advising term: %v", array("%v" => variable_get("advising_term_id", ""))) . "</li>
  1275. <li>" . t("Current catalog year: %v", array("%v" => variable_get("current_catalog_year", ""))) . "</li>
  1276. <li>" . t("Current draft catalog year: %v", array("%v" => variable_get("current_draft_catalog_year", ""))) . "</li>
  1277. <li>" . t("Not released grades terms: %v", array("%v" => variable_get("not_released_grades_terms", ""))) . "</li>
  1278. </ul>";
  1279. if (user_has_permission("can_edit_advising_settings")) {
  1280. $rtn .= l(t("Edit Advising Settings"), "admin/edit-advising-settings");
  1281. }
  1282. $rtn .= "</div>";
  1283. $rtn .= "</td>
  1284. </tr>";
  1285. $rtn .= "</table><br>"; // close table
  1286. //$settings = fp_get_system_settings();
  1287. $current_catalog_year = variable_get("current_catalog_year", 2006);
  1288. $earliest_catalog_year = variable_get("earliest_catalog_year", 2006);
  1289. if (user_has_permission("can_access_data_entry")) {
  1290. $rtn .= fp_render_curved_line("Data Entry");
  1291. $rtn .= "<div class='data-entry-cats'>";
  1292. // Have a pulldown here of years, then use javascript to hide/show relavant groups.
  1293. $rtn .= "&nbsp; &nbsp; &nbsp; " . t("Select a catalog year") . ": <select id='data-entry-select-cats' onChange='adminHideDECats();'>";
  1294. $selected_cat = ($de_catalog_year != "") ? $de_catalog_year : $current_catalog_year;
  1295. for ($t = $current_catalog_year +1; $t >= $earliest_catalog_year; $t--) {
  1296. $sel = ($t == $selected_cat) ? "selected" : "";
  1297. $rtn .= "<option value='$t' $sel>$t-" . ($t+1) . "</option>";
  1298. }
  1299. $rtn .= "</select>";
  1300. for ($t = $current_catalog_year +1; $t >= $earliest_catalog_year; $t--) {
  1301. $rtn .= "<ul class='data-entry-for-cat data-entry-for-cat-$t'>";
  1302. $rtn .= "<li>" . l(t("Degree plans for @year", array("@year" => "$t-" . ($t+1))), "admin/degrees", "de_catalog_year=$t") . "</li>";
  1303. $rtn .= "<li>" . l(t("Groups for @year", array("@year" => "$t-" . ($t+1))), "admin/groups", "de_catalog_year=$t") . "</li>";
  1304. $rtn .= "<li>" . l(t("Courses for @year", array("@year" => "$t-" . ($t+1))), "admin/courses", "de_catalog_year=$t") . "</li>";
  1305. $rtn .= "</ul>";
  1306. }
  1307. if (user_has_permission("can_edit_data_entry")) {
  1308. $rtn .= "<b>" . t("Administrator function:") . "</b><ul>
  1309. <li>" . l(t("Duplicate entire year worth of data to new year"), "admin/duplicate-year") . "</li>
  1310. </ul>";
  1311. }
  1312. $rtn .= "</div>";
  1313. // Draft changes?
  1314. $res = db_query("SELECT * FROM draft_instructions");
  1315. if (db_num_rows($res) > 0) {
  1316. $rtn .= "<div class='draft-changes-waiting-msg'>
  1317. " . t("Draft changes have been made which have yet to be applied.
  1318. When you are ready for your draft changes to appear in
  1319. production, click the link below.") . "</div>";
  1320. }
  1321. $rtn .= "<ul class='data-entry-draft-waiting'>
  1322. <li>" . l(t("Apply draft changes"), "admin/apply-draft-changes") . "</li>
  1323. </ul>";
  1324. }
  1325. return $rtn;
  1326. }