FlightPath.php

  1. 6.x classes/FlightPath.php
  2. 4.x custom/classes/FlightPath.php
  3. 5.x custom/classes/FlightPath.php

File

classes/FlightPath.php
View source
  1. <?php
  2. class FlightPath extends stdClass
  3. {
  4. public $student, $degree_plan, $db, $bool_what_if;
  5. public $course_list_advised_courses;
  6. function __construct($student = "", $degree_plan = "", DatabaseHandler $db = null, $bool_perform_full_init = false)
  7. {
  8. if ($student != "")
  9. {
  10. $this->student = $student;
  11. }
  12. if ($degree_plan != "")
  13. {
  14. $this->degree_plan = $degree_plan;
  15. }
  16. if ($db != null)
  17. {
  18. $this->db = $db;
  19. } else {
  20. $this->db = get_global_database_handler();
  21. }
  22. if ($bool_perform_full_init == true)
  23. {
  24. $this->init(true);
  25. }
  26. $this->course_list_advised_courses = new CourseList();
  27. }
  28. function init($bool_init_advising_variables = false, $bool_ignore_what_if_advising_variables = false, $bool_load_full = true) {
  29. global $current_student_id, $user, $student;
  30. // This will initialize this flightPath object
  31. // based on what is available in the global variables.
  32. // Takes the place of what was going on at the beginning
  33. // of advise.php.
  34. if ($bool_init_advising_variables == true)
  35. {
  36. //$temp_screen = new AdvisingScreen();
  37. //$temp_screen->init_advising_variables($bool_ignore_what_if_advising_variables);
  38. //advise_load_advising_variables_from_db($current_student_id, $user->id);
  39. advise_init_advising_variables();
  40. }
  41. $major_code_csv = $GLOBALS["fp_advising"]["advising_major_code"];
  42. //$track_code = $GLOBALS["fp_advising"]["advising_track_code"];
  43. $track_degree_ids = $GLOBALS["fp_advising"]["advising_track_degree_ids"];
  44. $student_id = $GLOBALS["fp_advising"]["advising_student_id"];
  45. $advising_term_id = $GLOBALS["fp_advising"]["advising_term_id"];
  46. @$available_terms = $GLOBALS["fp_advising"]["available_advising_term_ids"];
  47. // Keep in mind-- at this point, major_coe might be a CSV of major codes.
  48. $this->bool_what_if = false;
  49. // Are we in WhatIf mode?
  50. if ($GLOBALS["fp_advising"]["advising_what_if"] == "yes")
  51. {
  52. $major_code_csv = $GLOBALS["fp_advising"]["what_if_major_code"];
  53. $track_degree_ids = $GLOBALS["fp_advising"]["what_if_track_degree_ids"];
  54. $this->bool_what_if = true;
  55. }
  56. if ($bool_load_full == false)
  57. { // not trying to load anything, so return.
  58. return;
  59. }
  60. $db = $this->db;
  61. if ($bool_load_full == true)
  62. {
  63. $student = new Student($student_id);
  64. } else {
  65. $student = new Student();
  66. $student->student_id = $student_id;
  67. }
  68. $student_school_id = $db->get_school_id_for_student_id($student_id);
  69. $catalog_year = $student->catalog_year;
  70. if ($this->bool_what_if)
  71. {
  72. // We need to look at a "what_if_catalog_year" value.
  73. $catalog_year = $GLOBALS["fp_advising"]["what_if_catalog_year"];
  74. if ($catalog_year == "" || $catalog_year == 0) {
  75. // Some problem, default to current cat year.
  76. $catalog_year = variable_get_for_school("current_catalog_year",'',$student_school_id);
  77. }
  78. }
  79. // make sure their catalog year is not past the system's current
  80. // year setting.
  81. if ($catalog_year > variable_get_for_school("current_catalog_year",'',$student_school_id) && variable_get_for_school("current_catalog_year",'',$student_school_id) > intval(variable_get_for_school("earliest_catalog_year", 2006, $student_school_id)))
  82. { // Make sure degree plan is blank if it is!
  83. $catalog_year = 99999;
  84. }
  85. if ($GLOBALS["fp_advising"]["advising_update_student_settings_flag"] != "")
  86. {
  87. // TODO: This is used in What If mode. We need to make sure that these track_degree_ids
  88. // actually do match to the selected majors. If not, then we should remove them. This
  89. // is to make sure that when we switch What If settings, these get cleared.
  90. $wi = "";
  91. if ($this->bool_what_if) {
  92. $wi = "what_if_";
  93. }
  94. //$student->array_settings["track_code"] = $track_code;
  95. $student->array_settings[$wi . "track_degree_ids"] = $track_degree_ids;
  96. $student->array_settings[$wi . "major_code_csv"] = $major_code_csv;
  97. }
  98. // Let's add the track_degree_ids to the major_code_csv...
  99. $major_code_csv .= "," . $track_degree_ids;
  100. ///////////////////////////////
  101. // Okay folks. So this is basically where we will be iterating through all
  102. // of the student's major_codes (if they have more than one), and squishing them together,
  103. // to create a single DegreePlan object, made out of all the options.
  104. // We need like a loop here.
  105. $degree_plans = array();
  106. $temparr = explode(",", $major_code_csv);
  107. foreach ($temparr as $major_code) {
  108. $t_major_code = $major_code;
  109. if (trim($major_code) == "") continue;
  110. // If we are dealing with a track, then just get the degree_id directly, else, figure out the
  111. // degree_id from the t_major_code.
  112. if (is_numeric($t_major_code)) {
  113. $degree_id = $t_major_code;
  114. }
  115. else {
  116. $degree_id = $db->get_degree_id($t_major_code, $catalog_year, FALSE, $student_school_id);
  117. }
  118. // If we couldn't find the degree_id, then we should just skip it.
  119. if (!$degree_id || $degree_id == 0) {
  120. if (variable_get("warning_on_view_if_degree_not_found", "yes") == 'yes') {
  121. fp_add_message(t("Could not find degree %maj in catalog year %cat. FlightPath will
  122. skip loading this degree for now. If this message continues to appear,
  123. contact your advisor.", array("%maj" => $t_major_code, "%cat" => $student->catalog_year . "-" . ($student->catalog_year + 1))), "error", TRUE);
  124. }
  125. continue;
  126. }
  127. if ($bool_load_full == true)
  128. {
  129. $this->student = $student;
  130. $degree_plan = fp_load_degree($degree_id, $db, FALSE, $student->array_significant_courses);
  131. //$degree_plan = new DegreePlan($degree_id, $db, FALSE, $student->array_significant_courses);
  132. $degree_plan->add_semester_developmental($student->student_id);
  133. //$this->degree_plan = $degree_plan;
  134. $degree_plans[$degree_plan->degree_id] = $degree_plan;
  135. }
  136. } // foreach temparr as major_code. The foreach loop through all our major codes.
  137. // Okay, coming out of this, we have an array of degree_plans (maybe). If it's just one, then set it to that one.
  138. if (count($degree_plans) == 1) {
  139. $this->degree_plan = $degree_plan;
  140. }
  141. else if (count($degree_plans) > 1) {
  142. // Okay folks, here's the magic. We need to combine the degree plans in this array
  143. // into 1 generated degree plan.
  144. $combined_degree_plan = $this->combine_degree_plans($degree_plans, $student_id, $student_school_id);
  145. $combined_degree_plan->db_allow_dynamic = 1; // since they are combined, we must be allowing dynamic.
  146. $this->degree_plan = $combined_degree_plan;
  147. } // else if count(degree_plans) > 1
  148. else if (count($degree_plans) < 1) {
  149. // Meaning, we couldn't find any degree plans for this student! Let's just load some blank objects.
  150. $this->degree_plan = new DegreePlan();
  151. $this->student = $student;
  152. }
  153. // Invoke a hook which lets other modules act on this student and degree plan we just loaded.
  154. invoke_hook('init_flightpath_degree', array($this->student->student_id, &$this->degree_plan));
  155. $wi = "";
  156. if ($this->bool_what_if) $wi = "_what_if";
  157. if (isset($this->degree_plan) && $this->degree_plan != null) {
  158. // Add degree_plan to a simple cache to make our lives easier later on.
  159. $_SESSION["fp_simple_degree_plan_cache_for_student" . $wi] = array(
  160. "cwid" => $student_id,
  161. "degree_id" => $this->degree_plan->degree_id,
  162. "combined_degree_ids_array" => $this->degree_plan->combined_degree_ids_array,
  163. "is_combined_dynamic_degree_plan" => $this->degree_plan->is_combined_dynamic_degree_plan,
  164. );
  165. }
  166. } // end of function fp_init
  167. /**
  168. * This function is responsible for combining multiple degree plans into a single unified degree plan,
  169. * then returning it.
  170. */
  171. function combine_degree_plans($degree_plans, $student_id, $school_id = 0) {
  172. //DEV: return $degree_plans[0];
  173. $new_degree_plan = new DegreePlan();
  174. $new_degree_plan->school_id = intval($school_id);
  175. // Loop through the degree plans one at a time...
  176. foreach ($degree_plans as $degree_plan) {
  177. $new_degree_plan->combined_degree_ids_array[] = intval($degree_plan->degree_id);
  178. $new_degree_plan->add_to_required_course_id_array($degree_plan->required_course_id_array);
  179. // Is there a public note to copy over?
  180. if (isset($degree_plan->public_notes_array[$degree_plan->degree_id])) {
  181. $new_degree_plan->public_notes_array[$degree_plan->degree_id] = $degree_plan->public_notes_array[$degree_plan->degree_id];
  182. }
  183. if ($degree_plan->catalog_year == "" || $degree_plan->catalog_year == 0) {
  184. $degree_plan->load_descriptive_data();
  185. }
  186. $new_degree_plan->catalog_year = $degree_plan->catalog_year;
  187. // Okay, now copy whatever we need to into the new_degree_plan.
  188. // First, go through its list of semesters, and copy out all the courses and groups
  189. $degree_plan->list_semesters->reset_counter();
  190. while ($degree_plan->list_semesters->has_more()) {
  191. $sem = $degree_plan->list_semesters->get_next();
  192. // If the semester is the Added by Advisor (-88), or the developmental block (-55) then skip for now.
  193. if ($sem->semester_num == DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED || $sem->semester_num == DegreePlan::SEMESTER_NUM_FOR_DEVELOPMENTALS) {
  194. // This is the special one that is "added by advisor". Skip it. But remember to add it later to the finished product.
  195. // Or, it's the developmentals block. Add that later too.
  196. continue;
  197. }
  198. // Okay, the semester contains a CourseList called list_courses, and a GroupList caled list_groups.
  199. $new_list_courses = $sem->list_courses->get_clone();
  200. // Now, let's add them to the new_degree_plan's semester...
  201. // if the new degree plan already has this semester, get that instead.
  202. $the_semester = $new_degree_plan->get_semester($sem->semester_num);
  203. if (!$the_semester) {
  204. $the_semester = new Semester($sem->semester_num);
  205. $new_degree_plan->list_semesters->add($the_semester);
  206. }
  207. // Should we rename the_semester's title (because the semester we are grabbing is overriding?)
  208. //$degree_plan->load_descriptive_data(); // Doesn't appear to be necessary at this stage.
  209. $stitle = trim(@$degree_plan->array_semester_titles[$sem->semester_num]);
  210. if ($stitle != "") {
  211. // Meaning we should overwrite the semester title, because this degree isn't using the default title
  212. $the_semester->title = $stitle;
  213. $the_semester->bool_using_default_title = FALSE;
  214. }
  215. // Okay, now add the courses to the_semester
  216. $the_semester->list_courses->add_list($new_list_courses);
  217. ////////////////////////////
  218. // Getting the list of groups is going to be similar to getting our list of courses.
  219. // Go through the list of groups for this semester.
  220. $new_list_groups = $sem->list_groups->get_clone(FALSE, FALSE, FALSE);
  221. // Okay, now we can add to our semester
  222. $the_semester->list_groups->add_list($new_list_groups);
  223. // Also add this group list to the degree plan's list_groups.
  224. $new_degree_plan->list_groups->add_list($new_list_groups);
  225. } // while, listing semesters in degree plan.
  226. } // foreach degree_plans
  227. //////////////////////////////
  228. // Okay, now to put the finishing touches on the $new_degree_plan
  229. // Add in the "Developmental Req's" if required for this student.
  230. $new_degree_plan->add_semester_developmental($student_id);
  231. // Add in the "Courses added by advisor"
  232. $new_degree_plan->add_semester_courses_added();
  233. if (count($degree_plans) > 1) {
  234. $new_degree_plan->is_combined_dynamic_degree_plan = TRUE;
  235. $new_degree_plan->degree_id = DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE; // use constant to make it easier later on.
  236. }
  237. // Make sure all of our groups have reloaded any missing courses.
  238. $new_degree_plan->list_semesters->reset_counter();
  239. while ($new_degree_plan->list_semesters->has_more()) {
  240. $sem = $new_degree_plan->list_semesters->get_next();
  241. $sem->list_groups->reload_missing_courses();
  242. }
  243. return $new_degree_plan;
  244. } // combine_degree_plans
  245. /**
  246. * This function will check to see if we are trying to save
  247. * the draft from a tab change. It should be near the top
  248. * of all of FP's "tab" pages, like Main, Comments, etc.
  249. *
  250. */
  251. function process_request_save_draft()
  252. {
  253. /////////////////////////////////////
  254. /// Are we trying to save the draft
  255. /// from a tab change?
  256. /////////////////////////////////////
  257. if ($_REQUEST["save_draft"] == "yes")
  258. {
  259. $this->init(true, false, false);
  260. // If we are coming from the WhatIf tab, we need to save
  261. // as WhatIf. Else, save as normal.
  262. if ($_REQUEST["from_w_i"] == "yes")
  263. {
  264. // Yes, we are coming from WhatIf mode, so
  265. // save under WhatIf.
  266. $GLOBALS["advising_what_if"] = "yes";
  267. $this->init(false);
  268. } else {
  269. // NOT coming from WhatIf mode. Save as a normal draft.
  270. $GLOBALS["advising_what_if"] = "no";
  271. $this->init(true, true);
  272. }
  273. $this->save_advising_session_from_post(0,true);
  274. }
  275. }
  276. function assign_courses_to_groups() {
  277. // This method will look at the student's courses
  278. // and decide which groups they should be fit into.
  279. // We will be going through the degree plan's master list
  280. // of groups to decide this.
  281. $student = $this->student;
  282. $school_id = $student->school_id;
  283. $this->degree_plan->list_groups->sort_priority();
  284. // Now, sort by the advising weight of the degree itself.
  285. $this->degree_plan->list_groups->sort_degree_advising_weight();
  286. $this->degree_plan->list_groups->reset_counter();
  287. while($this->degree_plan->list_groups->has_more())
  288. {
  289. $g = $this->degree_plan->list_groups->get_next();
  290. if ($g->group_id == DegreePlan::GROUP_ID_FOR_COURSES_ADDED)
  291. {
  292. // Add a course group. Skip.
  293. continue;
  294. }
  295. // Does the student have any group additions for this
  296. // group? Technically it is a substitution.
  297. // We will add them in now, because we do not take additions
  298. // into consideration when figuring out branches.
  299. if ($course_list_additions = $student->list_substitutions->find_group_additions($g))
  300. {
  301. $course_list_additions->reset_counter();
  302. while($course_list_additions->has_more())
  303. {
  304. $cA = $course_list_additions->get_next();
  305. $new_course = new Course();
  306. $new_course->course_id = $cA->course_id;
  307. if ($cA->bool_transfer == true)
  308. {
  309. if ($cA->course_id == 0 && is_object($cA->course_transfer))
  310. { // This is a transfer course which has been added.
  311. $new_course->course_id = $cA->course_transfer->course_id;
  312. }
  313. $new_course->bool_transfer = true;
  314. }
  315. $new_course->assigned_to_semester_num = $g->assigned_to_semester_num;
  316. $new_course->requirement_type = $g->requirement_type;
  317. // Add this course as a requirement.
  318. //$new_course->load_descriptive_data();
  319. $g->list_courses->add($new_course, true);
  320. // Later on, when we do assign_courses_to_list, it
  321. // will automatically find this course and apply the
  322. // substitution.
  323. }
  324. }
  325. // First we see if there are any bare courses at this level. If there
  326. // are, then this group has NO branches! Otherwise, the courses must
  327. // always be contained in a branch!
  328. if (!$g->list_courses->is_empty)
  329. {
  330. // Yes, there are courses here. So, assign them at this level.
  331. $this->assign_courses_to_list($g->list_courses, $this->student, true, $g, true);
  332. // Okay, if we have fulfilled our courses at this level.
  333. // then we can continue on to the next "top level" group.
  334. //continue;
  335. }
  336. if (!$g->list_groups->is_empty)
  337. {
  338. /*
  339. Now we've got some trouble. This is our first level of groups.
  340. If this object exists, then it means that this group branches off
  341. at its first level. So, instead of actually assigning courses to
  342. groups, we need to find out which group has the most matches, and THEN
  343. we will assign them.
  344. */
  345. $g->reload_missing_courses();
  346. $high_count = -1;
  347. $best_branch = -1;
  348. // Sort our list of groups by student's grades, if applicable.
  349. $sort_policy = variable_get_for_school("initial_student_course_sort_policy", "alpha", $school_id); // will either be "alpha" or "grade"
  350. if ($sort_policy == "grade") {
  351. $g->list_groups->sort_best_grade_first_by_student_grades($student);
  352. }
  353. $g->list_groups->reset_counter();
  354. while($g->list_groups->has_more())
  355. {
  356. $branch_one = $g->list_groups->get_next();
  357. if (!$branch_one->list_courses->is_empty)
  358. {
  359. // This does not actually assign. Just counts.
  360. $count = $this->get_count_of_matches($branch_one, $this->student, $g);
  361. $branch_one->count_of_matches = $count;
  362. if ($count > $high_count)
  363. {
  364. $high_count = $count;
  365. $best_branch = $g->list_groups->object_index_of($branch_one);
  366. }
  367. }
  368. }
  369. // Okay, coming out of that, we should know which branch has the best count (number
  370. // of matches). So, let's assign courses to that branch.
  371. if ($best_branch != -1)
  372. {
  373. $winning_branch = $g->list_groups->get_element($best_branch);
  374. $winning_branch->bool_winning_branch = TRUE;
  375. $this->assign_courses_to_list($winning_branch->list_courses, $this->student, TRUE, $g, TRUE);
  376. }
  377. }
  378. } // while
  379. }
  380. function get_count_of_matches($branch, $student, $group)
  381. {
  382. return $this->assign_courses_to_list($branch->list_courses, $student, FALSE, $group, TRUE);
  383. }
  384. function flag_outdated_substitutions()
  385. {
  386. // Go through the student's substitutions and flag ones that
  387. // do not apply to this degree plan. Also, unset any bool_substitution
  388. // variables which were set.
  389. $this->student->list_substitutions->reset_counter();
  390. while ($this->student->list_substitutions->has_more())
  391. {
  392. $substitution = $this->student->list_substitutions->get_next();
  393. ////////////////////////////
  394. // Ticket #2316, from Logan Buth, this is to better detect outdated subs for combined degrees.
  395. $bool_sub_valid = true;
  396. $outdated_note = "";
  397. if ($this->degree_plan->degree_id == DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE &&
  398. !in_array($substitution->db_required_degree_id, $this->degree_plan->combined_degree_ids_array)) {
  399. //combined degree plan, degree id not in it.
  400. $bool_sub_valid = false;
  401. $sub_degree_title = fp_get_degree_title($substitution->db_required_degree_id, TRUE, TRUE, FALSE, TRUE);
  402. $outdated_note = t("This substitution is for the degree %did
  403. which is no longer in the student's degrees.", array("%did" => $sub_degree_title));
  404. }
  405. else if ($this->degree_plan->degree_id != DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE &&
  406. $this->degree_plan->degree_id != $substitution->db_required_degree_id) {
  407. $bool_sub_valid = false;
  408. $sub_degree_title = fp_get_degree_title($substitution->db_required_degree_id, TRUE, TRUE, FALSE, TRUE);
  409. $outdated_note = t("This substitution is for the degree %did
  410. which is no longer the student's degree", array("%did" => $sub_degree_title));
  411. }
  412. //////////////
  413. //$required_group_id = $substitution->course_requirement->assigned_to_group_id;
  414. $required_group_id = $substitution->course_requirement->get_first_assigned_to_group_id(); // we assume there's only one group to get
  415. // First check-- does this degree even have this group ID?
  416. if ($bool_sub_valid && $required_group_id == 0) {
  417. // bare degree plan.
  418. // Does the bare degree plan list the course_requirement
  419. // anywhere?
  420. $bool_sub_valid = false;
  421. $this->degree_plan->list_semesters->reset_counter();
  422. while($this->degree_plan->list_semesters->has_more() && $bool_sub_valid == false)
  423. {
  424. $sem = $this->degree_plan->list_semesters->get_next();
  425. if ($sem->list_courses->find_match($substitution->course_requirement))
  426. {
  427. $bool_sub_valid = true;
  428. } else {
  429. // Could not find the course requirement in question.
  430. $bool_sub_valid = false;
  431. $scr = $substitution->course_requirement;
  432. $scr->load_descriptive_data();
  433. $outdated_note = t("This substitution is for the course %info on the
  434. bare degree plan, but the student's current degree does
  435. not specify this course.", array("%info" => "$scr->subject_id $scr->course_num (id: $scr->course_id)"));
  436. }
  437. }
  438. }
  439. else if ($bool_sub_valid && $required_group_id != 0) {
  440. // required_group_id != 0, meaning, NOT the bare degree plan.
  441. // So, does this degree plan have a group with this id (required_group_id)?
  442. $bool_sub_valid = false;
  443. if ($g = $this->degree_plan->find_group($required_group_id)) {
  444. $bool_sub_valid = true;
  445. }
  446. else {
  447. // Could not find the group in question. Add an "outdated_note"
  448. // to the sub...
  449. $bool_sub_valid = false;
  450. $new_group = new Group();
  451. $new_group->group_id = $required_group_id;
  452. $new_group->load_descriptive_data();
  453. $group_name = "";
  454. if (user_has_permission("can_access_data_entry")) {
  455. // only show if we are a data entry administrator.
  456. $group_name = "<i>$new_group->group_name,</i>";
  457. }
  458. $outdated_note = t("This substitution is for the group %info,
  459. but the student's current degree does not call for this
  460. specific group.", array("%info" => "$new_group->title (id: $new_group->group_id, $group_name $new_group->catalog_year)"));
  461. }
  462. }
  463. if ($bool_sub_valid == false) {
  464. // Couldn't find a match, so remove this sub!
  465. $substitution->bool_outdated = true;
  466. $substitution->outdated_note = $outdated_note;
  467. $substitution->course_list_substitutions->get_first()->bool_outdated_sub = true;
  468. $substitution->course_list_substitutions->get_first()->set_bool_outdated_sub(0, TRUE);
  469. //$substitution->course_list_substitutions->get_first()->bool_substitution = false;
  470. $substitution->course_list_substitutions->get_first()->set_bool_substitution(0, FALSE);
  471. if ($substitution->course_list_substitutions->get_first()->temp_old_course_id > 0)
  472. { // Restore the course_id *if* it was set to 0 on purpose. (happens
  473. // when there is a sub of a transfer to kill the transfer eqv. This will
  474. // restore it).
  475. $substitution->course_list_substitutions->get_first()->course_id = $substitution->course_list_substitutions->get_first()->temp_old_course_id;
  476. }
  477. }
  478. }
  479. }
  480. function assign_courses_to_list(ObjList $list_requirements, Student $student, $bool_perform_assignment = true, Group $group = null, $bool_check_significant_courses = false, $assign_to_semester_num = -1)
  481. {
  482. $count = 0;
  483. $school_id = 0;
  484. if ($student) {
  485. $school_id = $student->school_id;
  486. }
  487. if ($group == null)
  488. {
  489. $group = new Group();
  490. $group->group_id = 0;
  491. }
  492. else if ($group->min_grade != "") {
  493. $group->assign_min_grade($group->min_grade); // If this is a group with a min grade value, let's make sure we assign all the courses in it to this min grade.
  494. }
  495. $sort_policy = variable_get_for_school("initial_student_course_sort_policy", "alpha", $school_id); // will either be "alpha" or "grade"
  496. $bool_disallow_graduate_credits = (variable_get_for_school("disallow_graduate_credits", "yes", $school_id) == "yes") ? TRUE : FALSE;
  497. $graduate_level_codes_array = csv_to_array(variable_get_for_school("graduate_level_codes", "GR", $school_id));
  498. // Get the course repeat policy.
  499. $course_repeat_policy = variable_get_for_school("course_repeat_policy", "most_recent_exclude_previous", $school_id);
  500. // Set the $bool_mark_repeats_exclude variable based on the course_repeat_policy.
  501. $bool_mark_repeats_exclude = ($course_repeat_policy == "most_recent_exclude_previous" || $course_repeat_policy == "best_grade_exclude_others");
  502. $group_id = $group->group_id;
  503. // If the group_id == 0, we may be talking about the bare degree plan.
  504. $hours_required = $group->hours_required*1;
  505. $hours_assigned = $group->hours_assigned;
  506. $meet_min_hours = 999999; // effectively infinite by default, to make logic easier later on.
  507. // If the group has min_hours, then we should allow the user to get at least the min hours before we stop trying to fill.
  508. if ($group->has_min_hours_allowed() && variable_get_for_school("group_full_at_min_hours", "yes", $school_id) == "yes") {
  509. $meet_min_hours = $group->min_hours_allowed;
  510. }
  511. if ($hours_required <= 0 || $hours_required == "")
  512. {
  513. $hours_required = 999999;
  514. }
  515. $list_requirements->sort_smallest_hours_first();
  516. // sort the requirement list by the best grades that the student has made? Similar to the substitutions?
  517. if ($sort_policy == "grade") {
  518. $list_requirements->sort_best_grade_first($student);
  519. }
  520. else if ($sort_policy == "alpha") {
  521. $list_requirements->sort_alphabetical_order();
  522. }
  523. $list_requirements->sort_substitutions_first($student->list_substitutions, $group_id);
  524. $list_requirements->reset_counter();
  525. while($list_requirements->has_more())
  526. {
  527. $course_requirement = $list_requirements->get_next();
  528. $req_by_degree_id = $course_requirement->req_by_degree_id; // what degree is requiring this course?
  529. // If we're dealing with a group, use it's required by degree id.
  530. if ($group->group_id != "" && $group->req_by_degree_id > 0) {
  531. $req_by_degree_id = $group->req_by_degree_id;
  532. }
  533. if ($bool_check_significant_courses == true)
  534. {
  535. // Only look for the course_requirement if it is in the student's
  536. // array_significant_courses array.
  537. if (isset($student->array_significant_courses[$course_requirement->course_id]) && $student->array_significant_courses[$course_requirement->course_id] != true)
  538. {// course was not in there, so skip!
  539. continue;
  540. }
  541. }
  542. if ($course_requirement->bool_specified_repeat == true)
  543. {
  544. // Since this requirement has specified repeats, we want
  545. // to make all of the student's taken courses (for this course)
  546. // also have specified repeats.
  547. $student->list_courses_taken->set_specified_repeats($course_requirement, $course_requirement->specified_repeats);
  548. }
  549. //if ($course_requirement->course_id == '101092') {
  550. //fpm($course_requirement);
  551. //}
  552. // Does the student have any substitutions for this requirement?
  553. if ($substitution = $student->list_substitutions->find_requirement($course_requirement, true, $group_id, $req_by_degree_id))
  554. {
  555. // Since the substitution was made, I don't really care about
  556. // min grades or the like. Let's just put it in.
  557. if ($bool_perform_assignment == TRUE)
  558. {
  559. // Check to see if this course requirement has "infinite repeats". If it does, then we want to
  560. // clone it and add it back into our list of requirements.
  561. if ($course_requirement->specified_repeats == Group::GROUP_COURSE_INFINITE_REPEATS) {
  562. $temp_ds = $course_requirement->to_data_string();
  563. $new_course = new Course();
  564. $new_course->load_course_from_data_string_for_requirement_clone($temp_ds);
  565. $new_course->min_grade = $course_requirement->min_grade;
  566. if ($assign_to_semester_num !== -1) {
  567. $new_course->assigned_to_semester_num = $assign_to_semester_num;
  568. }
  569. $list_requirements->add($new_course);
  570. }
  571. // Make sure this isn't a group addition and we are *currently*
  572. // NOT looking at the group it is being added to. This is to
  573. // correct a bug.
  574. if ($substitution->bool_group_addition == true)
  575. {
  576. if ($substitution->course_requirement->get_first_assigned_to_group_id() != $group_id)
  577. {
  578. continue;
  579. }
  580. }
  581. // If the course_requirement's min_hours are greater than
  582. // the substitution's hours, then we have to split the
  583. // coureRequirement into 2 pieces, and add the second piece just
  584. // after this one in the list.
  585. $course_sub = $substitution->course_list_substitutions->get_first();
  586. if ($course_requirement->min_hours*1 > $course_sub->get_hours_awarded($req_by_degree_id))
  587. {
  588. // Because float math can create some very strange results, we must
  589. // perform some rounding. We will round to 6 decimal places, which should
  590. // provide us the accuracy w/o losing precision (since we can only represent a max
  591. // of 4 decimals in the database anyway.
  592. $remaining_hours = round($course_requirement->min_hours - $course_sub->get_hours_awarded($req_by_degree_id), 6);
  593. $new_course_string = $course_requirement->to_data_string();
  594. $new_course = new Course();
  595. $new_course->load_course_from_data_string($new_course_string);
  596. $new_course->min_hours = $new_course->max_hours = $remaining_hours;
  597. $new_course->set_bool_substitution_split($req_by_degree_id, TRUE);
  598. $new_course->set_bool_substitution_new_from_split($req_by_degree_id, TRUE);
  599. $new_course->requirement_type = $course_requirement->requirement_type;
  600. $new_course->min_grade = $course_requirement->min_grade;
  601. $new_course->req_by_degree_id = $req_by_degree_id;
  602. $new_course->assigned_to_degree_ids_array[$req_by_degree_id] = $req_by_degree_id;
  603. $new_course->db_degree_requirement_id = floatval($course_requirement->db_degree_requirement_id . ".1");
  604. if ($assign_to_semester_num !== -1) {
  605. $new_course->assigned_to_semester_num = $assign_to_semester_num;
  606. }
  607. $course_requirement->set_bool_substitution_split($req_by_degree_id, TRUE);
  608. // I am commenting this out-- if we split up a sub multiple times, then we shouldn't
  609. // set the old course requirement to say it WASN'T from a split. This was causing a bug
  610. // where the pie charts got weird if you did more than 1 split. Was counting total
  611. // hours as more, in CourseList->count_hours().
  612. //$course_requirement->bool_substitution_new_from_split = false;
  613. // Only do this if we are NOT in a group! This is to correct a bug where split additions to groups wound up
  614. // being displayed like available selections in the group. It was like, weird man.
  615. if ($group_id == 0) {
  616. // Now, add this into the list, right after the course_requirement.
  617. $current_i = $list_requirements->i;
  618. $list_requirements->insert_after_index($current_i, $new_course);
  619. }
  620. } // if min_hours > sub's awarded hours
  621. $course_requirement->course_list_fulfilled_by = $substitution->course_list_substitutions;
  622. $substitution->course_list_substitutions->assign_group_id($group_id);
  623. $substitution->course_list_substitutions->set_has_been_assigned(true);
  624. $substitution->course_list_substitutions->set_bool_substitution($req_by_degree_id, TRUE);
  625. $course_requirement->db_substitution_id_array[] = $substitution->db_substitution_id;
  626. $substitution->course_list_substitutions->set_course_substitution($course_requirement, $substitution->remarks, $req_by_degree_id);
  627. $substitution->bool_has_been_applied = TRUE;
  628. if ($group_id != "" && intval($group_id) > 0) {
  629. // We are going to add the course_sub's hours in as being assigned to this list, if this is for a group.
  630. // I am surprised this wasn't already here. This fixes a bug with groups that allow min hours.
  631. $hours_assigned += $course_sub->get_hours_awarded($req_by_degree_id);
  632. }
  633. }
  634. $count++;
  635. continue;
  636. } // if student has any substitutions for this requirement
  637. // Has the student taken this course requirement?
  638. if ($c = $student->list_courses_taken->find_best_match($course_requirement, $course_requirement->min_grade, $bool_mark_repeats_exclude, $req_by_degree_id, TRUE, TRUE, $group_id))
  639. {
  640. $h_get_hours = $c->get_hours();
  641. if ($c->bool_ghost_hour) {
  642. // If this is a ghost hour, then $h_get_hours would == 0 right now,
  643. // instead, use the the adjusted value (probably 1).
  644. $h_get_hours = $c->get_hours_awarded($req_by_degree_id);
  645. }
  646. // Can we assign any more hours to this group? Are we
  647. // out of hours, and should stop?
  648. if ($hours_assigned >= $hours_required || $hours_assigned >= $meet_min_hours)
  649. {
  650. continue;
  651. }
  652. $c_hours_awarded = $c->get_hours_awarded($req_by_degree_id);
  653. // Will the hours of this course put us over the hours_required limit? NOTE: We don't care if it puts us over the min_hours, in fact, we want that.
  654. if ($hours_assigned + $c_hours_awarded > $hours_required )
  655. {
  656. continue;
  657. }
  658. // Do not apply substitution new_from_split courses to anything automatically. (from any degree!)
  659. // They must be applied by substitutions.
  660. if ($c->get_bool_substitution_new_from_split() == TRUE)
  661. {
  662. continue;
  663. }
  664. // Make sure the course meets min grade requirements.
  665. if (!$c->meets_min_grade_requirement_of($course_requirement))
  666. {
  667. continue;
  668. }
  669. // Has the course been unassigned from this group?
  670. if ($c->group_list_unassigned->find_match_with_degree_id($group, $req_by_degree_id))
  671. {
  672. continue;
  673. }
  674. // Make sure $c is not being used in a substitution (for this degree)
  675. if ($c->get_bool_substitution($req_by_degree_id) == TRUE) {
  676. continue;
  677. }
  678. // If this is a graduate level course, and we are not allowing grad credits, then skip!
  679. if ($c->level_code != "" && in_array($c->level_code, $graduate_level_codes_array)) {
  680. if ($bool_disallow_graduate_credits) {
  681. continue;
  682. }
  683. }
  684. // Check hooks to see if this course is allowed to be assigned to the GROUP in question.
  685. if ($group_id != "" && $group_id != 0) {
  686. $bool_can_proceed = TRUE;
  687. $result = invoke_hook("flightpath_can_assign_course_to_group", array($group, $c));
  688. foreach ($result as $m => $val) {
  689. // If *any* module said FALSE, then we must skip this course and not assign it to this degree.
  690. if ($val === FALSE) $bool_can_proceed = $val;
  691. }
  692. if (!$bool_can_proceed) {
  693. continue; // don't assign!
  694. }
  695. } // if group_id != ""
  696. // We want to see if this course has already been assigned to THIS degree...
  697. if (!in_array($req_by_degree_id, $c->assigned_to_degree_ids_array))
  698. {//Don't count courses which have already been placed in other groups.
  699. // Check hooks to see if this course is allowed to be assigned to the degree in question.
  700. $bool_can_proceed = TRUE;
  701. $result = invoke_hook("flightpath_can_assign_course_to_degree_id", array($req_by_degree_id, $c));
  702. foreach ($result as $m => $val) {
  703. // If *any* module said FALSE, then we must skip this course and not assign it to this degree.
  704. if ($val === FALSE) $bool_can_proceed = $val;
  705. }
  706. if (!$bool_can_proceed) {
  707. continue; // don't assign!
  708. }
  709. // Has another version of this course already been
  710. // assigned? And if so, are repeats allowed for this
  711. // course? And if so, then how many hours of the
  712. // repeat_hours have I used up? If I cannot do any more
  713. // repeats, then quit. Otherwise, let it continue...
  714. $course_list_repeats = $student->list_courses_taken->get_previous_assignments($c->course_id);
  715. if ($course_list_repeats->get_size() > 0)
  716. {
  717. // So, a copy of this course has been assigned more than once...
  718. // Get the total number of hours taken up by this course.
  719. $cc = $course_list_repeats->count_hours();
  720. // have we exceeded the number of available repeat_hours
  721. // for this course?
  722. if ($course_requirement->repeat_hours <= 0)
  723. {
  724. $course_requirement->load_descriptive_data();
  725. }
  726. if (($course_requirement->bool_ghost_hour != TRUE || $c->bool_ghost_hour != TRUE)
  727. && $cc + $h_get_hours > $course_requirement->repeat_hours*1)
  728. {
  729. // Do not allow the repeat, unless we are talking about courses worth zero hours.
  730. // meaning, they have a ghost hour. In which case, allow it.
  731. continue;
  732. }
  733. }
  734. // Basically--- if the most recent attempt fails
  735. // a min grade check, then tag all attempts as "unuseable"
  736. // so that they can't be used in other groups. --
  737. // unless they are able to be repeated. BARF!
  738. // Inc hours_assigned, even if we aren't actually
  739. // performing an assignment. This helps us accurately
  740. // calculate the count.
  741. $hours_assigned = $hours_assigned + $h_get_hours;
  742. if ($bool_perform_assignment == TRUE)
  743. {
  744. // If this course has an "infinite" number of specified repeats, then
  745. // let's actually clone the course and insert it as a new requirement, to replace
  746. // the one we're about to use.
  747. if ($course_requirement->specified_repeats == Group::GROUP_COURSE_INFINITE_REPEATS) {
  748. $temp_ds = $course_requirement->to_data_string();
  749. $new_course = new Course();
  750. $new_course->load_course_from_data_string_for_requirement_clone($temp_ds);
  751. $new_course->min_grade = $course_requirement->min_grade;
  752. if ($assign_to_semester_num !== -1) {
  753. $new_course->assigned_to_semester_num = $assign_to_semester_num;
  754. $new_course->appears_in_semester_nums[] = $assign_to_semester_num; // for combo-degrees
  755. }
  756. $list_requirements->add($new_course);
  757. } // infinite repeats?
  758. // Which degree is this coming from?
  759. //$req_by_degree_id = $course_requirement->req_by_degree_id;
  760. $c->assigned_to_degree_ids_array[$req_by_degree_id] = $req_by_degree_id;
  761. // Go ahead and state that the requirement was fulfilled.
  762. $course_requirement->course_list_fulfilled_by->add($c);
  763. $course_requirement->grade = $c->grade;
  764. $course_requirement->set_hours_awarded($req_by_degree_id, $c->get_hours_awarded($req_by_degree_id));
  765. $course_requirement->bool_ghost_hour = $c->bool_ghost_hour;
  766. if ($course_requirement->extra_attribs != "") {
  767. $c->extra_attribs = $course_requirement->extra_attribs;
  768. }
  769. // No longer using... using the assigned_to_degree_ids_array instead. // $c->bool_has_been_assigned = true;
  770. //$c->requirement_type = $course_requirement->requirement_type;
  771. if ($c->requirement_type == "") {
  772. // No requirement type given? Perhaps we are part of a group. If so, use that.
  773. //$c->requirement_type = $group->requirement_type;
  774. //$course_requirement->requirement_type = $group->requirement_type;
  775. }
  776. if ($assign_to_semester_num !== -1) {
  777. $c->assigned_to_semester_num = $assign_to_semester_num;
  778. $c->appears_in_semester_nums[] = $assign_to_semester_num; // for combo-degrees
  779. }
  780. // Check what groups it has been assigned to already.
  781. //$c->assigned_to_group_id = $group_id;
  782. if ($group_id != '') {
  783. $c->assigned_to_group_ids_array[$group_id . "_" . $req_by_degree_id] = $group_id;
  784. }
  785. $group->hours_assigned = $hours_assigned;
  786. // Should check for:
  787. // Can it be assigned, based on the number of allowed course repeats?
  788. if ($course_requirement->bool_specified_repeat == true)
  789. {
  790. // $c is what they actually took.
  791. $c->bool_specified_repeat = true;
  792. $c->specified_repeats = $course_requirement->specified_repeats;
  793. $list_requirements->dec_specified_repeats($c);
  794. }
  795. } // bool_perform_assignment == true
  796. $count++;
  797. }
  798. }
  799. }
  800. return $count;
  801. }
  802. function assign_courses_to_semesters()
  803. {
  804. // This method will look at the student's courses
  805. // and decide if they should be assigned to degree requirements
  806. // which have been spelled out in each semester. This
  807. // is not where it looks into groups.
  808. $this->degree_plan->list_semesters->reset_counter();
  809. while($this->degree_plan->list_semesters->has_more())
  810. {
  811. $semester = $this->degree_plan->list_semesters->get_next();
  812. $semester_num = $semester->semester_num;
  813. // Okay, let's look at the courses (not groups) in this
  814. // semester...
  815. $this->assign_courses_to_list($semester->list_courses, $this->student, TRUE, null, FALSE, $semester_num);
  816. }
  817. }
  818. /**
  819. * Get the plain English title of a subject, from
  820. * subject_id. Ex: COSC = Computer Science.
  821. *
  822. * @param unknown_type $subject_id
  823. * @return unknown
  824. */
  825. function get_subject_title($subject_id, $school_id = 0)
  826. {
  827. // From the subject_id, get the title.
  828. // Example: COSC = Computer Science.
  829. $res = $this->db->db_query("SELECT title FROM subjects
  830. WHERE subject_id = ?
  831. AND school_id = ?
  832. LIMIT 1 ", $subject_id, $school_id);
  833. $cur = $this->db->db_fetch_array($res);
  834. if ($cur) {
  835. return trim($cur["title"]);
  836. }
  837. }
  838. function get_all_courses_in_catalog_year($catalog_year = "2006", $bool_load_descriptive_data = false, $limit_start = 0, $limit_size = 0, $school_id = 0, $bool_only_undergrad = TRUE)
  839. {
  840. // Returns a CourseList object of all the
  841. // courses in the supplied catalog_year.
  842. $lim_line = "";
  843. if ($limit_size > 0)
  844. {
  845. $lim_line = " limit $limit_start, $limit_size ";
  846. }
  847. $rtn_list = new CourseList();
  848. $c_array = array();
  849. $params = array();
  850. $params[":catalog_year"] = $catalog_year;
  851. $params[":school_id"] = $school_id;
  852. $course_num_line = "";
  853. if ($bool_only_undergrad) {
  854. $course_num_line = " AND course_num < :gradnum ";
  855. $params[":params"] = variable_get_for_school("graduate_level_course_num", 5000, $school_id);
  856. }
  857. $result = $this->db->db_query("SELECT * FROM courses
  858. WHERE
  859. catalog_year = :catalog_year
  860. $course_num_line
  861. AND school_id = :school_id
  862. ORDER BY subject_id, course_num
  863. $lim_line
  864. ", $params);
  865. while($cur = $this->db->db_fetch_array($result))
  866. {
  867. $course = new Course();
  868. $course->course_id = $cur["course_id"];
  869. $course->subject_id = $cur["subject_id"];
  870. $course->course_num = $cur["course_num"];
  871. $course->min_hours = $cur["min_hours"];
  872. $course->max_hours = $cur["max_hours"];
  873. if ($bool_load_descriptive_data == true)
  874. {
  875. $course->load_descriptive_data();
  876. }
  877. $rtn_list->add($course);
  878. }
  879. return $rtn_list;
  880. }
  881. /**
  882. * This function replaces the original method of caching the course inventory, to something which uses
  883. * a file instead of database.
  884. */
  885. function z_____cache_course_inventory($limit_start = 0, $limit_size = 4000) {
  886. // This functionality has moved to the system module to make it easier to call.
  887. // This will eventually be depricated.
  888. system_reload_and_cache_course_inventory();
  889. } // function
  890. function z__cache_course_inventory($limit_start = 0, $limit_size = 4000)
  891. {
  892. // Load courses from the inventory into the inventory cache...
  893. // Attempt to load the course inventory cache...
  894. if ($course_inventory = unserialize(@$_SESSION["fp_cache_course_inventory"]))
  895. {
  896. $GLOBALS["fp_course_inventory"] = $course_inventory;
  897. }
  898. $result = $this->db->db_query("SELECT DISTINCT course_id FROM courses
  899. WHERE
  900. course_num < ?
  901. LIMIT $limit_start, $limit_size
  902. ", variable_get("graduate_level_course_num", 5000)); // just use default?
  903. while($cur = $this->db->db_fetch_array($result))
  904. {
  905. $course_id = $cur["course_id"];
  906. $this->db->load_course_descriptive_data(null, $course_id);
  907. }
  908. // Should we re-cache the course inventory? If there have been any changes
  909. // to it, then we will see that in a GLOBALS variable...
  910. if ($GLOBALS["cache_course_inventory"] == true)
  911. {
  912. $_SESSION["fp_cache_course_inventory"] = serialize($GLOBALS["fp_course_inventory"]);
  913. }
  914. }
  915. function replace_missing_course_in_group($course_id, $group_id)
  916. {
  917. // Given a group in the degree plan, this will
  918. // make sure that course is actually in the group. If it
  919. // is not, then it will add it in where it should be.
  920. // This is necessary because we have previously removed
  921. // courses which the student hadn't taken. Well, if the
  922. // student was advised for a particular course in a group,
  923. // then that course probably was originally removed
  924. // from the group. So, put it back in.
  925. // Were we given a valid group_id?
  926. if (!$group_id) return;
  927. // First, find the group.
  928. if (!$group = $this->degree_plan->find_group($group_id))
  929. {
  930. fpm("Admin note: could not find group '$group_id' for replace_missing_course_in_group, for course '$course_id'.");
  931. return;
  932. }
  933. // Okay, now tell the group to replace the instance of this course
  934. // in the group. This is made easy, because we have
  935. // the dbGroupRequirementID, which is the actual id from the
  936. // row in group_requirements that this course was advised from.
  937. $group->replace_missing_course($course_id);
  938. }
  939. function save_advising_session_from_post($faculty_id = 0, $bool_draft = true)
  940. {
  941. global $user;
  942. $catalog_year = 0;
  943. $bool_fp_goto_at_end = FALSE;
  944. // This method will, only by looking at variables in the
  945. // POST, save an advising session into the database.
  946. $db = get_global_database_handler();
  947. if ($faculty_id == 0) {
  948. // if none supplied, use the one from the session of
  949. // whomever is currently logged in.
  950. $faculty_id = $user->cwid;
  951. }
  952. $advising_session_token = $db->request_new_advising_session_token();
  953. // It's possible the user has simply pressed "refresh" after submitting the form. If so,
  954. // there is no reason to re-submit everything, creating duplicate data in some situations.
  955. $post_md5 = md5(serialize($_POST));
  956. if (@$_SESSION["fp_previous_advising_post_md5"] == $post_md5) {
  957. return array();
  958. }
  959. // We may proceed, but save the POST md5 for next time.
  960. $_SESSION["fp_previous_advising_post_md5"] = $post_md5;
  961. $bool_found_update_match = false;
  962. $student_id = $this->student->student_id;
  963. $school_id = db_get_school_id_for_student_id($student_id);
  964. $degree_id = $this->degree_plan->degree_id;
  965. $major_code_csv = $this->degree_plan->get_major_code_csv();
  966. $catalog_year = $this->degree_plan->catalog_year;
  967. $available_terms = variable_get_for_school("available_advising_term_ids", "0", $school_id);
  968. // Do we need to update the student's settings?
  969. if (trim($_POST["advising_update_student_settings_flag"]) != "")
  970. {
  971. // We are to assume that the student's array_settings
  972. // have already been updated by this point, so we will
  973. // simply convert them to XML and store in the database.
  974. $result = $db->db_query("REPLACE INTO student_settings
  975. (student_id, settings, posted)
  976. VALUES ('?','?', '?' ) ", $student_id, serialize($this->student->array_settings), time());
  977. watchdog("update_student_settings", "Settings updated for this student.");
  978. }
  979. //var_dump($_POST);
  980. // die;
  981. // We have changed tracks, so we are to edit the student degrees table.
  982. if ($_POST["advising_update_student_degrees_flag"] == "true") {
  983. // Begin by deleting all the "editable" rows for this student
  984. // in student_degrees.
  985. db_query("DELETE FROM student_degrees
  986. WHERE student_id = '?'
  987. AND is_editable = '1' ", $student_id);
  988. // Now, go through our list of degree tracks ids we're adding back in, and add to the table.
  989. $temp = explode(",", $_POST["advising_track_degree_ids"]);
  990. foreach ($temp as $tdegree_id) {
  991. if (trim($tdegree_id) == "") continue;
  992. if (!is_numeric($tdegree_id)) continue;
  993. $tdegree_plan = fp_load_degree($tdegree_id, NULL, TRUE);
  994. $tmajor_code = $tdegree_plan->major_code;
  995. /* // shouldn't need this anymore, as the major_code will contain both the major and track in one.
  996. $tmajor_code = $tdegree_plan->major_code;
  997. if (!strstr($tmajor_code, "|")) {
  998. $tmajor_code .= "|";
  999. }
  1000. $tmajor_code .= "_" . $tdegree_plan->track_code;
  1001. */
  1002. db_query("INSERT INTO student_degrees
  1003. (student_id, major_code, is_editable)
  1004. VALUES ('?', '?', '1')", $student_id, $tmajor_code);
  1005. }
  1006. // Reset the SESSION variables and re-init, so we get the correct
  1007. // major codes and track codes for this student.
  1008. $_SESSION["advising_track_degree_ids$student_id"] = "";
  1009. $_SESSION["advising_major_code$student_id"] = "";
  1010. $_REQUEST["advising_major_code"] = "";
  1011. $_REQUEST["advising_track_degree_ids"] = "";
  1012. $this->student->load_student_data();
  1013. // force re-build of cache
  1014. //$_REQUEST["load_from_cache"] = "no";
  1015. //$_SESSION["cache_fp$student_id"] = "";
  1016. //$_SESSION["cache_what_if$student_id"] = "";
  1017. $GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1018. $this->init(TRUE);
  1019. $bool_fp_goto_at_end = TRUE;
  1020. } // editing degrees?
  1021. // Is there anything in "log_addition" which we should write to the log?
  1022. if ($_POST["log_addition"] != "")
  1023. {
  1024. $temp = explode("~",$_POST["log_addition"]);
  1025. if ($temp[0] == "change_term") {
  1026. watchdog("change_term", "$student_id," . $temp[1]);
  1027. }
  1028. if ($temp[0] == "change_track"){
  1029. watchdog("change_track", "$student_id," . $temp[1]);
  1030. }
  1031. }
  1032. // If this user cannot advise, then just return right now.
  1033. if (!user_has_permission("can_advise_students")) {
  1034. return;
  1035. }
  1036. // First, create a new entry in the advising_sessions table,
  1037. // so we can get the advising_session_id.
  1038. // But before we can do that, we look for an existing entry
  1039. // which matches this. If we find it, we delete it so the
  1040. // new one will display instead.
  1041. // Only delete if its a draft copy!
  1042. $is_draft = intval($bool_draft);
  1043. $is_what_if = intval($this->bool_what_if);
  1044. // Since we only want one draft copy per term/per student and faculty,
  1045. // let's delete
  1046. // any draft copies already in existence, if we are saving a draft.
  1047. $result = $db->db_query("DELETE FROM advising_sessions
  1048. WHERE student_id = ?
  1049. AND is_draft = 1
  1050. AND faculty_id = ?
  1051. AND degree_id = ?
  1052. AND is_whatif = ? ", $student_id, $faculty_id, $degree_id, $is_what_if);
  1053. // Set all other advising sessions' "most_recent_session" flag to zero (0) for this student (but only if this is NOT an "is_draft" save!)
  1054. if ($is_draft === 0) {
  1055. db_query("UPDATE advising_sessions SET most_recent_session = 0 WHERE student_id = ?", array($student_id));
  1056. }
  1057. // The first thing we need to do is go through the available_terms,
  1058. // create new entries for them in the table, and store what their
  1059. // session ID's are in an array.
  1060. $advising_session_id_array = array();
  1061. $advising_session_id_array_count = array();
  1062. $posted = time();
  1063. $temp = explode(",",$available_terms);
  1064. foreach ($temp as $term_id)
  1065. {
  1066. $term_id = trim($term_id);
  1067. if ($term_id == "") { continue; }
  1068. // Okay, now create a new entry in the system for that term.
  1069. // We create entries for all available terms, whether we
  1070. // are going to use them later or not.
  1071. $result = $db->db_query("INSERT INTO advising_sessions
  1072. (student_id, faculty_id, term_id, degree_id,
  1073. major_code_csv,
  1074. catalog_year, posted, is_whatif, is_draft, advising_session_token, delete_flag, most_recent_session)
  1075. VALUES
  1076. (?,?,?,?,?,?,?,?,?,?, 0, 1)
  1077. ", $student_id, $faculty_id,$term_id,$degree_id, $major_code_csv, $catalog_year, $posted, $is_what_if, $is_draft, $advising_session_token);
  1078. $advising_session_id = db_insert_id();
  1079. $advising_session_id_array[$term_id] = $advising_session_id;
  1080. $advising_session_id_array_count[$term_id] = 0;
  1081. }
  1082. $wi = "";
  1083. if ($is_what_if == "1"){$wi = "_whatif";}
  1084. if ($bool_draft) {
  1085. watchdog("save_adv_draft$wi", "$student_id,major_code_csv:$major_code_csv");
  1086. }
  1087. else {
  1088. watchdog("save_adv_active$wi", "$student_id,major_code_csv:$major_code_csv");
  1089. }
  1090. // Go through the POST, looking for the
  1091. // phrase "advisecourse_" in the name of the variables.
  1092. // There should be one of these for every course that was
  1093. // on the page. It looks like this:
  1094. // advisecourse_course_id_semesterNum_group_id_varHours_randomID
  1095. foreach($_POST as $key => $value)
  1096. {
  1097. if (!strstr($key,"advisecourse_") && !(strstr($key, "advcr_")))
  1098. { // Skip vars which don't have this as part of the name.
  1099. // We accept either advisecourse_ or advcr_ for short. advisecourse_ is the old way.
  1100. // I changed to use advcr_ to save space, because some browsers will not allow long input names.
  1101. continue;
  1102. }
  1103. if ($value != "true")
  1104. { // This means the course was *not* advised to be taken,
  1105. // so, skip it.
  1106. continue;
  1107. }
  1108. // The key might contain a DoT (dot placeholder) instead of a period. If so, let's
  1109. // add the period back in. This was to correct a bug where courses with dots couldn't
  1110. // be advised.
  1111. if (strstr($key, "DoT")) {
  1112. $key = str_replace("DoT", ".", $key);
  1113. }
  1114. $temp = explode("_",$key);
  1115. $course_id = trim($temp[1]);
  1116. $semester_num = trim($temp[2]);
  1117. $group_id = str_replace("U", "_", trim($temp[3])); // replace U with _, which was required for the submission to work (couldn't use the _ in group_id.)
  1118. $var_hours = trim($temp[4]) * 1;
  1119. $random_id = trim($temp[5]);
  1120. $advised_term_id = trim($temp[6]);
  1121. //$db_group_requirement_id = trim($temp[7]);
  1122. $degree_id = trim($temp[7]);
  1123. if ($degree_id == "group") {
  1124. // Get degree_id from the group_id.
  1125. $tt = explode("_", $group_id);
  1126. $degree_id = $tt[1];
  1127. }
  1128. $advising_session_id = $advising_session_id_array[$advised_term_id];
  1129. $new_course = new Course($course_id);
  1130. $new_course->load_descriptive_data();
  1131. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1132. // Some particular course should be updated. Possibly this one.
  1133. // Updates happen because of a student changing the
  1134. // variable hours, for example.
  1135. if (trim(@$_POST["updatecourse"]) != "")
  1136. {
  1137. $temp2 = explode("~",trim($_POST["updatecourse"]));
  1138. $tcourse_id = $temp2[0];
  1139. $tgroup_id = $temp2[1];
  1140. $tsemester_num = $temp2[2];
  1141. $tvar_hours = $temp2[3];
  1142. $trandom_id = $temp2[4];
  1143. $tadvised_term_id = $temp2[5];
  1144. $tdegree_id = $temp2[6];
  1145. // Do we have a match?
  1146. if ($course_id == $tcourse_id && $random_id == $trandom_id)
  1147. {
  1148. // We have a match, so update with the new information.
  1149. $var_hours = $tvar_hours;
  1150. $degree_id = $tdegree_id;
  1151. $new_course = new Course($tcourse_id);
  1152. $new_course->load_descriptive_data();
  1153. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1154. $bool_found_update_match = true;
  1155. }
  1156. }
  1157. if ($group_id != 0)
  1158. {
  1159. $this->replace_missing_course_in_group($course_id, $group_id);
  1160. }
  1161. // Make sure degree_id is a valid number for the database.
  1162. if (!is_numeric($degree_id) || intval($degree_id) < 0) {
  1163. $degree_id = 0;
  1164. }
  1165. // Okay, write it to the table...
  1166. $result = $db->db_query("INSERT INTO advised_courses
  1167. (`advising_session_id`,`course_id`,
  1168. `entry_value`,`semester_num`,
  1169. `group_id`,`var_hours`,`term_id`, `degree_id`)
  1170. VALUES
  1171. ('?','?','?','?','?','?','?','?')
  1172. ", $advising_session_id, $course_id, $entry_value, $semester_num, $group_id, $var_hours, $advised_term_id, $degree_id);
  1173. $advising_session_id_array_count[$advised_term_id]++;
  1174. }
  1175. // Did we have to perform an update-- but no course was found?
  1176. if (trim(@$_POST["updatecourse"]) != "" && $bool_found_update_match == false)
  1177. {
  1178. // This means that the course was probably on the bare
  1179. // degree program, and not already checked for advising. So,
  1180. // let's add it to the advised_courses table, so it DOES
  1181. // get checked for advising.
  1182. $temp2 = explode("~",trim($_POST["updatecourse"]));
  1183. $course_id = $temp2[0];
  1184. $group_id = $temp2[1];
  1185. $semester_num = $temp2[2];
  1186. $var_hours = $temp2[3];
  1187. $advised_term_id = $temp2[5];
  1188. $degree_id = $temp2[6];
  1189. $new_course = new Course($course_id);
  1190. $new_course->load_descriptive_data();
  1191. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1192. $advising_session_id = $advising_session_id_array[$advised_term_id];
  1193. $result = $db->db_query("INSERT INTO advised_courses
  1194. (`advising_session_id`,`course_id`,`entry_value`,`semester_num`,
  1195. `group_id`,`var_hours`,`term_id`,`degree_id`)
  1196. VALUES
  1197. ('?','?','?','?','?','?','?','?')
  1198. ", $advising_session_id,$course_id,$entry_value,$semester_num,$group_id,$var_hours,$advised_term_id,$degree_id);
  1199. $advising_session_id_array_count[$advised_term_id]++;
  1200. if ($group_id != 0)
  1201. {
  1202. $this->replace_missing_course_in_group($course_id, $group_id);
  1203. }
  1204. }
  1205. //------------------------------------------------------
  1206. //
  1207. // Substitutions...
  1208. //
  1209. //-------------------------------------------------------
  1210. // check permissions for substitutions before saving
  1211. if (trim(@$_POST["savesubstitution"]) != "" && user_has_permission("can_substitute")) {
  1212. $temp = explode("~",trim($_POST["savesubstitution"]));
  1213. $course_id = $temp[0]; // required course
  1214. $group_id = trim($temp[1]);
  1215. $req_by_degree_id = $temp[2];
  1216. $semester_num = $temp[3] * 1;
  1217. $sub_course_id = $temp[4];
  1218. $sub_term_id = $temp[5];
  1219. $sub_transfer_flag = $temp[6];
  1220. $sub_hours = $temp[7] * 1;
  1221. $sub_addition = $temp[8];
  1222. $sub_remarks = urldecode($temp[9]);
  1223. if ($sub_addition == "true")
  1224. {
  1225. $course_id = 0;
  1226. }
  1227. // Figure out the entry values for the required course & sub course...
  1228. $required_entry_value = $sub_entry_value = "";
  1229. if ($course_id > 0)
  1230. {
  1231. $new_course = new Course($course_id);
  1232. $new_course->load_descriptive_data();
  1233. $required_entry_value = "$new_course->subject_id~$new_course->course_num";
  1234. }
  1235. if ($sub_transfer_flag != 1)
  1236. {
  1237. $new_course = new Course($sub_course_id);
  1238. $new_course->load_descriptive_data();
  1239. $sub_entry_value = "$new_course->subject_id~$new_course->course_num";
  1240. }
  1241. if ($group_id != 0 && $course_id != 0)
  1242. {
  1243. $this->replace_missing_course_in_group($course_id, $group_id);
  1244. }
  1245. // Make sure the sub_hours aren't larger than the sub_course_id's awarded hours.
  1246. // This is to stop a bug from happening where sometimes, some people are able to substitute
  1247. // a course for larger than the awarded hours. I believe it is a javascript bug.
  1248. if ($test_c = $this->student->list_courses_taken->find_specific_course($sub_course_id, $sub_term_id, (bool) $sub_transfer_flag, true)) {
  1249. // Are the hours out of whack?
  1250. if (floatval($sub_hours) > floatval($test_c->get_hours_awarded($req_by_degree_id))) {
  1251. // Yes! Set it to the value of the hours_awarded.
  1252. $sub_hours = floatval($test_c->get_hours_awarded($req_by_degree_id));
  1253. }
  1254. }
  1255. $result = $db->db_query("INSERT INTO student_substitutions
  1256. (`student_id`,`faculty_id`,`required_course_id`,`required_entry_value`,
  1257. `required_group_id`,`required_degree_id`,`required_semester_num`,`sub_course_id`,`sub_entry_value`,
  1258. `sub_term_id`,`sub_transfer_flag`,`sub_hours`,`sub_remarks`,`posted`)
  1259. VALUES
  1260. ('?','?','?','?','?','?','?','?','?','?','?','?','?','?')
  1261. ", $student_id,$faculty_id,$course_id,$required_entry_value,$group_id,$req_by_degree_id,$semester_num,$sub_course_id,$sub_entry_value,$sub_term_id,$sub_transfer_flag,$sub_hours,$sub_remarks, time());
  1262. watchdog("save_substitution", "$student_id,group_id:$group_id,insert_id:" . db_insert_id());
  1263. }
  1264. if (trim(@$_POST["removesubstitution"]) != "")
  1265. {
  1266. $temp = explode("~",trim($_POST["removesubstitution"]));
  1267. $sub_id = trim($temp[0]) * 1;
  1268. $result = $db->db_query("UPDATE student_substitutions
  1269. SET `delete_flag`='1'
  1270. WHERE `id`='?' ", $sub_id);
  1271. watchdog("remove_substitution", "$student_id,sub_id:$sub_id");
  1272. }
  1273. //------------------------------------------------------
  1274. //
  1275. // Group Unassignments
  1276. //
  1277. //-------------------------------------------------------
  1278. if (trim(@$_POST["unassign_group"]) != "")
  1279. {
  1280. $temp = explode("~",trim($_POST["unassign_group"]));
  1281. $course_id = $temp[0];
  1282. $term_id = $temp[1];
  1283. $transfer_flag = $temp[2];
  1284. $group_id = $temp[3];
  1285. $degree_id = $temp[4];
  1286. $result = db_query("INSERT INTO student_unassign_group
  1287. (`student_id`,`faculty_id`,`course_id`,
  1288. `term_id`,`transfer_flag`,`group_id`,`degree_id`,
  1289. `posted`)
  1290. VALUES
  1291. ('?','?','?','?','?','?','?','?')
  1292. ", $student_id,$faculty_id,$course_id,$term_id,$transfer_flag,$group_id,$degree_id,time());
  1293. watchdog("save_unassign_group", "$student_id,group_id:$group_id,degree_id:$degree_id");
  1294. }
  1295. if (trim(@$_POST["restore_unassign_group"]) != "")
  1296. {
  1297. $temp = explode("~",trim($_POST["restore_unassign_group"]));
  1298. $unassign_id = trim($temp[0]) * 1;
  1299. $result = $db->db_query("UPDATE student_unassign_group
  1300. SET `delete_flag`='1'
  1301. WHERE `id`='?' ", $unassign_id);
  1302. watchdog("restore_unassign_group", "$student_id,unassign_id:$unassign_id");
  1303. }
  1304. //------------------------------------------------------
  1305. //
  1306. // Transfer EQV Unassignments
  1307. //
  1308. //-------------------------------------------------------
  1309. if (trim(@$_POST["unassign_transfer_eqv"]) != "")
  1310. {
  1311. $temp = explode("~",trim($_POST["unassign_transfer_eqv"]));
  1312. $course_id = $temp[0];
  1313. $result = $db->db_query("INSERT INTO student_unassign_transfer_eqv
  1314. (`student_id`,`faculty_id`,`transfer_course_id`,
  1315. `posted`)
  1316. VALUES
  1317. ('?','?','?','?')
  1318. ", $student_id, $faculty_id, $course_id, time());
  1319. watchdog("save_unassign_transfer", "$student_id,course_id:$course_id");
  1320. }
  1321. if (trim(@$_POST["restore_transfer_eqv"]) != "")
  1322. {
  1323. $temp = explode("~",trim($_POST["restore_transfer_eqv"]));
  1324. $unassign_id = trim($temp[0]) * 1;
  1325. $result = $db->db_query("UPDATE student_unassign_transfer_eqv
  1326. SET `delete_flag`='1'
  1327. WHERE `id`='?' ", $unassign_id);
  1328. watchdog("restore_unassign_transfer", "$student_id,unassign_id:$unassign_id");
  1329. }
  1330. ////////////////////////////////////////////////////
  1331. /////// Cleanup !////////////////////////////////
  1332. ////////////////////////////////////////////////////
  1333. // If any of the advisingSessions we created earlier
  1334. // are blank, we should FLAG them, so they will not
  1335. // show up under the student's history.
  1336. // Only flag non-draft empty ones. If they are draft,
  1337. // let them be.
  1338. // We just look at $advising_session_id_array_count[] to see
  1339. // if any of the counts are still 0. If they are, delete
  1340. // that advisingSessionID from the table.
  1341. if ($is_draft == 0)
  1342. {
  1343. foreach ($advising_session_id_array as $term_id => $advising_session_id)
  1344. {
  1345. if ($advising_session_id_array_count[$term_id] == 0)
  1346. {
  1347. // This one is blank! Delete it!
  1348. $res = $db->db_query("UPDATE advising_sessions
  1349. SET is_empty = 1
  1350. WHERE advising_session_id = ? ", $advising_session_id);
  1351. $advising_session_id_array[$term_id] = "";
  1352. }
  1353. }
  1354. }
  1355. watchdog("advising", "Student has been advised: @student", array("@student" => $student_id));
  1356. // Call a hook so other modules can act when the advising session gets saved.
  1357. invoke_hook('save_advising_session_from_post', array($student_id, $is_draft, $advising_session_id_array));
  1358. // Instead of executing the page, we will issue a redirect using fp_goto.
  1359. // This makes it so if the user hits "refresh", it will not re-submit a POST request.
  1360. if ($bool_fp_goto_at_end) {
  1361. // Goto the same page we are already on. This mimics Drupal's Form API behavior.
  1362. $q = $_REQUEST['q'];
  1363. fp_goto($q, "advising_major_code=&load_from_cache=no&advising_student_id=$student_id");
  1364. }
  1365. return $advising_session_id_array;
  1366. }
  1367. function load_advising_session_from_database($faculty_id = 0, $term_id = "", $bool_what_if = false, $bool_draft = true, $advising_session_id = 0, $duplicate_for_faculty_id = 0)
  1368. {
  1369. global $user;
  1370. // This method will load an advising session for a particular
  1371. // student, and modify the degree plan object to reflect
  1372. // the advisings.
  1373. $db = get_global_database_handler();
  1374. $is_what_if = "0";
  1375. $is_draft = "0";
  1376. if ($bool_what_if == true){$is_what_if = "1";}
  1377. if ($bool_draft == true){$is_draft = "1";}
  1378. $degree_id = $this->degree_plan->degree_id;
  1379. $student_id = $this->student->student_id;
  1380. $school_id = db_get_school_id_for_student_id($student_id);
  1381. $available_terms = variable_get_for_school("available_advising_term_ids", "0", $school_id);
  1382. // If we are pulling up an active student record, then let's
  1383. // delete any draft sessions for this faculty user and student, so as not to cause
  1384. // a bug later on when changing tabs. We don't care if $faculty_id is set or not, just
  1385. // the current user's CWID.
  1386. if ($bool_draft == FALSE && $user->cwid != 0) {
  1387. $res = db_query("DELETE FROM advising_sessions
  1388. WHERE student_id = ?
  1389. AND faculty_id = ?
  1390. AND is_draft = 1
  1391. ", $student_id, $user->cwid);
  1392. }
  1393. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  1394. // First, find the advising session id...
  1395. if ($advising_session_id < 1 && $available_terms == "")
  1396. {
  1397. $advising_session_id = $this->db->get_advising_session_id($faculty_id, $student_id, $term_id, $degree_id, $bool_what_if, $bool_draft, TRUE);
  1398. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  1399. // Create a duplicate of this session as a draft...
  1400. if ($bool_draft == FALSE) {
  1401. $db->duplicate_advising_session($advising_session_id, $duplicate_for_faculty_id, "", "", "", "", 1);
  1402. }
  1403. } else if ($advising_session_id < 1 && $available_terms != "")
  1404. {
  1405. // Meaning, we are looking for more than one term.
  1406. $advising_session_line = "(";
  1407. $temp = explode(",",$available_terms);
  1408. for ($t = 0; $t < count($temp); $t++)
  1409. {
  1410. $t_id = trim($temp[$t]);
  1411. $asid = $this->db->get_advising_session_id($faculty_id, $student_id, $t_id,$degree_id, $bool_what_if, $bool_draft, TRUE);
  1412. if ($asid != 0)
  1413. {
  1414. $advising_session_line .= " advising_session_id='$asid' || ";
  1415. // Create a duplicate of this session as a draft...
  1416. if ($bool_draft == FALSE) {
  1417. $db->duplicate_advising_session($asid, $duplicate_for_faculty_id, "", "", "", "", 1);
  1418. }
  1419. }
  1420. }
  1421. // Take off the last 3 chars...
  1422. $advising_session_line = substr($advising_session_line, 0, -3);
  1423. $advising_session_line .= ")";
  1424. if ($advising_session_line == ")")
  1425. { // Found NO previously advised semesters, so just
  1426. // use a dummy value which guarantees it pulls up nothing.
  1427. $advising_session_line = " advising_session_id='-99999'";
  1428. }
  1429. }
  1430. // Now, look up the courses they were advised to take.
  1431. $query = "SELECT * FROM advised_courses
  1432. WHERE
  1433. $advising_session_line
  1434. ORDER BY `id` ";
  1435. $result = $db->db_query($query);
  1436. while($cur = $db->db_fetch_array($result))
  1437. {
  1438. $course_id = trim($cur["course_id"]);
  1439. $semester_num = trim($cur["semester_num"]);
  1440. $group_id = trim($cur["group_id"]);
  1441. $degree_id = $cur["degree_id"];
  1442. $var_hours = trim($cur["var_hours"]);
  1443. $advised_term_id = trim($cur["term_id"]);
  1444. $id = trim($cur["id"]);
  1445. // Add this course to the generic list of advised courses. Useful
  1446. // if we are using this to pull up an advising summary.
  1447. $temp_course = new Course($course_id);
  1448. $temp_course->advised_hours = $var_hours;
  1449. $this->course_list_advised_courses->add($temp_course);
  1450. if ($semester_num == DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED)
  1451. {
  1452. // This was a courses added by the advisor.
  1453. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1454. continue;
  1455. }
  1456. // Now, we need to modify the degree_plan object to
  1457. // show these advisings.
  1458. if ($course_list = $this->degree_plan->find_courses($course_id, $group_id, $semester_num, $degree_id))
  1459. {
  1460. // This course may exist in several different branches of a group, so we need
  1461. // to mark all the branches as having been advised to take. Usually, this CourseList
  1462. // will probably only have 1 course object in it. But, better safe than sorry.
  1463. $course_list->reset_counter();
  1464. if ($course = $course_list->get_next())
  1465. {
  1466. // make sure the hour count has been loaded correctly.
  1467. if ($course->get_catalog_hours() < 1)
  1468. {
  1469. $course->load_descriptive_data();
  1470. }
  1471. // Let's start by looking at the first course. Is it
  1472. // supposed to be repeated?
  1473. if ($course->bool_specified_repeat==true
  1474. && $course->specified_repeats >= 0 )
  1475. {
  1476. // This is a course which is supposed to be repeated.
  1477. // We need to cycle through and find an instance
  1478. // of this course which has not been advised yet.
  1479. $course_list->reset_counter();
  1480. while($course_list->has_more())
  1481. {
  1482. $course = $course_list->get_next();
  1483. // make sure the hour count has been loaded correctly.
  1484. if ($course->get_catalog_hours() < 1)
  1485. {
  1486. $course->load_descriptive_data();
  1487. }
  1488. ////////////////////
  1489. // Logan's change: https://bytetask.com/node/2455
  1490. // If we have the setting which says we should skip if it's already been completed/enrolled for this term,
  1491. // then we should do that.
  1492. if (variable_get_for_school("remove_advised_when_course_taken", "no", $school_id) == "yes") {
  1493. // First, see if this advised course has been attempted already.
  1494. if ($this->student->list_courses_taken->find_specific_course($course->course_id, $advised_term_id)) {
  1495. // Yep, found it! So, skip this one.
  1496. continue;
  1497. }
  1498. }
  1499. //////////////////////////
  1500. //if ($course->bool_advised_to_take != true && !is_object($course->courseFulfilledBy))
  1501. if ($course->bool_advised_to_take != true && $course->course_list_fulfilled_by->is_empty == true)
  1502. {
  1503. // Okay, this course is supposed to be taken/advised
  1504. // more than once. So, I will mark this one as
  1505. // advised, and then break out of the loop, since
  1506. // I don't want to mark all occurances as advised.
  1507. $course->bool_advised_to_take = true;
  1508. $course->assigned_to_semester_num = $semester_num;
  1509. //$course->assigned_to_group_id = $group_id;
  1510. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1511. // Make sure we assign the hours to the group, so this
  1512. // advised courses takes up a spot in the group. Otherwise
  1513. // it may be missed in later logic.
  1514. if ($g = $this->degree_plan->find_group($group_id)) {
  1515. $h = $var_hours;
  1516. if ($h == 0) {
  1517. $h = $course->get_catalog_hours();
  1518. if ($h == 0) {
  1519. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1520. // horribly break.
  1521. }
  1522. }
  1523. $g->hours_assigned += $h;
  1524. }
  1525. $course->advised_hours = $var_hours;
  1526. $course->advised_term_id = $advised_term_id;
  1527. $course->db_advised_courses_id = $id;
  1528. $course_list->dec_specified_repeats($course);
  1529. break;
  1530. }
  1531. }
  1532. continue; // Go to the next advised course.
  1533. }
  1534. } // if $course = $course_list->get_next();
  1535. //////////////////////////////
  1536. // We're here, because it was not a repeatable course.
  1537. // ** We should only go through THIS loop once! So,
  1538. // we will break after we make our assignment.
  1539. $course_list->reset_counter();
  1540. while($course_list->has_more())
  1541. {
  1542. $course = $course_list->get_next();
  1543. // make sure the hour count has been loaded correctly.
  1544. if ($course->get_catalog_hours() < 1)
  1545. {
  1546. $course->load_descriptive_data();
  1547. }
  1548. // make sure it has not already been advised to take.
  1549. // Would occur if the same course is specified more
  1550. // than once in a semester.
  1551. if ($course->bool_advised_to_take == true)
  1552. {
  1553. continue;
  1554. }
  1555. // If we have the setting which says we should skip if it's already been completed/enrolled for this term,
  1556. // then we should do that.
  1557. if (variable_get_for_school("remove_advised_when_course_taken", "no", $school_id) == "yes") {
  1558. // First, see if this advised course has been attempted already.
  1559. if ($taken_course = $this->student->list_courses_taken->find_specific_course($course->course_id, $advised_term_id)) {
  1560. // Yep, found it! So, skip this one.
  1561. continue;
  1562. }
  1563. }
  1564. // Has this course already been fulfilled by something?
  1565. // If so, we cannot attempt to say it's been advised!
  1566. if (!$course->course_list_fulfilled_by->is_empty)
  1567. {
  1568. // meaning, this course HAS been fulfilled.
  1569. // So, let's move this advising to the "added by advisor"
  1570. // spot.
  1571. /* This is the original bit of code here. It is causing a problem when there are courses which are supposed to be
  1572. * repeated. Example: MUSC courses which are advised one term at a time.
  1573. *
  1574. *
  1575. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1576. break;
  1577. *
  1578. * Strategy: Find out how many courses are in this course_list by looking at the size of the list. If it's > 1, then just continue. If it == 1, then
  1579. * do the original logic.
  1580. *
  1581. */
  1582. if ($course_list->get_size() > 1) {
  1583. continue;
  1584. }
  1585. else {
  1586. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1587. break;
  1588. }
  1589. }
  1590. $course->bool_advised_to_take = true;
  1591. $course->assigned_to_semester_num = $semester_num;
  1592. //$course->assigned_to_group_id = $group_id;
  1593. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1594. // Make sure we assign the hours to the group, so this
  1595. // advised courses takes up a spot in the group. Otherwise
  1596. // it may be missed in later logic.
  1597. if ($g = $this->degree_plan->find_group($group_id)) {
  1598. $h = $var_hours;
  1599. if ($h == 0) {
  1600. $h = $course->get_catalog_hours();
  1601. if ($h == 0) {
  1602. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1603. // horribly break.
  1604. }
  1605. }
  1606. $g->hours_assigned += $h;
  1607. }
  1608. $course->advised_hours = $var_hours;
  1609. $course->advised_term_id = $advised_term_id;
  1610. $course->db_advised_courses_id = $id;
  1611. if ($course->required_on_branch_id > 0)
  1612. {
  1613. // In other words, this course was found on a branch, so we need
  1614. // to increment that branch's count_of_matches.
  1615. if ($branch = $this->degree_plan->find_group($course->required_on_branch_id))
  1616. {
  1617. $branch->count_of_matches++;
  1618. } else {
  1619. fpm("Error: Could not find branch.");
  1620. }
  1621. }
  1622. // We should only be in this loop once, so let's
  1623. // break after we make our assignment.
  1624. break;
  1625. }
  1626. }
  1627. }
  1628. // Now, what we need to do is tell the DegreePlan to re-sort its
  1629. // group's course lists, so that the advised courses are lower
  1630. // than the fulfilled courses.
  1631. //$this->degree_plan->sortGroupsFulfilledFirst();
  1632. //print_pre($this->degree_plan->list_groups->toString());
  1633. } // function loadAdvisingSessionFromDatabase
  1634. function split_requirements_by_substitutions()
  1635. {
  1636. // Go through all the required courses on the degree plan,
  1637. // and if there is a partial substitution specified in the student's
  1638. // list of substitutions, then split that requirement into 2 courses,
  1639. // one with enough hours to satisfy the sub, and the remaining hours.
  1640. $degree_plan = $this->degree_plan;
  1641. $student = $this->student;
  1642. $student->list_substitutions->reset_counter();
  1643. while($student->list_substitutions->has_more())
  1644. {
  1645. $substitution = $student->list_substitutions->get_next();
  1646. $course_requirement = $substitution->course_requirement;
  1647. $course_sub = $substitution->course_list_substitutions->get_first();
  1648. // TODO: This could be an important part right here
  1649. // Check to see if the courseSub's hours_awarded are less than the
  1650. // course_requirement's min hours...
  1651. if ($course_requirement->min_hours > $course_sub->get_hours_awarded())
  1652. {
  1653. // Meaning the original course requirement is not being
  1654. // fully satisfied by this substitution! The original
  1655. // course requirement has hours left over which must be
  1656. // fulfilled somehow.
  1657. $remaining_hours = round($course_requirement->min_hours - $course_sub->get_hours_awarded(), 6);
  1658. // This means that the course requirement needs to be split.
  1659. // So, find this course in the degree plan.
  1660. $required_course_id = $course_requirement->course_id;
  1661. //$required_group_id = $course_requirement->assigned_to_group_id;
  1662. $required_group_id = $course_requirement->get_first_assigned_to_group_id(); // we assume a course requirement is only assigned to 1 group.
  1663. $required_semester_num = $course_requirement->assigned_to_semester_num;
  1664. }
  1665. }
  1666. } // split_requirements_by_substitution
  1667. function assign_course_to_courses_added_list($course_id, $var_hours = 0, $db_advised_courses_id = 0, $advised_term_id = 0)
  1668. {
  1669. // Set the supplied course as "advised to take" in the degree plan's
  1670. // special added courses group, which is number -88.
  1671. $course = new Course($course_id, false, $this->db);
  1672. $course->bool_advised_to_take = true;
  1673. $course->assigned_to_semester_num = DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED;
  1674. //$course->assigned_to_group_id = -88;
  1675. $course->assigned_to_group_ids_array[DegreePlan::GROUP_ID_FOR_COURSES_ADDED] = DegreePlan::GROUP_ID_FOR_COURSES_ADDED;
  1676. $course->advised_hours = $var_hours;
  1677. $course->db_advised_courses_id = $db_advised_courses_id;
  1678. $course->advised_term_id = $advised_term_id;
  1679. if ($group = $this->degree_plan->find_group(DegreePlan::GROUP_ID_FOR_COURSES_ADDED))
  1680. {
  1681. $group->list_courses->add($course);
  1682. }
  1683. // Done!
  1684. }
  1685. }

Classes

Namesort descending Description
FlightPath