admin.courses.inc

  1. 7.x modules/admin/admin.courses.inc
  2. 6.x modules/admin/admin.courses.inc
  3. 4.x modules/admin/admin.courses.inc
  4. 5.x modules/admin/admin.courses.inc

File

modules/admin/admin.courses.inc
View source
  1. <?php
  2. /* Functions related to working with Course data in FP */
  3. /**
  4. * This function displays all of our courses for us to edit.
  5. */
  6. function admin_display_courses() {
  7. $rtn = "";
  8. // Do this using $render array, so it can be altered
  9. // by hook_content_alter
  10. $render = array();
  11. $render['#id'] = 'admin_display_courses';
  12. $de_catalog_year = admin_get_de_catalog_year();
  13. fp_add_css(fp_get_module_path("admin") . "/css/admin.css");
  14. $cc = 1;
  15. $show_hidden = fp_trim(@$_GET["show_hidden"]);
  16. if ($show_hidden != "") {
  17. $_SESSION["dehidden"] = $show_hidden;
  18. }
  19. else {
  20. $show_hidden = @$_SESSION["dehidden"];
  21. }
  22. // Get the "upper range" (UR) and
  23. // lower range (LR) of the courses in question...
  24. $ur = fp_trim(@$_GET["ur"]);
  25. $lr = fp_trim(@$_GET["lr"]);
  26. if ($ur == "") {
  27. // meaning, no range was set. Use A - AZZZZZ, so, all of the A's.
  28. $ur = @$_SESSION["dec_ur"];
  29. $lr = @$_SESSION["dec_lr"];
  30. if ($ur == "") {
  31. // if still blank, assign it..
  32. $ur = "A";
  33. $lr = "AZZZZ";
  34. }
  35. }
  36. $_SESSION["dec_ur"] = $ur;
  37. $_SESSION["dec_lr"] = $lr;
  38. fp_set_title(t("Courses for @year", array("@year" => $de_catalog_year)));
  39. $html = "";
  40. $letter_ranges = array(
  41. "A" => array("A", "AZZZZ"),
  42. "B" => array("B", "BZZZZ"),
  43. "C-CN" => array("C", "CNZZZ"),
  44. "CO-CZ" => array("CO", "CZZZZ"),
  45. "D" => array("D", "DZZZZ"),
  46. "E" => array("E", "EZZZZ"),
  47. "F" => array("F", "FZZZZ"),
  48. "G" => array("G", "GZZZZ"),
  49. "H" => array("H", "HZZZZ"),
  50. "I-L" => array("I", "LZZZZ"),
  51. "M-MR" => array("M", "MRZZZ"),
  52. "MS-MZ" => array("MS", "MZZZZ"),
  53. "N-O" => array("N", "OZZZZ"),
  54. "P" => array("P", "PZZZZ"),
  55. "Q-R" => array("Q", "RZZZZ"),
  56. "S-SO" => array("S", "SOZZZ"),
  57. "SP-SZ" => array("SP", "SZZZZ"),
  58. "T-Z" => array("T", "ZZZZZ"),
  59. );
  60. $html .= "<div class='admin-courses-select-letter-bar'>
  61. ";
  62. foreach($letter_ranges as $disp => $vals) {
  63. $html .= l($disp, "admin/courses", "de_catalog_year=$de_catalog_year&ur=" . $vals[0] . "&lr=" . $vals[1], array("class" => "admin-courses-letter-link")) . " &nbsp; &nbsp; ";
  64. }
  65. $html .= "</div>
  66. <div >
  67. <div style='padding: 5px;'>
  68. " . l("<i class='fa fa-plus'></i> " . t("Add a course for @year", array("@year" => $de_catalog_year)), "admin/courses/edit-course", "course_id=new&de_catalog_year=$de_catalog_year") . "
  69. &nbsp; &nbsp; &nbsp;
  70. " . t("Legend: [e] = Course has at least one add'l excluded name. &nbsp; &nbsp;[v] = Course has at least one add'l valid name.") . "
  71. </div>
  72. </div>
  73. ";
  74. $render['upper_links'] = array(
  75. 'value' => $html,
  76. );
  77. $mark = "";
  78. $mark .= "<div class='degrees-filter'>";
  79. $mark .= fp_render_form("admin_courses_list_filter_form");
  80. $mark .= "</div>";
  81. $render['courses_filter'] = array(
  82. 'value' => $mark,
  83. );
  84. $render['courses_table_top'] = array(
  85. 'value' => "<table border='0' cellpadding='5' cellspacing='5' class='disp-courses-table'>
  86. <tr>
  87. <th>" . t("Course") . "</th>
  88. <th>" . t("Hours") . "</th>
  89. <th width='10%'>" . t("Extra") . "</th>
  90. </tr>",
  91. );
  92. $on_mouse_over = "
  93. onmouseover='$(this).addClass(\"selection_highlight\");'
  94. onmouseout='$(this).removeClass(\"selection_highlight\");'
  95. ";
  96. $extra_where_conditions = "";
  97. $extra_where_conditions .= " AND exclude != 1 ";
  98. $filter_exclude = @trim($_SESSION['courses_filter_exclude']);
  99. if ($filter_exclude == 'yes') {
  100. $extra_where_conditions = "";
  101. }
  102. $filter_school = @intval(trim($_SESSION['courses_filter_school']));
  103. if (module_enabled('schools')) {
  104. if ($filter_school) {
  105. $extra_where_conditions .= " AND school_id = $filter_school ";
  106. }
  107. }
  108. else {
  109. // schools not enabled, so only search for school = 0
  110. $extra_where_conditions .= " AND school_id = 0 ";
  111. }
  112. watchdog("admin", "Viewed admin courses list. Exclude option: $filter_exclude, Range: $ur - $lr, ($de_catalog_year), School id: $filter_school", array(), WATCHDOG_DEBUG);
  113. $q = "SELECT * FROM draft_courses
  114. WHERE
  115. catalog_year = ?
  116. AND subject_id BETWEEN ? AND ?
  117. AND delete_flag = 0
  118. $extra_where_conditions
  119. ORDER BY subject_id, course_num";
  120. $result = db_query($q, $de_catalog_year, $ur, $lr);
  121. while ($cur = db_fetch_array($result)) {
  122. extract($cur, 3, "db");
  123. $ex_names = "";
  124. $val_names = "";
  125. // Check to see if this course has more than one name...
  126. // removed AND `catalog_year`='$de_catalog_year' from query,
  127. // because we don't care what other cat year it came from.
  128. $res2 = db_query("SELECT * FROM draft_courses
  129. WHERE course_id = ?
  130. ", $db_course_id);
  131. while ($cur2 = db_fetch_array($res2)) {
  132. if ($cur2["subject_id"] == $db_subject_id && $cur2["course_num"] == $db_course_num) {
  133. continue;
  134. }
  135. if ($cur2["exclude"] == "1") {
  136. $ex_names = "[e]";
  137. }
  138. else {
  139. $val_names = "[v]";
  140. }
  141. }
  142. $spanstyle = "";
  143. if ($db_exclude == "1") {
  144. $spanstyle = "background-color: #ddd;";
  145. }
  146. $temp_course = new Course();
  147. $db_title = $temp_course->fix_title($db_title);
  148. $db_min_hours = $db_min_hours*1;
  149. $db_max_hours = $db_max_hours*1;
  150. $db_repeat_hours = $db_repeat_hours*1;
  151. $hrs = $db_min_hours;
  152. if (trim($db_min_hours) != trim($db_max_hours)) {
  153. $hrs .= " - $db_max_hours";
  154. }
  155. //$hrs .= " hrs";
  156. $rep_hours = "";
  157. if ($db_repeat_hours > $db_min_hours) {
  158. $rep_hours = "<div class='rep-msg'>rep to $db_repeat_hours</div>";
  159. }
  160. // remove special chars from subject_id...
  161. $display_subject_id = $db_subject_id;
  162. $db_subject_id = str_replace("&","_A_",$db_subject_id);
  163. $url = fp_url("admin/courses/edit-course", "course_id=$db_course_id&subject_id=$db_subject_id&course_num=$db_course_num&de_catalog_year=$de_catalog_year");
  164. $render['course_row_' . $db_course_id] = array(
  165. 'value' => "
  166. <tr style='$spanstyle; cursor:pointer;' $on_mouse_over
  167. onClick='window.location=\"$url\"'
  168. >
  169. <td valign='top' width=''>
  170. <a name='course_$db_course_id'></a>
  171. <div>$display_subject_id $db_course_num - $db_title</div>
  172. </td>
  173. <td>
  174. $hrs$rep_hours
  175. </td>
  176. <td valign='top' >
  177. $ex_names
  178. $val_names
  179. </tr>",
  180. 'data' => array(
  181. 'course_id' => $db_course_id,
  182. 'school_id' => $db_school_id,
  183. 'catalog_year' => $de_catalog_year,
  184. 'db_row' => $cur,
  185. 'subject_id' => $db_subject_id,
  186. 'course_num' => $db_course_num,
  187. ),
  188. );
  189. } // while
  190. $render['courses_table_bottom'] = array(
  191. 'value' => "</table>",
  192. );
  193. $rtn .= fp_render_content($render);
  194. return $rtn;
  195. }
  196. function admin_courses_list_filter_form() {
  197. $form = array();
  198. $form['mark_top'] = array(
  199. 'type' => 'markup',
  200. 'value' => "<strong>" . t('Filter by...') . "</strong>",
  201. 'weight' => 0,
  202. );
  203. $filter_exclude_value = @trim($_SESSION['courses_filter_exclude']);
  204. $form['filter_exclude'] = array(
  205. 'type' => 'select',
  206. 'label' => '',
  207. 'options' => array('' => 'Hide excluded courses', 'yes' => 'Show excluded courses'),
  208. 'value' => $filter_exclude_value,
  209. 'hide_please_select' => TRUE,
  210. 'size' => 20,
  211. 'weight' => 10,
  212. );
  213. // If we have enabled the schools module, then have a selector for that as well
  214. if (module_enabled('schools')) {
  215. $filter_school_value = @intval($_SESSION['courses_filter_school']);
  216. $options = schools_get_schools_for_fapi(TRUE, TRUE, 'course', TRUE);
  217. $options[0] = t('- All / Default -');
  218. $form['filter_school'] = array(
  219. 'type' => 'select',
  220. 'label' => t('School:'),
  221. 'options' => $options,
  222. 'value' => $filter_school_value,
  223. 'weight' => 20,
  224. 'hide_please_select' => TRUE,
  225. );
  226. } // if schools enabled
  227. $form['submit_btn'] = array(
  228. 'type' => 'submit',
  229. 'value' => t('Apply'),
  230. 'weight' => 100,
  231. );
  232. $form['reset_btn'] = array(
  233. 'type' => 'submit',
  234. 'value' => t('Reset'),
  235. 'weight' => 110,
  236. );
  237. return $form;
  238. }
  239. function admin_courses_list_filter_form_submit($form, $form_state) {
  240. $values = $form_state['values'];
  241. unset($_SESSION['courses_filter_exclude']);
  242. unset($_SESSION['courses_filter_school']);
  243. if ($values['submit_btn'] != '') {
  244. $_SESSION['courses_filter_exclude'] = trim($values['filter_exclude']);
  245. $_SESSION['courses_filter_school'] = @$values['filter_school'];
  246. }
  247. }
  248. /**
  249. * This form lets the user edit details about a course.
  250. */
  251. function admin_edit_course_form() {
  252. $form = array();
  253. $db = get_global_database_handler();
  254. $course_id = @$_REQUEST["course_id"];
  255. $subject_id = @$_REQUEST["subject_id"];
  256. $subject_id = str_replace("_A_","&",$subject_id);
  257. $course_num = @$_REQUEST["course_num"];
  258. $school_id = $db->get_school_id_for_course_id($course_id, TRUE);
  259. $de_catalog_year = admin_get_de_catalog_year(TRUE, $school_id);
  260. $m = 0;
  261. fp_set_title(t("Edit Course @course", array("@course" => "$subject_id $course_num ($de_catalog_year)")));
  262. fp_add_css(fp_get_module_path("admin") . "/css/admin.css");
  263. fp_add_js(fp_get_module_path("admin") . "/js/admin.js");
  264. $form["de_catalog_year"] = array(
  265. "type" => "hidden",
  266. "value" => $de_catalog_year,
  267. );
  268. $form["course_id"] = array(
  269. "type" => "hidden",
  270. "value" => $course_id,
  271. );
  272. $form["subject_id"] = array(
  273. "type" => "hidden",
  274. "value" => $subject_id,
  275. );
  276. $form["course_num"] = array(
  277. "type" => "hidden",
  278. "value" => $course_num,
  279. );
  280. $form["perform_action2"] = array(
  281. "type" => "hidden",
  282. "value" => "",
  283. );
  284. // Begin the form...
  285. /*
  286. if (@$_SESSION["de_advanced_mode"] == true)
  287. {
  288. $pC .= " <span class='tenpt' style='background-color: yellow; margin-left: 20px;'>
  289. adv: course_id = $course_id. Used by:
  290. <a href='javascript: popupWindow(\"admin.php?performAction=popup_degrees_using_course&course_id=$course_id\")'>[degrees]</a>
  291. <a href='javascript: popupWindow(\"admin.php?performAction=popup_groups_using_course&course_id=$course_id\")'>[groups]</a>
  292. <a href='javascript: popupWindow(\"admin.php?performAction=popup_students_using_course&course_id=$course_id\")'>[students]</a>
  293. </span>";
  294. }
  295. */
  296. $course = new Course($course_id,false,null,false,$de_catalog_year, TRUE);
  297. $course->catalog_year = $de_catalog_year; // Since it may be 1900, force it!
  298. $course->load_descriptive_data(false, true, false, true, true);
  299. $course->catalog_year = $de_catalog_year; // Since it may be 1900, force it!
  300. $all_names = $course->get_all_names(true);
  301. $warn_eqv = "";
  302. if (strstr($all_names, ",")) {
  303. $warn_eqv = "yes";
  304. }
  305. // Correct ghosthours, if they exist.
  306. if ($course->bool_ghost_hour) {
  307. $course->max_hours = 0;
  308. }
  309. if ($course->bool_ghost_min_hour) {
  310. $course->min_hours = 0;
  311. }
  312. $form['school_id'] = array(
  313. 'type' => 'hidden',
  314. 'value' => intval($course->school_id),
  315. );
  316. $form["course_names"] = array(
  317. "type" => "textfield",
  318. "label" => t("Course names(s):"),
  319. "required" => TRUE,
  320. "value" => $all_names,
  321. "popup_description" => t("These are the possible display names for this course. Typically,
  322. there will be only one name. Ex: ACCT 110. You must place a space
  323. between the subject ID and course number.
  324. If this course is known by another name (has an eqv course)
  325. then enter it as well using a comma.
  326. Ex: ACCT 110, MATH 110A
  327. Add the word 'exclude' to prevent it from showing in course
  328. selection windows in FlightPath.
  329. Ex: ACCT 110, MATH 110A exclude
  330. IMPORTANT: Course names are updated for ALL YEARS of a course."),
  331. "weight" => 10,
  332. );
  333. $form["title"] = array(
  334. "type" => "textfield",
  335. "label" => t("Title:"),
  336. "value" => $course->title,
  337. "popup_description" => t("The title of the course displayed in FlightPath."),
  338. "weight" => 20,
  339. );
  340. $form["min_hours"] = array(
  341. "type" => "textfield",
  342. "label" => t("Min hours:"),
  343. "size" => 10,
  344. "value" => $course->min_hours,
  345. "popup_description" => t("The min and max hours for a course will usually be the same
  346. number. Ex: 3. If they differ, it means the course has
  347. variable hours.
  348. For example, if you have a course
  349. worth 1-6 hours, enter 1 for min, and 6 for max."),
  350. "weight" => 30,
  351. );
  352. $form["max_hours"] = array(
  353. "type" => "textfield",
  354. "label" => t("Max hours:"),
  355. "size" => 10,
  356. "value" => $course->max_hours,
  357. "popup_description" => t("The min and max hours for a course will usually be the same
  358. number. Ex: 3. If they differ, it means the course has
  359. variable hours.
  360. For example, if you have a course
  361. worth 1-6 hours, enter 1 for min, and 6 for max."),
  362. "weight" => 40,
  363. );
  364. $form["repeat_hours"] = array(
  365. "type" => "textfield",
  366. "label" => t("Repeat hours:"),
  367. "size" => 10,
  368. "value" => $course->repeat_hours,
  369. "popup_description" => t("This is the number of hours a course may be repeated for credit.
  370. For example, if a course is worth 3 hours, but may be repeated
  371. for up to 9 hours of credit, enter a 9 in this box.
  372. If a course CANNOT be repeated for credit, this would
  373. be the same number as the min and max, or simply blank.
  374. If you are unsure what to enter, leave it blank."),
  375. "weight" => 50,
  376. );
  377. $form["description"] = array(
  378. "type" => "textarea",
  379. "label" => t("Description"),
  380. "value" => $course->description,
  381. "rows" => 4,
  382. "cols" => 80,
  383. "weight" => 60,
  384. );
  385. $form["all_years"] = array(
  386. "type" => "checkboxes",
  387. "label" => t("Update for all years?"),
  388. "options" => array("yes" => t("Update title, description, and hour info for all years of this course.")),
  389. "popup_description" => t("Check this box and press Submit to update title, description, and hour information
  390. for all available years of this course. Note that course name is automatically
  391. updated for all years, regardless if you check this box or not."),
  392. "weight" => 70,
  393. );
  394. $form["data_entry_comment"] = array(
  395. "type" => "textarea",
  396. "label" => t("Optional Comment: (only seen by other FlightPath administrators)"),
  397. "rows" => 3,
  398. "cols" => 80,
  399. "value" => $course->data_entry_comment,
  400. "weight" => 80,
  401. );
  402. $form["submit"] = array(
  403. "type" => "submit",
  404. "value" => t("Save for @year", array("@year" => $de_catalog_year)),
  405. "prefix" => "<hr>",
  406. "weight" => 90,
  407. );
  408. // Only show delete option based on permission
  409. if (user_has_permission("can_delete_data_entry")) {
  410. $form["mark" . $m++] = array(
  411. "type" => "markup",
  412. "value" => "<div align='right' class='courses-delete-course-wrapper'>
  413. " . t("Delete this course?") . " <input type='button' value='X'
  414. onClick='adminDeleteCourse(\"$course_id\",\"$de_catalog_year\",\"$warn_eqv\");'>
  415. </div>",
  416. "weight" => 100,
  417. );
  418. }
  419. return $form;
  420. }
  421. function admin_edit_course_form_submit(&$form, &$form_submit) {
  422. $values = $form_submit["values"];
  423. $de_catalog_year = $values["de_catalog_year"];
  424. $course_id = trim($values["course_id"]);
  425. $course_names = trim($values["course_names"]);
  426. $school_id = intval($values['school_id']);
  427. $db = get_global_database_handler();
  428. if ($course_names == "") {
  429. $course_names = $values["subject_id"] . " " . $values["course_num"];
  430. }
  431. $title = trim($values["title"]);
  432. $min_hours = floatval(trim($values["min_hours"]));
  433. $max_hours = floatval(trim($values["max_hours"]));
  434. $repeat_hours = floatval(trim($values["repeat_hours"]));
  435. //$exclude = trim($_POST["exclude"]);
  436. $description = trim($values["description"]);
  437. $data_entry_comment = trim($values["data_entry_comment"]);
  438. // Since we are making a change to the draft table(s), let's add a row
  439. // to draft instructions.
  440. $db->add_draft_instruction("-");
  441. // Unlike the degrees and the groups, course_ids are not
  442. // unique. We can have the same course id over multiple rows, with different catalog years. This
  443. // is so we can handle equivalent courses more gracefully.
  444. // So, the first thing we need to do is delete *all* courses with the
  445. // course_id and catalog_year listed above. For most courses, this will
  446. // only be one row. For eqv courses, this will delete more than one row.
  447. if ($course_id != "new") {
  448. // Don't delete! Temporarily transfer to a temporary course_id.
  449. // Will possibly delete later.
  450. $res = db_query("UPDATE draft_courses
  451. SET course_id = '-12345'
  452. WHERE course_id = ?
  453. AND catalog_year = ?
  454. AND school_id = ? ", $course_id, $de_catalog_year, $school_id);
  455. }
  456. if ($values["perform_action2"] == "delete_course" && user_has_permission("can_delete_data_entry")) {
  457. // That's it. All we wanted to do was delete the course.
  458. $query = "DELETE FROM draft_courses
  459. WHERE course_id = '-12345'
  460. AND school_id = ?
  461. ";
  462. $res = db_query($query, $school_id);
  463. fp_add_message(t("Course %course successfully deleted for %year", array("%course" => $course_names, "%year" => $de_catalog_year)));
  464. watchdog("admin", "Course $course_names deleted. Course id: $course_id, ($de_catalog_year), school_id: $school_id");
  465. // Redirect us to the list of courses.
  466. $form["#redirect"] = array(
  467. "path" => "admin/courses",
  468. "query" => "de_catalog_year=$de_catalog_year",
  469. );
  470. return;
  471. }
  472. // If the $course_id == new then create a new one.
  473. if ($course_id == "new") {
  474. $course_id = $db->request_new_course_id();
  475. $values["course_id"] = $course_id;
  476. // change the $form redirect so we get sent to the new course on save.
  477. $form["#redirect"] = array(
  478. "path" => "admin/courses/edit-course",
  479. "query" => "de_catalog_year=$de_catalog_year&course_id=$course_id",
  480. );
  481. $form_submit['values']['course_id'] = $course_id; // set the new course id back into the array, for other modules to use.
  482. }
  483. // Now, we will split the courseNames on commas, and for each
  484. // token, we will insert a row into the database.
  485. $courses = explode(",", $course_names);
  486. foreach($courses as $course) {
  487. $course = str_replace(" ", " ", $course);
  488. $course = str_replace(" ", " ", $course);
  489. $course = str_replace(" ", " ", $course);
  490. $course = trim($course);
  491. if ($course == "") { continue; }
  492. $temp = explode(" ", $course);
  493. $subject_id = trim($temp[0]);
  494. $course_num = trim($temp[1]);
  495. ////////////
  496. /// Error conditions...
  497. if (strtolower($course_num) == "exclude" || $course_num == "") {
  498. form_error("course_names", t("It appears you specified an excluded course
  499. without a course number. You entered %course.
  500. Notice there is no course number. Please re-enter.", array("%course" => "$subject_id $course_num")));
  501. continue;
  502. }
  503. ////////////////
  504. $exclude = 0;
  505. // Do we exclude?
  506. if (isset($temp[2]) && strtolower(fp_trim($temp[2])) == "exclude") {
  507. $exclude = 1;
  508. // Set ALL courses with this subject_id and course_num to exclude!
  509. $res = db_query("UPDATE draft_courses
  510. SET exclude = 1
  511. WHERE subject_id = ?
  512. AND course_num = ?
  513. AND school_id = ?
  514. ", $subject_id, $course_num, $school_id);
  515. }
  516. else {
  517. // Aet all courses with this subject_id and course_num to NOT exclude!
  518. $res = db_query("UPDATE draft_courses
  519. SET exclude = 0
  520. WHERE subject_id = ?
  521. AND course_num = ?
  522. AND school_id = ?
  523. ", $subject_id, $course_num, $school_id);
  524. }
  525. // Did the user specify a course which already exists? If so,
  526. // mark that course's ID as -12345...
  527. $res = db_query("UPDATE draft_courses
  528. SET course_id = '-12345'
  529. WHERE subject_id = ?
  530. AND course_num = ?
  531. AND catalog_year = ?
  532. AND school_id = ? ", $subject_id, $course_num, $de_catalog_year, $school_id);
  533. // We now have enough information to make an insertion into
  534. // the table.
  535. $query = "INSERT INTO draft_courses
  536. (`course_id`,`subject_id`,`course_num`,`catalog_year`,
  537. `title`,`description`,`min_hours`,`max_hours`,`repeat_hours`,
  538. `exclude`,`data_entry_comment`, `school_id`)
  539. values (?,?,?,?,?,?,?,?,?,?,?,?) ";
  540. //debug_c_t($query);
  541. $res = db_query($query, $course_id,$subject_id,$course_num,$de_catalog_year,
  542. $title,$description,$min_hours,$max_hours,$repeat_hours,
  543. $exclude,$data_entry_comment,$school_id);
  544. // Now, this part is tricky. Are there any courses which already
  545. // existed with this subject_id and course_num, but not this course_id?
  546. // This would happen if we add an eqv for a course that already existed
  547. // elsewhere. We want to change that existing course's ID to match the
  548. // new one, but we also need to update EVERY table that used the old
  549. // course_id with the new course_id, including degree plans, groups,
  550. // substitutions, etc.
  551. // query for subject_id and course_num but != course_id.
  552. // get oldCourseID.
  553. // call function update_course_id(oldCourseID, newCourseID)
  554. $res2 = db_query("SELECT * FROM draft_courses WHERE
  555. subject_id = ?
  556. AND course_num = ?
  557. AND course_id != ?
  558. AND course_id != '-12345'
  559. AND school_id = ? ", $subject_id, $course_num, $course_id, $school_id);
  560. while ($cur2 = db_fetch_array($res2)) {
  561. $old_course_id = $cur2["course_id"];
  562. // Now, update all the existing references to $old_course_id
  563. // with the new course_id.
  564. $db2 = new DatabaseHandler();
  565. $db2->update_course_id($old_course_id, $course_id, true);
  566. // Now, add it to our list of things to update when we apply
  567. // the draft changes...
  568. $db2->add_draft_instruction("update_course_id,$old_course_id,$course_id,$school_id");
  569. }
  570. }
  571. // We have to accomodate the situation that there used to be an
  572. // eqv set up (multiple course names were set) but now there is not.
  573. // In other words, someone wanted to undo an eqv.
  574. // We used to have: ACCT 101, MATH 101
  575. // But they took out the comma. So, only ACCT 101 just got written
  576. // to the database, while MATH 101 has been marked as -12345 and is
  577. // destined to be deleted.
  578. // -- we need to give MATH 101 a new course_id and update that course_id
  579. // for all years.
  580. // Then, we need to go through all our tables and update where it was
  581. // actually spelled out that "MATH 101" be used with the new course_id.
  582. // -- This process will ensure that no previous existing courses
  583. // will get deleted. That they will remain as their own unique
  584. // courses.
  585. // First thing's first. Go through all the courses with the course_id
  586. // of -12345. If we find one that does not have the same subject_id
  587. // and course_num with the new ID, then this is a removed eqv, and
  588. // that is our cue that it should be it's own course.
  589. $res = db_query("SELECT * FROM draft_courses
  590. WHERE course_id = '-12345'
  591. AND school_id = ? ", $school_id);
  592. while ($cur = db_fetch_array($res)) {
  593. $found_s_i = $cur["subject_id"];
  594. $found_c_n = $cur["course_num"];
  595. $db2 = new DatabaseHandler();
  596. $res2 = $db2->db_query("SELECT * FROM draft_courses
  597. WHERE course_id = ?
  598. AND subject_id = ?
  599. AND course_num = ?
  600. AND catalog_year = ?
  601. AND school_id = ? ", $course_id, $found_s_i, $found_c_n, $de_catalog_year, $school_id);
  602. if ($db2->db_num_rows($res2) == 0) {
  603. // Meaning, this course name is not listed with the course_id,
  604. // so this is a broken eqv.
  605. // We should make a new course_id and all that for this course,
  606. // for all available years.
  607. $new_course_id = $db2->request_new_course_id();
  608. $db3 = new DatabaseHandler();
  609. $res3 = $db3->db_query("UPDATE draft_courses
  610. SET course_id = ?
  611. WHERE subject_id = ?
  612. AND course_num = ?
  613. AND school_id = ? ", $new_course_id, $found_s_i, $found_c_n, $school_id);
  614. // removed WHERE `course_id`='-12345' from query. We want to UPDATE
  615. // this across all years for this course.
  616. // And also UPDATE every other table that specified foundSI &CN
  617. // as a requirement.
  618. $db3->update_course_requirement_from_name($found_s_i, $found_c_n, $new_course_id, $school_id);
  619. $db3->add_draft_instruction("update_course_requirement_from_name,$found_s_i,$found_c_n,$new_course_id,$school_id");
  620. }
  621. }
  622. // Was the "all_years" box checked? If it was, then update all instances
  623. // of this course, across all available catalog years.
  624. if (is_array($values["all_years"]) && $values["all_years"]["yes"] == "yes") {
  625. $res = db_query("UPDATE draft_courses
  626. SET title = ?,
  627. description = ?,
  628. min_hours = ?,
  629. max_hours = ?,
  630. repeat_hours = ?
  631. WHERE course_id = ?
  632. AND school_id = ? ", $title, $description, $min_hours, $max_hours, $repeat_hours, $course_id, $school_id);
  633. }
  634. watchdog("admin", "Course $course_names updated. ($de_catalog_year), school_id: $school_id");
  635. // Clean up. Delete the temporary course_id...
  636. $res = db_query("DELETE FROM draft_courses WHERE course_id = '-12345' AND school_id = ? ", $school_id);
  637. fp_add_message("Course updated successfully.");
  638. }

Functions

Namesort descending Description
admin_courses_list_filter_form
admin_courses_list_filter_form_submit
admin_display_courses This function displays all of our courses for us to edit.
admin_edit_course_form This form lets the user edit details about a course.
admin_edit_course_form_submit