advise.module

  1. 6.x modules/advise/advise.module
  2. 7.x modules/advise/advise.module
  3. 4.x modules/advise/advise.module
  4. 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, TRUE);
  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. $render['#advising_term_id'] = $GLOBALS['fp_advising']['advising_term_id'];
  1055. $school_id = db_get_school_id_for_student_id($current_student_id);
  1056. // Add some body classes to the page for this student.
  1057. $student = $screen->student;
  1058. if (is_object($student)) {
  1059. fp_add_body_class("student-rank-$student->db_rank student-catalog-year-$student->catalog_year");
  1060. }
  1061. $render['#student'] = $student;
  1062. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  1063. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  1064. // If we are on a print screen, we need to go out of our
  1065. // way to set the screen mode, so we don't display certain things
  1066. // when we go to draw the screen.
  1067. if (strstr($_REQUEST["q"], "/print")) {
  1068. $screen->bool_print = TRUE;
  1069. $screen->screen_mode = "not_advising";
  1070. }
  1071. if ($GLOBALS["fp_advising"]["advising_what_if"] == "yes" && $GLOBALS["fp_advising"]["what_if_major_code"] == "") {
  1072. // We are in WhatIf, but we have not selected a major, so give
  1073. // the user a selection screen.
  1074. $screen->screen_mode = "not_advising";
  1075. // If graduate degree selection is allowed for graduate students, then change bool_undergrad_only to FALSE.
  1076. // (if the student is a grad student!)
  1077. $bool_undergrad_only = TRUE;
  1078. $grad_level_codes = csv_to_array(variable_get_for_school("graduate_level_codes", "GR", $school_id));
  1079. if (in_array($student->db_rank, $grad_level_codes)) {
  1080. $bool_undergrad_only = FALSE;
  1081. }
  1082. // Check school setting: should we show all (both grad and undergrad) degrees on What If?
  1083. // This will overwrite the logic above.
  1084. if (variable_get_for_school('show_both_undergrad_and_grad_degrees_in_what_if', 'no', $school_id) == 'yes') {
  1085. $bool_undergrad_only = FALSE;
  1086. }
  1087. $render['#bool_undergrad_only'] = $bool_undergrad_only;
  1088. $render['whatif_selection_form'] = array(
  1089. 'value' => fp_render_form("advise_what_if_selection_form", "", $bool_undergrad_only),
  1090. 'weight' => 100,
  1091. );
  1092. //$rtn .= fp_render_form("advise_what_if_selection_form", "", $bool_undergrad_only);
  1093. }
  1094. else {
  1095. // This is a normal advising screen. Either View or WhatIf.
  1096. //$page_content .= $screen->display_view_options();
  1097. $screen->build_screen_elements();
  1098. $form_token = md5("advise_display_view" . fp_token());
  1099. $vurl = fp_url($view);
  1100. $render['degree_plan_wrapper_top'] = array(
  1101. 'value' => "<div class='degree-plan-wrapper'>
  1102. <form id='mainform' method='POST' action='$vurl'>
  1103. <input type='hidden' name='form_token' value='$form_token'>
  1104. <table class='fp-semester-table'>",
  1105. 'weight' => 200,
  1106. );
  1107. /*
  1108. $rtn .= "<div class='degree-plan-wrapper'>
  1109. <form id='mainform' method='POST' action='$vurl'>
  1110. <input type='hidden' name='form_token' value='$form_token'>
  1111. <table class='fp-semester-table'>";
  1112. */
  1113. $render['display_screen'] = array(
  1114. 'value' => $screen->display_screen(),
  1115. 'weight' => 300,
  1116. );
  1117. //$rtn .= $screen->display_screen();
  1118. $render['semester_table_close'] = array(
  1119. 'value' => "</table>",
  1120. 'weight' => 350,
  1121. );
  1122. //$rtn .= "</table>";
  1123. // Add in the required "advising variables"
  1124. $render['hidden_advising_variables'] = array(
  1125. 'value' => $screen->get_hidden_advising_variables("save_draft"),
  1126. 'weight' => 400,
  1127. );
  1128. //$rtn .= $screen->get_hidden_advising_variables("save_draft");
  1129. $render['close_form_and_wrapper'] = array(
  1130. 'value' => "</form></div>",
  1131. 'weight' => 500,
  1132. );
  1133. //$rtn .= "</form>";
  1134. //$rtn .= "</div>"; // degree-plan-wrapper
  1135. // Figure out what the page's sub-tabs should be, and set them.
  1136. $tab_array = array();
  1137. $tab_array[1]["title"] = "Display by Year";
  1138. $tab_array[1]["active"] = ($screen->view != "type");
  1139. $tab_array[1]["on_click"] = "changeView(\"year\");";
  1140. $tab_array[2]["title"] = "Display by Type";
  1141. $tab_array[2]["active"] = ($screen->view == "type");
  1142. $tab_array[2]["on_click"] = "changeView(\"type\");";
  1143. if ($view == 'what-if') {
  1144. //$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>";
  1145. $tab_array[3]["label"] = "\"What If?\" Mode";
  1146. $tab_array[3]['text'] = "<i class='fa fa-pencil'></i>";
  1147. $tab_array[3]['link_title'] = "Change What If settings?";
  1148. $tab_array[3]['link_class'] = "change-what-if-link";
  1149. $tab_array[3]["type"] = "link";
  1150. $tab_array[3]["active"] = FALSE;
  1151. $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") . "\";";
  1152. }
  1153. $advising_term_id = @$GLOBALS["fp_advising"]["advising_term_id"];
  1154. if ($advising_term_id != "" && user_has_permission("can_advise_students")) {
  1155. // If this is someone who is allowed to change terms. (advisor or above)
  1156. $t_term_id = $advising_term_id;
  1157. $for_term = " " . t("for") . " ";
  1158. $termdesc = get_term_description($t_term_id, FALSE, $school_id);
  1159. $furl = fp_url("advise/popup-change-term");
  1160. $tab_array[4]["label"] = "Advising Term: $termdesc ($t_term_id)";
  1161. $tab_array[4]['text'] = "<i class='fa fa-pencil'></i>";
  1162. $tab_array[4]['link_title'] = "Change term?";
  1163. $tab_array[4]['link_class'] = "change-term-link";
  1164. $tab_array[4]["type"] = "link";
  1165. $tab_array[4]["active"] = FALSE;
  1166. $tab_array[4]["on_click"] = "popupSmallIframeDialog(\"" . $furl . "\",\"" . t('Select an Advising Term') . "\",\"advising_term_id=$t_term_id\");";
  1167. }
  1168. fp_set_page_sub_tabs($tab_array);
  1169. watchdog("view_by_$screen->view", "$current_student_id", array());
  1170. }
  1171. // print_pre($student->list_courses_taken->toString());
  1172. // Should we re-cache the course inventory? If there have been any changes
  1173. // to it, then we will see that in a GLOBALS variable...
  1174. if (@$GLOBALS["cache_course_inventory"] == true) {
  1175. $_SESSION["fp_cache_course_inventory"] = serialize(@$GLOBALS["fp_course_inventory"]);
  1176. }
  1177. // Let's set our breadcrumbs
  1178. $db = get_global_database_handler();
  1179. $crumbs = array();
  1180. $crumbs[] = array(
  1181. 'text' => 'Students',
  1182. 'path' => 'student-search',
  1183. );
  1184. $crumbs[] = array(
  1185. 'text' => $db->get_student_name($screen->student->student_id) . " ({$screen->student->student_id})",
  1186. 'path' => 'student-profile',
  1187. 'query' => "current_student_id={$screen->student->student_id}",
  1188. );
  1189. fp_set_breadcrumbs($crumbs);
  1190. return fp_render_content($render);
  1191. //return $rtn;
  1192. }
  1193. function advise_what_if_selection_form($bool_undergrad_only = TRUE) {
  1194. global $screen, $current_student_id;
  1195. if ($screen && $screen->bool_print) {
  1196. return array();
  1197. }
  1198. fp_add_js(fp_get_module_path("advise") . "/js/advise.what-if-selection.js");
  1199. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  1200. $student_school_id = intval(db_get_school_id_for_student_id($current_student_id));
  1201. $form = array();
  1202. $m = 0;
  1203. fp_set_title(""); // Remove the default form's title
  1204. $db = get_global_database_handler();
  1205. $major_codes = array();
  1206. $form["mark" . $m++] = array(
  1207. "value" => fp_render_section_title("What if I change my degree to...") . "<br>",
  1208. );
  1209. $catalog_year = variable_get_for_school("current_catalog_year", 0, $student_school_id);
  1210. $current_catalog_year = $catalog_year; // keep track of what the current catalog year is.
  1211. $earliest_catalog_year = intval(variable_get_for_school("earliest_catalog_year", 2006, $student_school_id));
  1212. // Use the student's catalog year, based on a setting instead?
  1213. if (variable_get_for_school("what_if_catalog_year_mode", "current", $student_school_id) == "student") {
  1214. $db = get_global_database_handler();
  1215. $catalog_year = $db->get_student_catalog_year($current_student_id);
  1216. }
  1217. $form["mark_cat_year"] = array(
  1218. "value" => "<div class='mark-select-from-cat-year'>" . t("Please select from the %cat catalog year:", array("%cat" => $catalog_year . "-" . ($catalog_year+1))) . "</div>",
  1219. );
  1220. // We cannot go beyond the current catalog year, so if the catalog_year is now > than current, we must stop
  1221. // the user.
  1222. if ($catalog_year > $current_catalog_year || $catalog_year < $earliest_catalog_year) {
  1223. $form["mark_cat_year_past_current"] = array(
  1224. "value" => "<p class='cat-year-past-current'>" . t("Sorry, but the catalog year %cat is not available yet within
  1225. FlightPath. Please speak with your adviser about how to proceed
  1226. with advising.", array("%cat" => $catalog_year . "-" . ($catalog_year+1))) . "</p>",
  1227. );
  1228. return $form;
  1229. }
  1230. $form["catalog_year"] = array(
  1231. "type" => "hidden",
  1232. "value" => $catalog_year,
  1233. );
  1234. $bool_use_draft = FALSE; // leave as false for now. Because you can't select
  1235. // degree options, and if you click submit it really does
  1236. // save it. Better to just use blank degrees.
  1237. $c = 100;
  1238. /////////////////////
  1239. // Select a major....
  1240. $options = array();
  1241. if ($degree_array = $db->get_degrees_in_catalog_year($catalog_year, FALSE, $bool_use_draft, $bool_undergrad_only, array(1), $student_school_id)) {
  1242. foreach($degree_array as $major_code => $value) {
  1243. if (trim($value["title"]) == ""){continue;}
  1244. $options[$major_code] = $value["title"];
  1245. $major_codes[$major_code] = $major_code;
  1246. }
  1247. }
  1248. // Place in a fieldset...
  1249. $e1["select_level_1_degrees"] = array(
  1250. "type" => "checkboxes",
  1251. "label" => "",
  1252. "options" => $options,
  1253. );
  1254. $form["cfieldset_level_1"] = array(
  1255. "type" => "cfieldset",
  1256. "label" => "Select Major &raquo;",
  1257. "elements" => array($e1),
  1258. "start_closed" => FALSE,
  1259. );
  1260. /////////////////////////
  1261. // Select a minor....
  1262. $options = array();
  1263. if ($degree_array = $db->get_degrees_in_catalog_year($catalog_year, FALSE, $bool_use_draft, $bool_undergrad_only, array(2), $student_school_id)) {
  1264. foreach($degree_array as $major_code => $value) {
  1265. if (trim($value["title"]) == ""){continue;}
  1266. $options[$major_code] = $value["title"];
  1267. $major_codes[$major_code] = $major_code;
  1268. }
  1269. }
  1270. if (count($options) > 0) {
  1271. $e2["select_level_2_degrees"] = array(
  1272. "type" => "checkboxes",
  1273. "label" => "",
  1274. "options" => $options,
  1275. );
  1276. $form["cfieldset_level_2"] = array(
  1277. "type" => "cfieldset",
  1278. "label" => "Select Minor &raquo;",
  1279. "elements" => array($e2),
  1280. );
  1281. }
  1282. /////////////////////
  1283. // All the tracks...
  1284. if (variable_get_for_school("show_level_3_on_what_if_selection", "yes", $student_school_id) == 'yes') {
  1285. foreach ($major_codes as $major_code => $temp) {
  1286. // Let's see if this major has any tracks...
  1287. if ($tracks = $db->get_degree_tracks($major_code, $catalog_year, $student_school_id)) {
  1288. // Let's load the original degree plan.
  1289. $degree_plan = $db->get_degree_plan($major_code, $catalog_year, TRUE, $student_school_id);
  1290. $degree_plan->load_degree_plan_ancillary();
  1291. // Yes, there are indeed tracks for THIS major. Let's load them up...
  1292. // First, organize them by degree_class...
  1293. $tracks_by_class = array();
  1294. foreach ($tracks as $track) {
  1295. $t_degree_plan = $db->get_degree_plan($major_code . "|_" . $track, $catalog_year, TRUE, $student_school_id);
  1296. $t_degree_plan->load_degree_plan_ancillary();
  1297. $degree_class = trim($t_degree_plan->degree_class);
  1298. if ($degree_class) {
  1299. $tracks_by_class[$degree_class][] = $t_degree_plan;
  1300. }
  1301. }
  1302. // Now, create the form element...
  1303. foreach ($tracks_by_class as $degree_class => $c) {
  1304. $options = array();
  1305. $temp = fp_get_degree_classification_details($degree_class);
  1306. $class_title = $temp["title"];
  1307. // Are there any special requirements or defaults for this degree_class selection?
  1308. $tsca = $degree_plan->track_selection_config_array;
  1309. $default_tracks_array = @csv_to_array($tsca[$degree_class]["default_tracks"]);
  1310. $min_tracks = @intval($tsca[$degree_class]["min_tracks"]);
  1311. $max_tracks = @intval($tsca[$degree_class]["max_tracks"]);
  1312. $element_type = "checkboxes";
  1313. $element_value = array();
  1314. // If we require exactly 1 selection, then make this a radio button, and pre-select either the first element
  1315. // or the first default track.
  1316. if ($min_tracks == 1 && $max_tracks == 1) {
  1317. $element_type = "radios";
  1318. $element_value = array($default_tracks_array[0] => $default_tracks_array[0]);
  1319. }
  1320. // Actually build up the options...
  1321. foreach ($tracks_by_class[$degree_class] as $t_degree_plan) {
  1322. //$degree_id = $t_degree_plan->degree_id;
  1323. $tmajor_code = "" . trim($t_degree_plan->major_code);
  1324. $options[$tmajor_code] = $t_degree_plan->get_title2(FALSE, TRUE);
  1325. if (trim($t_degree_plan->track_description) != "") {
  1326. $options[$tmajor_code] .= "<div class='what-if-selection-track-desc what-if-selection-track-desc-for-" . fp_get_machine_readable($tmajor_code) . "'
  1327. >" . $t_degree_plan->track_description . "</div>";
  1328. }
  1329. // Is this a "default" major code?
  1330. if (in_array(trim($tmajor_code), $default_tracks_array)) {
  1331. $element_value[$tmajor_code] = $tmajor_code; // make it be selected
  1332. }
  1333. }
  1334. $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>";
  1335. if ($min_tracks == $max_tracks) {
  1336. $min_max_options = "<div class='advise-select-track-min-max advise-select-track-exact-number'>Please select $max_tracks $class_title options.</div>";
  1337. }
  1338. if ($min_tracks == $max_tracks && $max_tracks == 1) {
  1339. $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-exactly-one'>Please select 1 $class_title option.</div>";
  1340. }
  1341. if ($min_tracks > 0 && $max_tracks == 0) {
  1342. // Meaning, there is no maximum. It's infinite.
  1343. $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>";
  1344. }
  1345. if ($min_tracks == $max_tracks && $max_tracks == 0) {
  1346. $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>";
  1347. }
  1348. $form["L3__sel__{$degree_class}__for__{$major_code}__xx"] = array( //ends with xx so we can be sure when the major code ends.
  1349. "type" => $element_type,
  1350. "label" => "Select $class_title for " . $degree_plan->get_title2(),
  1351. "options" => $options,
  1352. "description" => "$min_max_options",
  1353. "value" => $element_value,
  1354. );
  1355. // Save min and max options for quick look-up later.
  1356. $form["L3__ops__{$degree_class}__for__{$major_code}__xx"] = array(
  1357. "type" => "hidden",
  1358. "value" => "$min_tracks~$max_tracks",
  1359. );
  1360. }
  1361. } // if tracks
  1362. } // foreach major codes
  1363. } // if level-3 selection...
  1364. $form["submit_btn"] = array(
  1365. "value" => "<div align='right'>
  1366. " . fp_render_button("Try It Out!", "showUpdate(true);$(\"#fp-form-advise_what_if_selection_form\").submit(); ") . "
  1367. </div>",
  1368. );
  1369. $form["current_student_id"] = array(
  1370. "type" => "hidden",
  1371. "value" => $current_student_id,
  1372. );
  1373. watchdog("advise", "what_if_selection_form $current_student_id", array());
  1374. return $form;
  1375. }
  1376. /**
  1377. * Validate handler for the what_if selection form. This is where we might, for example, make sure
  1378. * that if a non-dynamic degree was selected, that they can't proceed.
  1379. */
  1380. function advise_what_if_selection_form_validate($form, &$form_state) {
  1381. $catalog_year = $form_state['values']['catalog_year'];
  1382. $current_student_id = $form_state['values']['current_student_id'];
  1383. $school_id = db_get_school_id_for_student_id($current_student_id);
  1384. // Make sure they selected at least 1 level 1 degree.
  1385. $selected_degrees = array();
  1386. $temp = FALSE;
  1387. foreach (array(1,2) as $num) {
  1388. if (isset($form_state["values"]["select_level_{$num}_degrees"]) && is_array($form_state["values"]["select_level_{$num}_degrees"])) {
  1389. foreach ($form_state["values"]["select_level_{$num}_degrees"] as $k => $v) {
  1390. if ((string)$k === (string)$v && $k != "") {
  1391. $temp = TRUE;
  1392. $selected_degrees[$k] = $v;
  1393. }
  1394. }
  1395. }
  1396. }
  1397. if (!$temp) {
  1398. form_error("select_level_1_degrees", t("Sorry, you must select at least one top-level degree to proceed. Please try again."));
  1399. return;
  1400. }
  1401. $db = get_global_database_handler();
  1402. // If a non-dynamic degree was selected, along with anything else, the user may not proceed.
  1403. if (count($selected_degrees) > 1) {
  1404. foreach ($selected_degrees as $major_code) {
  1405. $temp = $db->get_degree_plan($major_code, $catalog_year, TRUE);
  1406. if (is_object($temp) && intval($temp->db_allow_dynamic) != 1) {
  1407. $temp->load_descriptive_data();
  1408. // meaning, we have selected more than one degree, and at least THIS degree does NOT allow for dynamic recombination. So, reject it!
  1409. 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.
  1410. It must be selected by itself. Please alter your selection and try again.", array("%deg"=> $temp->get_title2())));
  1411. return;
  1412. }
  1413. }
  1414. }
  1415. /////////////////////////
  1416. // Make sure they selected appropriate number of required tracks, if any.
  1417. $selected_tracks = 0; // just used to keep up with how many we are selecting.
  1418. // Begin by going through each track which was selected, and keep track of how many we selected.
  1419. $selected_for = array();
  1420. foreach ($form_state["values"] as $key => $val) {
  1421. if (strstr($key, "L3__sel__")) {
  1422. // L3_sel_{$degree_class}_for_{$major_code}_xx
  1423. $temp = explode("__", $key);
  1424. $degree_class = $temp[2];
  1425. $major_code = $temp[4];
  1426. if (!isset($selected_for[$major_code . "__" . $degree_class])) {
  1427. $selected_for[$major_code . "__" . $degree_class] = 0;
  1428. }
  1429. if (is_array($val)) { // In other words, this was a group of checkboxes.
  1430. foreach ($val as $k => $v) {
  1431. // Did the user select an item? Val's key and value will be identical if so.
  1432. if ($k == $v && $k != "") {
  1433. // YES. It was selected!
  1434. $selected_for[$major_code . "__" . $degree_class]++;
  1435. }
  1436. }
  1437. } // if is_array (val)
  1438. else if (is_string($val) && trim($val) != ""){
  1439. // Not an array-- was a radio list? So, this was a selection.
  1440. $selected_for[$major_code . "__" . $degree_class]++;
  1441. }
  1442. }
  1443. }
  1444. // Okay, now that we know how many were selected, let's make sure that the number falls within
  1445. // our min/max range for those tracks.
  1446. foreach ($form_state["values"] as $key => $val) {
  1447. if (!strstr($key, "L3__sel__")) { continue; }
  1448. $temp = explode("__", $key);
  1449. $degree_class = $temp[2];
  1450. $major_code = $temp[4];
  1451. $count = @intval($selected_for[$major_code . "__" . $degree_class]);
  1452. //First, make sure it's top-level degree was even selected. If it wasn't, skip it, it doesn't matter.
  1453. $temp = explode("|_", $major_code);
  1454. $top_level_code = trim($temp[0]);
  1455. if (@$form_state["values"]["select_level_1_degrees"][$top_level_code] != $top_level_code) {
  1456. if (@$form_state["values"]["select_level_2_degrees"][$top_level_code] != $top_level_code) {
  1457. continue;
  1458. }
  1459. }
  1460. // Okay, check to see if the count falls within the range for this degree & class.
  1461. $temp = explode("~", $form_state["values"]["L3__ops__{$degree_class}__for__{$major_code}__xx"]);
  1462. $min_tracks = @intval($temp[0]);
  1463. $max_tracks = @intval($temp[1]);
  1464. if ($count > $max_tracks && $max_tracks != 0) {
  1465. // We picked too many!
  1466. form_error("L3__sel__{$degree_class}__for__{$major_code}__xx", t("Sorry, you did not select the correct number of options for this degree."));
  1467. return;
  1468. }
  1469. if ($count < $min_tracks && $min_tracks > 0) {
  1470. // We picked too few!
  1471. form_error("L3__sel__{$degree_class}__for__{$major_code}__xx", t("Sorry, you did not select the correct number of options for this degree."));
  1472. return;
  1473. }
  1474. $selected_tracks += $count;
  1475. } // foreach
  1476. $total_selected = count($selected_degrees) + $selected_tracks;
  1477. // If this is more than what is allowed to be selected, then show error.
  1478. $max = intval(variable_get_for_school('max_allowed_selections_in_what_if', 5, $school_id));
  1479. if ($max === 0) $max = 5;
  1480. if ($total_selected > $max) {
  1481. 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."));
  1482. }
  1483. } //what_if_selection_form_validate
  1484. /**
  1485. * Submit handler for the what if selection form.
  1486. * Since at this point we have passed validation, let's just assemble the URL we need to now
  1487. * redirect to.
  1488. */
  1489. function advise_what_if_selection_form_submit($form, $form_state) {
  1490. $current_student_id = $form_state["values"]["current_student_id"];
  1491. $catalog_year = $form_state["values"]["catalog_year"];
  1492. // Get the major codes CSV
  1493. $what_if_major_code = "";
  1494. foreach (array(1, 2) as $num) {
  1495. if (isset($form_state["values"]["select_level_{$num}_degrees"]) && is_array($form_state["values"]["select_level_{$num}_degrees"])) {
  1496. foreach ($form_state["values"]["select_level_{$num}_degrees"] as $k => $v) {
  1497. if ((string)$k === (string)$v && $k != "") {
  1498. $what_if_major_code .= $k . ",";
  1499. }
  1500. }
  1501. }
  1502. }
  1503. // Add in the tracks, too, if selected.
  1504. foreach ($form_state["values"] as $key => $val) {
  1505. if (strstr($key, "L3__sel__")) {
  1506. if (is_array($val) && count($val) > 0) {
  1507. // Did the user select this item? Val's key and value will be identical if so.
  1508. foreach ($val as $k => $v) {
  1509. if ($k == $v && $k != "") {
  1510. // YES. It was selected!
  1511. //First, make sure it's top-level degree was even selected. If it wasn't, skip it, it doesn't matter.
  1512. $temp = explode("|_", $k);
  1513. $top_level_code = trim($temp[0]);
  1514. if (@$form_state["values"]["select_level_1_degrees"][$top_level_code] != $top_level_code) {
  1515. if (@$form_state["values"]["select_level_2_degrees"][$top_level_code] != $top_level_code) {
  1516. continue;
  1517. }
  1518. }
  1519. $what_if_major_code .= $k . ",";
  1520. }
  1521. }
  1522. } // if is_array val (cause it was a checkbox)
  1523. else if (is_string($val) && trim($val) != "") {
  1524. // This was from radio buttons.
  1525. //First, make sure it's top-level degree was even selected. If it wasn't, skip it, it doesn't matter.
  1526. $temp = explode("|_", $val);
  1527. $top_level_code = trim($temp[0]);
  1528. if (@$form_state["values"]["select_level_1_degrees"][$top_level_code] != $top_level_code) {
  1529. if (@$form_state["values"]["select_level_2_degrees"][$top_level_code] != $top_level_code) {
  1530. continue;
  1531. }
  1532. }
  1533. $what_if_major_code .= $val . ",";
  1534. }
  1535. }
  1536. }
  1537. // Remove training comma
  1538. $what_if_major_code = rtrim($what_if_major_code, ",");
  1539. // Okay, let's redirect the user to their proper destination
  1540. $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";
  1541. fp_goto("what-if", $query);
  1542. }
  1543. /**
  1544. * Takes various variables from the REQUEST and stores them in our advising_session_variables table for more convenient use later on.
  1545. */
  1546. function advise_init_advising_variables($bool_ignore_what_if_variables = FALSE) {
  1547. global $user;
  1548. $vars = array();
  1549. $student = null;
  1550. // The current student ID is what we append to all session variables
  1551. // dealing with the current student. We do this so that we will
  1552. // keep session variables unique, so that we can have more than one
  1553. // window open at a time, with multiple students.
  1554. // Therefor, this should never go into the session.
  1555. // Annoyingly, we must pass carry this around on each page in the system.
  1556. $vars["current_student_id"] = @$_REQUEST["current_student_id"];
  1557. if ($vars["current_student_id"] == "")
  1558. {
  1559. $vars["current_student_id"] = @$_REQUEST["advising_student_id"];
  1560. }
  1561. $csid = $vars["current_student_id"];
  1562. $school_id = db_get_school_id_for_student_id($csid);
  1563. // Get the student ID.
  1564. $vars["advising_student_id"] = @$_REQUEST["advising_student_id"];
  1565. if ($vars["advising_student_id"] == "")
  1566. {
  1567. $vars["advising_student_id"] = @$_SESSION["advising_student_id$csid"];
  1568. if ($vars["advising_student_id"] == "")
  1569. { // Default value...
  1570. $vars["advising_student_id"] = $csid;
  1571. }
  1572. }
  1573. // Should we load from the Draft advising session? or the active?
  1574. $vars["advising_load_active"] = @$_REQUEST["advising_load_active"];
  1575. if ($vars["advising_load_active"] == "")
  1576. { // values will either be "yes" or "" (any other value than "yes" is
  1577. // considered to be negative.
  1578. // Default value...
  1579. $vars["advising_load_active"] = "";
  1580. }
  1581. // Are we currently in WhatIf mode?
  1582. @$vars["advising_what_if"] = $_REQUEST["advising_what_if"]; // Get it from the GET or POST.
  1583. if ($vars["advising_what_if"] == "")
  1584. {
  1585. // Will equal "yes" if we ARE in whatIf mode.
  1586. @$vars["advising_what_if"] = $_SESSION["advising_what_if$csid"];
  1587. if ($vars["advising_what_if"] == "")
  1588. {
  1589. // Default value:
  1590. $vars["advising_what_if"] = "no";
  1591. }
  1592. }
  1593. // Go ahead and set our GLOBALS variable for advising_what_if. It's needed when we load
  1594. // the $student variable.
  1595. $GLOBALS["fp_advising"]["advising_what_if"] = $vars["advising_what_if"];
  1596. // Get the major_code(s).
  1597. $vars["advising_major_code"] = @$_REQUEST["advising_major_code"];
  1598. if ($vars["advising_major_code"] == "")
  1599. {
  1600. $vars["advising_major_code"] = @$_SESSION["advising_major_code$csid"];
  1601. if ($vars["advising_major_code"] == "")
  1602. { // Default value...
  1603. if (!$student) $student = new Student($csid);
  1604. $vars["advising_major_code"] = $student->major_code_csv;
  1605. $_REQUEST["advising_major_code"] = $student->major_code_csv;
  1606. }
  1607. }
  1608. $vars["advising_track_degree_ids"] = @$_REQUEST["advising_track_degree_ids"];
  1609. if ($vars["advising_track_degree_ids"] == "")
  1610. {
  1611. $vars["advising_track_degree_ids"] = @$_SESSION["advising_track_degree_ids$csid"];
  1612. if ($vars["advising_track_degree_ids"] == "")
  1613. { // Default value...
  1614. if (!$student) $student = new Student($csid);
  1615. // Re-load the major codes, as the tracks might have changed.
  1616. $student->load_student_data();
  1617. $vars["advising_major_code"] = $student->major_code_csv;
  1618. }
  1619. }
  1620. // Update the student's settings?
  1621. $vars["advising_update_student_settings_flag"] = @$_REQUEST["advising_update_student_settings_flag"];
  1622. // Make it only come from the POST, for safety.
  1623. if ($vars["advising_update_student_settings_flag"] == "")
  1624. {
  1625. $vars["advising_update_student_settings_flag"] = @$_SESSION["advising_update_student_settings_flag$csid"];
  1626. if ($vars["advising_update_student_settings_flag"] == "")
  1627. { // Default value...
  1628. }
  1629. }
  1630. @$vars["advising_term_id"] = $_REQUEST["advising_term_id"]; // Get it from the GET or POST.
  1631. if ($vars["advising_term_id"] == "")
  1632. {
  1633. // Set to the default advising term.
  1634. @$vars["advising_term_id"] = $_SESSION["advising_term_id$csid"];
  1635. if ($vars["advising_term_id"] == "")
  1636. {
  1637. // default value:
  1638. $vars["advising_term_id"] = variable_get_for_school("advising_term_id", '', $school_id);
  1639. if ($vars["advising_term_id"] == "") {
  1640. // It's STILL blank?! Just use 0 then.
  1641. $vars["advising_term_id"] = "0";
  1642. }
  1643. }
  1644. }
  1645. @$vars["what_if_major_code"] = $_REQUEST["what_if_major_code"]; // Get it from the GET or POST.
  1646. if ($vars["what_if_major_code"] == "")
  1647. {
  1648. // Will equal "yes" if we ARE in whatIf mode.
  1649. @$vars["what_if_major_code"] = $_SESSION["what_if_major_code$csid"];
  1650. if ($vars["what_if_major_code"] == "")
  1651. {
  1652. // Default value:
  1653. $vars["what_if_major_code"] = "";
  1654. }
  1655. }
  1656. @$vars["what_if_catalog_year"] = $_REQUEST["what_if_catalog_year"]; // Get it from the GET or POST.
  1657. if ($vars["what_if_catalog_year"] == "")
  1658. {
  1659. @$vars["what_if_catalog_year"] = $_SESSION["what_if_catalog_year$csid"];
  1660. if ($vars["what_if_catalog_year"] == "")
  1661. {
  1662. // Default value:
  1663. $vars["what_if_catalog_year"] = "";
  1664. }
  1665. }
  1666. @$vars["what_if_track_degree_ids"] = $_REQUEST["what_if_track_degree_ids"]; // Get it from the GET or POST.
  1667. if ($vars["what_if_track_degree_ids"] == "")
  1668. {
  1669. // Will equal "yes" if we ARE in whatIf mode.
  1670. @$vars["what_if_track_degree_ids"] = $_SESSION["what_if_track_degree_ids$csid"];
  1671. if ($vars["what_if_track_degree_ids"] == "")
  1672. {
  1673. // Default value:
  1674. $vars["what_if_track_degree_ids"] = "";
  1675. }
  1676. }
  1677. if ($vars["what_if_major_code"] == "none")
  1678. {
  1679. $vars["what_if_major_code"] = "";
  1680. }
  1681. if ($vars["what_if_track_degree_ids"] == "none")
  1682. {
  1683. $vars["what_if_track_degree_ids"] = "";
  1684. }
  1685. if ($vars["advising_track_degree_ids"] == "none")
  1686. {
  1687. $vars["advising_track_degree_ids"] = "";
  1688. }
  1689. // Settings... (from the database)
  1690. $vars["setting_available_advising_term_ids"] = variable_get_for_school("available_advising_term_ids", '', $school_id);
  1691. $vars["setting_advising_term_id"] = variable_get_for_school("advising_term_id", '', $school_id);
  1692. $vars["setting_current_catalog_year"] = variable_get_for_school("current_catalog_year",'', $school_id);
  1693. $vars["setting_current_draft_catalog_year"] = variable_get_for_school("current_draft_catalog_year",'', $school_id);
  1694. // Are we in Print View?
  1695. @$vars["print_view"] = $_REQUEST["print_view"];
  1696. // Should we try to load from the cache?
  1697. @$vars["load_from_cache"] = $_REQUEST["load_from_cache"];
  1698. if ($vars["load_from_cache"] == "")
  1699. {
  1700. // By default, attempt to load from cache.
  1701. $vars["load_from_cache"] = "yes";
  1702. }
  1703. // What "view" are we in? View by Year or by Type?
  1704. // Not the same as printView. printView should work regardless
  1705. // of our advising_view.
  1706. @$vars["advising_view"] = $_REQUEST["advising_view"];
  1707. if ($vars["advising_view"] == "")
  1708. {
  1709. @$vars["advising_view"] = $_SESSION["advising_view$csid"];
  1710. }
  1711. // Place values into session.
  1712. $_SESSION["advising_student_id$csid"] = $vars["advising_student_id"];
  1713. $_SESSION["advising_student_id"] = $vars["advising_student_id"]; // used ONLY in the error report popup!
  1714. $_SESSION["advising_major_code$csid"] = $vars["advising_major_code"];
  1715. $_SESSION["advising_track_degree_ids$csid"] = $vars["advising_track_degree_ids"];
  1716. $_SESSION["advising_term_id$csid"] = $vars["advising_term_id"];
  1717. $_SESSION["advising_what_if$csid"] = $vars["advising_what_if"];
  1718. $_SESSION["what_if_major_code$csid"] = $vars["what_if_major_code"];
  1719. $_SESSION["what_if_catalog_year$csid"] = $vars["what_if_catalog_year"];
  1720. $_SESSION["what_if_track_degree_ids$csid"] = $vars["what_if_track_degree_ids"];
  1721. $_SESSION["advising_view$csid"] = $vars["advising_view"];
  1722. if ($bool_ignore_what_if_variables == true)
  1723. {
  1724. $vars["advising_what_if"] = "";
  1725. $vars["what_if_major_code"] = "";
  1726. $vars["what_if_catalog_year"] = "";
  1727. $vars["what_if_track_degree_ids"] = "";
  1728. }
  1729. // Are we in draft mode?
  1730. if ($_SESSION["fp_draft_mode"] == "yes")
  1731. {
  1732. $vars["bool_use_draft"] = true;
  1733. } else {
  1734. $vars["bool_use_draft"] = false;
  1735. }
  1736. $GLOBALS["fp_advising"] = $vars;
  1737. // Add our current advising term (and our other settings) to javascript settings.
  1738. $js_settings = array(
  1739. "advisingTermId" => $GLOBALS['fp_advising']['advising_term_id'], // The currently selected advising term_id.
  1740. "fp_advising_variables" => $vars,
  1741. );
  1742. fp_add_js($js_settings, "setting");
  1743. }
  1744. /**
  1745. * Implementation of hook_init
  1746. */
  1747. function advise_init() {
  1748. global $current_student_id, $user, $screen, $student, $degree_plan;
  1749. $current_student_id = @$_REQUEST["current_student_id"];
  1750. // Since this user doesn't have permission to view this student's sessions,
  1751. // he can only view his own. This is to stop hackers from experimenting with the URL
  1752. // to see other users' data.
  1753. if (!advise_can_access_view($current_student_id)) {
  1754. // Reset our global vars....
  1755. $current_student_id = "";
  1756. if (isset($user->cwid) && $user->is_student) {
  1757. $current_student_id = $user->cwid;
  1758. }
  1759. $_REQUEST["current_student_id"] = $current_student_id;
  1760. $_POST["current_student_id"] = $current_student_id;
  1761. $_GET["current_student_id"] = $current_student_id;
  1762. $_SESSION["current_student_id"] = $current_student_id;
  1763. $_REQUEST["advising_student_id"] = $current_student_id;
  1764. $_POST["advising_student_id"] = $current_student_id;
  1765. $_GET["advising_student_id"] = $current_student_id;
  1766. $_SESSION["advising_student_id"] = $current_student_id;
  1767. $GLOBALS["fp_advising"]["advising_student_id"] = $current_student_id;
  1768. $_REQUEST["advising_load_active"] = "yes";
  1769. }
  1770. if (!isset($_SESSION["fp_draft_mode"])) $_SESSION["fp_draft_mode"] = "";
  1771. // Is draft mode enabled?
  1772. if ($_SESSION["fp_draft_mode"] == "yes") {
  1773. fp_add_message("<b>" . t("Draft mode") . "</b> " . t("is currently enabled, however, substitutions and advisings will
  1774. still be saved normally."), "status", TRUE);
  1775. }
  1776. }
  1777. /**
  1778. * Implementation of hook_clear_cache
  1779. * Called by other modules, this function will take care of clearing
  1780. * anything this module has cached.
  1781. */
  1782. function advise_clear_cache() {
  1783. foreach ($_SESSION as $key => $value) {
  1784. if (strstr($key, "cache_")) {
  1785. $_SESSION[$key] = FALSE;
  1786. unset($_SESSION[$key]); // do this just to make sure our server-side session file gets overwritten
  1787. }
  1788. if (strstr($key, "advising_") || strstr($key, "what_if_")) {
  1789. $_SESSION[$key] = FALSE;
  1790. unset($_SESSION[$key]);
  1791. }
  1792. }
  1793. unset($_SESSION['fp_cache_course_inventory_last_generated']);
  1794. system_reload_and_cache_course_inventory();
  1795. unset($_SESSION["last_student_selected"]);
  1796. fp_add_message(t("Advising cache has been cleared."));
  1797. }
  1798. /**
  1799. * From menu hook. Clear just the advising cache.
  1800. *
  1801. */
  1802. function advise_perform_clear_advising_cache() {
  1803. advise_clear_cache();
  1804. fp_goto("<front>");
  1805. }
  1806. function advise_init_screen() {
  1807. global $degree_plan, $student, $fp, $window_mode, $user, $current_student_id, $screen;
  1808. $db = get_global_database_handler();
  1809. $faculty_id = $user->cwid;
  1810. // Insert our advising vars into the GLOBALS array for easy use later.
  1811. advise_init_advising_variables();
  1812. $perform_action = trim(addslashes(@$_REQUEST["perform_action"]));
  1813. if (@$_REQUEST["clear_session"] == "yes") {
  1814. //advise_save_advising_variables_to_db();
  1815. // reload our advising vars into the GLOBALS array for easy use later.
  1816. //$GLOBALS["fp_advising"] = advise_load_advising_variables_from_db($current_student_id, $user->id);
  1817. }
  1818. // Insert our advising vars into the GLOBALS array for easy use later.
  1819. //$GLOBALS["fp_advising"] = advise_load_advising_variables_from_db($current_student_id, $user->id);
  1820. $bool_what_if = false;
  1821. $csid = $current_student_id;
  1822. $cache = @$_SESSION["cache_fp$csid"];
  1823. if (@$GLOBALS["fp_advising"]["advising_what_if"] == "yes") {
  1824. $major_code = @$GLOBALS["fp_advising"]["what_if_major_code"];
  1825. $track_code = @$GLOBALS["fp_advising"]["what_if_track_code"];
  1826. $bool_what_if = true;
  1827. $cache = @$_SESSION["cache_what_if$csid"];
  1828. }
  1829. $bool_draft = true;
  1830. if (@$GLOBALS["fp_advising"]["advising_load_active"] == "yes") {
  1831. // If we are loading from Active, then rebuild the cache as well.
  1832. $bool_draft = false;
  1833. @$GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1834. }
  1835. $student_school_id = $db->get_school_id_for_student_id($csid);
  1836. ///////////////////////
  1837. /// Disable student data Caching....
  1838. //$GLOBALS["load_from_cache"] = "no";
  1839. // Attempt to load the course inventory cache...
  1840. if ($course_inventory = unserialize(@$_SESSION["fp_cache_course_inventory"])) {
  1841. $GLOBALS["fp_course_inventory"] = $course_inventory;
  1842. }
  1843. $bool_loaded = FALSE;
  1844. if ($GLOBALS["fp_advising"]["load_from_cache"] == "yes" && $cache != "" && $fp = unserialize($cache)) {
  1845. $bool_loaded = TRUE;
  1846. $fp->db = get_global_database_handler();
  1847. $student = $fp->student;
  1848. if ($student->student_id == "") $bool_loaded = FALSE;
  1849. $degree_plan = $fp->degree_plan;
  1850. $student->db = get_global_database_handler();
  1851. $degree_plan->db = get_global_database_handler();
  1852. }
  1853. if (!$bool_loaded) {
  1854. $fp = new FlightPath();
  1855. $fp->init();
  1856. $student = $fp->student;
  1857. $degree_plan = $fp->degree_plan;
  1858. $GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1859. $bool_loaded = TRUE;
  1860. }
  1861. // If the form has been saved, this token is expected. This protects
  1862. // against XSS attacks.
  1863. $form_token = md5("advise_display_view" . fp_token());
  1864. if ($perform_action == "save_draft") {
  1865. if ($_REQUEST["form_token"] != $form_token) {
  1866. die(t("Sorry, but you have encountered an error. A form submission was flagged
  1867. as possibly being an invalid or forged submission. This may constitute a bug
  1868. in the system. Please report this error to your Systems Administrator."));
  1869. }
  1870. // Save, then reload the student.
  1871. $adv_id_array = $fp->save_advising_session_from_post(0,true);
  1872. $bool_draft = TRUE; // load draft, since we just saved it (and changed something)
  1873. }
  1874. else if ($perform_action == "save_active") {
  1875. if ($_REQUEST["form_token"] != $form_token) {
  1876. die(t("Sorry, but you have encountered an error. A form submission was flagged
  1877. as possibly being an invalid or forged submission. This may constitute a bug
  1878. in the system. Please report this error to your Systems Administrator."));
  1879. }
  1880. // Save, then go to the history screen.
  1881. $adv_id_array = $fp->save_advising_session_from_post(0,false);
  1882. // Use an fp_goto command here to go to the History screen
  1883. // Serialize the adv_id_array so we can send it along in our fp_goto command...
  1884. $adv_id_serialized = serialize($adv_id_array);
  1885. fp_goto("history", "adv_id_array_serialized=" . urlencode($adv_id_serialized));
  1886. return;
  1887. }
  1888. // Is the user trying to view "by type" or by year?
  1889. if ($GLOBALS["fp_advising"]["advising_view"] == "type") {
  1890. $screen = new AdvisingScreenTypeView("", $fp);
  1891. $screen->view = "type";
  1892. }
  1893. else {
  1894. // Default advising view. "View by Year"
  1895. $screen = new AdvisingScreen("", $fp);
  1896. $screen->view = "year";
  1897. }
  1898. if (@$_REQUEST["bool_blank"] == "true" || @$_REQUEST["blank_degree_id"] != "") {
  1899. $screen->bool_blank = TRUE;
  1900. }
  1901. if ($bool_what_if == true && @$GLOBALS["fp_advising"]["what_if_major_code"] == "") {
  1902. // In other words, we are on the WhatIf tab, but we have not
  1903. // selected a major. So, just exit out. We will give the user
  1904. // a display_screen later.
  1905. return;
  1906. }
  1907. if (@$GLOBALS["fp_advising"]["load_from_cache"] != "yes") {
  1908. // do not load from cache.... load the student fresh....
  1909. // Only do if we need to re-init after save
  1910. if (@$_REQUEST['reinit_fp_after_draft_save'] == 'yes') {
  1911. $fp = new FlightPath();
  1912. $fp->init();
  1913. $student = $fp->student;
  1914. $degree_plan = $fp->degree_plan;
  1915. $GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1916. }
  1917. $student->load_student();
  1918. $student->load_student_substitutions();
  1919. $student->load_unassignments();
  1920. // Make sure we assign the freshly-loaded student, and re-establish all of our connections.
  1921. $fp->student = $student;
  1922. $screen->flightpath = $fp;
  1923. $screen->student = $fp->student;
  1924. $screen->degree_plan = $fp->degree_plan;
  1925. $fp->flag_outdated_substitutions();
  1926. $fp->assign_courses_to_semesters(); // bare degree plan. not groups.
  1927. $fp->assign_courses_to_groups();
  1928. ////////////
  1929. /*
  1930. // Good place to output a serialization, in case we need it for testing.
  1931. $student->name = "Test Student2";
  1932. $student->student_id = "123457";
  1933. $temp = serialize($screen);
  1934. file_put_contents(fp_get_files_path() . "/test.txt", $temp);
  1935. /////////////*/
  1936. }
  1937. else {
  1938. }
  1939. if (@$GLOBALS["fp_advising"]["save_to_cache"] != "no" && $window_mode != "popup") {
  1940. if ($bool_what_if == false) {
  1941. // NOT in whatIf mode. Normal.
  1942. $_SESSION["cache_fp$csid"] = serialize($fp);
  1943. }
  1944. else {
  1945. // We are in WhatIf mode.
  1946. $_SESSION["cache_what_if$csid"] = serialize($fp);
  1947. }
  1948. }
  1949. // If we are loading from draft, then load the faculty_id which saved draft last. If we are
  1950. // loading fresh, not from draft, then load *any* faculty that saved last.
  1951. $use_faculty_id = $faculty_id;
  1952. if (!$bool_draft) $use_faculty_id = 0;
  1953. // We shouldn't supply the advising_term_id, so that it will load all terms available.
  1954. $fp->load_advising_session_from_database($use_faculty_id,"",$bool_what_if,$bool_draft,0,$faculty_id);
  1955. // Once we have loaded the advising session, we should always try to load
  1956. // from draft from then on out.
  1957. $GLOBALS["fp_advising"]["advising_load_active"] = "";
  1958. }
  1959. /**
  1960. * This is a hook which developers may use to add custom blocks (or perform other operations)
  1961. * onto the advising View or What If screen.
  1962. *
  1963. * This is called AFTER the AdvisingScreen class has called it's build_screen_elements()
  1964. * function, which draws the various semester blocks, footnotes, etc, onto the screen.
  1965. *
  1966. * This gives other modules a chance to alter the screen, or to add a custom block to the
  1967. * bottom of the screen. Note that the $screen element is sent by reference. Any changes
  1968. * you make to it will be instant; there is no need to return anything.
  1969. *
  1970. * To see how these blocks are best set up, look at AdvisingScreen->build_excess_credit(), or
  1971. * AdvisingScreen->displaySemester() for inspiration.
  1972. *
  1973. * @param AdvisingScreen &$screen
  1974. */
  1975. function hook_advise_build_screen_elements(&$screen) {
  1976. $html = "";
  1977. $html .= $screen->draw_semester_box_top("Sample", TRUE); // pass TRUE to hide the "headers"
  1978. $html .= "<tr><td colspan='8'>"; // required after the top!
  1979. ////////////////
  1980. // The content...
  1981. $html .= "<b>Hello World!</b>";
  1982. ///////////////////
  1983. // All done, time to tidy up...
  1984. $html .= "</td></tr>"; // required before the bottom!
  1985. $html .= $screen->draw_semester_box_bottom();
  1986. // Add to the screen as a "semester block".
  1987. $screen->add_to_screen($html);
  1988. }

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.