prereqs.module

This is the module file for the prereqs module.

File

modules/prereqs/prereqs.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * This is the module file for the prereqs module.
  5. */
  6. /**
  7. * Implements hook_menu
  8. */
  9. function prereqs_menu() {
  10. $items = array();
  11. $items["admin/config/prereqs"] = array(
  12. "title" => "Prereqs settings",
  13. "description" => "Configure settings related to the prereqs module.",
  14. "page_callback" => "fp_render_form",
  15. "page_arguments" => array("prereqs_settings_form", "system_settings"),
  16. "access_arguments" => array("administer_prereqs"),
  17. "page_settings" => array(
  18. "menu_icon" => fp_get_module_path('system') . "/icons/book_previous.png",
  19. "menu_links" => array(
  20. 0 => array(
  21. "text" => "Admin Console",
  22. "path" => "admin-tools/admin",
  23. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  24. ),
  25. ),
  26. ),
  27. "type" => MENU_TYPE_NORMAL_ITEM,
  28. "tab_parent" => "admin-tools/admin",
  29. );
  30. return $items;
  31. }
  32. function prereqs_perm() {
  33. return array(
  34. "administer_prereqs" => array(
  35. "title" => t("Administer prereq settings"),
  36. ),
  37. 'override_course_locks' => array(
  38. 'title' => t("Override course locks"),
  39. 'description' => t("Users with this permission are allowed to 'override' courses with locks for checkboxes, meaning they can
  40. still advise a course even if the prereqs (or other issues) have not passed."),
  41. ),
  42. );
  43. }
  44. function prereqs_settings_form() {
  45. $form = array();
  46. $elements = array();
  47. $elements["prereqs_show_availability_in_popup"] = array(
  48. "label" => t("Show course's anticipated availability (from Course Search module) in course description popups?"),
  49. "type" => "select",
  50. "options" => array("no" => t("No"), "yes" => "Yes"),
  51. "hide_please_select" => TRUE,
  52. "value" => variable_get("prereqs_show_availability_in_popup", "no"),
  53. "description" => t("If set to 'Yes', this will show a course's anticipated availability (what terms it will be available)
  54. in the course description popup which loads when a course is clicked."),
  55. );
  56. $elements["prereqs_lock_course_advise_based_on_avail"] = array(
  57. "label" => t("Lock advising for a course based on availability?"),
  58. "type" => "select",
  59. "options" => array("no" => t("No"), "yes" => "Yes"),
  60. "hide_please_select" => TRUE,
  61. "value" => variable_get("prereqs_lock_course_advise_based_on_avail", "no"),
  62. "description" => t("If set to 'Yes', this will 'lock' a course's advising checkbox if it is not
  63. offered in the advising term selected. This requires that most of your courses
  64. have accurate term schedules entered in the Course Search module. If unsure what to select, choose 'no'."),
  65. );
  66. $elements["prereqs_use_term_desc_abbr_in_popup"] = array(
  67. "label" => t("Use term description abbreviations in popup?"),
  68. "type" => "select",
  69. "options" => array("no" => t("No"), "yes" => "Yes"),
  70. "hide_please_select" => TRUE,
  71. "value" => variable_get("prereqs_use_term_desc_abbr_in_popup", "yes"),
  72. "description" => t("If set to 'Yes', then the availability text in a course's popup description will show
  73. the \"abbreviated\" term descriptions. Ex: Sum1 instead of Summer One. To show full
  74. term descriptions, chose 'no'. If unsure what to select, choose 'no'."),
  75. );
  76. $elements["prereqs_not_anticipated_text"] = array(
  77. "label" => t("The message to show in the popup description, when 'Not Anticipated' has been selected for a course, or if no current terms are selected:"),
  78. "type" => "textfield",
  79. "maxlength" => "255",
  80. "size" => "80",
  81. "value" => variable_get("prereqs_not_anticipated_text", "This course isn't currently anticipated to be offered. Please ask your advisor to learn more."),
  82. "description" => t("This message will show in the popup description for a course, when it has been flaged as 'Not Anticipated' in its schedule, or if no current terms
  83. have been selected.
  84. <br>Ex: <em>This course isn't currently anticipated to be offered. Please ask your advisor to learn more.</em>"),
  85. );
  86. $elements["prereqs_lock_msg_avail"] = array(
  87. "label" => t("The message to show the user when the course is locked due to availability (option above must be set to 'yes'):"),
  88. "type" => "textfield",
  89. "maxlength" => "255",
  90. "size" => "80",
  91. "value" => variable_get("prereqs_lock_msg_avail", "This course is not listed as being available for the selected advising term (@term)."),
  92. "description" => t("This message will show to the advisor when they try to bypass the lock for availability. You may use the replacement pattern <b>@term</b>
  93. to mean the current term selected.
  94. <br>Ex: <em>This course is not listed as being available for the selected advising term (@term).</em>"),
  95. );
  96. $form["avail"] = array(
  97. "type" => "cfieldset",
  98. "label" => t("Prereqs based on availability"),
  99. "elements" => array($elements),
  100. );
  101. //////////////////////////////////////////////////////////
  102. //////////////////////////////////////////////////////////
  103. //////////////////////////////////////////////////////////
  104. //////////////////////////////////////////////////////////
  105. //////////////////////////////////////////////////////////
  106. $elements = array();
  107. $elements["prereqs_show_courses_in_popup"] = array(
  108. "label" => t("Show course's prereq courses in course description popups and on Course Search module?"),
  109. "type" => "select",
  110. "options" => array("no" => t("No"), "yes" => "Yes"),
  111. "hide_please_select" => TRUE,
  112. "value" => variable_get("prereqs_show_courses_in_popup", "no"),
  113. "description" => t("If set to 'Yes', this will show a course's prereq course requirements (from the Course Edit form)
  114. in the course description popup which loads when a course is clicked, and in course descriptions in the Course Search module."),
  115. );
  116. $elements["prereqs_lock_course_advise_based_on_courses"] = array(
  117. "label" => t("Lock advising for a course based on prereq courses?"),
  118. "type" => "select",
  119. "options" => array("no" => t("No"), "yes" => "Yes"),
  120. "hide_please_select" => TRUE,
  121. "value" => variable_get("prereqs_lock_course_advise_based_on_courses", "no"),
  122. "description" => t("If set to 'Yes', this will 'lock' a course's advising checkbox if its prereq courses (entered on the Course Edit form for that course)
  123. have not been fulfilled. If unsure what to select, choose 'no'."),
  124. );
  125. $elements["prereqs_lock_msg_courses"] = array(
  126. "label" => t("The message to show the user when the course is locked due to prereq courses (option above must be set to 'yes'):"),
  127. "type" => "textfield",
  128. "maxlength" => "255",
  129. "size" => "80",
  130. "value" => variable_get("prereqs_lock_msg_courses", "This course is not listed as being available because the student has not fulfilled the following prerequisite course(s) and possible min grades:\\n @need_courses."),
  131. "description" => t("This message will show to the advisor when they try to bypass the lock for prereq courses. You may use the replacement pattern <b>@needed_courses</b>
  132. to mean the current term selected. You may also use \\n to mean 'insert new line.'
  133. <br>Ex: <em>This course is not listed as being available because the student has not fulfilled the following prerequisite course(s) and possible min grades:\\n @need_courses.</em>"),
  134. );
  135. $form["courses"] = array(
  136. "type" => "cfieldset",
  137. "label" => t("Prereqs based on prereq courses"),
  138. "elements" => array($elements),
  139. );
  140. ///////////////////////////
  141. ///////////////////////////
  142. ///////////////////////////
  143. ///////////////////////////
  144. $form["prereqs_confirm_msg"] = array(
  145. "label" => t("Confirm message:"),
  146. "type" => "textfield",
  147. "maxlength" => 255,
  148. "size" => 80,
  149. "value" => variable_get("prereqs_confirm_msg", "Are you sure you wish to advise the student to enroll in this course anyway?"),
  150. "description" => t("This message will be appended AFTER the lock message to the advisor, asking them if they wish to proceed with advising anyway.
  151. Ex: <em>Are you sure you wish to advise the student to enroll in this course anyway?</em>"),
  152. );
  153. return $form;
  154. }
  155. /**
  156. * Implements hook_form_alter
  157. */
  158. function prereqs_form_alter(&$form, $form_id) {
  159. // We want to edit the edit_course form, to inject some fields for adding prereqs to course requirements.
  160. if ($form_id == "admin_edit_course_form") {
  161. // Add in our validate and submit handlers...
  162. $form["#validate_handlers"][] = "prereqs_edit_course_form_validate";
  163. $form["#submit_handlers"][] = "prereqs_edit_course_form_submit";
  164. $existing_prereqs = (String) db_result(db_query("SELECT prereq_data FROM prereqs_prereqs
  165. WHERE course_id = ?", $form["course_id"]["value"]));
  166. // Add in the fields...
  167. $form["prereqs_prereqs"] = array(
  168. "label" => t("Prerequisites:"),
  169. "type" => "textarea",
  170. "value" => $existing_prereqs,
  171. "description" => t("Enter prereqs which must be completed before a student may be advised to take this course.
  172. Please note that this
  173. data is for <b>ALL CATALOG YEARS</b> of the course. Also, this is <b>not placed in a draft</b> state. Any changes
  174. to prereqs will be instantly live.
  175. <br>
  176. Enter data in this format: SUBJECT_ID COURSE_NUM (MIN_GRADE) -- you may leave off the min grade if any passing grade is acceptable.
  177. <br><br>Each row means 'AND this course'. To have and option of more than one course required, enter on a single line, separated by the word 'or'. <b>Remember to leave
  178. spaces between courses, grades, or's, etc.</b><br>For more details, <a href='http://getflightpath.com/node/1157' target='_blank'>please refer to the documentation page</a>.
  179. <br>
  180. Ex:
  181. <br><em>
  182. &nbsp; &nbsp; ACCT 104 (B)
  183. <br>&nbsp; &nbsp; ACCT 101 (C) or ACCT 102 (C)
  184. <br>&nbsp; &nbsp; ACCT 101 or ACCT 103
  185. </em>
  186. <br>The above example means 'The student must take ACCT 104 (earning a B or higher). They must also take EITHER ACCT 101 or ACCT 102. Finally, they
  187. must also take EITHER ACCT 101 or ACCT 103.<br>
  188. Take note in this example that if the student takes only ACCT 104 and ACCT 101, then they will have satisfied all of the prereq requirements, since ACCT 101 is listed
  189. in both rows 2 and 3.
  190. "),
  191. "weight" => 85,
  192. );
  193. } // if form id == admin_edit_course_form
  194. } // hook_form_alter
  195. /**
  196. * validate for the edit course form, from admin.courses.inc.
  197. *
  198. * We want to check that the prereqs entered are valid.
  199. */
  200. function prereqs_edit_course_form_validate($form, &$form_state) {
  201. $prereqs = trim($form_state["values"]["prereqs_prereqs"]);
  202. if ($prereqs == "") return; //nothing there, so ignore.
  203. $db = get_global_database_handler();
  204. $school_id = $db->get_school_id_for_course_id($form_state["values"]["course_id"], TRUE);
  205. // TODO: If schools_school exists, use THAT id instead?
  206. // Turn into a friendly array.
  207. $prereq_array = prereqs_get_prereq_array_from_string($prereqs, $school_id);
  208. // If any of the courses in our array don't have valid course id's, it means
  209. // the course wasn't found.
  210. foreach ($prereq_array as $reqs) {
  211. foreach ($reqs as $details) {
  212. if (!$details["course_id"] || $details["course_id"] == 0) {
  213. form_error("prereqs_prereqs", t("Prereqs: Could not find course %course in any catalog year. Check spelling and try again.", array("%course" => $details["subject_id"] . " " . $details["course_num"])));
  214. continue;
  215. }
  216. // also make sure they didn't enter the same course as its own prereq...
  217. if (intval($details["course_id"]) == intval($form_state["values"]["course_id"])) {
  218. form_error("prereqs_prereqs", t("Prereqs: You entered %course for a prereq but that is the course you are currently editing. A course cannot be its own prereq.
  219. Please check your spelling and try again.", array("%course" => $details["subject_id"] . " " . $details["course_num"])));
  220. continue;
  221. }
  222. }
  223. }
  224. } // validate handler
  225. /**
  226. * Our submit handler.
  227. *
  228. * In this, we just want to write our values to the database.
  229. */
  230. function prereqs_edit_course_form_submit($form, &$form_state) {
  231. $prereqs = trim(fp_reduce_whitespace($form_state["values"]["prereqs_prereqs"]));
  232. $prereqs = str_replace("\n ", "\n", $prereqs);
  233. // Make sure "or's" are lowercase.
  234. $prereqs = str_replace(" OR ", " or ", $prereqs);
  235. $prereqs = str_replace(" oR ", " or ", $prereqs);
  236. $prereqs = str_replace(" Or ", " or ", $prereqs);
  237. $prereqs = str_replace(" 0R ", " or ", $prereqs); // zero-r (to catch typos)
  238. $prereqs = str_replace(" 0r ", " or ", $prereqs); // zero-R
  239. // First, delete what is there for this course, if anything is there at all.
  240. $this_course_id = $form_state["values"]["course_id"];
  241. db_query("DELETE FROM prereqs_prereqs WHERE course_id = ?", $this_course_id);
  242. // Add to our table.
  243. db_query("INSERT INTO prereqs_prereqs (course_id, prereq_data)
  244. VALUES (?, ?) ", $this_course_id, $prereqs);
  245. } // submit handler
  246. /**
  247. * Just gets whatever is in the database for this course.
  248. */
  249. function prereqs_get_prereq_string_for_course($course_id) {
  250. $prereq_data = db_result(db_query("SELECT prereq_data from prereqs_prereqs WHERE course_id = ?", $course_id));
  251. $prereq_data = @(String) trim($prereq_data);
  252. // Get rid of windows trouble characters.
  253. $prereq_data = str_replace("\r", "", $prereq_data);
  254. // Make sure "or's" are lowercase.
  255. $prereq_data = str_replace(" OR ", " or ", $prereq_data);
  256. $prereq_data = str_replace(" oR ", " or ", $prereq_data);
  257. $prereq_data = str_replace(" Or ", " or ", $prereq_data);
  258. $prereq_data = str_replace(" 0R ", " or ", $prereq_data); // zero-r (to catch typos)
  259. $prereq_data = str_replace(" 0r ", " or ", $prereq_data); // zero-R
  260. return $prereq_data;
  261. }
  262. /**
  263. * Return back a friendly array of prereq courses that are required for THIS course_id.
  264. */
  265. function prereqs_get_prereq_array_for_course($course_id) {
  266. $rtn = array();
  267. $prereq_data = prereqs_get_prereq_string_for_course($course_id);
  268. $db = get_global_database_handler();
  269. $school_id = $db->get_school_id_for_course_id($course_id, TRUE);
  270. $rtn = prereqs_get_prereq_array_from_string($prereq_data, $school_id);
  271. return $rtn;
  272. }
  273. /**
  274. * Assumes prereqs are written in this format:
  275. * ACCT 101 (C) & ACCT 103
  276. * ACCT 102 (B)
  277. *
  278. * Returns back a friendly array that makes everything easier to read.
  279. *
  280. */
  281. function prereqs_get_prereq_array_from_string($prereqs_str, $school_id = 0) {
  282. $rtn = array();
  283. $db = get_global_database_handler();
  284. $c = 0;
  285. $lines = explode("\n", $prereqs_str);
  286. foreach ($lines as $line) {
  287. $line = fp_reduce_whitespace($line);
  288. $line = trim($line);
  289. if ($line == "") continue; // skip blanks.
  290. $courses = explode(" or ", $line);
  291. foreach ($courses as $course_line) {
  292. $course_line = trim(fp_reduce_whitespace($course_line));
  293. $temp = explode(" ", $course_line);
  294. $subject_id = trim($temp[0]);
  295. $course_num = trim($temp[1]);
  296. $min_grade = @trim(str_replace("(", "", $temp[2]));
  297. $min_grade = @trim(str_replace(")", "", $min_grade));
  298. // Was there a min grade stuck with the course_num?
  299. if (strstr($course_num, "(")) {
  300. $temp2 = explode("(", $course_num);
  301. $course_num = trim($temp2[0]);
  302. $min_grade = trim(str_replace(")", "", $temp2[1]));
  303. }
  304. // Okay, now that we have the subject_id and course_num, let's find the course_id (if it exists).
  305. $course_id = $db->get_course_id($subject_id, $course_num, '', FALSE, $school_id, TRUE);
  306. // Okay, add to our return array.
  307. $rtn[$c][] = array(
  308. "subject_id" => $subject_id,
  309. "course_num" => $course_num,
  310. "course_id" => $course_id,
  311. "min_grade" => $min_grade,
  312. );
  313. } //foreach courses
  314. $c++;
  315. } // foreach line
  316. return $rtn;
  317. }
  318. /**
  319. * This is meant to be a general function to find all relavent prereq warnings for the supplied course.
  320. *
  321. * It will also call a hook to allow other modules to add to it.
  322. *
  323. * Returns an array of warning messages, or an empty array if the course is good to go.
  324. */
  325. function prereqs_get_prereq_warnings_for_course(Course $course, Student $student = null) {
  326. $rtn = array();
  327. $school_id = $course->school_id;
  328. $bool_use_term_abbreviation = (variable_get("prereqs_use_term_desc_abbr_in_popup", "yes") == "yes");
  329. ///////////////////////////////////////////////////
  330. ///////////////////////////////////////////////////
  331. // Advising Term Based Locks
  332. // Should we lock this course if its unavailable for this advising term?
  333. if (variable_get("prereqs_lock_course_advise_based_on_avail", "no") == "yes") {
  334. $warning_msg = variable_get("prereqs_lock_msg_avail", "This course is not listed as being available for the selected advising term (@term). Are you sure you wish to advise the student to enroll in it?");
  335. // Find out what the rotation schedule is for this course.
  336. $advising_term_id = @$GLOBALS["fp_advising"]["advising_term_id"];
  337. // Get the advising year from the term.
  338. $year = substr($advising_term_id, 0, 4);
  339. $rotation_schedule = course_search_get_course_rotation_schedule($course->course_id, $year, 5);
  340. // Is the "not anticipated" flag set?
  341. $bool_not_anticipated = course_search_get_course_rotation_schedule_not_anticipated($course->course_id);
  342. if ($bool_not_anticipated) {
  343. // Clear out the rotation_schedule, since it isn't anticipated.
  344. $rotation_schedule = array();
  345. }
  346. if (!in_array($advising_term_id, $rotation_schedule)) {
  347. // The course is NOT listed for this advising term! Therefor, it SHOULD have a warning!
  348. $rtn["avail"]["plain_text"] = t($warning_msg, array("@term" => htmlentities(get_term_description($advising_term_id, $bool_use_term_abbreviation, $school_id), ENT_QUOTES)));
  349. } // !in_array advising_term_id in rotation_schedule
  350. } // advising availbility / term based locks
  351. /////////////////////////////////////////
  352. /////////////////////////////////////////
  353. // Previous course requirement prereq locks
  354. if (variable_get("prereqs_lock_course_advise_based_on_courses", "no") == "yes" && $student != null && is_object($student)) {
  355. // Let's get the prereqs array for this course.
  356. $prereqs = prereqs_get_prereq_array_for_course($course->course_id);
  357. $retake_grades = csv_to_array(variable_get_for_school("retake_grades", "W,F", $course->school_id));
  358. if (count($prereqs) > 0) {
  359. $bool_fulfilled_prereqs = TRUE;
  360. $completed_courses = array();
  361. $completed_branches = array();
  362. foreach ($prereqs as $branch_num => $reqs) {
  363. $bool_fulfilled_branch = FALSE;
  364. // Loop through and see if the student HAS fulfilled the specified prereq.
  365. foreach ($reqs as $details) {
  366. $bool_found_course = FALSE;
  367. $test_course = new Course();
  368. $test_course->course_id = $details["course_id"];
  369. $found = $student->list_courses_taken->find_best_match($test_course, $details["min_grade"], FALSE, 0, FALSE);
  370. if ($found && is_object($found) && !in_array($found->grade, $retake_grades)) {
  371. // YEP! They have this requirement, so that means the entire branch is good.
  372. $bool_found_course = TRUE;
  373. } // was found.
  374. else {
  375. // NOT FOUND!
  376. // Perhaps this course ($test_course) is being fulfilled by a substitution?
  377. $found_sub = $student->list_substitutions->find_requirement($test_course);
  378. if ($found_sub) {
  379. $found = $found_sub->course_requirement;
  380. // Yes, there is at least ONE substitution for this course. We will count it as completed the prereq, even if it does
  381. // not complete all of the hours.
  382. // TODO: Make that also check completed hours to make sure the sub is "complete" and not split up?
  383. $bool_found_course = TRUE;
  384. }
  385. else {
  386. // Nope, this was not a substitution. But perhaps the student has an automatic transfer eqv for this course?
  387. }
  388. } // if/else
  389. if ($bool_found_course) {
  390. $bool_fulfilled_branch = TRUE;
  391. $completed_branches[$branch_num] = $branch_num;
  392. $completed_courses[$found->course_id . "~" . $details["min_grade"]] = $found->course_id . "~" . $details["min_grade"];
  393. }
  394. } // foreach reqs
  395. // If we didn't fulfill a branch, then we have failed. We should quit.
  396. if ($bool_fulfilled_branch == FALSE) {
  397. $bool_fulfilled_prereqs = FALSE;
  398. }
  399. }// foreach prereqs
  400. if ($bool_fulfilled_prereqs == FALSE) {
  401. // We did NOT fulfill the prereqs for this course! Let's add a message!
  402. // Prepare our prereq requirements for display...
  403. $prereq_data = prereqs_get_prereq_string_for_course($course->course_id);
  404. // Fix trouble characters, and reformat so it looks pretty.
  405. $prereq_data = " - " . str_replace("\n", "\\n - ", $prereq_data);
  406. $warning_msg = variable_get("prereqs_lock_msg_courses", "This course is not listed as being available because the student has not fulfilled the following prerequisite course(s) and possible min grades:\\n@need_courses.\\nAre you sure you wish to advise the student to enroll in this course anyway?");
  407. $rtn["prereq"]["plain_text"] = t($warning_msg, array("@need_courses" => $prereq_data));
  408. // Let's also get the full-html version, where we indicate what we've completed or not.
  409. $html = "";
  410. foreach ($prereqs as $branch_num => $reqs) {
  411. $branch_class = "prereqs-incomplete-branch";
  412. if (in_array($branch_num, $completed_branches)) $branch_class = "prereqs-completed-branch";
  413. $html .= "<div class='prereqs-req-branch $branch_class'>";
  414. $c = 0;
  415. foreach ($reqs as $details) {
  416. if ($c > 0) {
  417. $html .= " <span class='prereq-req-or-token'>or</span> ";
  418. }
  419. $course_id = $details["course_id"];
  420. $course_class = "prereqs-incomplete-course";
  421. if (in_array($course_id . "~" . $details["min_grade"], $completed_courses)) $course_class = "prereqs-completed-course";
  422. $html .= "<span class='prereqs-req-course $course_class'>";
  423. $html .= $details["subject_id"] . " " . $details["course_num"];
  424. if ($details["min_grade"] != "") {
  425. $html .= " (" . $details["min_grade"] . ") ";
  426. }
  427. $html .= "</span>";
  428. $c++;
  429. }
  430. $html .= "</div>"; // prereqs-req-branch
  431. }
  432. $rtn["prereq"]["full_html"] = t($warning_msg, array("@need_courses" => $html));
  433. } // bool_fulfilled_prereqs = false
  434. } // if count > 0
  435. } // previous course requirement prereq locks
  436. //////////////////////////////////////
  437. // Okay, now we invoke a hook, to see if any other modules
  438. // would like to add or alter our prereq warnings.
  439. invoke_hook("prereqs_get_prereq_warnings_for_course", array(&$rtn, $course, $student));
  440. return $rtn;
  441. } //get prereq warnings for course
  442. /**
  443. * Implements hook_theme_advise_course_row. Lets us re-write how our course rows are drawn, if desired.
  444. */
  445. function prereqs_theme_advise_course_row(&$theme) {
  446. $display_status = $theme["course"]["display_status"];
  447. // We only need to bother to check
  448. if ($display_status == "eligible") {
  449. fp_add_js(fp_get_module_path("prereqs") . "/js/prereqs.js");
  450. fp_add_css(fp_get_module_path("prereqs") . "/css/prereqs.css");
  451. $course = $theme["course"]["course"];
  452. $student = $theme["student"];
  453. $warnings = prereqs_get_prereq_warnings_for_course($course, $student);
  454. if (count($warnings) == 0) return; // no prereqs to worry about!
  455. // Otherwise, yes, there are prereq warnings!
  456. // Combine the warning messages.....
  457. $warning_msg = "";
  458. foreach ($warnings as $details) {
  459. $warning_msg .= $details["plain_text"] . "\\n \\n";;
  460. }
  461. $confirm = variable_get("prereqs_confirm_msg", "Are you sure you wish to advise the student to enroll in this course anyway?");
  462. $confirm_warning_msg = $warning_msg . "\\n\\n" . $confirm;
  463. $function = "toggleSelection";
  464. $group_select_function = "";
  465. // Only allow user with correct permissions actually perform advising (override lock) If they do NOT have the permission,
  466. // we display a message saying they can't advise that course.
  467. if (!user_has_permission('override_course_locks')) {
  468. $confirm_warning_msg = $warning_msg . "<br><br>" . t("You do have have sufficient permissions to override this lock.");
  469. $function = "prereqs_no_toggleSelection";
  470. $group_select_function = "prereqs_no_group_toggleSelection";
  471. }
  472. $theme["op"]["display_status"] = "locked";
  473. $theme["course"]["display_status"] = "locked";
  474. $theme["op"]["extra_css"] = str_replace("eligible", "locked", $theme["op"]["extra_css"]);
  475. if ($theme["op"]["onclick"]["function"] == "toggleSelection") {
  476. // All we need to do is add text to argument 2.
  477. $theme["op"]["onclick"]["function"] = $function;
  478. $theme["op"]["onclick"]["arguments"][1] = "locked";
  479. $theme["op"]["onclick"]["arguments"][2] = $confirm_warning_msg;
  480. }
  481. if (@$theme["from_group_select"] == TRUE) {
  482. // Meaning, this is from a group select course row! Let's change some things.
  483. $theme["icon"]["filename"] = "n.gif";
  484. $theme["icon"]["location"] = fp_get_module_path("prereqs") . "/css/images";
  485. $theme["icon"]["title"] = str_replace("\\n", " ", $warning_msg);
  486. if ($group_select_function) {
  487. $theme["op"]["onclick"]["function"] = $group_select_function;
  488. }
  489. $theme["op"]["onclick"]["arguments"][0] = $confirm_warning_msg;
  490. }
  491. } // if display status == "eligible"
  492. } // hook_theme_advise_course_row
  493. /**
  494. * Implememnt hook_content_alter
  495. */
  496. function prereqs_content_alter(&$render, $content_id) {
  497. // TODO: Make this a setting?
  498. // Do we simply wish to DISPLAY prereq warnings in the popup window at all?
  499. if ($content_id == "AdvisingScreen_display_popup_course_description") {
  500. fp_add_css(fp_get_module_path("prereqs") . "/css/prereqs.css");
  501. $course = @$render["#course"]["value"];
  502. if (!is_object($course)) return; // some kind of problem...
  503. $student = @$GLOBALS["screen"]->student;
  504. $warnings = prereqs_get_prereq_warnings_for_course($course, $student);
  505. if (count($warnings) > 0) {
  506. $warning_msg = "";
  507. foreach ($warnings as $details) {
  508. $msg = $details["plain_text"];
  509. $bool_using_plain_text = TRUE;
  510. if (isset($details["full_html"])) {
  511. $msg = $details["full_html"];
  512. $bool_using_plain_text = FALSE;
  513. }
  514. $msg = str_replace("\\n", "\n", $msg);
  515. $msg = str_replace(" ", "&nbsp;&nbsp;", $msg);
  516. if ($bool_using_plain_text) {
  517. $msg = nl2br($msg);
  518. }
  519. $warning_msg .= "<div class='prereq-popup-warning-msg'>" . $msg . "</div>";
  520. }
  521. $render["prereq_warnings"] = array(
  522. "label" => t("Prerequisites Warning:"),
  523. "value" => $warning_msg,
  524. "attributes" => array("class" => "popup-description-section tenpt"),
  525. "weight" => 500,
  526. );
  527. // Do we have permission to override the prereq for this course?
  528. if (!user_has_permission('override_course_locks')) {
  529. // Set a temporary variable in our GLOBALS array so we know this course cannot be advised. Used in the advise.module, to make sure
  530. // if we get a description from within a group, we do not have this course selected when we change tabs back to the list.
  531. $GLOBALS['prereqs_no_advise_course_id'][] = $course->course_id;
  532. $render['hidden_vars_and_buttons']['value'] = "<p class='no-override-permission'><label>" .t("Cannot Advise") . "</label>" . t("Sorry, but you do not have permission to override the advising lock on this course.") . "<p>";
  533. }
  534. } // count of warnings > 0
  535. } // simply in the course description popup.
  536. ///////////////////////////////
  537. ///////////////////////////////
  538. ///////////////////////////////
  539. ///////////////////////////////
  540. ///////////////////////////////
  541. // We want to place "anticipated availability" for the course in its popup window.
  542. // Only do this based on our setting.
  543. if ($content_id == "AdvisingScreen_display_popup_course_description" && function_exists("course_search_get_course_rotation_schedule")
  544. && variable_get("prereqs_show_availability_in_popup", "no") == "yes") {
  545. // This is the popup window we see when we click on a course to get its description.
  546. //fpm($render);
  547. $course = @$render["#course"]["value"];
  548. if (!is_object($course)) return; // some kind of problem...
  549. $school_id = $course->school_id;
  550. // What is the current advising term?
  551. //fpm($GLOBALS["fp_advising"]);
  552. $advising_term_id = $GLOBALS["fp_advising"]["advising_term_id"];
  553. // Get the advising year from the term.
  554. $year = substr($advising_term_id, 0, 4);
  555. $rotation_schedule = course_search_get_course_rotation_schedule($course->course_id, $year, 5);
  556. $bool_not_anticipated = course_search_get_course_rotation_schedule_not_anticipated($course->course_id);
  557. //fpm($rotation_schedule);
  558. $bool_use_term_abbreviation = (variable_get("prereqs_use_term_desc_abbr_in_popup", "yes") == "yes");
  559. // By default, the scehdule text is saying that nothing is anticipated.
  560. $schedule_text = "<span class='prereqs-schedule-not-anticipated'>" . variable_get("prereqs_not_anticipated_text", "This course isn't currently anticipated to be offered. Please ask your advisor to learn more.");
  561. $schedule_text .= "</span>";
  562. if (!$bool_not_anticipated) {
  563. $x = "";
  564. foreach ($rotation_schedule as $term_id)
  565. {
  566. $x .= " <span class='term-rot-avail'>" . htmlentities(get_term_description($term_id, $bool_use_term_abbreviation, $school_id), ENT_QUOTES) . "</span><span class='comma'>,</span>";
  567. }
  568. $x = rtrim($x, ',');
  569. if ($x) $schedule_text = "<span class='term-rotation-schedule-terms'>$x</span>";
  570. }
  571. if ($schedule_text) {
  572. // Add it to our render array. Weeee.
  573. $render["schedule"] = array(
  574. "label" => t("<b>Anticipated availability:</b>"),
  575. "value" => " <div class='prereqs-schedule-text'>" . $schedule_text . "</div>",
  576. "attributes" => array("class" => "popup-description-section tenpt"),
  577. "weight" => 510,
  578. );
  579. }
  580. } // if content_id == AdvisingScreen_display_popup_course_description and showing availability
  581. ////////////////////////////////////////////////
  582. ////////////////////////////////////////////////
  583. ////////////////////////////////////////////////
  584. ////////////////////////////////////////////////
  585. ////////////////////////////////////////////////
  586. // Show course prereqs in the popup window too.
  587. if ($content_id == "AdvisingScreen_display_popup_course_description"
  588. && variable_get("prereqs_show_courses_in_popup", "no") == "yes") {
  589. $course = @$render["#course"]["value"];
  590. if (!is_object($course)) return; // some kind of problem...
  591. $prereq_data = prereqs_get_prereq_string_for_course($course->course_id);
  592. if ($prereq_data != "") {
  593. fp_add_css(fp_get_module_path("prereqs") . "/css/prereqs.css");
  594. // Format the string for HTML.
  595. $prereq_data = "- " . str_replace("\n", "<br>- ", $prereq_data);
  596. $prereq_data = "<div class='popup-prereq-course-req'>$prereq_data</div>";
  597. $render["prereq_courses"] = array(
  598. "value" => t("<b>Prerequisite courses:</b>") . $prereq_data,
  599. "attributes" => array("class" => "popup-description-section"),
  600. );
  601. }
  602. } // if in course description popup and showing course prereqs.
  603. //////////////////////////////////////////////////////
  604. //////////////////////////////////////////////////////
  605. //////////////////////////////////////////////////////
  606. //////////////////////////////////////////////////////
  607. // This is from the course_search module. Are we displaying rereq courses in the course description?
  608. if ($content_id == "course_search_display_courses" && variable_get("prereqs_show_courses_in_popup", "no") == "yes") {
  609. // Go through the render array, and find the "blocks" where we have our HTML about the courses.
  610. foreach ($render as $key => $details) {
  611. if (strstr($key, "course_search_course_block__")) {
  612. // Found it!
  613. // Get the course_id.
  614. $course_id = str_replace("course_search_course_block__", "", $key);
  615. // Okay, let's get our prereq data...
  616. $prereq_data = prereqs_get_prereq_string_for_course($course_id);
  617. if ($prereq_data != "") {
  618. fp_add_css(fp_get_module_path("prereqs") . "/css/prereqs.css");
  619. // Format the string for HTML.
  620. $prereq_data = "- " . str_replace("\n", "<br>- ", $prereq_data);
  621. $prereq_data = "<!-- PREREQ_COURSE--><div class='popup-prereq-course-req'>$prereq_data</div>";
  622. $html = t("<b>Prerequisite courses:</b>") . $prereq_data;
  623. // "attributes" => array("class" => "popup-description-section"),
  624. // Insert this html just after the description. (above the <!-- DETAILS --> comment)
  625. $render[$key]["value"] = str_replace("<!-- DETAILS -->", "$html<!-- DETAILS -->", $render[$key]["value"]);
  626. } // prereq_data != ""
  627. } // in course_search_course_block
  628. }
  629. } // course_search display courses
  630. } // hook_content_alter

Functions

Namesort descending Description
prereqs_content_alter Implememnt hook_content_alter
prereqs_edit_course_form_submit Our submit handler.
prereqs_edit_course_form_validate validate for the edit course form, from admin.courses.inc.
prereqs_form_alter Implements hook_form_alter
prereqs_get_prereq_array_for_course Return back a friendly array of prereq courses that are required for THIS course_id.
prereqs_get_prereq_array_from_string Assumes prereqs are written in this format: ACCT 101 (C) & ACCT 103 ACCT 102 (B)
prereqs_get_prereq_string_for_course Just gets whatever is in the database for this course.
prereqs_get_prereq_warnings_for_course This is meant to be a general function to find all relavent prereq warnings for the supplied course.
prereqs_menu Implements hook_menu
prereqs_perm
prereqs_settings_form
prereqs_theme_advise_course_row Implements hook_theme_advise_course_row. Lets us re-write how our course rows are drawn, if desired.