course_search.edit.inc

  1. 7.x modules/course_search/course_search.edit.inc
  2. 6.x modules/course_search/course_search.edit.inc
  3. 4.x modules/course_search/course_search.edit.inc
  4. 5.x modules/course_search/course_search.edit.inc

This file contains functions relating to editing the course info, like rotation schedule and syllabus

File

modules/course_search/course_search.edit.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * This file contains functions relating to editing the course info, like rotation schedule
  5. * and syllabus
  6. */
  7. /**
  8. * This form lets the user edit the course's syllabus or rotation schedule
  9. */
  10. function course_search_edit_course_details_form() {
  11. $form = array();
  12. $m = 0;
  13. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
  14. $course_id = $_REQUEST["course_id"];
  15. $subject_id = $_REQUEST["subject_id"];
  16. $course_num = $_REQUEST["course_num"];
  17. $catalog_year = variable_get("current_catalog_year", 2006);
  18. $course = new Course($course_id,false,null,false,$catalog_year);
  19. $course->load_descriptive_data(false, true, false, true);
  20. fp_set_title(t("Edit Course Info for @course", array("@course" => "$subject_id $course_num")));
  21. $form["#attributes"] = array("enctype" => "multipart/form-data");
  22. $form["course_id"] = array(
  23. "type" => "hidden",
  24. "value" => $course_id,
  25. );
  26. $form["subject_id"] = array(
  27. "type" => "hidden",
  28. "value" => $subject_id,
  29. );
  30. $form["course_num"] = array(
  31. "type" => "hidden",
  32. "value" => $course_num,
  33. );
  34. $course->catalog_year = $catalog_year;
  35. // Find out filename/link of current syllabus.
  36. $filelink = "- None currently entered -";
  37. $filename = "";
  38. if ($syllabus_details = course_search_get_course_syllabus_details("", "", $course_id)) {
  39. $filename = $syllabus_details["filename"];
  40. }
  41. $bool_delete_cb = FALSE;
  42. if ($filename != "") {
  43. $filelink = $filename;
  44. $bool_delete_cb = TRUE;
  45. }
  46. $form["mark" . $m++] = array(
  47. "value" => "<strong>$course->title (" . $course->get_catalog_hours() . " " . t("hrs.") . ")</strong>
  48. <div class='tenpt'>$course->description</div>
  49. ",
  50. );
  51. $form["syllabus"] = array(
  52. "type" => "file",
  53. "label" => t("Submit new sample course syllabus:"),
  54. "prefix" => "<br><br>" . t("Current sample syllabus:") . " " . $filelink,
  55. "description" => t("Note: selecting a new file will replace any existing
  56. syllabus. Remember to click Submit after selecting a file."),
  57. );
  58. if ($bool_delete_cb) {
  59. $form["del_syllabus"] = array(
  60. "type" => "checkboxes",
  61. "options" => array("yes" => t("Delete the existing syllabus?")),
  62. );
  63. }
  64. if ($filename != "") {
  65. $s_url = $syllabus_details["url"];
  66. $form["mark" . $m++] = array(
  67. "value" => "<p>" . t("Syllabus may be downloaded using this address: ") . "<a href='$s_url'>$s_url</a></p>",
  68. );
  69. }
  70. $form["mark" . $m++] = array(
  71. "value" => "<b>" . t("Course Rotation Schedule:") . "</b>
  72. <br>" . t("Select semesters/terms in which this Course
  73. will be offered for the next five years."),
  74. );
  75. //$term_array = get_term_id_suffixes();
  76. $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
  77. $form["mark" . $m++] = array(
  78. "value" => "<div class='rotation-form-checkboxes'>",
  79. );
  80. $term_structures = get_term_structures();
  81. $y = 1;
  82. for ($t = $catalog_year; $t <= $catalog_year + 5; $t++) {
  83. $form["year$y"] = array(
  84. "type" => "hidden",
  85. "value" => $t,
  86. );
  87. foreach($term_array as $x) {
  88. $check_year = $t;
  89. $term_id = $check_year . $x;
  90. // Should we make any adjustments based on the term_structure?
  91. // Does the term suffix ($x) call for the year to be
  92. // subtracted by 1? This is the case at ULM for fall.
  93. // Ex: 201340 is Fall of *2012*, not 2013.
  94. // We can tell this because the term structure (from admin settings)
  95. if (@strtoupper($term_structures[$x]["disp_adjust"]) == "[Y-1]") {
  96. $term_id = ($check_year + 1) . $x;
  97. }
  98. $new_course = new Course();
  99. $new_course->term_id = $term_id;
  100. $cb_disp_name = $new_course->get_term_description(TRUE);
  101. $cbname = $new_course->term_id;
  102. $cb_default_val = array();
  103. // See if this box should be checked...
  104. $res = db_query("select * from course_rotation_schedule
  105. where `course_id`='?'
  106. and `term_id`='$term_id' ", $course_id);
  107. if (db_num_rows($res) > 0) {
  108. $cb_default_val = array("yes" => "yes");
  109. }
  110. $form["cb_$cbname"] = array(
  111. "type" => "checkboxes",
  112. "options" => array("yes" => $cb_disp_name),
  113. "value" => $cb_default_val,
  114. );
  115. }
  116. $form["mark" . $m++] = array(
  117. "value" => "<br>",
  118. );
  119. $y++;
  120. }
  121. $form["mark" . $m++] = array(
  122. "value" => "</div>",
  123. );
  124. // Not anticipated check.
  125. $default_val = array();
  126. $res = db_query("SELECT * FROM course_rotation_schedule
  127. WHERE `course_id`='?'
  128. AND `term_id`='NOTA' ", $course_id);
  129. //debug_c_t("$t$x");
  130. if (db_num_rows($res) > 0)
  131. {
  132. $default_val = array("yes" => "yes");
  133. }
  134. $form["not_anticipated"] = array(
  135. "type" => "checkboxes",
  136. "label" => t("Not Anticipated:"),
  137. "options" => array("yes" => t("This course is not anticipated.")),
  138. "value" => $default_val,
  139. "description" => t("Checking this box means that the course is not
  140. anticipated to be offered within the time range above.
  141. This will override any selections made above."),
  142. );
  143. $form["submit"] = array(
  144. "type" => "submit",
  145. "value" => t("Submit"),
  146. "prefix" => "<hr>",
  147. );
  148. return $form;
  149. }
  150. function course_search_edit_course_details_form_submit($form, $form_state) {
  151. global $user;
  152. $faculty_id = $user->cwid;
  153. $course_id = $form_state["values"]["course_id"];
  154. $subject_id = $form_state["values"]["subject_id"];
  155. $course_num = $form_state["values"]["course_num"];
  156. //$term_array = get_term_id_suffixes();
  157. $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
  158. for ($t = 1; $t <= 6; $t++) {
  159. $year = $form_state["values"]["year$t"];
  160. // delete the existing entries for this year & course here.
  161. db_query("DELETE FROM course_rotation_schedule
  162. WHERE `course_id`= ?
  163. AND `term_id` LIKE ? ", $course_id, "$year%");
  164. /////////////////////////
  165. // Now, for x = 1 to 5,
  166. // if ($_request["cb_$year$x"] == "yes")
  167. // then insert into table... blah blah...
  168. foreach($term_array as $x) {
  169. if ($form_state["values"]["cb_$year$x"]["yes"] == "yes") {
  170. db_query("INSERT INTO course_rotation_schedule
  171. (faculty_id, course_id, term_id, entry_value, posted)
  172. VALUES (?, ?, ?, ?, ?) ", $faculty_id, $course_id, "$year$x", "$subject_id~$course_num", time());
  173. }
  174. }
  175. }
  176. // Not anticipated check?
  177. // delete first...
  178. db_query("DELETE FROM course_rotation_schedule
  179. WHERE course_id = ?
  180. AND term_id = 'NOTA' ", $course_id);
  181. if ($form_state["values"]["not_anticipated"]["yes"] == "yes") {
  182. db_query("INSERT INTO course_rotation_schedule
  183. (faculty_id, course_id, term_id, entry_value, posted)
  184. VALUES (?, ?, ?, ?, ?) ", $faculty_id, $course_id, "NOTA", "$subject_id~$course_num", time());
  185. }
  186. // Should we delete the current syllabus?
  187. if ($form_state["values"]["del_syllabus"]["yes"] == "yes") {
  188. if ($details = course_search_get_course_syllabus_details("", "", $course_id)) {
  189. $filename = $details["filename"];
  190. if ($filename != "") {
  191. unlink("./custom/files/syllabi/$filename");
  192. db_query("DELETE FROM course_syllabi
  193. WHERE `course_id`= ? ", $course_id);
  194. }
  195. }
  196. }
  197. // Did the user try to upload a file?
  198. if (trim($_FILES["syllabus"]["tmp_name"]) != "")
  199. {
  200. $test = course_search_upload_attachment($course_id, $subject_id, $course_num);
  201. if (!$test)
  202. {
  203. fp_add_message(t("There was an error uploading attachment. It is possible this is a write-permission
  204. issue with the server."));
  205. } else {
  206. // success.
  207. }
  208. }
  209. fp_add_message(t("This course's details have been updated successfully."));
  210. // TODO: Do a "goto" back to wherever we came from
  211. }
  212. function course_search_upload_attachment($course_id, $subject_id, $course_num) {
  213. // If any files were attached, go ahead and upload them.
  214. $datetime = date ("_y-j-m_g-i-sa", time());
  215. $tmp_filename = $_FILES["syllabus"]["tmp_name"];
  216. if (trim($tmp_filename) != "") {
  217. // Meaning, yes, a file was uploaded.
  218. $suffix = $datetime;
  219. // Create the new filename, based on the id's its been assigned.
  220. $original_filename = $_FILES["syllabus"]["name"];
  221. // replace problem characters...
  222. $original_filename = str_replace("'", "", $original_filename);
  223. $original_filename = str_replace('"', '', $original_filename);
  224. $original_filename = str_replace(",", "", $original_filename);
  225. $temp = explode("\.", $original_filename);
  226. $ext = $temp[count($temp) - 1]; // get the original extension.
  227. $new_filename = $original_filename . ".$suffix.$ext";
  228. // Does the directory/files/syllabi exist?
  229. // If not, we will create it.
  230. $files_path = $GLOBALS["fp_system_settings"]["file_system_path"];
  231. if (!is_dir("$files_path/custom/files/syllabi")) {
  232. if (!mkdir("$files_path/custom/files/syllabi")) {
  233. return FALSE;
  234. }
  235. }
  236. // Try to copy...
  237. if (!copy($tmp_filename, "$files_path/custom/files/syllabi/$new_filename")) {
  238. return FALSE;
  239. }
  240. // If we are here, then there is success! We should update the
  241. // table with the new filename, which is $new_filename.
  242. // delete the existing entry, if any.
  243. // We need to unlink any existing syllabus file...
  244. if ($file_details = course_search_get_course_syllabus_details($subject_id, $course_num, $course_id)) {
  245. $filename = $file_details["filename"];
  246. if (!unlink("$files_path/custom/files/syllabi/$filename")) {
  247. fp_add_message(t("Unable to delete existing file:") . " $filename");
  248. }
  249. }
  250. db_query("DELETE FROM course_syllabi
  251. WHERE course_id = '?' ", $course_id);
  252. // Okay, now add the new entry.
  253. db_query("INSERT INTO course_syllabi
  254. (course_id, course_perm_id, filename, posted)
  255. values (?, ?, ?, ? )", $course_id, $subject_id . '_' . $course_num, $new_filename, time());
  256. }
  257. return TRUE;
  258. }
  259. /**
  260. * Display a plain list of courses, making it easier for admins to edit schedules and details in one spot.
  261. *
  262. */
  263. function course_search_display_edit_courses()
  264. {
  265. $rtn = "";
  266. $current_catalog_year = variable_get("current_catalog_year", "");
  267. // catalog_year is always just whatever the current year is.
  268. $catalog_year = $current_catalog_year;
  269. $cc = 1;
  270. // Get the "upper range" (UR) and
  271. // lower range (LR) of the courses in question...
  272. $ur = trim($_GET["ur"]);
  273. $lr = trim($_GET["lr"]);
  274. if ($ur == "")
  275. { // meaning, no range was set. Use A - AZZZZZ, so, all of the A's.
  276. $ur = $_SESSION["dec_ur"];
  277. $lr = $_SESSION["dec_lr"];
  278. if ($ur == "")
  279. { // if still blank, assign it..
  280. $ur = "A";
  281. $lr = "AZZZZ";
  282. }
  283. }
  284. $_SESSION["dec_ur"] = $ur;
  285. $_SESSION["dec_lr"] = $lr;
  286. $rtn .= "<h2 class='title'>" . t("Update Course Information") . "</h2>
  287. <div class='tenpt' style='margin-bottom: 20px;'>
  288. " . t("To update a course's sample syllabus or schedule,
  289. please select the course from the list below.") . "
  290. <br>
  291. " . l(t("View Reports"), "tools/course-search/view-reports") . "
  292. </div>
  293. ";
  294. $letter_ranges = array(
  295. "A" => array("A", "AZZZZ"),
  296. "B" => array("B", "BZZZZ"),
  297. "C-CN" => array("C", "CNZZZ"),
  298. "CO-CZ" => array("CO", "CZZZZ"),
  299. "D" => array("D", "DZZZZ"),
  300. "E" => array("E", "EZZZZ"),
  301. "F" => array("F", "FZZZZ"),
  302. "G" => array("G", "GZZZZ"),
  303. "H" => array("H", "HZZZZ"),
  304. "I-L" => array("I", "LZZZZ"),
  305. "M-MR" => array("M", "MRZZZ"),
  306. "MS-MZ" => array("MS", "MZZZZ"),
  307. "N-O" => array("N", "OZZZZ"),
  308. "P" => array("P", "PZZZZ"),
  309. "Q-R" => array("Q", "RZZZZ"),
  310. "S-SO" => array("S", "SOZZZ"),
  311. "SP-SZ" => array("SP", "SZZZZ"),
  312. "T-Z" => array("T", "ZZZZZ"),
  313. );
  314. $rtn .= "<div class='admin-courses-select-letter-bar'>
  315. ";
  316. foreach($letter_ranges as $disp => $vals) {
  317. $rtn .= l($disp, "tools/course-search/edit-list", "ur=" . $vals[0] . "&lr=" . $vals[1], array("class" => "admin-courses-letter-link")) . " &nbsp; ";
  318. }
  319. $rtn .= "</div>
  320. <hr>";
  321. $rtn .= "<table border='0' cellpadding='3' cellspacing='0'>
  322. <tr>
  323. <td class='tenpt' width='95%'>Course</td>
  324. <td class='tenpt'>Sch</td>
  325. <td class='tenpt'>Syl</td>
  326. <td class='tenpt'>Updated</td>
  327. </tr>";
  328. $res = db_query("SELECT * FROM courses
  329. WHERE
  330. `catalog_year`='?' AND
  331. `subject_id` BETWEEN '?' AND '?'
  332. AND `delete_flag`='0'
  333. AND `exclude`='0'
  334. ORDER BY `subject_id`, `course_num` ", $catalog_year, $ur, $lr);
  335. while ($cur = db_fetch_array($res)) {
  336. extract($cur, 3, "db");
  337. $syl = $sch = $updated = "";
  338. // Right here, maybe check to see if this course has
  339. // a syllabus and/or schedule entered?
  340. $syllabus_details = course_search_get_course_syllabus_details("", "", $db_course_id);
  341. $filename = $syllabus_details["filename"];
  342. if ($filename != "") {
  343. $url = $syllabus_details["url"];
  344. $syl = "<a href='$url'><img src='" . fp_theme_location() . "/images/document_icon.gif' border='0'></a>";
  345. $updated = $syllabus_details["posted"];
  346. }
  347. $schedule_array = course_search_get_course_rotation_schedule($db_course_id, $catalog_year, 100, TRUE);
  348. $not_ant = course_search_get_course_rotation_schedule_not_anticipated($db_course_id);
  349. if (count($schedule_array) > 0 || $not_ant == true) {
  350. $sch = "<img src='" . fp_theme_location() . "/images/small_check.gif'>";
  351. if ($not_ant) {
  352. $sch = "NA";
  353. }
  354. // When was the schedule last updated?
  355. $res2 = db_query("SELECT * FROM course_rotation_schedule
  356. WHERE `course_id`='?' limit 1", $db_course_id);
  357. $cur2 = db_fetch_array($res2);
  358. $updated2 = $cur2["posted"];
  359. if ($updated2 > $updated) {
  360. $updated = $updated2;
  361. }
  362. }
  363. if ($updated != "") {
  364. $updated = date("n/d/y",$updated);
  365. }
  366. $hrs = $db_min_hours;
  367. if (trim($db_min_hours) != trim($db_max_hours)) {
  368. $hrs .= " - $db_max_hours";
  369. }
  370. $hrs .= " hrs.";
  371. $rep_hours = "";
  372. if ($db_repeat_hours > $db_min_hours)
  373. {
  374. $rep_hours = " rep to $db_repeat_hours hrs.";
  375. }
  376. // remove special chars from subject_id...
  377. $display_subject_id = $db_subject_id;
  378. $db_subject_id = urlencode($db_subject_id);
  379. $rtn .= "<tr style='$spanstyle'>
  380. <td valign='top' width='90%'>";
  381. /*$rtn .= "<div style='padding:3px;'>
  382. <a href='$moduleActionURL&performAction=editSpecificCourse&courseID=$db_course_id&subjectID=$db_subject_id&courseNum=$db_course_num'>$displaySubjectID $db_course_num - $db_title</a><!-- - $hrs$repHours --></div>";
  383. */
  384. $rtn .= l("$display_subject_id $db_course_num - $db_title", "tools/course-search/edit-info-details", "course_id=$db_course_id&subject_id=$db_subject_id&course_num=$db_course_num");
  385. // https://orion.ulm.edu/flightpath/tools/course-search/edit-info-details?course_id=468798&subject_id=ACCT&course_num=1010
  386. $rtn .= "</td>
  387. <td align='center'>$sch</td>
  388. <td align='center'>$syl</td>
  389. <td align='center' style='font-size: 8pt;'>$updated</td>
  390. </tr>";
  391. } // while
  392. $rtn .= "</table>";
  393. return $rtn;
  394. }
  395. function course_search_display_view_reports() {
  396. $rtn = "";
  397. $rtn .= "<h2 class='title'>" . t("View Reports") . "</h2>";
  398. $rtn .= "<ul>";
  399. $rtn .= "<li>" . l(t("[CSV] Anticipated Offerings - All Courses"), "tools/course-search/get-offering-csv") . "</a>
  400. - " . t("This report shows all courses in the catalog's anticipated offerings
  401. for the next 5 years. Will be downloaded as a CSV file.
  402. <b>May take up to a minute to load.</b>") . "</li> ";
  403. $rtn .= "</ul>";
  404. return $rtn;
  405. }
  406. function course_search_get_offering_csv() {
  407. $csv = "";
  408. $csv .= "SUBJ, NUM, COL, DEPT, SYL UPDATED, ";
  409. $catalog_year = variable_get("current_catalog_year", "");
  410. $course_term_array = array();
  411. $check_term_array = array();
  412. $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
  413. for ($t = $catalog_year; $t <= $catalog_year + 5; $t++)
  414. {
  415. foreach($term_array as $x)
  416. {
  417. $check_year = $t;
  418. $term_id = $check_year . $x;
  419. $check_term_array[] = $term_id;
  420. $new_course = new Course();
  421. $new_course->term_id = $term_id;
  422. $disp_name = $new_course->get_term_description(TRUE);
  423. $csv .= " " . $disp_name . " ($term_id) ,";
  424. // While we are here, we are going to get an array of ALL the courses
  425. // which have an entry for this term in our table. This should make
  426. // it faster to look up later.
  427. $res = db_query("SELECT * FROM course_rotation_schedule
  428. WHERE `term_id`='?' ", $term_id);
  429. while ($cur = db_fetch_array($res)) {
  430. $course_term_array[$term_id][$cur["course_id"]] = TRUE;
  431. }
  432. }
  433. }
  434. // Take off last comma of csv.
  435. $csv = substr($csv, 0, -1);
  436. //var_dump($courseTermArray);
  437. //debugCT($csv);
  438. $csv .= "\n";
  439. //return;
  440. $result = db_query("SELECT * FROM courses
  441. WHERE
  442. `catalog_year`='?'
  443. AND `delete_flag`='0'
  444. AND `exclude`='0'
  445. ORDER BY `subject_id`, `course_num` ", $catalog_year);
  446. while ($cur = db_fetch_array($result)) {
  447. extract($cur, 3, "db");
  448. //debugCT($db_subject_id . $db_course_num);
  449. $csv .= "$db_subject_id, $db_course_num, ";
  450. // What college does this course belong to?
  451. $res2 = db_query("SELECT * FROM subjects
  452. WHERE subject_id = '?' ", $db_subject_id);
  453. $cur2 = db_fetch_array($res2);
  454. $college = $cur2["college"];
  455. $dept_name = $cur2["title"];
  456. $csv .= "$college, $dept_name, ";
  457. // Also, when was their last syllabus submitted?
  458. $syl = "";
  459. $res2 = db_query("SELECT * FROM course_syllabi WHERE course_id = '?'", $db_course_id);
  460. $cur2 = db_fetch_array($res2);
  461. $syl = format_date($cur2["posted"]);
  462. $csv .= "$syl, ";
  463. // Now, get course offerings for the next X terms...
  464. foreach ($check_term_array as $term_id) {
  465. // See if this term is offered for this course
  466. if ($course_term_array[$term_id][$db_course_id] == TRUE) {
  467. $csv .= " X,";
  468. }
  469. else {
  470. $csv .= ",";
  471. }
  472. }
  473. // Take off last comma of csv.
  474. $csv = substr($csv, 0, -1);
  475. $csv .= "\n";
  476. }
  477. header('Content-type: text/csv');
  478. header('Content-Disposition: attachment; filename="report_ant_offering.csv"');
  479. print $csv;
  480. die;
  481. }

Functions

Namesort descending Description
course_search_display_edit_courses Display a plain list of courses, making it easier for admins to edit schedules and details in one spot.
course_search_display_view_reports
course_search_edit_course_details_form This form lets the user edit the course's syllabus or rotation schedule
course_search_edit_course_details_form_submit
course_search_get_offering_csv
course_search_upload_attachment