advise.module

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

File

modules/advise/advise.module
View source
  1. <?php
  2. function advise_menu() {
  3. $items = array();
  4. $items["admin-tools/toggle-draft"] = array(
  5. "title" => t("Toggle Draft Mode"),
  6. "description" => t("View Draft degrees, courses, and groups in blank degrees, rather than the published versions. This
  7. helps with testing and debugging degree data entry."),
  8. "page_callback" => "fp_render_form",
  9. "page_arguments" => array("advise_toggle_draft_form"),
  10. "access_arguments" => array("toggle_draft"),
  11. "type" => MENU_TYPE_NORMAL_ITEM,
  12. "page_settings" => array(
  13. "menu_links" => array(
  14. 0 => array(
  15. "text" => t("Admin Tools"),
  16. "path" => "admin-tools",
  17. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  18. ),
  19. ),
  20. "menu_icon" => fp_get_module_path('system') . "/icons/wand.png",
  21. ),
  22. 'weight' => 30,
  23. );
  24. $items["admin-tools/clear-advising-cache"] = array(
  25. "title" => t("Clear advising cache"),
  26. "description" => t("Clear the currently advising student & courses from memory."),
  27. "page_callback" => "advise_perform_clear_advising_cache",
  28. "access_arguments" => array("toggle_draft"),
  29. "type" => MENU_TYPE_NORMAL_ITEM,
  30. "page_settings" => array(
  31. "menu_icon" => fp_get_module_path('system') . "/icons/arrow_refresh.png",
  32. ),
  33. 'weight' => 20,
  34. );
  35. $items["view"] = array(
  36. "title" => "Degree",
  37. "page_callback" => "advise_display_view",
  38. "page_arguments" => array("view"),
  39. "access_callback" => "advise_can_access_view",
  40. "tab_family" => "system",
  41. "page_settings" => array (
  42. "display_currently_advising" => TRUE,
  43. ),
  44. "weight" => 30,
  45. "type" => MENU_TYPE_TAB,
  46. );
  47. $items["view/print"] = array(
  48. "title" => "Degree",
  49. "page_callback" => "advise_display_view",
  50. "page_arguments" => array("view"),
  51. "access_callback" => TRUE,
  52. "page_settings" => array (
  53. "display_currently_advising" => TRUE,
  54. "screen_mode" => "not_advising",
  55. ),
  56. "type" => MENU_TYPE_CALLBACK,
  57. );
  58. $items["what-if"] = array(
  59. "title" => "What If?",
  60. "page_callback" => "advise_display_view",
  61. "page_arguments" => array("what-if"),
  62. "access_callback" => "advise_can_access_view",
  63. "tab_family" => "system",
  64. "page_settings" => array (
  65. "display_currently_advising" => TRUE,
  66. ),
  67. "weight" => 60,
  68. "type" => MENU_TYPE_TAB,
  69. );
  70. $items["what-if/print"] = array(
  71. "title" => "What If?",
  72. "page_callback" => "advise_display_view",
  73. "page_arguments" => array("what-if"),
  74. "access_callback" => TRUE,
  75. "page_settings" => array (
  76. "display_currently_advising" => TRUE,
  77. "bool_print" => TRUE,
  78. "screen_mode" => "not_advising",
  79. ),
  80. "type" => MENU_TYPE_CALLBACK,
  81. );
  82. $items["history"] = array(
  83. "title" => "History",
  84. "page_callback" => "advise_display_history",
  85. "access_callback" => "advise_can_access_view",
  86. "tab_family" => "system",
  87. "page_settings" => array (
  88. "display_currently_advising" => TRUE,
  89. ),
  90. "weight" => 40,
  91. "type" => MENU_TYPE_TAB,
  92. "file" => menu_get_module_path("advise") . "/advise.history.inc",
  93. );
  94. // My popups....
  95. $items["advise/popup-display-summary"] = array(
  96. "title" => "Advising Summary",
  97. "page_callback" => "advise_popup_display_summary",
  98. "access_callback" => "advise_user_can_view_advising_session_access_callback",
  99. "page_settings" => array(
  100. "page_is_popup" => TRUE,
  101. "page_hide_report_error" => TRUE,
  102. "bool_print" => TRUE,
  103. ),
  104. "type" => MENU_TYPE_TAB,
  105. "tab_family" => "adv_summary",
  106. "file" => menu_get_module_path("advise") . "/advise.history.inc",
  107. );
  108. $items["advise/popup-change-term"] = array(
  109. "title" => "Change advising term",
  110. "page_callback" => "advise_display_popup_change_term",
  111. "access_arguments" => array("can_advise_students"),
  112. "page_settings" => array(
  113. "page_is_popup" => TRUE,
  114. "display_currently_advising" => FALSE,
  115. ),
  116. "type" => MENU_TYPE_CALLBACK,
  117. );
  118. $items["advise/popup-change-track"] = array(
  119. "title" => "Change advising track",
  120. "page_callback" => "advise_display_popup_change_track",
  121. "access_arguments" => array("access_logged_in_content"),
  122. "page_settings" => array(
  123. "page_is_popup" => TRUE,
  124. "page_hide_report_error" => TRUE,
  125. ),
  126. "type" => MENU_TYPE_CALLBACK,
  127. );
  128. $items["advise/popup-course-description"] = array(
  129. "title" => "Description",
  130. "page_callback" => "advise_display_popup_course_description",
  131. "access_callback" => TRUE,
  132. "page_settings" => array(
  133. "page_is_popup" => TRUE,
  134. "page_hide_report_error" => TRUE,
  135. ),
  136. "weight" => 10,
  137. );
  138. $items["advise/popup-substitute-selected"] = array(
  139. "title" => "Substitute",
  140. "page_callback" => "advise_display_popup_substitute_selected",
  141. "access_arguments" => array("can_substitute"),
  142. "page_settings" => array(
  143. "page_is_popup" => TRUE,
  144. "page_hide_report_error" => TRUE,
  145. ),
  146. "weight" => 10,
  147. );
  148. $items["advise/popup-group-select"] = array(
  149. "title" => "Select",
  150. "page_callback" => "advise_display_popup_group_select",
  151. "access_callback" => TRUE,
  152. "page_settings" => array(
  153. "page_is_popup" => TRUE,
  154. "page_hide_report_error" => TRUE,
  155. ),
  156. "weight" => 10,
  157. );
  158. // Toolbox...
  159. $items["advise/popup-toolbox/transfers"] = array(
  160. "title" => "Transfers",
  161. "page_callback" => "advise_display_popup_toolbox_transfers",
  162. "access_arguments" => array("can_substitute"),
  163. "page_settings" => array(
  164. "page_is_popup" => TRUE,
  165. "page_hide_report_error" => TRUE,
  166. ),
  167. "weight" => 10,
  168. "type" => MENU_TYPE_TAB,
  169. "tab_family" => "advise-toolbox",
  170. "file" => menu_get_module_path("advise") . "/advise.toolbox.inc",
  171. );
  172. $items["advise/popup-toolbox/substitutions"] = array(
  173. "title" => "Substitutions",
  174. "page_callback" => "advise_display_popup_toolbox_substitutions",
  175. "access_arguments" => array("can_substitute"),
  176. "page_settings" => array(
  177. "page_is_popup" => TRUE,
  178. "page_hide_report_error" => TRUE,
  179. ),
  180. "weight" => 20,
  181. "type" => MENU_TYPE_TAB,
  182. "tab_family" => "advise-toolbox",
  183. "file" => menu_get_module_path("advise") . "/advise.toolbox.inc",
  184. );
  185. $items["advise/popup-toolbox/moved"] = array(
  186. "title" => "Moved",
  187. "page_callback" => "advise_display_popup_toolbox_moved",
  188. "access_arguments" => array("can_substitute"),
  189. "page_settings" => array(
  190. "page_is_popup" => TRUE,
  191. "page_hide_report_error" => TRUE,
  192. ),
  193. "weight" => 30,
  194. "type" => MENU_TYPE_TAB,
  195. "tab_family" => "advise-toolbox",
  196. "file" => menu_get_module_path("advise") . "/advise.toolbox.inc",
  197. );
  198. $items["advise/popup-toolbox/courses"] = array(
  199. "title" => "Courses",
  200. "page_callback" => "advise_display_popup_toolbox_courses",
  201. "access_arguments" => array("can_substitute"),
  202. "page_settings" => array(
  203. "page_is_popup" => TRUE,
  204. "page_hide_report_error" => TRUE,
  205. ),
  206. "weight" => 40,
  207. "type" => MENU_TYPE_TAB,
  208. "tab_family" => "advise-toolbox",
  209. "file" => menu_get_module_path("advise") . "/advise.toolbox.inc",
  210. );
  211. return $items;
  212. }
  213. /**
  214. * hook_cron
  215. */
  216. function advise_cron() {
  217. // Delete advising data which has been marked with "delete_flag = 1"
  218. $last_run = intval(variable_get("advise_last_run_delete_flag_removal", 0));
  219. $check_against = strtotime("NOW - 7 DAYS"); // don't run any more often than once every 7 days.
  220. $c = 0;
  221. if ($check_against > $last_run) {
  222. $res = db_query("SELECT * FROM advising_sessions
  223. WHERE delete_flag = 1 ");
  224. while ($cur = db_fetch_object($res)) {
  225. $asid = $cur->advising_session_id;
  226. // Delete courses that were part of this advising session.
  227. db_query("DELETE FROM advised_courses WHERE advising_session_id = ?", array($asid));
  228. // Lastly, delete from advising_sessions table itself.
  229. db_query("DELETE FROM advising_sessions WHERE advising_session_id = ?", array($asid));
  230. watchdog("advise", "Deleted from flagged db deleted advising_session_id $asid", array(), WATCHDOG_DEBUG);
  231. $c++;
  232. } // while cur
  233. watchdog("advise", "Delete from flagged advising sessions db complete. $c items removed.", array(), WATCHDOG_DEBUG);
  234. $res = db_query("DELETE FROM student_substitutions WHERE delete_flag = 1");
  235. $c = db_affected_rows($res);
  236. watchdog("advise", "Delete from flagged student substitutions db complete. $c items removed.", array(), WATCHDOG_DEBUG);
  237. $res = db_query("DELETE FROM student_unassign_group WHERE delete_flag = 1");
  238. $c = db_affected_rows($res);
  239. watchdog("advise", "Delete from flagged student unassign group db complete. $c items removed.", array(), WATCHDOG_DEBUG);
  240. $res = db_query("DELETE FROM student_unassign_transfer_eqv WHERE delete_flag = 1");
  241. $c = db_affected_rows($res);
  242. watchdog("advise", "Delete from flagged student unassign transfer eqv db complete. $c items removed.", array(), WATCHDOG_DEBUG);
  243. variable_set("advise_last_run_delete_flag_removal", time());
  244. } // check against > last_run, so we should do it.
  245. } // hook_cron
  246. /**
  247. * Returns back an integer of the number of times a particular course was advised (unique per student) for a certain term.
  248. */
  249. function advise_get_count_of_advised_course_for_term($course_id, $term_id) {
  250. // Okay, now find the most recent advising session for this student.
  251. $res = db_query("SELECT count(a.student_id) as mycount
  252. FROM advising_sessions a, users b, advised_courses c, students d
  253. WHERE a.advising_session_id = c.advising_session_id
  254. AND c.course_id = ?
  255. AND a.term_id = ?
  256. AND a.delete_flag = 0
  257. AND a.is_draft = 0
  258. AND a.most_recent_session = 1
  259. AND a.student_id = b.cwid
  260. AND a.student_id = d.cwid
  261. AND d.is_active = 1
  262. ", array($course_id, $term_id));
  263. $cur = db_fetch_array($res);
  264. $count = intval(@$cur["mycount"]);
  265. return $count;
  266. } // advise_get_count_of_advised_course_for_term
  267. /**
  268. * Returns back an integer for the number of courses which a student was "enrolled" for a certain term.
  269. * In this situation, we will not make sure the student is "active", since they may have since graduated or something.
  270. */
  271. function advise_get_count_of_enrolled_course_for_term($course_id, $term_id) {
  272. $res = db_query("SELECT count(distinct(a.student_id)) as mycount
  273. FROM student_courses a, courses c
  274. WHERE c.course_id = ?
  275. AND c.delete_flag = 0
  276. AND a.course_id = c.course_id
  277. AND a.term_id = ?
  278. ", array($course_id, $term_id));
  279. $cur = db_fetch_array($res);
  280. $count = intval(@$cur["mycount"]);
  281. return $count;
  282. }
  283. /**
  284. * Returns an array of advising session id's for the given advising token.
  285. * Makes sure is_empty is 0 and is_draft is 0
  286. * Ordered by term_id DESC
  287. *
  288. * returns FALSE if nothing is found.
  289. */
  290. function advise_get_advising_sessions_for_advising_token($adv_token) {
  291. $rtn = array();
  292. $res = db_query("SELECT * FROM advising_sessions
  293. WHERE advising_session_token = ?
  294. AND is_empty = 0
  295. AND is_draft = 0
  296. ORDER BY term_id DESC", array($adv_token));
  297. while($cur = db_fetch_array($res)) {
  298. $rtn[] = $cur['advising_session_id'];
  299. }
  300. if (count($rtn) > 0) return $rtn;
  301. return FALSE;
  302. }
  303. /**
  304. * Returns back the advising row from the database for a particular advising session id.
  305. */
  306. function advise_get_advising_session_from_advising_session_id($adv_id) {
  307. $rtn = array();
  308. $res = db_query("SELECT * FROM advising_sessions
  309. WHERE advising_session_id = ?
  310. ORDER BY term_id DESC", array($adv_id));
  311. $cur = db_fetch_array($res);
  312. $rtn = $cur;
  313. return $rtn;
  314. }
  315. /**
  316. * Used by the menu to determine if the user can see the View (Degree and What If) tab for the current student.
  317. */
  318. function advise_can_access_view($student_id = "") {
  319. global $current_student_id, $user;
  320. if ($student_id == "") $student_id = $current_student_id;
  321. // must be logged in first...
  322. if (!user_has_permission("access_logged_in_content")) return FALSE;
  323. if ($student_id == "" || $student_id === 0) return FALSE;
  324. if ($user->id == 1) return TRUE; // the admin user.
  325. // Can the user view ANY advising session?
  326. if (user_has_permission("view_any_advising_session")) return TRUE;
  327. // can the user only see their own advisees, and is this student one of their advisees?
  328. if (user_has_permission("view_advisee_advising_session")) {
  329. // Is the student_id in their list of advisees?
  330. $advisees = advise_get_advisees();
  331. if (in_array($student_id, $advisees)) return TRUE;
  332. }
  333. // Is this user viewing THEIR OWN advising session?
  334. if (user_has_permission("view_own_advising_session")) {
  335. if ($student_id == $user->cwid && ($student_id != "" && $student_id !== 0)) return TRUE;
  336. }
  337. // All else fails, return FALSE
  338. return FALSE;
  339. }
  340. function advise_get_advisees($faculty_id = "") {
  341. global $user;
  342. if ($faculty_id == "") $faculty_id = $user->cwid;
  343. $rtn = array();
  344. $res = db_query("SELECT * FROM advisor_student
  345. WHERE faculty_id = ?
  346. ", $faculty_id);
  347. foreach ($res as $cur) {
  348. $rtn[] = $cur["student_id"];
  349. }
  350. return $rtn;
  351. }
  352. /**
  353. * Similar to @see advise_get_advisees, return a list of all advisors assigned to this student.
  354. */
  355. function advise_get_advisors_for_student($student_id = "") {
  356. $rtn = array();
  357. $res = db_query("SELECT * FROM advisor_student
  358. WHERE student_id = ?
  359. ", array($student_id));
  360. while ($cur = db_fetch_array($res)) {
  361. $faculty_id = $cur['faculty_id'];
  362. $rtn[] = $faculty_id;
  363. }
  364. return $rtn;
  365. }
  366. function advise_toggle_draft_form() {
  367. $form = array();
  368. $form["mark" . $m++] = array(
  369. "value" => "<p>" . t("By turning Draft Mode on, you will be able
  370. to view degree plans which are still in 'Draft' mode
  371. in both the regular View tab, as well as the Blank Degrees module,
  372. if enabled.") . "</p>",
  373. );
  374. $form["draft"] = array(
  375. "type" => "radios",
  376. "label" => t("Enable Draft Mode?"),
  377. "options" => array("yes" => t("Yes"), "no" => t("No")),
  378. "value" => $_SESSION["fp_draft_mode"],
  379. );
  380. $form["submit"] = array(
  381. "type" => "submit",
  382. "value" => t("Submit"),
  383. "prefix" => "<hr>",
  384. );
  385. $form["#redirect"] = array(
  386. "path" => "main",
  387. "query" => "",
  388. );
  389. return $form;
  390. }
  391. function advise_toggle_draft_form_submit($form, $form_state) {
  392. fp_add_message(t("Draft mode successfully updated."));
  393. $_SESSION["fp_draft_mode"] = $form_state["values"]["draft"];
  394. }
  395. /**
  396. * This is the "change track" popup we will display if the degree cannot be combined with anything else (non-dynamic).
  397. *
  398. * We will basically treat it similarly to how FlightPath 4x did things.
  399. */
  400. function advise_display_popup_change_track_non_dynamic_degree() {
  401. global $degree_plan, $student, $current_student_id;
  402. $rtn = "";
  403. $db = get_global_database_handler();
  404. // Find out what track the user is already on.
  405. // From What If mode...
  406. if (@$GLOBALS["fp_advising"]["advising_what_if"] == "yes") {
  407. $student_majors_array = @csv_to_array($_SESSION["what_if_major_code" . $student->student_id]);
  408. }
  409. else {
  410. // Not in what if mode-- get the data from the normal student_majors table.
  411. $student_majors_array = fp_get_student_majors($student->student_id, FALSE, FALSE);
  412. } //else
  413. $degree_plan->load_descriptive_data();
  414. $major_code = $degree_plan->major_code;
  415. $catalog_year = $degree_plan->catalog_year;
  416. $bare_degree_plan = $degree_plan;
  417. // Are we already on a track? If so, find out what the original degree was.
  418. if (strstr($major_code, "_")) {
  419. $temp = explode("_", $major_code);
  420. $m = trim($temp[0]);
  421. // Remove trailing | if its there.
  422. $m = rtrim($m, "|");
  423. $bare_degree_plan = $db->get_degree_plan($m, $catalog_year); // the original degree plan (bare, no tracks)
  424. $major_code = $m;
  425. }
  426. $just_major_code = $major_code;
  427. $temp = explode("_" , $just_major_code);
  428. $just_major_code = $temp[0];
  429. $just_major_code = rtrim($just_major_code, "|");
  430. $rtn .= "<div>
  431. " . t("The student's degree has one or more degree options, which affects which courses are required.
  432. Please select a degree option (or track) from the list below.") . "
  433. <br><br>
  434. " . t("If you are unsure of what to do, simply close this window.") . "
  435. </div>
  436. ";
  437. $rtn .= "<br><br><b>" . $bare_degree_plan->title . "</b> " . t("degree options:") . "<!--DEFAULT-->
  438. <ul>";
  439. // Get the list of available tracks for this degree.
  440. if (!$tracks = $bare_degree_plan->get_available_tracks())
  441. {
  442. $rtn .= "<li>" . t("This major has no degree options.") . "</li>";
  443. }
  444. // Is there a "default" message for all tracks, which will override
  445. // any other track descriptions?
  446. // We need to look through all the tracks for the
  447. // characters: "DEFAULT:"
  448. // If we find this, then this is the default description
  449. // which applies to all the tracks, and it should be displayed
  450. // at the top.
  451. $bool_default_description = false;
  452. for ($t = 0; $t < count($tracks); $t++)
  453. {
  454. $temp = explode(" ~~ ", $tracks[$t]);
  455. $track_code = trim($temp[0]);
  456. $track_title = trim($temp[1]);
  457. $track_description = trim($temp[2]);
  458. if (strstr($track_description, "DEFAULT:")) {
  459. // Yes! We found a default message.
  460. $bool_default_description = true;
  461. $track_description = filter_markup(trim(str_replace("DEFAULT:", "", $track_description)));
  462. $track_description = "<div style='padding-top: 10px;' class='tenpt'>$track_description</div>";
  463. $rtn = str_replace("<!--DEFAULT-->",$track_description, $rtn);
  464. break;
  465. }
  466. }
  467. for ($t = 0; $t < count($tracks); $t++)
  468. {
  469. $temp = explode(" ~~ ", $tracks[$t]);
  470. $track_code = trim($temp[0]);
  471. $track_title = trim($temp[1]);
  472. $track_description = "";
  473. $temp_tc = $track_code;
  474. if ($temp_tc == "")
  475. {
  476. $temp_tc = "none";
  477. }
  478. $major_and_track_code = $just_major_code;
  479. if ($temp_tc != "none") {
  480. if (!strstr($major_and_track_code, "|")) {
  481. $major_and_track_code .= "|";
  482. }
  483. $major_and_track_code .= "_" . $temp_tc;
  484. }
  485. // If this is the current track_code, mark it as such.
  486. if (in_array($major_and_track_code, $student_majors_array)) {
  487. $track_title .= " <b>(" . t("current") . ")</b>";
  488. }
  489. if ($bool_default_description == false)
  490. {
  491. $track_description = filter_markup(trim($temp[2]));
  492. if ($track_description != "")
  493. {
  494. $track_description = " - $track_description";
  495. }
  496. }
  497. // We need the track's degree id.
  498. $trid = $db->get_degree_id($major_and_track_code, $catalog_year);
  499. if ($trid == $bare_degree_plan->degree_id) $trid = ""; // don't use anything for the "none" option (the "orignal" degree plan)
  500. $link = fp_get_js_confirm_link(t("Are you sure you wish to change degree options?"), "opener.changeTrackNonDynamicDegree(\"$trid\"); window.close(); ", $track_title);
  501. if ($GLOBALS["fp_advising"]["advising_what_if"] == "yes") {
  502. $link = "<a href='javascript: popupChangeWhatIfTrackNonDynamicDegree(\"$major_and_track_code\", \"" . t("Are you sure you wish to change degree options?") . "\");'>$track_title</a>";
  503. }
  504. $rtn .= "<li class='tenpt' style='padding:3px;'>
  505. $link $track_description</li>";
  506. }
  507. $rtn .= "</ul>";
  508. watchdog("advise", "display_popup_change_track_non_dynamic $current_student_id", array(), WATCHDOG_DEBUG);
  509. return $rtn;
  510. } // popup_change_track_non_dynamic_degree
  511. function advise_display_popup_change_track() {
  512. global $degree_plan, $student, $current_student_id;
  513. $rtn = "";
  514. advise_init_screen();
  515. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  516. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  517. if ($degree_plan->db_allow_dynamic == 0) {
  518. // Since this is NOT a degree plan which can be combined with others, we
  519. // want to display this popup like in FlightPath 4.x.
  520. return advise_display_popup_change_track_non_dynamic_degree();
  521. }
  522. $top_level_majors_csv = "";
  523. $degree_plan_array = array();
  524. if ($degree_plan->is_combined_dynamic_degree_plan == FALSE) {
  525. // NOT a combined degree plan. Just use the 1 degree plan we gots.
  526. $degree_plan_array[$degree_plan->degree_id] = $degree_plan;
  527. }
  528. else {
  529. // It IS a combined degree plan, so we need to get all the plans out of there.
  530. foreach ($degree_plan->combined_degree_ids_array as $t_degree_id) {
  531. $t_degree_plan = fp_load_degree($t_degree_id);
  532. $t_degree_plan->load_descriptive_data();
  533. if ($t_degree_plan->get_available_tracks()) {
  534. }
  535. $degree_plan_array[$t_degree_plan->degree_id] = $t_degree_plan;
  536. }
  537. }
  538. $locked_array = array(); // keep track of any degree classes which are "locked".
  539. // From What If mode...
  540. if (@$GLOBALS["fp_advising"]["advising_what_if"] == "yes") {
  541. $student_majors_array = @csv_to_array($_SESSION["what_if_major_code" . $student->student_id]);
  542. }
  543. else {
  544. // Not in what if mode-- get the data from the normal student_majors table.
  545. $student_majors_array = fp_get_student_majors($student->student_id, FALSE, TRUE);
  546. // Also see if any degree classes should be "locked" for this student.
  547. $db = get_global_database_handler();
  548. $temp = $db->get_student_majors_from_db($student->student_id, FALSE, FALSE, FALSE);
  549. foreach ($temp as $line) {
  550. $t = explode("~", $line);
  551. if (trim(strtoupper($t[0])) == "LOCKED") {
  552. $locked_array[] = trim($t[1]);
  553. }
  554. }
  555. } //else
  556. $rtn .= "<div>
  557. " . t("The student's degree has one or more degree options, which affects which courses are required.
  558. Please select a degree option (or track) from the list below.") . "
  559. <br><br>
  560. " . t("If you are unsure of what to do, simply close this window.") . "
  561. </div>
  562. ";
  563. // Loop through available degrees here
  564. foreach ($degree_plan_array as $t_degree_plan) {
  565. $t_degree_plan->load_descriptive_data();
  566. // Skip any degree plan that isn't level 1 or level 2. In other words,
  567. // if this is already a track, then skip it.
  568. $details = fp_get_degree_classification_details($t_degree_plan->degree_class);
  569. if ($details["level_num"] == 3) continue;
  570. // Go through each type of classification in this degree's track_selection_config_array.
  571. //foreach ($t_degree_plan->track_selection_config_array as $machine_name => $tdetails) {
  572. $degree_classes = fp_get_degree_classifications();
  573. foreach ($degree_classes["levels"][3] as $machine_name => $class_title) {
  574. $extra_css_class = "";
  575. $class_is_empty = TRUE;
  576. $is_locked = FALSE;
  577. if (in_array($machine_name, $locked_array)) {
  578. $is_locked = TRUE;
  579. $extra_css_class = "degree-class-is-locked";
  580. }
  581. $html = "";
  582. $min_max_options = "";
  583. // Check to see what we have in this degree's track_selection_config_array
  584. $min_tracks = @intval($t_degree_plan->track_selection_config_array[$machine_name]["min_tracks"]);
  585. $max_tracks = @intval($t_degree_plan->track_selection_config_array[$machine_name]["max_tracks"]);
  586. $default_tracks = @trim($t_degree_plan->track_selection_config_array[$machine_name]["default_tracks"]);
  587. $default_tracks_array = csv_to_array($default_tracks);
  588. $degree_id = $t_degree_plan->degree_id;
  589. // Add this information to our javascript settings...
  590. $js = array(
  591. "degree_min_max_tracks_" . $degree_id . "_split_" . $machine_name => $min_tracks . "~" . $max_tracks,
  592. "degree_name_" . $degree_id => $t_degree_plan->get_title2(FALSE, FALSE, FALSE),
  593. "class_title_" . $machine_name => $class_title,
  594. );
  595. fp_add_js($js, "setting");
  596. $min_max_options = "<div class='advise-select-track-min-max advise-select-track-between'>Please select between $min_tracks and $max_tracks $class_title options.</div>";
  597. if ($min_tracks == $max_tracks) {
  598. $min_max_options = "<div class='advise-select-track-min-max advise-select-track-exact-number'>Please select $max_tracks $class_title options.</div>";
  599. }
  600. if ($min_tracks == $max_tracks && $max_tracks == 1) {
  601. $min_max_options = "<div class='advise-select-track-min-max advise-select-track-exactly-one'>Please select 1 $class_title option.</div>";
  602. }
  603. if ($min_tracks > 0 && $max_tracks == 0) {
  604. // Meaning, there is no maximum. It's infinite.
  605. $min_max_options = "<div class='advise-select-track-min-max advise-select-track-at-least-one'>Please select at least $min_tracks $class_title option(s) for this degree.</div>";
  606. }
  607. if ($min_tracks == $max_tracks && $max_tracks == 0) {
  608. $min_max_options = "<div class='advise-select-track-min-max advise-select-track-optional'>Optional: You are not required to select any additional $class_title options.</div>";
  609. }
  610. // Let's look to see what "tracks" this degree has.
  611. $html .= "<br>
  612. <div class='advise-track-selection-tracks $extra_css_class'>
  613. <div class='tenpt'><span class='advise-select-degree-title'>" . $t_degree_plan->title . "</span> <span class='advise-select-class-title'>$class_title</span> options:</div>
  614. <div class='advise-track-min-max-options advise-track-min-$min_tracks advise-track-max-$max_tracks'>$min_max_options</div>
  615. <!--DEFAULT_$machine_name-->
  616. <div class='advise-track-options-region'>
  617. ";
  618. $major_code = $t_degree_plan->major_code;
  619. $top_level_majors_csv .= $major_code . ",";
  620. $tracks = array();
  621. // Get the list of available tracks for this student.
  622. if (!$tracks = $t_degree_plan->get_available_tracks())
  623. {
  624. $html .= "<div class='advise-select-track-none'>&nbsp; &nbsp; &bull; " . t("This degree has no degree options.") . "</div>";
  625. }
  626. if (!is_array($tracks)) $tracks = array();
  627. // Is there a "default" message for all tracks, which will override
  628. // any other track descriptions?
  629. // We need to look through all the tracks for the
  630. // characters: "DEFAULT:"
  631. // If we find this, then this is the default description
  632. // which applies to all the tracks, and it should be displayed
  633. // at the top.
  634. $bool_default_description = false;
  635. for ($t = 0; $t < count($tracks); $t++)
  636. {
  637. $temp = explode(" ~~ ", $tracks[$t]);
  638. $track_code = trim(@$temp[0]);
  639. $track_title = trim(@$temp[1]);
  640. $track_description = trim(@$temp[2]);
  641. // if this track is NOT of the same classification as the current machine_code, we skip it.
  642. $track_machine_name = trim(@$temp[4]);
  643. if ($track_machine_name != $machine_name) continue; // not the right degree_class
  644. if (strstr($track_description, "DEFAULT:")) {
  645. // Yes! We found a default message.
  646. $bool_default_description = true;
  647. $track_description = filter_markup(trim(str_replace("DEFAULT:", "", $track_description)));
  648. $track_description = "<div style='padding-top: 10px;' class='tenpt advise-select-track-description'>$track_description</div>";
  649. $html = str_replace("<!--DEFAULT_$machine_name-->",$track_description, $rtn);
  650. break;
  651. }
  652. }
  653. ///////////////////
  654. // Okay, go through the tracks,
  655. for ($t = 0; $t < count($tracks); $t++)
  656. {
  657. $temp = explode(" ~~ ", $tracks[$t]);
  658. $track_code = trim(@$temp[0]);
  659. $track_title = trim(@$temp[1]);
  660. $track_degree_id = intval(trim(@$temp[3]));
  661. $track_description = "";
  662. // if this track is NOT of the same classification as the current machine_code, we skip it.
  663. $track_machine_name = trim(@$temp[4]);
  664. if ($track_machine_name != $machine_name) continue; // not the right degree_class
  665. $selected = $disabled = "";
  666. // If this track has been selected already, mark it as such
  667. if (isset($degree_plan_array[$track_degree_id])) {
  668. // Meaning yes, this was already selected for this student.
  669. $selected = "checked=checked";
  670. }
  671. // Is this track marked as NOT is_editable?
  672. $is_editable = 1;
  673. if (isset($student_majors_array[$t_degree_plan->major_code . "|_" . $track_code])) {
  674. $is_editable = intval(@$student_majors_array[$t_degree_plan->major_code . "|_" . $track_code]["is_editable"]);
  675. }
  676. if ($is_editable != 1 || $is_locked == TRUE) {
  677. $disabled = "disabled=disabled";
  678. }
  679. if ($bool_default_description == false) {
  680. $track_description = filter_markup(trim(@$temp[2]));
  681. }
  682. $temp_tc = $track_code;
  683. if ($temp_tc == "") {
  684. $temp_tc = "none";
  685. }
  686. $link = fp_get_js_confirm_link(t("Are you sure you wish to change degree options?"), "opener.changeTrack(\"$temp_tc\");", $track_title);
  687. // We actually don't need to do anything special for what_if, I think. When
  688. // we save, it should automatically detect it and set the appropriate values.
  689. $is_whatif = 0;
  690. if ($GLOBALS["fp_advising"]["advising_what_if"] == "yes") {
  691. $is_whatif = 1;
  692. }
  693. $track_degree_plan = fp_load_degree($track_degree_id, NULL, TRUE); // load minimally
  694. $input_type = "checkbox";
  695. $input_name = "track_degree_id_$track_degree_id";
  696. // We are extected to select EXACTLY 1 track...
  697. if ($min_tracks == $max_tracks && $max_tracks == 1) {
  698. $input_type = "radio";
  699. $input_name = "track_degree_id_" . $degree_id; // needs to be the same for all options.
  700. }
  701. if ($track_degree_plan->db_allow_dynamic == 1) {
  702. $extra_class = "";
  703. $is_default = FALSE;
  704. if (in_array($t_degree_plan->major_code . "|_" . $track_code, $default_tracks_array)) {
  705. $extra_class = "advise-select-track-default-track";
  706. $is_default = TRUE;
  707. }
  708. $html .= "<div class='track-option $extra_class'>";
  709. $html .= "
  710. <label>
  711. <input type='$input_type' name='$input_name' degree_id_class='{$degree_id}_class_{$machine_name}'
  712. is_editable='$is_editable'
  713. value='$track_degree_id' $selected $disabled>
  714. <span class='track-title'>" . $track_degree_plan->get_title2(TRUE, TRUE) . "
  715. ";
  716. if ($is_default) {
  717. $html .= "<span class='track-default-track'>" . t("(Default)") . "</span>";
  718. }
  719. $html .= "
  720. </span>
  721. </label>";
  722. if (!$is_editable) {
  723. $html .= "<div class='track-not-editable'>" . t("You are not allowed to modify this option.") . "</div>";
  724. }
  725. $html .= "
  726. <div class='track-description'>
  727. $track_description
  728. </div>
  729. </div>";
  730. $class_is_empty = FALSE;
  731. }
  732. } // for (count(tracks))
  733. if ($is_locked) {
  734. $html .= "<div class='track-class-is-locked-msg'>" . t("Selections from this degree classification are locked. You may use What If mode to explore
  735. other options, or ask your advisor about changing these options officially.") . "</div>";
  736. }
  737. $html .= "</div>";
  738. $html .= "</div>"; // advise-track-selection-tracks
  739. if (!$class_is_empty) {
  740. $rtn .= $html;
  741. }
  742. }
  743. } // foreach degree_plan_array
  744. $rtn .= "<input type='button' value='" . t("Apply Selections") . "'
  745. onClick='if(confirm(\"Are you sure you wish to apply these selections to the degree plan?\")) { popupChangeTrackSelections($is_whatif); }'>";
  746. // Keep track of what our top-level majors were.
  747. $top_level_majors_csv = rtrim($top_level_majors_csv, ","); // remove trailing comma if exists
  748. $rtn .= "<input type='hidden' name='top_level_majors_csv' id='top_level_majors_csv' value='$top_level_majors_csv'>";
  749. watchdog("advise", "display_popup_change_track $current_student_id", array(), WATCHDOG_DEBUG);
  750. return $rtn;
  751. } // display_popup_change_track
  752. /**
  753. * This popup allows the advisor to change the advising term.
  754. */
  755. function advise_display_popup_change_term() {
  756. global $current_student_id;
  757. $rtn = "";
  758. $school_id = db_get_school_id_for_student_id($current_student_id);
  759. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  760. $current_term_id = $_REQUEST["advising_term_id"];
  761. $current_term = get_term_description($current_term_id, FALSE, $school_id);
  762. $rtn .= "<div>
  763. " . t("You may advise this student for future semesters. Please select which
  764. advising term you would like to advise for from the list below. If you
  765. are unsure, simply close this window and continue to advise for the current
  766. term of %current_term.", array("%current_term" => $current_term)) . "
  767. </div>";
  768. $rtn .= "<ul class='change-terms'>";
  769. $temp = explode(",", variable_get_for_school("available_advising_term_ids", "0", $school_id));
  770. for ($t = 0; $t < count($temp); $t++) {
  771. $term_id = trim($temp[$t]);
  772. $term_desc = get_term_description($term_id, FALSE, $school_id);
  773. if ($term_id == $current_term_id) {
  774. $term_desc = "<strong class='current-term'>$term_desc</strong> - " . t("current");
  775. }
  776. // This bit allows other modules to use this function, but change (by appending a string) to the parent function
  777. // we intend to call.
  778. // Example: if the append string is "MyModule" then the full function called below will be changeTermMyModule().
  779. $perform_parent_function = "changeTerm";
  780. if (isset($_REQUEST['append_parent_function'])) {
  781. $x = fp_get_machine_readable(trim($_REQUEST['append_parent_function'])); // Make safe from hackers
  782. $perform_parent_function .= $x;
  783. }
  784. $link = fp_get_js_confirm_link(t("Are you sure you wish to change advising terms?"), "parent.fpCloseSmallIframeDialog(\"\");parent.$perform_parent_function(\"$term_id\");", $term_desc);
  785. $rtn .= "<li>$link</li>";
  786. }
  787. $rtn .= "</ul>";
  788. watchdog("advise", "display_popup_change_term $current_student_id", array(), WATCHDOG_DEBUG);
  789. return $rtn;
  790. }
  791. /**
  792. * This is an access callback. Can the user view the advising session specified
  793. * in the REQUEST?
  794. */
  795. function advise_user_can_view_advising_session_access_callback() {
  796. global $user;
  797. if (user_has_permission("view_any_advising_session")) {
  798. return TRUE;
  799. }
  800. if (user_has_permission("view_own_advising_session") || user_has_permission("view_advisee_advising_session")) {
  801. $advising_session_id = $_REQUEST["advising_session_id"];
  802. // First, what was the student's CWID associated with that advising_session_id?
  803. $res = db_query("SELECT student_id FROM advising_sessions
  804. WHERE advising_session_id = ? ", $advising_session_id);
  805. $cur = db_fetch_array($res);
  806. if (user_has_permission("view_own_advising_session") && $user->cwid == $cur["student_id"]) {
  807. return TRUE;
  808. }
  809. if (user_has_permission("view_advisee_advising_session")) {
  810. $faculty_advisees = advise_get_advisees();
  811. if (in_array($cur["student_id"], $faculty_advisees)) {
  812. return TRUE;
  813. }
  814. }
  815. }
  816. return FALSE;
  817. }
  818. function advise_display_popup_group_select() {
  819. global $current_student_id, $fp, $screen, $degree_plan;
  820. $rtn = "";
  821. advise_init_screen();
  822. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  823. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  824. $db = get_global_database_handler();
  825. $blank_degree_id = trim(@$_GET["blank_degree_id"]);
  826. $course_id = trim(@$_GET["course_id"]);
  827. $group_id = trim(addslashes(@$_GET["group_id"]));
  828. $group_hours_remaining = trim(addslashes(@$_GET["group_hours_remaining"]));
  829. $semester_num = trim(addslashes(@$_GET["semester_num"]));
  830. $req_by_degree_id = trim(addslashes(@$_REQUEST["req_by_degree_id"]));
  831. $perform_action2 = @$_REQUEST["perform_action2"];
  832. $school_id = db_get_school_id_for_student_id($current_student_id);
  833. // If this is a "blank" degree, make sure we set the degree_id correctly.
  834. if($blank_degree_id != "") {
  835. // If req_by_degree_id isn't blank or zero, then use it instead.
  836. if ($req_by_degree_id != '' && intval($req_by_degree_id) != 0) {
  837. $degree_plan = fp_load_degree($req_by_degree_id);
  838. }
  839. else {
  840. // Default behavior
  841. $degree_plan = fp_load_degree($blank_degree_id);
  842. }
  843. $fp->degree_plan = $degree_plan;
  844. $screen->degree_plan = $degree_plan;
  845. $screen->bool_blank = TRUE;
  846. }
  847. if (!$group = $degree_plan->find_placeholder_group($group_id, $semester_num)) {
  848. fpm("Could not find group (id: $group_id) in semester (num: $semester_num).");
  849. fpm($degree_plan);
  850. return;
  851. }
  852. if ($group_id == DegreePlan::GROUP_ID_FOR_COURSES_ADDED) {
  853. // This is the Add a Course group. We must initialize it, as it
  854. // does not exist yet.
  855. // We need to populate this group now.
  856. // TODO: Maybe a setting to where we only show undergrad courses in this special group?
  857. $group->list_courses = $fp->get_all_courses_in_catalog_year(variable_get_for_school("current_catalog_year", '', $school_id),FALSE,0,0,$school_id, FALSE);
  858. $group->title = t("Add an Additional Course");
  859. $group->list_courses->assign_group_id($group_id);
  860. $group->list_courses->load_course_descriptive_data();
  861. }
  862. if ($course_id != "") {
  863. // Meaning, a course_id was specified, so make sure
  864. // it is "selected" inside the group and branches.
  865. $course = new Course();
  866. $course->course_id = $course_id;
  867. $course->req_by_degree_id = $req_by_degree_id;
  868. // TODO: Right here, do we need to limit by degree id? Probably...
  869. $temp_course_list = $group->find_courses($course);
  870. if (!$temp_course_list) {
  871. $temp_course_list = $degree_plan->find_courses($course_id, $group_id, $semester_num);
  872. }
  873. if ($temp_course_list) {
  874. $temp_course_list->reset_counter();
  875. while($temp_course_list->has_more()) {
  876. $temp_course = $temp_course_list->get_next();
  877. $temp_course->bool_selected = true;
  878. //$temp_course->assigned_to_semester_num = $semester_num;
  879. }
  880. }
  881. }
  882. if ($perform_action2 == "" || $perform_action2 == "select") {
  883. if ($group) {
  884. $rtn .= $screen->display_popup_group_select($group, $group_hours_remaining, $req_by_degree_id);
  885. }
  886. // Create the tabs for the page...
  887. $tab_array = array();
  888. $tab_array[0]["title"] = "Description";
  889. $tab_array[0]["on_click"] = "popupDescribeSelected(\"$group_id\",\"$semester_num\",\"0\",\"\",\"req_by_degree_id=$req_by_degree_id&group_hours_remaining=$group_hours_remaining&blank_degree_id=$blank_degree_id\");";
  890. $tab_array[1]["title"] = "Select";
  891. $tab_array[1]["active"] = true;
  892. // If we are allowed to substitute....
  893. if (user_has_permission("can_substitute") && $group_id != DegreePlan::GROUP_ID_FOR_COURSES_ADDED && !$screen->bool_blank) {
  894. $tab_array[2]["title"] = "Substitute";
  895. $tab_array[2]["on_click"] = "popupSubstituteSelected(\"0\",\"$group_id\",\"$semester_num\",\"$req_by_degree_id\",\"group_hours_remaining=$group_hours_remaining\");";
  896. }
  897. }
  898. if ($perform_action2 == "describe_course") {
  899. $rtn .= $screen->display_popup_course_description($course_id,null,$group, true);
  900. // Create the tabs for the page...
  901. $tab_array = array();
  902. $tab_array[0]["title"] = "Description";
  903. $tab_array[0]["active"] = true;
  904. $tab_array[1]["title"] = "Select";
  905. $subject = trim($_GET["selected_subject"]);
  906. $use_course_id = $course_id;
  907. // if we are unable to advise due to a prereq, then set use_course_id to an invalid course id (so nothing is selected when we change tabs)
  908. if (isset($GLOBALS['prereqs_no_advise_course_id']) && in_array($course_id, $GLOBALS['prereqs_no_advise_course_id'])) {
  909. $use_course_id = 0;
  910. }
  911. $tab_array[1]["on_click"] = "popupBackToGroupSelect(\"$use_course_id\",\"$group_id\",\"$semester_num\",\"req_by_degree_id=$req_by_degree_id&selected_subject=$subject&group_hours_remaining=$group_hours_remaining&blank_degree_id=$blank_degree_id\");";
  912. // If we are allowed to substitute....
  913. if (user_has_permission("can_substitute") && $group_id != DegreePlan::GROUP_ID_FOR_COURSES_ADDED && !$screen->bool_blank) {
  914. $tab_array[2]["title"] = "Substitute";
  915. $tab_array[2]["on_click"] = "popupSubstituteSelected(\"$course_id\",\"$group_id\",\"$semester_num\",\"$req_by_degree_id\",\"group_hours_remaining=$group_hours_remaining\");";
  916. }
  917. }
  918. if ($tab_array) {
  919. fp_set_page_tabs($tab_array);
  920. }
  921. return $rtn;
  922. }
  923. function advise_display_popup_substitute_selected() {
  924. global $current_student_id, $fp, $screen;
  925. $rtn = "";
  926. $school_id = db_get_school_id_for_student_id($current_student_id);
  927. advise_init_screen();
  928. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  929. $sub_decimals_allowed = variable_get_for_school("sub_hours_decimals_allowed", 2, $school_id);
  930. // Add our allowed substitution decimals as a js setting for later use.
  931. fp_add_js(array("subDecimalsAllowed" => $sub_decimals_allowed), "setting");
  932. $course_id = trim(@$_GET["course_id"]);
  933. $group_id = trim(addslashes(@$_GET["group_id"]));
  934. $semester_num = trim(addslashes(@$_GET["semester_num"]));
  935. $req_by_degree_id = trim(addslashes(@$_GET["req_by_degree_id"]));
  936. $hours_avail = trim(addslashes(@$_GET["group_hours_remaining"]));
  937. if (@$_GET["hours_avail"] * 1 > 0) {
  938. $hours_avail = $_GET["hours_avail"] * 1;
  939. }
  940. $rtn .= "<div class='tenpt'><a href='javascript:history.go(-1);' class='nounderline'>&laquo; " . t("return to course selection") . "</a></div>";
  941. $rtn .= $screen->display_popup_substitute($course_id, $group_id, $semester_num, $hours_avail, $req_by_degree_id);
  942. watchdog("advise", "display_popup_substitute_selected $current_student_id", array(), WATCHDOG_DEBUG);
  943. return $rtn;
  944. }
  945. function advise_display_popup_course_description() {
  946. global $current_student_id, $screen;
  947. $rtn = "";
  948. advise_init_screen();
  949. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  950. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  951. $data_string = trim($_GET["data_string"]);
  952. $course = new Course();
  953. if ($data_string != "")
  954. {
  955. $course->load_course_from_data_string($data_string);
  956. }
  957. $req_by_degree_id = $course->req_by_degree_id;
  958. // Save the max hours from the data string here. This is to fix a bug where we didn't keep track
  959. // of a course's remainder from a split substitution. Due to pass-by-reference, it gets reset
  960. // in the display_popup_course_description function.
  961. $datastring_max_hours = $course->max_hours;
  962. $rtn .= $screen->display_popup_course_description("", $course);
  963. // Create the tabs for the page...
  964. $tab_array = array();
  965. $tab_array[0]["title"] = "Description";
  966. $tab_array[0]["active"] = true;
  967. if (user_has_permission("can_substitute") && !$screen->bool_blank && intval($course->get_first_assigned_to_group_id()) != DegreePlan::GROUP_ID_FOR_COURSES_ADDED) {
  968. if ($course->get_bool_substitution() != TRUE && $course->grade == "") {
  969. // By checking grade, we are making sure this course has NOT already
  970. // been taken by the student. In other words, verify that this course
  971. // is an unfulfilled requirement on the degree plan ONLY.
  972. $extra_vars = "hours_avail=$datastring_max_hours";
  973. $tab_array[1]["title"] = "Substitute";
  974. $tab_array[1]["on_click"] = "popupSubstituteSelected(\"$course->course_id\",\"" . $course->get_first_assigned_to_group_id() . "\",\"$course->assigned_to_semester_num\",\"$req_by_degree_id\",\"$extra_vars\");";
  975. }
  976. }
  977. fp_set_page_tabs($tab_array);
  978. //$screen->page_tabs = $screen->draw_tabs($tab_array);
  979. return $rtn;
  980. }
  981. /**
  982. * Implementation of hook_perm
  983. */
  984. function advise_perm() {
  985. $perms = array();
  986. $perms["view_any_advising_session"] = array(
  987. "title" => t("View any advising session"),
  988. "description" => t("The user is allowed to view any advising sessions for any user.
  989. For example, the user is an advisor."),
  990. );
  991. $perms["view_advisee_advising_session"] = array(
  992. "title" => t("View advisee advising sessions"),
  993. "description" => t("The user is allowed to view their assigned advisee's advising sessions.
  994. For example, the user is a limited advisor with advisees assigned."),
  995. );
  996. $perms["view_own_advising_session"] = array(
  997. "title" => t("View own advising session"),
  998. "description" => t("The user is allowed to view their own advising sessions.
  999. For example, the user is a student."),
  1000. );
  1001. $perms["can_delete_own_advising_session_3_months"] = array(
  1002. "title" => t("Can delete advising session for 3 months (faculty/staff only)"),
  1003. "description" => t("The faculty/staff user may delete advising sessions they have made for up to 3 months. After 3 months, they
  1004. will not be able to delete the advising session. <strong>Note: The user must also have the 'Can advise students' permission as well.</strong>"),
  1005. );
  1006. $perms["can_advise_students"] = array(
  1007. "title" => t("Can advise students"),
  1008. "description" => t("The user is allowed to advise other students,
  1009. by clicking a checkbox next to a course, or by selecting
  1010. a course from an elective group."),
  1011. );
  1012. $perms["can_substitute"] = array(
  1013. "title" => t("Can substitute"),
  1014. "description" => t("The user is allowed to substitute courses on a student's
  1015. degree plan."),
  1016. );
  1017. $perms["toggle_draft"] = array(
  1018. "title" => t("Toggle draft mode"),
  1019. "description" => t("The user toggle 'draft' mode, so they can view draft degree plans
  1020. in FlightPath."),
  1021. );
  1022. return $perms;
  1023. }
  1024. /**
  1025. * This is the page which actually displays the "view" for the user
  1026. * to see their advising session, or for an advisor to advise them.
  1027. *
  1028. */
  1029. function advise_display_view($view = "view") {
  1030. global $user, $fp, $degree_plan, $screen, $current_student_id;
  1031. $rtn = "";
  1032. // Do we need to rebuild the course inventory cache?
  1033. if (system_check_course_inventory_should_be_reloaded()) {
  1034. system_reload_and_cache_course_inventory();
  1035. }
  1036. fp_set_title('');
  1037. if ($view == "what-if") {
  1038. $GLOBALS["fp_advising"]["advising_what_if"] = "yes";
  1039. $_REQUEST["advising_what_if"] = "yes";
  1040. }
  1041. else {
  1042. $GLOBALS["fp_advising"]["advising_what_if"] = "no";
  1043. $_REQUEST["advising_what_if"] = "no";
  1044. }
  1045. // Initialize everything we need to initialize for this advising session.
  1046. advise_init_screen();
  1047. $render = array();
  1048. $render['#id'] = 'advise_display_view';
  1049. $render['#view'] = $view;
  1050. $render['#fp'] = $fp;
  1051. $render['#degree_plan'] = $degree_plan;
  1052. $render['#screen'] = $screen;
  1053. $render['#current_student_id'] = $current_student_id;
  1054. $school_id = db_get_school_id_for_student_id($current_student_id);
  1055. // Add some body classes to the page for this student.
  1056. $student = $screen->student;
  1057. if (is_object($student)) {
  1058. fp_add_body_class("student-rank-$student->db_rank student-catalog-year-$student->catalog_year");
  1059. }
  1060. $render['#student'] = $student;
  1061. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  1062. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  1063. // If we are on a print screen, we need to go out of our
  1064. // way to set the screen mode, so we don't display certain things
  1065. // when we go to draw the screen.
  1066. if (strstr($_REQUEST["q"], "/print")) {
  1067. $screen->bool_print = TRUE;
  1068. $screen->screen_mode = "not_advising";
  1069. }
  1070. if ($GLOBALS["fp_advising"]["advising_what_if"] == "yes" && $GLOBALS["fp_advising"]["what_if_major_code"] == "") {
  1071. // We are in WhatIf, but we have not selected a major, so give
  1072. // the user a selection screen.
  1073. $screen->screen_mode = "not_advising";
  1074. // If graduate degree selection is allowed for graduate students, then change bool_undergrad_only to FALSE.
  1075. // (if the student is a grad student!)
  1076. $bool_undergrad_only = TRUE;
  1077. $grad_level_codes = csv_to_array(variable_get_for_school("graduate_level_codes", "GR", $school_id));
  1078. if (in_array($student->db_rank, $grad_level_codes)) {
  1079. $bool_undergrad_only = FALSE;
  1080. }
  1081. // Check school setting: should we show all (both grad and undergrad) degrees on What If?
  1082. // This will overwrite the logic above.
  1083. if (variable_get_for_school('show_both_undergrad_and_grad_degrees_in_what_if', 'no', $school_id) == 'yes') {
  1084. $bool_undergrad_only = FALSE;
  1085. }
  1086. $render['#bool_undergrad_only'] = $bool_undergrad_only;
  1087. $render['whatif_selection_form'] = array(
  1088. 'value' => fp_render_form("advise_what_if_selection_form", "", $bool_undergrad_only),
  1089. 'weight' => 100,
  1090. );
  1091. //$rtn .= fp_render_form("advise_what_if_selection_form", "", $bool_undergrad_only);
  1092. }
  1093. else {
  1094. // This is a normal advising screen. Either View or WhatIf.
  1095. //$page_content .= $screen->display_view_options();
  1096. $screen->build_screen_elements();
  1097. $form_token = md5("advise_display_view" . fp_token());
  1098. $vurl = fp_url($view);
  1099. $render['degree_plan_wrapper_top'] = array(
  1100. 'value' => "<div class='degree-plan-wrapper'>
  1101. <form id='mainform' method='POST' action='$vurl'>
  1102. <input type='hidden' name='form_token' value='$form_token'>
  1103. <table class='fp-semester-table'>",
  1104. 'weight' => 200,
  1105. );
  1106. /*
  1107. $rtn .= "<div class='degree-plan-wrapper'>
  1108. <form id='mainform' method='POST' action='$vurl'>
  1109. <input type='hidden' name='form_token' value='$form_token'>
  1110. <table class='fp-semester-table'>";
  1111. */
  1112. $render['display_screen'] = array(
  1113. 'value' => $screen->display_screen(),
  1114. 'weight' => 300,
  1115. );
  1116. //$rtn .= $screen->display_screen();
  1117. $render['semester_table_close'] = array(
  1118. 'value' => "</table>",
  1119. 'weight' => 350,
  1120. );
  1121. //$rtn .= "</table>";
  1122. // Add in the required "advising variables"
  1123. $render['hidden_advising_variables'] = array(
  1124. 'value' => $screen->get_hidden_advising_variables("save_draft"),
  1125. 'weight' => 400,
  1126. );
  1127. //$rtn .= $screen->get_hidden_advising_variables("save_draft");
  1128. $render['close_form_and_wrapper'] = array(
  1129. 'value' => "</form></div>",
  1130. 'weight' => 500,
  1131. );
  1132. //$rtn .= "</form>";
  1133. //$rtn .= "</div>"; // degree-plan-wrapper
  1134. // Figure out what the page's sub-tabs should be, and set them.
  1135. $tab_array = array();
  1136. $tab_array[1]["title"] = "Display by Year";
  1137. $tab_array[1]["active"] = ($screen->view != "type");
  1138. $tab_array[1]["on_click"] = "changeView(\"year\");";
  1139. $tab_array[2]["title"] = "Display by Type";
  1140. $tab_array[2]["active"] = ($screen->view == "type");
  1141. $tab_array[2]["on_click"] = "changeView(\"type\");";
  1142. if ($view == 'what-if') {
  1143. //$what_if_select = "<span class='what-if-change-settings'>" . l("<i class='fa fa-cog'></i> " . t("Change Settings"), "what-if", "advising_what_if=yes&what_if_major_code=none&what_if_track_code=none&what_if_track_degree_ids=none&current_student_id=$current_student_id") . "</span>";
  1144. $tab_array[3]["label"] = "\"What If?\" Mode";
  1145. $tab_array[3]['text'] = "<i class='fa fa-pencil'></i>";
  1146. $tab_array[3]['link_title'] = "Change What If settings?";
  1147. $tab_array[3]['link_class'] = "change-what-if-link";
  1148. $tab_array[3]["type"] = "link";
  1149. $tab_array[3]["active"] = FALSE;
  1150. $tab_array[3]["on_click"] = "window.location=\"" . fp_url('what-if', "advising_what_if=yes&what_if_major_code=none&what_if_track_code=none&what_if_track_degree_ids=none&current_student_id=$current_student_id") . "\";";
  1151. }
  1152. $advising_term_id = @$GLOBALS["fp_advising"]["advising_term_id"];
  1153. if ($advising_term_id != "" && user_has_permission("can_advise_students")) {
  1154. // If this is someone who is allowed to change terms. (advisor or above)
  1155. $t_term_id = $advising_term_id;
  1156. $for_term = " " . t("for") . " ";
  1157. $termdesc = get_term_description($t_term_id, FALSE, $school_id);
  1158. $furl = fp_url("advise/popup-change-term");
  1159. $tab_array[4]["label"] = "Advising Term: $termdesc ($t_term_id)";
  1160. $tab_array[4]['text'] = "<i class='fa fa-pencil'></i>";
  1161. $tab_array[4]['link_title'] = "Change term?";
  1162. $tab_array[4]['link_class'] = "change-term-link";
  1163. $tab_array[4]["type"] = "link";
  1164. $tab_array[4]["active"] = FALSE;
  1165. $tab_array[4]["on_click"] = "popupSmallIframeDialog(\"" . $furl . "\",\"" . t('Select an Advising Term') . "\",\"advising_term_id=$t_term_id\");";
  1166. }
  1167. fp_set_page_sub_tabs($tab_array);
  1168. watchdog("view_by_$screen->view", "$current_student_id", array());
  1169. }
  1170. // print_pre($student->list_courses_taken->toString());
  1171. // Should we re-cache the course inventory? If there have been any changes
  1172. // to it, then we will see that in a GLOBALS variable...
  1173. if (@$GLOBALS["cache_course_inventory"] == true) {
  1174. $_SESSION["fp_cache_course_inventory"] = serialize(@$GLOBALS["fp_course_inventory"]);
  1175. }
  1176. // Let's set our breadcrumbs
  1177. $db = get_global_database_handler();
  1178. $crumbs = array();
  1179. $crumbs[] = array(
  1180. 'text' => 'Students',
  1181. 'path' => 'student-search',
  1182. );
  1183. $crumbs[] = array(
  1184. 'text' => $db->get_student_name($screen->student->student_id) . " ({$screen->student->student_id})",
  1185. 'path' => 'student-profile',
  1186. 'query' => "current_student_id={$screen->student->student_id}",
  1187. );
  1188. fp_set_breadcrumbs($crumbs);
  1189. return fp_render_content($render);
  1190. //return $rtn;
  1191. }
  1192. function advise_what_if_selection_form($bool_undergrad_only = TRUE) {
  1193. global $screen, $current_student_id;
  1194. if ($screen && $screen->bool_print) {
  1195. return array();
  1196. }
  1197. fp_add_js(fp_get_module_path("advise") . "/js/advise.what-if-selection.js");
  1198. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  1199. $student_school_id = intval(db_get_school_id_for_student_id($current_student_id));
  1200. $form = array();
  1201. $m = 0;
  1202. fp_set_title(""); // Remove the default form's title
  1203. $db = get_global_database_handler();
  1204. $major_codes = array();
  1205. $form["mark" . $m++] = array(
  1206. "value" => fp_render_section_title("What if I change my degree to...") . "<br>",
  1207. );
  1208. $catalog_year = variable_get_for_school("current_catalog_year", 0, $student_school_id);
  1209. $current_catalog_year = $catalog_year; // keep track of what the current catalog year is.
  1210. $earliest_catalog_year = intval(variable_get_for_school("earliest_catalog_year", 2006, $student_school_id));
  1211. // Use the student's catalog year, based on a setting instead?
  1212. if (variable_get_for_school("what_if_catalog_year_mode", "current", $student_school_id) == "student") {
  1213. $db = get_global_database_handler();
  1214. $catalog_year = $db->get_student_catalog_year($current_student_id);
  1215. }
  1216. $form["mark_cat_year"] = array(
  1217. "value" => "<div class='mark-select-from-cat-year'>" . t("Please select from the %cat catalog year:", array("%cat" => $catalog_year . "-" . ($catalog_year+1))) . "</div>",
  1218. );
  1219. // We cannot go beyond the current catalog year, so if the catalog_year is now > than current, we must stop
  1220. // the user.
  1221. if ($catalog_year > $current_catalog_year || $catalog_year < $earliest_catalog_year) {
  1222. $form["mark_cat_year_past_current"] = array(
  1223. "value" => "<p class='cat-year-past-current'>" . t("Sorry, but the catalog year %cat is not available yet within
  1224. FlightPath. Please speak with your adviser about how to proceed
  1225. with advising.", array("%cat" => $catalog_year . "-" . ($catalog_year+1))) . "</p>",
  1226. );
  1227. return $form;
  1228. }
  1229. $form["catalog_year"] = array(
  1230. "type" => "hidden",
  1231. "value" => $catalog_year,
  1232. );
  1233. $bool_use_draft = FALSE; // leave as false for now. Because you can't select
  1234. // degree options, and if you click submit it really does
  1235. // save it. Better to just use blank degrees.
  1236. $c = 100;
  1237. /////////////////////
  1238. // Select a major....
  1239. $options = array();
  1240. if ($degree_array = $db->get_degrees_in_catalog_year($catalog_year, FALSE, $bool_use_draft, $bool_undergrad_only, array(1), $student_school_id)) {
  1241. foreach($degree_array as $major_code => $value) {
  1242. if (trim($value["title"]) == ""){continue;}
  1243. $options[$major_code] = $value["title"];
  1244. $major_codes[$major_code] = $major_code;
  1245. }
  1246. }
  1247. // Place in a fieldset...
  1248. $e1["select_level_1_degrees"] = array(
  1249. "type" => "checkboxes",
  1250. "label" => "",
  1251. "options" => $options,
  1252. );
  1253. $form["cfieldset_level_1"] = array(
  1254. "type" => "cfieldset",
  1255. "label" => "Select Major &raquo;",
  1256. "elements" => array($e1),
  1257. "start_closed" => FALSE,
  1258. );
  1259. /////////////////////////
  1260. // Select a minor....
  1261. $options = array();
  1262. if ($degree_array = $db->get_degrees_in_catalog_year($catalog_year, FALSE, $bool_use_draft, $bool_undergrad_only, array(2), $student_school_id)) {
  1263. foreach($degree_array as $major_code => $value) {
  1264. if (trim($value["title"]) == ""){continue;}
  1265. $options[$major_code] = $value["title"];
  1266. $major_codes[$major_code] = $major_code;
  1267. }
  1268. }
  1269. if (count($options) > 0) {
  1270. $e2["select_level_2_degrees"] = array(
  1271. "type" => "checkboxes",
  1272. "label" => "",
  1273. "options" => $options,
  1274. );
  1275. $form["cfieldset_level_2"] = array(
  1276. "type" => "cfieldset",
  1277. "label" => "Select Minor &raquo;",
  1278. "elements" => array($e2),
  1279. );
  1280. }
  1281. /////////////////////
  1282. // All the tracks...
  1283. if (variable_get_for_school("show_level_3_on_what_if_selection", "yes", $student_school_id) == 'yes') {
  1284. foreach ($major_codes as $major_code => $temp) {
  1285. // Let's see if this major has any tracks...
  1286. if ($tracks = $db->get_degree_tracks($major_code, $catalog_year, $student_school_id)) {
  1287. // Let's load the original degree plan.
  1288. $degree_plan = $db->get_degree_plan($major_code, $catalog_year, TRUE, $student_school_id);
  1289. $degree_plan->load_degree_plan_ancillary();
  1290. // Yes, there are indeed tracks for THIS major. Let's load them up...
  1291. // First, organize them by degree_class...
  1292. $tracks_by_class = array();
  1293. foreach ($tracks as $track) {
  1294. $t_degree_plan = $db->get_degree_plan($major_code . "|_" . $track, $catalog_year, TRUE, $student_school_id);
  1295. $t_degree_plan->load_degree_plan_ancillary();
  1296. $degree_class = trim($t_degree_plan->degree_class);
  1297. if ($degree_class) {
  1298. $tracks_by_class[$degree_class][] = $t_degree_plan;
  1299. }
  1300. }
  1301. // Now, create the form element...
  1302. foreach ($tracks_by_class as $degree_class => $c) {
  1303. $options = array();
  1304. $temp = fp_get_degree_classification_details($degree_class);
  1305. $class_title = $temp["title"];
  1306. // Are there any special requirements or defaults for this degree_class selection?
  1307. $tsca = $degree_plan->track_selection_config_array;
  1308. $default_tracks_array = @csv_to_array($tsca[$degree_class]["default_tracks"]);
  1309. $min_tracks = @intval($tsca[$degree_class]["min_tracks"]);
  1310. $max_tracks = @intval($tsca[$degree_class]["max_tracks"]);
  1311. $element_type = "checkboxes";
  1312. $element_value = array();
  1313. // If we require exactly 1 selection, then make this a radio button, and pre-select either the first element
  1314. // or the first default track.
  1315. if ($min_tracks == 1 && $max_tracks == 1) {
  1316. $element_type = "radios";
  1317. $element_value = array($default_tracks_array[0] => $default_tracks_array[0]);
  1318. }
  1319. // Actually build up the options...
  1320. foreach ($tracks_by_class[$degree_class] as $t_degree_plan) {
  1321. //$degree_id = $t_degree_plan->degree_id;
  1322. $tmajor_code = "" . trim($t_degree_plan->major_code);
  1323. $options[$tmajor_code] = $t_degree_plan->get_title2(FALSE, TRUE);
  1324. if (trim($t_degree_plan->track_description) != "") {
  1325. $options[$tmajor_code] .= "<div class='what-if-selection-track-desc what-if-selection-track-desc-for-" . fp_get_machine_readable($tmajor_code) . "'
  1326. >" . $t_degree_plan->track_description . "</div>";
  1327. }
  1328. // Is this a "default" major code?
  1329. if (in_array(trim($tmajor_code), $default_tracks_array)) {
  1330. $element_value[$tmajor_code] = $tmajor_code; // make it be selected
  1331. }
  1332. }
  1333. $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-between'>Please select between $min_tracks and $max_tracks $class_title options.</div>";
  1334. if ($min_tracks == $max_tracks) {
  1335. $min_max_options = "<div class='advise-select-track-min-max advise-select-track-exact-number'>Please select $max_tracks $class_title options.</div>";
  1336. }
  1337. if ($min_tracks == $max_tracks && $max_tracks == 1) {
  1338. $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-exactly-one'>Please select 1 $class_title option.</div>";
  1339. }
  1340. if ($min_tracks > 0 && $max_tracks == 0) {
  1341. // Meaning, there is no maximum. It's infinite.
  1342. $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-at-least-one'>Please select at least $min_tracks $class_title option(s) for this degree.</div>";
  1343. }
  1344. if ($min_tracks == $max_tracks && $max_tracks == 0) {
  1345. $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-optional'>Optional: You are not required to select any additional $class_title options.</div>";
  1346. }
  1347. $form["L3__sel__{$degree_class}__for__{$major_code}__xx"] = array( //ends with xx so we can be sure when the major code ends.
  1348. "type" => $element_type,
  1349. "label" => "Select $class_title for " . $degree_plan->get_title2(),
  1350. "options" => $options,
  1351. "description" => "$min_max_options",
  1352. "value" => $element_value,
  1353. );
  1354. // Save min and max options for quick look-up later.
  1355. $form["L3__ops__{$degree_class}__for__{$major_code}__xx"] = array(
  1356. "type" => "hidden",
  1357. "value" => "$min_tracks~$max_tracks",
  1358. );
  1359. }
  1360. } // if tracks
  1361. } // foreach major codes
  1362. } // if level-3 selection...
  1363. $form["submit_btn"] = array(
  1364. "value" => "<div align='right'>
  1365. " . fp_render_button("Try It Out!", "showUpdate(true);$(\"#fp-form-advise_what_if_selection_form\").submit(); ") . "
  1366. </div>",
  1367. );
  1368. $form["current_student_id"] = array(
  1369. "type" => "hidden",
  1370. "value" => $current_student_id,
  1371. );
  1372. watchdog("advise", "what_if_selection_form $current_student_id", array());
  1373. return $form;
  1374. }
  1375. /**
  1376. * Validate handler for the what_if selection form. This is where we might, for example, make sure
  1377. * that if a non-dynamic degree was selected, that they can't proceed.
  1378. */
  1379. function advise_what_if_selection_form_validate($form, &$form_state) {
  1380. $catalog_year = $form_state['values']['catalog_year'];
  1381. $current_student_id = $form_state['values']['current_student_id'];
  1382. $school_id = db_get_school_id_for_student_id($current_student_id);
  1383. // Make sure they selected at least 1 level 1 degree.
  1384. $selected_degrees = array();
  1385. $temp = FALSE;
  1386. foreach (array(1,2) as $num) {
  1387. if (isset($form_state["values"]["select_level_{$num}_degrees"]) && is_array($form_state["values"]["select_level_{$num}_degrees"])) {
  1388. foreach ($form_state["values"]["select_level_{$num}_degrees"] as $k => $v) {
  1389. if ((string)$k === (string)$v && $k != "") {
  1390. $temp = TRUE;
  1391. $selected_degrees[$k] = $v;
  1392. }
  1393. }
  1394. }
  1395. }
  1396. if (!$temp) {
  1397. form_error("select_level_1_degrees", t("Sorry, you must select at least one top-level degree to proceed. Please try again."));
  1398. return;
  1399. }
  1400. $db = get_global_database_handler();
  1401. // If a non-dynamic degree was selected, along with anything else, the user may not proceed.
  1402. if (count($selected_degrees) > 1) {
  1403. foreach ($selected_degrees as $major_code) {
  1404. $temp = $db->get_degree_plan($major_code, $catalog_year, TRUE);
  1405. if (is_object($temp) && intval($temp->db_allow_dynamic) != 1) {
  1406. $temp->load_descriptive_data();
  1407. // meaning, we have selected more than one degree, and at least THIS degree does NOT allow for dynamic recombination. So, reject it!
  1408. form_error("select_level_1_degrees", t("Sorry, but the degree you selected, %deg, does not allow you to combine it with any other degree.
  1409. It must be selected by itself. Please alter your selection and try again.", array("%deg"=> $temp->get_title2())));
  1410. return;
  1411. }
  1412. }
  1413. }
  1414. /////////////////////////
  1415. // Make sure they selected appropriate number of required tracks, if any.
  1416. $selected_tracks = 0; // just used to keep up with how many we are selecting.
  1417. // Begin by going through each track which was selected, and keep track of how many we selected.
  1418. $selected_for = array();
  1419. foreach ($form_state["values"] as $key => $val) {
  1420. if (strstr($key, "L3__sel__")) {
  1421. // L3_sel_{$degree_class}_for_{$major_code}_xx
  1422. $temp = explode("__", $key);
  1423. $degree_class = $temp[2];
  1424. $major_code = $temp[4];
  1425. if (!isset($selected_for[$major_code . "__" . $degree_class])) {
  1426. $selected_for[$major_code . "__" . $degree_class] = 0;
  1427. }
  1428. if (is_array($val)) { // In other words, this was a group of checkboxes.
  1429. foreach ($val as $k => $v) {
  1430. // Did the user select an item? Val's key and value will be identical if so.
  1431. if ($k == $v && $k != "") {
  1432. // YES. It was selected!
  1433. $selected_for[$major_code . "__" . $degree_class]++;
  1434. }
  1435. }
  1436. } // if is_array (val)
  1437. else if (is_string($val) && trim($val) != ""){
  1438. // Not an array-- was a radio list? So, this was a selection.
  1439. $selected_for[$major_code . "__" . $degree_class]++;
  1440. }
  1441. }
  1442. }
  1443. // Okay, now that we know how many were selected, let's make sure that the number falls within
  1444. // our min/max range for those tracks.
  1445. foreach ($form_state["values"] as $key => $val) {
  1446. if (!strstr($key, "L3__sel__")) { continue; }
  1447. $temp = explode("__", $key);
  1448. $degree_class = $temp[2];
  1449. $major_code = $temp[4];
  1450. $count = @intval($selected_for[$major_code . "__" . $degree_class]);
  1451. //First, make sure it's top-level degree was even selected. If it wasn't, skip it, it doesn't matter.
  1452. $temp = explode("|_", $major_code);
  1453. $top_level_code = trim($temp[0]);
  1454. if (@$form_state["values"]["select_level_1_degrees"][$top_level_code] != $top_level_code) {
  1455. if (@$form_state["values"]["select_level_2_degrees"][$top_level_code] != $top_level_code) {
  1456. continue;
  1457. }
  1458. }
  1459. // Okay, check to see if the count falls within the range for this degree & class.
  1460. $temp = explode("~", $form_state["values"]["L3__ops__{$degree_class}__for__{$major_code}__xx"]);
  1461. $min_tracks = @intval($temp[0]);
  1462. $max_tracks = @intval($temp[1]);
  1463. if ($count > $max_tracks && $max_tracks != 0) {
  1464. // We picked too many!
  1465. form_error("L3__sel__{$degree_class}__for__{$major_code}__xx", t("Sorry, you did not select the correct number of options for this degree."));
  1466. return;
  1467. }
  1468. if ($count < $min_tracks && $min_tracks > 0) {
  1469. // We picked too few!
  1470. form_error("L3__sel__{$degree_class}__for__{$major_code}__xx", t("Sorry, you did not select the correct number of options for this degree."));
  1471. return;
  1472. }
  1473. $selected_tracks += $count;
  1474. } // foreach
  1475. $total_selected = count($selected_degrees) + $selected_tracks;
  1476. // If this is more than what is allowed to be selected, then show error.
  1477. $max = intval(variable_get_for_school('max_allowed_selections_in_what_if', 5, $school_id));
  1478. if ($max === 0) $max = 5;
  1479. if ($total_selected > $max) {
  1480. form_error('', t("Sorry, you have exceeded the maximum number of allowed selections for What If. Please reduce your number of selections and try again."));
  1481. }
  1482. } //what_if_selection_form_validate
  1483. /**
  1484. * Submit handler for the what if selection form.
  1485. * Since at this point we have passed validation, let's just assemble the URL we need to now
  1486. * redirect to.
  1487. */
  1488. function advise_what_if_selection_form_submit($form, $form_state) {
  1489. $current_student_id = $form_state["values"]["current_student_id"];
  1490. $catalog_year = $form_state["values"]["catalog_year"];
  1491. // Get the major codes CSV
  1492. $what_if_major_code = "";
  1493. foreach (array(1, 2) as $num) {
  1494. if (isset($form_state["values"]["select_level_{$num}_degrees"]) && is_array($form_state["values"]["select_level_{$num}_degrees"])) {
  1495. foreach ($form_state["values"]["select_level_{$num}_degrees"] as $k => $v) {
  1496. if ((string)$k === (string)$v && $k != "") {
  1497. $what_if_major_code .= $k . ",";
  1498. }
  1499. }
  1500. }
  1501. }
  1502. // Add in the tracks, too, if selected.
  1503. foreach ($form_state["values"] as $key => $val) {
  1504. if (strstr($key, "L3__sel__")) {
  1505. if (is_array($val) && count($val) > 0) {
  1506. // Did the user select this item? Val's key and value will be identical if so.
  1507. foreach ($val as $k => $v) {
  1508. if ($k == $v && $k != "") {
  1509. // YES. It was selected!
  1510. //First, make sure it's top-level degree was even selected. If it wasn't, skip it, it doesn't matter.
  1511. $temp = explode("|_", $k);
  1512. $top_level_code = trim($temp[0]);
  1513. if (@$form_state["values"]["select_level_1_degrees"][$top_level_code] != $top_level_code) {
  1514. if (@$form_state["values"]["select_level_2_degrees"][$top_level_code] != $top_level_code) {
  1515. continue;
  1516. }
  1517. }
  1518. $what_if_major_code .= $k . ",";
  1519. }
  1520. }
  1521. } // if is_array val (cause it was a checkbox)
  1522. else if (is_string($val) && trim($val) != "") {
  1523. // This was from radio buttons.
  1524. //First, make sure it's top-level degree was even selected. If it wasn't, skip it, it doesn't matter.
  1525. $temp = explode("|_", $val);
  1526. $top_level_code = trim($temp[0]);
  1527. if (@$form_state["values"]["select_level_1_degrees"][$top_level_code] != $top_level_code) {
  1528. if (@$form_state["values"]["select_level_2_degrees"][$top_level_code] != $top_level_code) {
  1529. continue;
  1530. }
  1531. }
  1532. $what_if_major_code .= $val . ",";
  1533. }
  1534. }
  1535. }
  1536. // Remove training comma
  1537. $what_if_major_code = rtrim($what_if_major_code, ",");
  1538. // Okay, let's redirect the user to their proper destination
  1539. $query = "advising_what_if=yes&load_from_cache=no&window_mode=screen&current_student_id=$current_student_id&what_if_major_code=$what_if_major_code&what_if_catalog_year=$catalog_year";
  1540. fp_goto("what-if", $query);
  1541. }
  1542. /**
  1543. * Takes various variables from the REQUEST and stores them in our advising_session_variables table for more convenient use later on.
  1544. */
  1545. function advise_init_advising_variables($bool_ignore_what_if_variables = FALSE) {
  1546. global $user;
  1547. $vars = array();
  1548. $student = null;
  1549. // The current student ID is what we append to all session variables
  1550. // dealing with the current student. We do this so that we will
  1551. // keep session variables unique, so that we can have more than one
  1552. // window open at a time, with multiple students.
  1553. // Therefor, this should never go into the session.
  1554. // Annoyingly, we must pass carry this around on each page in the system.
  1555. $vars["current_student_id"] = @$_REQUEST["current_student_id"];
  1556. if ($vars["current_student_id"] == "")
  1557. {
  1558. $vars["current_student_id"] = @$_REQUEST["advising_student_id"];
  1559. }
  1560. $csid = $vars["current_student_id"];
  1561. $school_id = db_get_school_id_for_student_id($csid);
  1562. // Get the student ID.
  1563. $vars["advising_student_id"] = @$_REQUEST["advising_student_id"];
  1564. if ($vars["advising_student_id"] == "")
  1565. {
  1566. $vars["advising_student_id"] = @$_SESSION["advising_student_id$csid"];
  1567. if ($vars["advising_student_id"] == "")
  1568. { // Default value...
  1569. $vars["advising_student_id"] = $csid;
  1570. }
  1571. }
  1572. // Should we load from the Draft advising session? or the active?
  1573. $vars["advising_load_active"] = @$_REQUEST["advising_load_active"];
  1574. if ($vars["advising_load_active"] == "")
  1575. { // values will either be "yes" or "" (any other value than "yes" is
  1576. // considered to be negative.
  1577. // Default value...
  1578. $vars["advising_load_active"] = "";
  1579. }
  1580. // Are we currently in WhatIf mode?
  1581. @$vars["advising_what_if"] = $_REQUEST["advising_what_if"]; // Get it from the GET or POST.
  1582. if ($vars["advising_what_if"] == "")
  1583. {
  1584. // Will equal "yes" if we ARE in whatIf mode.
  1585. @$vars["advising_what_if"] = $_SESSION["advising_what_if$csid"];
  1586. if ($vars["advising_what_if"] == "")
  1587. {
  1588. // Default value:
  1589. $vars["advising_what_if"] = "no";
  1590. }
  1591. }
  1592. // Go ahead and set our GLOBALS variable for advising_what_if. It's needed when we load
  1593. // the $student variable.
  1594. $GLOBALS["fp_advising"]["advising_what_if"] = $vars["advising_what_if"];
  1595. // Get the major_code(s).
  1596. $vars["advising_major_code"] = @$_REQUEST["advising_major_code"];
  1597. if ($vars["advising_major_code"] == "")
  1598. {
  1599. $vars["advising_major_code"] = @$_SESSION["advising_major_code$csid"];
  1600. if ($vars["advising_major_code"] == "")
  1601. { // Default value...
  1602. if (!$student) $student = new Student($csid);
  1603. $vars["advising_major_code"] = $student->major_code_csv;
  1604. $_REQUEST["advising_major_code"] = $student->major_code_csv;
  1605. }
  1606. }
  1607. $vars["advising_track_degree_ids"] = @$_REQUEST["advising_track_degree_ids"];
  1608. if ($vars["advising_track_degree_ids"] == "")
  1609. {
  1610. $vars["advising_track_degree_ids"] = @$_SESSION["advising_track_degree_ids$csid"];
  1611. if ($vars["advising_track_degree_ids"] == "")
  1612. { // Default value...
  1613. if (!$student) $student = new Student($csid);
  1614. // Re-load the major codes, as the tracks might have changed.
  1615. $student->load_student_data();
  1616. $vars["advising_major_code"] = $student->major_code_csv;
  1617. }
  1618. }
  1619. // Update the student's settings?
  1620. $vars["advising_update_student_settings_flag"] = @$_REQUEST["advising_update_student_settings_flag"];
  1621. // Make it only come from the POST, for safety.
  1622. if ($vars["advising_update_student_settings_flag"] == "")
  1623. {
  1624. $vars["advising_update_student_settings_flag"] = @$_SESSION["advising_update_student_settings_flag$csid"];
  1625. if ($vars["advising_update_student_settings_flag"] == "")
  1626. { // Default value...
  1627. }
  1628. }
  1629. @$vars["advising_term_id"] = $_REQUEST["advising_term_id"]; // Get it from the GET or POST.
  1630. if ($vars["advising_term_id"] == "")
  1631. {
  1632. // Set to the default advising term.
  1633. @$vars["advising_term_id"] = $_SESSION["advising_term_id$csid"];
  1634. if ($vars["advising_term_id"] == "")
  1635. {
  1636. // default value:
  1637. $vars["advising_term_id"] = variable_get_for_school("advising_term_id", '', $school_id);
  1638. if ($vars["advising_term_id"] == "") {
  1639. // It's STILL blank?! Just use 0 then.
  1640. $vars["advising_term_id"] = "0";
  1641. }
  1642. }
  1643. }
  1644. @$vars["what_if_major_code"] = $_REQUEST["what_if_major_code"]; // Get it from the GET or POST.
  1645. if ($vars["what_if_major_code"] == "")
  1646. {
  1647. // Will equal "yes" if we ARE in whatIf mode.
  1648. @$vars["what_if_major_code"] = $_SESSION["what_if_major_code$csid"];
  1649. if ($vars["what_if_major_code"] == "")
  1650. {
  1651. // Default value:
  1652. $vars["what_if_major_code"] = "";
  1653. }
  1654. }
  1655. @$vars["what_if_catalog_year"] = $_REQUEST["what_if_catalog_year"]; // Get it from the GET or POST.
  1656. if ($vars["what_if_catalog_year"] == "")
  1657. {
  1658. @$vars["what_if_catalog_year"] = $_SESSION["what_if_catalog_year$csid"];
  1659. if ($vars["what_if_catalog_year"] == "")
  1660. {
  1661. // Default value:
  1662. $vars["what_if_catalog_year"] = "";
  1663. }
  1664. }
  1665. @$vars["what_if_track_degree_ids"] = $_REQUEST["what_if_track_degree_ids"]; // Get it from the GET or POST.
  1666. if ($vars["what_if_track_degree_ids"] == "")
  1667. {
  1668. // Will equal "yes" if we ARE in whatIf mode.
  1669. @$vars["what_if_track_degree_ids"] = $_SESSION["what_if_track_degree_ids$csid"];
  1670. if ($vars["what_if_track_degree_ids"] == "")
  1671. {
  1672. // Default value:
  1673. $vars["what_if_track_degree_ids"] = "";
  1674. }
  1675. }
  1676. if ($vars["what_if_major_code"] == "none")
  1677. {
  1678. $vars["what_if_major_code"] = "";
  1679. }
  1680. if ($vars["what_if_track_degree_ids"] == "none")
  1681. {
  1682. $vars["what_if_track_degree_ids"] = "";
  1683. }
  1684. if ($vars["advising_track_degree_ids"] == "none")
  1685. {
  1686. $vars["advising_track_degree_ids"] = "";
  1687. }
  1688. // Settings... (from the database)
  1689. $vars["setting_available_advising_term_ids"] = variable_get_for_school("available_advising_term_ids", '', $school_id);
  1690. $vars["setting_advising_term_id"] = variable_get_for_school("advising_term_id", '', $school_id);
  1691. $vars["setting_current_catalog_year"] = variable_get_for_school("current_catalog_year",'', $school_id);
  1692. $vars["setting_current_draft_catalog_year"] = variable_get_for_school("current_draft_catalog_year",'', $school_id);
  1693. // Are we in Print View?
  1694. @$vars["print_view"] = $_REQUEST["print_view"];
  1695. // Should we try to load from the cache?
  1696. @$vars["load_from_cache"] = $_REQUEST["load_from_cache"];
  1697. if ($vars["load_from_cache"] == "")
  1698. {
  1699. // By default, attempt to load from cache.
  1700. $vars["load_from_cache"] = "yes";
  1701. }
  1702. // What "view" are we in? View by Year or by Type?
  1703. // Not the same as printView. printView should work regardless
  1704. // of our advising_view.
  1705. @$vars["advising_view"] = $_REQUEST["advising_view"];
  1706. if ($vars["advising_view"] == "")
  1707. {
  1708. @$vars["advising_view"] = $_SESSION["advising_view$csid"];
  1709. }
  1710. // Place values into session.
  1711. $_SESSION["advising_student_id$csid"] = $vars["advising_student_id"];
  1712. $_SESSION["advising_student_id"] = $vars["advising_student_id"]; // used ONLY in the error report popup!
  1713. $_SESSION["advising_major_code$csid"] = $vars["advising_major_code"];
  1714. $_SESSION["advising_track_degree_ids$csid"] = $vars["advising_track_degree_ids"];
  1715. $_SESSION["advising_term_id$csid"] = $vars["advising_term_id"];
  1716. $_SESSION["advising_what_if$csid"] = $vars["advising_what_if"];
  1717. $_SESSION["what_if_major_code$csid"] = $vars["what_if_major_code"];
  1718. $_SESSION["what_if_catalog_year$csid"] = $vars["what_if_catalog_year"];
  1719. $_SESSION["what_if_track_degree_ids$csid"] = $vars["what_if_track_degree_ids"];
  1720. $_SESSION["advising_view$csid"] = $vars["advising_view"];
  1721. if ($bool_ignore_what_if_variables == true)
  1722. {
  1723. $vars["advising_what_if"] = "";
  1724. $vars["what_if_major_code"] = "";
  1725. $vars["what_if_catalog_year"] = "";
  1726. $vars["what_if_track_degree_ids"] = "";
  1727. }
  1728. // Are we in draft mode?
  1729. if ($_SESSION["fp_draft_mode"] == "yes")
  1730. {
  1731. $vars["bool_use_draft"] = true;
  1732. } else {
  1733. $vars["bool_use_draft"] = false;
  1734. }
  1735. $GLOBALS["fp_advising"] = $vars;
  1736. }
  1737. /**
  1738. * Implementation of hook_init
  1739. */
  1740. function advise_init() {
  1741. global $current_student_id, $user, $screen, $student, $degree_plan;
  1742. $current_student_id = @$_REQUEST["current_student_id"];
  1743. // Since this user doesn't have permission to view this student's sessions,
  1744. // he can only view his own. This is to stop hackers from experimenting with the URL
  1745. // to see other users' data.
  1746. if (!advise_can_access_view($current_student_id)) {
  1747. // Reset our global vars....
  1748. $current_student_id = "";
  1749. if (isset($user->cwid) && $user->is_student) {
  1750. $current_student_id = $user->cwid;
  1751. }
  1752. $_REQUEST["current_student_id"] = $current_student_id;
  1753. $_POST["current_student_id"] = $current_student_id;
  1754. $_GET["current_student_id"] = $current_student_id;
  1755. $_SESSION["current_student_id"] = $current_student_id;
  1756. $_REQUEST["advising_student_id"] = $current_student_id;
  1757. $_POST["advising_student_id"] = $current_student_id;
  1758. $_GET["advising_student_id"] = $current_student_id;
  1759. $_SESSION["advising_student_id"] = $current_student_id;
  1760. $GLOBALS["fp_advising"]["advising_student_id"] = $current_student_id;
  1761. $_REQUEST["advising_load_active"] = "yes";
  1762. }
  1763. if (!isset($_SESSION["fp_draft_mode"])) $_SESSION["fp_draft_mode"] = "";
  1764. // Is draft mode enabled?
  1765. if ($_SESSION["fp_draft_mode"] == "yes") {
  1766. fp_add_message("<b>" . t("Draft mode") . "</b> " . t("is currently enabled, however, substitutions and advisings will
  1767. still be saved normally."), "status", TRUE);
  1768. }
  1769. }
  1770. /**
  1771. * Implementation of hook_clear_cache
  1772. * Called by other modules, this function will take care of clearing
  1773. * anything this module has cached.
  1774. */
  1775. function advise_clear_cache() {
  1776. foreach ($_SESSION as $key => $value) {
  1777. if (strstr($key, "cache_")) {
  1778. $_SESSION[$key] = FALSE;
  1779. unset($_SESSION[$key]); // do this just to make sure our server-side session file gets overwritten
  1780. }
  1781. if (strstr($key, "advising_") || strstr($key, "what_if_")) {
  1782. $_SESSION[$key] = FALSE;
  1783. unset($_SESSION[$key]);
  1784. }
  1785. }
  1786. unset($_SESSION['fp_cache_course_inventory_last_generated']);
  1787. system_reload_and_cache_course_inventory();
  1788. unset($_SESSION["last_student_selected"]);
  1789. fp_add_message(t("Advising cache has been cleared."));
  1790. }
  1791. /**
  1792. * From menu hook. Clear just the advising cache.
  1793. *
  1794. */
  1795. function advise_perform_clear_advising_cache() {
  1796. advise_clear_cache();
  1797. fp_goto("<front>");
  1798. }
  1799. function advise_init_screen() {
  1800. global $degree_plan, $student, $fp, $window_mode, $user, $current_student_id, $screen;
  1801. $db = get_global_database_handler();
  1802. $faculty_id = $user->cwid;
  1803. // Insert our advising vars into the GLOBALS array for easy use later.
  1804. advise_init_advising_variables();
  1805. $perform_action = trim(addslashes(@$_REQUEST["perform_action"]));
  1806. if (@$_REQUEST["clear_session"] == "yes") {
  1807. //advise_save_advising_variables_to_db();
  1808. // reload our advising vars into the GLOBALS array for easy use later.
  1809. //$GLOBALS["fp_advising"] = advise_load_advising_variables_from_db($current_student_id, $user->id);
  1810. }
  1811. // Insert our advising vars into the GLOBALS array for easy use later.
  1812. //$GLOBALS["fp_advising"] = advise_load_advising_variables_from_db($current_student_id, $user->id);
  1813. $bool_what_if = false;
  1814. $csid = $current_student_id;
  1815. $cache = @$_SESSION["cache_fp$csid"];
  1816. if (@$GLOBALS["fp_advising"]["advising_what_if"] == "yes") {
  1817. $major_code = @$GLOBALS["fp_advising"]["what_if_major_code"];
  1818. $track_code = @$GLOBALS["fp_advising"]["what_if_track_code"];
  1819. $bool_what_if = true;
  1820. $cache = @$_SESSION["cache_what_if$csid"];
  1821. }
  1822. $bool_draft = true;
  1823. if (@$GLOBALS["fp_advising"]["advising_load_active"] == "yes") {
  1824. // If we are loading from Active, then rebuild the cache as well.
  1825. $bool_draft = false;
  1826. @$GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1827. }
  1828. $student_school_id = $db->get_school_id_for_student_id($csid);
  1829. ///////////////////////
  1830. /// Disable student data Caching....
  1831. //$GLOBALS["load_from_cache"] = "no";
  1832. // Attempt to load the course inventory cache...
  1833. if ($course_inventory = unserialize(@$_SESSION["fp_cache_course_inventory"])) {
  1834. $GLOBALS["fp_course_inventory"] = $course_inventory;
  1835. }
  1836. $bool_loaded = FALSE;
  1837. if ($GLOBALS["fp_advising"]["load_from_cache"] == "yes" && $cache != "" && $fp = unserialize($cache)) {
  1838. $bool_loaded = TRUE;
  1839. $fp->db = get_global_database_handler();
  1840. $student = $fp->student;
  1841. if ($student->student_id == "") $bool_loaded = FALSE;
  1842. $degree_plan = $fp->degree_plan;
  1843. $student->db = get_global_database_handler();
  1844. $degree_plan->db = get_global_database_handler();
  1845. }
  1846. if (!$bool_loaded) {
  1847. $fp = new FlightPath();
  1848. $fp->init();
  1849. $student = $fp->student;
  1850. $degree_plan = $fp->degree_plan;
  1851. $GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1852. $bool_loaded = TRUE;
  1853. }
  1854. // If the form has been saved, this token is expected. This protects
  1855. // against XSS attacks.
  1856. $form_token = md5("advise_display_view" . fp_token());
  1857. if ($perform_action == "save_draft") {
  1858. if ($_REQUEST["form_token"] != $form_token) {
  1859. die(t("Sorry, but you have encountered an error. A form submission was flagged
  1860. as possibly being an invalid or forged submission. This may constitute a bug
  1861. in the system. Please report this error to your Systems Administrator."));
  1862. }
  1863. // Save, then reload the student.
  1864. $adv_id_array = $fp->save_advising_session_from_post(0,true);
  1865. $bool_draft = TRUE; // load draft, since we just saved it (and changed something)
  1866. }
  1867. else if ($perform_action == "save_active") {
  1868. if ($_REQUEST["form_token"] != $form_token) {
  1869. die(t("Sorry, but you have encountered an error. A form submission was flagged
  1870. as possibly being an invalid or forged submission. This may constitute a bug
  1871. in the system. Please report this error to your Systems Administrator."));
  1872. }
  1873. // Save, then go to the history screen.
  1874. $adv_id_array = $fp->save_advising_session_from_post(0,false);
  1875. // Use an fp_goto command here to go to the History screen
  1876. // Serialize the adv_id_array so we can send it along in our fp_goto command...
  1877. $adv_id_serialized = serialize($adv_id_array);
  1878. fp_goto("history", "adv_id_array_serialized=" . urlencode($adv_id_serialized));
  1879. return;
  1880. }
  1881. // Is the user trying to view "by type" or by year?
  1882. if ($GLOBALS["fp_advising"]["advising_view"] == "type") {
  1883. $screen = new AdvisingScreenTypeView("", $fp);
  1884. $screen->view = "type";
  1885. }
  1886. else {
  1887. // Default advising view. "View by Year"
  1888. $screen = new AdvisingScreen("", $fp);
  1889. $screen->view = "year";
  1890. }
  1891. if (@$_REQUEST["bool_blank"] == "true" || @$_REQUEST["blank_degree_id"] != "") {
  1892. $screen->bool_blank = TRUE;
  1893. }
  1894. if ($bool_what_if == true && @$GLOBALS["fp_advising"]["what_if_major_code"] == "") {
  1895. // In other words, we are on the WhatIf tab, but we have not
  1896. // selected a major. So, just exit out. We will give the user
  1897. // a display_screen later.
  1898. return;
  1899. }
  1900. if (@$GLOBALS["fp_advising"]["load_from_cache"] != "yes") {
  1901. // do not load from cache.... load the student fresh....
  1902. // Only do if we need to re-init after save
  1903. if (@$_REQUEST['reinit_fp_after_draft_save'] == 'yes') {
  1904. $fp = new FlightPath();
  1905. $fp->init();
  1906. $student = $fp->student;
  1907. $degree_plan = $fp->degree_plan;
  1908. $GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1909. }
  1910. $student->load_student();
  1911. $student->load_student_substitutions();
  1912. $student->load_unassignments();
  1913. // Make sure we assign the freshly-loaded student, and re-establish all of our connections.
  1914. $fp->student = $student;
  1915. $screen->flightpath = $fp;
  1916. $screen->student = $fp->student;
  1917. $screen->degree_plan = $fp->degree_plan;
  1918. $fp->flag_outdated_substitutions();
  1919. $fp->assign_courses_to_semesters(); // bare degree plan. not groups.
  1920. $fp->assign_courses_to_groups();
  1921. ////////////
  1922. /*
  1923. // Good place to output a serialization, in case we need it for testing.
  1924. $student->name = "Test Student2";
  1925. $student->student_id = "123457";
  1926. $temp = serialize($screen);
  1927. file_put_contents(fp_get_files_path() . "/test.txt", $temp);
  1928. /////////////*/
  1929. }
  1930. else {
  1931. }
  1932. if (@$GLOBALS["fp_advising"]["save_to_cache"] != "no" && $window_mode != "popup") {
  1933. if ($bool_what_if == false) {
  1934. // NOT in whatIf mode. Normal.
  1935. $_SESSION["cache_fp$csid"] = serialize($fp);
  1936. }
  1937. else {
  1938. // We are in WhatIf mode.
  1939. $_SESSION["cache_what_if$csid"] = serialize($fp);
  1940. }
  1941. }
  1942. // If we are loading from draft, then load the faculty_id which saved draft last. If we are
  1943. // loading fresh, not from draft, then load *any* faculty that saved last.
  1944. $use_faculty_id = $faculty_id;
  1945. if (!$bool_draft) $use_faculty_id = 0;
  1946. // We shouldn't supply the advising_term_id, so that it will load all terms available.
  1947. $fp->load_advising_session_from_database($use_faculty_id,"",$bool_what_if,$bool_draft,0,$faculty_id);
  1948. // Once we have loaded the advising session, we should always try to load
  1949. // from draft from then on out.
  1950. $GLOBALS["fp_advising"]["advising_load_active"] = "";
  1951. }
  1952. /**
  1953. * This is a hook which developers may use to add custom blocks (or perform other operations)
  1954. * onto the advising View or What If screen.
  1955. *
  1956. * This is called AFTER the AdvisingScreen class has called it's build_screen_elements()
  1957. * function, which draws the various semester blocks, footnotes, etc, onto the screen.
  1958. *
  1959. * This gives other modules a chance to alter the screen, or to add a custom block to the
  1960. * bottom of the screen. Note that the $screen element is sent by reference. Any changes
  1961. * you make to it will be instant; there is no need to return anything.
  1962. *
  1963. * To see how these blocks are best set up, look at AdvisingScreen->build_excess_credit(), or
  1964. * AdvisingScreen->displaySemester() for inspiration.
  1965. *
  1966. * @param AdvisingScreen &$screen
  1967. */
  1968. function hook_advise_build_screen_elements(&$screen) {
  1969. $html = "";
  1970. $html .= $screen->draw_semester_box_top("Sample", TRUE); // pass TRUE to hide the "headers"
  1971. $html .= "<tr><td colspan='8'>"; // required after the top!
  1972. ////////////////
  1973. // The content...
  1974. $html .= "<b>Hello World!</b>";
  1975. ///////////////////
  1976. // All done, time to tidy up...
  1977. $html .= "</td></tr>"; // required before the bottom!
  1978. $html .= $screen->draw_semester_box_bottom();
  1979. // Add to the screen as a "semester block".
  1980. $screen->add_to_screen($html);
  1981. }

Functions

Namesort descending Description
advise_can_access_view Used by the menu to determine if the user can see the View (Degree and What If) tab for the current student.
advise_clear_cache Implementation of hook_clear_cache Called by other modules, this function will take care of clearing anything this module has cached.
advise_cron hook_cron
advise_display_popup_change_term This popup allows the advisor to change the advising term.
advise_display_popup_change_track
advise_display_popup_change_track_non_dynamic_degree This is the "change track" popup we will display if the degree cannot be combined with anything else (non-dynamic).
advise_display_popup_course_description
advise_display_popup_group_select
advise_display_popup_substitute_selected
advise_display_view This is the page which actually displays the "view" for the user to see their advising session, or for an advisor to advise them.
advise_get_advisees
advise_get_advising_sessions_for_advising_token Returns an array of advising session id's for the given advising token. Makes sure is_empty is 0 and is_draft is 0 Ordered by term_id DESC
advise_get_advising_session_from_advising_session_id Returns back the advising row from the database for a particular advising session id.
advise_get_advisors_for_student Similar to
advise_get_count_of_advised_course_for_term Returns back an integer of the number of times a particular course was advised (unique per student) for a certain term.
advise_get_count_of_enrolled_course_for_term Returns back an integer for the number of courses which a student was "enrolled" for a certain term. In this situation, we will not make sure the student is "active", since they may have since graduated or something.
advise_init Implementation of hook_init
advise_init_advising_variables Takes various variables from the REQUEST and stores them in our advising_session_variables table for more convenient use later on.
advise_init_screen
advise_menu
advise_perform_clear_advising_cache From menu hook. Clear just the advising cache.
advise_perm Implementation of hook_perm
advise_toggle_draft_form
advise_toggle_draft_form_submit
advise_user_can_view_advising_session_access_callback This is an access callback. Can the user view the advising session specified in the REQUEST?
advise_what_if_selection_form
advise_what_if_selection_form_submit Submit handler for the what if selection form. Since at this point we have passed validation, let's just assemble the URL we need to now redirect to.
advise_what_if_selection_form_validate Validate handler for the what_if selection form. This is where we might, for example, make sure that if a non-dynamic degree was selected, that they can't proceed.
hook_advise_build_screen_elements This is a hook which developers may use to add custom blocks (or perform other operations) onto the advising View or What If screen.