system.module

  1. 6.x modules/system/system.module
  2. 4.x modules/system/system.module
  3. 5.x modules/system/system.module

File

modules/system/system.module
View source
  1. <?php
  2. /**
  3. * Implementation of hook_perm().
  4. * Expects to return an array of permissions recognized by
  5. * this module.
  6. *
  7. * Ex: $a = array(
  8. * "deCanDoSomething" => array (
  9. * "title" => "Can Do Something",
  10. * "description" => "Allow the user to do something."
  11. * )
  12. * );
  13. *
  14. */
  15. function system_perm() {
  16. $perms = array (
  17. "access_logged_in_content" => array(
  18. "title" => t("Access logged-in content"),
  19. "description" => t("This should be given to all authenticated users. It simply means
  20. the user is allowed to view the logged-in area of FlightPath."),
  21. ),
  22. "administer_modules" => array(
  23. "title" => t("Administer modules"),
  24. "description" => t("This will allow a user to install, enable, disable, and uninstall modules."),
  25. "admin_restricted" => TRUE, // means only appears for admin (user_id == 1)
  26. ),
  27. "clear_system_cache" => array(
  28. "title" => t("Clear system cache"),
  29. "description" => t("This will allow a to clear the system cache, including the menu router. Give to developers and/or admin users."),
  30. ),
  31. "run_cron" => array(
  32. "title" => t("Run Cron"),
  33. "description" => t("The user may run hook_cron functions at will. Causes a new menu link to appear
  34. on the admin page."),
  35. ),
  36. "de_can_administer_system_settings" => array(
  37. "title" => t("Can administer system settings"),
  38. "description" => t("This allows the user to edit any of the FlightPath
  39. system settings."),
  40. ),
  41. "de_can_administer_school_data" => array(
  42. "title" => t("Can administer school data"),
  43. "description" => t("This allows the user to edit the school data settings for FlightPath.
  44. For example, describing college and subject codes."),
  45. ),
  46. "view_fpm_debug" => array(
  47. "title" => t("View debug output from the fpm() function"),
  48. "description" => t("The user may view debug output from the fpm() function.
  49. Useful for developers."),
  50. ),
  51. "view_system_status" => array(
  52. "title" => t("View system status"),
  53. "description" => t("The user may view the update status and other requirements of the system."),
  54. ),
  55. "execute_php" => array(
  56. "title" => t("Execute PHP code"),
  57. "description" => t("WARNING: This is a very VERY powerful and DANGEROUS permission. Only give it to
  58. developers. An 'Execute PHP' link will appear on the admin menu, which
  59. lets the user execute any arbitrary PHP code."),
  60. "admin_restricted" => TRUE, // means only appears for admin (user_id == 1)
  61. ),
  62. );
  63. return $perms;
  64. }
  65. /**
  66. * Implements hook flightpath_can_assign_course_to_degree_id
  67. *
  68. */
  69. function system_flightpath_can_assign_course_to_degree_id($degree_id, Course $course) {
  70. // If this course has already been assigned to another degree, should we allow it to be assigned to THIS degree?
  71. $this_major_code = fp_get_degree_major_code($degree_id);
  72. $temp = explode("|", $this_major_code);
  73. $this_first_part = trim($temp[0]); // get just the first part. Ex, ENGL|_something => ENGL
  74. // If the configuration is such that a course cannot be assigned to a degree's tracks, then no.
  75. // Example: if a course has been assigned to ENGL, then it can't also get assigned to ENGL|_track1
  76. if (variable_get_for_school("prevent_course_assignment_to_both_degree_and_track", "yes", $course->school_id) == 'yes') {
  77. // Begin by checking to see what degrees the course has already been assigned to (if any)
  78. if (count($course->assigned_to_degree_ids_array)) {
  79. foreach ($course->assigned_to_degree_ids_array as $d_id) {
  80. $m_code = fp_get_degree_major_code($d_id);
  81. if ($m_code) {
  82. $temp = explode("|", $this_major_code);
  83. $m_code_first_part = trim($temp[0]); // get just the first part. Ex, ENGL|_something => ENGL
  84. // At this point, we have a major code for a degree which this course has already been assigned.
  85. // Ex: ENGL or ENGL|minor
  86. // If this degree is a track, the variable $this_major_code should equal ENGL|_whatever or, ENGL|minor_whatever.
  87. // If that condition is true, then we must return FALSE.
  88. // We will look for the presence of an underscore and a pipe symbol first, and see if this_first_part == m_code_first_part
  89. if (strstr($this_major_code, "_") && strstr($this_major_code, "|") && $this_first_part == $m_code_first_part) {
  90. // Now, if this_major_code CONTAINS m_code, then that means our condition
  91. // is true.
  92. if (strstr($this_major_code, $m_code)) {
  93. return FALSE; // meaning, no, we cannot assign this course!
  94. }
  95. }
  96. }
  97. }
  98. } //if count(assigned to degree ids array)
  99. } // if variable_get ...
  100. // Default, return TRUE
  101. return TRUE;
  102. } // hook_flightpath_can_assign_course_to_degree_id
  103. /**
  104. * Implements hook_fp_get_student_majors.
  105. *
  106. * In our case, we will use our database method and get directly from our student_degrees table.
  107. */
  108. function system_fp_get_student_majors($student_cwid, $bool_return_as_full_record = FALSE, $perform_join_with_degrees = TRUE, $bool_skip_directives = TRUE, $bool_check_for_allow_dynamic = TRUE, $school_id = 0) {
  109. $db = get_global_database_handler();
  110. $rtn = $db->get_student_majors_from_db($student_cwid, $bool_return_as_full_record, $perform_join_with_degrees, $bool_skip_directives, $bool_check_for_allow_dynamic, $school_id);
  111. return $rtn;
  112. }
  113. /**
  114. * Return an array containing the roles which have been assigned to
  115. * a specific user.
  116. */
  117. function system_get_roles_for_user($user_id) {
  118. $rtn = array();
  119. $res = db_query("SELECT * FROM user_roles a, roles b
  120. WHERE user_id = '?'
  121. AND a.rid = b.rid ", $user_id);
  122. while ($cur = db_fetch_array($res)) {
  123. $rtn[$cur["rid"]] = $cur["name"];
  124. }
  125. // Is this person in the users table? If so, they will get the rid 2 (authenticated)
  126. // If not, they will get the role 1 (anonymous)
  127. $res2 = db_query("SELECT user_id FROM users WHERE user_id = '?' AND user_id <> '0' ", $user_id);
  128. if (db_num_rows($res2) > 0) {
  129. $rtn[2] = t("authenticated user");
  130. }
  131. else {
  132. $rtn[1] = t("anonymous user");
  133. }
  134. return $rtn;
  135. }
  136. /**
  137. * This function will attempt to confirm that "clean URLs" is functioning, and
  138. * allowed on this server.
  139. *
  140. * Returns TRUE or FALSE
  141. */
  142. function system_check_clean_urls() {
  143. // Are clean-url's enabled?
  144. // We will do this by trying to retrieve a test URL, built into index.php.
  145. // If we can get a success message back from "http://example.com/flightpath/test-clean-urls/check", then
  146. // we are good to go.
  147. // First, figure out the base URL.
  148. $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
  149. $host = $_SERVER['HTTP_HOST'];
  150. $script = $_SERVER['SCRIPT_NAME'];
  151. $base_url = $protocol . "://" . $host . $script;
  152. $base_url = str_replace("/install.php", "", $base_url);
  153. $base_url = str_replace("/index.php", "", $base_url);
  154. // Try to get our test URL's success message...
  155. $res = fp_http_request($base_url . '/test-clean-urls/check');
  156. if ($res->code != 200) {
  157. // There was an error or some other problem!
  158. // But wait-- did we get redirected?
  159. if (isset($res->redirect_code) && $res->redirect_code == 200) {
  160. return TRUE; // it's OK after all!
  161. }
  162. return FALSE;
  163. }
  164. // If we made it here, it must have worked.
  165. return TRUE;
  166. }
  167. /**
  168. * Hook block regions.
  169. *
  170. * This function simply defines which block regions we will handle. Each
  171. * block section should have a unique machine name, so it is best to namespace it with the
  172. * name of the module, then page or tab it appears on.
  173. *
  174. * The array looks like this:
  175. * return array(
  176. * "system_main" => array(
  177. * "title" => t("Main Tab"),
  178. * "regions" => array (
  179. * "left_col" => array("title" => t("Left Column")),
  180. * "right_col" => array("title" => t("Right Column")),
  181. * ),
  182. * ),
  183. * );
  184. *
  185. *
  186. * REMEMBER to make these machine-names, so only alpha numeric and underscores!
  187. */
  188. function system_block_regions() {
  189. return array(
  190. "system_main" => array(
  191. "title" => t("Main Tab"),
  192. "regions" => array (
  193. "left_col" => array("title" => t("Left Column")),
  194. "right_col" => array("title" => t("Right Column")),
  195. ),
  196. ),
  197. "system_login" => array(
  198. "title" => t("Login Page"),
  199. "regions" => array (
  200. "top" => array("title" => t("Top")),
  201. "left_col" => array("title" => t("Left Column")),
  202. "right_col" => array("title" => t("Right Column")),
  203. "bottom" => array("title" => t("Bottom")),
  204. ),
  205. ),
  206. );
  207. }
  208. function system_menu() {
  209. $items = array();
  210. $items["main"] = array(
  211. "title" => "Dashboard",
  212. "page_callback" => "system_display_dashboard_page",
  213. "access_callback" => TRUE,
  214. "type" => MENU_TYPE_NORMAL_ITEM,
  215. "weight" => 10,
  216. "page_settings" => array(
  217. "screen_mode" => "not_advising",
  218. ),
  219. );
  220. $items["render-advising-snapshot-for-iframe"] = array(
  221. "title" => "Dashboard",
  222. "page_callback" => "system_render_advising_snapshop_for_iframe",
  223. "access_arguments" => array("access_logged_in_content"),
  224. "type" => MENU_TYPE_NORMAL_ITEM,
  225. "weight" => 10,
  226. "page_settings" => array(
  227. "screen_mode" => "not_advising",
  228. ),
  229. );
  230. $items['login-help'] = array(
  231. "title" => "Login Help",
  232. "page_callback" => "system_display_login_help_page",
  233. "access_callback" => TRUE,
  234. );
  235. $items["install-finished"] = array(
  236. "title" => "Installation Finished",
  237. "page_callback" => "system_display_install_finished_page",
  238. "access_callback" => TRUE,
  239. "type" => MENU_TYPE_CALLBACK,
  240. );
  241. $items["login"] = array(
  242. "title" => "Login",
  243. "page_callback" => "system_display_login_page",
  244. "access_callback" => TRUE,
  245. "type" => MENU_TYPE_NORMAL_ITEM,
  246. );
  247. $items["mfa-login"] = array(
  248. "title" => "Multi-Factor Authentication",
  249. "page_callback" => "fp_render_form",
  250. "page_arguments" => array("system_mfa_login_form"),
  251. "access_callback" => TRUE,
  252. "type" => MENU_TYPE_NORMAL_ITEM,
  253. );
  254. $items["disable-login"] = array(
  255. "title" => "Login Disabled",
  256. "page_callback" => "system_display_disable_login_page",
  257. "access_callback" => TRUE,
  258. "type" => MENU_TYPE_NORMAL_ITEM,
  259. );
  260. $items["disable-student-login"] = array(
  261. "title" => "Student Logins Disabled",
  262. "page_callback" => "system_display_disable_login_page",
  263. "page_arguments" => array("student"),
  264. "access_callback" => TRUE,
  265. "type" => MENU_TYPE_NORMAL_ITEM,
  266. );
  267. $items["admin-tools/clear-cache"] = array(
  268. "title" => t("Clear all cache"),
  269. "description" => t("Clear and reset all cached items in FlightPath, including menu items, advising, etc."),
  270. "page_callback" => "system_perform_clear_cache",
  271. "access_arguments" => array("clear_system_cache"),
  272. "type" => MENU_TYPE_NORMAL_ITEM,
  273. "page_settings" => array(
  274. "menu_icon" => fp_get_module_path('system') . "/icons/arrow_refresh.png",
  275. ),
  276. );
  277. $items["admin/db-updates"] = array(
  278. "title" => "Run DB updates?",
  279. "page_callback" => "fp_render_form",
  280. "page_arguments" => array("system_confirm_db_updates_form"),
  281. "access_arguments" => array("administer_modules"),
  282. "type" => MENU_TYPE_NORMAL_ITEM,
  283. );
  284. $items["admin/completed-db-updates"] = array(
  285. "title" => "Database updates completed",
  286. "page_callback" => "system_display_completed_db_updates",
  287. "access_arguments" => array("administer_modules"),
  288. "page_settings" => array(
  289. "page_show_title" => TRUE,
  290. ),
  291. "type" => MENU_TYPE_NORMAL_ITEM,
  292. );
  293. $items["system/uninstall-module"] = array(
  294. "page_callback" => "system_handle_uninstall_module",
  295. "page_arguments" => array(2),
  296. "access_arguments" => array("administer_modules"),
  297. "type" => MENU_TYPE_CALLBACK,
  298. );
  299. $items["system-handle-form-submit"] = array(
  300. "page_callback" => "system_handle_form_submit",
  301. "access_callback" => TRUE,
  302. "type" => MENU_TYPE_CALLBACK,
  303. );
  304. $items["logout"] = array(
  305. "title" => "Logout",
  306. "page_callback" => "system_handle_logout",
  307. "access_callback" => TRUE,
  308. "type" => MENU_TYPE_CALLBACK,
  309. );
  310. $items["popup-report-contact"] = array(
  311. "title" => "Report/Contact",
  312. "page_callback" => "fp_render_form",
  313. "page_arguments" => array("system_popup_report_contact_form"),
  314. "access_callback" => TRUE,
  315. "page_settings" => array(
  316. "page_is_popup" => TRUE,
  317. "page_hide_report_error" => TRUE,
  318. ),
  319. "type" => MENU_TYPE_CALLBACK,
  320. );
  321. $items["popup-contact-form/thank-you"] = array(
  322. "title" => "Report/Contact",
  323. "page_callback" => "system_popup_report_contact_thank_you",
  324. "access_callback" => TRUE,
  325. "page_settings" => array(
  326. "page_is_popup" => TRUE,
  327. "page_hide_report_error" => TRUE,
  328. ),
  329. "type" => MENU_TYPE_CALLBACK,
  330. );
  331. //////////////// Config (admin console main menu) /////////////
  332. $items["admin/config/run-cron"] = array(
  333. "title" => "Run cron now",
  334. "description" => "Run the normal cron operations right away",
  335. "page_callback" => "system_perform_run_cron",
  336. "access_arguments" => array("run_cron"),
  337. "page_settings" => array(
  338. "menu_icon" => fp_get_module_path('system') . "/icons/clock.png",
  339. ),
  340. "type" => MENU_TYPE_NORMAL_ITEM,
  341. );
  342. $items["admin/config/status"] = array(
  343. "title" => "System status",
  344. "description" => "View important notifications and updates for your installation of " . variable_get("system_name", "FlightPath"),
  345. "page_callback" => "system_display_status_page",
  346. "access_arguments" => array("view_system_status"),
  347. "page_settings" => array(
  348. "page_show_title" => TRUE,
  349. "menu_icon" => fp_get_module_path('system') . "/icons/application_view_list.png",
  350. "menu_links" => array(
  351. 0 => array(
  352. "text" => "Admin Console",
  353. "path" => "admin-tools/admin",
  354. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  355. ),
  356. ),
  357. ),
  358. "type" => MENU_TYPE_NORMAL_ITEM,
  359. "tab_parent" => "admin-tools/admin",
  360. );
  361. $items["admin/config/system-settings"] = array(
  362. "title" => "System settings",
  363. "description" => "Configure settings for FlightPath",
  364. "page_callback" => "fp_render_form",
  365. "page_arguments" => array("system_settings_form", "system_settings"),
  366. "access_arguments" => array("de_can_administer_system_settings"),
  367. "page_settings" => array(
  368. "page_hide_report_error" => TRUE,
  369. "menu_icon" => fp_get_module_path('system') . "/icons/cog.png",
  370. "menu_links" => array(
  371. 0 => array(
  372. "text" => "Admin Console",
  373. "path" => "admin-tools/admin",
  374. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  375. ),
  376. ),
  377. ),
  378. "type" => MENU_TYPE_NORMAL_ITEM,
  379. "tab_parent" => "admin-tools/admin",
  380. );
  381. $items["admin/config/school-data"] = array(
  382. "title" => "Configure school settings",
  383. "description" => "Configure school-specific data and settings",
  384. "page_callback" => "fp_render_form",
  385. "page_arguments" => array("system_school_data_form", "system_settings"),
  386. "access_arguments" => array("de_can_administer_school_data"),
  387. "page_settings" => array(
  388. "page_hide_report_error" => TRUE,
  389. "menu_icon" => fp_get_module_path('system') . "/icons/cog_edit.png",
  390. "menu_links" => array(
  391. 0 => array(
  392. "text" => "Admin Console",
  393. "path" => "admin-tools/admin",
  394. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  395. ),
  396. ),
  397. ),
  398. "type" => MENU_TYPE_NORMAL_ITEM,
  399. "tab_parent" => "admin-tools/admin",
  400. );
  401. $items["admin/config/modules"] = array(
  402. "title" => "Modules",
  403. "description" => "Manage which modules are enabled for your site",
  404. "page_callback" => "fp_render_form",
  405. "page_arguments" => array("system_modules_form"),
  406. "access_arguments" => array("administer_modules"),
  407. "page_settings" => array(
  408. "page_hide_report_error" => TRUE,
  409. "menu_icon" => fp_get_module_path('system') . "/icons/bricks.png",
  410. "menu_links" => array(
  411. 0 => array(
  412. "text" => "Admin Console",
  413. "path" => "admin-tools/admin",
  414. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  415. ),
  416. ),
  417. ),
  418. "type" => MENU_TYPE_NORMAL_ITEM,
  419. "tab_parent" => "admin-tools/admin",
  420. );
  421. $items["admin/config/clear-menu-cache"] = array(
  422. "title" => "Clear menu cache",
  423. "description" => "Clear and rebuild menus and URLs",
  424. "page_callback" => "system_perform_clear_menu_cache",
  425. "access_arguments" => array("clear_system_cache"),
  426. "type" => MENU_TYPE_NORMAL_ITEM,
  427. "page_settings" => array(
  428. "menu_icon" => fp_get_module_path('system') . "/icons/arrow_refresh.png",
  429. ),
  430. );
  431. $items["admin/config/execute-php"] = array(
  432. "title" => "Execute PHP",
  433. "description" => "Execute arbitrary PHP on your server. Caution: could be dangerous if not understood",
  434. "page_callback" => "fp_render_form",
  435. "page_arguments" => array("system_execute_php_form", "system_settings"),
  436. "access_arguments" => array("execute_php"),
  437. "page_settings" => array(
  438. "menu_icon" => fp_get_module_path('system') . "/icons/page_white_php.png",
  439. "page_hide_report_error" => TRUE,
  440. "menu_links" => array(
  441. 0 => array(
  442. "text" => "Admin Console",
  443. "path" => "admin-tools/admin",
  444. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  445. ),
  446. ),
  447. ),
  448. "type" => MENU_TYPE_NORMAL_ITEM,
  449. "tab_parent" => "admin-tools/admin",
  450. );
  451. return $items;
  452. }
  453. /**
  454. * This page will be shown when the user clicks the "Need Help Logging In?" link on the login page.
  455. */
  456. function system_display_login_help_page() {
  457. //First, are we meant to redirect to a different piece of content? This is configured in the System Settings.
  458. $cid = intval(variable_get("login_help_cid", "0"));
  459. if ($cid > 0) {
  460. fp_goto("content/$cid");
  461. return;
  462. }
  463. // Else, display a generic message here.
  464. $rtn = "";
  465. $rtn .= t("If you need help logging in to FlightPath (eg, you forgot your password or do not have access), contact
  466. the system administrator or your IT department.");
  467. return $rtn;
  468. }
  469. /**
  470. * Used by the menu to determine if the user can access some basic information about the student (like Profile page, etc)
  471. */
  472. function system_can_access_student($student_id = "") {
  473. global $current_student_id, $user;
  474. if ($student_id == "") $student_id = $current_student_id;
  475. // must be logged in first...
  476. if (!user_has_permission("access_logged_in_content")) return FALSE;
  477. if ($student_id == "" || $student_id === 0) return FALSE;
  478. if ($user->id == 1) return TRUE; // the admin user.
  479. // Can the user view ANY advising session?
  480. if (user_has_permission("view_any_advising_session")) return TRUE;
  481. // can the user only see their own advisees, and is this student one of their advisees?
  482. if (user_has_permission("view_advisee_advising_session")) {
  483. // Is the student_id in their list of advisees?
  484. $advisees = advise_get_advisees();
  485. if (in_array($student_id, $advisees)) return TRUE;
  486. }
  487. // Is this user viewing THEIR OWN advising session?
  488. if (user_has_permission("view_own_advising_session")) {
  489. if ($student_id == $user->cwid && ($student_id != "" && $student_id !== 0)) return TRUE;
  490. }
  491. // All else fails, return FALSE
  492. return FALSE;
  493. }
  494. function system_display_disable_login_page($type = "all") {
  495. $rtn = "";
  496. if ($type == "all") {
  497. $rtn .= "<h2>Logins Currently Disabled</h2>
  498. We're sorry, but logins are disabled at this time due to maintenance on FlightPath.
  499. <br><br>Please try again later.
  500. <br><br>
  501. ";
  502. }
  503. if ($type == "student") {
  504. $rtn .= t("We're sorry, but student logins are disabled at this time.");
  505. }
  506. $rtn .= " " . l("Return to login page", "<front>") . "";
  507. return $rtn;
  508. }
  509. function system_execute_php_form() {
  510. $form = array();
  511. $m = 0;
  512. $form["mark" . $m++] = array(
  513. "value" => t("Use this form to execute arbitrary PHP code. <b>DO NOT</b>
  514. type php tags (&lt;php ?&gt;). Be careful! Entering bad code
  515. here can harm your site. Only use if you know what you are doing."),
  516. );
  517. $form["system_execute_php"] = array(
  518. "type" => "textarea",
  519. "label" => t("Enter PHP code here:"),
  520. "value" => variable_get("system_execute_php", ""),
  521. "rows" => 20,
  522. );
  523. return $form;
  524. }
  525. function system_execute_php_form_submit($form, $form_state) {
  526. $code = trim($form_state["values"]["system_execute_php"]);
  527. if ($code == "") return;
  528. if (user_has_permission("execute_php")) { // double-check one more time on this, just in case.
  529. try {
  530. $res = @eval($code);
  531. // Check for errors less than PHP 7.
  532. if ($res === FALSE &&($error = error_get_last())) {
  533. fp_add_message("Error: " . $error["message"] . ". See line: " . $error["line"], "error");
  534. }
  535. }
  536. catch (ParseError $e) {
  537. // Catches PHP 7+ ParseError exceptions...
  538. fp_add_message("Exception detected: " . $e->getMessage() . ". See line: " . $e->getLine(), "error");
  539. }
  540. }
  541. }
  542. /**
  543. * Display a confirmation form before we run the db updates (hook_updates)
  544. *
  545. * @return unknown
  546. */
  547. function system_confirm_db_updates_form() {
  548. $form = array();
  549. $m = 0;
  550. $form["mark" . $m++] = array(
  551. "value" => t("Are you sure you wish to run the database updates?
  552. This will find modules which have been updated, and now need to
  553. make database changes.") . "
  554. <br><br>
  555. " . t("You should back up your entire database first, just in case a problem
  556. occurs!"),
  557. );
  558. $form["submit_btn"] = array(
  559. "type" => "submit",
  560. "spinner" => TRUE,
  561. "value" => t("Continue"),
  562. "prefix" => "<hr>",
  563. "suffix" => "&nbsp; &nbsp; <a href='javascript: history.go(-1);'>" . t("Cancel") . "</a>",
  564. );
  565. $form["mark" . $m++] = array(
  566. "value" => t("Press only once, as this make take several moments to run."),
  567. );
  568. return $form;
  569. }
  570. /**
  571. * Perform the actual hook_update calls here, send the user to a completed page.
  572. *
  573. * @param unknown_type $form
  574. * @param unknown_type $form_state
  575. */
  576. function system_confirm_db_updates_form_submit($form, $form_state) {
  577. // Since this could take a little while, let's use the batch system.
  578. $modules = array();
  579. // We need to find modules whose schema in their .info file
  580. // is different than what's in the database.
  581. $module_dirs = array();
  582. $module_dirs[] = array("start" => "modules", "type" => t("Core"));
  583. $module_dirs[] = array("start" => "custom/modules", "type" => t("Custom"));
  584. // We will also add any directories which begin with an underscore in the custom/modules directory.
  585. // For example: custom/modules/_contrib
  586. // Let's find such directories now.
  587. $dir_files = scandir("custom/modules");
  588. foreach ($dir_files as $file) {
  589. if ($file == '.' || $file == '..') continue;
  590. if (substr($file, 0, 1) == '_' && is_dir("custom/modules/$file")) {
  591. $module_dirs[] = array("start" => "custom/modules/$file", "type" => t("Custom/$file"));
  592. }
  593. }
  594. foreach ($module_dirs as $module_dir) {
  595. $start_dir = $module_dir["start"];
  596. if ($dh = opendir($start_dir)) {
  597. while ($file = readdir($dh)) {
  598. if ($file == "." || $file == "..") continue;
  599. if (is_dir($start_dir . "/" . $file)) {
  600. // Okay, now look inside and see if there is a .info file.
  601. if (file_exists("$start_dir/$file/$file.info")) {
  602. $module = $file;
  603. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  604. // From the info_contents variable, split up and place into an array.
  605. $info_details_array = array();
  606. $lines = explode("\n", $info_contents);
  607. foreach ($lines as $line) {
  608. if (trim($line) == "") continue;
  609. $temp = explode("=", trim($line));
  610. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  611. }
  612. $path = "$start_dir/$file";
  613. $res = db_query("SELECT * FROM modules WHERE path = ? ", $path);
  614. $cur = db_fetch_array($res);
  615. $info_details_array["enabled"] = intval($cur["enabled"]);
  616. // Does this module need to run db updates?
  617. if (@$cur["enabled"] == 1 && @intval($cur["schema"]) != @intval($info_details_array["schema"]) && @$info_details_array["schema"] != "") {
  618. // Add to our list of modules to run in our batch operations.
  619. $modules[] = array(
  620. 'module' => $module,
  621. 'path' => $path,
  622. 'cur_schema' => intval($cur['schema']),
  623. 'schema' => intval($info_details_array['schema']),
  624. );
  625. } // if enabled & schema != db schema
  626. } // if fileexists
  627. }//if isdir(file)
  628. }// while file = readdir()
  629. } // if opendir
  630. } // foreach module dirs as module_dir
  631. // Clear our cache
  632. //fp_clear_cache();
  633. //fp_goto("admin/completed-db-updates");
  634. // Okay, set up the batch....
  635. $batch = array(
  636. "operation" => array("system_perform_db_updates_perform_batch_operation", array($modules)),
  637. "title" => t("Performing Database Updates"),
  638. "progress_message" => "Processing @current of @total...",
  639. "display_percent" => TRUE,
  640. );
  641. $batch["finished_callback"] = array("system_finished_db_updates_finished");
  642. watchdog("admin", "Ran DB updates for modules");
  643. // Set the batch...
  644. batch_set($batch);
  645. }
  646. function system_finished_db_updates_finished($batch) {
  647. // Clear our cache, since menu options might have changed.
  648. fp_clear_cache();
  649. fp_goto("admin/config/modules");
  650. }
  651. /**
  652. * Performs db updates ONE module at a time.
  653. */
  654. function system_perform_db_updates_perform_batch_operation(&$batch, $modules) { // if this is our first time through, let's init our values.
  655. if (!isset($batch["results"]["total"])) {
  656. // Our first time through. Let's start up.
  657. $batch["results"]["total"] = count($modules);
  658. $batch["results"]["current"] = 0;
  659. $batch["results"]["finished"] = FALSE;
  660. }
  661. $t = $batch["results"]["current"];
  662. $module = $modules[$t]['module'];
  663. $path = $modules[$t]['path'];
  664. $cur_schema = $modules[$t]['cur_schema'];
  665. $schema = $modules[$t]['schema'];
  666. // If the module has a .install file, begin by including it.
  667. if (include_module_install($module, $path)) {
  668. // Include the original module file first.
  669. include_module($module, TRUE, $path);
  670. // Now, we can call hook_update, if it exists.
  671. if (function_exists($module . '_update')) {
  672. call_user_func_array($module . '_update', array($cur_schema, $schema));
  673. }
  674. }
  675. // Okay, update the modules table for this module, and set schema to correct version.
  676. $res = db_query("UPDATE modules
  677. SET `schema` = '?'
  678. WHERE path = '?' LIMIT 1 ", $schema, $path);
  679. fp_add_message(t("The module %module has run its DB updates.", array("%module" => $module)));
  680. // Update our values.
  681. $batch["results"]["current"] = $t + 1; // go to next one.
  682. // Have we finished?
  683. if (intval($batch["results"]["current"]) >= intval($batch["results"]["total"])) {
  684. $batch["results"]["finished"] = TRUE;
  685. }
  686. } // system_perform_db_updates_perform_batch_operation
  687. /**
  688. * Once db updates are run, display contents of this page.
  689. *
  690. */
  691. function system_display_completed_db_updates() {
  692. $rtn = "";
  693. $rtn .= t("Database updates have been completed. If you do not see
  694. any errors displayed, it means everything was run correctly.");
  695. $rtn .= "<br><br>
  696. <ul>";
  697. $rtn .= "<li>" . l(t("Return to Admin"), "admin-tools/admin") . "</li>
  698. <li>" . l(t("Return to Modules page"), "admin/config/modules") . "</li>
  699. </ul>";
  700. return $rtn;
  701. }
  702. /**
  703. * This page is displayed to the user once FlightPath has been installed.
  704. */
  705. function system_display_install_finished_page() {
  706. $rtn = "";
  707. // Rebuild one more time
  708. menu_rebuild_cache(FALSE);
  709. fp_show_title(TRUE);
  710. $rtn .= t("Your new installation of FlightPath is now complete.
  711. <br><br>
  712. As a security precaution, you should:
  713. <ul>
  714. <li>change the permissions
  715. on custom/settings.php so that it cannot be read or written to by unauthorized
  716. users.</li>
  717. <li>You should also rename or remove install.php so that web visitors cannot
  718. access it.</li>
  719. </ul>
  720. If you need to re-install FlightPath, delete custom/settings.php, and drop all of the tables
  721. in the database, then re-access install.php.") . "<br><br>";
  722. $rtn .= l(t("Access your new FlightPath site now."), "<front>");
  723. return $rtn;
  724. }
  725. /**
  726. * This is the thank you page you see after submitting the contact form.
  727. */
  728. function system_popup_report_contact_thank_you() {
  729. $rtn = "";
  730. $rtn .= "<p>";
  731. $rtn .= t("Thank you for submitting to the @FlightPath Production Team. We
  732. have received your comment and will review it shortly.", array("@FlightPath" => variable_get("system_name", "FlightPath"))) . "<br><br>";
  733. $rtn .= t("You may now close this window.");
  734. $rtn .= "</p>";
  735. $rtn .= "<p>" . "<a href='javascript:parent.fpCloseLargeIframeDialog();' class='button'>" . t("Close Window") . "</a></p>";
  736. return $rtn;
  737. }
  738. /**
  739. * This is the form which lets users send an email to the FlightPath production
  740. * team,
  741. */
  742. function system_popup_report_contact_form() {
  743. $form = array();
  744. fp_set_title("");
  745. $m = 0;
  746. /*
  747. $form["mark" . $m++] = array(
  748. "value" => fp_render_section_title(t("Contact the @FlightPath Production Team", array("@FlightPath" => variable_get("system_name", "FlightPath")))),
  749. );
  750. */
  751. if (!user_has_permission("access_logged_in_content")) {
  752. $form["mark" . $m++] = array(
  753. "value" => t("We're sorry, but for security reasons you may only access this form
  754. if you are logged in to @FlightPath.", array("@FlightPath" => variable_get("system_name", "FlightPath"))),
  755. );
  756. return $form;
  757. }
  758. $form["mark" . $m++] = array(
  759. "value" => "<p>" . t("If you've noticed an error or have a suggestion, use this
  760. form to contact the @FlightPath Production Team.", array("@FlightPath" => variable_get("system_name", "FlightPath"))) . "</p>",
  761. );
  762. $form["category"] = array(
  763. "type" => "select",
  764. "label" => t("Please select a category"),
  765. "options" => array(
  766. t("Dashboard") => t("Dashboard"),
  767. t("Appointments") => t("Appointments"),
  768. t("Advising") => t("Advising"),
  769. t("Degree plan") => t("Degree plan"),
  770. t("What If?") => t("What If?"),
  771. t("Searching") => t("Searching"),
  772. t("Comments") => t("Comments"),
  773. t("Audit") => t("Audit"),
  774. t("Engagements") => t("Engagements"),
  775. t("Sending/Receiving Text") => t("Sending/Receiving Text"),
  776. t("Reports") => t("Reports/Analytics"),
  777. t("Other") => t("Other"),
  778. ),
  779. );
  780. $form["comment"] = array(
  781. "type" => "textarea",
  782. "rows" => 7,
  783. "label" => t("Comment:"),
  784. );
  785. $form["submit"] = array(
  786. "type" => "submit",
  787. "spinner" => TRUE,
  788. "value" => t("Send email"),
  789. );
  790. $form["#redirect"] = array("path" => "popup-contact-form/thank-you");
  791. return $form;
  792. }
  793. function system_popup_report_contact_form_submit($form, $form_state) {
  794. global $user;
  795. $category = filter_markup($form_state["values"]["category"],'plain');
  796. $comment = filter_markup($form_state["values"]["comment"], 'plain');
  797. $possible_student = filter_markup($_SESSION['last_student_selected'], 'plain');
  798. $user_roles = filter_markup(implode(", ", $user->roles), 'plain');
  799. $datetime = date("Y-m-d H:i:s", convert_time(strtotime("now")));
  800. //$headers = "From: FlightPath-noreply@noreply.com\n";
  801. $subject = t("FLIGHTPATH REPORT CONTACT") . " - $category ";
  802. $msg = "";
  803. $msg .= t("You have received a new report/contact on") . " $datetime.\n";
  804. $msg .= t("Name:") . " $user->f_name $user->l_name ($user->name) CWID: $user->cwid \n" . t("User roles:") . " $user_roles \n\n";
  805. $msg .= t("Category:") . " $category \n";
  806. $msg .= t("Last Student Selected:") . " $possible_student \n";
  807. $msg .= t("Comment:") . " \n $comment \n\n";
  808. $msg .= "------------------------------------------------ \n";
  809. $themd5 = md5($user->name . $user->cwid . $comment . $user_roles . $category);
  810. if ($_SESSION["da_error_report_md5"] != $themd5)
  811. { // Helps stop people from resubmitting over and over again
  812. // (by hitting refresh, or by malicious intent)..
  813. $to = variable_get("contact_email_address", "");
  814. if ($to != "") {
  815. fp_mail($to,$subject,$msg);
  816. }
  817. }
  818. $_SESSION["da_error_report_md5"] = $themd5;
  819. watchdog("admin", "Sent message with popup report contact form: Category: $category; Comment: $comment");
  820. }
  821. /**
  822. * This form is for the school-data, like subject code descriptions, colleges, etc.
  823. *
  824. */
  825. function system_school_data_form($school_id = 0) {
  826. $form = array();
  827. $m = 0;
  828. $school_id = intval($school_id);
  829. $fs = ""; // The field name suffix. We will add this to the end of all of our field names. If this is the default school, leave blank.
  830. if (module_enabled("schools")) {
  831. $school_name = schools_get_school_name_for_id($school_id);
  832. fp_set_title(t("Configure %school school settings", array('%school' => $school_name)));
  833. if ($school_id !== 0) {
  834. $fs = "~~school_" . $school_id;
  835. }
  836. }
  837. $form['school_id'] = array(
  838. 'type' => 'hidden',
  839. 'value' => $school_id,
  840. );
  841. $form["school_initials" . $fs] = array(
  842. "type" => "textfield",
  843. "size" => 20,
  844. "label" => t("School initials:"),
  845. "value" => variable_get_for_school("school_initials", "DEMO", $school_id, TRUE),
  846. "description" => t("Ex: ULM or BPCC"),
  847. );
  848. $form["earliest_catalog_year" . $fs] = array(
  849. "type" => "textfield",
  850. "size" => 20,
  851. "label" => t("Earliest catalog year:"),
  852. "value" => variable_get_for_school("earliest_catalog_year", "2006", $school_id, TRUE),
  853. "description" => t("This is the earliest possible catalog year FlightPath may look
  854. up. Typically, this is the earliest year for which you have
  855. data (ie, when FlightPath went online.
  856. If FlightPath cannot figure out a catalog year to use,
  857. it will default to this one. Ex: 2006"),
  858. );
  859. $form["graduate_level_course_num" . $fs] = array(
  860. "type" => "textfield",
  861. "size" => 20,
  862. "label" => t("Graduate level course num:"),
  863. "value" => variable_get_for_school("graduate_level_course_num", "5000", $school_id, TRUE),
  864. "description" => t("This is the course num which means 'graduate level', meaning
  865. anything above it is considered a graduate level course. Ex: 5000"),
  866. );
  867. $form["hiding_grades_message" . $fs] = array(
  868. "type" => "textarea",
  869. "label" => t("Hiding grades message:"),
  870. "value" => variable_get_for_school("hiding_grades_message", "", $school_id, TRUE),
  871. "description" => t("This message will be displayed when any course on the page
  872. has its bool_hide_grade set to TRUE. If you are not using
  873. this functionality, you can leave this blank."),
  874. );
  875. $form["show_group_titles_on_view" . $fs] = array(
  876. "type" => "select",
  877. "label" => t("Show group titles on View and What If screens?"),
  878. "hide_please_select" => TRUE,
  879. "options" => array("no" => t("No"), "yes" => t("Yes")),
  880. "value" => variable_get_for_school("show_group_titles_on_view", "no", $school_id, TRUE),
  881. "description" => t("If set to Yes, then group titles will be displayed in the View
  882. and What if screens, similar to how they are displayed when printing.
  883. If unsure what to select, select 'No'."),
  884. );
  885. $form['max_allowed_selections_in_what_if' . $fs] = array(
  886. 'type' => 'textfield',
  887. 'label' => t("Maximum number of allowed selections in What If:"),
  888. 'value' => variable_get_for_school('max_allowed_selections_in_what_if', 5, $school_id, TRUE),
  889. 'description' => t("Selecting multiple degrees and options for What If can significantly impact server performance. It is recommended
  890. to limit the number of selections to no more than 5. If you are unsure what to put here, enter '5'."),
  891. );
  892. $form['show_both_undergrad_and_grad_degrees_in_what_if' . $fs] = array(
  893. 'type' => 'select',
  894. 'label' => t("Show both undergraduate and graduate degrees for every student in What If?"),
  895. 'options' => array('no' => t('No (default behavior)'), 'yes' => t('Yes')),
  896. 'hide_please_select' => TRUE,
  897. 'value' => variable_get_for_school('show_both_undergrad_and_grad_degrees_in_what_if', 'no', $school_id, TRUE),
  898. 'description' => t("Normally on the What If selection screen, undergrad students can only select from undergrad degrees, and
  899. graduate students can only select from graduate degrees. However, if this is set to 'Yes', then
  900. students will be able to see and select from any degree in What If. If unsure what to select,
  901. choose 'No'."),
  902. );
  903. $form["show_level_3_on_what_if_selection" . $fs] = array(
  904. "type" => "select",
  905. "label" => t("Show level-3 degree options on What If selection screen?"),
  906. "hide_please_select" => TRUE,
  907. "options" => array("no" => t("No"), "yes" => t("Yes")),
  908. "value" => variable_get_for_school("show_level_3_on_what_if_selection", "yes", $school_id, TRUE),
  909. "description" => t("If set to Yes, then level 3 Track/Options will appear on the What If
  910. selection screen, if a degree is selected with available options.
  911. Setting to 'no' gives behavior more like FlightPath 4.
  912. If unsure what to select, select 'No'."),
  913. );
  914. $form["course_repeat_policy" . $fs] = array(
  915. "type" => "select",
  916. "label" => t("Course repeat policy:"),
  917. "options" => array("most_recent_exclude_previous" => t("most recent, exclude previous attempts"),
  918. "most_recent_do_not_exclude" => t("most recent, do not exclude previous attempts - \"beta\" feature"),
  919. "best_grade_exclude_others" => t("best grade, exclude other attempts - \"beta\" feature")),
  920. "value" => variable_get_for_school("course_repeat_policy", "most_recent_exclude_previous", $school_id, TRUE),
  921. "hide_please_select" => TRUE,
  922. "description" => t("This setting affects the course repeat policy for FlightPath for normal courses (courses which are not allowed to be repeated normally).
  923. <br><b>If you are unsure what to select</b>, choose 'most recent, exclude previous attempts'.
  924. <br>Please see the
  925. <b><a href='http://getflightpath.com/node/1085' target='_blank'>FlightPath documentation</a></b>
  926. on how to set up this field."),
  927. );
  928. $form["what_if_catalog_year_mode" . $fs] = array(
  929. "type" => "select",
  930. "label" => t("What If mode default catalog year:"),
  931. "options" => array("current" => t("Current catalog year only"),
  932. "student" => t("Student catalog year only"),
  933. ),
  934. "value" => variable_get_for_school("what_if_catalog_year_mode", "current", $school_id, TRUE),
  935. "hide_please_select" => TRUE,
  936. "description" => t("What should be the default catalog year that What If pulls degrees from? For some schools,
  937. changing majors means moving to the current catalog year. However, at other schools, students
  938. may remain in their current catalog year when they change majors. If you are unsure what
  939. to select, choose 'Current catalog year only.'"),
  940. );
  941. $form["ignore_courses_from_hour_counts" . $fs] = array(
  942. "type" => "textfield",
  943. "label" => t("Ignore courses from hour counts (CSV):"),
  944. "value" => variable_get_for_school("ignore_courses_from_hour_counts", "", $school_id, TRUE),
  945. "description" => t("List courses, separated by comma,
  946. which should be ignored in hours counts. This helps
  947. remedial courses from being applied to hour counts.
  948. <br><b>These courses will automatically be assigned the requirement type code 'x'.</b>
  949. <br>
  950. Ex: MATH 093, ENGL 090, UNIV 1001"),
  951. );
  952. $form["term_id_structure" . $fs] = array(
  953. "type" => "textarea",
  954. "label" => t("Structure of term ID's:"),
  955. "value" => variable_get_for_school("term_id_structure", "", $school_id, TRUE),
  956. "description" => t("Use this space to define termID structures, one per line.
  957. Please see the
  958. <b><a href='http://getflightpath.com/node/1085' target='_blank'>FlightPath documentation</a></b>
  959. on how to set up this field.") . "
  960. <br>&nbsp; &nbsp; &nbsp; " . t("Like so: Structure, Short Desc, Long Desc, Abbr Desc, Year Adjustment") . "
  961. <br>" . t("Ex:") . "
  962. <br>&nbsp; &nbsp; &nbsp; [Y4]60, Spring, Spring of [Y4], Spr '[Y2], [Y]
  963. <br>&nbsp; &nbsp; &nbsp; [Y4]40, Fall, Fall of [Y4-1], Fall '[Y2-1], [Y-1]",
  964. );
  965. // Let's load the subjects...
  966. $subjects = "";
  967. $query = "SELECT DISTINCT b.subject_id, a.title, a.college FROM draft_courses b LEFT JOIN subjects a
  968. ON (a.subject_id = b.subject_id AND a.school_id = b.school_id)
  969. WHERE exclude = 0
  970. AND b.school_id = ?
  971. ORDER BY b.subject_id
  972. ";
  973. $result = db_query($query, $school_id);
  974. while ($cur = db_fetch_array($result))
  975. {
  976. $title = trim($cur["title"]);
  977. $subject_id = trim($cur["subject_id"]);
  978. $college = trim($cur["college"]);
  979. $subjects .= $subject_id . " ~ " . $college . " ~ " . $title . "\n";
  980. }
  981. $form["subjects" . $fs] = array(
  982. "type" => "textarea",
  983. "label" => t("Subjects:"),
  984. "value" => $subjects,
  985. "rows" => 15,
  986. "description" => t("Enter subjects known to FlightPath (for use
  987. in popups and the Course Search, for example), one per line
  988. in this format:") . "<br>SUBJ ~ COLLEGE ~ Title<br>" . t("For example:") . "
  989. <br>&nbsp; ACCT ~ BA ~ Accounting<br>&nbsp; BIOL ~ AS ~ Biology<br>" . t("Notice
  990. the separator between the code, college, and title is 1 tilde (~). Whatespace is ignored.
  991. <br><b>Important:</b> This field cannot be set up until you have your courses
  992. fully entered. Once that occurs, the course
  993. subjects will automatically appear in this box, where you can then assign the college code
  994. and subject title."),
  995. );
  996. // Load the colleges...
  997. $colleges = "";
  998. $res = db_query("SELECT * FROM colleges WHERE school_id = ? ORDER BY college_code", array($school_id));
  999. while ($cur = db_fetch_array($res)) {
  1000. $colleges .= $cur["college_code"] . " ~ " . $cur["title"] . "\n";
  1001. }
  1002. $form["colleges" . $fs] = array(
  1003. "type" => "textarea",
  1004. "label" => t("Colleges:"),
  1005. "value" => $colleges,
  1006. "description" => t("Enter colleges known to FlightPath, one per line, in this format:
  1007. ") . "<br>COLLEGE_CODE ~ Title<br>" . t("For example:") . "
  1008. <br>&nbsp; AE ~ College of Arts, Science, and Education
  1009. <br>&nbsp; PY ~ College of Pharmacy<br>" . t("Notice
  1010. the separator between the code and title is 1 tilde (~). Whitespace is ignored."),
  1011. );
  1012. // Load the degree_college data....
  1013. $degree_college = "";
  1014. $res = db_query("SELECT DISTINCT(major_code) FROM draft_degrees WHERE school_id = ? ORDER BY major_code", array($school_id));
  1015. while ($cur = db_fetch_array($res)) {
  1016. $major_code = $cur["major_code"];
  1017. // Is there an assigned college already?
  1018. $res2 = db_query("SELECT college_code FROM degree_college WHERE major_code = ? AND school_id = ? ", $major_code, $school_id);
  1019. $cur2 = db_fetch_array($res2);
  1020. $college_code = $cur2["college_code"];
  1021. $degree_college .= $major_code . " ~ " . $college_code . "\n";
  1022. }
  1023. $form["degree_college" . $fs] = array(
  1024. "type" => "textarea",
  1025. "label" => t("Degree Colleges:"),
  1026. "value" => $degree_college,
  1027. "rows" => 15,
  1028. "description" => t("Enter the degree's college, one per line, in this format:
  1029. ") . "<br>MAJOR_CODE ~ COLLEGE_CODE<br>" . t("For example:") . "
  1030. <br>&nbsp; ACCT ~ AE
  1031. <br>&nbsp; BUSN ~ SB<br>" . t("Notice
  1032. the separator between the codes is 1 tilde (~). Whitespace is ignored.
  1033. <br><b>Important:</b> This field cannot be set up until you have your degrees
  1034. entered. Once that occurs, the degree major codes
  1035. will automatically appear in this box, where you can then assign the college code.
  1036. "),
  1037. );
  1038. $form['departments' . $fs] = array(
  1039. "type" => 'textarea',
  1040. 'label' => t("Departments:"),
  1041. 'value' => variable_get_for_school('departments', '', $school_id, TRUE),
  1042. 'rows' => 15,
  1043. 'description' => t("Enter each department, one per line, in this format:
  1044. <br>DEPT_CODE ~ Department Name
  1045. <br>
  1046. For example:
  1047. <br> &nbsp; FINAID ~ Financial Aid
  1048. <br> &nbsp; REGST ~ Registrar
  1049. <br><b>Important:</b> The DEPT_CODE must be <strong>unique</strong> and contain only
  1050. letters, numbers, and underscores. The Department Name must not contain any tildes (~) or line breaks, and should be relatively short.
  1051. <br>The separator between the DEPT_CODE and the Department Name is a single tilde (~)."),
  1052. );
  1053. // How many decimal places allowed in substitutions?
  1054. $form["sub_hours_decimals_allowed" . $fs] = array(
  1055. "type" => "select",
  1056. "label" => t("Substitution hours decimal places allowed:"),
  1057. "options" => array(1 => t("1 (ex: 1.1 hrs)"), 2 => t("2 (ex: 1.15 hrs)"), 3 => t("3 (ex: 1.155 hrs)"), 4 => t("4 (ex: 1.1556 hrs)")),
  1058. "value" => variable_get_for_school("sub_hours_decimals_allowed", 2, $school_id, TRUE),
  1059. "no_please_select" => TRUE,
  1060. "description" => t("For hours with decimals (like 2.25 hours), how many numbers
  1061. after the decimal place will be allowed? Affects users performing
  1062. substitutions. For example, if you select \"2\" here, then
  1063. a value of 1.2555 will be rejected, and the user will be asked to re-enter.
  1064. 1.25, would be accepted, since it has 2 decimal places.
  1065. <br>If you are unsure what to select, set to 2."),
  1066. );
  1067. // Auto-correct course titles?
  1068. $form["autocapitalize_course_titles" . $fs] = array(
  1069. "type" => "select",
  1070. "label" => t("Auto-capitalize course titles?"),
  1071. "options" => array("yes" => "Yes", "no" => "No"),
  1072. "hide_please_select" => TRUE,
  1073. "value" => variable_get_for_school("autocapitalize_course_titles", "yes", $school_id, TRUE),
  1074. "description" => t("If set to yes, course titles in FlightPath will be run through a capitalization
  1075. filter, so that 'INTRO TO ACCOUNTING' becomes 'Intro to Accounting'.
  1076. Generally, this makes the course names more attractive, but it can
  1077. incorrectly capitalize acronyms and initials. Disable if you would like
  1078. complete control over capitalization.
  1079. <br>If unsure, set to Yes."),
  1080. );
  1081. // Auto-correct institution names?
  1082. $form["autocapitalize_institution_names" . $fs] = array(
  1083. "type" => "select",
  1084. "label" => t("Auto-capitalize institution names?"),
  1085. "options" => array("yes" => "Yes", "no" => "No"),
  1086. "hide_please_select" => TRUE,
  1087. "value" => variable_get_for_school("autocapitalize_institution_names", "yes", $school_id, TRUE),
  1088. "description" => t("If set to yes, transfer institution names in
  1089. FlightPath will be run through a capitalization
  1090. filter, so that 'UNIVERSITY OF LOUISIANA AT MONROE'
  1091. becomes 'University of Louisiana at Monroe'.
  1092. Like the course title setting above, this is to make
  1093. inconsistent or unattractive capitalization prettier.
  1094. Disable if you would like
  1095. complete control over capitalization.
  1096. <br>If unsure, set to Yes."),
  1097. );
  1098. // Only allow ghost subs for fellow ghost hours?
  1099. $form["restrict_ghost_subs_to_ghost_hours" . $fs] = array(
  1100. "type" => "select",
  1101. "label" => t("Restrict ghost substitutions to courses with zero hours only?"),
  1102. "options" => array("yes" => "Yes", "no" => "No"),
  1103. "hide_please_select" => TRUE,
  1104. "value" => variable_get_for_school("restrict_ghost_subs_to_ghost_hours", "yes", $school_id, TRUE),
  1105. "description" => t("If set to yes, courses with \"ghost\" hours may only be
  1106. substituted for other courses with \"ghost\" hours. What this
  1107. means is that if a course is worth zero hours, it may only be
  1108. subbed for a requirement worth zero hours, and it will not appear
  1109. as an option for substitutions of courses worth more than zero hours.
  1110. This will not affect old subs; only new ones.
  1111. <br>If unsure, set to Yes."),
  1112. );
  1113. $form["initial_student_course_sort_policy" . $fs] = array(
  1114. "type" => "select",
  1115. "label" => t("Initial student course sort policy:"),
  1116. "options" => array("alpha" => "Alphabetical sort [default]", "grade" => "Best grade first"),
  1117. "hide_please_select" => TRUE,
  1118. "value" => variable_get_for_school("initial_student_course_sort_policy", "alpha", $school_id, TRUE),
  1119. "description" => t("Student courses are sorted more than once as they are evaluated by FlightPath.
  1120. By default, they are sorted alphabetically first. If you change this to best-grade-first,
  1121. courses will be initally sorted according to the grade they earned, in the order defined in 'Grade order CSV' below.
  1122. Any student grades not defined below will be considered the lowest possible grade."),
  1123. );
  1124. $form["grade_order" . $fs] = array(
  1125. "type" => "textfield",
  1126. "label" => t("Grade order (CSV):"),
  1127. "value" => variable_get_for_school("grade_order", "E,AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I", $school_id, TRUE),
  1128. "description" => t("List all possible grades, separated by comma, from highest to lowest. This is
  1129. used if you select 'Best Grade first' order above, but also is used in determining
  1130. if a course fulfills a minimum grade requirement.
  1131. <br>Ex: AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I"),
  1132. );
  1133. $form["retake_grades" . $fs] = array(
  1134. "type" => "textfield",
  1135. "label" => t("Retake grades (CSV):"),
  1136. "value" => variable_get_for_school("retake_grades", "F,W,I", $school_id, TRUE),
  1137. "description" => t("List grades, separated by comma, which means 'the student must
  1138. retake this course. They did not earn credit.' Ex: F,W,I"),
  1139. );
  1140. $form["withdrew_grades" . $fs] = array(
  1141. "type" => "textfield",
  1142. "label" => t("Withdrew grades (CSV):"),
  1143. "value" => variable_get_for_school("withdrew_grades", "W", $school_id, TRUE),
  1144. "description" => t("List grades, separated by comma, which means 'the student withdrew
  1145. from this course. They did not earn credit.' Ex: W,WD,WF. If not sure
  1146. what to enter here, just enter 'W'."),
  1147. );
  1148. $form["enrolled_grades" . $fs] = array(
  1149. "type" => "textfield",
  1150. "label" => t("Enrolled grades (CSV):"),
  1151. "value" => variable_get_for_school("enrolled_grades", "E", $school_id, TRUE),
  1152. "description" => t("List grades, separated by comma, which means 'the student is
  1153. currently enrolled in this course.' Ex: E,AMID,BMID "),
  1154. );
  1155. $form["minimum_substitutable_grade" . $fs] = array(
  1156. "type" => "textfield",
  1157. "size" => 3,
  1158. "label" => t("Minimum substitutable grade:"),
  1159. "value" => variable_get_for_school("minimum_substitutable_grade", "D", $school_id, TRUE),
  1160. "description" => t("Enter a grade which is the minimum grade a student must have earned
  1161. for the course to be allowed in a substitution. This will affect
  1162. new substitutions, not old ones. If unsure, enter D."),
  1163. );
  1164. $form["group_min_grades" . $fs] = array(
  1165. "type" => "textfield",
  1166. "label" => t("Group requirement min grades (CSV):"),
  1167. "value" => variable_get_for_school("group_min_grades", "D,C,B,A", $school_id, TRUE),
  1168. "description" => t("List grades, separated by comma, which should appear in the min grade pulldown when setting a group requirement
  1169. in a degree (this also sets the order in which they will appear). If unsure what to enter, use: D,C,B,A"),
  1170. );
  1171. $form["calculate_cumulative_hours_and_gpa" . $fs] = array(
  1172. "label" => t("Calculate student cumulative hours and GPA?"),
  1173. "type" => "select",
  1174. "hide_please_select" => TRUE,
  1175. "options" => array("no" => t("No"), "yes" => t("Yes")),
  1176. "value" => variable_get_for_school("calculate_cumulative_hours_and_gpa", 'no', $school_id, TRUE),
  1177. "description" => t("If set to Yes, student cumulative hours and GPA will not be read from the
  1178. 'students' database table, but will instead be calculated on the fly
  1179. each time a student is loaded. If unsure what to do, set to Yes."),
  1180. );
  1181. $form['numeric_to_letter_grades' . $fs] = array(
  1182. "label" => t("Numeric to Letter Grades:"),
  1183. "type" => "textarea",
  1184. "value" => variable_get_for_school("numeric_to_letter_grades", "", $school_id, TRUE),
  1185. "description" => t("If your school supports numeric grades in your SIS (ex: 91, 80, 65, etc), then they must be converted to
  1186. letter grades (A, B, D, etc) for FlightPath. Use this box to define what numeric range translates to which
  1187. letter grade. If you are unsure what to enter here, or if your school does not use numeric grades, leave this blank.
  1188. <br>Enter in the form of: MIN ~ MAX ~ GRADE
  1189. <br>Ex:
  1190. <br>&nbsp; 0 ~ 59.99 ~ F
  1191. <br>&nbsp; 60 ~ 69.99 ~ D
  1192. <br>&nbsp; 70 ~ 79.99 ~ C
  1193. <br>&nbsp; 80 ~ 89.99 ~ B
  1194. <br>&nbsp; 90 ~ 100.99 ~ A
  1195. <br>&nbsp; 101 ~ 999 ~ A &nbsp; &nbsp; <em>(In case scores above 100 are possible)</em>"),
  1196. );
  1197. $form["quality_points_grades" . $fs] = array(
  1198. "label" => t("Quality points and grades:"),
  1199. "type" => "textarea",
  1200. "value" => variable_get_for_school("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0", $school_id, TRUE),
  1201. "description" => t("Enter a grade, and how many quality points it is worth, separated by
  1202. tilde (~), one per line. You must include every grade which should count
  1203. for (or against) a GPA calculation, even if it is worth zero points. For example,
  1204. if an 'F' should cause a GPA to lower (which normally it would), it should be
  1205. listed here. If a 'W' grade should simply be ignored, then DO NOT list it here.
  1206. Any grade you do not list here will be IGNORED in all GPA calculations.") . "
  1207. <br>
  1208. Ex:<blockquote style='margin-top:0; font-family: Courier New, monospace;'>
  1209. A ~ 4<br>B ~ 3<br>C ~ 2<br>D ~ 1<br>F ~ 0<br>I ~ 0</blockquote>",
  1210. );
  1211. $form["requirement_types" . $fs] = array(
  1212. "label" => t("Requirement types and codes:"),
  1213. "type" => "textarea",
  1214. "value" => variable_get_for_school("requirement_types", "g ~ General Requirements\nc ~ Core Requirements\ne ~ Electives\nm ~ Major Requirements\ns ~ Supporting Requirements\nx ~ Additional Requirements", $school_id, TRUE),
  1215. "description" => t("Enter requirement type codes and descriptions, separated by a tilde (~), one
  1216. per line. <b>You may not use the code 'u'</b> as that is reserved in FlightPath.
  1217. <b>You should define what 'x' means</b>, but be aware that the code 'x' will always
  1218. designate a course whose hours should be ignored from GPA calculations.
  1219. <b>You should define what 'm' means</b>, as this is the default code applied
  1220. to a requirement if one is not entered. <b>You should define what
  1221. 'e' means</b>, as this is also the code given to courses whose types we cannot
  1222. figure out, perhaps because of a typo or intentionally. Ex: Electives.
  1223. This list also defines the order in which they will appear on screen in
  1224. Type View. By convention, codes should be lower case single-letters.") . "
  1225. <br>Ex:
  1226. <div style='padding-left: 20px; font-family: Courier New, monospace'>
  1227. g ~ General Requirements<br>
  1228. c ~ Core Requirements<br>
  1229. e ~ Electives<br>
  1230. m ~ Major Requirements<br>
  1231. s ~ Supporting Requirements<br>
  1232. x ~ Additional Requirements
  1233. </div>
  1234. Please see the
  1235. <b><a href='http://getflightpath.com/node/1085' target='_blank'>FlightPath documentation</a></b>
  1236. for more information on how to set up this field.
  1237. ",
  1238. );
  1239. // Check to make sure the gd extension is loaded, since that will be required to display
  1240. // the pie charts...
  1241. if (!extension_loaded('gd') && !extension_loaded('gd2')) {
  1242. $form["mark_no_gd_library"] = array(
  1243. "value" => "<p class='hypo'><b>" . t("Note: it appears your web server does not have the 'GD' library
  1244. enabled for PHP. This is required to make the pie charts show up
  1245. correctly. Contact your server administrator about enabling the 'GD'
  1246. library.") . "</b></p>",
  1247. );
  1248. }
  1249. $form["pie_chart_config" . $fs] = array(
  1250. "label" => t("Pie chart configuration:"),
  1251. "type" => "textarea",
  1252. "value" => variable_get_for_school("pie_chart_config", "c ~ Core Requirements\nm ~ Major Requirements\ndegree ~ Degree Progress", $school_id, TRUE),
  1253. "description" => t("Enter configuration data for the pie charts which graph a student's progress
  1254. through their degree. Enter the requirement type code, pie chart label, and optional
  1255. colors separated by tilde (~). Requirement types not found for a student will be skipped
  1256. and the chart will not be drawn. <b>Enter 'degree' for total progress.</b>") . "
  1257. <br>Ex: CODE ~ LABEL ~ [optional: UNFINISHED COLOR ~ PROGRESS COLOR ]
  1258. <div style='padding-left: 20px; font-family: Courier New, monospace'>
  1259. c ~ Core Requirements ~ 660000 ~ FFCC33<br>
  1260. m ~ Major Requirements ~ 660000 ~ 93D18B<br>
  1261. degree ~ Degree Progress ~ 660000 ~ 5B63A5
  1262. </div>",
  1263. );
  1264. $form["pie_chart_gpa" . $fs] = array(
  1265. "label" => t("Should pie charts show GPAs?"),
  1266. "type" => "select",
  1267. "options" => array("no" => "No", "yes" => "Yes"),
  1268. "value" => variable_get_for_school("pie_chart_gpa", "no", $school_id, TRUE),
  1269. "hide_please_select" => TRUE,
  1270. "description" => t("If set to 'Yes', the GPA will be displayed below each pie chart on the View and What If screens.
  1271. If unsure what to select, choose 'no'."),
  1272. );
  1273. $form["developmentals_title" . $fs] = array(
  1274. "label" => t("Developmentals semester block title:"),
  1275. "type" => "textfield",
  1276. "value" => variable_get_for_school("developmentals_title", t("Developmental Requirements", $school_id)),
  1277. "description" => t("This is the title of the Developmental Requirements semester block,
  1278. which appears on a student's degree plan, near the bottom, when they
  1279. have remedial courses they are required to take. If you are
  1280. unsure what to enter, use 'Developmental Requirements'."),
  1281. );
  1282. $form["developmentals_notice" . $fs] = array(
  1283. "label" => t("Developmentals notice text:"),
  1284. "type" => "textarea",
  1285. "value" => variable_get_for_school("developmentals_notice", t("According to our records, you are required to complete the course(s) listed above. For some transfer students, your record may not be complete. If you have any questions, please ask your advisor."), $school_id, TRUE),
  1286. "description" => t("The text you enter here will be displayed below the Developmentals semester
  1287. block, explaining to the student what these courses are. For example:
  1288. 'According to our records, you are required to complete the course(s) listed
  1289. above.'"),
  1290. );
  1291. $form["graduate_level_codes" . $fs] = array(
  1292. "type" => "textfield",
  1293. "label" => t("Graduate level codes (CSV):"),
  1294. "value" => variable_get_for_school("graduate_level_codes", "GR", $school_id, TRUE),
  1295. "description" => t("List level codes, separated by comma, for both students, courses, and degrees, which should be considered at the Graduate level. If you do not need
  1296. to distinguish between graduate and undergraduate credit, leave this field blank.<br>If unsure, set to GR."),
  1297. );
  1298. $form["disallow_graduate_credits" . $fs] = array(
  1299. "type" => "select",
  1300. "label" => t("Disallow automatic use of graduate credits?"),
  1301. "options" => array("yes" => "Yes", "no" => "No"),
  1302. "hide_please_select" => TRUE,
  1303. "value" => variable_get_for_school("disallow_graduate_credits", "yes", $school_id, TRUE),
  1304. "description" => t("If set to yes, FlightPath will not automatically use graduate credits (based on the level code the student's credit
  1305. is given in the database) to populate elective groups or on the degree plan. They may still be substituted using the
  1306. substitution system however. In order for this setting to work, the 'Graduate course level codes' field must be set above.
  1307. <br>If unsure, set to Yes."),
  1308. );
  1309. $form["display_graduate_credits_block" . $fs] = array(
  1310. "type" => "select",
  1311. "label" => t("Display graduate credits in their own semester block?"),
  1312. "options" => array("yes" => "Yes", "no" => "No"),
  1313. "hide_please_select" => TRUE,
  1314. "value" => variable_get_for_school("display_graduate_credits_block", "yes", $school_id, TRUE),
  1315. "description" => t("If set to yes, FlightPath will display graduate credits in their own block, and NOT in Excess credits. The graduate block details
  1316. are set below.
  1317. <br>If unsure, set to Yes."),
  1318. );
  1319. $form["graduate_credits_block_title" . $fs] = array(
  1320. "label" => t("Graduate Credits block title:"),
  1321. "type" => "textfield",
  1322. "value" => variable_get_for_school("graduate_credits_block_title", t("Graduate Credits"), $school_id, TRUE),
  1323. "description" => t("This is the title of the Graduate Credits semester block (setting above),
  1324. which appears on a student's degree plan, near the bottom, when they
  1325. have graduate credits in their history (based on the credit's level code). If you are
  1326. unsure what to enter, use 'Graduate Credits'."),
  1327. );
  1328. $form["graduate_credits_block_notice" . $fs] = array(
  1329. "label" => t("Graduate Credits block notice text:"),
  1330. "type" => "textarea",
  1331. "value" => variable_get_for_school("graduate_credits_block_notice", t("These courses may not be used for undergraduate credit."), $school_id, TRUE),
  1332. "description" => t("The text you enter here will be displayed below the Gradute Credits semester
  1333. block, explaining to the student what these courses are. For example:
  1334. 'These courses may not be used for undergraduate credit.'"),
  1335. );
  1336. $form["exclude_majors_from_appears_in_counts" . $fs] = array(
  1337. "label" => t("Exclude major codes from \"appears in\" counts (CSV):"),
  1338. "type" => "textfield",
  1339. "maxlength" => 1000,
  1340. "value" => variable_get_for_school("exclude_majors_from_appears_in_counts", "", $school_id, TRUE),
  1341. "description" => t('When a course appears in more than one degree, it is given an extra CSS class
  1342. denoting that. This fields lets you enter major codes for degrees, separated by commas,
  1343. for any degrees you do not wish to be counted toward the "appears in" counts.
  1344. <br>&nbsp; &nbsp; Ex: UGELEC, ACCTB
  1345. <br>If you are unsure what to enter, leave this field blank.'),
  1346. );
  1347. $form["group_full_at_min_hours" . $fs] = array(
  1348. "label" => t("Groups should be considered 'full' when min hours are met or exceeded?"),
  1349. "type" => "select",
  1350. "options" => array("yes" => "Yes", "no" => "No"),
  1351. "value" => variable_get_for_school("group_full_at_min_hours", "yes", $school_id, TRUE),
  1352. "hide_please_select" => TRUE,
  1353. "description" => t("If a group has been added to a degree plan with 'min hours', should FlightPath consider the group
  1354. 'full', and stop assigning courses to it, once the assigned courses meets or goes over the min hours value,
  1355. even if the max hours have not been fulfilled? This
  1356. only affects groups which have been added to a degree plan with min hours set. Ex: 3-6 hours.
  1357. If you are unsure what to enter, select 'Yes'"),
  1358. );
  1359. $form["remove_advised_when_course_taken" . $fs] = array(
  1360. "label" => t("Remove an advised course when a student enrolls in it (or completes it), for the same term?"),
  1361. "type" => "select",
  1362. "options" => array("yes" => "Yes", "no" => "No"),
  1363. "value" => variable_get_for_school("remove_advised_when_course_taken", "no", $school_id, TRUE),
  1364. "hide_please_select" => TRUE,
  1365. "description" => t("If a student has been advised into a course, and then enrolls in that course before the next
  1366. advising term begins, should the advised course (and checkbox) be removed? This would also affect
  1367. courses the student completes within that term. The default is 'No', meaning advising checkboxes in View
  1368. will continue to show, even if the student has enrolled or completes the course that term. The checkboxes
  1369. will disappear when the advising term is no longer available for advising.
  1370. Select 'Yes' if you wish to have FlightPath hide advising checkboxes on the View screen when a student
  1371. is enrolled or completes a course within the same advising term. If you are unsure what to enter, select 'No'."),
  1372. );
  1373. $form["prevent_course_assignment_to_both_degree_and_track" . $fs] = array(
  1374. "label" => t("Prevent a course assignment to both a degree and its track(s)?"),
  1375. "type" => "select",
  1376. "options" => array("yes" => "Yes", "no" => "No"),
  1377. "value" => variable_get_for_school("prevent_course_assignment_to_both_degree_and_track", "yes", $school_id, TRUE),
  1378. "hide_please_select" => TRUE,
  1379. "description" => t("If set to 'Yes' (default), then FlightPath will not allow the same course to be assigned to both a Level-1 degree
  1380. and its tracks. For example, if a student completes ENGL 101, and it can be assigned to the major COMPSCI, then
  1381. it cannot also be assigned to the track COMPSCI|_OPT1. If you are unsure what to select, leave this set to 'Yes'."),
  1382. );
  1383. $form["group_list_course_show_repeat_information" . $fs] = array(
  1384. "label" => t("Display 'Repeat Information' for a course in a group's course list?"),
  1385. "type" => "select",
  1386. "options" => array("yes" => "Yes", "no" => "No"),
  1387. "value" => variable_get_for_school("group_list_course_show_repeat_information", "yes", $school_id, TRUE),
  1388. "hide_please_select" => TRUE,
  1389. "description" => t("If set to 'Yes' (default), FlightPath will how many times a groups may be repeated, when viewing a list
  1390. of a Group's courses in a popup. If set to 'No', repeat information will not be displayed, and instead
  1391. the course's normal hour information is displayed. If you
  1392. are unsure what to select, leave this set to 'Yes'."),
  1393. );
  1394. $form["degree_requirement_sort_policy" . $fs] = array(
  1395. "type" => "select",
  1396. "label" => t("Degree requirement sort policy:"),
  1397. "options" => array("alpha" => "Alphabetical sort (default)", "database" => "As entered in database [beta]"),
  1398. "hide_please_select" => TRUE,
  1399. "value" => variable_get_for_school("degree_requirement_sort_policy", "alpha", $school_id, TRUE),
  1400. "description" => t("How should degree course requirements appear to the end user? By default, they will be sorted into alphabetical order.
  1401. However, if you wish them to appear in the order the were entered on the Edit Degree form, select 'As entered...'.
  1402. <br>If unsure, select 'Alphabetical sort'."),
  1403. );
  1404. $form["group_requirement_sort_policy" . $fs] = array(
  1405. "type" => "select",
  1406. "label" => t("Group requirement sort policy:"),
  1407. "options" => array("alpha" => "Alphabetical sort (default)", "database" => "As entered in database [beta]"),
  1408. "hide_please_select" => TRUE,
  1409. "value" => variable_get_for_school("group_requirement_sort_policy", "alpha", $school_id, TRUE),
  1410. "description" => t("How should group course requirements appear to the end user in the popup dialog window? By default, they will be sorted into alphabetical order.
  1411. However, if you wish them to appear in the order the were entered on the Edit Group form, select 'As entered...'.
  1412. <br>If unsure, select 'Alphabetical sort'."),
  1413. );
  1414. return $form;
  1415. }
  1416. /**
  1417. * Uses the "exclude_majors...." setting, but converts them into an array of degree_ids.
  1418. */
  1419. function system_get_exclude_degree_ids_from_appears_in_counts($school_id) {
  1420. $rtn = array();
  1421. // Have we already cached this for this page load?
  1422. if (isset($GLOBALS["exclude_degree_ids_from_appears_in_counts"][$school_id])) {
  1423. return $GLOBALS["exclude_degree_ids_from_appears_in_counts"][$school_id];
  1424. }
  1425. $db = get_global_database_handler();
  1426. $majors = csv_to_array(variable_get_for_school("exclude_majors_from_appears_in_counts", "", $school_id));
  1427. foreach ($majors as $major_code) {
  1428. $rtn = array_merge($rtn, $db->get_degree_ids($major_code));
  1429. }
  1430. $GLOBALS["exclude_degree_ids_from_appears_in_counts"][$school_id] = $rtn; // cache for next time.
  1431. return $rtn;
  1432. } //system_get_exclude_degree_ids_from_appears_in_counts
  1433. /**
  1434. * Validate handler for the school_data_form.
  1435. *
  1436. * Most of our data can be saved as simple system_settings, but for the others,
  1437. * we want to save them to special tables, then remove them from the form_state so
  1438. * they don't get saved to the variables table, taking up a lot of space.
  1439. *
  1440. * @param unknown_type $form
  1441. * @param unknown_type $form_state
  1442. */
  1443. function system_school_data_form_validate($form, &$form_state) {
  1444. $school_id = intval($form_state['values']['school_id']);
  1445. $fs = "";
  1446. if ($school_id !== 0) {
  1447. $fs = "~~school_" . $school_id;
  1448. }
  1449. // Subjects...
  1450. db_query("DELETE FROM subjects WHERE school_id = ?", $school_id);
  1451. $subjects = trim($form_state["values"]["subjects" . $fs]);
  1452. $lines = explode("\n", $subjects);
  1453. foreach ($lines as $line) {
  1454. $temp = explode("~", $line);
  1455. db_query("INSERT INTO subjects (subject_id, college, title, school_id)
  1456. VALUES (?, ?, ?, ?) ", strtoupper(trim($temp[0])), strtoupper(trim($temp[1])), trim($temp[2]), $school_id);
  1457. }
  1458. // Remove the data from our form_state, so it isn't saved twice
  1459. unset($form_state["values"]["subjects" . $fs]);
  1460. // Colleges...
  1461. db_query("DELETE FROM colleges WHERE school_id = ?", $school_id);
  1462. $contents = trim($form_state["values"]["colleges" . $fs]);
  1463. $lines = explode("\n", $contents);
  1464. foreach ($lines as $line) {
  1465. $temp = explode("~", $line);
  1466. db_query("INSERT INTO colleges (college_code, title, school_id)
  1467. VALUES (?, ?, ?) ", strtoupper(trim($temp[0])), trim($temp[1]), $school_id);
  1468. }
  1469. // Remove the data from our form_state, so it isn't saved twice
  1470. unset($form_state["values"]["colleges" . $fs]);
  1471. // Degree College...
  1472. db_query("DELETE FROM degree_college WHERE school_id = ?", $school_id);
  1473. $contents = trim($form_state["values"]["degree_college" . $fs]);
  1474. $lines = explode("\n", $contents);
  1475. foreach ($lines as $line) {
  1476. $temp = explode("~", $line);
  1477. db_query("INSERT INTO degree_college (major_code, college_code, school_id)
  1478. VALUES (?, ?, ?) ", strtoupper(trim($temp[0])), strtoupper(trim($temp[1])), $school_id);
  1479. }
  1480. // Remove the data from our form_state, so it isn't saved twice
  1481. unset($form_state["values"]["degree_college" . $fs]);
  1482. watchdog("system", "Updated school settings (school_id: $school_id)");
  1483. }
  1484. /**
  1485. * Returns back an array (suitable for FAPI) of the available themes in the system.
  1486. */
  1487. function system_get_available_themes() {
  1488. $rtn = array();
  1489. // First, search for themes in our core folder. Themes must have a .info file which matches
  1490. // their folder name, just like modules.
  1491. $theme_dirs = array();
  1492. $theme_dirs[] = array("start" => "themes", "type" => t("Core"));
  1493. $theme_dirs[] = array("start" => "custom/themes", "type" => t("Custom"));
  1494. foreach ($theme_dirs as $theme_dir) {
  1495. $start_dir = $theme_dir["start"];
  1496. $type_dir = $theme_dir['type'];
  1497. if ($dh = @opendir($start_dir)) {
  1498. $dir_files = scandir($start_dir);
  1499. foreach ($dir_files as $file) {
  1500. if ($file == "." || $file == "..") continue;
  1501. if (is_dir($start_dir . "/" . $file)) {
  1502. // Okay, now look inside and see if there is a .info file.
  1503. if (file_exists("$start_dir/$file/$file.info")) {
  1504. $theme = $file;
  1505. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  1506. // From the info_contents variable, split up and place into an array.
  1507. $info_details_array = array("name" => t("Name Not Set. Configure theme's .info file."), "path" => "", "module" => "",
  1508. "schema" => "", "core" => "", "description" => "",
  1509. "requires" => "", "version" => "",
  1510. "required" => "", );
  1511. $lines = explode("\n", $info_contents);
  1512. foreach ($lines as $line) {
  1513. if (trim($line) == "") continue;
  1514. $temp = explode("=", trim($line));
  1515. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  1516. }
  1517. $path = "$start_dir/$file";
  1518. $rtn[$path] = $info_details_array['name'] . "<div style='font-size: 0.8em; font-style: italic; padding-left: 40px;'>{$info_details_array['description']}
  1519. <br>(Type: $type_dir &nbsp; &nbsp; Location: $path)</div>";
  1520. } // if file_exists
  1521. } //if is_dir
  1522. } //foreach dir_files as $file
  1523. } // if we can opendir
  1524. } // foreach theme_dirs as theme_dir
  1525. return $rtn;
  1526. }
  1527. /**
  1528. * Returns the "whitelist" or "allow list" (from system settings) as an array. If empty, it will return FALSE
  1529. */
  1530. function system_get_user_whitelist() {
  1531. $rtn = array();
  1532. $list = trim(variable_get('user_whitelist', ''));
  1533. if (!$list) return FALSE;
  1534. $lines = explode("\n", $list);
  1535. foreach ($lines as $line) {
  1536. $line = trim($line);
  1537. if ($line == "") continue;
  1538. // If the first char is a # then its a comment, skip it.
  1539. if (substr($line, 0, 1) == '#') continue;
  1540. // Otherwise, we can add to our rtn array.
  1541. $rtn[] = $line;
  1542. // To make sure we catch all occurances, also force lower-case (for emails)
  1543. $rtn[] = strtolower($line);
  1544. } // foreach
  1545. if (count($rtn) == 0) return FALSE;
  1546. return $rtn;
  1547. }
  1548. /**
  1549. * This is the "system settings" form.
  1550. */
  1551. function system_settings_form() {
  1552. $form = array();
  1553. $m = 0;
  1554. $form["mark" . $m++] = array(
  1555. "value" => t("Use this form to alter the various system settings in FlightPath.
  1556. Before making changes, it is always good policy to first back up your database."),
  1557. );
  1558. $form["mark" . $m++] = array(
  1559. "value" => "<p><div style='font-size:0.8em;'>" . t("Your site requires a cron job in order to perform routine tasks. This
  1560. is accomplished by having your server access the following URL every so often
  1561. (like once an hour):") . "<br>&nbsp; &nbsp; <i>" . $GLOBALS["fp_system_settings"]["base_url"] . "/cron.php?t=" . $GLOBALS["fp_system_settings"]["cron_security_token"] . "</i>
  1562. <br>" . t("Example linux cron command:") . "&nbsp; <i>wget -O - -q -t 1 http://ABOVE_URL</i></div></p>",
  1563. );
  1564. $form["maintenance_mode"] = array(
  1565. "label" => t("Set maintenance mode?"),
  1566. "type" => "checkbox",
  1567. "value" => variable_get("maintenance_mode", FALSE),
  1568. "description" => t("If checked, a message will display on every page stating
  1569. that the system is currently undergoing routine maintenance."),
  1570. );
  1571. $form["disable_login_except_admin"] = array(
  1572. "type" => "select",
  1573. "label" => t("Disable all new logins (except admin user)?"),
  1574. "hide_please_select" => TRUE,
  1575. "options" => array("no" => t("No"), "yes" => t("Yes")),
  1576. "value" => variable_get('disable_login_except_admin', 'no'),
  1577. "description" => t("If set to Yes, then when normal users attempt to log in, they will be
  1578. sent back to the login page, with a message displayed explaning that
  1579. logins are disabled. Admin will still be able to log in. This
  1580. is useful when trying to perform maintenance on FlightPath. If unsure
  1581. what to select, select 'No'."),
  1582. );
  1583. $form["disable_student_logins"] = array(
  1584. "type" => "select",
  1585. "label" => t("Disable all new student logins?"),
  1586. "hide_please_select" => TRUE,
  1587. "options" => array("no" => t("No"), "yes" => t("Yes")),
  1588. "value" => variable_get('disable_student_logins', 'no'),
  1589. "description" => t("If set to Yes, then when student users (not specified in the whitelist below) attempt to log in, they will be
  1590. sent back to the login page, with a message displayed explaning that
  1591. student logins are disabled. Admin and faculty/staff will still be able to log in.
  1592. If unsure what to select, select 'No'."),
  1593. );
  1594. $form["user_whitelist"] = array(
  1595. "type" => "textarea",
  1596. "label" => t("Only allow certain users to log in (allow list):"),
  1597. "value" => variable_get('user_whitelist', ''),
  1598. "description" => t("You may explicitly state which users are allowed to log in to FlightPath at this time.
  1599. Enter usernames, email addresses, or CWIDs, one per line. Users who are not part of this \"allow list\"
  1600. will be returned to the login screen, with a message stating that the system is only allowing
  1601. certain users to log in at this time.
  1602. <br>Note: the admin user
  1603. will always be able to log in. To disable, simply erase the contents of
  1604. this box and save."),
  1605. );
  1606. $form['mfa_enabled'] = array(
  1607. 'type' => 'select',
  1608. 'label' => t("Enable multi-factor authentication?"),
  1609. 'options' => array('no' => 'No (default)', 'yes' => 'Yes'),
  1610. 'hide_please_select' => TRUE,
  1611. 'value' => variable_get("mfa_enabled", "no"),
  1612. 'description' => t("If enabled, local users in FlightPath (like admin) will be emailed a validation code upon logging in, if and only if they have
  1613. an email address saved for their user account. This will not affect users which use an alternate method of logging in, such
  1614. as SSO, LDAP, etc. If unsure what to select, set this value to 'No'."),
  1615. );
  1616. $form["system_name"] = array(
  1617. "type" => "textfield",
  1618. "label" => t("System Name:"),
  1619. "value" => variable_get("system_name", "FlightPath"),
  1620. "description" => t("This is the name of this software system. Ex: FlightPath. This setting allows you to re-name this
  1621. system for you school. You will also need to create new themes, and edit where the name FlightPath
  1622. is hard-coded in the template files. This will only change the name FlightPath in user-facing pages,
  1623. it will still appear in admin sections. After changing this value, clear your cache, as several
  1624. menu items will need to be updated."),
  1625. );
  1626. $form['system_timezone'] = array(
  1627. 'type' => 'select',
  1628. 'label' => t('System timezone:'),
  1629. 'options' => get_timezones(),
  1630. 'value' => variable_get('system_timezone', 'America/Chicago'),
  1631. );
  1632. $form['system_default_student_load_tab'] = array(
  1633. 'type' => 'select',
  1634. 'label' => t('Default tab to view when loading a new student:'),
  1635. 'options' => array('profile' => t('Student Profile'), 'engagements' => t("Engagements"), 'degree' => t('Degree')),
  1636. 'value' => variable_get('system_default_student_load_tab', 'profile'),
  1637. 'hide_please_select' => TRUE,
  1638. 'description' => t("Unless overridden by the user's settings, this is the tab which
  1639. the user will see when pulling up a new student for advising.
  1640. <br>If unsure what to select, chose 'Student Profile'."),
  1641. );
  1642. // Can we support clean_urls?
  1643. $bool_support_clean = system_check_clean_urls();
  1644. $form["support_clean_urls"] = array(
  1645. "type" => "hidden",
  1646. "value" => ($bool_support_clean) ? "yes" : "no",
  1647. );
  1648. if ($bool_support_clean) {
  1649. // Give the option to change ONLY if we can support clean URLs
  1650. $form["clean_urls"] = array(
  1651. "type" => "checkbox",
  1652. "label" => t("Enable 'Clean URLs?'"),
  1653. "value" => variable_get("clean_urls", FALSE),
  1654. "description" => t("Your server supports 'clean URLs', which eliminates 'index.php?q=' from your URLs, making them
  1655. more readable. It is recommended you leave this feature enabled. For more information, see: http://getflightpath.com/node/5."),
  1656. );
  1657. }
  1658. else {
  1659. // Server does not support clean URLs.
  1660. $form["support_clean_markup"] = array(
  1661. "value" => "<p><b>Clean URLs:</b> This server <u>does not support</u> clean URLs. If you are using an Apache-compatible server,
  1662. make sure that your .htaccess file is properly configured. For more information, see: http://getflightpath.com/node/5.</p>",
  1663. );
  1664. }
  1665. $form["theme"] = array(
  1666. "type" => "radios",
  1667. "label" => t("Theme:"),
  1668. "options" => system_get_available_themes(),
  1669. "value" => variable_get("theme", "themes/fp6_clean"),
  1670. "description" => t("Select the theme you wish to use. Ex: Classic (themes/fp6_clean)"),
  1671. );
  1672. $form['external_css'] = array(
  1673. 'type' => 'textfield',
  1674. 'label' => t("External/Additional CSS file(s):"),
  1675. 'value' => variable_get("external_css", ""),
  1676. "description" => t("Enter the URL to one or more external or internal CSS files (separated by comma). Be aware
  1677. that due to the ordering of when your CSS file is loaded, you may need to use the !important keyword on some styles.
  1678. <br>If using an external source, your URL should begin with https:// and may not contain any queries (ex: ?a=b).
  1679. <br>If you are unsure what to enter here, leave it blank."),
  1680. );
  1681. $form['logo_image_url'] = array(
  1682. 'type' => 'textfield',
  1683. 'label' => t("Logo image URL:"),
  1684. 'value' => variable_get("logo_image_url", ""),
  1685. "description" => t("Enter the URL to a logo image. This is normally the \"FlightPath\" banner image seen in the upper left corner of every page.
  1686. <br>The image should be approximately 700x100 pixels, or a smaller size with a 7:1 width to height ratio.
  1687. <br>If using an external source, your URL should begin with https:// and may not contain any queries (ex: ?a=b).
  1688. <br>If you are unsure what to enter here, leave it blank to use the default logo."),
  1689. );
  1690. $form["contact_email_address"] = array(
  1691. "type" => "textfield",
  1692. "label" => t("Contact email address:"),
  1693. "value" => variable_get("contact_email_address", ""),
  1694. "description" => t("Enter the email address to mail when a user accesses the
  1695. Contact FlightPath Production Team popup. Leave blank to disable the link to the popup."),
  1696. );
  1697. $form["notify_apply_draft_changes_email_address"] = array(
  1698. "type" => "textfield",
  1699. "label" => t("Notify apply draft changes email address:"),
  1700. "value" => variable_get("notify_apply_draft_changes_email_address", ""),
  1701. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  1702. draft changes are applied from the admin console.
  1703. Leave blank to disable."),
  1704. );
  1705. $form["notify_mysql_error_email_address"] = array(
  1706. "type" => "textfield",
  1707. "label" => t("Notify MySQL error email address:"),
  1708. "value" => variable_get("notify_mysql_error_email_address", ""),
  1709. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  1710. a mysql error occurs.
  1711. Leave blank to disable."),
  1712. );
  1713. $form["notify_php_error_email_address"] = array(
  1714. "type" => "textfield",
  1715. "label" => t("Notify PHP error email address:"),
  1716. "value" => variable_get("notify_php_error_email_address", ""),
  1717. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  1718. a PHP warning or error occurs. Leave blank to disable. Recommendation: disable
  1719. on development, but enable on production."),
  1720. );
  1721. $form["admin_transfer_passcode"] = array(
  1722. "type" => "textfield",
  1723. "label" => t("Admin Apply Draft password:"),
  1724. "value" => variable_get("admin_transfer_passcode", "changeMe"),
  1725. "description" => t("Enter a password which an admin user must enter
  1726. in order to apply draft changes to FlightPath.
  1727. This is an added security measure. Ex: p@ssWord569w"),
  1728. );
  1729. $options = array(
  1730. "90" => t("90 days"),
  1731. "180" => t("180 days"),
  1732. "365" => t("1 year"),
  1733. "548" => t("1.5 years"),
  1734. "730" => t("2 years"),
  1735. "912" => t("2.5 years"),
  1736. "1095" => t("3 years"),
  1737. "1460" => t("4 years"),
  1738. "1825" => t("5 years"),
  1739. "2190" => t("6 years"),
  1740. "2555" => t("7 years"),
  1741. "2920" => t("8 years"),
  1742. "3285" => t("9 years"),
  1743. "3650" => t("10 years"),
  1744. "never" => t("Never - Do not trim log table"),
  1745. );
  1746. $form["max_watchdog_age"] = array(
  1747. "type" => "select",
  1748. "label" => t("Max watchdog (log) entry age:"),
  1749. "hide_please_select" => TRUE,
  1750. "options" => $options,
  1751. "value" => variable_get("max_watchdog_age", "1095"),
  1752. "description" => t("Keep entries in the watchdog log tables until they are this old.
  1753. Entries older than this will be deleted at every cron run.
  1754. For example, if you only want to keep log entries for 1 year, then
  1755. set this to 1 year.
  1756. <b>Warning:</b> the Stats module uses data in this table to create
  1757. statistics and reports about use of FlightPath. Once data is removed from the
  1758. watchdog table, it cannot be retrieved again.
  1759. <br>If you are unsure what to put here, select '3 years'."),
  1760. );
  1761. $form['max_watchdog_debug_age'] = array(
  1762. "type" => "select",
  1763. "label" => t("Max watchdog (log) DEBUG entry age:"),
  1764. "hide_please_select" => TRUE,
  1765. "options" => array('7' => t('7 days'), '15' => t('15 days'), '30' => t('30 days'), '60' => t('60 days'), '90' => t('90 days'), '180' => t('180 days'), '365' => t('1 year'), 'never' => t("Never - do not remove debug entries from log table")),
  1766. "value" => variable_get("max_watchdog_debug_age", "30"),
  1767. "description" => t("This is similar to the setting above, but this sets how long to keep 'debug' messages in the watchdog (logs).
  1768. Debug events are generally useful for tracking down issues or problems, and are not used in any official reporting. Removing them
  1769. helps reduce the size of the watchdog table.
  1770. <br>If unsure what to choose, select '1 year'."),
  1771. );
  1772. $form["admin_degrees_default_allow_dynamic"] = array(
  1773. "type" => "textfield",
  1774. "size" => 5,
  1775. "label" => t("Default 'Allow Dynamic' value for new degrees:"),
  1776. "value" => variable_get("admin_degrees_default_allow_dynamic", "1"),
  1777. "description" => t("When creating a new degree, this is the default value to set for 'Allow Dynamic'. If set to 1 (the number one), it means
  1778. the degree is allowed to be dynamic, meaning it can be combined with other 'dynamic' degrees. If it is set to 0 (zero), it
  1779. means the degree is not allowed to be combined with anything else. If you are unsure what to enter here, type 1 (one)."),
  1780. );
  1781. $form["degree_classifications_level_1"] = array(
  1782. "label" => t("Degree Classifications - Level 1:"),
  1783. "type" => "textarea",
  1784. "rows" => 3,
  1785. "value" => variable_get("degree_classifications_level_1", "MAJOR ~ Major"),
  1786. "description" => t("Enter the 'level 1' (ie, top level) degree classifications, one per line, in the following format:
  1787. <br>&nbsp; &nbsp; MACHINE_NAME ~ Title
  1788. <br> Example: MAJOR ~ Major
  1789. <br>These are degrees which might be combined with
  1790. another degree, as in a double-major, or selected on their own for graduation.
  1791. For example, a degree in Computer Science, by itself would be
  1792. classified as a 'Major' by most universities. If you are unsure what to enter,
  1793. use: MAJOR ~ Major"),
  1794. );
  1795. $form["degree_classifications_level_2"] = array(
  1796. "label" => t("Degree Classifications - Level 2:"),
  1797. "type" => "textarea",
  1798. "rows" => 3,
  1799. "value" => variable_get("degree_classifications_level_2", "MINOR ~ Minor"),
  1800. "description" => t("Enter the 'level 2' degree classifications, one per line, in the following format:
  1801. <br>&nbsp; &nbsp; MACHINE_NAME ~ Title
  1802. <br> Example: MINOR ~ Minor
  1803. <br>These are degrees which might be combined with another degree
  1804. but are not selected by themselves for graduation. Most universities
  1805. would consider this type to be a 'Minor'. For example, a student
  1806. might Major in Computer Science, with a Minor in Math. In this instance,
  1807. Math would be classified by this level. If you are unsuare what to enter, use:
  1808. MINOR ~ Minor"),
  1809. );
  1810. $form["degree_classifications_level_3"] = array(
  1811. "label" => t("Degree Classifications - Level 3 (Add-on degrees, attached to other degrees):"),
  1812. "type" => "textarea",
  1813. "rows" => 3,
  1814. "value" => variable_get("degree_classifications_level_3", "CONC ~ Concentration"),
  1815. "description" => t("Enter the 'level 3' degree classifications, one per line, in the following format:
  1816. <br>&nbsp; &nbsp; MACHINE_NAME ~ Title
  1817. <br> Example: CONC ~ Concentration
  1818. <br>These are degree plans which are only ever 'attached' to other degree plans as an add-on option
  1819. to the student.
  1820. For example, Computer Science might have an Option or Track or Concentration in 'Business'.
  1821. The Business concentration would ONLY be selectable if the student were already majoring in Computer Science,
  1822. therefor it would fall into this classification.
  1823. If unsure what to enter here, use: CONC ~ Concentration"),
  1824. );
  1825. $form["enable_legacy_concentrations"] = array(
  1826. "label" => t("Enable legacy concentrations?"),
  1827. "type" => "checkbox",
  1828. "value" => variable_get("enable_legacy_concentrations", FALSE),
  1829. "description" => t("If checked, FlightPath will instruct users creating new degrees (and in other places) to
  1830. enter concentrations with a | (pipe) symbol. This is how concentrations were handled in FlightPath 4x and
  1831. before-- as entirely separate degrees. However, this can cause confusion if Dynamic Degrees
  1832. and/or Level-3 degrees are being utilized, as a concentration is a similar concept as a level-3 track, and some schools
  1833. may even name it as such. If you are unsure what to do, leave this unchecked."),
  1834. );
  1835. $form["allowed_student_ranks"] = array(
  1836. "type" => "textfield",
  1837. "label" => t("Allowed student ranks (CSV):"),
  1838. "value" => variable_get("allowed_student_ranks", "FR, SO, JR, SR"),
  1839. "description" => t("This is a list of which student ranks (aka Classifications) are allowed into FlightPath.
  1840. It should be separated by commas.
  1841. This also affects which students you may search for on the Advisees
  1842. tab. Ex: FR, SO, JR, SR"),
  1843. );
  1844. $form["rank_descriptions"] = array(
  1845. "type" => "textarea",
  1846. "label" => t("Rank descriptions:"),
  1847. "rows" => 8,
  1848. "value" => variable_get("rank_descriptions", "FR ~ Freshman\nSO ~ Sophomore\nJR ~ Junior\nSR ~ Senior\nPR ~ Professional\nGR ~ Graduate"),
  1849. "description" => t("Enter the rank code (from above) and the description which should appear on screen, in the format:
  1850. RANK ~ DESC, one per line.
  1851. <br>Ex:
  1852. <br>&nbsp; FR ~ Freshman
  1853. <br>&nbsp; SO ~ Sophomore
  1854. <br>&nbsp; JR ~ Junior
  1855. <br>&nbsp; SR ~ Senior"),
  1856. );
  1857. $form["not_allowed_student_message"] = array(
  1858. "type" => "textarea",
  1859. "label" => t("Not allowed student message:"),
  1860. "value" => variable_get("not_allowed_student_message", ""),
  1861. "description" => t("When a student is NOT allowed into FlightPath because of their
  1862. rank, this message will be displayed."),
  1863. );
  1864. $form['login_help_cid'] = array(
  1865. 'label' => t("Enter the 'Need Help Logging In?' Content ID number:"),
  1866. 'type' => 'textfield',
  1867. 'size' => 5,
  1868. 'value' => variable_get("login_help_cid", "0"),
  1869. 'description' => t("Enter the Content ID number of the web page you'd like the visitor to see if they click the 'Need Help Logging In?' link
  1870. on the login page. If you leave this blank, a generic message will be shown. To customize, visit the Content sectiona and
  1871. create a new 'Page'. Once you save, you will see the Content ID number at the end of the URL. Ex: flightpath_url/content/543 means
  1872. that 543 is the Content ID."),
  1873. );
  1874. $form['logout_message'] = array(
  1875. 'label' => t("Log out message:"),
  1876. 'type' => 'textarea',
  1877. 'value' => variable_get("logout_message", "You have been logged out of FlightPath."),
  1878. 'description' => t("This message displays to the user when they have logged out of FlightPath. If unsure what to enter, use the following:
  1879. <br>&nbsp; &nbsp; <i>You have been logged out of FlightPath.</i>
  1880. <br><b>Note:</b> You may use basic HTML in this field to add bold, italics, or links."),
  1881. );
  1882. $form['recalculate_alert_badge_seconds'] = array(
  1883. 'label' => t('How often should we recalculate the alert "bell" count?'),
  1884. 'type' => 'select',
  1885. 'hide_please_select' => TRUE,
  1886. 'options' => array( 1 => "1 second (recalculate on every page load)",
  1887. 15 => "15 seconds",
  1888. 30 => "30 seconds (default)",
  1889. 60 => "1 minute",
  1890. 300 => "5 minutes",
  1891. 600 => "10 minutes",
  1892. 1200 => "20 minutes",
  1893. ),
  1894. 'value' => variable_get('recalculate_alert_badge_seconds', 30),
  1895. 'description' => t('The alert "bell" at the top-right of the screen will display a notification graphic if there is something important for the user to look at.
  1896. For example, a new email or text message sent by the student. Please select how often we should check to see
  1897. if there is anything new. The alert count will be automatically recalculated when new content is created or deleted.
  1898. <br>This process may cause delays in page loads. If you notice slow page loads, set this time higher.
  1899. <br>If unsure, set to <em>30 seconds</em>.'),
  1900. );
  1901. return $form;
  1902. }
  1903. /**
  1904. * Extra submit handler for the system_settings_form
  1905. *
  1906. * @param unknown_type $form
  1907. * @param unknown_type $form_state
  1908. */
  1909. function system_settings_form_submit($form, &$form_state) {
  1910. // Left empty for now.
  1911. }
  1912. /**
  1913. * Implementation of hook_cron
  1914. *
  1915. * We will perform operations necessary for keep FlightPath's tables in shape.
  1916. *
  1917. */
  1918. function system_cron() {
  1919. // Should we trim the watchdog table of extra entries? Only once every so often, not every cron run.
  1920. $last_run = intval(variable_get("system_last_run_trim_watchdog", 0));
  1921. $check_against = strtotime("NOW - 7 DAYS"); // don't run any more often than once every 7 days
  1922. $c = 0;
  1923. if ($check_against > $last_run) {
  1924. // Should we "trim" the watchdog table of old entries?
  1925. $max_age_days = variable_get("max_watchdog_age", "1095");
  1926. if ($max_age_days != "never" && ($max_age_days*1) > 0) {
  1927. // Okay, let's trim the table.
  1928. $max_timestamp = strtotime("$max_age_days DAYS AGO");
  1929. $result = db_query("DELETE FROM watchdog WHERE `timestamp` < ? ", $max_timestamp);
  1930. $rows = db_affected_rows($result);
  1931. if ($rows > 0) {
  1932. watchdog("system", t("@rows old rows (older than @max days) trimmed from watchdog table on system cron run."), array("@rows" => $rows, "@max" => $max_age_days), WATCHDOG_DEBUG);
  1933. }
  1934. }
  1935. // Should we trim the watchdog table of DEBUG records?
  1936. $max_age_days = intval(variable_get("max_watchdog_debug_age", "30"));
  1937. if ($max_age_days != "never" && ($max_age_days) > 0) {
  1938. // Okay, let's trim the table.
  1939. $max_timestamp = strtotime("$max_age_days DAYS AGO");
  1940. $result = db_query("DELETE FROM watchdog WHERE `timestamp` < ? AND severity = ? ", $max_timestamp, WATCHDOG_DEBUG);
  1941. $rows = db_affected_rows($result);
  1942. if ($rows > 0) {
  1943. watchdog("system", t("@rows old 'debug' rows (older than @max days) trimmed from watchdog table on system cron run."), array("@rows" => $rows, "@max" => $max_age_days), WATCHDOG_DEBUG);
  1944. }
  1945. }
  1946. variable_set("system_last_run_trim_watchdog", time());
  1947. } // check against > last_run, so we should do it.
  1948. // Should we delete from user_attributes any mda_validation_codes which are older than X hours?
  1949. $max_age_hours = 1;
  1950. // Okay, let's trim the table.
  1951. $max_timestamp = strtotime("$max_age_hours HOURS AGO");
  1952. $result = db_query("DELETE FROM user_attributes WHERE `name` = 'mfa_validation_code' AND `updated` < ? ", $max_timestamp);
  1953. $rows = db_affected_rows($result);
  1954. if ($rows > 0) {
  1955. watchdog("system", t("@rows old 'mfa_validation_code' rows (older than @max hours) trimmed from user_attributes table on system cron run."), array("@rows" => $rows, "@max" => $max_age_days), WATCHDOG_DEBUG);
  1956. }
  1957. } // hook_cron
  1958. /**
  1959. * Intercepts form submissions from forms built with the form API.
  1960. */
  1961. function system_handle_form_submit() {
  1962. $callback = $_REQUEST["callback"];
  1963. $form_type = $_REQUEST["form_type"];
  1964. watchdog('system', "handle_form_submit callback:$callback, form_type:$form_type", array());
  1965. $form_include = $_REQUEST["form_include"];
  1966. $form_token = $_REQUEST["form_token"];
  1967. // Make sure the form_token is valid!
  1968. if ($form_token != md5($callback . fp_token())) {
  1969. watchdog('system', "handle_form_submit - Error; invalid form token. Got: $form_token. Expected: " . md5($callback . fp_token()), array(), WATCHDOG_ERROR);
  1970. die(t("Sorry, but you have encountered an error. A form submission was flagged
  1971. as possibly being an invalid or forged submission. This may constitute a bug
  1972. in the system. Please report this error to your Systems Administrator."));
  1973. }
  1974. if ($form_include != "") {
  1975. // This is a file we need to include in order to complete the submission process.
  1976. // We will also make sure that we only allow certain file extensions to be included.
  1977. $allowed_ext = array(
  1978. "php",
  1979. "inc",
  1980. "class",
  1981. "module",
  1982. );
  1983. $temp = explode(".", $form_include);
  1984. $test_ext = trim($temp[count($temp) - 1]);
  1985. if (!in_array($test_ext, $allowed_ext)) {
  1986. watchdog('system', "handle_form_submit - file type $test_ext not allowed to be included in form submission.", array(), WATCHDOG_ERROR);
  1987. fp_add_message(t("Include file type (%ext) not allowed in form submission. Allowed extensions: .php, .inc, .class, .module.", array("%ext" => $test_ext)), "error");
  1988. fp_goto("<front>");
  1989. return;
  1990. }
  1991. // We need to make sure, before we include this file, that it is something only available from within the main FlightPath directory.
  1992. $absolute_path = realpath($form_include);
  1993. $absolute_path = str_replace("\\", "/", $absolute_path);
  1994. // In order for us to proceed, the $absolute_path must BEGIN with our base FlightPath installation directory.
  1995. $file_system_path = $GLOBALS['fp_system_settings']['file_system_path'];
  1996. if (substr($absolute_path, 0, strlen($file_system_path)) != $file_system_path) {
  1997. watchdog('system', "handle_form_submit - Include file outside of FlightPath installation directory.
  1998. <br>FlightPath directory path: %fsp
  1999. <br>Include file path: %ap", array("%fsp" => $file_system_path, "%ap" => $absolute_path), WATCHDOG_ERROR);
  2000. fp_add_message(t("Include file in form submission is outside of the FlightPath installation directory.
  2001. <br>FlightPath directory path: %fsp
  2002. <br>Include file path: %ap", array("%fsp" => $file_system_path, "%ap" => $absolute_path)), "error");
  2003. fp_goto("<front>");
  2004. return;
  2005. }
  2006. include_once($form_include);
  2007. }
  2008. // We need to make sure the user has permission to submit this form!
  2009. $form_path = $_REQUEST["form_path"];
  2010. // Check the menu router table for whatever the permissions were for this
  2011. // path, if any.
  2012. if ($form_path != "") {
  2013. // For the sake of makeing sure our wildcards get replaced correctly,
  2014. // temporarily set $_REQUEST['q'] to our $form_q.
  2015. $form_q = base64_decode($_REQUEST["form_q_64"]);
  2016. $temp_q = $_REQUEST['q'];
  2017. $_REQUEST['q'] = $form_q;
  2018. $router_item = menu_get_item($form_path) ;
  2019. if (!menu_check_user_access($router_item)) {
  2020. // The user does NOT have access to submit this form! The fact that
  2021. // it has made it this far means this may be some sort of hacking attempt.
  2022. watchdog('system', "handle_form_submit - Insufficient permissions to submit form.", array(), WATCHDOG_ERROR);
  2023. die(t("Sorry, but you have encountered an error. A form submission was flagged
  2024. as possibly being an invalid or having insufficient permissions to submit.
  2025. This may constitute a bug in the system.
  2026. Please report this error to your Systems Administrator."));
  2027. }
  2028. // I don't think this is needed, just causes problems! // $_REQUEST['q'] = $temp_q; // set back to original, just in case.
  2029. }
  2030. // Let's get our set of allowed values, by looking at the original form,
  2031. // and grab what's in the POST which matches the name.
  2032. $values = array();
  2033. $safe_values = array(); // will be the same as $values, but anything of type password will not be included.
  2034. if (function_exists($callback)) {
  2035. // Get any params for the callback, or, an empty array.
  2036. $form_params = @unserialize(base64_decode($_REQUEST['form_params']));
  2037. if (!$form_params) {
  2038. $form_params = array();
  2039. }
  2040. // Actually get the form now.
  2041. $form = fp_get_form($callback, $form_params);
  2042. foreach ($form as $name => $element) {
  2043. // Save to our $values array, but we don't care about markup.
  2044. if (@$element["type"] != "" && @$element["type"] != "markup" && @$element["type"] != "markup_no_wrappers") {
  2045. $values[$name] = @$_POST[$name];
  2046. // Save to save_values, too, if this is not a password field.
  2047. if (@$element["type"] != "password") {
  2048. $safe_values[$name] = @$_POST[$name];
  2049. }
  2050. // If this is a checkbox, and we have any value in the POST, it should
  2051. // be saved as boolean TRUE
  2052. if (isset($element["type"]) && $element["type"] == "checkbox") {
  2053. if (isset($_POST[$name]) && $_POST[$name] === "1") {
  2054. $values[$name] = TRUE;
  2055. }
  2056. else {
  2057. $values[$name] = FALSE;
  2058. }
  2059. }
  2060. }
  2061. // Do we need to alter the value from the POST?
  2062. // If this element is a cfieldset, it may contain other elements. We should get
  2063. // those values too.
  2064. if (isset($element["elements"])) {
  2065. foreach ($element["elements"] as $k => $v) {
  2066. foreach ($element["elements"][$k] as $cname => $celement) {
  2067. // Save to our $values array, but we don't care about markup.
  2068. if (@$celement["type"] != "" && @$celement["type"] != "markup" && @$element["type"] != "markup_no_wrappers") {
  2069. $values[$cname] = @$_POST[$cname];
  2070. // Save to save_values, too, if this is not a password field.
  2071. if (@$celement["type"] != "password") {
  2072. $safe_values[$cname] = @$_POST[$cname];
  2073. }
  2074. // If this is a checkbox, and we have any value in the POST, it should
  2075. // be saved as boolean TRUE
  2076. if (isset($celement["type"]) && $celement["type"] == "checkbox") {
  2077. if (isset($_POST[$cname]) && $_POST[$cname] === "1") {
  2078. $values[$cname] = TRUE;
  2079. }
  2080. else {
  2081. $values[$cname] = FALSE;
  2082. }
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. }
  2090. // Does the form have any defined submit_handler's? If not, let's assign it the
  2091. // default of callback_submit().
  2092. $submit_handlers = $form["#submit_handlers"];
  2093. if (!is_array($submit_handlers)) $submit_handlers = array();
  2094. // If the submit_handlers is empty, then add our default submit handler. We don't
  2095. // want to do this if the user went out of their way to enter a different handler.
  2096. if (count($submit_handlers) == 0) {
  2097. array_push($submit_handlers, $callback . "_submit");
  2098. }
  2099. // Does the form have any defined validate_handler's? This works exactly like the submit handler.
  2100. $validate_handlers = $form["#validate_handlers"];
  2101. if (!is_array($validate_handlers)) $validate_handlers = array();
  2102. if (count($validate_handlers) == 0) {
  2103. array_push($validate_handlers, $callback . "_validate");
  2104. }
  2105. // Let's store our values in the SESSION in case we need them later on.
  2106. // But only if this is NOT a system_settings form!
  2107. if ($form_type != "system_settings") {
  2108. // Do not store any "password" field, for security, so it isn't stored
  2109. // in the server's session file in plain text.
  2110. // For this reason we will use the $safe_values array we created earlier.
  2111. $_SESSION["fp_form_submissions"][$callback]["values"] = $safe_values;
  2112. }
  2113. $form_state = array("values" => $values, "POST" => $_POST);
  2114. // Let's pass this through our default form validator (mainly to check for required fields
  2115. // which do not have values entered)
  2116. form_basic_validate($form, $form_state);
  2117. if (!form_has_errors()) {
  2118. // Let's now pass it through all of our custom validators, if there are any.
  2119. foreach ($validate_handlers as $validate_callback) {
  2120. if (function_exists($validate_callback)) {
  2121. call_user_func_array($validate_callback, array(&$form, &$form_state));
  2122. }
  2123. }
  2124. }
  2125. if (!form_has_errors()) {
  2126. // No errors from the validate, so let's continue.
  2127. // Is this a "system settings" form, or a normal form?
  2128. if ($form_type == "system_settings") {
  2129. // This is system settings, so let's save all of our values to the variables table.
  2130. // Write our values array to our variable table.
  2131. foreach ($form_state["values"] as $name => $val) {
  2132. variable_set($name, $val);
  2133. }
  2134. fp_add_message("Settings saved successfully.");
  2135. }
  2136. // Let's go through the form's submit handlers now.
  2137. foreach ($submit_handlers as $submit_callback) {
  2138. if (function_exists($submit_callback)) {
  2139. call_user_func_array($submit_callback, array(&$form, &$form_state));
  2140. }
  2141. }
  2142. }
  2143. // Figure out where we are supposed to redirect the user.
  2144. $redirect_path = $redirect_query = "";
  2145. if (!form_has_errors() && isset($form["#redirect"]) && is_array($form["#redirect"])) {
  2146. $redirect_path = $form["#redirect"]["path"];
  2147. $redirect_query = $form["#redirect"]["query"];
  2148. }
  2149. else {
  2150. $redirect_path = @$_REQUEST["default_redirect_path"];
  2151. $redirect_query = @$_REQUEST["default_redirect_query"];
  2152. // To help prevent directory traversal attacks, the redirect_path cannot contain periods (.) and semi-colons, and other trouble characters
  2153. $redirect_path = str_replace(".", "", $redirect_path);
  2154. $redirect_path = str_replace(";", "", $redirect_path);
  2155. $redirect_path = str_replace("'", "", $redirect_path);
  2156. $redirect_path = str_replace('"', "", $redirect_path);
  2157. $redirect_path = str_replace(' ', "", $redirect_path);
  2158. }
  2159. // Was scroll_top set? Meaning, are we meant to scroll to a specific position when the page loads?
  2160. if (isset($_REQUEST["scroll_top"])) {
  2161. $scroll_top = @floatval($_REQUEST["scroll_top"]);
  2162. if ($scroll_top > 0) {
  2163. if ($redirect_query != "") $redirect_query .= "&"; // not blank? Add this as another property with &.
  2164. $redirect_query .= "scroll_top=" . $scroll_top;
  2165. }
  2166. }
  2167. // If there is a Batch process we need to do, do it here instead of the fp_goto.
  2168. if (isset($_SESSION["fp_batch_id"]) && function_exists("batch_menu")) {
  2169. $batch_id = $_SESSION["fp_batch_id"];
  2170. unset($_SESSION["fp_batch_id"]);
  2171. batch_start_batch_from_form_submit($batch_id, $redirect_path, $redirect_query);
  2172. return;
  2173. }
  2174. else if (isset($_SESSION["fp_batch_id"]) && !function_exists("batch_menu")) {
  2175. // We requested a batch action, but the batch module is not installed.
  2176. watchdog('system', "handle_form_submit - Batch process attempted, but batch module not enabled", array(), WATCHDOG_ERROR);
  2177. fp_add_message(t("A batch process was attempted, but it appears that the Batch module is not enabled. Please contact your FlightPath administrator."), "error");
  2178. unset($_SESSION["fp_batch_id"]);
  2179. }
  2180. // Okay, go back to where we were!
  2181. fp_goto($redirect_path, $redirect_query);
  2182. }
  2183. function system_handle_logout() {
  2184. global $user;
  2185. $user_name = $user->name;
  2186. $uid = $user->id;
  2187. // Finish up logging out.
  2188. // In an effort to mimimize a bug in Safari, we will
  2189. // overwrite the SESSION variables, then perform a few other operations,
  2190. // to make sure they are well and truly destroyed.
  2191. foreach ($_SESSION as $key => $val) {
  2192. $_SESSION[$key] = "x";
  2193. }
  2194. foreach ($_SESSION as $key => $val) {
  2195. $_SESSION[$key] = FALSE;
  2196. }
  2197. $_SESSION = array();
  2198. if (isset($_COOKIE[session_name()])) // remove cookie by setting it to expire, if it's there.
  2199. {
  2200. $cookie_expires = time() - 3600;
  2201. setcookie(session_name(), "", $cookie_expires, '/');
  2202. }
  2203. // unset cookies from https://stackoverflow.com/questions/2310558/how-to-delete-all-cookies-of-my-website-in-php
  2204. // We won't use $_COOKIE for this, as we might get an array for the $val, if the cookie was set using array notation. This
  2205. // code snippit should fix that.
  2206. if (isset($_SERVER['HTTP_COOKIE'])) {
  2207. $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
  2208. foreach($cookies as $cookie) {
  2209. $parts = explode('=', $cookie);
  2210. $name = trim($parts[0]);
  2211. // Only do this for non-mfa related cookies.
  2212. if (!str_starts_with($name, "flightpath_mfa_remember")) {
  2213. setcookie($name, '', time() - 3600);
  2214. setcookie($name, '', time() - 3600, '/');
  2215. }
  2216. }
  2217. }
  2218. // I know this is repetitive, but I want to make ABSOLUTELY SURE
  2219. // I am removing the session by removing it, creating a new one, then killing that one too.
  2220. session_destroy();
  2221. session_commit();
  2222. session_start();
  2223. session_destroy();
  2224. session_commit();
  2225. // Check for hook_user_logout
  2226. $modules = modules_implement_hook("user_logout");
  2227. foreach($modules as $module) {
  2228. call_user_func($module . '_user_logout');
  2229. }
  2230. watchdog("logout", "@user has logged out", array("@user" => "$user_name ($uid)"));
  2231. fp_goto("<front>", "logout=true");
  2232. }
  2233. /**
  2234. * This function will clear our various caches by calling
  2235. * on the hook_clear_cache in each module.
  2236. */
  2237. function system_perform_clear_cache() {
  2238. fp_clear_cache();
  2239. fp_goto("admin-tools");
  2240. }
  2241. /**
  2242. * Called from menu, will run hook_cron() for all modules.
  2243. */
  2244. function system_perform_run_cron() {
  2245. // Keep the script from timing out prematurely...
  2246. set_time_limit(99999); // around 27 hours.
  2247. watchdog("cron", "Cron run started", array(), WATCHDOG_DEBUG);
  2248. invoke_hook("cron");
  2249. watchdog("cron", "Cron run completed", array(), WATCHDOG_DEBUG);
  2250. variable_set("cron_last_run", time());
  2251. fp_add_message(t("Cron run completed successfully."));
  2252. fp_goto("admin-tools/admin");
  2253. }
  2254. /**
  2255. * This page displayes the results of each module's hook_status.
  2256. *
  2257. */
  2258. function system_display_status_page() {
  2259. $rtn = "";
  2260. $pol = "";
  2261. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  2262. $status_array = invoke_hook("status"); // get everyone's hook_status.
  2263. $rtn .= "<p>" . t("This page will show you important status messages
  2264. about FlightPath. For example, what modules (if any) have
  2265. an update available.") . "</p>";
  2266. $rtn .= "<table width='100%' border='1' class='status-table' cellpadding='4'>
  2267. <tr class='header-row'>
  2268. <th width='10%' class='package-header'>" . t("Package") . "</th>
  2269. <th>" . t("Status") . "</th>
  2270. </tr>";
  2271. foreach ($status_array as $module => $details) {
  2272. $pol = ($pol == "even") ? "odd" : "even";
  2273. if (@$details["severity"] == "") $details["severity"] = "normal";
  2274. $rtn .= "<tr class='status-row status-row-$pol'>
  2275. <td valign='top' class='module-name'>$module</td>
  2276. <td valign='top' class='module-status module-status-" . $details["severity"] . "'>
  2277. " . $details["status"] . "
  2278. </td>
  2279. </tr>";
  2280. }
  2281. $rtn .= "</table>";
  2282. return $rtn;
  2283. }
  2284. /**
  2285. * Implementation of hook_status
  2286. * Expected return is array(
  2287. * "severity" => "normal" or "warning" or "alert",
  2288. * "status" => "A message to display to the user.",
  2289. * );
  2290. */
  2291. function system_status() {
  2292. $rtn = array();
  2293. $rtn["severity"] = "normal";
  2294. $rtn["status"] = "";
  2295. // Check on the last time cron was run; make sure it's working properly.
  2296. $last_run = convert_time(variable_get("cron_last_run", 0));
  2297. // Report on current details about FlightPath.
  2298. $fpversion = FLIGHTPATH_VERSION;
  2299. if ($fpversion == "%FP_VERSION%") {
  2300. // This means you are using a version not downloaded from getflightpath.com. Probably directly from a git repository.
  2301. $fpversion = "GitRepo";
  2302. }
  2303. $rtn["status"] .= "<p>" . t("FlightPath version:") . " " . FLIGHTPATH_CORE . "-" . $fpversion . "</p>";
  2304. if ($last_run < strtotime("-2 DAY")) {
  2305. $rtn["severity"] = "alert";
  2306. $rtn["status"] .= t("Cron hasn't run in over 2 days. For your installation of FlightPath
  2307. to function properly, cron.php must be accessed routinely. At least once per day is recommended.
  2308. Set for more frequently if making use of text messaging, emails, or notifications in FlightPath.
  2309. For example, every 10 minutes.");
  2310. }
  2311. else {
  2312. $rtn["status"] .= t("Cron was last run on %date", array("%date" => format_date($last_run)));
  2313. }
  2314. $cron_url = $GLOBALS["fp_system_settings"]["base_url"] . "/cron.php?t=" . $GLOBALS["fp_system_settings"]["cron_security_token"];
  2315. $rtn["status"] .= "<p style='font-size: 0.8em;'>" . t("Your site's cron URL is:");
  2316. $rtn["status"] .= "&nbsp; <i>" . $cron_url . "</i>
  2317. <br>" . t("Ex linux cron command (every 10 min):") . "&nbsp; <i style='background-color: beige;'>*/10 * * * * wget -O - -q -t 1 $cron_url</i>";
  2318. $rtn["status"] .= "</p>";
  2319. return $rtn;
  2320. }
  2321. /**
  2322. * Implements hook_clear_cache
  2323. * Take care of clearing caches managed by this module
  2324. */
  2325. function system_clear_cache() {
  2326. unset($_SESSION["fp_form_submissions"]);
  2327. unset($_SESSION["fp_db_host"]);
  2328. unset($_SESSION["fp_draft_mode"]);
  2329. unset($_SESSION["fp_simple_degree_plan_cache_for_student"]);
  2330. unset($_SESSION['fp_alert_count_by_type']);
  2331. unset($_SESSION['fp_alert_count_by_type_last_check']);
  2332. menu_rebuild_cache();
  2333. system_rebuild_css_js_query_string();
  2334. }
  2335. /**
  2336. * This function will recreate the dummy query string we add to the end of css and js files.
  2337. *
  2338. */
  2339. function system_rebuild_css_js_query_string() {
  2340. // A dummy query string gets added to the URLs for css and javascript files,
  2341. // to give us control over browser caching. When this value changes (cause we
  2342. // cleared the cache, updated a module, etc) it tells the browser to get a new
  2343. // copy of our css and js files.
  2344. // This idea, like many other ideas in FlightPath, was borrowed from Drupal.
  2345. // The timestamp is converted to base 36 in order to make it more compact.
  2346. // This gives us a random-looking string of 6 numbers and letters.
  2347. variable_set('css_js_query_string', base_convert(time(), 10, 36));
  2348. }
  2349. /**
  2350. * Clears only the menu cache
  2351. */
  2352. function system_perform_clear_menu_cache() {
  2353. menu_rebuild_cache();
  2354. fp_goto("admin-tools/admin");
  2355. }
  2356. /**
  2357. * Display the "login" page. This is the default page displayed
  2358. * to the user, at /login, if they have not logged in yet.
  2359. *
  2360. * This page is meant to be displayed in conjunction with blocks, so the user can
  2361. * easily define their own messages and such.
  2362. *
  2363. * @return unknown
  2364. */
  2365. function system_display_login_page() {
  2366. $rtn = "";
  2367. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  2368. $login_form = fp_render_form("system_login_form");
  2369. $rtn .= "<noscript>
  2370. <div style='padding: 5px; background-color: red; color: white; font-size: 12pt; font-weight: bold;'>
  2371. " . t("@FlightPath requires JavaScript to be enabled in order to
  2372. function correctly. Please enable JavaScript on your browser
  2373. before continuing.", array("@FlightPath" => variable_get("system_name", "FlightPath"))) . "</div>
  2374. </noscript>";
  2375. $rtn .= "<div class='login-content-div'>";
  2376. $rtn .= "
  2377. <div class='left-side-content'>
  2378. $login_form
  2379. </div>";
  2380. $rtn .= "</div>";
  2381. return $rtn;
  2382. }
  2383. function system_mfa_login_form() {
  2384. $form = array();
  2385. $db_row = $_SESSION['mfa__form_state_db_row'];
  2386. $email = $db_row['email'];
  2387. $obf_email = substr($email, 0, 5) . str_repeat("*", strlen($email) - 5);
  2388. $form['mark_top_msg'] = array(
  2389. 'value' => "<strong>" . t("A message has been sent to your email address (%obfemail) with a code to continue. Please enter the code below.", array("%obfemail" => $obf_email)) . "</strong>
  2390. <p>" . t("Check your Spam or Bulk Mail folder if you do not receive the email within 5 minutes.") . "</p>
  2391. <p>" . t("To recreate and resend the validation code, simply return to the login page and try again.") . "</p>
  2392. <hr>",
  2393. 'weight' => 10,
  2394. );
  2395. $form['mfa_code'] = array(
  2396. 'type' => 'textfield',
  2397. 'label' => t("Code:"),
  2398. 'weight' => 20,
  2399. 'required' => TRUE,
  2400. );
  2401. $form['mfa_remember'] = array(
  2402. 'type' => 'checkbox',
  2403. 'label' => t("Do not ask again for this browser/device for 30 days?"),
  2404. 'weight' => 30,
  2405. );
  2406. $form['submit_btn'] = array(
  2407. 'type' => 'submit',
  2408. 'value' => t("Submit"),
  2409. 'spinner' => TRUE,
  2410. 'weight' => 200,
  2411. );
  2412. return $form;
  2413. } // system_mfa_login_form
  2414. function system_mfa_login_form_validate($form, $form_state) {
  2415. $db_row = $_SESSION['mfa__form_state_db_row'];
  2416. $user_id = $db_row['user_id'];
  2417. // Validate the code.
  2418. $db_code = user_get_attribute($user_id, "mfa_validation_code", FALSE);
  2419. if (intval($form_state['values']['mfa_code']) !== intval($db_code)) {
  2420. form_error('mfa_code', t("Sorry, but the code you entered is not the same that was sent to your address. Try again. If you are unable to log in, have a systems
  2421. administrator reset your password."));
  2422. return;
  2423. }
  2424. } // mfa_login_form_validate
  2425. function system_mfa_login_form_submit($form, $form_state) {
  2426. // If we made it here, the user is allowed to log in.
  2427. $db_row = $_SESSION['mfa__form_state_db_row'];
  2428. $user_id = $db_row['user_id'];
  2429. $mfa_remember = intval($form_state['values']['mfa_remember']);
  2430. // If we should remember for 30 days, then set cookie.
  2431. if ($mfa_remember == TRUE) {
  2432. setcookie("flightpath_mfa_remember__" . $user_id, "yes", strtotime("NOW + 30 DAYS"));
  2433. }
  2434. else {
  2435. // Clear the cookie
  2436. setcookie("flightpath_mfa_remember__" . $user_id, "no", 1);
  2437. }
  2438. // Actually log in the user.
  2439. $account = system_perform_user_login($user_id);
  2440. // Watchdog
  2441. watchdog("mfa-login", "@user has logged in via mfa. CWID: @cwid", array("@user" => "$account->name ($account->id)", "@cwid" => $account->cwid));
  2442. fp_goto("<front>");
  2443. } // .. submit
  2444. /**
  2445. * This draws the form which facilitates logins.
  2446. */
  2447. function system_login_form() {
  2448. $form = array();
  2449. fp_set_title("");
  2450. $bool_clear_cookies = FALSE;
  2451. // If we are coming from having just logged out, display a message.
  2452. if (isset($_REQUEST["logout"]) && $_REQUEST["logout"] == "true") {
  2453. $x = variable_get("logout_message", "You have been logged out of FlightPath.");
  2454. fp_add_message(filter_markup($x));
  2455. }
  2456. // Are we here because the user was not found in the whitelist?
  2457. if (isset($_REQUEST['wlist']) && $_REQUEST['wlist'] == 'notfound') {
  2458. fp_add_message(t("Sorry, but only certain users are allowed access at this time. If you believe you need access, please contact your system administrator."), 'error', TRUE);
  2459. }
  2460. // Are we here because the user was not found at all?
  2461. if (isset($_REQUEST['user']) && $_REQUEST['user'] == 'notfound') {
  2462. fp_add_message(t("Sorry, but the user you specified could not be found in FlightPath's database. If you believe you need access, please contact your system administrator."), 'error', TRUE);
  2463. }
  2464. // Are we here because only the admin user is allowed in?
  2465. if (isset($_REQUEST['user']) && $_REQUEST['user'] == 'adminonly') {
  2466. fp_add_message(t("Sorry, but logins are disabled at this time while maintenance is being performed. Please try again later."), 'error', TRUE);
  2467. }
  2468. // Are we here because only the user's rank is not allowed?
  2469. if (isset($_REQUEST['user']) && $_REQUEST['user'] == 'rank') {
  2470. fp_add_message(t("Sorry, your rank/classification is not allowed. At this time this system is only available to students
  2471. in the following ranks/classifications: @ranks_str", array("@ranks_str" => $allowed_ranks_str)), 'error', TRUE);
  2472. }
  2473. // Are we here because the user was not found in the whitelist?
  2474. if (isset($_REQUEST['user']) && $_REQUEST['user'] == 'disabled') {
  2475. fp_add_message(t("Sorry, but the user you specified has been marked as disabled. If you believe you need access, please contact your system administrator."), 'error', TRUE);
  2476. }
  2477. // Are we here because the user is trying to do a zoom installation from the marketplace?
  2478. if (module_enabled('zoomapi') && isset($_REQUEST['zoom_install']) && $_REQUEST['zoom_install'] == 'marketplace') {
  2479. fp_add_message(t("To install FlightPath Academics to your Zoom account (which allows for automatic meeting requests through appointments), please
  2480. sign in below."));
  2481. fp_add_message(t("You may be asked to sign into your Zoom account and authorize FlightPath.<br>You will be returned to FlightPath afterwards."));
  2482. $form['zoom_install'] = array(
  2483. 'type' => 'hidden',
  2484. 'value' => 'marketplace',
  2485. );
  2486. }
  2487. $form["user"] = array(
  2488. "label" => t("User:"),
  2489. "type" => "textfield",
  2490. "size" => 30,
  2491. "required" => TRUE,
  2492. "description" => t("Enter your user name or email address."),
  2493. );
  2494. $form["password"] = array(
  2495. "label" => t("Password:"),
  2496. "type" => "password",
  2497. "size" => 30,
  2498. "required" => TRUE,
  2499. );
  2500. $form["submit"] = array(
  2501. "type" => "submit",
  2502. "value" => t("Log in"),
  2503. "suffix" => "<div id='login-form-forgot-password'>" . l(t("Need help logging in?"), 'login-help') ."</div>",
  2504. );
  2505. $form["#attributes"] = array("onSubmit" => "showUpdate(true);");
  2506. return $form;
  2507. }
  2508. /**
  2509. * Validate function for the login form.
  2510. * This is where we will do all of the lookups to verify username
  2511. * and password. If you want to write your own login handler (like for LDAP)
  2512. * this is the function you would duplicate in a custom module, then use hook_form_alter
  2513. * to make your function be the validator, not this one.
  2514. *
  2515. * We will simply verify the password, then let the submit handler take over from there.
  2516. */
  2517. function system_login_form_validate($form, &$form_state) {
  2518. $user = trim($form_state["values"]["user"]);
  2519. // If the $user is an email address, then find out the user it actually belongs to.
  2520. if (filter_var($user, FILTER_VALIDATE_EMAIL)) {
  2521. // This appears to be the user's email address. Convert to their username
  2522. // instead.
  2523. // Force email addresses to be lowercase.
  2524. $test = db_result(db_query("SELECT user_name FROM users WHERE email = ?", array(strtolower($user))));
  2525. if ($test) {
  2526. $user = $test;
  2527. $form_state["values"]["user"] = $test;
  2528. }
  2529. }
  2530. $password = $form_state["values"]["password"];
  2531. // If the GRANT_FULL_ACCESS is turned on, skip trying to validate
  2532. if ($GLOBALS["fp_system_settings"]["GRANT_FULL_ACCESS"] == TRUE) {
  2533. $form_state["passed_authentication"] = TRUE;
  2534. $form_state["db_row"]["user_id"] = 1;
  2535. $form_state["db_row"]["user_name"] = "FULL ACCESS USER";
  2536. return;
  2537. }
  2538. // Otherwise, check the table normally.
  2539. /*
  2540. $res = db_query("SELECT * FROM users WHERE user_name = '?' AND password = '?' AND is_disabled = '0' ", $user, md5($password));
  2541. if (db_num_rows($res) == 0) {
  2542. form_error("password", t("Sorry, but that username and password combination could not
  2543. be found. Please check your spelling and try again."));
  2544. return;
  2545. }
  2546. */
  2547. $res = db_query("SELECT * FROM users WHERE user_name = ? AND is_disabled = '0' ", $user);
  2548. $cur = db_fetch_array($res);
  2549. // Check the user's password is valid.
  2550. $stored_hash = @$cur["password"];
  2551. if (!user_check_password($password, $stored_hash)) {
  2552. watchdog("login", "@user has not logged in. Username/password could not be verified. Incorrect password?", array("@user" => $user), WATCHDOG_ALERT);
  2553. form_error("password", t("Sorry, but that username and password combination could not
  2554. be found. Please check your spelling and try again."));
  2555. return;
  2556. }
  2557. // Have we disabled all logins except for "admin" (user id = 1)?
  2558. if (intval($cur['user_id']) !== 1 && variable_get('disable_login_except_admin', 'no') == 'yes') {
  2559. watchdog("login", "@user has not logged in. All logins except admin are disabled.", array("@user" => $user), WATCHDOG_ALERT);
  2560. fp_goto("disable-login");
  2561. return;
  2562. }
  2563. // If this is a student, does this student have an accepted "allowed rank" (ie, FR, SO, JR, etc)?
  2564. $allowed_ranks_str = variable_get("allowed_student_ranks", "FR, SO, JR, SR");
  2565. $allowed_ranks = csv_to_array($allowed_ranks_str);
  2566. if (intval($cur['is_student']) === 1) {
  2567. $rank_code = db_result(db_query("SELECT rank_code FROM students WHERE cwid = ?", array($cur['cwid'])));
  2568. if (!in_array($rank_code, $allowed_ranks)) {
  2569. form_error("password", t("Sorry, your rank/classification is %rc. At this time FlightPath is only available to students
  2570. in the following ranks/classifications: @ranks_str", array("%rc" => $rank_code, "@ranks_str" => $allowed_ranks_str)));
  2571. watchdog("login", "@user has not logged in. User rank/classification is %rc. At this time FlightPath is only available to students
  2572. in the following ranks/classifications: @ranks_str", array("@user" => $user, "%rc" => $rank_code, "@ranks_str" => $allowed_ranks_str), WATCHDOG_ALERT);
  2573. return;
  2574. }
  2575. }
  2576. // Do we have a "whitelist" and is this user part of it? Note: ignore if we are admin.
  2577. $bool_pass_whitelist_test = FALSE;
  2578. $list = system_get_user_whitelist();
  2579. if (intval($cur['user_id']) !== 1 && $list) {
  2580. if (!in_array($cur['user_name'], $list) && !in_array($cur['cwid'], $list) && ($cur['email'] != '' && !in_array($cur['email'], $list))) {
  2581. form_error("password", t("Sorry, but only certain users are allowed access at this time. If you believe you need access, please contact your system administrator."));
  2582. watchdog("login", "@user has not logged in. Only certain users allowed at this time.", array("@user" => $user), WATCHDOG_ALERT);
  2583. return;
  2584. }
  2585. else {
  2586. // user is listed in the whitelist.
  2587. $bool_pass_whitelist_test = TRUE;
  2588. }
  2589. }
  2590. else {
  2591. // There was no whitelist.
  2592. $bool_pass_whitelist_test = TRUE;
  2593. }
  2594. // Have we disabled all student logins AND this student was not in the whitelist?
  2595. if (intval($cur['is_student']) == 1 && variable_get('disable_student_logins', 'no') == 'yes') {
  2596. if ($list && $bool_pass_whitelist_test == FALSE || !$list) {
  2597. // There was a whitelist and we didn't pass, OR, there was no whitelist.
  2598. watchdog("login", "@user has not logged in. Student logins are disabled.", array("@user" => $user), WATCHDOG_ALERT);
  2599. fp_goto("disable-student-login");
  2600. return;
  2601. }
  2602. }
  2603. // otherwise, we know it must be correct. Continue.
  2604. $form_state["db_row"] = $cur;
  2605. // If we made it here, then the user successfully authenticated.
  2606. $form_state["passed_authentication"] = TRUE;
  2607. // It will now proceed to the submit handler.
  2608. }
  2609. /**
  2610. * Submit handler for login form.
  2611. * If we are here, it probably means we have indeed authenticated. Just in case, we will
  2612. * test the form_state["passed_authentication"] value, which we expect to have been
  2613. * set in our validate handler.
  2614. *
  2615. * We will now proceed to actually log the user into the system.
  2616. *
  2617. */
  2618. function system_login_form_submit($form, &$form_state) {
  2619. $user = $form_state["values"]["user"];
  2620. $password = $form_state["values"]["password"];
  2621. $passed = $form_state["passed_authentication"];
  2622. // Special case (if we have the zoomapi module enabled). This
  2623. // lets us tell if we are trying to install zoom from the marketplace.
  2624. $zoom_install = @$form_state['values']['zoom_install'];
  2625. // Used later when we do a fp_goto.
  2626. $db_row = $form_state["db_row"];
  2627. $user_id = $db_row['user_id'];
  2628. $email = trim($db_row['email']);
  2629. if (!$passed) {
  2630. fp_add_message(t("Sorry, there has been an error while trying to authenticate the user."));
  2631. watchdog("login", "@user has not logged in. Error while trying to authenticate. Wrong password?", array("@user" => $user), WATCHDOG_ALERT);
  2632. return;
  2633. }
  2634. // if we have MFA turned on AND the user has an email address saved, then we should redirect the user now to the MFA form.
  2635. // Also check to see if we have "mfa_remember" cookie set, and is it not expired.
  2636. $mfa_enabled = variable_get("mfa_enabled", "no");
  2637. if ($email && $mfa_enabled === "yes" && (!isset($_COOKIE['flightpath_mfa_remember__' . $user_id]) || $_COOKIE['flightpath_mfa_remember__' . $user_id] !== 'yes')) {
  2638. // Craft the query so we can use it.
  2639. $_SESSION['mfa__form_state_db_row'] = $db_row;
  2640. // Create validation code
  2641. $mfa_code = mt_rand(100000, 999999);
  2642. user_set_attribute($user_id, "mfa_validation_code", $mfa_code);
  2643. // Send validation code to email.
  2644. notify_by_mail($email, "FlightPath - Validation Code", t("Your multi-factor validation code is: <strong>@code</strong>
  2645. \n\n<br><br>This code will remain valid for approximately one hour.", array("@code" => $mfa_code)));
  2646. fp_goto("mfa-login");
  2647. return;
  2648. }
  2649. // Actually log in the user.
  2650. $account = system_perform_user_login($db_row['user_id']);
  2651. // Watchdog
  2652. watchdog("login", "@user has logged in. CWID: @cwid", array("@user" => "$account->name ($account->id)", "@cwid" => $account->cwid));
  2653. if ($zoom_install == 'marketplace' && module_enabled('zoomapi')) {
  2654. fp_goto(zoomapi_get_zoom_install_url($account->id, FALSE, TRUE));
  2655. die();
  2656. }
  2657. fp_goto("<front>");
  2658. }
  2659. /**
  2660. * Actually performs the logging in of a user with user_id.
  2661. */
  2662. function system_perform_user_login($user_id) {
  2663. $_SESSION["fp_logged_in"] = TRUE;
  2664. // Set up a new $account object.
  2665. $account = new stdClass();
  2666. $account = fp_load_user($user_id);
  2667. // Set the $account to the SESSION.
  2668. $_SESSION["fp_user_object"] = $account;
  2669. db_query("UPDATE users SET last_login = ? WHERE user_id = ?", array(time(), $user_id));
  2670. return $account;
  2671. }
  2672. /**
  2673. * Formerly part of the FlightPath class, this function will read in or reload the course inventory into a
  2674. * file, which then goes into the SESSION to make it faster to access.
  2675. */
  2676. function system_reload_and_cache_course_inventory() {
  2677. // Load from file. If not there, or if we cannot unserialize, then we will rebuild cache and save new file.
  2678. if (file_exists(fp_get_files_path() . "/cache_data/courses_serialized.info")) {
  2679. if ($_SESSION["fp_cache_course_inventory"] = file_get_contents(fp_get_files_path() . "/cache_data/courses_serialized.info"))
  2680. {
  2681. if ($GLOBALS["fp_course_inventory"] = unserialize($_SESSION["fp_cache_course_inventory"])) {
  2682. $last_generated = intval(variable_get('cache_course_inventory_last_generated', 0));
  2683. $_SESSION['fp_cache_course_inventory_last_generated'] = $last_generated;
  2684. //fpm('reloading from file');
  2685. return;
  2686. }
  2687. }
  2688. }
  2689. $array_valid_names_by_course = array();
  2690. //fpm('rebuilding course cache');
  2691. //fpm("LIMIT $limit_start, $limit_size");
  2692. // To save memory, we're only going to keep a certain number of catalog years in the cache, and even then, only up to a max number of rows.
  2693. $start_year = intval(date('Y', strtotime('NOW + 1 YEAR'))); // start with one year into the future.
  2694. $end_year = intval(date('Y', strtotime('NOW - 10 YEARS'))); // end with 10 years into the past
  2695. $in_years = "";
  2696. for ($t = $end_year; $t <= $start_year; $t++) {
  2697. $in_years .= $t . ",";
  2698. }
  2699. $in_years .= "1900"; // add in the 1900 year as well.
  2700. $result = db_query("SELECT * FROM courses
  2701. WHERE delete_flag = 0
  2702. AND catalog_year IN ($in_years)
  2703. ORDER BY catalog_year DESC
  2704. LIMIT 50000");
  2705. while($cur = db_fetch_array($result))
  2706. {
  2707. $course_id = $cur["course_id"];
  2708. //$this->db->load_course_descriptive_data(null, $course_id);
  2709. $title = $cur["title"];
  2710. $description = trim($cur["description"]);
  2711. $subject_id = trim(strtoupper($cur["subject_id"]));
  2712. $course_num = trim(strtoupper($cur["course_num"]));
  2713. $cache_catalog_year = $cur['catalog_year'];
  2714. $min_hours = $cur["min_hours"];
  2715. $max_hours = $cur["max_hours"];
  2716. $repeat_hours = $cur["repeat_hours"];
  2717. if ($repeat_hours*1 == 0)
  2718. {
  2719. $repeat_hours = $max_hours;
  2720. }
  2721. $db_exclude = $cur["exclude"];
  2722. $db_school_id = $cur['school_id'];
  2723. $data_entry_comment = $cur["data_entry_comment"];
  2724. // Now, lets get a list of all the valid names for this course.
  2725. // In other words, all the non-excluded names. For most
  2726. // courses, this will just be one name. But for cross-listed
  2727. // courses, this will be 2 or more (probably just 2 though).
  2728. // Example: MATH 373 and CSCI 373 are both valid names for that course.
  2729. if (!isset($array_valid_names_by_course[$course_id])) {
  2730. $array_valid_names = array();
  2731. $res2 = db_query("SELECT * FROM courses
  2732. WHERE course_id = ?
  2733. AND delete_flag = 0 ", $course_id);
  2734. while($cur2 = db_fetch_array($res2))
  2735. {
  2736. $si = $cur2["subject_id"];
  2737. $cn = $cur2["course_num"];
  2738. if (in_array("$si~$cn", $array_valid_names))
  2739. {
  2740. continue;
  2741. }
  2742. $array_valid_names[] = "$si~$cn";
  2743. }
  2744. $array_valid_names_by_course[$course_id] = $array_valid_names;
  2745. }
  2746. $array_valid_names = $array_valid_names_by_course[$course_id];
  2747. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["subject_id"] = $subject_id;
  2748. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["course_num"] = $course_num;
  2749. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["title"] = $title;
  2750. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["description"] = $description;
  2751. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["min_hours"] = $min_hours;
  2752. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["max_hours"] = $max_hours;
  2753. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["repeat_hours"] = $repeat_hours;
  2754. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["db_exclude"] = $db_exclude;
  2755. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["school_id"] = $db_school_id;
  2756. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["array_valid_names"] = $array_valid_names;
  2757. $cache_catalog_year = 0;
  2758. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["subject_id"] = $subject_id;
  2759. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["course_num"] = $course_num;
  2760. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["title"] = $title;
  2761. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["description"] = $description;
  2762. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["min_hours"] = $min_hours;
  2763. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["max_hours"] = $max_hours;
  2764. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["repeat_hours"] = $repeat_hours;
  2765. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["db_exclude"] = $db_exclude;
  2766. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["school_id"] = $db_school_id;
  2767. $GLOBALS["fp_course_inventory"][$course_id][$cache_catalog_year]["array_valid_names"] = $array_valid_names;
  2768. $GLOBALS["cache_course_inventory"] = TRUE;
  2769. } // while cur
  2770. // Should we re-cache the course inventory? If there have been any changes
  2771. // to it, then we will see that in a GLOBALS variable...
  2772. if ($GLOBALS["cache_course_inventory"] == true)
  2773. {
  2774. $_SESSION["fp_cache_course_inventory"] = serialize($GLOBALS["fp_course_inventory"]);
  2775. }
  2776. // Save to file.
  2777. if (!is_dir(fp_get_files_path() . "/cache_data")) {
  2778. $x = mkdir(fp_get_files_path() . "/cache_data");
  2779. if (!$x) {
  2780. fpm("Cannot create cache_data directory under custom/files. Permission error?");
  2781. watchdog("system", "Cannot create cache_data directory under custom/files. Permission error?", array(), WATCHDOG_ERROR);
  2782. }
  2783. }
  2784. // It is named .info because in our htaccess, it already says that file extension cannot be downloaded.
  2785. $x = file_put_contents(fp_get_files_path() . "/cache_data/courses_serialized.info", $_SESSION["fp_cache_course_inventory"]);
  2786. if ($x === FALSE) {
  2787. fpm("Cannot create cache_data/courses_serialized.info under custom/files. Permission error?");
  2788. watchdog("system", "Cannot create cache_data/courses_serialized.info under custom/files. Permission error?", array(), WATCHDOG_ERROR);
  2789. }
  2790. // Also put in when we LAST performed this operation in a variable for reading later on.
  2791. $last_generated = time();
  2792. $_SESSION['fp_cache_course_inventory_last_generated'] = $last_generated;
  2793. variable_set('cache_course_inventory_last_generated', $last_generated);
  2794. } // system_reload_and_cache_course_inventory
  2795. /**
  2796. * Should the course inventory get reloaded from file? If so, return TRUE.
  2797. */
  2798. function system_check_course_inventory_should_be_reloaded() {
  2799. $x = intval($_SESSION['fp_cache_course_inventory_last_generated']);
  2800. $last_generated = intval(variable_get('cache_course_inventory_last_generated', 0));
  2801. if ($x !== $last_generated) {
  2802. return TRUE;
  2803. }
  2804. return FALSE;
  2805. }
  2806. /**
  2807. * This is the "dashboard" page for FlightPath, which replaces the "main" page from FP 5.
  2808. */
  2809. function system_display_dashboard_page () {
  2810. global $user;
  2811. $rtn = "";
  2812. fp_set_title('');
  2813. $render = array();
  2814. $render['#id'] = 'system_display_dashboard_page';
  2815. // If we are not logged in, then we need to re-direct the user to
  2816. // the login page!
  2817. if ($_SESSION["fp_logged_in"] != TRUE) {
  2818. $query = "";
  2819. if (isset($_REQUEST["logout"])) $query = "logout=" . $_REQUEST["logout"];
  2820. // Since we are not logged in, and are headed to the login page, also clear out any advising variables we might have.
  2821. foreach ($_REQUEST as $key => $val) {
  2822. unset($_REQUEST[$key]);
  2823. unset($_GET[$key]);
  2824. unset($_POST[$key]);
  2825. }
  2826. global $current_student_id;
  2827. $current_student_id = ""; // clear this so the fp_goto doesn't try to add it.
  2828. @session_destroy(); // In a rare occasion, the session hasn't had time to initialize yet, so this destroy triggers a warning. The @ suppresses it.
  2829. session_commit();
  2830. fp_goto("login", $query);
  2831. return;
  2832. }
  2833. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  2834. // It's a cheap hack, but when we don't have anything to show, the boxes get too small. We're going to force some spaces
  2835. // in that case, and we can tell it to display:none if we don't need it anymore in CSS.
  2836. $force_spaces = "<span class='force-spaces'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  2837. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  2838. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  2839. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  2840. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  2841. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  2842. </span>";
  2843. //////////////////////////////////////////////////////////
  2844. // To cut down on how long it takes to load huge groups
  2845. // like Free Electives, we will the course inventory from cache here.
  2846. if (@$_SESSION["fp_cached_inventory_flag_one"] != TRUE)
  2847. {
  2848. system_reload_and_cache_course_inventory();
  2849. }
  2850. $today = date("D, F jS, Y", convert_time(time()));
  2851. $dname = $user->name;
  2852. if ($user->f_name != "" || $user->l_name != "") {
  2853. $dname = trim($user->f_name . " " . $user->l_name) . " ($user->name)";
  2854. }
  2855. $render['inner_wrapper_start'] = array(
  2856. 'value' => "<div class='dashboard-inner-wrapper'>",
  2857. 'weight' => 10,
  2858. );
  2859. //$rtn .= "<div class='dashboard-inner-wrapper'>";
  2860. $render["welcome_block"] = array('value' => "<div class='dash-welcome-block'>
  2861. <div class='welcome-section'>
  2862. " . t("<h1>Welcome @dname!</h1>
  2863. <h2>Today is @today</h2>", array("@dname" => $dname, "@today" => $today)) . "
  2864. </div>
  2865. </div>",
  2866. 'weight' => 20);
  2867. /*
  2868. $rtn .= "<div class='dash-welcome-block'>
  2869. <div class='welcome-section'>
  2870. <h1>Welcome $dname!</h1>
  2871. <h2>Today is $today</h2>
  2872. </div>
  2873. </div>";
  2874. */
  2875. // Load announcements as HTML
  2876. $announcements = "";
  2877. $announcements .= "
  2878. <div class='announcements-feed-block dash-feed-block'>
  2879. " . fp_render_section_title(t("Announcements")) . "
  2880. <div class='contents'>";
  2881. $res = db_query("SELECT DISTINCT(a.cid) FROM content__announcement a, content n
  2882. WHERE a.vid = n.vid
  2883. AND a.cid = n.cid
  2884. AND n.delete_flag = 0
  2885. AND n.published = 1
  2886. ORDER BY field__activity_datetime DESC, a.vid DESC
  2887. LIMIT 7");
  2888. $bool_is_empty = TRUE;
  2889. while ($cur = db_fetch_object($res)) {
  2890. $cid = $cur->cid;
  2891. $content = content_load($cid);
  2892. // is this "faculty" visibility? If so, do we have access to view?
  2893. if ($content->field__visibility['value'] == 'faculty' && !user_has_permission('can_view_faculty_engagements')) {
  2894. continue;
  2895. }
  2896. $disp_date = date("m/d/Y g:ia", convert_time(strtotime($content->field__activity_datetime['value'])));
  2897. $bool_is_empty = FALSE;
  2898. $announcements .= "<div class='feed-item'>
  2899. <div class='feed-item-title'>$content->title</div>
  2900. <div class='feed-item-desc'>{$content->field__msg['display_value']}</div>
  2901. <div class='feed-item-datetime'>$disp_date</div>
  2902. </div>";
  2903. } // while
  2904. if ($bool_is_empty) {
  2905. $announcements .= "<div class='empty'>
  2906. <p>" . t("Sorry, there are no announcements available at this time.") . "</p>
  2907. </div>";
  2908. }
  2909. $announcements .= "$force_spaces</div> <!-- contents -->
  2910. </div> <!-- feed block --> ";
  2911. // Build up the "appoinments" HTML
  2912. $appointments = "";
  2913. $appointments .= "<div class='appointments-feed-block dash-feed-block'>
  2914. " . fp_render_section_title(t("Upcoming Appointments")) . "
  2915. <div class='contents'>";
  2916. $upcoming = calendar_get_upcoming_appointments_for_cwid($user->cwid);
  2917. $bool_is_empty = TRUE;
  2918. foreach ($upcoming as $details) {
  2919. $thedate = format_date(convert_time($details['utc_start_ts']), 'long_no_year');
  2920. $use_name = $details['faculty_name'];
  2921. if ($user->is_faculty) {
  2922. $use_name = $details['student_name'];
  2923. }
  2924. $bool_is_empty = FALSE;
  2925. $msg = t("You have an appointment with @fn on @td.", array("@fn" => $use_name, "@td" => $thedate));
  2926. $appointments .= "<div class='feed-item'>
  2927. <div class='feed-item-icon'><i class='fa fa-calendar'></i></div>
  2928. <div class='feed-item-title'>$use_name</div>
  2929. <div class='feed-item-desc'>$msg</div>
  2930. </div>";
  2931. }
  2932. if ($bool_is_empty) {
  2933. $appointments .= "<div class='empty'>
  2934. <p>" . t("You have no upcoming appointments within the next 5 days.") . "</p>
  2935. </div>
  2936. $force_spaces";
  2937. }
  2938. $appointments .= "
  2939. </div> <!-- contents -->
  2940. </div> <!-- feed-block -->
  2941. ";
  2942. $render['#user_is_faculty'] = $user->is_faculty;
  2943. if ($user->is_faculty) {
  2944. $render['dash_left_wrapper'] = array('value' => "<div class='dash-box dash-left'>", 'weight' => 30);
  2945. //$rtn .= "<div class='dash-box dash-left'>";
  2946. $render["appointments"] = array('value' => $appointments, 'weight' => 40);
  2947. //$rtn .= $appointments;
  2948. if (user_has_permission('can_view_advisee_activity_records')) {
  2949. $render["activity_feed_block_top"] = array('value' => "<div class='activity-feed-block dash-feed-block'>
  2950. " . fp_render_section_title("Advisee Activity Feed") . "
  2951. <div class='contents'>",
  2952. 'weight' => 50);
  2953. /*
  2954. $rtn .= "<div class='activity-feed-block dash-feed-block'>
  2955. " . fp_render_section_title("Advisee Activity Feed") . "
  2956. <div class='contents'>";
  2957. */
  2958. $activity = "";
  2959. // Needs to only be within my advisees list....
  2960. $adv_array = student_search_display_my_advisees(TRUE);
  2961. $student_ids = array_keys($adv_array);
  2962. $students_line = "'" . join("','", $student_ids) . "'";
  2963. $icons = array(
  2964. 'alert' => 'fa-bell-o',
  2965. 'mail' => 'fa-envelope-o',
  2966. 'comment' => 'fa-comment-o',
  2967. 'calendar' => 'fa-calendar-o',
  2968. );
  2969. $res = db_query("SELECT DISTINCT(a.cid) FROM content__activity_record a, content n
  2970. WHERE a.vid = n.vid
  2971. AND a.cid = n.cid
  2972. AND n.delete_flag = 0
  2973. AND n.published = 1
  2974. AND field__student_id IN ($students_line)
  2975. ORDER BY updated DESC, a.vid DESC
  2976. LIMIT 10");
  2977. $bool_is_empty = TRUE;
  2978. while ($cur = db_fetch_object($res)) {
  2979. $cid = $cur->cid;
  2980. $content = content_load($cid);
  2981. $student_name = fp_get_student_name($content->field__student_id['value'], TRUE);
  2982. $disp_date = date("m/d/Y g:ia", convert_time($content->updated));
  2983. $icon = $icons[$content->field__activity_type['value']];
  2984. $bool_is_empty = FALSE;
  2985. $activity .= "<div class='feed-item'>
  2986. <div class='feed-item-icon'><i class='fa $icon'></i></div>
  2987. <div class='feed-item-title'>$student_name</div>
  2988. <div class='feed-item-desc'>$content->title</div>
  2989. <div class='feed-item-datetime'>$disp_date</div>
  2990. </div>";
  2991. } // while
  2992. if (!$bool_is_empty) {
  2993. $activity .= "<div class='activity-view-all'>" . l(t("View All"), "advisee-activities", '', array('class' => 'button')) . "</div>";
  2994. }
  2995. else {
  2996. $activity .= "<div class='empty'>
  2997. <p>" . t("There is no student activity to report at this time.") . "</p>
  2998. </div>$force_spaces";
  2999. }
  3000. $render['close_activity_feed_block'] = array('value' => "$activity</div>", 'weight' => 60);
  3001. $render['close_activities_feed_block'] = array('value' => "</div> <!-- feed-block --> ", 'weight' => 70);
  3002. $render['close_left_dash_wrapper'] = array('value' => "</div> <!-- dash-box --> ", 'weight' => 80);
  3003. } // if user has permission can_view_advisee_activity_records
  3004. $render['dash_right_wrapper'] = array('value' => "<div class='dash-box dash-right'>", 'weight' => 90);
  3005. //$rtn .= "<div class='dash-box dash-right'>";
  3006. $advising_term_id = variable_get("advising_term_id", "");
  3007. $advising_term_desc = get_term_description($advising_term_id, FALSE, $user->school_id);
  3008. $url = fp_url("render-advising-snapshot-for-iframe", "window_mode=popup");
  3009. // Show slightly different if we have the schools module enabled
  3010. if (module_enabled("schools")) {
  3011. $advising_term_desc = "Current Terms";
  3012. // Get all the school ids this user is allowed to search.
  3013. $school_ids = student_search_get_school_ids_user_is_allowed_to_search();
  3014. $school_id_list = join(",", $school_ids);
  3015. $url = fp_url("render-advising-snapshot-for-iframe", "window_mode=popup&school_id_list=$school_id_list");
  3016. }
  3017. $render['advising_snapshot'] = array('value' => "<div class='snapshot-feed-block dash-feed-block'>
  3018. " . fp_render_section_title(t("Advising Snapshot for ") . $advising_term_desc) . "
  3019. <div class='contents'>
  3020. <iframe src='$url' frameborder=0 width=100% height=85></iframe>
  3021. </div>
  3022. </div>",
  3023. 'weight' => 100);
  3024. /// Do announcements under.
  3025. $render['announcements'] = array('value' => $announcements, 'weight' => 110);
  3026. $render['close_right_dash_wrapper'] = array('value' => "</div>", 'weight' => 120);
  3027. } // if is_faculty
  3028. else if ($user->is_student) {
  3029. $render['dash_left_wrapper'] = array('value' => "<div class='dash-box dash-left'>", 'weight' => 30);
  3030. $render["appointments"] = array('value' => $appointments, 'weight' => 40);
  3031. //$rtn .= "<div class='dash-box dash-left'>";
  3032. //$rtn .= $appointments;
  3033. fp_add_js(fp_get_module_path('advise') . '/js/advise.js');
  3034. $render['recent_advising_history_top'] = array('value' => "<div class='advising-history-feed-block dash-feed-block'>
  3035. " . fp_render_section_title(t("Recent Advising History")) . "
  3036. <div class='contents'>", 'weight' => 50);
  3037. // TODO: For the student advisings, we want to group together terms that were advised at the same time.
  3038. $res = db_query("SELECT * FROM advising_sessions
  3039. WHERE student_id = ?
  3040. AND is_draft = 0
  3041. AND is_empty = 0
  3042. AND delete_flag = 0
  3043. ORDER BY `posted` DESC, `term_id` DESC
  3044. LIMIT 5", $user->cwid);
  3045. $c = 0;
  3046. while($cur = db_fetch_array($res)) {
  3047. $dt = date("n/j/y g:ia",$cur['posted']);
  3048. $fac_name = fp_get_faculty_name($cur['faculty_id'], FALSE);
  3049. $html = "";
  3050. $turl = fp_url("advise/popup-display-summary", "advising_session_id=" . $cur['advising_session_id']);
  3051. $advising_session_id_array[] = $cur['advising_session_id'];
  3052. $term = get_term_description($cur['term_id'], FALSE, $user->student_id);
  3053. $link = "popupLargeIframeDialog(\"" . $turl . "\",\"" . t("Advising Session @term - @date", array("@term" => $term, "@date" => $dt)) . "\",\"\");";
  3054. $html .= "<div class='feed-item'>
  3055. <div class='feed-item-icon'><i class='fa fa-graduation-cap'></i></div>
  3056. <div class='feed-item-title'>Advised by $fac_name</div>
  3057. <a href='javascript:$link'>
  3058. <div class='feed-item-desc'>$term</div>
  3059. </a>
  3060. <div class='feed-item-datetime'>$dt</div>
  3061. </div>";
  3062. $render['recent_advising_history_row_' . $cur['advising_session_id']] = array('value' => $html, 'weight' => (200 + $c++));
  3063. }
  3064. $render['close_advising_history_contents'] = array('value' => "</div> <!-- contents -->", 'weight' => 300);
  3065. $render['close_advising_sessions_feed_block'] = array('value' => "</div> <!-- feed-block --> ", 'weight' => 310);
  3066. $render['close_left_dash_wrapper'] = array('value' => "</div> <!-- dash-box --> ", 'weight' => 320);
  3067. $render['dash_box_right_wrapper'] = array('value' => "<div class='dash-box dash-right'>", 'weight' => 330);
  3068. $render['announcements'] = array('value' => $announcements, 'weight' => 340);
  3069. $render['close_right_dash_box'] = array('value' => "</div>", 'weight' => 350);
  3070. } // if is_student
  3071. watchdog("display_dashboard", "", array());
  3072. $rtn = fp_render_content($render);
  3073. return $rtn;
  3074. } // display_dashboard_page
  3075. /**
  3076. * This is meant to be a widget which shows in the dashboard of the advising user, within an iframe, since it can
  3077. * take a while to load.
  3078. */
  3079. function system_render_advising_snapshop_for_iframe() {
  3080. $rtn = "";
  3081. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  3082. if (!isset($_SESSION["fp_pie_chart_token"])) {
  3083. $_SESSION["fp_pie_chart_token"] = md5(fp_token());
  3084. }
  3085. $school_ids = array(0);
  3086. if (isset($_REQUEST['school_id_list'])) {
  3087. $school_ids = explode(",", $_REQUEST['school_id_list']);
  3088. }
  3089. $selected_school_id = $school_ids[0];
  3090. if (isset($_REQUEST['selected_school_id'])) $selected_school_id = intval($_REQUEST['selected_school_id']);
  3091. // Get total number of advisees VS number that have been advised for current term.
  3092. $adv_array = student_search_display_my_advisees(TRUE, NULL, $selected_school_id, 9999999); // We want to get ALL advisees, so we set the limit very high.
  3093. $total = count($adv_array);
  3094. $advised_count = 0;
  3095. $advised_percent = 0;
  3096. if ($total > 0) {
  3097. foreach ($adv_array as $details) {
  3098. if (@$details['advised_image'] != "") {
  3099. $advised_count++;
  3100. }
  3101. }
  3102. $advised_percent = round($advised_count/$total * 100, 2) ;
  3103. $unfinished = 100 - $advised_percent;
  3104. $pie_chart_url_advised_percent = base_path() . "/libraries/pchart/fp_pie_chart.php?size=75&radius=35&progress=$advised_percent&unfinished=$unfinished&unfinished_col=cccccc&progress_col=5780FF&token=" . $_SESSION["fp_pie_chart_token"];
  3105. $advising_term_id = variable_get_for_school("advising_term_id", "", $selected_school_id);
  3106. $advising_term_desc = get_term_description($advising_term_id, FALSE, $selected_school_id);
  3107. // If we have more than one school, then we should also display a selector which auto-submits when changed.
  3108. $school_selector_html = "";
  3109. if (count($school_ids) > 1 && module_enabled("schools")) {
  3110. fp_add_js(fp_get_module_path("system") . "/js/snapshot.js");
  3111. $url = fp_url("render-advising-snapshot-for-iframe");
  3112. $school_selector_html .= "<div class='snapshot-school-selector'>
  3113. <form action='$url' method='GET' id='snapshot-school-selector-form'>
  3114. <input type='hidden' name='window_mode' value='popup'>
  3115. <input type='hidden' name='school_id_list' value='" . join(",", $school_ids) . "'>
  3116. <strong>School: </strong>
  3117. <select name='selected_school_id' id='selected_school_id'>";
  3118. foreach ($school_ids as $school_id) {
  3119. $sel = "";
  3120. if (intval($school_id) === $selected_school_id) $sel = "selected";
  3121. $school_selector_html .= "<option value='$school_id' $sel>" . schools_get_school_name_for_id($school_id) . "</option>";
  3122. }
  3123. $school_selector_html .= "</select>
  3124. </form>
  3125. </div>";
  3126. }
  3127. $rtn .= "<div class='snapshot-in-iframe'>
  3128. $school_selector_html
  3129. <div class='pie-image'>
  3130. <img src='$pie_chart_url_advised_percent'>
  3131. </div>
  3132. <div class='pie-term-title'>$advising_term_desc ($advising_term_id)</div>
  3133. <div class='pie-term-caption'>" . t("You have advised %p of your advisees @math", array("%p" => "$advised_percent%", "@math" => "($advised_count/$total)")) . "</div>
  3134. </div>
  3135. ";
  3136. } // if total > 0
  3137. else {
  3138. // Meaning, the user does not have any advisees assigned to them.
  3139. $rtn .= "<div class='snapshot-in-iframe'>
  3140. <div class='pie-term-title'>" . t("No Advisees") . "</div>
  3141. <div class='pie-term-caption'>" . t("You do not have any advisees assigned to you at this time.") . "</div>
  3142. </div>
  3143. ";
  3144. }
  3145. return $rtn;
  3146. } // system_render_advising_snapshop_for_iframe
  3147. /**
  3148. * Called on every page load.
  3149. */
  3150. function system_init() {
  3151. // Let's see if the $user object (for the logged-in user) has been set up.
  3152. global $user;
  3153. $user = new stdClass();
  3154. if (!isset($_SESSION["fp_user_object"])) {
  3155. $_SESSION["fp_user_object"] = new stdClass();
  3156. }
  3157. if (!isset($_SESSION["fp_user_object"]->roles[1])) $_SESSION["fp_user_object"]->roles[1] = "";
  3158. if (@$_SESSION["fp_logged_in"] == TRUE) {
  3159. // Make sure it doesn't have the anonymous user role (rid == 1).
  3160. if ($_SESSION["fp_user_object"]->roles[1] == "anonymous user") {
  3161. unset($_SESSION["fp_user_object"]->roles[1]);
  3162. }
  3163. $user = $_SESSION["fp_user_object"];
  3164. // To make sure we pick up the user's newest permissions, re-load
  3165. // the user here.
  3166. $user = fp_load_user($user->id);
  3167. }
  3168. else {
  3169. // User is anonymous, so set it up as such.
  3170. $user = fp_load_user(0);
  3171. }
  3172. // Are we in maintenance mode? If so, display a message.
  3173. if (variable_get("maintenance_mode", FALSE)) {
  3174. fp_add_message(t("@FlightPath is currently undergoing routine maintenance.
  3175. During this time, some data may appear incomplete.
  3176. We apologize for the inconvenience and appreciate your patience.", array("@FlightPath" => variable_get("system_name", "FlightPath"))), "status", TRUE);
  3177. }
  3178. // Is there an urgent message to display?
  3179. $urgent_msg = variable_get("urgent_msg", "");
  3180. if ($urgent_msg) {
  3181. fp_add_message("<b>" . t("Important Message:") . "</b> " . $urgent_msg, "status", TRUE);
  3182. }
  3183. // Since current_student_id is coming from the REQUEST, sanitize it.
  3184. $current_student_id = @$_REQUEST['current_student_id'];
  3185. $current_student_id = str_replace("'", "", $current_student_id); // remove single quotes
  3186. $current_student_id = str_replace('"', "", $current_student_id); // remove back quotes
  3187. $current_student_id = str_replace(';', "", $current_student_id); // remove semicolons
  3188. // Add in our custom JS settings.
  3189. $settings = array(
  3190. "themeLocation" => fp_theme_location(),
  3191. "currentStudentId" => $current_student_id,
  3192. "basePath" => base_path(),
  3193. // Add in the popup window options....
  3194. "popupAdminWinOptions" => variable_get("popup_admin_win_options", "toolbar=no,status=2,scrollbars=yes,resizable=yes,width=600,height=400"), // used by admin groups, edit definitions, degrees, and popup contact form.
  3195. "popupAdviseWinOptions" => variable_get("popup_advise_win_options", "toolbar=no,status=2,scrollbars=yes,resizable=yes,width=460,height=375"), // the work-horse of most of the advising popups. course desc, subs, etc.
  3196. "popupPrintWinOptions" => variable_get("popup_print_win_options", "toolbar=no,status=2,scrollbars=yes,resizable=yes,width=750,height=600"), // any printable screen is displayed in this.
  3197. );
  3198. fp_add_js($settings, "setting");
  3199. fp_add_js(fp_get_module_path("system") . "/js/system.js");
  3200. }
  3201. /**
  3202. * This is the form which an admin may use to manage the modules
  3203. * in the system.
  3204. */
  3205. function system_modules_form() {
  3206. $form = array();
  3207. $m = 0;
  3208. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  3209. $form["mark" . $m++] = array(
  3210. "value" => t("Use this form to enable or disable modules. This scans the /modules/ and then /custom/modules/
  3211. directories.") . "
  3212. " . l(t("Run DB updates?"), "admin/db-updates") . "<br><br>",
  3213. );
  3214. // Begin by scanning the /modules/ directory. Anything in there
  3215. // cannot be disabled.
  3216. $module_dirs = array();
  3217. $module_dirs[] = array("start" => "modules", "type" => t("Core"));
  3218. $module_dirs[] = array("start" => "custom/modules", "type" => t("Custom"));
  3219. // We will also add any directories which begin with an underscore in the custom/modules directory.
  3220. // For example: custom/modules/_contrib
  3221. // Let's find such directories now.
  3222. $dir_files = scandir("custom/modules");
  3223. foreach ($dir_files as $file) {
  3224. if ($file == '.' || $file == '..') continue;
  3225. if (substr($file, 0, 1) == '_' && is_dir("custom/modules/$file")) {
  3226. $module_dirs[] = array("start" => "custom/modules/$file", "type" => t("Custom/$file"));
  3227. }
  3228. }
  3229. foreach ($module_dirs as $module_dir) {
  3230. $start_dir = $module_dir["start"];
  3231. if ($dh = opendir($start_dir)) {
  3232. //$pC .= "<div class='fp-system-modules-type'>{$module_dir["type"]}</div>
  3233. // <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>";
  3234. $form["mark" . $m++] = array(
  3235. "value" => "<div class='fp-system-modules-type'>{$module_dir["type"]}</div>
  3236. <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>",
  3237. );
  3238. $pol = "even";
  3239. $dir_files = scandir($start_dir);
  3240. foreach ($dir_files as $file) {
  3241. if ($file == "." || $file == "..") continue;
  3242. if (is_dir($start_dir . "/" . $file)) {
  3243. // Okay, now look inside and see if there is a .info file.
  3244. if (file_exists("$start_dir/$file/$file.info")) {
  3245. $module = $file;
  3246. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  3247. // From the info_contents variable, split up and place into an array.
  3248. $info_details_array = array("path" => "", "module" => "",
  3249. "schema" => "", "core" => "", "description" => "",
  3250. "requires" => "", "version" => "",
  3251. "required" => "", );
  3252. $lines = explode("\n", $info_contents);
  3253. foreach ($lines as $line) {
  3254. if (trim($line) == "") continue;
  3255. $temp = explode("=", trim($line));
  3256. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  3257. }
  3258. $path = "$start_dir/$file";
  3259. $info_details_array["path"] = $path;
  3260. $info_details_array["module"] = $module;
  3261. // Expected keys:
  3262. // name, description, version, core, requires (csv), requred (true or false)
  3263. $checked = "";
  3264. $form["mark" . $m++] = array(
  3265. "value" => "<tr class='fp-system-modules-row fp-system-modules-row-$pol'>
  3266. <td width='35%'>",
  3267. );
  3268. // the Checkbox.
  3269. // Should it be checked? We can check the modules table to see if it's enabled/installed or not.
  3270. $installation_status = "";
  3271. $default_value = array();
  3272. $res = db_query("SELECT * FROM modules WHERE path = '?' ", $path);
  3273. $cur = db_fetch_array($res);
  3274. if ($cur) {
  3275. $info_details_array["enabled"] = $cur["enabled"];
  3276. if ($cur["enabled"] == "1") {
  3277. // Yes, it is checked!
  3278. $default_value = array($module => $module);
  3279. }
  3280. else if ($cur["enabled"] == "") {
  3281. $installation_status = t("not installed");
  3282. }
  3283. else if ($cur["enabled"] == "0") {
  3284. $installation_status = fp_get_js_confirm_link(t("Are you sure you wish to uninstall @module?\\nThis may remove saved data belonging to the module.", array("@module" => $module)),
  3285. ' window.location="' . fp_url("system/uninstall-module", "module=$module&path=" . urlencode($path) . "") . '"; ', t("uninstall?"));
  3286. }
  3287. // Does this module need to run db updates?
  3288. if ($cur["enabled"] == "1" && $cur["schema"] != $info_details_array["schema"] && $info_details_array["schema"] != "") {
  3289. $installation_status = "<b>" . l(t("Run db updates"), "admin/db-updates") . "</b>";
  3290. // Let's also make sure to enable a message at the top of the screen, letting the user
  3291. // know that there are needed updates.
  3292. fp_add_message("<b>" . t("Note:") . "</b> " . t("There are modules which have been updated. Please back up your database,
  3293. then run the DB Updates function below as soon as possible."), "error", TRUE);
  3294. }
  3295. }
  3296. $attributes = array();
  3297. if ($info_details_array["required"]) {
  3298. // This is a required module; it cannot be unchecked.
  3299. $attributes["disabled"] = "disabled";
  3300. }
  3301. $bool_overriding = FALSE;
  3302. // Did this module already exist in $form? In other words,
  3303. // is the module overriding a core module? If so, we need to know
  3304. // so we can display something special.
  3305. if (isset($form["cb__$module"])) {
  3306. $bool_overriding = TRUE;
  3307. }
  3308. $requires = "";
  3309. // If this module requires a higher core version of FlightPath than what we
  3310. // are running, disable and explain to the user.
  3311. if (FLIGHTPATH_VERSION != '%FP_VERSION%' && $info_details_array["requires core version"]) {
  3312. // Test to see if the current version is >= to the required core version.
  3313. if (version_compare(FLIGHTPATH_VERSION, $info_details_array["requires core version"], "<")) {
  3314. // No, it's LESS than the required version! We shouldn't be able to use this module!
  3315. $attributes["disabled"] = "disabled";
  3316. $requires .= "<div style='color: red;'>" . t("This module requires
  3317. that you run FlightPath version %fpv or higher.
  3318. You are instead running version %fpov. Please update
  3319. your core copy of FlightPath before attempting to install this
  3320. module.", array('%fpv' => $info_details_array["requires core version"],
  3321. '%fpov' => FLIGHTPATH_VERSION)) . "</div>";
  3322. }
  3323. }
  3324. // Let's see if this module is for the wrong core entirely.
  3325. if ($info_details_array["core"]) {
  3326. // Test to see if we are not the correct core version.
  3327. if (strtolower(FLIGHTPATH_CORE) != strtolower($info_details_array["core"])) {
  3328. // Nope, the wrong core version!
  3329. $attributes["disabled"] = "disabled";
  3330. $requires .= "<div style='color: red;'>" . t("This module requires
  3331. that you run FlightPath core version %fpv.
  3332. You are instead running version %fpov. Please either download
  3333. the correct version of this module for your FlightPath core version,
  3334. or update FlightPath to the required core version.", array('%fpv' => $info_details_array["core"],
  3335. '%fpov' => FLIGHTPATH_CORE)) . "</div>";
  3336. }
  3337. }
  3338. $form["cb__$module"] = array(
  3339. "type" => "checkboxes",
  3340. "options" => array($module => $info_details_array["name"]),
  3341. "value" => $default_value,
  3342. "suffix" => "<div class='fp-system-modules-machine-name'>$file</div>
  3343. <div class='fp-system-modules-installation-status'>$installation_status</div>
  3344. ",
  3345. "attributes" => $attributes,
  3346. );
  3347. // hidden variable containing the details about this module, for later use on submit.
  3348. $form["module_details__$module"] = array(
  3349. "type" => "hidden",
  3350. "value" => urlencode(serialize($info_details_array)),
  3351. );
  3352. // Version & descr.
  3353. if ($info_details_array["requires"] != "") {
  3354. $requires .= "<div class='fp-system-modules-requires hypo'>
  3355. <b>" . t("Requires:") . "</b> {$info_details_array["requires"]}
  3356. </div>";
  3357. }
  3358. // if we are overriding a module, then display something special.
  3359. if ($bool_overriding) {
  3360. $form["mark" . $m++] = array(
  3361. "value" => "<em>" . t("Overriding core module:") . "<br>{$info_details_array["name"]}</em>
  3362. <div class='fp-system-modules-machine-name'>$file</div>
  3363. <div class='fp-system-modules-installation-status'>
  3364. " . t("Use checkbox in Core section above to manage module") . "
  3365. </div>",
  3366. );
  3367. }
  3368. $form["mark" . $m++] = array(
  3369. "value" => " </td>
  3370. <td width='5%' >{$info_details_array["version"]}</td>
  3371. <td >{$info_details_array["description"]}$requires</td>
  3372. </tr>
  3373. ",
  3374. );
  3375. $pol = ($pol == "even") ? "odd" : "even";
  3376. } // if file_exists (info file)
  3377. } // if is_dir
  3378. } // while file=readdir
  3379. $form["mark" . $m++] = array(
  3380. "value" => "</table>",
  3381. );
  3382. } // if opendir($startdir)
  3383. }// foreach moduledirs
  3384. $form["submit"] = array(
  3385. "type" => "submit",
  3386. "spinner" => TRUE,
  3387. "value" => t("Submit"),
  3388. "prefix" => "<hr>",
  3389. );
  3390. return $form;
  3391. }
  3392. /**
  3393. * Submit handler for the modules form.
  3394. */
  3395. function system_modules_form_submit($form, $form_state) {
  3396. // Go through all of the checkboxes which we have "module_details" for. If there is NOT a corresponding
  3397. // checkbox, it means it wasn't checked, and should be disabled in the database. Otherwise, it means it WAS
  3398. // checked, and should be enabled/installed.
  3399. $did_something = FALSE;
  3400. foreach ($form_state["values"] as $key => $value) {
  3401. if (strstr($key, "module_details__")) {
  3402. if ($module_details = unserialize(urldecode($value))) {
  3403. $module = $module_details["module"];
  3404. // Disabling a module.
  3405. if (@$module_details["enabled"] == "1" && !isset($form_state["values"]["cb__$module"])) {
  3406. // So it WAS enabled, but now the checkbox wasn't checked. So disable it!
  3407. system_disable_module($module_details);
  3408. $did_something = TRUE;
  3409. }
  3410. // Enabling a module
  3411. if (@$module_details["enabled"] != "1" && isset($form_state["values"]["cb__$module"])) {
  3412. system_enable_module($module_details);
  3413. $did_something = TRUE;
  3414. }
  3415. }
  3416. }
  3417. }
  3418. if ($did_something) {
  3419. // Refetch all of the modules from the modules table.
  3420. fp_rebuild_modules_list();
  3421. // We should clear the cache if we did something.
  3422. fp_clear_cache();
  3423. watchdog("admin", "Saved system modules form (enabled or diabled module)");
  3424. }
  3425. }
  3426. /**
  3427. * Called from the menu (ie, a URL) this function will uninstall a module.
  3428. *
  3429. */
  3430. function system_handle_uninstall_module() {
  3431. $module = $_REQUEST["module"];
  3432. // First, let's get information about this module from the db.
  3433. $res = db_query("SELECT * FROM modules WHERE name = '?' ", $module);
  3434. $cur = db_fetch_array($res);
  3435. // Make sure it is not currently enabled.
  3436. if ($cur["enabled"] == "1") {
  3437. fp_add_message(t("Module %module not yet disabled. Disable first, then try to uninstall.", array("%module" => $module)));
  3438. return;
  3439. }
  3440. // Let's see if we can call hook_uninstall for this module.
  3441. if (include_module($module, TRUE, $cur["path"])) {
  3442. if (include_module_install($module, $cur["path"])) {
  3443. if (function_exists($module . "_uninstall")) {
  3444. call_user_func($module . "_uninstall");
  3445. }
  3446. }
  3447. }
  3448. // Remove from the database.
  3449. $res = db_query("DELETE FROM modules WHERE name = '?' ", $module);
  3450. fp_add_message(t("Uninstalled %module.", array("%module" => $module)));
  3451. fp_goto("admin/config/modules");
  3452. }
  3453. /**
  3454. * Handles the enabling (and possible installation) of module.
  3455. */
  3456. function system_enable_module($module_details) {
  3457. $module = $module_details["module"];
  3458. $path = $module_details["path"];
  3459. $bool_call_hook_install = FALSE;
  3460. // Do we need to attempt to call the hook_install function?
  3461. if (@$module_details["enabled"] == "") {
  3462. // Wasn't in the database, so we need to install it.
  3463. $schema = 0;
  3464. if (isset($module_details['schema'])) $schema = $module_details['schema'];
  3465. // Add to our table.
  3466. // (delete anything all ready there first)
  3467. $res = db_query("DELETE FROM modules WHERE `name` = ? ", $module);
  3468. // Now, add back into the table.
  3469. $res = db_query("INSERT INTO modules (`name`, `path`, `version`, `requires`, `enabled`, `type`, `schema`, `info`)
  3470. VALUES (?, ?, ?, ?, ?, ?, ?, ?)
  3471. ", $module, $path, @$module_details["version"], @$module_details["required"], 0, "module",
  3472. @intval($schema), serialize($module_details));
  3473. $bool_call_hook_install = TRUE;
  3474. fp_add_message(t("The module %module has been installed.", array("%module" => $module)));
  3475. }
  3476. // If the module has a .install file, begin by including it.
  3477. if (include_module_install($module, $path)) {
  3478. // Include the original module file first.
  3479. include_module($module, TRUE, $path);
  3480. if ($bool_call_hook_install) {
  3481. // call hook_install if it exists.
  3482. if (function_exists($module . '_install')) {
  3483. call_user_func($module . '_install');
  3484. }
  3485. }
  3486. // Now, we can call hook_enable, if it exists.
  3487. if (function_exists($module . '_enable')) {
  3488. call_user_func($module . '_enable');
  3489. }
  3490. }
  3491. // Update our table.
  3492. $res = db_query("UPDATE modules SET `enabled` = '1' WHERE `name` = ? ", $module);
  3493. fp_add_message(t("The module %module has been enabled.", array("%module" => $module)));
  3494. }
  3495. /**
  3496. * Handles the disabling of the module in question.
  3497. */
  3498. function system_disable_module($module_details) {
  3499. $module = $module_details["module"];
  3500. $path = $module_details["path"];
  3501. // This module cannot be disabled!
  3502. if ($module_details["required"] == TRUE) {
  3503. return;
  3504. }
  3505. // If the module has a "hook_disable" in it's path/module.install file, include and call it.
  3506. if (include_module_install($module, $path) && function_exists($module . '_disable')) {
  3507. call_user_func($module . '_disable');
  3508. }
  3509. // Disable it in the modules table.
  3510. $res = db_query("UPDATE modules
  3511. SET enabled = '0'
  3512. WHERE name = '?' ", $module);
  3513. fp_add_message(t("The module %module has been disabled.", array("%module" => $module)));
  3514. }

Functions

Namesort descending Description
system_block_regions Hook block regions.
system_can_access_student Used by the menu to determine if the user can access some basic information about the student (like Profile page, etc)
system_check_clean_urls This function will attempt to confirm that "clean URLs" is functioning, and allowed on this server.
system_check_course_inventory_should_be_reloaded Should the course inventory get reloaded from file? If so, return TRUE.
system_clear_cache Implements hook_clear_cache Take care of clearing caches managed by this module
system_confirm_db_updates_form Display a confirmation form before we run the db updates (hook_updates)
system_confirm_db_updates_form_submit Perform the actual hook_update calls here, send the user to a completed page.
system_cron Implementation of hook_cron
system_disable_module Handles the disabling of the module in question.
system_display_completed_db_updates Once db updates are run, display contents of this page.
system_display_dashboard_page This is the "dashboard" page for FlightPath, which replaces the "main" page from FP 5.
system_display_disable_login_page
system_display_install_finished_page This page is displayed to the user once FlightPath has been installed.
system_display_login_help_page This page will be shown when the user clicks the "Need Help Logging In?" link on the login page.
system_display_login_page Display the "login" page. This is the default page displayed to the user, at /login, if they have not logged in yet.
system_display_status_page This page displayes the results of each module's hook_status.
system_enable_module Handles the enabling (and possible installation) of module.
system_execute_php_form
system_execute_php_form_submit
system_finished_db_updates_finished
system_flightpath_can_assign_course_to_degree_id Implements hook flightpath_can_assign_course_to_degree_id
system_fp_get_student_majors Implements hook_fp_get_student_majors.
system_get_available_themes Returns back an array (suitable for FAPI) of the available themes in the system.
system_get_exclude_degree_ids_from_appears_in_counts Uses the "exclude_majors...." setting, but converts them into an array of degree_ids.
system_get_roles_for_user Return an array containing the roles which have been assigned to a specific user.
system_get_user_whitelist Returns the "whitelist" or "allow list" (from system settings) as an array. If empty, it will return FALSE
system_handle_form_submit Intercepts form submissions from forms built with the form API.
system_handle_logout
system_handle_uninstall_module Called from the menu (ie, a URL) this function will uninstall a module.
system_init Called on every page load.
system_login_form This draws the form which facilitates logins.
system_login_form_submit Submit handler for login form. If we are here, it probably means we have indeed authenticated. Just in case, we will test the form_state["passed_authentication"] value, which we expect to have been set in our validate handler.
system_login_form_validate Validate function for the login form. This is where we will do all of the lookups to verify username and password. If you want to write your own login handler (like for LDAP) this is the function you would duplicate in a custom module, then use…
system_menu
system_mfa_login_form
system_mfa_login_form_submit
system_mfa_login_form_validate
system_modules_form This is the form which an admin may use to manage the modules in the system.
system_modules_form_submit Submit handler for the modules form.
system_perform_clear_cache This function will clear our various caches by calling on the hook_clear_cache in each module.
system_perform_clear_menu_cache Clears only the menu cache
system_perform_db_updates_perform_batch_operation Performs db updates ONE module at a time.
system_perform_run_cron Called from menu, will run hook_cron() for all modules.
system_perform_user_login Actually performs the logging in of a user with user_id.
system_perm Implementation of hook_perm(). Expects to return an array of permissions recognized by this module.
system_popup_report_contact_form This is the form which lets users send an email to the FlightPath production team,
system_popup_report_contact_form_submit
system_popup_report_contact_thank_you This is the thank you page you see after submitting the contact form.
system_rebuild_css_js_query_string This function will recreate the dummy query string we add to the end of css and js files.
system_reload_and_cache_course_inventory Formerly part of the FlightPath class, this function will read in or reload the course inventory into a file, which then goes into the SESSION to make it faster to access.
system_render_advising_snapshop_for_iframe This is meant to be a widget which shows in the dashboard of the advising user, within an iframe, since it can take a while to load.
system_school_data_form This form is for the school-data, like subject code descriptions, colleges, etc.
system_school_data_form_validate Validate handler for the school_data_form.
system_settings_form This is the "system settings" form.
system_settings_form_submit Extra submit handler for the system_settings_form
system_status Implementation of hook_status Expected return is array( "severity" => "normal" or "warning" or "alert", "status" => "A message to display to the user.", );