system.module

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

File

modules/system/system.module
View source
  1. <?php
  2. /**
  3. * Implementation of hook_perm().
  4. * Expects to return an array of permissions recognized by
  5. * this module.
  6. *
  7. * Ex: $a = array(
  8. * "deCanDoSomething" => array (
  9. * "title" => "Can Do Something",
  10. * "description" => "Allow the user to do something."
  11. * )
  12. * );
  13. *
  14. */
  15. function system_perm() {
  16. $perms = array (
  17. "access_logged_in_content" => array(
  18. "title" => t("Access logged-in content"),
  19. "description" => t("This should be given to all authenticated users. It simply means
  20. the user is allowed to view the logged-in area of FlightPath."),
  21. ),
  22. "administer_modules" => array(
  23. "title" => t("Administer modules"),
  24. "description" => t("This will allow a user to install, enable, disable, and uninstall modules."),
  25. ),
  26. "run_cron" => array(
  27. "title" => t("Run Cron"),
  28. "description" => t("The user may run hook_cron functions at will. Causes a new menu link to appear
  29. on the admin page."),
  30. ),
  31. "de_can_administer_system_settings" => array(
  32. "title" => t("Can administer system settings"),
  33. "description" => t("This allows the user to edit any of the FlightPath
  34. system settings."),
  35. ),
  36. "de_can_administer_school_data" => array(
  37. "title" => t("Can administer school data"),
  38. "description" => t("This allows the user to edit the school data settings for FlightPath.
  39. For example, describing college and subject codes."),
  40. ),
  41. "view_fpm_debug" => array(
  42. "title" => t("View debug output from the fpm() function"),
  43. "description" => t("The user may view debug output from the fpm() function.
  44. Useful for developers."),
  45. ),
  46. "view_system_status" => array(
  47. "title" => t("View system status"),
  48. "description" => t("The user may view the update status and other requirements of the system."),
  49. ),
  50. "execute_php" => array(
  51. "title" => t("Execute PHP code"),
  52. "description" => t("WARNING: This is a very VERY powerful and DANGEROUS permission. Only give it to
  53. developers. An 'Execute PHP' link will appear on the admin menu, which
  54. lets the user execute any arbitrary PHP code."),
  55. ),
  56. );
  57. return $perms;
  58. }
  59. /**
  60. * Implements hook flightpath_can_assign_course_to_degree_id
  61. *
  62. */
  63. function system_flightpath_can_assign_course_to_degree_id($degree_id, Course $course) {
  64. // If this course has already been assigned to another degree, should we allow it to be assigned to THIS degree?
  65. $this_major_code = fp_get_degree_major_code($degree_id);
  66. $temp = explode("|", $this_major_code);
  67. $this_first_part = trim($temp[0]); // get just the first part. Ex, ENGL|_something => ENGL
  68. //fpm('here in system fp_can_assign.....');
  69. // If the configuration is such that a course cannot be assigned to a degree's tracks, then no.
  70. // Example: if a course has been assigned to ENGL, then it can't also get assigned to ENGL|_track1
  71. if (variable_get("prevent_course_assignment_to_both_degree_and_track", "yes") == 'yes') {
  72. // Begin by checking to see what degrees the course has already been assigned to (if any)
  73. if (count($course->assigned_to_degree_ids_array)) {
  74. foreach ($course->assigned_to_degree_ids_array as $d_id) {
  75. $m_code = fp_get_degree_major_code($d_id);
  76. if ($m_code) {
  77. $temp = explode("|", $this_major_code);
  78. $m_code_first_part = trim($temp[0]); // get just the first part. Ex, ENGL|_something => ENGL
  79. // At this point, we have a major code for a degree which this course has already been assigned.
  80. // Ex: ENGL or ENGL|minor
  81. // If this degree is a track, the variable $this_major_code should equal ENGL|_whatever or, ENGL|minor_whatever.
  82. // If that condition is true, then we must return FALSE.
  83. // We will look for the presence of an underscore and a pipe symbol first, and see if this_first_part == m_code_first_part
  84. if (strstr($this_major_code, "_") && strstr($this_major_code, "|") && $this_first_part == $m_code_first_part) {
  85. // Now, if this_major_code CONTAINS m_code, then that means our condition
  86. // is true.
  87. if (strstr($this_major_code, $m_code)) {
  88. return FALSE; // meaning, no, we cannot assign this course!
  89. }
  90. }
  91. }
  92. }
  93. } //if count(assigned to degree ids array)
  94. } // if variable_get ...
  95. // Default, return TRUE
  96. return TRUE;
  97. } // hook_flightpath_can_assign_course_to_degree_id
  98. /**
  99. * Implements hook_fp_get_student_majors.
  100. *
  101. * In our case, we will use our database method and get directly from our student_degrees table.
  102. */
  103. 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) {
  104. $db = get_global_database_handler();
  105. $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);
  106. return $rtn;
  107. }
  108. /**
  109. * Return an array containing the roles which have been assigned to
  110. * a specific user.
  111. */
  112. function system_get_roles_for_user($user_id) {
  113. $rtn = array();
  114. $res = db_query("SELECT * FROM user_roles a, roles b
  115. WHERE user_id = '?'
  116. AND a.rid = b.rid ", $user_id);
  117. while ($cur = db_fetch_array($res)) {
  118. $rtn[$cur["rid"]] = $cur["name"];
  119. }
  120. // Is this person in the users table? If so, they will get the rid 2 (authenticated)
  121. // If not, they will get the role 1 (anonymous)
  122. $res2 = db_query("SELECT user_id FROM users WHERE user_id = '?' AND user_id <> '0' ", $user_id);
  123. if (db_num_rows($res2) > 0) {
  124. $rtn[2] = t("authenticated user");
  125. }
  126. else {
  127. $rtn[1] = t("anonymous user");
  128. }
  129. return $rtn;
  130. }
  131. /**
  132. * This function will attempt to confirm that "clean URLs" is functioning, and
  133. * allowed on this server.
  134. *
  135. * Returns TRUE or FALSE
  136. */
  137. function system_check_clean_urls() {
  138. // Are clean-url's enabled?
  139. // We will do this by trying to retrieve a test URL, built into index.php.
  140. // If we can get a success message back from "http://example.com/flightpath/test-clean-urls/check", then
  141. // we are good to go.
  142. // First, figure out the base URL.
  143. $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
  144. $host = $_SERVER['HTTP_HOST'];
  145. $script = $_SERVER['SCRIPT_NAME'];
  146. $base_url = $protocol . "://" . $host . $script;
  147. $base_url = str_replace("/install.php", "", $base_url);
  148. $base_url = str_replace("/index.php", "", $base_url);
  149. // Try to get our test URL's success message...
  150. $res = fp_http_request($base_url . '/test-clean-urls/check');
  151. if ($res->code != 200) {
  152. // There was an error or some other problem!
  153. // But wait-- did we get redirected?
  154. if (isset($res->redirect_code) && $res->redirect_code == 200) {
  155. return TRUE; // it's OK after all!
  156. }
  157. return FALSE;
  158. }
  159. // If we made it here, it must have worked.
  160. return TRUE;
  161. }
  162. /**
  163. * Hook block regions.
  164. *
  165. * This function simply defines which block regions we will handle. Each
  166. * block section should have a unique machine name, so it is best to namespace it with the
  167. * name of the module, then page or tab it appears on.
  168. *
  169. * The array looks like this:
  170. * return array(
  171. * "system_main" => array(
  172. * "title" => t("Main Tab"),
  173. * "regions" => array (
  174. * "left_col" => array("title" => t("Left Column")),
  175. * "right_col" => array("title" => t("Right Column")),
  176. * ),
  177. * ),
  178. * );
  179. *
  180. *
  181. * REMEMBER to make these machine-names, so only alpha numeric and underscores!
  182. */
  183. function system_block_regions() {
  184. return array(
  185. "system_main" => array(
  186. "title" => t("Main Tab"),
  187. "regions" => array (
  188. "left_col" => array("title" => t("Left Column")),
  189. "right_col" => array("title" => t("Right Column")),
  190. ),
  191. ),
  192. "system_login" => array(
  193. "title" => t("Login Page"),
  194. "regions" => array (
  195. "top" => array("title" => t("Top")),
  196. "left_col" => array("title" => t("Left Column")),
  197. "right_col" => array("title" => t("Right Column")),
  198. "bottom" => array("title" => t("Bottom")),
  199. ),
  200. ),
  201. );
  202. }
  203. function system_menu() {
  204. $items = array();
  205. $items["main"] = array(
  206. "title" => "Main",
  207. "page_callback" => "system_display_main_page",
  208. "access_callback" => TRUE,
  209. "type" => MENU_TYPE_TAB,
  210. "tab_family" => "system",
  211. "weight" => 10,
  212. "page_settings" => array(
  213. "display_greeting" => TRUE,
  214. "display_currently_advising" => TRUE,
  215. "screen_mode" => "not_advising",
  216. "page_has_search" => TRUE,
  217. ),
  218. );
  219. $items["install-finished"] = array(
  220. "title" => "Installation Finished",
  221. "page_callback" => "system_display_install_finished_page",
  222. "access_callback" => TRUE,
  223. "type" => MENU_TYPE_CALLBACK,
  224. );
  225. $items["login"] = array(
  226. "title" => "Login",
  227. "page_callback" => "system_display_login_page",
  228. "access_callback" => TRUE,
  229. "type" => MENU_TYPE_NORMAL_ITEM,
  230. );
  231. $items["disable-login"] = array(
  232. "title" => "Login Disabled",
  233. "page_callback" => "system_display_disable_login_page",
  234. "access_callback" => TRUE,
  235. "type" => MENU_TYPE_NORMAL_ITEM,
  236. );
  237. $items["admin-tools/clear-cache"] = array(
  238. "title" => "Clear all cache",
  239. "page_callback" => "system_perform_clear_cache",
  240. "access_arguments" => array("administer_modules"),
  241. "type" => MENU_TYPE_NORMAL_ITEM,
  242. );
  243. $items["admin/db-updates"] = array(
  244. "title" => "Run DB updates?",
  245. "page_callback" => "fp_render_form",
  246. "page_arguments" => array("system_confirm_db_updates_form"),
  247. "access_arguments" => array("administer_modules"),
  248. "type" => MENU_TYPE_NORMAL_ITEM,
  249. );
  250. $items["admin/completed-db-updates"] = array(
  251. "title" => "Database updates completed",
  252. "page_callback" => "system_display_completed_db_updates",
  253. "access_arguments" => array("administer_modules"),
  254. "page_settings" => array(
  255. "page_show_title" => TRUE,
  256. ),
  257. "type" => MENU_TYPE_NORMAL_ITEM,
  258. );
  259. $items["system/uninstall-module"] = array(
  260. "page_callback" => "system_handle_uninstall_module",
  261. "page_arguments" => array(2),
  262. "access_arguments" => array("administer_modules"),
  263. "type" => MENU_TYPE_CALLBACK,
  264. );
  265. $items["system-handle-form-submit"] = array(
  266. "page_callback" => "system_handle_form_submit",
  267. "access_callback" => TRUE,
  268. "type" => MENU_TYPE_CALLBACK,
  269. );
  270. $items["logout"] = array(
  271. "title" => "Logout",
  272. "page_callback" => "system_handle_logout",
  273. "access_callback" => TRUE,
  274. "type" => MENU_TYPE_CALLBACK,
  275. );
  276. $items["popup-report-contact"] = array(
  277. "title" => "Report/Contact",
  278. "page_callback" => "fp_render_form",
  279. "page_arguments" => array("system_popup_report_contact_form"),
  280. "access_callback" => TRUE,
  281. "page_settings" => array(
  282. "page_is_popup" => TRUE,
  283. "page_hide_report_error" => TRUE,
  284. ),
  285. "type" => MENU_TYPE_CALLBACK,
  286. );
  287. $items["popup-contact-form/thank-you"] = array(
  288. "title" => "Report/Contact",
  289. "page_callback" => "system_popup_report_contact_thank_you",
  290. "access_callback" => TRUE,
  291. "page_settings" => array(
  292. "page_is_popup" => TRUE,
  293. "page_hide_report_error" => TRUE,
  294. ),
  295. "type" => MENU_TYPE_CALLBACK,
  296. );
  297. //////////////// Config (admin console main menu) /////////////
  298. $items["admin/config/run-cron"] = array(
  299. "title" => "Run cron now",
  300. "description" => "Run the normal cron operations right away",
  301. "page_callback" => "system_perform_run_cron",
  302. "access_arguments" => array("run_cron"),
  303. "page_settings" => array(
  304. "menu_icon" => fp_get_module_path('system') . "/icons/bullet_go.png",
  305. ),
  306. "type" => MENU_TYPE_NORMAL_ITEM,
  307. );
  308. $items["admin/config/status"] = array(
  309. "title" => "System status",
  310. "description" => "View important notifications and updates for your installation of " . variable_get("system_name", "FlightPath"),
  311. "page_callback" => "system_display_status_page",
  312. "access_arguments" => array("view_system_status"),
  313. "page_settings" => array(
  314. "page_show_title" => TRUE,
  315. "menu_icon" => fp_get_module_path('system') . "/icons/application_view_list.png",
  316. "menu_links" => array(
  317. 0 => array(
  318. "text" => "Admin Console",
  319. "path" => "admin-tools/admin",
  320. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  321. ),
  322. ),
  323. ),
  324. "type" => MENU_TYPE_NORMAL_ITEM,
  325. "tab_parent" => "admin-tools/admin",
  326. "weight" => 50,
  327. );
  328. $items["admin/config/system-settings"] = array(
  329. "title" => "System settings",
  330. "description" => "Configure settings for FlightPath",
  331. "page_callback" => "fp_render_form",
  332. "page_arguments" => array("system_settings_form", "system_settings"),
  333. "access_arguments" => array("de_can_administer_system_settings"),
  334. "page_settings" => array(
  335. "page_has_search" => FALSE,
  336. "page_banner_is_link" => TRUE,
  337. "page_hide_report_error" => TRUE,
  338. "menu_icon" => fp_get_module_path('system') . "/icons/cog.png",
  339. "menu_links" => array(
  340. 0 => array(
  341. "text" => "Admin Console",
  342. "path" => "admin-tools/admin",
  343. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  344. ),
  345. ),
  346. ),
  347. "type" => MENU_TYPE_NORMAL_ITEM,
  348. "tab_parent" => "admin-tools/admin",
  349. );
  350. $items["admin/config/school-data"] = array(
  351. "title" => "Configure school settings",
  352. "description" => "Configure school-specific data and settings",
  353. "page_callback" => "fp_render_form",
  354. "page_arguments" => array("system_school_data_form", "system_settings"),
  355. "access_arguments" => array("de_can_administer_school_data"),
  356. "page_settings" => array(
  357. "page_has_search" => FALSE,
  358. "page_banner_is_link" => TRUE,
  359. "page_hide_report_error" => TRUE,
  360. "menu_icon" => fp_get_module_path('system') . "/icons/cog_edit.png",
  361. "menu_links" => array(
  362. 0 => array(
  363. "text" => "Admin Console",
  364. "path" => "admin-tools/admin",
  365. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  366. ),
  367. ),
  368. ),
  369. "type" => MENU_TYPE_NORMAL_ITEM,
  370. "tab_parent" => "admin-tools/admin",
  371. );
  372. $items["admin/config/modules"] = array(
  373. "title" => "Modules",
  374. "description" => "Manage which modules are enabled for your site",
  375. "page_callback" => "fp_render_form",
  376. "page_arguments" => array("system_modules_form"),
  377. "access_arguments" => array("administer_modules"),
  378. "page_settings" => array(
  379. "page_has_search" => FALSE,
  380. "page_banner_is_link" => TRUE,
  381. "page_hide_report_error" => TRUE,
  382. "menu_icon" => fp_get_module_path('system') . "/icons/bricks.png",
  383. "menu_links" => array(
  384. 0 => array(
  385. "text" => "Admin Console",
  386. "path" => "admin-tools/admin",
  387. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  388. ),
  389. ),
  390. ),
  391. "type" => MENU_TYPE_NORMAL_ITEM,
  392. "tab_parent" => "admin-tools/admin",
  393. );
  394. $items["admin/config/clear-menu-cache"] = array(
  395. "title" => "Clear menu cache",
  396. "description" => "Clear and rebuild menus and URLs",
  397. "page_callback" => "system_perform_clear_menu_cache",
  398. "access_arguments" => array("administer_modules"),
  399. "type" => MENU_TYPE_NORMAL_ITEM,
  400. "page_settings" => array(
  401. "menu_icon" => fp_get_module_path('system') . "/icons/arrow_refresh.png",
  402. ),
  403. );
  404. $items["admin/config/execute-php"] = array(
  405. "title" => "Execute PHP",
  406. "description" => "Execute arbitrary PHP on your server. Caution: could be dangerous if not understood",
  407. "page_callback" => "fp_render_form",
  408. "page_arguments" => array("system_execute_php_form", "system_settings"),
  409. "access_arguments" => array("execute_php"),
  410. "page_settings" => array(
  411. "page_has_search" => FALSE,
  412. "menu_icon" => fp_get_module_path('system') . "/icons/page_white_php.png",
  413. "page_banner_is_link" => TRUE,
  414. "page_hide_report_error" => TRUE,
  415. "menu_links" => array(
  416. 0 => array(
  417. "text" => "Admin Console",
  418. "path" => "admin-tools/admin",
  419. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  420. ),
  421. ),
  422. ),
  423. "type" => MENU_TYPE_NORMAL_ITEM,
  424. "tab_parent" => "admin-tools/admin",
  425. );
  426. return $items;
  427. }
  428. function system_display_disable_login_page() {
  429. $rtn = "";
  430. $rtn .= "<h2>Logins Currently Disabled</h2>
  431. We're sorry, but logins are disabled at this time due to maintenance on FlightPath.
  432. <br><br>Please try again later.
  433. <br><br>
  434. " . l("Return to login page", "<front>") . "";
  435. return $rtn;
  436. }
  437. function system_execute_php_form() {
  438. $form = array();
  439. $m = 0;
  440. $form["mark" . $m++] = array(
  441. "value" => t("Use this form to execute arbitrary PHP code. <b>DO NOT</b>
  442. type php tags (&lt;php ?&gt;). Be careful! Entering bad code
  443. here can harm your site. Only use if you know what you are doing."),
  444. );
  445. $form["system_execute_php"] = array(
  446. "type" => "textarea",
  447. "label" => t("Enter PHP code here:"),
  448. "value" => variable_get("system_execute_php", ""),
  449. "rows" => 20,
  450. );
  451. return $form;
  452. }
  453. function system_execute_php_form_submit($form, $form_state) {
  454. $code = trim($form_state["values"]["system_execute_php"]);
  455. if ($code == "") return;
  456. try {
  457. $res = @eval($code);
  458. // Check for errors less than PHP 7.
  459. if ($res === FALSE &&($error = error_get_last())) {
  460. fp_add_message("Error: " . $error["message"] . ". See line: " . $error["line"], "error");
  461. }
  462. }
  463. catch (ParseError $e) {
  464. // Catches PHP 7+ ParseError exceptions...
  465. fp_add_message("Exception detected: " . $e->getMessage() . ". See line: " . $e->getLine(), "error");
  466. }
  467. }
  468. /**
  469. * Display a confirmation form before we run the db updates (hook_updates)
  470. *
  471. * @return unknown
  472. */
  473. function system_confirm_db_updates_form() {
  474. $form = array();
  475. $m = 0;
  476. $form["mark" . $m++] = array(
  477. "value" => t("Are you sure you wish to run the database updates?
  478. This will find modules which have been updated, and now need to
  479. make database changes.") . "
  480. <br><br>
  481. " . t("You should back up your entire database first, just in case a problem
  482. occurs!"),
  483. );
  484. $form["submit"] = array(
  485. "type" => "submit",
  486. "value" => t("Continue"),
  487. "prefix" => "<hr>",
  488. "suffix" => "&nbsp; &nbsp; <a href='javascript: history.go(-1);'>" . t("Cancel") . "</a>",
  489. );
  490. $form["mark" . $m++] = array(
  491. "value" => t("Press only once, as this make take several moments to run."),
  492. );
  493. return $form;
  494. }
  495. /**
  496. * Perform the actual hook_update calls here, send the user to a completed page.
  497. *
  498. * @param unknown_type $form
  499. * @param unknown_type $form_state
  500. */
  501. function system_confirm_db_updates_form_submit($form, $form_state) {
  502. // We need to find modules whose schema in their .info file
  503. // is different than what's in the database.
  504. $module_dirs = array();
  505. $module_dirs[] = array("start" => "modules", "type" => t("Core"));
  506. $module_dirs[] = array("start" => "custom/modules", "type" => t("Custom"));
  507. foreach ($module_dirs as $module_dir) {
  508. $start_dir = $module_dir["start"];
  509. if ($dh = opendir($start_dir)) {
  510. while ($file = readdir($dh)) {
  511. if ($file == "." || $file == "..") continue;
  512. if (is_dir($start_dir . "/" . $file)) {
  513. // Okay, now look inside and see if there is a .info file.
  514. if (file_exists("$start_dir/$file/$file.info")) {
  515. $module = $file;
  516. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  517. // From the info_contents variable, split up and place into an array.
  518. $info_details_array = array();
  519. $lines = explode("\n", $info_contents);
  520. foreach ($lines as $line) {
  521. if (trim($line) == "") continue;
  522. $temp = explode("=", trim($line));
  523. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  524. }
  525. $path = "$start_dir/$file";
  526. $res = db_query("SELECT * FROM modules WHERE path = '?' ", $path);
  527. $cur = db_fetch_array($res);
  528. $info_details_array["enabled"] = $cur["enabled"];
  529. // Does this module need to run db updates?
  530. if (@$cur["enabled"] == "1" && @$cur["schema"] != @$info_details_array["schema"] && @$info_details_array["schema"] != "") {
  531. // YES, we need to run this module's hook_update function, if it exists.
  532. // So, let's try to do that.
  533. // If the module has a .install file, begin by including it.
  534. if (include_module_install($module, $path)) {
  535. // Include the original module file first.
  536. include_module($module, TRUE, $path);
  537. // Now, we can call hook_update, if it exists.
  538. if (function_exists($module . '_update')) {
  539. call_user_func_array($module . '_update', array($cur["schema"], $info_details_array["schema"]));
  540. }
  541. }
  542. // Okay, update the modules table for this module, and set schema to correct version.
  543. $res = db_query("UPDATE modules
  544. SET `schema` = '?'
  545. WHERE path = '?' LIMIT 1 ", $info_details_array["schema"], $path);
  546. fp_add_message(t("The module %module has run its DB updates.", array("%module" => $module)));
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. // Clear our cache
  554. fp_clear_cache();
  555. fp_goto("admin/completed-db-updates");
  556. }
  557. /**
  558. * Once db updates are run, display contents of this page.
  559. *
  560. */
  561. function system_display_completed_db_updates() {
  562. $rtn = "";
  563. $rtn .= t("Database updates have been completed. If you do not see
  564. any errors displayed, it means everything was run correctly.");
  565. $rtn .= "<br><br>
  566. <ul>";
  567. $rtn .= "<li>" . l(t("Return to Admin"), "admin-tools/admin") . "</li>
  568. <li>" . l(t("Return to Modules page"), "admin/config/modules") . "</li>
  569. </ul>";
  570. return $rtn;
  571. }
  572. /**
  573. * This page is displayed to the user once FlightPath has been installed.
  574. */
  575. function system_display_install_finished_page() {
  576. $rtn = "";
  577. // Rebuild one more time
  578. menu_rebuild_cache(FALSE);
  579. fp_show_title(TRUE);
  580. $rtn .= t("Your new installation of FlightPath is now complete.
  581. <br><br>
  582. As a security precaution, you should:
  583. <ul>
  584. <li>change the permissions
  585. on custom/settings.php so that it cannot be read or written to by unauthorized
  586. users.</li>
  587. <li>You should also rename or remove install.php so that web visitors cannot
  588. access it.</li>
  589. </ul>
  590. If you need to re-install FlightPath, delete custom/settings.php, and drop all of the tables
  591. in the database, then re-access install.php.") . "<br><br>";
  592. $rtn .= l(t("Access your new FlightPath site now."), "<front>");
  593. return $rtn;
  594. }
  595. /**
  596. * This is the thank you page you see after submitting the contact form.
  597. */
  598. function system_popup_report_contact_thank_you() {
  599. $rtn = "";
  600. $rtn .= fp_render_curved_line(t("Contact the @FlightPath Production Team", array("@FlightPath" => variable_get("system_name", "FlightPath"))));
  601. $rtn .= t("Thank you for submitting to the @FlightPath Production Team. They
  602. have received your comment and will review it shortly.", array("@FlightPath" => variable_get("system_name", "FlightPath"))) . "<br><br>";
  603. $rtn .= t("You may now close this window.");
  604. return $rtn;
  605. }
  606. /**
  607. * This is the form which lets users send an email to the FlightPath production
  608. * team,
  609. */
  610. function system_popup_report_contact_form() {
  611. $form = array();
  612. fp_set_title("");
  613. $m = 0;
  614. $form["mark" . $m++] = array(
  615. "value" => fp_render_curved_line(t("Contact the @FlightPath Production Team", array("@FlightPath" => variable_get("system_name", "FlightPath")))),
  616. );
  617. if (!user_has_permission("access_logged_in_content")) {
  618. $form["mark" . $m++] = array(
  619. "value" => t("We're sorry, but for security reasons you may only access this form
  620. if you are logged in to @FlightPath.", array("@FlightPath" => variable_get("system_name", "FlightPath"))),
  621. );
  622. return $form;
  623. }
  624. $form["mark" . $m++] = array(
  625. "value" => t("If you've noticed an error or have a suggestion, use this
  626. form to contact the @FlightPath Production Team.", array("@FlightPath" => variable_get("system_name", "FlightPath"))),
  627. );
  628. $form["category"] = array(
  629. "type" => "select",
  630. "label" => t("Please select a category"),
  631. "options" => array(
  632. t("Advising") => t("Advising"),
  633. t("Degree plan") => t("Degree plan"),
  634. t("What If?") => t("What If?"),
  635. t("Searching") => t("Searching"),
  636. t("Comments") => t("Comments"),
  637. t("Other") => t("Other"),
  638. ),
  639. );
  640. $form["comment"] = array(
  641. "type" => "textarea",
  642. "label" => t("Comment:"),
  643. );
  644. $form["submit"] = array(
  645. "type" => "submit",
  646. "value" => t("Send email"),
  647. );
  648. $form["#redirect"] = array("path" => "popup-contact-form/thank-you");
  649. return $form;
  650. }
  651. function system_popup_report_contact_form_submit($form, $form_state) {
  652. global $user;
  653. $category = strip_tags($form_state["values"]["category"]);
  654. $comment = strip_tags($form_state["values"]["comment"]);
  655. $possible_student = $_SESSION["advising_student_id"];
  656. $user_roles = implode(", ", $user->roles);
  657. $datetime = date("Y-m-d H:i:s", strtotime("now"));
  658. //$headers = "From: FlightPath-noreply@noreply.com\n";
  659. $subject = t("FLIGHTPATH REPORT CONTACT") . " - $category ";
  660. $msg = "";
  661. $msg .= t("You have received a new report/contact on") . " $datetime.\n";
  662. $msg .= t("Name:") . " $user->f_name $user->l_name ($user->name) CWID: $user->cwid \n" . t("User roles:") . " $user_roles \n\n";
  663. $msg .= t("Category:") . " $category \n";
  664. $msg .= t("Possible Student:") . " $possible_student \n";
  665. $msg .= t("Comment:") . " \n $comment \n\n";
  666. $msg .= "------------------------------------------------ \n";
  667. $themd5 = md5($user->name . $user->cwid . $comment . $user_roles . $category);
  668. if ($_SESSION["da_error_report_md5"] != $themd5)
  669. { // Helps stop people from resubmitting over and over again
  670. // (by hitting refresh, or by malicious intent)..
  671. $msg = addslashes($msg);
  672. $to = variable_get("contact_email_address", "");
  673. if ($to != "") {
  674. //mail($to,$subject,$msg,$headers);
  675. fp_mail($to,$subject,$msg);
  676. }
  677. }
  678. $_SESSION["da_error_report_md5"] = $themd5;
  679. }
  680. /**
  681. * This form is for the school-data, like subject code descriptions, colleges, etc.
  682. *
  683. */
  684. function system_school_data_form() {
  685. $form = array();
  686. $m = 0;
  687. $form["contact_email_address"] = array(
  688. "type" => "textfield",
  689. "label" => t("Contact email address:"),
  690. "value" => variable_get("contact_email_address", ""),
  691. "description" => t("Enter the email address to mail when a user accesses the
  692. Contact FlightPath Production Team popup."),
  693. );
  694. $form["school_initials"] = array(
  695. "type" => "textfield",
  696. "size" => 20,
  697. "label" => t("School initials:"),
  698. "value" => variable_get("school_initials", "DEMO"),
  699. "description" => t("Ex: ULM or BPCC"),
  700. );
  701. $form["earliest_catalog_year"] = array(
  702. "type" => "textfield",
  703. "size" => 20,
  704. "label" => t("Earliest catalog year:"),
  705. "value" => variable_get("earliest_catalog_year", "2006"),
  706. "description" => t("This is the earliest possible catalog year FlightPath may look
  707. up. Typically, this is the earliest year for which you have
  708. data (ie, when FlightPath went online.
  709. If FlightPath cannot figure out a catalog year to use,
  710. it will default to this one. Ex: 2006"),
  711. );
  712. $form["graduate_level_course_num"] = array(
  713. "type" => "textfield",
  714. "size" => 20,
  715. "label" => t("Graduate level course num:"),
  716. "value" => variable_get("graduate_level_course_num", "5000"),
  717. "description" => t("This is the course num which means 'graduate level', meaning
  718. anything above it is considered a graduate level course. Ex: 5000"),
  719. );
  720. $form["allowed_student_ranks"] = array(
  721. "type" => "textfield",
  722. "label" => t("Allowed student ranks (CSV):"),
  723. "value" => variable_get("allowed_student_ranks", "FR, SO, JR, SR"),
  724. "description" => t("This is a list of which student ranks are allowed into FlightPath.
  725. It should be separated by commas.
  726. This also affects which students you may search for on the Advisees
  727. tab. Ex: FR, SO, JR, SR"),
  728. );
  729. $form["rank_descriptions"] = array(
  730. "type" => "textarea",
  731. "label" => t("Rank descriptions:"),
  732. "rows" => 8,
  733. "value" => variable_get("rank_descriptions", "FR ~ Freshman\nSO ~ Sophomore\nJR ~ Junior\nSR ~ Senior\nPR ~ Professional\nGR ~ Graduate"),
  734. "description" => t("Enter the rank code (from above) and the description which should appear on screen, in the format:
  735. RANK ~ DESC, one per line.
  736. <br>Ex:
  737. <br>&nbsp; FR ~ Freshman
  738. <br>&nbsp; SO ~ Sophomore
  739. <br>&nbsp; JR ~ Junior
  740. <br>&nbsp; SR ~ Senior"),
  741. );
  742. $form["not_allowed_student_message"] = array(
  743. "type" => "textarea",
  744. "label" => t("Not allowed student message:"),
  745. "value" => variable_get("not_allowed_student_message", ""),
  746. "description" => t("When a student is NOT allowed into FlightPath because of their
  747. rank, this message will be displayed."),
  748. );
  749. $form["hiding_grades_message"] = array(
  750. "type" => "textarea",
  751. "label" => t("Hiding grades message:"),
  752. "value" => variable_get("hiding_grades_message", ""),
  753. "description" => t("This message will be displayed when any course on the page
  754. has its bool_hide_grade set to TRUE. If you are not using
  755. this functionality, you can leave this blank."),
  756. );
  757. $form["show_group_titles_on_view"] = array(
  758. "type" => "select",
  759. "label" => t("Show group titles on View and What If screens?"),
  760. "hide_please_select" => TRUE,
  761. "options" => array("no" => t("No"), "yes" => t("Yes")),
  762. "value" => variable_get("show_group_titles_on_view", "no"),
  763. "description" => t("If set to Yes, then group titles will be displayed in the View
  764. and What if screens, similar to how they are displayed when printing.
  765. If unsure what to select, select 'No'."),
  766. );
  767. $form["show_level_3_on_what_if_selection"] = array(
  768. "type" => "select",
  769. "label" => t("Show level-3 degree options on What If selection screen?"),
  770. "hide_please_select" => TRUE,
  771. "options" => array("no" => t("No"), "yes" => t("Yes")),
  772. "value" => variable_get("show_level_3_on_what_if_selection", "yes"),
  773. "description" => t("If set to Yes, then level 3 Track/Options will appear on the What If
  774. selection screen, if a degree is selected with available options.
  775. Setting to 'no' gives behavior more like FlightPath 4.
  776. If unsure what to select, select 'No'."),
  777. );
  778. $form["course_repeat_policy"] = array(
  779. "type" => "select",
  780. "label" => t("Course repeat policy:"),
  781. "options" => array("most_recent_exclude_previous" => t("most recent, exclude previous attempts"),
  782. "most_recent_do_not_exclude" => t("most recent, do not exclude previous attempts - \"beta\" feature"),
  783. "best_grade_exclude_others" => t("best grade, exclude other attempts - \"beta\" feature")),
  784. "value" => variable_get("course_repeat_policy", "most_recent_exclude_previous"),
  785. "hide_please_select" => TRUE,
  786. "description" => t("This setting affects the course repeat policy for FlightPath for normal courses (courses which are not allowed to be repeated normally).
  787. <br><b>If you are unsure what to select</b>, choose 'most recent, exclude previous attempts'.
  788. <br>Please see the
  789. <b><a href='http://getflightpath.com/node/1085' target='_blank'>FlightPath documentation</a></b>
  790. on how to set up this field."),
  791. );
  792. $form["what_if_catalog_year"] = array(
  793. "type" => "select",
  794. "label" => t("What If mode default catalog year:"),
  795. "options" => array("current" => t("Current catalog year only"),
  796. "student" => t("Student catalog year only [beta]"),
  797. ),
  798. "value" => variable_get("what_if_catalog_year", "current"),
  799. "hide_please_select" => TRUE,
  800. "description" => t("What should be the default catalog year that What If pulls degrees from? For some schools,
  801. changing majors means moving to the current catalog year. However, at other schools, students
  802. may remain in their current catalog year when they change majors. If you are unsure what
  803. to select, choose 'Current catalog year only.'"),
  804. );
  805. $form["ignore_courses_from_hour_counts"] = array(
  806. "type" => "textfield",
  807. "label" => t("Ignore courses from hour counts (CSV):"),
  808. "value" => variable_get("ignore_courses_from_hour_counts", ""),
  809. "description" => t("List courses, separated by comma,
  810. which should be ignored in hours counts. This helps
  811. remedial courses from being applied to hour counts.
  812. <br><b>These courses will automatically be assigned the requirement type code 'x'.</b>
  813. <br>
  814. Ex: MATH 093, ENGL 090, UNIV 1001"),
  815. );
  816. $form["term_id_structure"] = array(
  817. "type" => "textarea",
  818. "label" => t("Structure of term ID's:"),
  819. "value" => variable_get("term_id_structure", ""),
  820. "description" => t("Use this space to define termID structures, one per line.
  821. Please see the
  822. <b><a href='http://getflightpath.com/node/1085' target='_blank'>FlightPath documentation</a></b>
  823. on how to set up this field.") . "
  824. <br>&nbsp; &nbsp; &nbsp; " . t("Like so: Structure, Short Desc, Long Desc, Abbr Desc, Year Adjustment") . "
  825. <br>" . t("Ex:") . "
  826. <br>&nbsp; &nbsp; &nbsp; [Y4]60, Spring, Spring of [Y4], Spr '[Y2], [Y]
  827. <br>&nbsp; &nbsp; &nbsp; [Y4]40, Fall, Fall of [Y4-1], Fall '[Y2-1], [Y-1]",
  828. );
  829. // Let's load the subjects...
  830. $subjects = "";
  831. $query = "SELECT DISTINCT b.subject_id, a.title, a.college FROM draft_courses b LEFT JOIN subjects a
  832. ON (a.subject_id = b.subject_id)
  833. WHERE exclude = 0
  834. ORDER BY b.subject_id
  835. ";
  836. $result = db_query($query);
  837. while ($cur = db_fetch_array($result))
  838. {
  839. $title = trim($cur["title"]);
  840. $subject_id = trim($cur["subject_id"]);
  841. $college = trim($cur["college"]);
  842. $subjects .= $subject_id . " ~ " . $college . " ~ " . $title . "\n";
  843. }
  844. $form["subjects"] = array(
  845. "type" => "textarea",
  846. "label" => t("Subjects:"),
  847. "value" => $subjects,
  848. "rows" => 15,
  849. "description" => t("Enter subjects known to FlightPath (for use
  850. in popups and the Course Search, for example), one per line
  851. in this format:") . "<br>SUBJ ~ COLLEGE ~ Title<br>" . t("For example:") . "
  852. <br>&nbsp; ACCT ~ BA ~ Accounting<br>&nbsp; BIOL ~ AS ~ Biology<br>" . t("Notice
  853. the separator between the code, college, and title is 1 tilde (~). Whatespace is ignored.
  854. <br><b>Important:</b> This field cannot be set up until you have your courses
  855. fully entered. Once that occurs, the course
  856. subjects will automatically appear in this box, where you can then assign the college code
  857. and subject title."),
  858. );
  859. // Load the colleges...
  860. $colleges = "";
  861. $res = db_query("SELECT * FROM colleges ORDER BY college_code");
  862. while ($cur = db_fetch_array($res)) {
  863. $colleges .= $cur["college_code"] . " ~ " . $cur["title"] . "\n";
  864. }
  865. $form["colleges"] = array(
  866. "type" => "textarea",
  867. "label" => t("Colleges:"),
  868. "value" => $colleges,
  869. "description" => t("Enter colleges known to FlightPath, one per line, in this format:
  870. ") . "<br>COLLEGE_CODE ~ Title<br>" . t("For example:") . "
  871. <br>&nbsp; AE ~ College of Arts, Science, and Education
  872. <br>&nbsp; PY ~ College of Pharmacy<br>" . t("Notice
  873. the separator between the code and title is 1 tilde (~). Whitespace is ignored."),
  874. );
  875. // Load the degree_college data....
  876. $degree_college = "";
  877. $res = db_query("SELECT DISTINCT(major_code) FROM draft_degrees ORDER BY major_code");
  878. while ($cur = db_fetch_array($res)) {
  879. $major_code = $cur["major_code"];
  880. // Is there an assigned college already?
  881. $res2 = db_query("SELECT college_code FROM degree_college WHERE major_code = '?' ", $major_code);
  882. $cur2 = db_fetch_array($res2);
  883. $college_code = $cur2["college_code"];
  884. $degree_college .= $major_code . " ~ " . $college_code . "\n";
  885. }
  886. $form["degree_college"] = array(
  887. "type" => "textarea",
  888. "label" => t("Degree Colleges:"),
  889. "value" => $degree_college,
  890. "rows" => 15,
  891. "description" => t("Enter the degree's college, one per line, in this format:
  892. ") . "<br>MAJOR_CODE ~ COLLEGE_CODE<br>" . t("For example:") . "
  893. <br>&nbsp; ACCT ~ AE
  894. <br>&nbsp; BUSN ~ SB<br>" . t("Notice
  895. the separator between the codes is 1 tilde (~). Whitespace is ignored.
  896. <br><b>Important:</b> This field cannot be set up until you have your degrees
  897. entered. Once that occurs, the degree major codes
  898. will automatically appear in this box, where you can then assign the college code.
  899. "),
  900. );
  901. // How many decimal places allowed in substitutions?
  902. $form["sub_hours_decimals_allowed"] = array(
  903. "type" => "select",
  904. "label" => t("Substitution hours decimal places allowed:"),
  905. "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)")),
  906. "value" => variable_get("sub_hours_decimals_allowed", 2),
  907. "no_please_select" => TRUE,
  908. "description" => t("For hours with decimals (like 2.25 hours), how many numbers
  909. after the decimal place will be allowed? Affects users performing
  910. substitutions. For example, if you select \"2\" here, then
  911. a value of 1.2555 will be rejected, and the user will be asked to re-enter.
  912. 1.25, would be accepted, since it has 2 decimal places.
  913. <br>If you are unsure what to select, set to 2."),
  914. );
  915. // Auto-correct course titles?
  916. $form["autocapitalize_course_titles"] = array(
  917. "type" => "select",
  918. "label" => t("Auto-capitalize course titles?"),
  919. "options" => array("yes" => "Yes", "no" => "No"),
  920. "hide_please_select" => TRUE,
  921. "value" => variable_get("autocapitalize_course_titles", "yes"),
  922. "description" => t("If set to yes, course titles in FlightPath will be run through a capitalization
  923. filter, so that 'INTRO TO ACCOUNTING' becomes 'Intro to Accounting'.
  924. Generally, this makes the course names more attractive, but it can
  925. incorrectly capitalize acronyms and initials. Disable if you would like
  926. complete control over capitalization.
  927. <br>If unsure, set to Yes."),
  928. );
  929. // Auto-correct institution names?
  930. $form["autocapitalize_institution_names"] = array(
  931. "type" => "select",
  932. "label" => t("Auto-capitalize institution names?"),
  933. "options" => array("yes" => "Yes", "no" => "No"),
  934. "hide_please_select" => TRUE,
  935. "value" => variable_get("autocapitalize_institution_names", "yes"),
  936. "description" => t("If set to yes, transfer institution names in
  937. FlightPath will be run through a capitalization
  938. filter, so that 'UNIVERSITY OF LOUISIANA AT MONROE'
  939. becomes 'University of Louisiana at Monroe'.
  940. Like the course title setting above, this is to make
  941. inconsistent or unattractive capitalization prettier.
  942. Disable if you would like
  943. complete control over capitalization.
  944. <br>If unsure, set to Yes."),
  945. );
  946. // Only allow ghost subs for fellow ghost hours?
  947. $form["restrict_ghost_subs_to_ghost_hours"] = array(
  948. "type" => "select",
  949. "label" => t("Restrict ghost substitutions to courses with zero hours only?"),
  950. "options" => array("yes" => "Yes", "no" => "No"),
  951. "hide_please_select" => TRUE,
  952. "value" => variable_get("restrict_ghost_subs_to_ghost_hours", "yes"),
  953. "description" => t("If set to yes, courses with \"ghost\" hours may only be
  954. substituted for other courses with \"ghost\" hours. What this
  955. means is that if a course is worth zero hours, it may only be
  956. subbed for a requirement worth zero hours, and it will not appear
  957. as an option for substitutions of courses worth more than zero hours.
  958. This will not affect old subs; only new ones.
  959. <br>If unsure, set to Yes."),
  960. );
  961. $form["initial_student_course_sort_policy"] = array(
  962. "type" => "select",
  963. "label" => t("Initial student course sort policy:"),
  964. "options" => array("alpha" => "Alphabetical sort [default]", "grade" => "Best grade first (beta)"),
  965. "hide_please_select" => TRUE,
  966. "value" => variable_get("initial_student_course_sort_policy", "alpha"),
  967. "description" => t("Student courses are sorted more than once as they are evaluated by FlightPath.
  968. By default, they are sorted alphabetically first. If you change this to best-grade-first,
  969. courses will be initally sorted according to the grade they earned, in the order defined in 'Grade order CSV' below.
  970. Any student grades not defined below will be considered the lowest possible grade."),
  971. );
  972. $form["grade_order"] = array(
  973. "type" => "textfield",
  974. "label" => t("Grade order (CSV):"),
  975. "value" => variable_get("grade_order", ""),
  976. "description" => t("List all possible grades, separated by comma, from highest to lowest. This is
  977. used if you select 'Best Grade first' order above, but also is used in determining
  978. if a course fulfills a minimum grade requirement.
  979. <br>Ex: AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I"),
  980. );
  981. $form["retake_grades"] = array(
  982. "type" => "textfield",
  983. "label" => t("Retake grades (CSV):"),
  984. "value" => variable_get("retake_grades", ""),
  985. "description" => t("List grades, separated by comma, which means 'the student must
  986. retake this course. They did not earn credit.' Ex: F,W,I"),
  987. );
  988. $form["withdrew_grades"] = array(
  989. "type" => "textfield",
  990. "label" => t("Withdrew grades (CSV):"),
  991. "value" => variable_get("withdrew_grades", "W"),
  992. "description" => t("List grades, separated by comma, which means 'the student withdrew
  993. from this course. They did not earn credit.' Ex: W,WD,WF. If not sure
  994. what to enter here, just enter 'W'."),
  995. );
  996. $form["enrolled_grades"] = array(
  997. "type" => "textfield",
  998. "label" => t("Enrolled grades (CSV):"),
  999. "value" => variable_get("enrolled_grades", ""),
  1000. "description" => t("List grades, separated by comma, which means 'the student is
  1001. currently enrolled in this course.' Ex: E,AMID,BMID "),
  1002. );
  1003. /*
  1004. $form["b_or_better"] = array(
  1005. "type" => "textfield",
  1006. "label" => t("B or better grades (CSV):"),
  1007. "value" => variable_get("b_or_better", ""),
  1008. "description" => t("List grades, separated by comma, which are either a B or better."),
  1009. );
  1010. $form["c_or_better"] = array(
  1011. "type" => "textfield",
  1012. "label" => t("C or better grades (CSV):"),
  1013. "value" => variable_get("c_or_better", ""),
  1014. "description" => t("List grades, separated by comma, which are either a C or better."),
  1015. );
  1016. $form["d_or_better"] = array(
  1017. "type" => "textfield",
  1018. "label" => t("D or better grades (CSV):"),
  1019. "value" => variable_get("d_or_better", ""),
  1020. "description" => t("List grades, separated by comma, which are either a D or better."),
  1021. );
  1022. *
  1023. */
  1024. $form["minimum_substitutable_grade"] = array(
  1025. "type" => "textfield",
  1026. "size" => 3,
  1027. "label" => t("Minimum substitutable grade:"),
  1028. "value" => variable_get("minimum_substitutable_grade", "D"),
  1029. "description" => t("Enter a grade which is the minimum grade a student must have earned
  1030. for the course to be allowed in a substitution. This will affect
  1031. new substitutions, not old ones. If unsure, enter D."),
  1032. );
  1033. $form["group_min_grades"] = array(
  1034. "type" => "textfield",
  1035. "label" => t("Group requirement min grades (CSV):"),
  1036. "value" => variable_get("group_min_grades", "D,C,B,A"),
  1037. "description" => t("List grades, separated by comma, which should appear in the min grade pulldown when setting a group requirement
  1038. in a degree (this also sets the order in which they will appear). If unsure what to enter, use: D,C,B,A"),
  1039. );
  1040. $form["calculate_cumulative_hours_and_gpa"] = array(
  1041. "label" => t("Calculate student cumulative hours and GPA?"),
  1042. "type" => "checkbox",
  1043. "value" => variable_get("calculate_cumulative_hours_and_gpa", FALSE),
  1044. "description" => t("If checked, student cumulative hours and GPA will not be read from the
  1045. 'students' database table, but will instead be calculated on the fly
  1046. each time a student is loaded. If unsure what to do, check this box."),
  1047. );
  1048. $form["quality_points_grades"] = array(
  1049. "label" => t("Quality points and grades:"),
  1050. "type" => "textarea",
  1051. "value" => variable_get("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0"),
  1052. "description" => t("Enter a grade, and how many quality points it is worth, separated by
  1053. tilde (~), one per line. You must include every grade which should count
  1054. for (or against) a GPA calculation, even if it is worth zero points. For example,
  1055. if an 'F' should cause a GPA to lower (which normally it would), it should be
  1056. listed here. If a 'W' grade should simply be ignored, then DO NOT list it here.
  1057. Any grade you do not list here will be IGNORED in all GPA calculations.") . "
  1058. <br>
  1059. Ex:<blockquote style='margin-top:0; font-family: Courier New, monospace;'>
  1060. A ~ 4<br>B ~ 3<br>C ~ 2<br>D ~ 1<br>F ~ 0<br>I ~ 0</blockquote>",
  1061. );
  1062. $form["requirement_types"] = array(
  1063. "label" => t("Requirement types and codes:"),
  1064. "type" => "textarea",
  1065. "value" => variable_get("requirement_types", "g ~ General Requirements\nc ~ Core Requirements\ne ~ Electives\nm ~ Major Requirements\ns ~ Supporting Requirements\nx ~ Additional Requirements"),
  1066. "description" => t("Enter requirement type codes and descriptions, separated by a tilde (~), one
  1067. per line. <b>You may not use the code 'u'</b> as that is reserved in FlightPath.
  1068. <b>You should define what 'x' means</b>, but be aware that the code 'x' will always
  1069. designate a course whose hours should be ignored from GPA calculations.
  1070. <b>You should define what 'm' means</b>, as this is the default code applied
  1071. to a requirement if one is not entered. <b>You should define what
  1072. 'e' means</b>, as this is also the code given to courses whose types we cannot
  1073. figure out, perhaps because of a typo or intentionally. Ex: Electives.
  1074. This list also defines the order in which they will appear on screen in
  1075. Type View. By convention, codes should be lower case single-letters.") . "
  1076. <br>Ex:
  1077. <div style='padding-left: 20px; font-family: Courier New, monospace'>
  1078. g ~ General Requirements<br>
  1079. c ~ Core Requirements<br>
  1080. e ~ Electives<br>
  1081. m ~ Major Requirements<br>
  1082. s ~ Supporting Requirements<br>
  1083. x ~ Additional Requirements
  1084. </div>
  1085. Please see the
  1086. <b><a href='http://getflightpath.com/node/1085' target='_blank'>FlightPath documentation</a></b>
  1087. for more information on how to set up this field.
  1088. ",
  1089. );
  1090. // Check to make sure the gd extension is loaded, since that will be required to display
  1091. // the pie charts...
  1092. if (!extension_loaded('gd') && !extension_loaded('gd2')) {
  1093. $form["mark" . $m++] = array(
  1094. "value" => "<p class='hypo'><b>" . t("Note: it appears your web server does not have the 'GD' library
  1095. enabled for PHP. This is required to make the pie charts show up
  1096. correctly. Contact your server administrator about enabling the 'GD'
  1097. library.") . "</b></p>",
  1098. );
  1099. }
  1100. $form["pie_chart_config"] = array(
  1101. "label" => t("Pie chart configuration:"),
  1102. "type" => "textarea",
  1103. "value" => variable_get("pie_chart_config", "c ~ Core Requirements\nm ~ Major Requirements\ndegree ~ Degree Progress"),
  1104. "description" => t("Enter configuration data for the pie charts which graph a student's progress
  1105. through their degree. Enter the requirement type code, pie chart label, and optional
  1106. colors separated by tilde (~). Requirement types not found for a student will be skipped
  1107. and the chart will not be drawn. <b>Enter 'degree' for total progress.</b>") . "
  1108. <br>Ex: CODE ~ LABEL ~ [optional: UNFINISHED COLOR ~ PROGRESS COLOR ]
  1109. <div style='padding-left: 20px; font-family: Courier New, monospace'>
  1110. c ~ Core Requirements ~ 660000 ~ FFCC33<br>
  1111. m ~ Major Requirements ~ 660000 ~ 93D18B<br>
  1112. degree ~ Degree Progress ~ 660000 ~ 5B63A5
  1113. </div>",
  1114. );
  1115. $form["pie_chart_gpa"] = array(
  1116. "label" => t("Should pie charts show GPAs?"),
  1117. "type" => "select",
  1118. "options" => array("no" => "No", "yes" => "Yes"),
  1119. "value" => variable_get("pie_chart_gpa", "no"),
  1120. "hide_please_select" => TRUE,
  1121. "description" => t("If set to 'Yes', the GPA will be displayed below each pie chart on the View and What If screens.
  1122. If unsure what to select, choose 'no'."),
  1123. );
  1124. $form["developmentals_title"] = array(
  1125. "label" => t("Developmentals semester block title:"),
  1126. "type" => "textfield",
  1127. "value" => variable_get("developmentals_title", t("Developmental Requirements")),
  1128. "description" => t("This is the title of the Developmental Requirements semester block,
  1129. which appears on a student's degree plan, near the bottom, when they
  1130. have remedial courses they are required to take. If you are
  1131. unsure what to enter, use 'Developmental Requirements'."),
  1132. );
  1133. $form["developmentals_notice"] = array(
  1134. "label" => t("Developmentals notice text:"),
  1135. "type" => "textarea",
  1136. "value" => variable_get("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.")),
  1137. "description" => t("The text you enter here will be displayed below the Developmentals semester
  1138. block, explaining to the student what these courses are. For example:
  1139. 'According to our records, you are required to complete the course(s) listed
  1140. above.'"),
  1141. );
  1142. $form["graduate_level_codes"] = array(
  1143. "type" => "textfield",
  1144. "label" => t("Graduate course level codes (CSV):"),
  1145. "value" => variable_get("graduate_level_codes", "GR"),
  1146. "description" => t("List level codes, separated by comma, which should be considered graduate credit. If you do not need
  1147. to distinguish between graduate and undergraduate credit, leave this field blank.<br>If unsure, set to GR."),
  1148. );
  1149. $form["disallow_graduate_credits"] = array(
  1150. "type" => "select",
  1151. "label" => t("Disallow automatic use of graduate credits?"),
  1152. "options" => array("yes" => "Yes", "no" => "No"),
  1153. "hide_please_select" => TRUE,
  1154. "value" => variable_get("disallow_graduate_credits", "yes"),
  1155. "description" => t("If set to yes, FlightPath will not automatically use graduate credits (based on the level code the student's credit
  1156. is given in the database) to populate elective groups or on the degree plan. They may still be substituted using the
  1157. substitution system however. In order for this setting to work, the 'Graduate course level codes' field must be set above.
  1158. <br>If unsure, set to Yes."),
  1159. );
  1160. $form["display_graduate_credits_block"] = array(
  1161. "type" => "select",
  1162. "label" => t("Display graduate credits in their own semester block?"),
  1163. "options" => array("yes" => "Yes", "no" => "No"),
  1164. "hide_please_select" => TRUE,
  1165. "value" => variable_get("display_graduate_credits_block", "yes"),
  1166. "description" => t("If set to yes, FlightPath will display graduate credits in their own block, and NOT in Excess credits. The graduate block details
  1167. are set below.
  1168. <br>If unsure, set to Yes."),
  1169. );
  1170. $form["graduate_credits_block_title"] = array(
  1171. "label" => t("Graduate Credits block title:"),
  1172. "type" => "textfield",
  1173. "value" => variable_get("graduate_credits_block_title", t("Graduate Credits")),
  1174. "description" => t("This is the title of the Graduate Credits semester block (setting above),
  1175. which appears on a student's degree plan, near the bottom, when they
  1176. have graduate credits in their history (based on the credit's level code). If you are
  1177. unsure what to enter, use 'Graduate Credits'."),
  1178. );
  1179. $form["graduate_credits_block_notice"] = array(
  1180. "label" => t("Graduate Credits block notice text:"),
  1181. "type" => "textarea",
  1182. "value" => variable_get("graduate_credits_block_notice", t("These courses may not be used for undergraduate credit.")),
  1183. "description" => t("The text you enter here will be displayed below the Gradute Credits semester
  1184. block, explaining to the student what these courses are. For example:
  1185. 'These courses may not be used for undergraduate credit.'"),
  1186. );
  1187. $form["degree_classifications_level_1"] = array(
  1188. "label" => t("Degree Classifications - Level 1:"),
  1189. "type" => "textarea",
  1190. "rows" => 3,
  1191. "value" => variable_get("degree_classifications_level_1", "MAJOR ~ Major"),
  1192. "description" => t("Enter the 'level 1' (ie, top level) degree classifications, one per line, in the following format:
  1193. <br>&nbsp; &nbsp; MACHINE_NAME ~ Title
  1194. <br> Example: MAJOR ~ Major
  1195. <br>These are degrees which might be combined with
  1196. another degree, as in a double-major, or selected on their own for graduation.
  1197. For example, a degree in Computer Science, by itself would be
  1198. classified as a 'Major' by most universities. If you are unsure what to enter,
  1199. use: MAJOR ~ Major"),
  1200. );
  1201. $form["degree_classifications_level_2"] = array(
  1202. "label" => t("Degree Classifications - Level 2:"),
  1203. "type" => "textarea",
  1204. "rows" => 3,
  1205. "value" => variable_get("degree_classifications_level_2", "MINOR ~ Minor"),
  1206. "description" => t("Enter the 'level 2' degree classifications, one per line, in the following format:
  1207. <br>&nbsp; &nbsp; MACHINE_NAME ~ Title
  1208. <br> Example: MINOR ~ Minor
  1209. <br>These are degrees which might be combined with another degree
  1210. but are not selected by themselves for graduation. Most universities
  1211. would consider this type to be a 'Minor'. For example, a student
  1212. might Major in Computer Science, with a Minor in Math. In this instance,
  1213. Math would be classified by this level. If you are unsuare what to enter, use:
  1214. MINOR ~ Minor"),
  1215. );
  1216. $form["degree_classifications_level_3"] = array(
  1217. "label" => t("Degree Classifications - Level 3 (Add-on degrees, attached to other degrees):"),
  1218. "type" => "textarea",
  1219. "rows" => 3,
  1220. "value" => variable_get("degree_classifications_level_3", "CONC ~ Concentration"),
  1221. "description" => t("Enter the 'level 3' degree classifications, one per line, in the following format:
  1222. <br>&nbsp; &nbsp; MACHINE_NAME ~ Title
  1223. <br> Example: CONC ~ Concentration
  1224. <br>These are degree plans which are only ever 'attached' to other degree plans as an add-on option
  1225. to the student.
  1226. For example, Computer Science might have an Option or Track or Concentration in 'Business'.
  1227. The Business concentration would ONLY be selectable if the student were already majoring in Computer Science,
  1228. therefor it would fall into this classification.
  1229. If unsure what to enter here, use: CONC ~ Concentration"),
  1230. );
  1231. $form["exclude_majors_from_appears_in_counts"] = array(
  1232. "label" => t("Exclude major codes from \"appears in\" counts (CSV):"),
  1233. "type" => "textfield",
  1234. "maxlength" => 1000,
  1235. "value" => variable_get("exclude_majors_from_appears_in_counts", ""),
  1236. "description" => t('When a course appears in more than one degree, it is given an extra CSS class
  1237. denoting that. This fields lets you enter major codes for degrees, separated by commas,
  1238. for any degrees you do not wish to be counted toward the "appears in" counts.
  1239. <br>&nbsp; &nbsp; Ex: UGELEC, ACCTB
  1240. <br>If you are unsure what to enter, leave this field blank.'),
  1241. );
  1242. $form["group_full_at_min_hours"] = array(
  1243. "label" => t("Groups should be considered 'full' when min hours are met or exceeded?"),
  1244. "type" => "select",
  1245. "options" => array("yes" => "Yes", "no" => "No"),
  1246. "value" => variable_get("group_full_at_min_hours", "yes"),
  1247. "hide_please_select" => TRUE,
  1248. "description" => t("If a group has been added to a degree plan with 'min hours', should FlightPath consider the group
  1249. 'full', and stop assigning courses to it, once the assigned courses meets or goes over the min hours value,
  1250. even if the max hours have not been fulfilled? This
  1251. only affects groups which have been added to a degree plan with min hours set. Ex: 3-6 hours.
  1252. If you are unsure what to enter, select 'Yes'"),
  1253. );
  1254. $form["remove_advised_when_course_taken"] = array(
  1255. "label" => t("Remove an advised course when a student enrolls in it (or completes it), for the same term?"),
  1256. "type" => "select",
  1257. "options" => array("yes" => "Yes", "no" => "No"),
  1258. "value" => variable_get("remove_advised_when_course_taken", "no"),
  1259. "hide_please_select" => TRUE,
  1260. "description" => t("If a student has been advised into a course, and then enrolls in that course before the next
  1261. advising term begins, should the advised course (and checkbox) be removed? This would also affect
  1262. courses the student completes within that term. The default is 'No', meaning advising checkboxes in View
  1263. will continue to show, even if the student has enrolled or completes the course that term. The checkboxes
  1264. will disappear when the advising term is no longer available for advising.
  1265. Select 'Yes' if you wish to have FlightPath hide advising checkboxes on the View screen when a student
  1266. is enrolled or completes a course within the same advising term. If you are unsure what to enter, select 'No'."),
  1267. );
  1268. $form["prevent_course_assignment_to_both_degree_and_track"] = array(
  1269. "label" => t("Prevent a course assignment to both a degree and its track(s)?"),
  1270. "type" => "select",
  1271. "options" => array("yes" => "Yes", "no" => "No"),
  1272. "value" => variable_get("prevent_course_assignment_to_both_degree_and_track", "yes"),
  1273. "hide_please_select" => TRUE,
  1274. "description" => t("If set to 'Yes' (default), then FlightPath will not allow the same course to be assigned to both a Level-1 degree
  1275. and its tracks. For example, if a student completes ENGL 101, and it can be assigned to the major COMPSCI, then
  1276. it cannot also be assigned to the track COMPSCI|_OPT1. If you are unsure what to select, leave this set to 'Yes'."),
  1277. );
  1278. $form["group_list_course_show_repeat_information"] = array(
  1279. "label" => t("Display 'Repeat Information' for a course in a group's course list?"),
  1280. "type" => "select",
  1281. "options" => array("yes" => "Yes", "no" => "No"),
  1282. "value" => variable_get("group_list_course_show_repeat_information", "yes"),
  1283. "hide_please_select" => TRUE,
  1284. "description" => t("If set to 'Yes' (default), FlightPath will how many times a groups may be repeated, when viewing a list
  1285. of a Group's courses in a popup. If set to 'No', repeat information will not be displayed, and instead
  1286. the course's normal hour information is displayed. If you
  1287. are unsure what to select, leave this set to 'Yes'."),
  1288. );
  1289. return $form;
  1290. }
  1291. /**
  1292. * Uses the "exclude_majors...." setting, but converts them into an array of degree_ids.
  1293. */
  1294. function system_get_exclude_degree_ids_from_appears_in_counts() {
  1295. // Have we already cached this for this page load?
  1296. if (isset($GLOBALS["exclude_degree_ids_from_appears_in_counts"])) {
  1297. return $GLOBALS["exclude_degree_ids_from_appears_in_counts"];
  1298. }
  1299. $db = get_global_database_handler();
  1300. $rtn = array();
  1301. $majors = csv_to_array(variable_get("exclude_majors_from_appears_in_counts", ""));
  1302. foreach ($majors as $major_code) {
  1303. $rtn = array_merge($rtn, $db->get_degree_ids($major_code));
  1304. }
  1305. $GLOBALS["exclude_degree_ids_from_appears_in_counts"] = $rtn; // cache for next time.
  1306. return $rtn;
  1307. } //system_get_exclude_degree_ids_from_appears_in_counts
  1308. /**
  1309. * Validate handler for the school_data_form.
  1310. *
  1311. * Most of our data can be saved as simple system_settings, but for the others,
  1312. * we want to save them to special tables, then remove them from the form_state so
  1313. * they don't get saved to the variables table, taking up a lot of space.
  1314. *
  1315. * @param unknown_type $form
  1316. * @param unknown_type $form_state
  1317. */
  1318. function system_school_data_form_validate($form, &$form_state) {
  1319. // Subjects...
  1320. db_query("TRUNCATE TABLE subjects");
  1321. $subjects = trim($form_state["values"]["subjects"]);
  1322. $lines = explode("\n", $subjects);
  1323. foreach ($lines as $line) {
  1324. $temp = explode("~", $line);
  1325. db_query("INSERT INTO subjects (subject_id, college, title)
  1326. VALUES ('?', '?', '?') ", strtoupper(trim($temp[0])), strtoupper(trim($temp[1])), trim($temp[2]));
  1327. }
  1328. // Remove the data from our form_state, so it isn't saved twice
  1329. unset($form_state["values"]["subjects"]);
  1330. // Colleges...
  1331. db_query("TRUNCATE TABLE colleges");
  1332. $contents = trim($form_state["values"]["colleges"]);
  1333. $lines = explode("\n", $contents);
  1334. foreach ($lines as $line) {
  1335. $temp = explode("~", $line);
  1336. db_query("INSERT INTO colleges (college_code, title)
  1337. VALUES ('?', '?') ", strtoupper(trim($temp[0])), trim($temp[1]));
  1338. }
  1339. // Remove the data from our form_state, so it isn't saved twice
  1340. unset($form_state["values"]["colleges"]);
  1341. // Degree College...
  1342. db_query("TRUNCATE TABLE degree_college");
  1343. $contents = trim($form_state["values"]["degree_college"]);
  1344. $lines = explode("\n", $contents);
  1345. foreach ($lines as $line) {
  1346. $temp = explode("~", $line);
  1347. db_query("INSERT INTO degree_college (major_code, college_code)
  1348. VALUES ('?', '?') ", strtoupper(trim($temp[0])), strtoupper(trim($temp[1])));
  1349. }
  1350. // Remove the data from our form_state, so it isn't saved twice
  1351. unset($form_state["values"]["degree_college"]);
  1352. }
  1353. /**
  1354. * Returns back an array (suitable for FAPI) of the available themes in the system.
  1355. */
  1356. function system_get_available_themes() {
  1357. $rtn = array();
  1358. // First, search for themes in our core folder. Themes must have a .info file which matches
  1359. // their folder name, just like modules.
  1360. $theme_dirs = array();
  1361. $theme_dirs[] = array("start" => "themes", "type" => t("Core"));
  1362. $theme_dirs[] = array("start" => "custom/themes", "type" => t("Custom"));
  1363. foreach ($theme_dirs as $theme_dir) {
  1364. $start_dir = $theme_dir["start"];
  1365. $type_dir = $theme_dir['type'];
  1366. if ($dh = @opendir($start_dir)) {
  1367. $dir_files = scandir($start_dir);
  1368. foreach ($dir_files as $file) {
  1369. if ($file == "." || $file == "..") continue;
  1370. if (is_dir($start_dir . "/" . $file)) {
  1371. // Okay, now look inside and see if there is a .info file.
  1372. if (file_exists("$start_dir/$file/$file.info")) {
  1373. $theme = $file;
  1374. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  1375. // From the info_contents variable, split up and place into an array.
  1376. $info_details_array = array("name" => t("Name Not Set. Configure theme's .info file."), "path" => "", "module" => "",
  1377. "schema" => "", "core" => "", "description" => "",
  1378. "requires" => "", "version" => "",
  1379. "required" => "", );
  1380. $lines = explode("\n", $info_contents);
  1381. foreach ($lines as $line) {
  1382. if (trim($line) == "") continue;
  1383. $temp = explode("=", trim($line));
  1384. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  1385. }
  1386. $path = "$start_dir/$file";
  1387. $rtn[$path] = $info_details_array['name'] . "<div style='font-size: 0.8em; font-style: italic; padding-left: 40px;'>{$info_details_array['description']}
  1388. <br>(Type: $type_dir &nbsp; &nbsp; Location: $path)</div>";
  1389. } // if file_exists
  1390. } //if is_dir
  1391. } //foreach dir_files as $file
  1392. } // if we can opendir
  1393. } // foreach theme_dirs as theme_dir
  1394. return $rtn;
  1395. }
  1396. /**
  1397. * This is the "system settings" form.
  1398. */
  1399. function system_settings_form() {
  1400. $form = array();
  1401. $m = 0;
  1402. $form["mark" . $m++] = array(
  1403. "value" => t("Use this form to alter the various system settings in FlightPath.
  1404. Before making changes, it is always good policy to first back up your database."),
  1405. );
  1406. $form["mark" . $m++] = array(
  1407. "value" => "<p><div style='font-size:0.8em;'>" . t("Your site requires a cron job in order to perform routine tasks. This
  1408. is accomplished by having your server access the following URL every so often
  1409. (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>
  1410. <br>" . t("Example linux cron command:") . "&nbsp; <i>wget -O - -q -t 1 http://ABOVE_URL</i></div></p>",
  1411. );
  1412. $form["maintenance_mode"] = array(
  1413. "label" => t("Set maintenance mode?"),
  1414. "type" => "checkbox",
  1415. "value" => variable_get("maintenance_mode", FALSE),
  1416. "description" => t("If checked, a message will display on every page stating
  1417. that the system is currently undergoing routine maintenance."),
  1418. );
  1419. $form["disable_login_except_admin"] = array(
  1420. "type" => "select",
  1421. "label" => t("Disable all new logins (except admin user)?"),
  1422. "hide_please_select" => TRUE,
  1423. "options" => array("no" => t("No"), "yes" => t("Yes")),
  1424. "value" => variable_get('disable_login_except_admin', 'no'),
  1425. "description" => t("If set to Yes, then when normal users attempt to log in, they will be
  1426. sent back to the login page, with a message displayed explaning that
  1427. logins are disabled. Admin will still be able to log in. This
  1428. is useful when trying to perform maintenance on FlightPath. If unsure
  1429. what to select, select 'No'."),
  1430. );
  1431. $form["system_name"] = array(
  1432. "type" => "textfield",
  1433. "label" => t("System Name:"),
  1434. "value" => variable_get("system_name", "FlightPath"),
  1435. "description" => t("This is the name of this software system. Ex: FlightPath. This setting allows you to re-name this
  1436. system for you school. You will also need to create new themes, and edit where the name FlightPath
  1437. is hard-coded in the template files. This will only change the name FlightPath in user-facing pages,
  1438. it will still appear in admin sections. After changing this value, clear your cache, as several
  1439. menu items will need to be updated."),
  1440. );
  1441. // Can we support clean_urls?
  1442. $bool_support_clean = system_check_clean_urls();
  1443. $form["support_clean_urls"] = array(
  1444. "type" => "hidden",
  1445. "value" => ($bool_support_clean) ? "yes" : "no",
  1446. );
  1447. if ($bool_support_clean) {
  1448. // Give the option to change ONLY if we can support clean URLs
  1449. $form["clean_urls"] = array(
  1450. "type" => "checkbox",
  1451. "label" => t("Enable 'Clean URLs?'"),
  1452. "value" => variable_get("clean_urls", FALSE),
  1453. "description" => t("Your server supports 'clean URLs', which eliminates 'index.php?q=' from your URLs, making them
  1454. more readable. It is recommended you leave this feature enabled. For more information, see: http://getflightpath.com/node/5."),
  1455. );
  1456. }
  1457. else {
  1458. // Server does not support clean URLs.
  1459. $form["support_clean_markup"] = array(
  1460. "value" => "<p><b>Clean URLs:</b> This server <u>does not support</u> clean URLs. If you are using an Apache-compatible server,
  1461. make sure that your .htaccess file is properly configured. For more information, see: http://getflightpath.com/node/5.</p>",
  1462. );
  1463. }
  1464. $form["theme"] = array(
  1465. "type" => "radios",
  1466. "label" => t("Theme:"),
  1467. "options" => system_get_available_themes(),
  1468. "value" => variable_get("theme", "themes/classic"),
  1469. "description" => t("Select the theme you wish to use. Ex: Classic (themes/classic)"),
  1470. );
  1471. $form["notify_apply_draft_changes_email_address"] = array(
  1472. "type" => "textfield",
  1473. "label" => t("Notify apply draft changes email address:"),
  1474. "value" => variable_get("notify_apply_draft_changes_email_address", ""),
  1475. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  1476. draft changes are applied from the admin console.
  1477. Leave blank to disable."),
  1478. );
  1479. $form["notify_mysql_error_email_address"] = array(
  1480. "type" => "textfield",
  1481. "label" => t("Notify MySQL error email address:"),
  1482. "value" => variable_get("notify_mysql_error_email_address", ""),
  1483. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  1484. a mysql error occurs.
  1485. Leave blank to disable."),
  1486. );
  1487. $form["notify_php_error_email_address"] = array(
  1488. "type" => "textfield",
  1489. "label" => t("Notify PHP error email address:"),
  1490. "value" => variable_get("notify_php_error_email_address", ""),
  1491. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  1492. a PHP warning or error occurs. Leave blank to disable. Recommendation: disable
  1493. on development, but enable on production."),
  1494. );
  1495. $form["admin_transfer_passcode"] = array(
  1496. "type" => "textfield",
  1497. "label" => t("Admin Apply Draft password:"),
  1498. "value" => variable_get("admin_transfer_passcode", "changeMe"),
  1499. "description" => t("Enter a password which an admin user must enter
  1500. in order to apply draft changes to FlightPath.
  1501. This is an added security measure. Ex: p@ssWord569w"),
  1502. );
  1503. $options = array(
  1504. "90" => "90 days",
  1505. "180" => "180 days",
  1506. "365" => "1 year (365 days)",
  1507. "548" => "1.5 years (548 days)",
  1508. "730" => "2 years (730 days)",
  1509. "912" => "2.5 years (912 days)",
  1510. "never" => t("Never - Do not trim log table"),
  1511. );
  1512. $form["max_watchdog_age"] = array(
  1513. "type" => "select",
  1514. "label" => t("Max watchdog (log) entry age:"),
  1515. "hide_please_select" => TRUE,
  1516. "options" => $options,
  1517. "value" => variable_get("max_watchdog_age", "548"),
  1518. "description" => t("Keep entries in the watchdog log tables until they are this old.
  1519. Entries older than this will be deleted at every cron run.
  1520. For example, if you only want to keep log entries for 1 year, then
  1521. set this to 1 year.
  1522. <b>Warning:</b> the Stats module uses data in this table to create
  1523. statistics and reports about use of FlightPath. Once data is removed from the
  1524. watchdog table, it cannot be retrieved again.
  1525. <br>If you are unsure what to put here, select '1.5 years'."),
  1526. );
  1527. $form["popup_admin_win_options"] = array(
  1528. "type" => "textfield",
  1529. "size" => 80,
  1530. "label" => t("Javascript Popup Admin Window Options:"),
  1531. "value" => variable_get("popup_admin_win_options", "toolbar=no,status=2,scrollbars=yes,resizable=yes,width=600,height=400"),
  1532. "description" => t("This is the popup javascript options for the 'Admin' popup window. This popup is used for
  1533. assigning groups in degree edit, editing definitions, and the popup contact window.
  1534. <br><b>DO NOT ENTER ANY SPACES OR QUOTES! Entering invalid syntax could break your Javascript.</b>
  1535. <br>If unsure what to enter, use: <em>toolbar=no,status=2,scrollbars=yes,resizable=yes,width=600,height=400</em>"),
  1536. );
  1537. $form["popup_advise_win_options"] = array(
  1538. "type" => "textfield",
  1539. "size" => 80,
  1540. "label" => t("Javascript Popup Advise Window Options:"),
  1541. "value" => variable_get("popup_advise_win_options", "toolbar=no,status=2,scrollbars=yes,resizable=yes,width=460,height=375"),
  1542. "description" => t("This is the popup javascript options for the 'Advising' popup window. This popup is used for
  1543. course descriptions, group selections, substitutions, etc.
  1544. <br><b>DO NOT ENTER ANY SPACES OR QUOTES! Entering invalid syntax could break your Javascript.</b>
  1545. <br>If unsure what to enter, use: <em>toolbar=no,status=2,scrollbars=yes,resizable=yes,width=460,height=375</em>"),
  1546. );
  1547. $form["popup_print_win_options"] = array(
  1548. "type" => "textfield",
  1549. "size" => 80,
  1550. "label" => t("Javascript Popup Print Window Options:"),
  1551. "value" => variable_get("popup_print_win_options", "toolbar=no,status=2,scrollbars=yes,resizable=yes,width=750,height=600"),
  1552. "description" => t("This is the popup javascript options for the 'Print' popup window. This popup is used for
  1553. printable views of degree plans.
  1554. <br><b>DO NOT ENTER ANY SPACES OR QUOTES! Entering invalid syntax could break your Javascript.</b>
  1555. <br>If unsure what to enter, use: <em>toolbar=no,status=2,scrollbars=yes,resizable=yes,width=750,height=600</em>"),
  1556. );
  1557. $form["admin_degrees_default_allow_dynamic"] = array(
  1558. "type" => "textfield",
  1559. "size" => 5,
  1560. "label" => t("Default 'Allow Dynamic' value for new degrees:"),
  1561. "value" => variable_get("admin_degrees_default_allow_dynamic", "0"),
  1562. "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
  1563. the degree is allowed to be dynamic, meaning it can be combined with other 'dynamic' degrees. If it is set to 0 (zero), it
  1564. means the degree is not allowed to be combined with anything else. If you are unsure what to enter here, type 0 (zero)."),
  1565. );
  1566. $form["enable_legacy_concentrations"] = array(
  1567. "label" => t("Enable legacy concentrations?"),
  1568. "type" => "checkbox",
  1569. "value" => variable_get("enable_legacy_concentrations", FALSE),
  1570. "description" => t("If checked, FlightPath will instruct users creating new degrees (and in other places) to
  1571. enter concentrations with a | (pipe) symbol. This is how concentrations were handled in FlightPath 4x and
  1572. before-- as entirely separate degrees. However, this can cause confusion if Dynamic Degrees
  1573. and/or Level-3 degrees are being utilized, as a concentration is a similar concept as a level-3 track, and some schools
  1574. may even name it as such. If you are unsure what to do, leave this unchecked."),
  1575. );
  1576. return $form;
  1577. }
  1578. /**
  1579. * Extra submit handler for the system_settings_form
  1580. *
  1581. * @param unknown_type $form
  1582. * @param unknown_type $form_state
  1583. */
  1584. function system_settings_form_submit($form, &$form_state) {
  1585. // Left empty for now.
  1586. }
  1587. /**
  1588. * Implementation of hook_cron
  1589. *
  1590. * We will perform operations necessary for keep FlightPath's tables in shape.
  1591. *
  1592. */
  1593. function system_cron() {
  1594. // Should we "trim" the watchdog table of old entries?
  1595. $max_age_days = variable_get("max_watchdog_age", "548");
  1596. if ($max_age_days != "never" && ($max_age_days*1) > 0) {
  1597. // Okay, let's trim the table.
  1598. $max_timestamp = strtotime("$max_age_days DAYS AGO");
  1599. $result = db_query("DELETE FROM watchdog WHERE `timestamp` < ? ", $max_timestamp);
  1600. $rows = db_affected_rows($result);
  1601. if ($rows > 0) {
  1602. 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)));
  1603. }
  1604. }
  1605. }
  1606. /**
  1607. * Intercepts form submissions from forms built with the form API.
  1608. */
  1609. function system_handle_form_submit() {
  1610. $callback = $_REQUEST["callback"];
  1611. $form_type = $_REQUEST["form_type"];
  1612. $form_include = $_REQUEST["form_include"];
  1613. $form_token = $_REQUEST["form_token"];
  1614. // Make sure the form_token is valid!
  1615. if ($form_token != md5($callback . fp_token())) {
  1616. die(t("Sorry, but you have encountered an error. A form submission was flagged
  1617. as possibly being an invalid or forged submission. This may constitute a bug
  1618. in the system. Please report this error to your Systems Administrator."));
  1619. }
  1620. if ($form_include != "") {
  1621. // This is a file we need to include in order to complete the submission process.
  1622. // We will also make sure that we only allow certain file extensions to be included.
  1623. $allowed_ext = array(
  1624. "php",
  1625. "inc",
  1626. "class",
  1627. "module",
  1628. );
  1629. $temp = explode(".", $form_include);
  1630. $test_ext = trim($temp[count($temp) - 1]);
  1631. if (!in_array($test_ext, $allowed_ext)) {
  1632. fp_add_message(t("Include file type (%ext) not allowed in form submission.", array("%ext" => $test_ext)), "error");
  1633. fp_goto("<front>");
  1634. return;
  1635. }
  1636. // We need to make sure, before we include this file, that it is something only available from within the main FlightPath directory.
  1637. $absolute_path = realpath($form_include);
  1638. $absolute_path = str_replace("\\", "/", $absolute_path);
  1639. // In order for us to proceed, the $absolute_path must BEGIN with our base FlightPath installation directory.
  1640. $file_system_path = $GLOBALS['fp_system_settings']['file_system_path'];
  1641. if (substr($absolute_path, 0, strlen($file_system_path)) != $file_system_path) {
  1642. fp_add_message(t("Include file in form submission is outside of the FlightPath installation directory.
  1643. <br>FlightPath directory path: %fsp
  1644. <br>Include file path: %ap", array("%fsp" => $file_system_path, "%ap" => $absolute_path)), "error");
  1645. fp_goto("<front>");
  1646. return;
  1647. }
  1648. include_once($form_include);
  1649. }
  1650. // We need to make sure the user has permission to submit this form!
  1651. $form_path = $_REQUEST["form_path"];
  1652. // Check the menu router table for whatever the permissions were for this
  1653. // path, if any.
  1654. if ($form_path != "") {
  1655. $router_item = menu_get_item($form_path) ;
  1656. if (!menu_check_user_access($router_item)) {
  1657. // The user does NOT have access to submit this form! The fact that
  1658. // it has made it this far means this may be some sort of hacking attempt.
  1659. die(t("Sorry, but you have encountered an error. A form submission was flagged
  1660. as possibly being an invalid or having insufficient permissions to submit.
  1661. This may constitute a bug in the system.
  1662. Please report this error to your Systems Administrator."));
  1663. }
  1664. }
  1665. // Let's get our set of allowed values, by looking at the original form,
  1666. // and grab what's in the POST which matches the name.
  1667. $values = array();
  1668. $safe_values = array(); // will be the same as $values, but anything of type password will not be included.
  1669. if (function_exists($callback)) {
  1670. // Get any params for the callback, or, an empty array.
  1671. $form_params = @unserialize(base64_decode($_REQUEST['form_params']));
  1672. if (!$form_params) {
  1673. $form_params = array();
  1674. }
  1675. // Actually get the form now.
  1676. $form = fp_get_form($callback, $form_params);
  1677. foreach ($form as $name => $element) {
  1678. // Save to our $values array, but we don't care about markup.
  1679. if (@$element["type"] != "" && @$element["type"] != "markup") {
  1680. $values[$name] = @$_POST[$name];
  1681. // Save to save_values, too, if this is not a password field.
  1682. if (@$element["type"] != "password") {
  1683. $safe_values[$name] = @$_POST[$name];
  1684. }
  1685. }
  1686. // Do we need to alter the value from the POST?
  1687. // If this element is a cfieldset, it may contain other elements. We should get
  1688. // those values too.
  1689. if (isset($element["elements"])) {
  1690. foreach ($element["elements"] as $k => $v) {
  1691. foreach ($element["elements"][$k] as $cname => $celement) {
  1692. // Save to our $values array, but we don't care about markup.
  1693. if (@$celement["type"] != "" && @$celement["type"] != "markup") {
  1694. $values[$cname] = @$_POST[$cname];
  1695. // Save to save_values, too, if this is not a password field.
  1696. if (@$celement["type"] != "password") {
  1697. $safe_values[$cname] = @$_POST[$cname];
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. // If this is a checkbox, and we have any value in the POST, it should
  1704. // be saved as boolean TRUE
  1705. if (isset($element["type"]) && $element["type"] == "checkbox") {
  1706. if (isset($_POST[$name]) && $_POST[$name] === "1") {
  1707. $values[$name] = TRUE;
  1708. }
  1709. }
  1710. }
  1711. }
  1712. // Does the form have any defined submit_handler's? If not, let's assign it the
  1713. // default of callback_submit().
  1714. $submit_handlers = $form["#submit_handlers"];
  1715. if (!is_array($submit_handlers)) $submit_handlers = array();
  1716. // If the submit_handlers is empty, then add our default submit handler. We don't
  1717. // want to do this if the user went out of their way to enter a different handler.
  1718. if (count($submit_handlers) == 0) {
  1719. array_push($submit_handlers, $callback . "_submit");
  1720. }
  1721. // Does the form have any defined validate_handler's? This works exactly like the submit handler.
  1722. $validate_handlers = $form["#validate_handlers"];
  1723. if (!is_array($validate_handlers)) $validate_handlers = array();
  1724. if (count($validate_handlers) == 0) {
  1725. array_push($validate_handlers, $callback . "_validate");
  1726. }
  1727. // Let's store our values in the SESSION in case we need them later on.
  1728. // But only if this is NOT a system_settings form!
  1729. if ($form_type != "system_settings") {
  1730. // Do not store any "password" field, for security, so it isn't stored
  1731. // in the server's session file in plain text.
  1732. // For this reason we will use the $safe_values array we created earlier.
  1733. $_SESSION["fp_form_submissions"][$callback]["values"] = $safe_values;
  1734. }
  1735. $form_state = array("values" => $values, "POST" => $_POST);
  1736. // Let's pass this through our default form validator (mainly to check for required fields
  1737. // which do not have values entered)
  1738. form_basic_validate($form, $form_state);
  1739. if (!form_has_errors()) {
  1740. // Let's now pass it through all of our custom validators, if there are any.
  1741. foreach ($validate_handlers as $validate_callback) {
  1742. if (function_exists($validate_callback)) {
  1743. call_user_func_array($validate_callback, array(&$form, &$form_state));
  1744. }
  1745. }
  1746. }
  1747. if (!form_has_errors()) {
  1748. // No errors from the validate, so let's continue.
  1749. // Is this a "system settings" form, or a normal form?
  1750. if ($form_type == "system_settings") {
  1751. // This is system settings, so let's save all of our values to the variables table.
  1752. // Write our values array to our variable table.
  1753. foreach ($form_state["values"] as $name => $val) {
  1754. variable_set($name, $val);
  1755. }
  1756. fp_add_message("Settings saved successfully.");
  1757. }
  1758. // Let's go through the form's submit handlers now.
  1759. foreach ($submit_handlers as $submit_callback) {
  1760. if (function_exists($submit_callback)) {
  1761. //call_user_func($submit_callback, $form, &$form_state);
  1762. call_user_func_array($submit_callback, array(&$form, &$form_state));
  1763. }
  1764. }
  1765. }
  1766. // Figure out where we are supposed to redirect the user.
  1767. $redirect_path = $redirect_query = "";
  1768. if (isset($form["#redirect"]) && is_array($form["#redirect"])) {
  1769. $redirect_path = $form["#redirect"]["path"];
  1770. $redirect_query = $form["#redirect"]["query"];
  1771. }
  1772. else {
  1773. $redirect_path = @$_REQUEST["default_redirect_path"];
  1774. $redirect_query = @$_REQUEST["default_redirect_query"];
  1775. // To help prevent directory traversal attacks, the redirect_path cannot contain periods (.) and semi-colons, and other trouble characters
  1776. $redirect_path = str_replace(".", "", $redirect_path);
  1777. $redirect_path = str_replace(";", "", $redirect_path);
  1778. $redirect_path = str_replace("'", "", $redirect_path);
  1779. $redirect_path = str_replace('"', "", $redirect_path);
  1780. $redirect_path = str_replace(' ', "", $redirect_path);
  1781. }
  1782. // If there is a Batch process we need to do, do it here instead of the fp_goto.
  1783. if (isset($_SESSION["fp_batch_id"]) && function_exists("batch_menu")) {
  1784. $batch_id = $_SESSION["fp_batch_id"];
  1785. unset($_SESSION["fp_batch_id"]);
  1786. batch_start_batch_from_form_submit($batch_id, $redirect_path, $redirect_query);
  1787. return;
  1788. }
  1789. else if (isset($_SESSION["fp_batch_id"]) && !function_exists("batch_menu")) {
  1790. // We requested a batch action, but the batch module is not installed.
  1791. 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");
  1792. unset($_SESSION["fp_batch_id"]);
  1793. }
  1794. // Okay, go back to where we were!
  1795. fp_goto($redirect_path, $redirect_query);
  1796. }
  1797. function system_handle_logout() {
  1798. global $user;
  1799. $name = $user->name;
  1800. $uid = $user->id;
  1801. // Check for hook_user_logout
  1802. $modules = modules_implement_hook("user_logout");
  1803. foreach($modules as $module) {
  1804. call_user_func($module . '_user_logout');
  1805. }
  1806. // Finish up logging out.
  1807. watchdog("logout", "@user has logged out", array("@user" => "$name ($uid)"));
  1808. // In an effort to mimimize a bug in Safari, we will
  1809. // overwrite the SESSION variables, then perform a few other operations,
  1810. // to make sure they are well and truly destroyed.
  1811. foreach ($_SESSION as $key => $val) {
  1812. $_SESSION[$key] = "x";
  1813. }
  1814. foreach ($_SESSION as $key => $val) {
  1815. $_SESSION[$key] = FALSE;
  1816. }
  1817. $_SESSION = array();
  1818. if (isset($_COOKIE[session_name()])) // remove cookie by setting it to expire, if it's there.
  1819. {
  1820. $cookie_expires = time() - date('Z') - 3600;
  1821. setcookie(session_name(), '', $cookie_expires, '/');
  1822. }
  1823. // I know this is repetitive, but I want to make ABSOLUTELY SURE
  1824. // I am removing the session by removing it, creating a new one, then killing that one too.
  1825. session_destroy();
  1826. session_commit();
  1827. session_start();
  1828. session_destroy();
  1829. session_commit();
  1830. fp_goto("<front>", "logout=true");
  1831. }
  1832. /**
  1833. * This function will clear our various caches by calling
  1834. * on the hook_clear_cache in each module.
  1835. */
  1836. function system_perform_clear_cache() {
  1837. fp_clear_cache();
  1838. fp_goto("<front>");
  1839. }
  1840. /**
  1841. * Called from menu, will run hook_cron() for all modules.
  1842. */
  1843. function system_perform_run_cron() {
  1844. invoke_hook("cron");
  1845. fp_add_message(t("Cron run completed successfully."));
  1846. variable_set("cron_last_run", time());
  1847. fp_goto("admin-tools/admin");
  1848. }
  1849. /**
  1850. * This page displayes the results of each module's hook_status.
  1851. *
  1852. */
  1853. function system_display_status_page() {
  1854. $rtn = "";
  1855. $pol = "";
  1856. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  1857. $status_array = invoke_hook("status"); // get everyone's hook_status.
  1858. $rtn .= "<p>" . t("This page will show you important status messages
  1859. about FlightPath. For example, what modules (if any) have
  1860. an update available.") . "</p>";
  1861. $rtn .= "<table width='100%' border='1' class='status-table' cellpadding='4'>
  1862. <tr class='header-row'>
  1863. <th width='10%' class='package-header'>" . t("Package") . "</th>
  1864. <th>" . t("Status") . "</th>
  1865. </tr>";
  1866. foreach ($status_array as $module => $details) {
  1867. $pol = ($pol == "even") ? "odd" : "even";
  1868. if (@$details["severity"] == "") $details["severity"] = "normal";
  1869. $rtn .= "<tr class='status-row status-row-$pol'>
  1870. <td valign='top' class='module-name'>$module</td>
  1871. <td valign='top' class='module-status module-status-" . $details["severity"] . "'>
  1872. " . $details["status"] . "
  1873. </td>
  1874. </tr>";
  1875. }
  1876. $rtn .= "</table>";
  1877. return $rtn;
  1878. }
  1879. /**
  1880. * Implementation of hook_status
  1881. * Expected return is array(
  1882. * "severity" => "normal" or "warning" or "alert",
  1883. * "status" => "A message to display to the user.",
  1884. * );
  1885. */
  1886. function system_status() {
  1887. $rtn = array();
  1888. $rtn["severity"] = "normal";
  1889. $rtn["status"] = "";
  1890. // Check on the last time cron was run; make sure it's working properly.
  1891. $last_run = variable_get("cron_last_run", 0);
  1892. // Report on current details about FlightPath.
  1893. $rtn["status"] .= "<p>" . t("FlightPath version:") . " " . FLIGHTPATH_CORE . "-" . FLIGHTPATH_VERSION . "</p>";
  1894. if ($last_run < strtotime("-2 DAY")) {
  1895. $rtn["severity"] = "alert";
  1896. $rtn["status"] .= t("Cron hasn't run in over 2 days. For your installation of FlightPath
  1897. to function properly, cron.php must be accessed routinely. At least once per day is recommended.");
  1898. }
  1899. else {
  1900. $rtn["status"] .= t("Cron was last run on %date", array("%date" => format_date($last_run)));
  1901. }
  1902. $rtn["status"] .= "<p style='font-size: 0.8em;'>" . t("Your site's cron URL is:");
  1903. $rtn["status"] .= "<br>&nbsp; &nbsp; <i>" . $GLOBALS["fp_system_settings"]["base_url"] . "/cron.php?t=" . $GLOBALS["fp_system_settings"]["cron_security_token"] . "</i>
  1904. <br>" . t("Example linux cron command:") . "&nbsp; <i>wget -O - -q -t 1 http://ABOVE_URL</i>";
  1905. $rtn["status"] .= "</p>";
  1906. return $rtn;
  1907. }
  1908. /**
  1909. * Implements hook_clear_cache
  1910. * Take care of clearing caches managed by this module
  1911. */
  1912. function system_clear_cache() {
  1913. unset($_SESSION["fp_form_submissions"]);
  1914. unset($_SESSION["fp_db_host"]);
  1915. unset($_SESSION["fp_draft_mode"]);
  1916. unset($_SESSION["fp_simple_degree_plan_cache_for_student"]);
  1917. menu_rebuild_cache();
  1918. system_rebuild_css_js_query_string();
  1919. }
  1920. /**
  1921. * This function will recreate the dummy query string we add to the end of css and js files.
  1922. *
  1923. */
  1924. function system_rebuild_css_js_query_string() {
  1925. // A dummy query string gets added to the URLs for css and javascript files,
  1926. // to give us control over browser caching. When this value changes (cause we
  1927. // cleared the cache, updated a module, etc) it tells the browser to get a new
  1928. // copy of our css and js files.
  1929. // This idea, like many other ideas in FlightPath, was borrowed from Drupal.
  1930. // The timestamp is converted to base 36 in order to make it more compact.
  1931. // This gives us a random-looking string of 6 numbers and letters.
  1932. variable_set('css_js_query_string', base_convert(time(), 10, 36));
  1933. }
  1934. /**
  1935. * Clears only the menu cache
  1936. */
  1937. function system_perform_clear_menu_cache() {
  1938. menu_rebuild_cache();
  1939. fp_goto("admin-tools/admin");
  1940. }
  1941. /**
  1942. * Display the "login" page. This is the default page displayed
  1943. * to the user, at /login, if they have not logged in yet.
  1944. *
  1945. * This page is meant to be displayed in conjunction with blocks, so the user can
  1946. * easily define their own messages and such.
  1947. *
  1948. * @return unknown
  1949. */
  1950. function system_display_login_page() {
  1951. $rtn = "";
  1952. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  1953. $top_blocks = blocks_render_blocks("system_login", "top");
  1954. $bottom_blocks = blocks_render_blocks("system_login", "bottom");
  1955. $left_col_blocks = blocks_render_blocks("system_login", "left_col");
  1956. $right_col_blocks = blocks_render_blocks("system_login", "right_col");
  1957. $rtn .= "<noscript>
  1958. <div style='padding: 5px; background-color: red; color: white; font-size: 12pt; font-weight: bold;'>
  1959. " . t("@FlightPath requires JavaScript to be enabled in order to
  1960. function correctly. Please enable JavaScript on your browser
  1961. before continuing.", array("@FlightPath" => variable_get("system_name", "FlightPath"))) . "</div>
  1962. </noscript>";
  1963. $w1 = 300;
  1964. if (fp_screen_is_mobile()) $w1 = "90%";
  1965. $login_box = fp_render_curved_line("Please login below...");
  1966. $login_box .= fp_render_form("system_login_form");
  1967. if (fp_screen_is_mobile()) {
  1968. // the user is viewing this on a mobile device, so make it look
  1969. // a bit nicer.
  1970. $rtn .= $top_blocks . $left_col_blocks . $right_col_blocks . $bottom_blocks;
  1971. }
  1972. else {
  1973. // This is NOT mobile, this is a regular desktop browser.
  1974. $rtn .= "
  1975. $top_blocks
  1976. <table border='0' class='login-content-table'>
  1977. <tr>
  1978. <td valign='top' width='40%' class='left-side-content'>
  1979. $left_col_blocks
  1980. </td>
  1981. <td valign='top' style='padding-left: 20px;' class='right-side-content'>
  1982. $right_col_blocks
  1983. </td>
  1984. </tr>
  1985. </table>
  1986. $bottom_blocks
  1987. ";
  1988. }
  1989. return $rtn;
  1990. }
  1991. /**
  1992. * This draws the form which facilitates logins.
  1993. */
  1994. function system_login_form() {
  1995. $form = array();
  1996. fp_set_title("");
  1997. // If we are coming from having just logged out, display a message.
  1998. if (isset($_REQUEST["logout"]) && $_REQUEST["logout"] == "true") {
  1999. fp_add_message(t("You have been logged out of @FlightPath.", array("@FlightPath" => variable_get("system_name", "FlightPath"))), "status", TRUE);
  2000. }
  2001. $form["user"] = array(
  2002. "label" => t("User:"),
  2003. "type" => "textfield",
  2004. "size" => 30,
  2005. "required" => TRUE,
  2006. );
  2007. $form["password"] = array(
  2008. "label" => t("Password:"),
  2009. "type" => "password",
  2010. "size" => 30,
  2011. "required" => TRUE,
  2012. );
  2013. $form["submit"] = array(
  2014. "type" => "submit",
  2015. "value" => t("Login"),
  2016. );
  2017. $form["#attributes"] = array("onSubmit" => "showUpdate(true);");
  2018. return $form;
  2019. }
  2020. /**
  2021. * Validate function for the login form.
  2022. * This is where we will do all of the lookups to verify username
  2023. * and password. If you want to write your own login handler (like for LDAP)
  2024. * this is the function you would duplicate in a custom module, then use hook_form_alter
  2025. * to make your function be the validator, not this one.
  2026. *
  2027. * We will simply verify the password, then let the submit handler take over from there.
  2028. */
  2029. function system_login_form_validate($form, &$form_state) {
  2030. $user = $form_state["values"]["user"];
  2031. if ($user != 'admin' && variable_get('disable_login_except_admin', 'no') == 'yes') {
  2032. fp_goto("disable-login");
  2033. return;
  2034. }
  2035. $password = $form_state["values"]["password"];
  2036. // If the GRANT_FULL_ACCESS is turned on, skip trying to validate
  2037. if ($GLOBALS["fp_system_settings"]["GRANT_FULL_ACCESS"] == TRUE) {
  2038. $user = "admin";
  2039. $form_state["passed_authentication"] = TRUE;
  2040. $form_state["db_row"]["user_id"] = 1;
  2041. $form_state["db_row"]["user_name"] = "FULL ACCESS USER";
  2042. return;
  2043. }
  2044. // Otherwise, check the table normally.
  2045. /*
  2046. $res = db_query("SELECT * FROM users WHERE user_name = '?' AND password = '?' AND is_disabled = '0' ", $user, md5($password));
  2047. if (db_num_rows($res) == 0) {
  2048. form_error("password", t("Sorry, but that username and password combination could not
  2049. be found. Please check your spelling and try again."));
  2050. return;
  2051. }
  2052. */
  2053. $res = db_query("SELECT * FROM users WHERE user_name = ? AND is_disabled = '0' ", $user);
  2054. $cur = db_fetch_array($res);
  2055. // Check the user's password is valid.
  2056. $stored_hash = @$cur["password"];
  2057. if (!user_check_password($password, $stored_hash)) {
  2058. form_error("password", t("Sorry, but that username and password combination could not
  2059. be found. Please check your spelling and try again."));
  2060. return;
  2061. }
  2062. // If this is a student, does this student have an accepted "allowed rank" (ie, FR, SO, JR, etc)?
  2063. $allowed_ranks_str = variable_get("allowed_student_ranks", "FR, SO, JR, SR");
  2064. $allowed_ranks = csv_to_array($allowed_ranks_str);
  2065. if (intval($cur['is_student']) === 1) {
  2066. $rank_code = db_result(db_query("SELECT rank_code FROM students WHERE cwid = ?", array($cur['cwid'])));
  2067. if (!in_array($rank_code, $allowed_ranks)) {
  2068. form_error("password", t("Sorry, your rank/classification is %rc. At this time FlightPath is only available to students
  2069. in the following ranks/classifications: @ranks_str", array("%rc" => $rank_code, "@ranks_str" => $allowed_ranks_str)));
  2070. return;
  2071. }
  2072. }
  2073. // otherwise, we know it must be correct. Continue.
  2074. $form_state["db_row"] = $cur;
  2075. // If we made it here, then the user successfully authenticated.
  2076. $form_state["passed_authentication"] = TRUE;
  2077. // It will now proceed to the submit handler.
  2078. }
  2079. /**
  2080. * Submit handler for login form.
  2081. * If we are here, it probably means we have indeed authenticated. Just in case, we will
  2082. * test the form_state["passed_authentication"] value, which we expect to have been
  2083. * set in our validate handler.
  2084. *
  2085. * We will now proceed to actually log the user into the system.
  2086. *
  2087. */
  2088. function system_login_form_submit($form, &$form_state) {
  2089. $user = $form_state["values"]["user"];
  2090. $password = $form_state["values"]["password"];
  2091. $passed = $form_state["passed_authentication"];
  2092. $db_row = $form_state["db_row"];
  2093. if (!$passed) {
  2094. fp_add_message(t("Sorry, there has been an error while trying to authenticate the user."));
  2095. return;
  2096. }
  2097. $_SESSION["fp_logged_in"] = TRUE;
  2098. // Set up a new $account object.
  2099. $account = new stdClass();
  2100. $account = fp_load_user($db_row["user_id"]);
  2101. /*
  2102. // Okay, let's look for all the modules who have implimented hook_user_login
  2103. $modules = modules_implement_hook("user_login");
  2104. if (is_array($modules) && count($modules) > 0) {
  2105. foreach ($modules as $module) {
  2106. call_user_func_array($module . '_user_login', array(&$account));
  2107. }
  2108. }*/
  2109. // Set the $account to the SESSION.
  2110. $_SESSION["fp_user_object"] = $account;
  2111. watchdog("login", "@user has logged in. CWID: @cwid", array("@user" => "$account->name ($account->id)", "@cwid" => $account->cwid));
  2112. fp_goto("<front>");
  2113. }
  2114. /**
  2115. * Display the "main" tab-page for FlightPath. Displays announcements
  2116. * as well as the Tools menu, and the "special administrative tools" menu.
  2117. */
  2118. function system_display_main_page() {
  2119. global $user;
  2120. $rtn = "";
  2121. // If we are not logged in, then we need to re-direct the user to
  2122. // the login page!
  2123. if ($_SESSION["fp_logged_in"] != TRUE) {
  2124. $query = "";
  2125. if (isset($_REQUEST["logout"])) $query = "logout=" . $_REQUEST["logout"];
  2126. // Since we are not logged in, and are headed to the login page, also clear out any advising variables we might have.
  2127. foreach ($_REQUEST as $key => $val) {
  2128. unset($_REQUEST[$key]);
  2129. unset($_GET[$key]);
  2130. unset($_POST[$key]);
  2131. }
  2132. global $current_student_id;
  2133. $current_student_id = ""; // clear this so the fp_goto doesn't try to add it.
  2134. session_destroy();
  2135. session_commit();
  2136. fp_goto("login", $query);
  2137. return;
  2138. }
  2139. $rtn .= "<table class='fp-semester-table'>";
  2140. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  2141. $left_col_blocks = blocks_render_blocks("system_main", "left_col");
  2142. $right_col_blocks = blocks_render_blocks("system_main", "right_col");
  2143. if (fp_screen_is_mobile()) {
  2144. $rtn .= "<tr><td colspan='2'>$left_col_blocks $right_col_blocks</td></tr>";
  2145. }
  2146. else {
  2147. $rtn .= "<tr><td width='50%' valign='top' style='padding-right: 10px;'>
  2148. $left_col_blocks
  2149. </td><td width='50%' valign='top' style='padding-left: 10px;'>
  2150. $right_col_blocks
  2151. </td></tr>";
  2152. }
  2153. $rtn .= "</table>";
  2154. $rtn .= "<form id='mainform' method='POST'>
  2155. <input type='hidden' id='scrollTop'>
  2156. <input type='hidden' id='performAction' name='performAction'>
  2157. <input type='hidden' id='advisingWhatIf' name='advisingWhatIf'>
  2158. <input type='hidden' id='currentStudentID' name='currentStudentID'>
  2159. </form>";
  2160. //$pC .= $screen->get_javascript_code();
  2161. /*
  2162. $screen->page_content = $pC;
  2163. $screen->page_has_search = true;
  2164. if ($_SESSION["fp_user_type"] == "student" || $_SESSION["fp_can_advise"] == false)
  2165. {
  2166. $screen->page_has_search = false;
  2167. }
  2168. $screen->build_system_tabs(0);
  2169. */
  2170. //////////////////////////////////////////////////////////
  2171. // To cut down on how long it takes to load huge groups
  2172. // like Free Electives, we will pre-load some of the course inventory here.
  2173. if (@$_SESSION["fp_cached_inventory_flag_one"] != true)
  2174. {
  2175. $load_number = $GLOBALS["fp_system_settings"]["load_course_inventory_on_login_number"];
  2176. if ($load_number > 1) {
  2177. $fp = new FlightPath();
  2178. $fp->cache_course_inventory(0,$load_number);
  2179. $_SESSION["fp_cached_inventory_flag_one"] = true;
  2180. }
  2181. }
  2182. // send to the browser
  2183. //$screen->output_to_browser();
  2184. return $rtn;
  2185. }
  2186. function system_blocks() {
  2187. return array(
  2188. "tools" => t("Tools menu"),
  2189. "admin_tools" => t("Admin Tools menu"),
  2190. "login_form" => t("Login form"),
  2191. );
  2192. }
  2193. function system_render_block($delta) {
  2194. $block = array();
  2195. if ($delta == "tools") {
  2196. $block["title"] = t("Tools");
  2197. $block["body"] = fp_render_menu_block("", "tools");
  2198. }
  2199. if ($delta == "admin_tools") {
  2200. $block["title"] = t("Administrative Tools");
  2201. $block["body"] = fp_render_menu_block("", "admin-tools");
  2202. }
  2203. if ($delta == "login_form") {
  2204. $block["title"] = t("Please log in below...");
  2205. $block["body"] = fp_render_form("system_login_form");
  2206. }
  2207. // We don't want empty blocks to show up at all.
  2208. if ($block["body"] == "") {
  2209. return FALSE;
  2210. }
  2211. return $block;
  2212. }
  2213. /**
  2214. * Called on every page load.
  2215. */
  2216. function system_init() {
  2217. // Let's see if the $user object (for the logged-in user) has been set up.
  2218. global $user;
  2219. $user = new stdClass();
  2220. if (!isset($_SESSION["fp_user_object"]->roles[1])) $_SESSION["fp_user_object"]->roles[1] = "";
  2221. if (@$_SESSION["fp_logged_in"] == TRUE) {
  2222. // Make sure it doesn't have the anonymous user role (rid == 1).
  2223. if ($_SESSION["fp_user_object"]->roles[1] == "anonymous user") {
  2224. unset($_SESSION["fp_user_object"]->roles[1]);
  2225. }
  2226. $user = $_SESSION["fp_user_object"];
  2227. // To make sure we pick up the user's newest permissions, re-load
  2228. // the user here.
  2229. $user = fp_load_user($user->id);
  2230. }
  2231. else {
  2232. // User is anonymous, so set it up as such.
  2233. $user = fp_load_user(0);
  2234. }
  2235. // Are we in maintenance mode? If so, display a message.
  2236. if (variable_get("maintenance_mode", FALSE)) {
  2237. fp_add_message(t("@FlightPath is currently undergoing routine maintenance.
  2238. During this time, some data may appear incomplete.
  2239. We apologize for the inconvenience and appreciate your patience.", array("@FlightPath" => variable_get("system_name", "FlightPath"))), "status", TRUE);
  2240. }
  2241. // Is there an urgent message to display?
  2242. $urgent_msg = variable_get("urgent_msg", "");
  2243. if ($urgent_msg) {
  2244. fp_add_message("<b>" . t("Important Message:") . "</b> " . $urgent_msg, "status", TRUE);
  2245. }
  2246. // Since current_student_id is coming from the REQUEST, sanitize it.
  2247. $current_student_id = @$_REQUEST['current_student_id'];
  2248. $current_student_id = str_replace("'", "", $current_student_id); // remove single quotes
  2249. $current_student_id = str_replace('"', "", $current_student_id); // remove back quotes
  2250. $current_student_id = str_replace(';', "", $current_student_id); // remove semicolons
  2251. // Add in our custom JS settings.
  2252. $settings = array(
  2253. "themeLocation" => fp_theme_location(),
  2254. "currentStudentId" => $current_student_id,
  2255. "basePath" => base_path(),
  2256. // Add in the popup window options....
  2257. "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.
  2258. "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.
  2259. "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.
  2260. );
  2261. fp_add_js($settings, "setting");
  2262. fp_add_js(fp_get_module_path("system") . "/js/system.js");
  2263. }
  2264. /**
  2265. * This is the form which an admin may use to manage the modules
  2266. * in the system.
  2267. */
  2268. function system_modules_form() {
  2269. $form = array();
  2270. $m = 0;
  2271. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  2272. $form["mark" . $m++] = array(
  2273. "value" => t("Use this form to enable or disable modules. This scans the /modules/ and then /custom/modules/
  2274. directories.") . "
  2275. " . l(t("Run DB updates?"), "admin/db-updates") . "<br><br>",
  2276. );
  2277. // Begin by scanning the /modules/ directory. Anything in there
  2278. // cannot be disabled.
  2279. $module_dirs = array();
  2280. $module_dirs[] = array("start" => "modules", "type" => t("Core"));
  2281. $module_dirs[] = array("start" => "custom/modules", "type" => t("Custom"));
  2282. foreach ($module_dirs as $module_dir) {
  2283. $start_dir = $module_dir["start"];
  2284. if ($dh = opendir($start_dir)) {
  2285. //$pC .= "<div class='fp-system-modules-type'>{$module_dir["type"]}</div>
  2286. // <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>";
  2287. $form["mark" . $m++] = array(
  2288. "value" => "<div class='fp-system-modules-type'>{$module_dir["type"]}</div>
  2289. <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>",
  2290. );
  2291. $pol = "even";
  2292. $dir_files = scandir($start_dir);
  2293. foreach ($dir_files as $file) {
  2294. if ($file == "." || $file == "..") continue;
  2295. if (is_dir($start_dir . "/" . $file)) {
  2296. // Okay, now look inside and see if there is a .info file.
  2297. if (file_exists("$start_dir/$file/$file.info")) {
  2298. $module = $file;
  2299. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  2300. // From the info_contents variable, split up and place into an array.
  2301. $info_details_array = array("path" => "", "module" => "",
  2302. "schema" => "", "core" => "", "description" => "",
  2303. "requires" => "", "version" => "",
  2304. "required" => "", );
  2305. $lines = explode("\n", $info_contents);
  2306. foreach ($lines as $line) {
  2307. if (trim($line) == "") continue;
  2308. $temp = explode("=", trim($line));
  2309. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  2310. }
  2311. $path = "$start_dir/$file";
  2312. $info_details_array["path"] = $path;
  2313. $info_details_array["module"] = $module;
  2314. // Expected keys:
  2315. // name, description, version, core, requires (csv), requred (true or false)
  2316. $checked = "";
  2317. $form["mark" . $m++] = array(
  2318. "value" => "<tr class='fp-system-modules-row fp-system-modules-row-$pol'>
  2319. <td width='35%'>",
  2320. );
  2321. // the Checkbox.
  2322. // Should it be checked? We can check the modules table to see if it's enabled/installed or not.
  2323. $installation_status = "";
  2324. $default_value = array();
  2325. $res = db_query("SELECT * FROM modules WHERE path = '?' ", $path);
  2326. $cur = db_fetch_array($res);
  2327. $info_details_array["enabled"] = $cur["enabled"];
  2328. if ($cur["enabled"] == "1") {
  2329. // Yes, it is checked!
  2330. $default_value = array($module => $module);
  2331. }
  2332. else if ($cur["enabled"] == "") {
  2333. $installation_status = t("not installed");
  2334. }
  2335. else if ($cur["enabled"] == "0") {
  2336. $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)),
  2337. ' window.location="' . fp_url("system/uninstall-module", "module=$module&path=" . urlencode($path) . "") . '"; ', t("uninstall?"));
  2338. }
  2339. // Does this module need to run db updates?
  2340. if ($cur["enabled"] == "1" && $cur["schema"] != $info_details_array["schema"] && $info_details_array["schema"] != "") {
  2341. $installation_status = "<b>" . l(t("Run db updates"), "admin/db-updates") . "</b>";
  2342. // Let's also make sure to enable a message at the top of the screen, letting the user
  2343. // know that there are needed updates.
  2344. fp_add_message("<b>" . t("Note:") . "</b> " . t("There are modules which have been updated. Please back up your database,
  2345. then run the DB Updates function below as soon as possible."), "error", TRUE);
  2346. }
  2347. $attributes = array();
  2348. if ($info_details_array["required"]) {
  2349. // This is a required module; it cannot be unchecked.
  2350. $attributes["disabled"] = "disabled";
  2351. }
  2352. $bool_overriding = FALSE;
  2353. // Did this module already exist in $form? In other words,
  2354. // is the module overriding a core module? If so, we need to know
  2355. // so we can display something special.
  2356. if (isset($form["cb__$module"])) {
  2357. $bool_overriding = TRUE;
  2358. }
  2359. $requires = "";
  2360. // If this module requires a higher core version of FlightPath than what we
  2361. // are running, disable and explain to the user.
  2362. if (FLIGHTPATH_VERSION != '%FP_VERSION%' && $info_details_array["requires core version"]) {
  2363. // Test to see if the current version is >= to the required core version.
  2364. if (version_compare(FLIGHTPATH_VERSION, $info_details_array["requires core version"], "<")) {
  2365. // No, it's LESS than the required version! We shouldn't be able to use this module!
  2366. $attributes["disabled"] = "disabled";
  2367. $requires .= "<div style='color: red;'>" . t("This module requires
  2368. that you run FlightPath version %fpv or higher.
  2369. You are instead running version %fpov. Please update
  2370. your core copy of FlightPath before attempting to install this
  2371. module.", array('%fpv' => $info_details_array["requires core version"],
  2372. '%fpov' => FLIGHTPATH_VERSION)) . "</div>";
  2373. }
  2374. }
  2375. // Let's see if this module is for the wrong core entirely.
  2376. if ($info_details_array["core"]) {
  2377. // Test to see if we are not the correct core version.
  2378. if (strtolower(FLIGHTPATH_CORE) != strtolower($info_details_array["core"])) {
  2379. // Nope, the wrong core version!
  2380. $attributes["disabled"] = "disabled";
  2381. $requires .= "<div style='color: red;'>" . t("This module requires
  2382. that you run FlightPath core version %fpv.
  2383. You are instead running version %fpov. Please either download
  2384. the correct version of this module for your FlightPath core version,
  2385. or update FlightPath to the required core version.", array('%fpv' => $info_details_array["core"],
  2386. '%fpov' => FLIGHTPATH_CORE)) . "</div>";
  2387. }
  2388. }
  2389. $form["cb__$module"] = array(
  2390. "type" => "checkboxes",
  2391. "options" => array($module => $info_details_array["name"]),
  2392. "value" => $default_value,
  2393. "suffix" => "<div class='fp-system-modules-machine-name'>$file</div>
  2394. <div class='fp-system-modules-installation-status'>$installation_status</div>
  2395. ",
  2396. "attributes" => $attributes,
  2397. );
  2398. // hidden variable containing the details about this module, for later use on submit.
  2399. $form["module_details__$module"] = array(
  2400. "type" => "hidden",
  2401. "value" => urlencode(serialize($info_details_array)),
  2402. );
  2403. // Version & descr.
  2404. if ($info_details_array["requires"] != "") {
  2405. $requires .= "<div class='fp-system-modules-requires hypo'>
  2406. <b>" . t("Requires:") . "</b> {$info_details_array["requires"]}
  2407. </div>";
  2408. }
  2409. // if we are overriding a module, then display something special.
  2410. if ($bool_overriding) {
  2411. $form["mark" . $m++] = array(
  2412. "value" => "<em>" . t("Overriding core module:") . "<br>{$info_details_array["name"]}</em>
  2413. <div class='fp-system-modules-machine-name'>$file</div>
  2414. <div class='fp-system-modules-installation-status'>
  2415. " . t("Use checkbox in Core section above to manage module") . "
  2416. </div>",
  2417. );
  2418. }
  2419. $form["mark" . $m++] = array(
  2420. "value" => " </td>
  2421. <td width='5%' >{$info_details_array["version"]}</td>
  2422. <td >{$info_details_array["description"]}$requires</td>
  2423. </tr>
  2424. ",
  2425. );
  2426. $pol = ($pol == "even") ? "odd" : "even";
  2427. } // if file_exists (xml file)
  2428. } // if is_dir
  2429. } // while file=readdir
  2430. $form["mark" . $m++] = array(
  2431. "value" => "</table>",
  2432. );
  2433. } // if opendir($startdir)
  2434. }// foreach moduledirs
  2435. $form["submit"] = array(
  2436. "type" => "submit",
  2437. "value" => t("Submit"),
  2438. "prefix" => "<hr>",
  2439. );
  2440. return $form;
  2441. }
  2442. /**
  2443. * Submit handler for the modules form.
  2444. */
  2445. function system_modules_form_submit($form, $form_state) {
  2446. // Go through all of the checkboxes which we have "module_details" for. If there is NOT a corresponding
  2447. // checkbox, it means it wasn't checked, and should be disabled in the database. Otherwise, it means it WAS
  2448. // checked, and should be enabled/installed.
  2449. $did_something = FALSE;
  2450. foreach ($form_state["values"] as $key => $value) {
  2451. if (strstr($key, "module_details__")) {
  2452. if ($module_details = unserialize(urldecode($value))) {
  2453. $module = $module_details["module"];
  2454. // Disabling a module.
  2455. if ($module_details["enabled"] == "1" && !isset($form_state["values"]["cb__$module"])) {
  2456. // So it WAS enabled, but now the checkbox wasn't checked. So disable it!
  2457. system_disable_module($module_details);
  2458. $did_something = TRUE;
  2459. }
  2460. // Enabling a module
  2461. if ($module_details["enabled"] != "1" && isset($form_state["values"]["cb__$module"])) {
  2462. system_enable_module($module_details);
  2463. $did_something = TRUE;
  2464. }
  2465. }
  2466. }
  2467. }
  2468. if ($did_something) {
  2469. // Refetch all of the modules from the modules table.
  2470. fp_rebuild_modules_list();
  2471. // We should clear the cache if we did something.
  2472. fp_clear_cache();
  2473. }
  2474. }
  2475. /**
  2476. * Called from the menu (ie, a URL) this function will uninstall a module.
  2477. *
  2478. */
  2479. function system_handle_uninstall_module() {
  2480. $module = $_REQUEST["module"];
  2481. // First, let's get information about this module from the db.
  2482. $res = db_query("SELECT * FROM modules WHERE name = '?' ", $module);
  2483. $cur = db_fetch_array($res);
  2484. // Make sure it is not currently enabled.
  2485. if ($cur["enabled"] == "1") {
  2486. fp_add_message(t("Module %module not yet disabled. Disable first, then try to uninstall.", array("%module" => $module)));
  2487. return;
  2488. }
  2489. // Let's see if we can call hook_uninstall for this module.
  2490. if (include_module($module, TRUE, $cur["path"])) {
  2491. if (include_module_install($module, $cur["path"])) {
  2492. if (function_exists($module . "_uninstall")) {
  2493. call_user_func($module . "_uninstall");
  2494. }
  2495. }
  2496. }
  2497. // Remove from the database.
  2498. $res = db_query("DELETE FROM modules WHERE name = '?' ", $module);
  2499. fp_add_message(t("Uninstalled %module.", array("%module" => $module)));
  2500. fp_goto("admin/config/modules");
  2501. }
  2502. /**
  2503. * Handles the enabling (and possible installation) of module.
  2504. */
  2505. function system_enable_module($module_details) {
  2506. $module = $module_details["module"];
  2507. $path = $module_details["path"];
  2508. $bool_call_hook_install = FALSE;
  2509. // Do we need to attempt to call the hook_install function?
  2510. if (@$module_details["enabled"] == "") {
  2511. // Wasn't in the database, so we need to install it.
  2512. // Add to our table.
  2513. // (delete anything all ready there first)
  2514. $res = db_query("DELETE FROM modules WHERE name = '?' ", $module);
  2515. // Now, add back into the table.
  2516. $res = db_query("INSERT INTO modules (name, path, version, requires, enabled, type, `schema`, info)
  2517. VALUES ('?', '?', '?', '?', '?', '?', '?', '?')
  2518. ", $module, $path, @$module_details["version"], @$module_details["required"], "1", "module",
  2519. @intval($module_details["schema"]), serialize($module_details));
  2520. $bool_call_hook_install = TRUE;
  2521. fp_add_message(t("The module %module has been installed.", array("%module" => $module)));
  2522. }
  2523. // If the module has a .install file, begin by including it.
  2524. if (include_module_install($module, $path)) {
  2525. // Include the original module file first.
  2526. include_module($module, TRUE, $path);
  2527. if ($bool_call_hook_install) {
  2528. // call hook_install if it exists.
  2529. if (function_exists($module . '_install')) {
  2530. call_user_func($module . '_install');
  2531. }
  2532. }
  2533. // Now, we can call hook_enable, if it exists.
  2534. if (function_exists($module . '_enable')) {
  2535. call_user_func($module . '_enable');
  2536. }
  2537. }
  2538. // Update our table.
  2539. $res = db_query("UPDATE modules SET enabled = '1' WHERE name = '?' ", $module);
  2540. fp_add_message(t("The module %module has been enabled.", array("%module" => $module)));
  2541. }
  2542. /**
  2543. * Handles the disabling of the module in question.
  2544. */
  2545. function system_disable_module($module_details) {
  2546. $module = $module_details["module"];
  2547. $path = $module_details["path"];
  2548. // This module cannot be disabled!
  2549. if ($module_details["required"] == TRUE) {
  2550. return;
  2551. }
  2552. // If the module has a "hook_disable" in it's path/module.install file, include and call it.
  2553. if (include_module_install($module, $path) && function_exists($module . '_disable')) {
  2554. call_user_func($module . '_disable');
  2555. }
  2556. // Disable it in the modules table.
  2557. $res = db_query("UPDATE modules
  2558. SET enabled = '0'
  2559. WHERE name = '?' ", $module);
  2560. fp_add_message(t("The module %module has been disabled.", array("%module" => $module)));
  2561. }
  2562. /**
  2563. * Construct an HTML element and return it.
  2564. *
  2565. */
  2566. function system_build_element($name, $type = "", $label = "", $description = "", $default_value = "", $csv_to_array = FALSE) {
  2567. $rtn = "";
  2568. if (!$default_value) {
  2569. $default_value = $GLOBALS["fp_system_settings"][$name];
  2570. }
  2571. if (is_array($default_value)) {
  2572. $default_value = @join(", ", $default_value);
  2573. }
  2574. if (!$type) {
  2575. $type = "textfield";
  2576. }
  2577. if (!$label) {
  2578. $label = $name;
  2579. }
  2580. if ($type == "textfield") {
  2581. $rtn .= "<div class='fp-system-settings-element fp-system-settings-textfield'>
  2582. <label>$label:</label>
  2583. <div class='fp-system-settings-input'>
  2584. <input type='textfield' name='$name' value='$default_value'>
  2585. </div>
  2586. ";
  2587. if ($description) {
  2588. $rtn .= "<div class='fp-system-settings-element-description'>$description</div>";
  2589. }
  2590. $rtn .= "</div>";
  2591. }
  2592. if ($type == "textarea") {
  2593. $rtn .= "<div class='fp-system-settings-element fp-system-settings-textarea'>
  2594. <label>$label:</label>
  2595. <div class='fp-system-settings-input'>
  2596. <textarea name='$name'>$default_value</textarea>
  2597. </div>
  2598. ";
  2599. if ($description) {
  2600. $rtn .= "<div class='fp-system-settings-element-description'>$description</div>";
  2601. }
  2602. $rtn .= "</div>";
  2603. }
  2604. if ($type == "boolean") {
  2605. $sel_f = $sel_t = "";
  2606. if ($default_value) {
  2607. $sel_t = "selected";
  2608. }
  2609. $rtn .= "<div class='fp-system-settings-element fp-system-settings-boolean'>
  2610. <label>$label:</label>
  2611. <div class='fp-system-settings-input'>
  2612. <select name='$name'>
  2613. <option value='' $sel_f>FALSE</option>
  2614. <option value='1' $sel_t>TRUE</option>
  2615. </select>
  2616. </div>
  2617. ";
  2618. if ($description) {
  2619. $rtn .= "<div class='fp-system-settings-element-description'>$description</div>";
  2620. }
  2621. $rtn .= "</div>";
  2622. }
  2623. // We need to convert this CSV back into an array when we save it!
  2624. if ($csv_to_array) {
  2625. if (!isset($_SESSION["fp_system"]["csv_to_array"])) {
  2626. $_SESSION["fp_system"]["csv_to_array"] = array();
  2627. }
  2628. // Add to our list.
  2629. $_SESSION["fp_system"]["csv_to_array"][] = $name;
  2630. }
  2631. return $rtn;
  2632. }

Functions

Namesort descending Description
system_blocks
system_block_regions Hook block regions.
system_build_element Construct an HTML element and return it.
system_check_clean_urls This function will attempt to confirm that "clean URLs" is functioning, and allowed on this server.
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_disable_login_page
system_display_install_finished_page This page is displayed to the user once FlightPath has been installed.
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_main_page Display the "main" tab-page for FlightPath. Displays announcements as well as the Tools menu, and the "special administrative tools" menu.
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_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_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_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_run_cron Called from menu, will run hook_cron() for all modules.
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_render_block
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.", );