FlightPath.php

  1. 7.x classes/FlightPath.php
  2. 6.x classes/FlightPath.php
  3. 4.x custom/classes/FlightPath.php
  4. 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 (floatval($course_requirement->min_hours) > floatval($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, $bool_skip_excluded = FALSE)
  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. $exclude_line = "";
  853. if ($bool_skip_excluded) {
  854. $exclude_line = " AND exclude = 0 ";
  855. }
  856. $course_num_line = "";
  857. if ($bool_only_undergrad) {
  858. $course_num_line = " AND course_num < :gradnum ";
  859. $params[":params"] = variable_get_for_school("graduate_level_course_num", 5000, $school_id);
  860. }
  861. $result = $this->db->db_query("SELECT * FROM courses
  862. WHERE
  863. catalog_year = :catalog_year
  864. $course_num_line
  865. AND school_id = :school_id
  866. AND delete_flag = 0
  867. $exclude_line
  868. ORDER BY subject_id, course_num
  869. $lim_line
  870. ", $params);
  871. while($cur = $this->db->db_fetch_array($result))
  872. {
  873. $course = new Course();
  874. $course->course_id = $cur["course_id"];
  875. $course->subject_id = $cur["subject_id"];
  876. $course->course_num = $cur["course_num"];
  877. $course->min_hours = $cur["min_hours"];
  878. $course->max_hours = $cur["max_hours"];
  879. if ($bool_load_descriptive_data == true)
  880. {
  881. $course->load_descriptive_data();
  882. }
  883. $rtn_list->add($course);
  884. }
  885. return $rtn_list;
  886. }
  887. /**
  888. * This function replaces the original method of caching the course inventory, to something which uses
  889. * a file instead of database.
  890. */
  891. function z_____cache_course_inventory($limit_start = 0, $limit_size = 4000) {
  892. // This functionality has moved to the system module to make it easier to call.
  893. // This will eventually be depricated.
  894. system_reload_and_cache_course_inventory();
  895. } // function
  896. function z__cache_course_inventory($limit_start = 0, $limit_size = 4000)
  897. {
  898. // Load courses from the inventory into the inventory cache...
  899. // Attempt to load the course inventory cache...
  900. if ($course_inventory = unserialize(@$_SESSION["fp_cache_course_inventory"]))
  901. {
  902. $GLOBALS["fp_course_inventory"] = $course_inventory;
  903. }
  904. $result = $this->db->db_query("SELECT DISTINCT course_id FROM courses
  905. WHERE
  906. course_num < ?
  907. LIMIT $limit_start, $limit_size
  908. ", variable_get("graduate_level_course_num", 5000)); // just use default?
  909. while($cur = $this->db->db_fetch_array($result))
  910. {
  911. $course_id = $cur["course_id"];
  912. $this->db->load_course_descriptive_data(null, $course_id);
  913. }
  914. // Should we re-cache the course inventory? If there have been any changes
  915. // to it, then we will see that in a GLOBALS variable...
  916. if ($GLOBALS["cache_course_inventory"] == true)
  917. {
  918. $_SESSION["fp_cache_course_inventory"] = serialize($GLOBALS["fp_course_inventory"]);
  919. }
  920. }
  921. function replace_missing_course_in_group($course_id, $group_id)
  922. {
  923. // Given a group in the degree plan, this will
  924. // make sure that course is actually in the group. If it
  925. // is not, then it will add it in where it should be.
  926. // This is necessary because we have previously removed
  927. // courses which the student hadn't taken. Well, if the
  928. // student was advised for a particular course in a group,
  929. // then that course probably was originally removed
  930. // from the group. So, put it back in.
  931. // Were we given a valid group_id?
  932. if (!$group_id) return;
  933. // First, find the group.
  934. if (!$group = $this->degree_plan->find_group($group_id))
  935. {
  936. fpm("Admin note: could not find group '$group_id' for replace_missing_course_in_group, for course '$course_id'.");
  937. return;
  938. }
  939. // Okay, now tell the group to replace the instance of this course
  940. // in the group. This is made easy, because we have
  941. // the dbGroupRequirementID, which is the actual id from the
  942. // row in group_requirements that this course was advised from.
  943. $group->replace_missing_course($course_id);
  944. }
  945. function save_advising_session_from_post($faculty_id = 0, $bool_draft = true)
  946. {
  947. global $user;
  948. $catalog_year = 0;
  949. $bool_fp_goto_at_end = FALSE;
  950. // This method will, only by looking at variables in the
  951. // POST, save an advising session into the database.
  952. $db = get_global_database_handler();
  953. if ($faculty_id == 0) {
  954. // if none supplied, use the one from the session of
  955. // whomever is currently logged in.
  956. $faculty_id = $user->cwid;
  957. }
  958. $advising_session_token = $db->request_new_advising_session_token();
  959. // It's possible the user has simply pressed "refresh" after submitting the form. If so,
  960. // there is no reason to re-submit everything, creating duplicate data in some situations.
  961. $post_md5 = md5(serialize($_POST));
  962. if (@$_SESSION["fp_previous_advising_post_md5"] == $post_md5) {
  963. return array();
  964. }
  965. // We may proceed, but save the POST md5 for next time.
  966. $_SESSION["fp_previous_advising_post_md5"] = $post_md5;
  967. $bool_found_update_match = false;
  968. $student_id = $this->student->student_id;
  969. $school_id = db_get_school_id_for_student_id($student_id);
  970. $degree_id = $this->degree_plan->degree_id;
  971. $major_code_csv = $this->degree_plan->get_major_code_csv();
  972. $catalog_year = $this->degree_plan->catalog_year;
  973. $available_terms = variable_get_for_school("available_advising_term_ids", "0", $school_id);
  974. // Do we need to update the student's settings?
  975. if (trim($_POST["advising_update_student_settings_flag"]) != "")
  976. {
  977. // We are to assume that the student's array_settings
  978. // have already been updated by this point, so we will
  979. // simply convert them to XML and store in the database.
  980. $result = $db->db_query("REPLACE INTO student_settings
  981. (student_id, settings, posted)
  982. VALUES ('?','?', '?' ) ", $student_id, serialize($this->student->array_settings), time());
  983. watchdog("update_student_settings", "Settings updated for this student.");
  984. }
  985. //var_dump($_POST);
  986. // die;
  987. // We have changed tracks, so we are to edit the student degrees table.
  988. if ($_POST["advising_update_student_degrees_flag"] == "true") {
  989. // Begin by deleting all the "editable" rows for this student
  990. // in student_degrees.
  991. db_query("DELETE FROM student_degrees
  992. WHERE student_id = '?'
  993. AND is_editable = '1' ", $student_id);
  994. // Now, go through our list of degree tracks ids we're adding back in, and add to the table.
  995. $temp = explode(",", $_POST["advising_track_degree_ids"]);
  996. foreach ($temp as $tdegree_id) {
  997. if (trim($tdegree_id) == "") continue;
  998. if (!is_numeric($tdegree_id)) continue;
  999. $tdegree_plan = fp_load_degree($tdegree_id, NULL, TRUE);
  1000. $tmajor_code = $tdegree_plan->major_code;
  1001. /* // shouldn't need this anymore, as the major_code will contain both the major and track in one.
  1002. $tmajor_code = $tdegree_plan->major_code;
  1003. if (!strstr($tmajor_code, "|")) {
  1004. $tmajor_code .= "|";
  1005. }
  1006. $tmajor_code .= "_" . $tdegree_plan->track_code;
  1007. */
  1008. db_query("INSERT INTO student_degrees
  1009. (student_id, major_code, is_editable)
  1010. VALUES ('?', '?', '1')", $student_id, $tmajor_code);
  1011. }
  1012. // Reset the SESSION variables and re-init, so we get the correct
  1013. // major codes and track codes for this student.
  1014. $_SESSION["advising_track_degree_ids$student_id"] = "";
  1015. $_SESSION["advising_major_code$student_id"] = "";
  1016. $_REQUEST["advising_major_code"] = "";
  1017. $_REQUEST["advising_track_degree_ids"] = "";
  1018. $this->student->load_student_data();
  1019. // force re-build of cache
  1020. //$_REQUEST["load_from_cache"] = "no";
  1021. //$_SESSION["cache_fp$student_id"] = "";
  1022. //$_SESSION["cache_what_if$student_id"] = "";
  1023. $GLOBALS["fp_advising"]["load_from_cache"] = "no";
  1024. $this->init(TRUE);
  1025. $bool_fp_goto_at_end = TRUE;
  1026. } // editing degrees?
  1027. // Is there anything in "log_addition" which we should write to the log?
  1028. if ($_POST["log_addition"] != "")
  1029. {
  1030. $temp = explode("~",$_POST["log_addition"]);
  1031. if ($temp[0] == "change_term") {
  1032. watchdog("change_term", "$student_id," . $temp[1]);
  1033. }
  1034. if ($temp[0] == "change_track"){
  1035. watchdog("change_track", "$student_id," . $temp[1]);
  1036. }
  1037. }
  1038. // If this user cannot advise, then just return right now.
  1039. if (!user_has_permission("can_advise_students")) {
  1040. return;
  1041. }
  1042. // First, create a new entry in the advising_sessions table,
  1043. // so we can get the advising_session_id.
  1044. // But before we can do that, we look for an existing entry
  1045. // which matches this. If we find it, we delete it so the
  1046. // new one will display instead.
  1047. // Only delete if its a draft copy!
  1048. $is_draft = intval($bool_draft);
  1049. $is_what_if = intval($this->bool_what_if);
  1050. // Since we only want one draft copy per term/per student and faculty,
  1051. // let's delete
  1052. // any draft copies already in existence, if we are saving a draft.
  1053. $result = $db->db_query("DELETE FROM advising_sessions
  1054. WHERE student_id = ?
  1055. AND is_draft = 1
  1056. AND faculty_id = ?
  1057. AND degree_id = ?
  1058. AND is_whatif = ? ", $student_id, $faculty_id, $degree_id, $is_what_if);
  1059. // 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!)
  1060. if ($is_draft === 0) {
  1061. db_query("UPDATE advising_sessions SET most_recent_session = 0 WHERE student_id = ?", array($student_id));
  1062. }
  1063. // The first thing we need to do is go through the available_terms,
  1064. // create new entries for them in the table, and store what their
  1065. // session ID's are in an array.
  1066. $advising_session_id_array = array();
  1067. $advising_session_id_array_count = array();
  1068. $posted = time();
  1069. $temp = explode(",",$available_terms);
  1070. foreach ($temp as $term_id)
  1071. {
  1072. $term_id = trim($term_id);
  1073. if ($term_id == "") { continue; }
  1074. // Okay, now create a new entry in the system for that term.
  1075. // We create entries for all available terms, whether we
  1076. // are going to use them later or not.
  1077. $result = $db->db_query("INSERT INTO advising_sessions
  1078. (student_id, faculty_id, term_id, degree_id,
  1079. major_code_csv,
  1080. catalog_year, posted, is_whatif, is_draft, advising_session_token, delete_flag, most_recent_session)
  1081. VALUES
  1082. (?,?,?,?,?,?,?,?,?,?, 0, 1)
  1083. ", $student_id, $faculty_id,$term_id,$degree_id, $major_code_csv, $catalog_year, $posted, $is_what_if, $is_draft, $advising_session_token);
  1084. $advising_session_id = db_insert_id();
  1085. $advising_session_id_array[$term_id] = $advising_session_id;
  1086. $advising_session_id_array_count[$term_id] = 0;
  1087. }
  1088. $wi = "";
  1089. if ($is_what_if == "1"){$wi = "_whatif";}
  1090. if ($bool_draft) {
  1091. watchdog("save_adv_draft$wi", "$student_id,major_code_csv:$major_code_csv~adv_session_token:$advising_session_token");
  1092. }
  1093. else {
  1094. watchdog("save_adv_active$wi", "$student_id,major_code_csv:$major_code_csv~adv_session_token:$advising_session_token");
  1095. }
  1096. // Go through the POST, looking for the
  1097. // phrase "advisecourse_" in the name of the variables.
  1098. // There should be one of these for every course that was
  1099. // on the page. It looks like this:
  1100. // advisecourse_course_id_semesterNum_group_id_varHours_randomID
  1101. foreach($_POST as $key => $value)
  1102. {
  1103. if (!strstr($key,"advisecourse_") && !(strstr($key, "advcr_")))
  1104. { // Skip vars which don't have this as part of the name.
  1105. // We accept either advisecourse_ or advcr_ for short. advisecourse_ is the old way.
  1106. // I changed to use advcr_ to save space, because some browsers will not allow long input names.
  1107. continue;
  1108. }
  1109. if ($value != "true")
  1110. { // This means the course was *not* advised to be taken,
  1111. // so, skip it.
  1112. continue;
  1113. }
  1114. // The key might contain a DoT (dot placeholder) instead of a period. If so, let's
  1115. // add the period back in. This was to correct a bug where courses with dots couldn't
  1116. // be advised.
  1117. if (strstr($key, "DoT")) {
  1118. $key = str_replace("DoT", ".", $key);
  1119. }
  1120. $temp = explode("_",$key);
  1121. $course_id = trim($temp[1]);
  1122. $semester_num = trim($temp[2]);
  1123. $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.)
  1124. $var_hours = trim($temp[4]) * 1;
  1125. $random_id = trim($temp[5]);
  1126. $advised_term_id = trim($temp[6]);
  1127. //$db_group_requirement_id = trim($temp[7]);
  1128. $degree_id = trim($temp[7]);
  1129. if ($degree_id == "group") {
  1130. // Get degree_id from the group_id.
  1131. $tt = explode("_", $group_id);
  1132. $degree_id = $tt[1];
  1133. }
  1134. $advising_session_id = $advising_session_id_array[$advised_term_id];
  1135. $new_course = new Course($course_id);
  1136. $new_course->load_descriptive_data();
  1137. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1138. // Some particular course should be updated. Possibly this one.
  1139. // Updates happen because of a student changing the
  1140. // variable hours, for example.
  1141. if (trim(@$_POST["updatecourse"]) != "")
  1142. {
  1143. $temp2 = explode("~",trim($_POST["updatecourse"]));
  1144. $tcourse_id = $temp2[0];
  1145. $tgroup_id = $temp2[1];
  1146. $tsemester_num = $temp2[2];
  1147. $tvar_hours = $temp2[3];
  1148. $trandom_id = $temp2[4];
  1149. $tadvised_term_id = $temp2[5];
  1150. $tdegree_id = $temp2[6];
  1151. // Do we have a match?
  1152. if ($course_id == $tcourse_id && $random_id == $trandom_id)
  1153. {
  1154. // We have a match, so update with the new information.
  1155. $var_hours = $tvar_hours;
  1156. $degree_id = $tdegree_id;
  1157. $new_course = new Course($tcourse_id);
  1158. $new_course->load_descriptive_data();
  1159. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1160. $bool_found_update_match = true;
  1161. }
  1162. }
  1163. if ($group_id != 0)
  1164. {
  1165. $this->replace_missing_course_in_group($course_id, $group_id);
  1166. }
  1167. // Make sure degree_id is a valid number for the database.
  1168. if (!is_numeric($degree_id) || intval($degree_id) < 0) {
  1169. $degree_id = 0;
  1170. }
  1171. // Okay, write it to the table...
  1172. $result = $db->db_query("INSERT INTO advised_courses
  1173. (`advising_session_id`,`course_id`,
  1174. `entry_value`,`semester_num`,
  1175. `group_id`,`var_hours`,`term_id`, `degree_id`)
  1176. VALUES
  1177. ('?','?','?','?','?','?','?','?')
  1178. ", $advising_session_id, $course_id, $entry_value, $semester_num, $group_id, $var_hours, $advised_term_id, $degree_id);
  1179. $advising_session_id_array_count[$advised_term_id]++;
  1180. }
  1181. // Did we have to perform an update-- but no course was found?
  1182. if (trim(@$_POST["updatecourse"]) != "" && $bool_found_update_match == false)
  1183. {
  1184. // This means that the course was probably on the bare
  1185. // degree program, and not already checked for advising. So,
  1186. // let's add it to the advised_courses table, so it DOES
  1187. // get checked for advising.
  1188. $temp2 = explode("~",trim($_POST["updatecourse"]));
  1189. $course_id = $temp2[0];
  1190. $group_id = $temp2[1];
  1191. $semester_num = $temp2[2];
  1192. $var_hours = $temp2[3];
  1193. $advised_term_id = $temp2[5];
  1194. $degree_id = $temp2[6];
  1195. $new_course = new Course($course_id);
  1196. $new_course->load_descriptive_data();
  1197. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1198. $advising_session_id = $advising_session_id_array[$advised_term_id];
  1199. $result = $db->db_query("INSERT INTO advised_courses
  1200. (`advising_session_id`,`course_id`,`entry_value`,`semester_num`,
  1201. `group_id`,`var_hours`,`term_id`,`degree_id`)
  1202. VALUES
  1203. ('?','?','?','?','?','?','?','?')
  1204. ", $advising_session_id,$course_id,$entry_value,$semester_num,$group_id,$var_hours,$advised_term_id,$degree_id);
  1205. $advising_session_id_array_count[$advised_term_id]++;
  1206. if ($group_id != 0)
  1207. {
  1208. $this->replace_missing_course_in_group($course_id, $group_id);
  1209. }
  1210. }
  1211. //------------------------------------------------------
  1212. //
  1213. // Substitutions...
  1214. //
  1215. //-------------------------------------------------------
  1216. // check permissions for substitutions before saving
  1217. if (trim(@$_POST["savesubstitution"]) != "" && user_has_permission("can_substitute")) {
  1218. $temp = explode("~",trim($_POST["savesubstitution"]));
  1219. $course_id = $temp[0]; // required course
  1220. $group_id = trim($temp[1]);
  1221. $req_by_degree_id = $temp[2];
  1222. $semester_num = $temp[3] * 1;
  1223. $sub_course_id = $temp[4];
  1224. $sub_term_id = $temp[5];
  1225. $sub_transfer_flag = $temp[6];
  1226. $sub_hours = $temp[7] * 1;
  1227. $sub_addition = $temp[8];
  1228. $sub_remarks = urldecode($temp[9]);
  1229. if ($sub_addition == "true")
  1230. {
  1231. $course_id = 0;
  1232. }
  1233. // Figure out the entry values for the required course & sub course...
  1234. $required_entry_value = $sub_entry_value = "";
  1235. if ($course_id > 0)
  1236. {
  1237. $new_course = new Course($course_id);
  1238. $new_course->load_descriptive_data();
  1239. $required_entry_value = "$new_course->subject_id~$new_course->course_num";
  1240. }
  1241. if ($sub_transfer_flag != 1)
  1242. {
  1243. $new_course = new Course($sub_course_id);
  1244. $new_course->load_descriptive_data();
  1245. $sub_entry_value = "$new_course->subject_id~$new_course->course_num";
  1246. }
  1247. if ($group_id != 0 && $course_id != 0)
  1248. {
  1249. $this->replace_missing_course_in_group($course_id, $group_id);
  1250. }
  1251. // Make sure the sub_hours aren't larger than the sub_course_id's awarded hours.
  1252. // This is to stop a bug from happening where sometimes, some people are able to substitute
  1253. // a course for larger than the awarded hours. I believe it is a javascript bug.
  1254. if ($test_c = $this->student->list_courses_taken->find_specific_course($sub_course_id, $sub_term_id, (bool) $sub_transfer_flag, true)) {
  1255. // Are the hours out of whack?
  1256. if (floatval($sub_hours) > floatval($test_c->get_hours_awarded($req_by_degree_id))) {
  1257. // Yes! Set it to the value of the hours_awarded.
  1258. $sub_hours = floatval($test_c->get_hours_awarded($req_by_degree_id));
  1259. }
  1260. }
  1261. $result = $db->db_query("INSERT INTO student_substitutions
  1262. (`student_id`,`faculty_id`,`required_course_id`,`required_entry_value`,
  1263. `required_group_id`,`required_degree_id`,`required_semester_num`,`sub_course_id`,`sub_entry_value`,
  1264. `sub_term_id`,`sub_transfer_flag`,`sub_hours`,`sub_remarks`,`posted`)
  1265. VALUES
  1266. ('?','?','?','?','?','?','?','?','?','?','?','?','?','?')
  1267. ", $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());
  1268. watchdog("save_substitution", "$student_id,group_id:$group_id,insert_id:" . db_insert_id());
  1269. }
  1270. if (trim(@$_POST["removesubstitution"]) != "")
  1271. {
  1272. $temp = explode("~",trim($_POST["removesubstitution"]));
  1273. $sub_id = trim($temp[0]) * 1;
  1274. $result = $db->db_query("UPDATE student_substitutions
  1275. SET `delete_flag`='1'
  1276. WHERE `id`='?' ", $sub_id);
  1277. watchdog("remove_substitution", "$student_id,sub_id:$sub_id");
  1278. }
  1279. //------------------------------------------------------
  1280. //
  1281. // Group Unassignments
  1282. //
  1283. //-------------------------------------------------------
  1284. if (trim(@$_POST["unassign_group"]) != "")
  1285. {
  1286. $temp = explode("~",trim($_POST["unassign_group"]));
  1287. $course_id = $temp[0];
  1288. $term_id = $temp[1];
  1289. $transfer_flag = $temp[2];
  1290. $group_id = $temp[3];
  1291. $degree_id = $temp[4];
  1292. $result = db_query("INSERT INTO student_unassign_group
  1293. (`student_id`,`faculty_id`,`course_id`,
  1294. `term_id`,`transfer_flag`,`group_id`,`degree_id`,
  1295. `posted`)
  1296. VALUES
  1297. ('?','?','?','?','?','?','?','?')
  1298. ", $student_id,$faculty_id,$course_id,$term_id,$transfer_flag,$group_id,$degree_id,time());
  1299. watchdog("save_unassign_group", "$student_id,group_id:$group_id,degree_id:$degree_id");
  1300. }
  1301. if (trim(@$_POST["restore_unassign_group"]) != "")
  1302. {
  1303. $temp = explode("~",trim($_POST["restore_unassign_group"]));
  1304. $unassign_id = trim($temp[0]) * 1;
  1305. $result = $db->db_query("UPDATE student_unassign_group
  1306. SET `delete_flag`='1'
  1307. WHERE `id`='?' ", $unassign_id);
  1308. watchdog("restore_unassign_group", "$student_id,unassign_id:$unassign_id");
  1309. }
  1310. //------------------------------------------------------
  1311. //
  1312. // Transfer EQV Unassignments
  1313. //
  1314. //-------------------------------------------------------
  1315. if (trim(@$_POST["unassign_transfer_eqv"]) != "")
  1316. {
  1317. $temp = explode("~",trim($_POST["unassign_transfer_eqv"]));
  1318. $course_id = $temp[0];
  1319. $result = $db->db_query("INSERT INTO student_unassign_transfer_eqv
  1320. (`student_id`,`faculty_id`,`transfer_course_id`,
  1321. `posted`)
  1322. VALUES
  1323. ('?','?','?','?')
  1324. ", $student_id, $faculty_id, $course_id, time());
  1325. watchdog("save_unassign_transfer", "$student_id,course_id:$course_id");
  1326. }
  1327. if (trim(@$_POST["restore_transfer_eqv"]) != "")
  1328. {
  1329. $temp = explode("~",trim($_POST["restore_transfer_eqv"]));
  1330. $unassign_id = trim($temp[0]) * 1;
  1331. $result = $db->db_query("UPDATE student_unassign_transfer_eqv
  1332. SET `delete_flag`='1'
  1333. WHERE `id`='?' ", $unassign_id);
  1334. watchdog("restore_unassign_transfer", "$student_id,unassign_id:$unassign_id");
  1335. }
  1336. ////////////////////////////////////////////////////
  1337. /////// Cleanup !////////////////////////////////
  1338. ////////////////////////////////////////////////////
  1339. // If any of the advisingSessions we created earlier
  1340. // are blank, we should FLAG them, so they will not
  1341. // show up under the student's history.
  1342. // Only flag non-draft empty ones. If they are draft,
  1343. // let them be.
  1344. // We just look at $advising_session_id_array_count[] to see
  1345. // if any of the counts are still 0. If they are, delete
  1346. // that advisingSessionID from the table.
  1347. if ($is_draft == 0)
  1348. {
  1349. foreach ($advising_session_id_array as $term_id => $advising_session_id)
  1350. {
  1351. if ($advising_session_id_array_count[$term_id] == 0)
  1352. {
  1353. // This one is blank! Delete it!
  1354. $res = $db->db_query("UPDATE advising_sessions
  1355. SET is_empty = 1
  1356. WHERE advising_session_id = ? ", $advising_session_id);
  1357. $advising_session_id_array[$term_id] = "";
  1358. }
  1359. }
  1360. }
  1361. watchdog("advising", "Student has been advised: @student", array("@student" => $student_id));
  1362. // Call a hook so other modules can act when the advising session gets saved.
  1363. invoke_hook('save_advising_session_from_post', array($student_id, $is_draft, $advising_session_id_array));
  1364. // Instead of executing the page, we will issue a redirect using fp_goto.
  1365. // This makes it so if the user hits "refresh", it will not re-submit a POST request.
  1366. if ($bool_fp_goto_at_end) {
  1367. // Goto the same page we are already on. This mimics Drupal's Form API behavior.
  1368. $q = $_REQUEST['q'];
  1369. fp_goto($q, "advising_major_code=&load_from_cache=no&advising_student_id=$student_id");
  1370. }
  1371. return $advising_session_id_array;
  1372. }
  1373. 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)
  1374. {
  1375. global $user;
  1376. // This method will load an advising session for a particular
  1377. // student, and modify the degree plan object to reflect
  1378. // the advisings.
  1379. $db = get_global_database_handler();
  1380. $is_what_if = "0";
  1381. $is_draft = "0";
  1382. if ($bool_what_if == true){$is_what_if = "1";}
  1383. if ($bool_draft == true){$is_draft = "1";}
  1384. $degree_id = $this->degree_plan->degree_id;
  1385. $student_id = $this->student->student_id;
  1386. $school_id = db_get_school_id_for_student_id($student_id);
  1387. $available_terms = variable_get_for_school("available_advising_term_ids", "0", $school_id);
  1388. // If we are pulling up an active student record, then let's
  1389. // delete any draft sessions for this faculty user and student, so as not to cause
  1390. // a bug later on when changing tabs. We don't care if $faculty_id is set or not, just
  1391. // the current user's CWID.
  1392. if ($bool_draft == FALSE && $user->cwid != 0) {
  1393. $res = db_query("DELETE FROM advising_sessions
  1394. WHERE student_id = ?
  1395. AND faculty_id = ?
  1396. AND is_draft = 1
  1397. ", $student_id, $user->cwid);
  1398. }
  1399. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  1400. // First, find the advising session id...
  1401. if ($advising_session_id < 1 && $available_terms == "")
  1402. {
  1403. $advising_session_id = $this->db->get_advising_session_id($faculty_id, $student_id, $term_id, $degree_id, $bool_what_if, $bool_draft, TRUE);
  1404. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  1405. // Create a duplicate of this session as a draft...
  1406. if ($bool_draft == FALSE) {
  1407. $db->duplicate_advising_session($advising_session_id, $duplicate_for_faculty_id, "", "", "", "", 1);
  1408. }
  1409. } else if ($advising_session_id < 1 && $available_terms != "")
  1410. {
  1411. // Meaning, we are looking for more than one term.
  1412. $advising_session_line = "(";
  1413. $temp = explode(",",$available_terms);
  1414. for ($t = 0; $t < count($temp); $t++)
  1415. {
  1416. $t_id = trim($temp[$t]);
  1417. $asid = $this->db->get_advising_session_id($faculty_id, $student_id, $t_id,$degree_id, $bool_what_if, $bool_draft, TRUE);
  1418. if ($asid != 0)
  1419. {
  1420. $advising_session_line .= " advising_session_id='$asid' || ";
  1421. // Create a duplicate of this session as a draft...
  1422. if ($bool_draft == FALSE) {
  1423. $db->duplicate_advising_session($asid, $duplicate_for_faculty_id, "", "", "", "", 1);
  1424. }
  1425. }
  1426. }
  1427. // Take off the last 3 chars...
  1428. $advising_session_line = substr($advising_session_line, 0, -3);
  1429. $advising_session_line .= ")";
  1430. if ($advising_session_line == ")")
  1431. { // Found NO previously advised semesters, so just
  1432. // use a dummy value which guarantees it pulls up nothing.
  1433. $advising_session_line = " advising_session_id='-99999'";
  1434. }
  1435. }
  1436. // Now, look up the courses they were advised to take.
  1437. $query = "SELECT * FROM advised_courses
  1438. WHERE
  1439. $advising_session_line
  1440. ORDER BY `id` ";
  1441. $result = $db->db_query($query);
  1442. while($cur = $db->db_fetch_array($result))
  1443. {
  1444. $course_id = trim($cur["course_id"]);
  1445. $semester_num = trim($cur["semester_num"]);
  1446. $group_id = trim($cur["group_id"]);
  1447. $degree_id = $cur["degree_id"];
  1448. $var_hours = trim($cur["var_hours"]);
  1449. $advised_term_id = trim($cur["term_id"]);
  1450. $id = trim($cur["id"]);
  1451. // Add this course to the generic list of advised courses. Useful
  1452. // if we are using this to pull up an advising summary.
  1453. $temp_course = new Course($course_id);
  1454. $temp_course->advised_hours = $var_hours;
  1455. $this->course_list_advised_courses->add($temp_course);
  1456. if ($semester_num == DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED)
  1457. {
  1458. // This was a courses added by the advisor.
  1459. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1460. continue;
  1461. }
  1462. // Now, we need to modify the degree_plan object to
  1463. // show these advisings.
  1464. if ($course_list = $this->degree_plan->find_courses($course_id, $group_id, $semester_num, $degree_id))
  1465. {
  1466. // This course may exist in several different branches of a group, so we need
  1467. // to mark all the branches as having been advised to take. Usually, this CourseList
  1468. // will probably only have 1 course object in it. But, better safe than sorry.
  1469. $course_list->reset_counter();
  1470. if ($course = $course_list->get_next())
  1471. {
  1472. // make sure the hour count has been loaded correctly.
  1473. if ($course->get_catalog_hours() < 1)
  1474. {
  1475. $course->load_descriptive_data();
  1476. }
  1477. // Let's start by looking at the first course. Is it
  1478. // supposed to be repeated?
  1479. if ($course->bool_specified_repeat==true
  1480. && $course->specified_repeats >= 0 )
  1481. {
  1482. // This is a course which is supposed to be repeated.
  1483. // We need to cycle through and find an instance
  1484. // of this course which has not been advised yet.
  1485. $course_list->reset_counter();
  1486. while($course_list->has_more())
  1487. {
  1488. $course = $course_list->get_next();
  1489. // make sure the hour count has been loaded correctly.
  1490. if ($course->get_catalog_hours() < 1)
  1491. {
  1492. $course->load_descriptive_data();
  1493. }
  1494. ////////////////////
  1495. // Logan's change: https://bytetask.com/node/2455
  1496. // If we have the setting which says we should skip if it's already been completed/enrolled for this term,
  1497. // then we should do that.
  1498. if (variable_get_for_school("remove_advised_when_course_taken", "no", $school_id) == "yes") {
  1499. // First, see if this advised course has been attempted already.
  1500. if ($this->student->list_courses_taken->find_specific_course($course->course_id, $advised_term_id)) {
  1501. // Yep, found it! So, skip this one.
  1502. continue;
  1503. }
  1504. }
  1505. //////////////////////////
  1506. //if ($course->bool_advised_to_take != true && !is_object($course->courseFulfilledBy))
  1507. if ($course->bool_advised_to_take != true && $course->course_list_fulfilled_by->is_empty == true)
  1508. {
  1509. // Okay, this course is supposed to be taken/advised
  1510. // more than once. So, I will mark this one as
  1511. // advised, and then break out of the loop, since
  1512. // I don't want to mark all occurances as advised.
  1513. $course->bool_advised_to_take = true;
  1514. $course->assigned_to_semester_num = $semester_num;
  1515. //$course->assigned_to_group_id = $group_id;
  1516. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1517. // Make sure we assign the hours to the group, so this
  1518. // advised courses takes up a spot in the group. Otherwise
  1519. // it may be missed in later logic.
  1520. if ($g = $this->degree_plan->find_group($group_id)) {
  1521. $h = $var_hours;
  1522. if ($h == 0) {
  1523. $h = $course->get_catalog_hours();
  1524. if ($h == 0) {
  1525. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1526. // horribly break.
  1527. }
  1528. }
  1529. $g->hours_assigned += $h;
  1530. }
  1531. $course->advised_hours = $var_hours;
  1532. $course->advised_term_id = $advised_term_id;
  1533. $course->db_advised_courses_id = $id;
  1534. $course_list->dec_specified_repeats($course);
  1535. break;
  1536. }
  1537. }
  1538. continue; // Go to the next advised course.
  1539. }
  1540. } // if $course = $course_list->get_next();
  1541. //////////////////////////////
  1542. // We're here, because it was not a repeatable course.
  1543. // ** We should only go through THIS loop once! So,
  1544. // we will break after we make our assignment.
  1545. $course_list->reset_counter();
  1546. while($course_list->has_more())
  1547. {
  1548. $course = $course_list->get_next();
  1549. // make sure the hour count has been loaded correctly.
  1550. if ($course->get_catalog_hours() < 1)
  1551. {
  1552. $course->load_descriptive_data();
  1553. }
  1554. // make sure it has not already been advised to take.
  1555. // Would occur if the same course is specified more
  1556. // than once in a semester.
  1557. if ($course->bool_advised_to_take == true)
  1558. {
  1559. continue;
  1560. }
  1561. // If we have the setting which says we should skip if it's already been completed/enrolled for this term,
  1562. // then we should do that.
  1563. if (variable_get_for_school("remove_advised_when_course_taken", "no", $school_id) == "yes") {
  1564. // First, see if this advised course has been attempted already.
  1565. if ($taken_course = $this->student->list_courses_taken->find_specific_course($course->course_id, $advised_term_id)) {
  1566. // Yep, found it! So, skip this one.
  1567. continue;
  1568. }
  1569. }
  1570. // Has this course already been fulfilled by something?
  1571. // If so, we cannot attempt to say it's been advised!
  1572. if (!$course->course_list_fulfilled_by->is_empty)
  1573. {
  1574. // meaning, this course HAS been fulfilled.
  1575. // So, let's move this advising to the "added by advisor"
  1576. // spot.
  1577. /* This is the original bit of code here. It is causing a problem when there are courses which are supposed to be
  1578. * repeated. Example: MUSC courses which are advised one term at a time.
  1579. *
  1580. *
  1581. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1582. break;
  1583. *
  1584. * 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
  1585. * do the original logic.
  1586. *
  1587. */
  1588. if ($course_list->get_size() > 1) {
  1589. continue;
  1590. }
  1591. else {
  1592. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1593. break;
  1594. }
  1595. }
  1596. $course->bool_advised_to_take = true;
  1597. $course->assigned_to_semester_num = $semester_num;
  1598. //$course->assigned_to_group_id = $group_id;
  1599. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1600. // Make sure we assign the hours to the group, so this
  1601. // advised courses takes up a spot in the group. Otherwise
  1602. // it may be missed in later logic.
  1603. if ($g = $this->degree_plan->find_group($group_id)) {
  1604. $h = $var_hours;
  1605. if ($h == 0) {
  1606. $h = $course->get_catalog_hours();
  1607. if ($h == 0) {
  1608. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1609. // horribly break.
  1610. }
  1611. }
  1612. $g->hours_assigned += $h;
  1613. }
  1614. $course->advised_hours = $var_hours;
  1615. $course->advised_term_id = $advised_term_id;
  1616. $course->db_advised_courses_id = $id;
  1617. if ($course->required_on_branch_id > 0)
  1618. {
  1619. // In other words, this course was found on a branch, so we need
  1620. // to increment that branch's count_of_matches.
  1621. if ($branch = $this->degree_plan->find_group($course->required_on_branch_id))
  1622. {
  1623. $branch->count_of_matches++;
  1624. } else {
  1625. fpm("Error: Could not find branch.");
  1626. }
  1627. }
  1628. // We should only be in this loop once, so let's
  1629. // break after we make our assignment.
  1630. break;
  1631. }
  1632. }
  1633. }
  1634. // Now, what we need to do is tell the DegreePlan to re-sort its
  1635. // group's course lists, so that the advised courses are lower
  1636. // than the fulfilled courses.
  1637. //$this->degree_plan->sortGroupsFulfilledFirst();
  1638. //print_pre($this->degree_plan->list_groups->toString());
  1639. } // function loadAdvisingSessionFromDatabase
  1640. function split_requirements_by_substitutions()
  1641. {
  1642. // Go through all the required courses on the degree plan,
  1643. // and if there is a partial substitution specified in the student's
  1644. // list of substitutions, then split that requirement into 2 courses,
  1645. // one with enough hours to satisfy the sub, and the remaining hours.
  1646. $degree_plan = $this->degree_plan;
  1647. $student = $this->student;
  1648. $student->list_substitutions->reset_counter();
  1649. while($student->list_substitutions->has_more())
  1650. {
  1651. $substitution = $student->list_substitutions->get_next();
  1652. $course_requirement = $substitution->course_requirement;
  1653. $course_sub = $substitution->course_list_substitutions->get_first();
  1654. // TODO: This could be an important part right here
  1655. // Check to see if the courseSub's hours_awarded are less than the
  1656. // course_requirement's min hours...
  1657. if ($course_requirement->min_hours > $course_sub->get_hours_awarded())
  1658. {
  1659. // Meaning the original course requirement is not being
  1660. // fully satisfied by this substitution! The original
  1661. // course requirement has hours left over which must be
  1662. // fulfilled somehow.
  1663. $remaining_hours = round($course_requirement->min_hours - $course_sub->get_hours_awarded(), 6);
  1664. // This means that the course requirement needs to be split.
  1665. // So, find this course in the degree plan.
  1666. $required_course_id = $course_requirement->course_id;
  1667. //$required_group_id = $course_requirement->assigned_to_group_id;
  1668. $required_group_id = $course_requirement->get_first_assigned_to_group_id(); // we assume a course requirement is only assigned to 1 group.
  1669. $required_semester_num = $course_requirement->assigned_to_semester_num;
  1670. }
  1671. }
  1672. } // split_requirements_by_substitution
  1673. function assign_course_to_courses_added_list($course_id, $var_hours = 0, $db_advised_courses_id = 0, $advised_term_id = 0)
  1674. {
  1675. // Set the supplied course as "advised to take" in the degree plan's
  1676. // special added courses group, which is number -88.
  1677. $course = new Course($course_id, false, $this->db);
  1678. $course->bool_advised_to_take = true;
  1679. $course->assigned_to_semester_num = DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED;
  1680. //$course->assigned_to_group_id = -88;
  1681. $course->assigned_to_group_ids_array[DegreePlan::GROUP_ID_FOR_COURSES_ADDED] = DegreePlan::GROUP_ID_FOR_COURSES_ADDED;
  1682. $course->advised_hours = $var_hours;
  1683. $course->db_advised_courses_id = $db_advised_courses_id;
  1684. $course->advised_term_id = $advised_term_id;
  1685. if ($group = $this->degree_plan->find_group(DegreePlan::GROUP_ID_FOR_COURSES_ADDED))
  1686. {
  1687. $group->list_courses->add($course);
  1688. }
  1689. // Done!
  1690. }
  1691. }

Classes

Namesort descending Description
FlightPath