system.module

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

Functions & methods

NameDescription
system_blocks
system_block_regionsHook block regions.
system_build_elementConstruct an HTML element and return it.
system_clear_cacheImplements hook_clear_cache Take care of clearing caches managed by this module
system_confirm_db_updates_formDisplay a confirmation form before we run the db updates (hook_updates)
system_confirm_db_updates_form_submitPerform the actual hook_update calls here, send the user to a completed page.
system_disable_moduleHandles the disabling of the module in question.
system_display_completed_db_updatesOnce db updates are run, display contents of this page.
system_display_install_finished_pageThis page is displayed to the user once FlightPath has been installed.
system_display_login_pageDisplay the "login" page. This is the default page displayed to the user, at /login, if they have not logged in yet.
system_display_main_pageDisplay the "main" tab-page for FlightPath. Displays announcements as well as the Tools menu, and the "special administrative tools" menu.
system_display_status_pageThis page displayes the results of each module's hook_status.
system_enable_moduleHandles the enabling (and possible installation) of module.
system_execute_php_form
system_execute_php_form_submit
system_get_roles_for_userReturn an array containing the roles which have been assigned to a specific user.
system_handle_form_submitIntercepts form submissions from System Settings Forms.
system_handle_logout
system_handle_uninstall_moduleCalled from the menu (ie, a URL) this function will uninstall a module.
system_initCalled on every page load.
system_login_formThis draws the form which facilitates logins.
system_login_form_submitSubmit 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_validateValidate 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_formThis is the form which an admin may use to manage the modules in the system.
system_modules_form_submitSubmit handler for the modules form.
system_perform_clear_cacheThis function will clear our various caches by calling on the hook_clear_cache in each module.
system_perform_clear_menu_cacheClears only the menu cache
system_perform_run_cronCalled from menu, will run hook_cron() for all modules.
system_permImplementation of hook_perm(). Expects to return an array of permissions recognized by this module.
system_popup_report_contact_formThis 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_youThis is the thank you page you see after submitting the contact form.
system_render_block
system_school_data_formThis form is for the school-data, like subject code descriptions, colleges, etc.
system_school_data_form_validateValidate handler for the school_data_form.
system_settings_formThis is the "system settings" form.
system_settings_form_submitExtra submit handler for the system_settings_form
system_statusImplementation of hook_status Expected return is array( "severity" => "normal" or "warning" or "alert", "status" => "A message to display to the user.", );

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. * Return an array containing the roles which have been assigned to
  61. * a specific user.
  62. */
  63. function system_get_roles_for_user($user_id) {
  64. $rtn = array();
  65. $res = db_query("SELECT * FROM user_roles a, roles b
  66. WHERE user_id = '?'
  67. AND a.rid = b.rid ", $user_id);
  68. while ($cur = db_fetch_array($res)) {
  69. $rtn[$cur["rid"]] = $cur["name"];
  70. }
  71. // Is this person in the users table? If so, they will get the rid 2 (authenticated)
  72. // If not, they will get the role 1 (anonymous)
  73. $res2 = db_query("SELECT user_id FROM users WHERE user_id = '?' AND user_id <> '0' ", $user_id);
  74. if (db_num_rows($res2) > 0) {
  75. $rtn[2] = t("authenticated user");
  76. }
  77. else {
  78. $rtn[1] = t("anonymous user");
  79. }
  80. return $rtn;
  81. }
  82. /**
  83. * Hook block regions.
  84. *
  85. * This function simply defines which block regions we will handle. Each
  86. * block section should have a unique machine name, so it is best to namespace it with the
  87. * name of the module, then page or tab it appears on.
  88. *
  89. * The array looks like this:
  90. * return array(
  91. * "system_main" => array(
  92. * "title" => t("Main Tab"),
  93. * "regions" => array (
  94. * "left_col" => array("title" => t("Left Column")),
  95. * "right_col" => array("title" => t("Right Column")),
  96. * ),
  97. * ),
  98. * );
  99. *
  100. *
  101. * REMEMBER to make these machine-names, so only alpha numeric and underscores!
  102. */
  103. function system_block_regions() {
  104. return array(
  105. "system_main" => array(
  106. "title" => t("Main Tab"),
  107. "regions" => array (
  108. "left_col" => array("title" => t("Left Column")),
  109. "right_col" => array("title" => t("Right Column")),
  110. ),
  111. ),
  112. "system_login" => array(
  113. "title" => t("Login Page"),
  114. "regions" => array (
  115. "top" => array("title" => t("Top")),
  116. "left_col" => array("title" => t("Left Column")),
  117. "right_col" => array("title" => t("Right Column")),
  118. "bottom" => array("title" => t("Bottom")),
  119. ),
  120. ),
  121. );
  122. }
  123. function system_menu() {
  124. $items = array();
  125. $items["main"] = array(
  126. "title" => "Main",
  127. "page_callback" => "system_display_main_page",
  128. "access_callback" => TRUE,
  129. "type" => MENU_TYPE_TAB,
  130. "tab_family" => "system",
  131. "weight" => 10,
  132. "page_settings" => array(
  133. "display_greeting" => TRUE,
  134. "display_currently_advising" => TRUE,
  135. "screen_mode" => "not_advising",
  136. "page_has_search" => TRUE,
  137. ),
  138. );
  139. $items["install-finished"] = array(
  140. "title" => "Installation Finished",
  141. "page_callback" => "system_display_install_finished_page",
  142. "access_callback" => TRUE,
  143. "type" => MENU_TYPE_CALLBACK,
  144. );
  145. $items["login"] = array(
  146. "title" => "Login",
  147. "page_callback" => "system_display_login_page",
  148. "access_callback" => TRUE,
  149. "type" => MENU_TYPE_NORMAL_ITEM,
  150. );
  151. $items["admin-tools/clear-cache"] = array(
  152. "title" => "Clear all cache",
  153. "page_callback" => "system_perform_clear_cache",
  154. "access_arguments" => array("administer_modules"),
  155. "type" => MENU_TYPE_NORMAL_ITEM,
  156. );
  157. $items["admin/config/run-cron"] = array(
  158. "title" => "Run cron now",
  159. "description" => "Run the normal cron operations right away",
  160. "page_callback" => "system_perform_run_cron",
  161. "access_arguments" => array("run_cron"),
  162. "type" => MENU_TYPE_NORMAL_ITEM,
  163. );
  164. $items["admin/config/status"] = array(
  165. "title" => "System status",
  166. "description" => "View important notifications and updates for your installation of FlightPath",
  167. "page_callback" => "system_display_status_page",
  168. "access_arguments" => array("view_system_status"),
  169. "page_settings" => array(
  170. "page_show_title" => TRUE,
  171. "menu_links" => array(
  172. 0 => array(
  173. "text" => "Back to main menu",
  174. "path" => "admin-tools/admin",
  175. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  176. ),
  177. ),
  178. ),
  179. "type" => MENU_TYPE_NORMAL_ITEM,
  180. "tab_parent" => "admin-tools/admin",
  181. "weight" => 50,
  182. );
  183. $items["admin/db-updates"] = array(
  184. "title" => "Run DB updates?",
  185. "page_callback" => "fp_render_form",
  186. "page_arguments" => array("system_confirm_db_updates_form"),
  187. "access_arguments" => array("administer_modules"),
  188. "type" => MENU_TYPE_NORMAL_ITEM,
  189. );
  190. $items["admin/completed-db-updates"] = array(
  191. "title" => "Database updates completed",
  192. "page_callback" => "system_display_completed_db_updates",
  193. "access_arguments" => array("administer_modules"),
  194. "page_settings" => array(
  195. "page_show_title" => TRUE,
  196. ),
  197. "type" => MENU_TYPE_NORMAL_ITEM,
  198. );
  199. $items["admin/config/system-settings"] = array(
  200. "title" => "System settings",
  201. "description" => "Configure settings for FlightPath",
  202. "page_callback" => "fp_render_form",
  203. "page_arguments" => array("system_settings_form", "system_settings"),
  204. "access_arguments" => array("de_can_administer_system_settings"),
  205. "page_settings" => array(
  206. "page_has_search" => FALSE,
  207. "page_banner_is_link" => TRUE,
  208. "page_hide_report_error" => TRUE,
  209. "menu_icon" => fp_theme_location() . "/images/toolbox.gif",
  210. "menu_links" => array(
  211. 0 => array(
  212. "text" => "Back to main menu",
  213. "path" => "admin-tools/admin",
  214. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  215. ),
  216. ),
  217. ),
  218. "type" => MENU_TYPE_NORMAL_ITEM,
  219. "tab_parent" => "admin-tools/admin",
  220. );
  221. $items["admin/config/school-data"] = array(
  222. "title" => "Configure school data",
  223. "description" => "Configure school-specific data and settings",
  224. "page_callback" => "fp_render_form",
  225. "page_arguments" => array("system_school_data_form", "system_settings"),
  226. "access_arguments" => array("de_can_administer_school_data"),
  227. "page_settings" => array(
  228. "page_has_search" => FALSE,
  229. "page_banner_is_link" => TRUE,
  230. "page_hide_report_error" => TRUE,
  231. "menu_icon" => fp_theme_location() . "/images/toolbox.gif",
  232. "menu_links" => array(
  233. 0 => array(
  234. "text" => "Back to main menu",
  235. "path" => "admin-tools/admin",
  236. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  237. ),
  238. ),
  239. ),
  240. "type" => MENU_TYPE_NORMAL_ITEM,
  241. "tab_parent" => "admin-tools/admin",
  242. );
  243. $items["admin/config/modules"] = array(
  244. "title" => "Modules",
  245. "description" => "Manage which modules are enabled for your site",
  246. "page_callback" => "fp_render_form",
  247. "page_arguments" => array("system_modules_form"),
  248. "access_arguments" => array("administer_modules"),
  249. "page_settings" => array(
  250. "page_has_search" => FALSE,
  251. "page_banner_is_link" => TRUE,
  252. "page_hide_report_error" => TRUE,
  253. "menu_links" => array(
  254. 0 => array(
  255. "text" => "Back to main menu",
  256. "path" => "admin-tools/admin",
  257. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  258. ),
  259. ),
  260. ),
  261. "type" => MENU_TYPE_NORMAL_ITEM,
  262. "tab_parent" => "admin-tools/admin",
  263. );
  264. $items["system/uninstall-module"] = array(
  265. "page_callback" => "system_handle_uninstall_module",
  266. "page_arguments" => array(2),
  267. "access_arguments" => array("administer_modules"),
  268. "type" => MENU_TYPE_CALLBACK,
  269. );
  270. $items["admin/config/clear-menu-cache"] = array(
  271. "title" => "Clear menu cache",
  272. "description" => "Clear and rebuild menus and URLs",
  273. "page_callback" => "system_perform_clear_menu_cache",
  274. "access_arguments" => array("administer_modules"),
  275. "type" => MENU_TYPE_NORMAL_ITEM,
  276. );
  277. $items["system-handle-form-submit"] = array(
  278. "page_callback" => "system_handle_form_submit",
  279. "access_callback" => TRUE,
  280. "type" => MENU_TYPE_CALLBACK,
  281. );
  282. $items["logout"] = array(
  283. "title" => "Logout",
  284. "page_callback" => "system_handle_logout",
  285. "access_callback" => TRUE,
  286. "type" => MENU_TYPE_CALLBACK,
  287. );
  288. $items["popup-report-contact"] = array(
  289. "title" => "Report/Contact",
  290. "page_callback" => "fp_render_form",
  291. "page_arguments" => array("system_popup_report_contact_form"),
  292. "access_callback" => TRUE,
  293. "page_settings" => array(
  294. "page_is_popup" => TRUE,
  295. "page_hide_report_error" => TRUE,
  296. ),
  297. "type" => MENU_TYPE_CALLBACK,
  298. );
  299. $items["popup-contact-form/thank-you"] = array(
  300. "title" => "Report/Contact",
  301. "page_callback" => "system_popup_report_contact_thank_you",
  302. "access_callback" => TRUE,
  303. "page_settings" => array(
  304. "page_is_popup" => TRUE,
  305. "page_hide_report_error" => TRUE,
  306. ),
  307. "type" => MENU_TYPE_CALLBACK,
  308. );
  309. $items["admin/config/execute-php"] = array(
  310. "title" => "Execute PHP",
  311. "description" => "Execute arbitrary PHP on your server. Caution: could be dangerous if not understood",
  312. "page_callback" => "fp_render_form",
  313. "page_arguments" => array("system_execute_php_form", "system_settings"),
  314. "access_arguments" => array("execute_php"),
  315. "page_settings" => array(
  316. "page_has_search" => FALSE,
  317. "page_banner_is_link" => TRUE,
  318. "page_hide_report_error" => TRUE,
  319. "menu_links" => array(
  320. 0 => array(
  321. "text" => "Back to main menu",
  322. "path" => "admin-tools/admin",
  323. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  324. ),
  325. ),
  326. ),
  327. "type" => MENU_TYPE_NORMAL_ITEM,
  328. "tab_parent" => "admin-tools/admin",
  329. );
  330. return $items;
  331. }
  332. function system_execute_php_form() {
  333. $form = array();
  334. $form["mark" . $m++] = array(
  335. "value" => t("Use this form to execute arbitrary PHP code. <b>DO NOT</b>
  336. type php tags (&lt;php ?&gt;). Be careful! Entering bad code
  337. here can harm your site. Only use if you know what you are doing."),
  338. );
  339. $form["system_execute_php"] = array(
  340. "type" => "textarea",
  341. "label" => t("Enter PHP code here:"),
  342. "value" => variable_get("system_execute_php", ""),
  343. "rows" => 20,
  344. );
  345. return $form;
  346. }
  347. function system_execute_php_form_submit($form, $form_state) {
  348. $code = trim($form_state["values"]["system_execute_php"]);
  349. if ($code == "") return;
  350. eval($code);
  351. }
  352. /**
  353. * Display a confirmation form before we run the db updates (hook_updates)
  354. *
  355. * @return unknown
  356. */
  357. function system_confirm_db_updates_form() {
  358. $form = array();
  359. $form["mark" . $m++] = array(
  360. "value" => t("Are you sure you wish to run the database updates?
  361. This will find modules which have been updated, and now need to
  362. make database changes.") . "
  363. <br><br>
  364. " . t("You should back up your entire database first, just in case a problem
  365. occurs!"),
  366. );
  367. $form["submit"] = array(
  368. "type" => "submit",
  369. "value" => t("Continue"),
  370. "prefix" => "<hr>",
  371. "suffix" => "&nbsp; &nbsp; <a href='javascript: history.go(-1);'>" . t("Cancel") . "</a>",
  372. );
  373. $form["mark" . $m++] = array(
  374. "value" => t("Press only once, as this make take several moments to run."),
  375. );
  376. return $form;
  377. }
  378. /**
  379. * Perform the actual hook_update calls here, send the user to a completed page.
  380. *
  381. * @param unknown_type $form
  382. * @param unknown_type $form_state
  383. */
  384. function system_confirm_db_updates_form_submit($form, $form_state) {
  385. // We need to find modules whose schema in their .info file
  386. // is different than what's in the database.
  387. $module_dirs = array();
  388. $module_dirs[] = array("start" => "modules", "type" => t("Core"));
  389. $module_dirs[] = array("start" => "custom/modules", "type" => t("Custom"));
  390. foreach ($module_dirs as $module_dir) {
  391. $start_dir = $module_dir["start"];
  392. if ($dh = opendir($start_dir)) {
  393. while ($file = readdir($dh)) {
  394. if ($file == "." || $file == "..") continue;
  395. if (is_dir($start_dir . "/" . $file)) {
  396. // Okay, now look inside and see if there is a .info file.
  397. if (file_exists("$start_dir/$file/$file.info")) {
  398. $module = $file;
  399. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  400. //fpm($info_contents);
  401. // From the info_contents variable, split up and place into an array.
  402. $info_details_array = array();
  403. $lines = explode("\n", $info_contents);
  404. foreach ($lines as $line) {
  405. if (trim($line) == "") continue;
  406. $temp = explode("=", trim($line));
  407. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  408. }
  409. $path = "$start_dir/$file";
  410. $res = db_query("SELECT * FROM modules WHERE path = '?' ", $path);
  411. $cur = db_fetch_array($res);
  412. $info_details_array["enabled"] = $cur["enabled"];
  413. // Does this module need to run db updates?
  414. if ($cur["enabled"] == "1" && $cur["schema"] != $info_details_array["schema"] && $info_details_array["schema"] != "") {
  415. // YES, we need to run this module's hook_update function, if it exists.
  416. // So, let's try to do that.
  417. // If the module has a .install file, begin by including it.
  418. if (include_module_install($module, $path)) {
  419. // Include the original module file first.
  420. include_module($module, TRUE, $path);
  421. // Now, we can call hook_update, if it exists.
  422. if (function_exists($module . '_update')) {
  423. call_user_func_array($module . '_update', array($cur["schema"], $info_details_array["schema"]));
  424. }
  425. }
  426. // Okay, update the modules table for this module, and set schema to correct version.
  427. $res = db_query("UPDATE modules
  428. SET `schema` = '?'
  429. WHERE path = '?' LIMIT 1 ", $info_details_array["schema"], $path);
  430. fp_add_message(t("The module %module has run its DB updates.", array("%module" => $module)));
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. // Clear our cache
  438. fp_clear_cache();
  439. fp_goto("admin/completed-db-updates");
  440. }
  441. /**
  442. * Once db updates are run, display contents of this page.
  443. *
  444. */
  445. function system_display_completed_db_updates() {
  446. $rtn = "";
  447. $rtn .= t("Database updates have been completed. If you do not see
  448. any errors displayed, it means everything was run correctly.");
  449. $rtn .= "<br><br>
  450. <ul>";
  451. $rtn .= "<li>" . l(t("Return to Admin"), "admin-tools/admin") . "</li>
  452. <li>" . l(t("Return to Modules page"), "admin/config/modules") . "</li>
  453. </ul>";
  454. return $rtn;
  455. }
  456. /**
  457. * This page is displayed to the user once FlightPath has been installed.
  458. */
  459. function system_display_install_finished_page() {
  460. $rtn = "";
  461. // Rebuild one more time
  462. menu_rebuild_cache(FALSE);
  463. fp_show_title(TRUE);
  464. $rtn .= t("Your new installation of FlightPath is now complete.
  465. <br><br>
  466. As a security precaution, you should:
  467. <ul>
  468. <li>change the permissions
  469. on custom/settings.php so that it cannot be read or written to by unauthorized
  470. users.</li>
  471. <li>You should also rename or remove install.php so that web visitors cannot
  472. access it.</li>
  473. </ul>
  474. If you need to re-install FlightPath, delete custom/settings.php, and drop all of the tables
  475. in the database, then re-access install.php.") . "<br><br>";
  476. $rtn .= l(t("Access your new FlightPath site now."), "<front>");
  477. return $rtn;
  478. }
  479. /**
  480. * This is the thank you page you see after submitting the contact form.
  481. */
  482. function system_popup_report_contact_thank_you() {
  483. $rtn = "";
  484. $rtn .= fp_render_curved_line(t("Contact the FlightPath Production Team"));
  485. $rtn .= t("Thank you for submitting to the FlightPath Production Team. They
  486. have received your comment and will review it shortly.") . "<br><br>";
  487. $rtn .= t("You may now close this window.");
  488. return $rtn;
  489. }
  490. /**
  491. * This is the form which lets users send an email to the FlightPath production
  492. * team,
  493. */
  494. function system_popup_report_contact_form() {
  495. $form = array();
  496. fp_set_title("");
  497. $form["mark" . $m++] = array(
  498. "value" => fp_render_curved_line(t("Contact the FlightPath Production Team")),
  499. );
  500. if (!user_has_permission("access_logged_in_content")) {
  501. $form["mark" . $m++] = array(
  502. "value" => t("We're sorry, but for security reasons you may only access this form
  503. if you are logged in to FlightPath."),
  504. );
  505. return $form;
  506. }
  507. $form["mark" . $m++] = array(
  508. "value" => t("If you've noticed an error or have a suggestion, use this
  509. form to contact the FlightPath Production Team."),
  510. );
  511. $form["category"] = array(
  512. "type" => "select",
  513. "label" => t("Please select a category"),
  514. "options" => array(
  515. t("Advising") => t("Advising"),
  516. t("Degree plan") => t("Degree plan"),
  517. t("What If?") => t("What If?"),
  518. t("Searching") => t("Searching"),
  519. t("Comments") => t("Comments"),
  520. t("Other") => t("Other"),
  521. ),
  522. );
  523. $form["comment"] = array(
  524. "type" => "textarea",
  525. "label" => t("Comment:"),
  526. );
  527. $form["submit"] = array(
  528. "type" => "submit",
  529. "value" => t("Send email"),
  530. );
  531. $form["#redirect"] = array("path" => "popup-contact-form/thank-you");
  532. return $form;
  533. }
  534. function system_popup_report_contact_form_submit($form, $form_state) {
  535. global $user;
  536. $category = strip_tags($form_state["values"]["category"]);
  537. $comment = strip_tags($form_state["values"]["comment"]);
  538. $possible_student = $_SESSION["advising_student_id"];
  539. $user_roles = implode(", ", $user->roles);
  540. $datetime = date("Y-m-d H:i:s", strtotime("now"));
  541. //$headers = "From: FlightPath-noreply@noreply.com\n";
  542. $subject = t("FLIGHTPATH REPORT CONTACT") . " - $category ";
  543. $msg = "";
  544. $msg .= t("You have received a new report/contact on") . " $datetime.\n";
  545. $msg .= t("Name:") . " $user->f_name $user->l_name ($user->name) CWID: $user->cwid \n" . t("User roles:") . " $user_roles \n\n";
  546. $msg .= t("Category:") . " $category \n";
  547. $msg .= t("Possible Student:") . " $possible_student \n";
  548. $msg .= t("Comment:") . " \n $comment \n\n";
  549. $msg .= "------------------------------------------------ \n";
  550. $themd5 = md5($user->name . $user->cwid . $comment . $user_roles . $category);
  551. if ($_SESSION["da_error_report_md5"] != $themd5)
  552. { // Helps stop people from resubmitting over and over again
  553. // (by hitting refresh, or by malicious intent)..
  554. $msg = addslashes($msg);
  555. $to = variable_get("contact_email_address", "");
  556. if ($to != "") {
  557. //mail($to,$subject,$msg,$headers);
  558. mail($to,$subject,$msg);
  559. }
  560. }
  561. $_SESSION["da_error_report_md5"] = $themd5;
  562. }
  563. /**
  564. * This form is for the school-data, like subject code descriptions, colleges, etc.
  565. *
  566. */
  567. function system_school_data_form() {
  568. $form = array();
  569. $form["ignore_courses_from_hour_counts"] = array(
  570. "type" => "textfield",
  571. "label" => t("Ignore courses from hour counts (CSV):"),
  572. "value" => variable_get("ignore_courses_from_hour_counts", ""),
  573. "description" => t("List courses, separated by comma,
  574. which should be ignored in hours counts. This helps
  575. remedial courses from being applied to hour counts.
  576. Ex: MATH 093, ENGL 090, UNIV 1001"),
  577. );
  578. $form["term_id_structure"] = array(
  579. "type" => "textarea",
  580. "label" => t("Structure of term ID's:"),
  581. "value" => variable_get("term_id_structure", ""),
  582. "description" => t("Use this space to define termID structures, one per line.
  583. Please see the FlightPath documentation on how to set up this field.") . "
  584. <br>" . t("Ex:") . "
  585. <br>[Y4]60, Spring, Spring of [Y4], Spr '[Y2]
  586. <br>[Y4]40, Fall, Fall of [Y4-1], Fall '[Y2-1]",
  587. );
  588. // Let's load the subjects...
  589. $subjects = "";
  590. $query = "SELECT DISTINCT b.subject_id, a.title, a.college FROM courses b LEFT JOIN subjects a
  591. ON (a.subject_id = b.subject_id)
  592. WHERE exclude = 0
  593. ORDER BY b.subject_id
  594. ";
  595. $result = db_query($query);
  596. while ($cur = db_fetch_array($result))
  597. {
  598. //fpm($cur);
  599. $title = trim($cur["title"]);
  600. $subject_id = trim($cur["subject_id"]);
  601. $college = trim($cur["college"]);
  602. $subjects .= $subject_id . " ~ " . $college . " ~ " . $title . "\n";
  603. }
  604. $form["subjects"] = array(
  605. "type" => "textarea",
  606. "label" => t("Subjects:"),
  607. "value" => $subjects,
  608. "rows" => 15,
  609. "description" => t("Enter subjects known to FlightPath (for use
  610. in popups and the Course Search, for example), one per line
  611. in this format:") . "<br>SUBJ ~ COLLEGE ~ Title<br>" . t("For example:") . "
  612. <br>&nbsp; ACCT ~ BA ~ Accounting<br>&nbsp; BIOL ~ AS ~ Biology<br>" . t("Notice
  613. the separator between the code, college, and title is 1 tilde (~). Whatespace is ignored."),
  614. );
  615. // Load the colleges...
  616. $colleges = "";
  617. $res = db_query("SELECT * FROM colleges ORDER BY college_code");
  618. while ($cur = db_fetch_array($res)) {
  619. $colleges .= $cur["college_code"] . " ~ " . $cur["title"] . "\n";
  620. }
  621. $form["colleges"] = array(
  622. "type" => "textarea",
  623. "label" => t("Colleges:"),
  624. "value" => $colleges,
  625. "description" => t("Enter colleges known to FlightPath, one per line, in this format:
  626. ") . "<br>COLLEGE_CODE ~ Title<br>" . t("For example:") . "
  627. <br>&nbsp; AE ~ College of Arts, Science, and Education
  628. <br>&nbsp; PY ~ College of Pharmacy<br>" . t("Notice
  629. the separator between the code and title is 1 tilde (~). Whitespace is ignored."),
  630. );
  631. // Load the degree_college data....
  632. $degree_college = "";
  633. $res = db_query("SELECT DISTINCT(major_code) FROM draft_degrees ORDER BY major_code");
  634. while ($cur = db_fetch_array($res)) {
  635. $major_code = $cur["major_code"];
  636. // Is there an assigned college already?
  637. $res2 = db_query("SELECT college_code FROM degree_college WHERE major_code = '?' ", $major_code);
  638. $cur2 = db_fetch_array($res2);
  639. $college_code = $cur2["college_code"];
  640. $degree_college .= $major_code . " ~ " . $college_code . "\n";
  641. }
  642. $form["degree_college"] = array(
  643. "type" => "textarea",
  644. "label" => t("Degree Colleges:"),
  645. "value" => $degree_college,
  646. "rows" => 15,
  647. "description" => t("Enter the degree's college, one per line, in this format:
  648. ") . "<br>MAJOR_CODE ~ COLLEGE_CODE<br>" . t("For example:") . "
  649. <br>&nbsp; ACCT ~ AE
  650. <br>&nbsp; BUSN ~ SB<br>" . t("Notice
  651. the separator between the codes is 1 tilde (~). Whitespace is ignored."),
  652. );
  653. // How many decimal places allowed in substitutions?
  654. $form["sub_hours_decimals_allowed"] = array(
  655. "type" => "select",
  656. "label" => t("Substitution hours decimal places allowed:"),
  657. "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)")),
  658. "value" => variable_get("sub_hours_decimals_allowed", 2),
  659. "no_please_select" => TRUE,
  660. "description" => t("For hours with decimals (like 2.25 hours), how many numbers
  661. after the decimal place will be allowed? Affects users performing
  662. substitutions. For example, if you select \"2\" here, then
  663. a value of 1.2555 will be rejected, and the user will be asked to re-enter.
  664. 1.25, would be accepted, since it has 2 decimal places.
  665. <br>If you are unsure what to select, set to 2."),
  666. );
  667. // Auto-correct course titles?
  668. $form["autocapitalize_course_titles"] = array(
  669. "type" => "select",
  670. "label" => t("Auto-capitalize course titles?"),
  671. "options" => array("yes" => "Yes", "no" => "No"),
  672. "hide_please_select" => TRUE,
  673. "value" => variable_get("autocapitalize_course_titles", "yes"),
  674. "description" => t("If set to yes, course titles in FlightPath will be run through a capitalization
  675. filter, so that 'INTRO TO ACCOUNTING' becomes 'Intro to Accounting'.
  676. Generally, this makes the course names more attractive, but it can
  677. incorrectly capitalize acronyms and initials. Disable if you would like
  678. complete control over capitalization.
  679. <br>If unsure, set to Yes."),
  680. );
  681. $form["retake_grades"] = array(
  682. "type" => "textfield",
  683. "label" => t("Retake grades (CSV):"),
  684. "value" => variable_get("retake_grades", ""),
  685. "description" => t("List grades, separated by comma, which means 'the student must
  686. retake this course. They did not earn credit.' Ex: F,W,I"),
  687. );
  688. $form["enrolled_grades"] = array(
  689. "type" => "textfield",
  690. "label" => t("Enrolled grades (CSV):"),
  691. "value" => variable_get("enrolled_grades", ""),
  692. "description" => t("List grades, separated by comma, which means 'the student is
  693. currently enrolled in this course.' Ex: E,AMID,BMID "),
  694. );
  695. $form["b_or_better"] = array(
  696. "type" => "textfield",
  697. "label" => t("B or better grades (CSV):"),
  698. "value" => variable_get("b_or_better", ""),
  699. "description" => t("List grades, separated by comma, which are either a B or better."),
  700. );
  701. $form["c_or_better"] = array(
  702. "type" => "textfield",
  703. "label" => t("C or better grades (CSV):"),
  704. "value" => variable_get("c_or_better", ""),
  705. "description" => t("List grades, separated by comma, which are either a C or better."),
  706. );
  707. $form["d_or_better"] = array(
  708. "type" => "textfield",
  709. "label" => t("D or better grades (CSV):"),
  710. "value" => variable_get("d_or_better", ""),
  711. "description" => t("List grades, separated by comma, which are either a D or better."),
  712. );
  713. $form["calculate_cumulative_hours_and_gpa"] = array(
  714. "label" => t("Calculate student cumulative hours and GPA?"),
  715. "type" => "checkbox",
  716. "value" => variable_get("calculate_cumulative_hours_and_gpa", FALSE),
  717. "description" => t("If checked, student cumulative hours and GPA will not be read from the
  718. 'students' database table, but will instead be calculated on the fly
  719. each time a student is loaded. If unsure what to do, check this box."),
  720. );
  721. $form["quality_points_grades"] = array(
  722. "label" => t("Quality points and grades:"),
  723. "type" => "textarea",
  724. "value" => variable_get("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0"),
  725. "description" => t("Enter a grade, and how many quality points it is worth, separated by
  726. tilde (~), one per line. You must include every grade which should count
  727. for (or against) a GPA calculation, even if it is worth zero points. For example,
  728. if an 'F' should cause a GPA to lower (which normally it would), it should be
  729. listed here. If a 'W' grade should simply be ignored, then DO NOT list it here.
  730. Any grade you do not list here will be IGNORED in all GPA calculations.") . "
  731. <br>
  732. Ex:<blockquote style='margin-top:0; font-family: Courier New, monospace;'>
  733. A ~ 4<br>B ~ 3<br>C ~ 2<br>D ~ 1<br>F ~ 0<br>I ~ 0</blockquote>",
  734. );
  735. return $form;
  736. }
  737. /**
  738. * Validate handler for the school_data_form.
  739. *
  740. * Most of our data can be saved as simple system_settings, but for the others,
  741. * we want to save them to special tables, then remove them from the form_state so
  742. * they don't get saved to the variables table, taking up a lot of space.
  743. *
  744. * @param unknown_type $form
  745. * @param unknown_type $form_state
  746. */
  747. function system_school_data_form_validate($form, &$form_state) {
  748. // Subjects...
  749. db_query("TRUNCATE TABLE subjects");
  750. $subjects = trim($form_state["values"]["subjects"]);
  751. $lines = explode("\n", $subjects);
  752. foreach ($lines as $line) {
  753. $temp = explode("~", $line);
  754. db_query("INSERT INTO subjects (subject_id, college, title)
  755. VALUES ('?', '?', '?') ", strtoupper(trim($temp[0])), strtoupper(trim($temp[1])), trim($temp[2]));
  756. }
  757. // Remove the data from our form_state, so it isn't saved twice
  758. unset($form_state["values"]["subjects"]);
  759. // Colleges...
  760. db_query("TRUNCATE TABLE colleges");
  761. $contents = trim($form_state["values"]["colleges"]);
  762. $lines = explode("\n", $contents);
  763. foreach ($lines as $line) {
  764. $temp = explode("~", $line);
  765. db_query("INSERT INTO colleges (college_code, title)
  766. VALUES ('?', '?') ", strtoupper(trim($temp[0])), trim($temp[1]));
  767. }
  768. // Remove the data from our form_state, so it isn't saved twice
  769. unset($form_state["values"]["colleges"]);
  770. // Degree College...
  771. db_query("TRUNCATE TABLE degree_college");
  772. $contents = trim($form_state["values"]["degree_college"]);
  773. $lines = explode("\n", $contents);
  774. foreach ($lines as $line) {
  775. $temp = explode("~", $line);
  776. db_query("INSERT INTO degree_college (major_code, college_code)
  777. VALUES ('?', '?') ", strtoupper(trim($temp[0])), strtoupper(trim($temp[1])));
  778. }
  779. // Remove the data from our form_state, so it isn't saved twice
  780. unset($form_state["values"]["degree_college"]);
  781. }
  782. /**
  783. * This is the "system settings" form.
  784. */
  785. function system_settings_form() {
  786. $form = array();
  787. $form["mark" . $m++] = array(
  788. "value" => t("Use this form to alter the various system settings in FlightPath.
  789. Before making changes, it is always good policy to first back up your database."),
  790. );
  791. $form["mark" . $m++] = array(
  792. "value" => "<p><div style='font-size:0.8em;'>" . t("Your site requires a cron job in order to perform routine tasks. This
  793. is accomplished by having your server access the following URL every so often
  794. (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>
  795. <br>" . t("Example linux cron command:") . "&nbsp; <i>wget -O - -q -t 1 http://ABOVE_URL</i></div></p>",
  796. );
  797. $form["maintenance_mode"] = array(
  798. "label" => t("Set maintenance mode?"),
  799. "type" => "checkbox",
  800. "value" => variable_get("maintenance_mode", FALSE),
  801. "description" => t("If checked, a message will display on every page stating
  802. that the system is currently undergoing routine maintenance."),
  803. );
  804. $form["contact_email_address"] = array(
  805. "type" => "textfield",
  806. "label" => t("Contact email address:"),
  807. "value" => variable_get("contact_email_address", ""),
  808. "description" => t("Enter the email address to mail when a user accesses the
  809. Contact FlightPath Production Team popup."),
  810. );
  811. $form["theme"] = array(
  812. "type" => "textfield",
  813. "label" => t("Theme location:"),
  814. "value" => variable_get("theme", "themes/classic"),
  815. "description" => t("Enter the file location for your theme. Do not put preceeding or trailing slashes. Ex: themes/classic"),
  816. );
  817. $form["school_initials"] = array(
  818. "type" => "textfield",
  819. "size" => 20,
  820. "label" => t("School initials:"),
  821. "value" => variable_get("school_initials", "DEMO"),
  822. "description" => t("Ex: ULM or BPCC"),
  823. );
  824. $form["earliest_catalog_year"] = array(
  825. "type" => "textfield",
  826. "size" => 20,
  827. "label" => t("Earliest catalog year:"),
  828. "value" => variable_get("earliest_catalog_year", "2006"),
  829. "description" => t("This is the earliest possible catalog year FlightPath may look
  830. up. Typically, this is the earliest year for which you have
  831. data (ie, when FlightPath went online.
  832. If FlightPath cannot figure out a catalog year to use,
  833. it will default to this one. Ex: 2006"),
  834. );
  835. $form["graduate_level_course_num"] = array(
  836. "type" => "textfield",
  837. "size" => 20,
  838. "label" => t("Graduate level course num:"),
  839. "value" => variable_get("graduate_level_course_num", "5000"),
  840. "description" => t("This is the course num which means 'graduate level', meaning
  841. anything above it is considered a graduate level course. Ex: 5000"),
  842. );
  843. $form["allowed_student_ranks"] = array(
  844. "type" => "textfield",
  845. "label" => t("Allowed student ranks (CSV):"),
  846. "value" => variable_get("allowed_student_ranks", ""),
  847. "description" => t("This is a list of which student ranks are allowed into FlightPath.
  848. It should be separated by commas.
  849. This also affects which students you may search for on the Advisees
  850. tab. Ex: FR, SO, JR, SR"),
  851. );
  852. $form["not_allowed_student_message"] = array(
  853. "type" => "textarea",
  854. "label" => t("Not allowed student message:"),
  855. "value" => variable_get("not_allowed_student_message", ""),
  856. "description" => t("When a student is NOT allowed into FlightPath because of their
  857. rank, this message will be displayed."),
  858. );
  859. $form["hiding_grades_message"] = array(
  860. "type" => "textarea",
  861. "label" => t("Hiding grades message:"),
  862. "value" => variable_get("hiding_grades_message", ""),
  863. "description" => t("This message will be displayed when any course on the page
  864. has its bool_hide_grade set to TRUE. If you are not using
  865. this functionality, you can leave this blank."),
  866. );
  867. $form["notify_apply_draft_changes_email_address"] = array(
  868. "type" => "textfield",
  869. "label" => t("Notify apply draft changes email address:"),
  870. "value" => variable_get("notify_apply_draft_changes_email_address", ""),
  871. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  872. draft changes are applied from the admin console.
  873. Leave blank to disable."),
  874. );
  875. $form["notify_mysql_error_email_address"] = array(
  876. "type" => "textfield",
  877. "label" => t("Notify MySQL error email address:"),
  878. "value" => variable_get("notify_mysql_error_email_address", ""),
  879. "description" => t("Enter 1 or more email addresses (separated by comma) to notify when
  880. a mysql error occurs.
  881. Leave blank to disable."),
  882. );
  883. $form["admin_transfer_passcode"] = array(
  884. "type" => "textfield",
  885. "label" => t("Admin Apply Draft password:"),
  886. "value" => variable_get("admin_transfer_passcode", "changeMe"),
  887. "description" => t("Enter a password which an admin user must enter
  888. in order to apply draft changes to FlightPath.
  889. This is an added security measure. Ex: p@ssWord569w"),
  890. );
  891. return $form;
  892. }
  893. /**
  894. * Extra submit handler for the system_settings_form
  895. *
  896. * @param unknown_type $form
  897. * @param unknown_type $form_state
  898. */
  899. function system_settings_form_submit($form, &$form_state) {
  900. // Empty, for the time being.
  901. }
  902. /**
  903. * Intercepts form submissions from System Settings Forms.
  904. */
  905. function system_handle_form_submit() {
  906. $callback = $_REQUEST["callback"];
  907. $form_type = $_REQUEST["form_type"];
  908. $form_include = $_REQUEST["form_include"];
  909. $form_token = $_REQUEST["form_token"];
  910. // Make sure the form_token is valid!
  911. if ($form_token != md5($callback . fp_token())) {
  912. die(t("Sorry, but you have encountered an error. A form submission was flagged
  913. as possibly being an invalid or forged submission. This may constitute a bug
  914. in the system. Please report this error to your Systems Administrator."));
  915. }
  916. if ($form_include != "") {
  917. // This is a file we need to include in order to complete the submission process.
  918. include_once($form_include);
  919. }
  920. // We need to make sure the user has permission to submit this form!
  921. $form_path = $_REQUEST["form_path"];
  922. // Check the menu router table for whatever the permissions were for this
  923. // path, if any.
  924. if ($form_path != "") {
  925. $router_item = menu_get_item($form_path) ;
  926. if (!menu_check_user_access($router_item)) {
  927. // The user does NOT have access to submit this form! The fact that
  928. // it has made it this far means this may be some sort of hacking attempt.
  929. die(t("Sorry, but you have encountered an error. A form submission was flagged
  930. as possibly being an invalid or having insufficient permissions to submit.
  931. This may constitute a bug in the system.
  932. Please report this error to your Systems Administrator."));
  933. }
  934. }
  935. // Let's get our set of allowed values, by looking at the original form,
  936. // and grab what's in the POST which matches the name.
  937. $values = array();
  938. if (function_exists($callback)) {
  939. $form = fp_get_form($callback);
  940. foreach ($form as $name => $element) {
  941. $values[$name] = $_POST[$name];
  942. // Do we need to alter the value from the POST?
  943. // If this is a checkbox, and we have any value in the POST, it should
  944. // be saved as boolean TRUE
  945. if ($element["type"] == "checkbox") {
  946. if (isset($_POST[$name]) && $_POST[$name] === "1") {
  947. $values[$name] = TRUE;
  948. }
  949. }
  950. }
  951. }
  952. // Does the form have any defined submit_handler's? If not, let's assign it the
  953. // default of callback_submit().
  954. $submit_handlers = $form["#submit_handlers"];
  955. if (!is_array($submit_handlers)) $submit_handlers = array();
  956. // If the submit_handlers is empty, then add our default submit handler. We don't
  957. // want to do this if the user went out of their way to enter a different handler.
  958. if (count($submit_handlers) == 0) {
  959. array_push($submit_handlers, $callback . "_submit");
  960. }
  961. // Does the form have any defined validate_handler's? This works exactly like the submit handler.
  962. $validate_handlers = $form["#validate_handlers"];
  963. if (!is_array($validate_handlers)) $validate_handlers = array();
  964. if (count($validate_handlers) == 0) {
  965. array_push($validate_handlers, $callback . "_validate");
  966. }
  967. // Let's store our values in the SESSION in case we need them later on.
  968. // But only if this is NOT a system_settings form!
  969. if ($form_type != "system_settings") {
  970. $_SESSION["fp_form_submissions"][$callback]["values"] = $values;
  971. }
  972. $form_state = array("values" => $values);
  973. // Let's pass this through our default form validator (mainly to check for required fields
  974. // which do not have values entered)
  975. form_basic_validate($form, $form_state);
  976. if (!form_has_errors()) {
  977. // Let's now pass it through all of our custom validators, if there are any.
  978. foreach ($validate_handlers as $validate_callback) {
  979. if (function_exists($validate_callback)) {
  980. call_user_func_array($validate_callback, array(&$form, &$form_state));
  981. }
  982. }
  983. }
  984. if (!form_has_errors()) {
  985. // No errors from the validate, so let's continue.
  986. // Is this a "system settings" form, or a normal form?
  987. if ($form_type == "system_settings") {
  988. // This is system settings, so let's save all of our values to the variables table.
  989. // Write our values array to our variable table.
  990. foreach ($form_state["values"] as $name => $val) {
  991. variable_set($name, $val);
  992. }
  993. fp_add_message("Settings saved successfully.");
  994. }
  995. // Let's go through the form's submit handlers now.
  996. foreach ($submit_handlers as $submit_callback) {
  997. if (function_exists($submit_callback)) {
  998. //call_user_func($submit_callback, $form, &$form_state);
  999. call_user_func_array($submit_callback, array(&$form, &$form_state));
  1000. }
  1001. }
  1002. }
  1003. // Figure out where we are supposed to redirect the user.
  1004. $redirect_path = $redirect_query = "";
  1005. if (is_array($form["#redirect"])) {
  1006. $redirect_path = $form["#redirect"]["path"];
  1007. $redirect_query = $form["#redirect"]["query"];
  1008. }
  1009. else {
  1010. $redirect_path = $_REQUEST["default_redirect_path"];
  1011. $redirect_query = $_REQUEST["default_redirect_query"];
  1012. }
  1013. // Okay, go back to where we were!
  1014. fp_goto($redirect_path, $redirect_query);
  1015. }
  1016. function system_handle_logout() {
  1017. global $user;
  1018. $name = $user->name;
  1019. $uid = $user->id;
  1020. // Check for hook_user_logout
  1021. $modules = modules_implement_hook("user_logout");
  1022. foreach($modules as $module) {
  1023. call_user_func($module . '_user_logout');
  1024. }
  1025. // Finish up logging out.
  1026. $_SESSION["fp_logged_in"] = FALSE;
  1027. $_SESSION["fp_user_object"] = FALSE;
  1028. session_destroy();
  1029. session_start();
  1030. watchdog("logout", "@user has logged out", array("@user" => "$name ($uid)"));
  1031. fp_add_message(t("You have been logged out of FlightPath."));
  1032. fp_goto("<front>");
  1033. }
  1034. /**
  1035. * This function will clear our various caches by calling
  1036. * on the hook_clear_cache in each module.
  1037. */
  1038. function system_perform_clear_cache() {
  1039. fp_clear_cache();
  1040. fp_goto("<front>");
  1041. }
  1042. /**
  1043. * Called from menu, will run hook_cron() for all modules.
  1044. */
  1045. function system_perform_run_cron() {
  1046. invoke_hook("cron");
  1047. fp_add_message(t("Cron run completed successfully."));
  1048. variable_set("cron_last_run", time());
  1049. fp_goto("admin-tools/admin");
  1050. }
  1051. /**
  1052. * This page displayes the results of each module's hook_status.
  1053. *
  1054. */
  1055. function system_display_status_page() {
  1056. $rtn = "";
  1057. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  1058. $status_array = invoke_hook("status"); // get everyone's hook_status.
  1059. $rtn .= "<p>" . t("This page will show you important status messages
  1060. about FlightPath. For example, what modules (if any) have
  1061. an update available.") . "</p>";
  1062. $rtn .= "<table width='100%' border='1' class='status-table' cellpadding='4'>
  1063. <tr class='header-row'>
  1064. <th width='10%' class='package-header'>" . t("Package") . "</th>
  1065. <th>" . t("Status") . "</th>
  1066. </tr>";
  1067. foreach ($status_array as $module => $details) {
  1068. $pol = ($pol == "even") ? "odd" : "even";
  1069. if ($details["severity"] == "") $details["severity"] = "normal";
  1070. $rtn .= "<tr class='status-row status-row-$pol'>
  1071. <td valign='top' class='module-name'>$module</td>
  1072. <td valign='top' class='module-status module-status-" . $details["severity"] . "'>
  1073. " . $details["status"] . "
  1074. </td>
  1075. </tr>";
  1076. }
  1077. $rtn .= "</table>";
  1078. return $rtn;
  1079. }
  1080. /**
  1081. * Implementation of hook_status
  1082. * Expected return is array(
  1083. * "severity" => "normal" or "warning" or "alert",
  1084. * "status" => "A message to display to the user.",
  1085. * );
  1086. */
  1087. function system_status() {
  1088. $rtn = array();
  1089. $rtn["severity"] = "normal";
  1090. // Check on the last time cron was run; make sure it's working properly.
  1091. $last_run = variable_get("cron_last_run", 0);
  1092. // Report on current details about FlightPath.
  1093. $rtn["status"] .= "<p>" . t("FlightPath version:") . " " . FLIGHTPATH_CORE . "-" . FLIGHTPATH_VERSION . "</p>";
  1094. if ($last_run < strtotime("-2 DAY")) {
  1095. $rtn["severity"] = "alert";
  1096. $rtn["status"] .= t("Cron hasn't run in over 2 days. For your installation of FlightPath
  1097. to function properly, cron.php must be accessed routinely. At least once per day is recommended.");
  1098. }
  1099. else {
  1100. $rtn["status"] .= t("Cron was last run on %date", array("%date" => format_date($last_run)));
  1101. }
  1102. $rtn["status"] .= "<p style='font-size: 0.8em;'>" . t("Your site's cron URL is:");
  1103. $rtn["status"] .= "<br>&nbsp; &nbsp; <i>" . $GLOBALS["fp_system_settings"]["base_url"] . "/cron.php?t=" . $GLOBALS["fp_system_settings"]["cron_security_token"] . "</i>
  1104. <br>" . t("Example linux cron command:") . "&nbsp; <i>wget -O - -q -t 1 http://ABOVE_URL</i>";
  1105. $rtn["status"] .= "</p>";
  1106. return $rtn;
  1107. }
  1108. /**
  1109. * Implements hook_clear_cache
  1110. * Take care of clearing caches managed by this module
  1111. */
  1112. function system_clear_cache() {
  1113. menu_rebuild_cache();
  1114. }
  1115. /**
  1116. * Clears only the menu cache
  1117. */
  1118. function system_perform_clear_menu_cache() {
  1119. menu_rebuild_cache();
  1120. fp_goto("admin-tools/admin");
  1121. }
  1122. /**
  1123. * Display the "login" page. This is the default page displayed
  1124. * to the user, at /login, if they have not logged in yet.
  1125. *
  1126. * This page is meant to be displayed in conjunction with blocks, so the user can
  1127. * easily define their own messages and such.
  1128. *
  1129. * @return unknown
  1130. */
  1131. function system_display_login_page() {
  1132. $rtn = "";
  1133. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  1134. $top_blocks = blocks_render_blocks("system_login", "top");
  1135. $bottom_blocks = blocks_render_blocks("system_login", "bottom");
  1136. $left_col_blocks = blocks_render_blocks("system_login", "left_col");
  1137. $right_col_blocks = blocks_render_blocks("system_login", "right_col");
  1138. $rtn .= "<noscript>
  1139. <div style='padding: 5px; background-color: red; color: white; font-size: 12pt; font-weight: bold;'>
  1140. " . t("FlightPath requires JavaScript to be enabled in order to
  1141. function correctly. Please enable JavaScript on your browser
  1142. before continuing.") . "</div>
  1143. </noscript>";
  1144. $w1 = 300;
  1145. if (fp_screen_is_mobile()) $w1 = "90%";
  1146. $login_box = fp_render_curved_line("Please login below...");
  1147. $login_box .= fp_render_form("system_login_form");
  1148. if (fp_screen_is_mobile()) {
  1149. // the user is viewing this on a mobile device, so make it look
  1150. // a bit nicer.
  1151. $rtn .= $top_blocks . $left_col_blocks . $right_col_blocks . $bottom_blocks;
  1152. }
  1153. else {
  1154. // This is NOT mobile, this is a regular desktop browser.
  1155. $rtn .= "
  1156. $top_blocks
  1157. <table border='0'>
  1158. <tr>
  1159. <td valign='top' width='40%'>
  1160. $left_col_blocks
  1161. </td>
  1162. <td valign='top' style='padding-left: 20px;'>
  1163. $right_col_blocks
  1164. </td>
  1165. </tr>
  1166. </table>
  1167. $bottom_blocks
  1168. ";
  1169. }
  1170. return $rtn;
  1171. }
  1172. /**
  1173. * This draws the form which facilitates logins.
  1174. */
  1175. function system_login_form() {
  1176. $form = array();
  1177. fp_set_title("");
  1178. $form["user"] = array(
  1179. "label" => t("User:"),
  1180. "type" => "textfield",
  1181. "size" => 30,
  1182. "required" => TRUE,
  1183. );
  1184. $form["password"] = array(
  1185. "label" => t("Password:"),
  1186. "type" => "password",
  1187. "size" => 30,
  1188. "required" => TRUE,
  1189. );
  1190. $form["submit"] = array(
  1191. "type" => "submit",
  1192. "value" => t("Login"),
  1193. );
  1194. $form["#attributes"] = array("onSubmit" => "showUpdate(true);");
  1195. return $form;
  1196. }
  1197. /**
  1198. * Validate function for the login form.
  1199. * This is where we will do all of the lookups to verify username
  1200. * and password. If you want to write your own login handler (like for LDAP)
  1201. * this is the function you would duplicate in a custom module, then use hook_form_alter
  1202. * to make your function be the validator, not this one.
  1203. *
  1204. * We will simply verify the password, then let the submit handler take over from there.
  1205. */
  1206. function system_login_form_validate($form, &$form_state) {
  1207. $user = $form_state["values"]["user"];
  1208. $password = $form_state["values"]["password"];
  1209. // If the GRANT_FULL_ACCESS is turned on, skip trying to validate
  1210. if ($GLOBALS["fp_system_settings"]["GRANT_FULL_ACCESS"] == TRUE) {
  1211. $user = "admin";
  1212. $form_state["passed_authentication"] = TRUE;
  1213. $form_state["db_row"]["user_id"] = 1;
  1214. $form_state["db_row"]["user_name"] = "FULL ACCESS USER";
  1215. return;
  1216. }
  1217. // Otherwise, check the table normally.
  1218. // Check the user's password is valid.
  1219. $res = db_query("SELECT * FROM users WHERE user_name = '?' AND password = '?' AND is_disabled = '0' ", $user, md5($password));
  1220. if (db_num_rows($res) == 0) {
  1221. form_error("password", t("Sorry, but that username and password combination could not
  1222. be found. Please check your spelling and try again."));
  1223. return;
  1224. }
  1225. $cur = db_fetch_array($res);
  1226. $form_state["db_row"] = $cur;
  1227. // If we made it here, then the user successfully authenticated.
  1228. $form_state["passed_authentication"] = TRUE;
  1229. // It will now proceed to the submit handler.
  1230. }
  1231. /**
  1232. * Submit handler for login form.
  1233. * If we are here, it probably means we have indeed authenticated. Just in case, we will
  1234. * test the form_state["passed_authentication"] value, which we expect to have been
  1235. * set in our validate handler.
  1236. *
  1237. * We will now proceed to actually log the user into the system.
  1238. *
  1239. */
  1240. function system_login_form_submit($form, &$form_state) {
  1241. $user = $form_state["values"]["user"];
  1242. $password = $form_state["value"]["password"];
  1243. $passed = $form_state["passed_authentication"];
  1244. $db_row = $form_state["db_row"];
  1245. if (!$passed) {
  1246. fp_add_message(t("Sorry, there has been an error while trying to authenticate the user."));
  1247. return;
  1248. }
  1249. $_SESSION["fp_logged_in"] = TRUE;
  1250. // Set up a new $account object.
  1251. $account = new stdClass();
  1252. $account = fp_load_user($db_row["user_id"]);
  1253. // Okay, let's look for all the modules who have implimented hook_user_login
  1254. $modules = modules_implement_hook("user_login");
  1255. foreach ($modules as $module) {
  1256. call_user_func_array($module . '_user_login', array(&$account));
  1257. }
  1258. // Set the $account to the SESSION.
  1259. $_SESSION["fp_user_object"] = $account;
  1260. watchdog("login", "@user has logged in. CWID: @cwid", array("@user" => "$account->name ($account->id)", "@cwid" => $account->cwid));
  1261. fp_goto("<front>");
  1262. }
  1263. /**
  1264. * Display the "main" tab-page for FlightPath. Displays announcements
  1265. * as well as the Tools menu, and the "special administrative tools" menu.
  1266. */
  1267. function system_display_main_page() {
  1268. global $user;
  1269. $rtn = "";
  1270. // If we are not logged in, then we need to re-direct the user to
  1271. // the login page!
  1272. if ($_SESSION["fp_logged_in"] != TRUE) {
  1273. fp_goto("login");
  1274. return;
  1275. }
  1276. $rtn .= "<table class='fp-semester-table'>";
  1277. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  1278. $left_col_blocks = blocks_render_blocks("system_main", "left_col");
  1279. $right_col_blocks = blocks_render_blocks("system_main", "right_col");
  1280. if (fp_screen_is_mobile()) {
  1281. $rtn .= "<tr><td colspan='2'>$left_col_blocks $right_col_blocks</td></tr>";
  1282. }
  1283. else {
  1284. $rtn .= "<tr><td width='50%' valign='top' style='padding-right: 10px;'>
  1285. $left_col_blocks
  1286. </td><td width='50%' valign='top' style='padding-left: 10px;'>
  1287. $right_col_blocks
  1288. </td></tr>";
  1289. }
  1290. $rtn .= "</table>";
  1291. $rtn .= "<form id='mainform' method='POST'>
  1292. <input type='hidden' id='scrollTop'>
  1293. <input type='hidden' id='performAction' name='performAction'>
  1294. <input type='hidden' id='advisingWhatIf' name='advisingWhatIf'>
  1295. <input type='hidden' id='currentStudentID' name='currentStudentID'>
  1296. </form>";
  1297. //$pC .= $screen->get_javascript_code();
  1298. /*
  1299. $screen->page_content = $pC;
  1300. $screen->page_has_search = true;
  1301. if ($_SESSION["fp_user_type"] == "student" || $_SESSION["fp_can_advise"] == false)
  1302. {
  1303. $screen->page_has_search = false;
  1304. }
  1305. $screen->build_system_tabs(0);
  1306. */
  1307. //////////////////////////////////////////////////////////
  1308. // To cut down on how long it takes to load huge groups
  1309. // like Free Electives, we will pre-load some of the course inventory here.
  1310. if ($_SESSION["fp_cached_inventory_flag_one"] != true)
  1311. {
  1312. $load_number = $GLOBALS["fp_system_settings"]["load_course_inventory_on_login_number"];
  1313. if ($load_number > 1) {
  1314. $fp = new FlightPath();
  1315. $fp->cache_course_inventory(0,$load_number);
  1316. $_SESSION["fp_cached_inventory_flag_one"] = true;
  1317. }
  1318. }
  1319. // send to the browser
  1320. //$screen->output_to_browser();
  1321. return $rtn;
  1322. }
  1323. function system_blocks() {
  1324. return array(
  1325. "tools" => t("Tools menu"),
  1326. "admin_tools" => t("Admin Tools menu"),
  1327. "login_form" => t("Login form"),
  1328. );
  1329. }
  1330. function system_render_block($delta) {
  1331. $block = array();
  1332. if ($delta == "tools") {
  1333. $block["title"] = t("Tools");
  1334. $block["body"] = fp_render_menu_block("", "tools");
  1335. }
  1336. if ($delta == "admin_tools") {
  1337. $block["title"] = t("Administrative Tools");
  1338. $block["body"] = fp_render_menu_block("", "admin-tools");
  1339. }
  1340. if ($delta == "login_form") {
  1341. $block["title"] = t("Please log in below...");
  1342. $block["body"] = fp_render_form("system_login_form");
  1343. }
  1344. // We don't want empty blocks to show up at all.
  1345. if ($block["body"] == "") {
  1346. return FALSE;
  1347. }
  1348. return $block;
  1349. }
  1350. /**
  1351. * Called on every page load.
  1352. */
  1353. function system_init() {
  1354. // Let's see if the $user object (for the logged-in user) has been set up.
  1355. global $user;
  1356. $user = new stdClass();
  1357. if ($_SESSION["fp_logged_in"] == TRUE) {
  1358. // Make sure it doesn't have the anonymous user role (rid == 1).
  1359. if ($_SESSION["fp_user_object"]->roles[1] == "anonymous user") {
  1360. unset($_SESSION["fp_user_object"]->roles[1]);
  1361. }
  1362. $user = $_SESSION["fp_user_object"];
  1363. // To make sure we pick up the user's newest permissions, re-load
  1364. // the user here.
  1365. $user = fp_load_user($user->id);
  1366. }
  1367. else {
  1368. // User is anonymous, so set it up as such.
  1369. $user = fp_load_user(0);
  1370. }
  1371. // Are we in maintenance mode? If so, display a message.
  1372. if (variable_get("maintenance_mode", FALSE)) {
  1373. fp_add_message(t("FlightPath is currently undergoing routine maintenance.
  1374. During this time, some data may appear incomplete.
  1375. We apologize for the inconvenience and appreciate your patience."), "status", TRUE);
  1376. }
  1377. // Is there an urgent message to display?
  1378. $urgent_msg = variable_get("urgent_msg", "");
  1379. if ($urgent_msg) {
  1380. fp_add_message("<b>" . t("Important Message:") . "</b> " . $urgent_msg, "status", TRUE);
  1381. }
  1382. // Add in our custom JS settings.
  1383. fp_add_js(array("themeLocation" => fp_theme_location(), "currentStudentId" => $_REQUEST["current_student_id"], "basePath" => base_path()), "setting");
  1384. fp_add_js(fp_get_module_path("system") . "/js/system.js");
  1385. }
  1386. /**
  1387. * This is the form which an admin may use to manage the modules
  1388. * in the system.
  1389. */
  1390. function system_modules_form() {
  1391. $form = array();
  1392. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  1393. $form["mark" . $m++] = array(
  1394. "value" => t("Use this form to enable or disable modules. This scans the /modules/ and then /custom/modules/
  1395. directories.") . "
  1396. " . l(t("Run DB updates?"), "admin/db-updates") . "<br><br>",
  1397. );
  1398. // Begin by scanning the /modules/ directory. Anything in there
  1399. // cannot be disabled.
  1400. $module_dirs = array();
  1401. $module_dirs[] = array("start" => "modules", "type" => t("Core"));
  1402. $module_dirs[] = array("start" => "custom/modules", "type" => t("Custom"));
  1403. foreach ($module_dirs as $module_dir) {
  1404. $start_dir = $module_dir["start"];
  1405. if ($dh = opendir($start_dir)) {
  1406. //$pC .= "<div class='fp-system-modules-type'>{$module_dir["type"]}</div>
  1407. // <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>";
  1408. $form["mark" . $m++] = array(
  1409. "value" => "<div class='fp-system-modules-type'>{$module_dir["type"]}</div>
  1410. <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>",
  1411. );
  1412. $pol = "even";
  1413. $dir_files = scandir($start_dir);
  1414. foreach ($dir_files as $file) {
  1415. if ($file == "." || $file == "..") continue;
  1416. if (is_dir($start_dir . "/" . $file)) {
  1417. // Okay, now look inside and see if there is a .info file.
  1418. if (file_exists("$start_dir/$file/$file.info")) {
  1419. $module = $file;
  1420. $info_contents = file_get_contents("$start_dir/$file/$file.info");
  1421. //fpm($info_contents);
  1422. // From the info_contents variable, split up and place into an array.
  1423. $info_details_array = array();
  1424. $lines = explode("\n", $info_contents);
  1425. foreach ($lines as $line) {
  1426. if (trim($line) == "") continue;
  1427. $temp = explode("=", trim($line));
  1428. $info_details_array[trim($temp[0])] = trim(substr($line, strlen($temp[0]) + 1));
  1429. }
  1430. $path = "$start_dir/$file";
  1431. $info_details_array["path"] = $path;
  1432. $info_details_array["module"] = $module;
  1433. //fpm($info_details_array);
  1434. // Expected keys:
  1435. // name, description, version, core, requires (csv), requred (true or false)
  1436. $checked = "";
  1437. $form["mark" . $m++] = array(
  1438. "value" => "<tr class='fp-system-modules-row fp-system-modules-row-$pol'>
  1439. <td width='35%'>",
  1440. );
  1441. // the Checkbox.
  1442. // Should it be checked? We can check the modules table to see if it's enabled/installed or not.
  1443. $installation_status = "";
  1444. $default_value = array();
  1445. $res = db_query("SELECT * FROM modules WHERE path = '?' ", $path);
  1446. $cur = db_fetch_array($res);
  1447. $info_details_array["enabled"] = $cur["enabled"];
  1448. if ($cur["enabled"] == "1") {
  1449. // Yes, it is checked!
  1450. $default_value = array($module => $module);
  1451. }
  1452. else if ($cur["enabled"] == "") {
  1453. $installation_status = t("not installed");
  1454. }
  1455. else if ($cur["enabled"] == "0") {
  1456. $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)),
  1457. ' window.location="' . fp_url("system/uninstall-module", "module=$module&path=" . urlencode($path) . "") . '"; ', t("uninstall?"));
  1458. }
  1459. // Does this module need to run db updates?
  1460. if ($cur["enabled"] == "1" && $cur["schema"] != $info_details_array["schema"] && $info_details_array["schema"] != "") {
  1461. $installation_status = "<b>" . l(t("Run db updates"), "admin/db-updates") . "</b>";
  1462. // Let's also make sure to enable a message at the top of the screen, letting the user
  1463. // know that there are needed updates.
  1464. fp_add_message("<b>" . t("Note:") . "</b> " . t("There are modules which have been updated. Please back up your database,
  1465. then run the DB Updates function below as soon as possible."), "error", TRUE);
  1466. }
  1467. $attributes = array();
  1468. if ($info_details_array["required"]) {
  1469. // This is a required module; it cannot be unchecked.
  1470. $attributes["disabled"] = "disabled";
  1471. }
  1472. $bool_overriding = FALSE;
  1473. // Did this module already exist in $form? In other words,
  1474. // is the module overriding a core module? If so, we need to know
  1475. // so we can display something special.
  1476. if (isset($form["cb__$module"])) {
  1477. $bool_overriding = TRUE;
  1478. }
  1479. $requires = "";
  1480. // If this module requires a higher core version of FlightPath than what we
  1481. // are running, disable and explain to the user.
  1482. if (FLIGHTPATH_VERSION != '%FP_VERSION%' && $info_details_array["requires core version"]) {
  1483. // Test to see if the current version is >= to the required core version.
  1484. if (version_compare(FLIGHTPATH_VERSION, $info_details_array["requires core version"], "<")) {
  1485. // No, it's LESS than the required version! We shouldn't be able to use this module!
  1486. $attributes["disabled"] = "disabled";
  1487. $requires .= "<div style='color: red;'>" . t("This module requires
  1488. that you run FlightPath version %fpv or higher.
  1489. You are instead running version %fpov. Please update
  1490. your core copy of FlightPath before attempting to install this
  1491. module.", array('%fpv' => $info_details_array["requires core version"],
  1492. '%fpov' => FLIGHTPATH_VERSION)) . "</div>";
  1493. }
  1494. }
  1495. $form["cb__$module"] = array(
  1496. "type" => "checkboxes",
  1497. "options" => array($module => $info_details_array["name"]),
  1498. "value" => $default_value,
  1499. "suffix" => "<div class='fp-system-modules-machine-name'>$file</div>
  1500. <div class='fp-system-modules-installation-status'>$installation_status</div>
  1501. ",
  1502. "attributes" => $attributes,
  1503. );
  1504. // hidden variable containing the details about this module, for later use on submit.
  1505. $form["module_details__$module"] = array(
  1506. "type" => "hidden",
  1507. "value" => urlencode(serialize($info_details_array)),
  1508. );
  1509. // Version & descr.
  1510. if ($info_details_array["requires"] != "") {
  1511. $requires .= "<div class='fp-system-modules-requires hypo'>
  1512. <b>" . t("Requires:") . "</b> {$info_details_array["requires"]}
  1513. </div>";
  1514. }
  1515. // if we are overriding a module, then display something special.
  1516. if ($bool_overriding) {
  1517. $form["mark" . $m++] = array(
  1518. "value" => "<em>" . t("Overriding core module:") . "<br>{$info_details_array["name"]}</em>
  1519. <div class='fp-system-modules-machine-name'>$file</div>
  1520. <div class='fp-system-modules-installation-status'>
  1521. " . t("Use checkbox in Core section above to manage module") . "
  1522. </div>",
  1523. );
  1524. }
  1525. $form["mark" . $m++] = array(
  1526. "value" => " </td>
  1527. <td width='5%' >{$info_details_array["version"]}</td>
  1528. <td >{$info_details_array["description"]}$requires</td>
  1529. </tr>
  1530. ",
  1531. );
  1532. $pol = ($pol == "even") ? "odd" : "even";
  1533. } // if file_exists (xml file)
  1534. } // if is_dir
  1535. } // while file=readdir
  1536. $form["mark" . $m++] = array(
  1537. "value" => "</table>",
  1538. );
  1539. } // if opendir($startdir)
  1540. }// foreach moduledirs
  1541. $form["submit"] = array(
  1542. "type" => "submit",
  1543. "value" => t("Submit"),
  1544. "prefix" => "<hr>",
  1545. );
  1546. return $form;
  1547. }
  1548. /**
  1549. * Submit handler for the modules form.
  1550. */
  1551. function system_modules_form_submit($form, $form_state) {
  1552. // Go through all of the checkboxes which we have "module_details" for. If there is NOT a corresponding
  1553. // checkbox, it means it wasn't checked, and should be disabled in the database. Otherwise, it means it WAS
  1554. // checked, and should be enabled/installed.
  1555. //fpm($form_state["values"]);
  1556. $did_something = FALSE;
  1557. foreach ($form_state["values"] as $key => $value) {
  1558. if (strstr($key, "module_details__")) {
  1559. if ($module_details = unserialize(urldecode($value))) {
  1560. $module = $module_details["module"];
  1561. // Disabling a module.
  1562. if ($module_details["enabled"] == "1" && !isset($form_state["values"]["cb__$module"])) {
  1563. // So it WAS enabled, but now the checkbox wasn't checked. So disable it!
  1564. system_disable_module($module_details);
  1565. $did_something = TRUE;
  1566. }
  1567. // Enabling a module
  1568. if ($module_details["enabled"] != "1" && isset($form_state["values"]["cb__$module"])) {
  1569. system_enable_module($module_details);
  1570. $did_something = TRUE;
  1571. }
  1572. }
  1573. }
  1574. }
  1575. if ($did_something) {
  1576. // We should clear the cache if we did something.
  1577. // Refetch all of the modules from the modules table.
  1578. fp_rebuild_modules_list();
  1579. // Rebuild the menu router now.
  1580. menu_rebuild_cache();
  1581. }
  1582. }
  1583. /**
  1584. * Called from the menu (ie, a URL) this function will uninstall a module.
  1585. *
  1586. */
  1587. function system_handle_uninstall_module() {
  1588. $module = $_REQUEST["module"];
  1589. // First, let's get information about this module from the db.
  1590. $res = db_query("SELECT * FROM modules WHERE name = '?' ", $module);
  1591. $cur = db_fetch_array($res);
  1592. // Make sure it is not currently enabled.
  1593. if ($cur["enabled"] == "1") {
  1594. fp_add_message(t("Module %module not yet disabled. Disable first, then try to uninstall.", array("%module" => $module)));
  1595. return;
  1596. }
  1597. // Let's see if we can call hook_uninstall for this module.
  1598. if (include_module($module, TRUE, $cur["path"])) {
  1599. if (include_module_install($module, $cur["path"])) {
  1600. if (function_exists($module . "_uninstall")) {
  1601. call_user_func($module . "_uninstall");
  1602. }
  1603. }
  1604. }
  1605. // Remove from the database.
  1606. $res = db_query("DELETE FROM modules WHERE name = '?' ", $module);
  1607. fp_add_message(t("Uninstalled %module.", array("%module" => $module)));
  1608. fp_goto("admin/config/modules");
  1609. }
  1610. /**
  1611. * Handles the enabling (and possible installation) of module.
  1612. */
  1613. function system_enable_module($module_details) {
  1614. $module = $module_details["module"];
  1615. $path = $module_details["path"];
  1616. $bool_call_hook_install = FALSE;
  1617. // Do we need to attempt to call the hook_install function?
  1618. if ($module_details["enabled"] == "") {
  1619. // Wasn't in the database, so we need to install it.
  1620. // Add to our table.
  1621. // (delete anything all ready there first)
  1622. $res = db_query("DELETE FROM modules WHERE name = '?' ", $module);
  1623. // Now, add back into the table.
  1624. $res = db_query("INSERT INTO modules (name, path, version, requires, enabled, type, `schema`, info)
  1625. VALUES ('?', '?', '?', '?', '?', '?', '?', '?')
  1626. ", $module, $path, $module_details["version"], $module_details["required"], "1", "module",
  1627. $module_details["schema"], serialize($module_details));
  1628. $bool_call_hook_install = TRUE;
  1629. fp_add_message(t("The module %module has been installed.", array("%module" => $module)));
  1630. }
  1631. // If the module has a .install file, begin by including it.
  1632. if (include_module_install($module, $path)) {
  1633. // Include the original module file first.
  1634. include_module($module, TRUE, $path);
  1635. if ($bool_call_hook_install) {
  1636. // call hook_install if it exists.
  1637. if (function_exists($module . '_install')) {
  1638. call_user_func($module . '_install');
  1639. }
  1640. }
  1641. // Now, we can call hook_enable, if it exists.
  1642. if (function_exists($module . '_enable')) {
  1643. call_user_func($module . '_enable');
  1644. }
  1645. }
  1646. // Update our table.
  1647. $res = db_query("UPDATE modules SET enabled = '1' WHERE name = '?' ", $module);
  1648. fp_add_message(t("The module %module has been enabled.", array("%module" => $module)));
  1649. }
  1650. /**
  1651. * Handles the disabling of the module in question.
  1652. */
  1653. function system_disable_module($module_details) {
  1654. $module = $module_details["module"];
  1655. $path = $module_details["path"];
  1656. // This module cannot be disabled!
  1657. if ($module_details["required"] == TRUE) {
  1658. return;
  1659. }
  1660. // If the module has a "hook_disable" in it's path/module.install file, include and call it.
  1661. if (include_module_install($module, $path) && function_exists($module . '_disable')) {
  1662. call_user_func($module . '_disable');
  1663. }
  1664. // Disable it in the modules table.
  1665. $res = db_query("UPDATE modules
  1666. SET enabled = '0'
  1667. WHERE name = '?' ", $module);
  1668. fp_add_message(t("The module %module has been disabled.", array("%module" => $module)));
  1669. }
  1670. /**
  1671. * Construct an HTML element and return it.
  1672. *
  1673. */
  1674. function system_build_element($name, $type = "", $label = "", $description = "", $default_value = "", $csv_to_array = FALSE) {
  1675. $rtn = "";
  1676. if (!$default_value) {
  1677. $default_value = $GLOBALS["fp_system_settings"][$name];
  1678. }
  1679. if (is_array($default_value)) {
  1680. $default_value = @join(", ", $default_value);
  1681. }
  1682. if (!$type) {
  1683. $type = "textfield";
  1684. }
  1685. if (!$label) {
  1686. $label = $name;
  1687. }
  1688. if ($type == "textfield") {
  1689. $rtn .= "<div class='fp-system-settings-element fp-system-settings-textfield'>
  1690. <label>$label:</label>
  1691. <div class='fp-system-settings-input'>
  1692. <input type='textfield' name='$name' value='$default_value'>
  1693. </div>
  1694. ";
  1695. if ($description) {
  1696. $rtn .= "<div class='fp-system-settings-element-description'>$description</div>";
  1697. }
  1698. $rtn .= "</div>";
  1699. }
  1700. if ($type == "textarea") {
  1701. $rtn .= "<div class='fp-system-settings-element fp-system-settings-textarea'>
  1702. <label>$label:</label>
  1703. <div class='fp-system-settings-input'>
  1704. <textarea name='$name'>$default_value</textarea>
  1705. </div>
  1706. ";
  1707. if ($description) {
  1708. $rtn .= "<div class='fp-system-settings-element-description'>$description</div>";
  1709. }
  1710. $rtn .= "</div>";
  1711. }
  1712. if ($type == "boolean") {
  1713. $sel_f = $sel_t = "";
  1714. if ($default_value) {
  1715. $sel_t = "selected";
  1716. }
  1717. $rtn .= "<div class='fp-system-settings-element fp-system-settings-boolean'>
  1718. <label>$label:</label>
  1719. <div class='fp-system-settings-input'>
  1720. <select name='$name'>
  1721. <option value='' $sel_f>FALSE</option>
  1722. <option value='1' $sel_t>TRUE</option>
  1723. </select>
  1724. </div>
  1725. ";
  1726. if ($description) {
  1727. $rtn .= "<div class='fp-system-settings-element-description'>$description</div>";
  1728. }
  1729. $rtn .= "</div>";
  1730. }
  1731. // We need to convert this CSV back into an array when we save it!
  1732. if ($csv_to_array) {
  1733. if (!isset($_SESSION["fp_system"]["csv_to_array"])) {
  1734. $_SESSION["fp_system"]["csv_to_array"] = array();
  1735. }
  1736. // Add to our list.
  1737. $_SESSION["fp_system"]["csv_to_array"][] = $name;
  1738. }
  1739. return $rtn;
  1740. }