system.module

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

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.", );