course_search.module

  1. 6.x modules/course_search/course_search.module
  2. 4.x modules/course_search/course_search.module
  3. 5.x modules/course_search/course_search.module

This module allows users to search for courses, descriptions, and, if supported, rotation schedules and sample syllabi.

File

modules/course_search/course_search.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * This module allows users to search for courses, descriptions, and, if supported, rotation schedules
  5. * and sample syllabi.
  6. */
  7. function course_search_menu() {
  8. $items = array();
  9. $items["tools/course-search"] = array(
  10. "title" => "Course Search",
  11. "description" => "Use this tool to view course descriptions, sample syllabi, and projected course offering schedules.",
  12. "page_callback" => "course_search_display_search",
  13. "access_callback" => TRUE,
  14. "page_settings" => array(
  15. "page_has_search" => FALSE,
  16. "page_banner_is_link" => TRUE,
  17. "page_hide_report_error" => TRUE,
  18. "target" => "_blank",
  19. "menu_icon" => fp_theme_location() . "/images/book_glass_20.jpg",
  20. ),
  21. "type" => MENU_TYPE_NORMAL_ITEM,
  22. );
  23. $items["course-search/get-syllabus"] = array(
  24. "title" => "Course Search",
  25. "page_callback" => "course_search_download_syllabus",
  26. "access_callback" => TRUE,
  27. "type" => MENU_TYPE_CALLBACK,
  28. );
  29. $items["admin/config/course-search"] = array(
  30. "title" => "Course Search Settings",
  31. "description" => "Administer the Course Search module's settings",
  32. "page_callback" => "fp_render_form",
  33. "page_arguments" => array("course_search_settings_form", "system_settings"),
  34. "access_arguments" => array("administer_course_search"),
  35. "page_settings" => array(
  36. "page_has_search" => FALSE,
  37. "page_banner_is_link" => TRUE,
  38. "page_hide_report_error" => TRUE,
  39. "menu_icon" => fp_theme_location() . "/images/book_glass_20.jpg",
  40. "menu_links" => array(
  41. 0 => array(
  42. "text" => "Back to main menu",
  43. "path" => "admin-tools/admin",
  44. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  45. ),
  46. ),
  47. ),
  48. "type" => MENU_TYPE_NORMAL_ITEM,
  49. );
  50. $items["tools/course-search/courses"] = array(
  51. "title" => "Course Search",
  52. "page_callback" => "course_search_display_courses",
  53. "access_callback" => TRUE,
  54. "page_settings" => array(
  55. "page_has_search" => FALSE,
  56. "page_banner_is_link" => TRUE,
  57. "page_hide_report_error" => TRUE,
  58. ),
  59. "type" => MENU_TYPE_CALLBACK,
  60. );
  61. $items["tools/course-search/edit-list"] = array(
  62. "title" => "Update Course Information",
  63. "page_callback" => "course_search_display_edit_courses",
  64. "access_arguments" => array("can_update_course_info_details"),
  65. "page_settings" => array(
  66. "page_has_search" => FALSE,
  67. "menu_links" => array(
  68. 0 => array(
  69. "text" => "Back to Course Search",
  70. "path" => "tools/course-search",
  71. ),
  72. ),
  73. ),
  74. "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
  75. "type" => MENU_TYPE_CALLBACK,
  76. );
  77. $items["tools/course-search/edit-info-details"] = array(
  78. "title" => "Edit Course Info Details",
  79. "page_callback" => "fp_render_form",
  80. "page_arguments" => array("course_search_edit_course_details_form"),
  81. "access_arguments" => array("can_update_course_info_details"),
  82. "page_settings" => array(
  83. "page_has_search" => FALSE,
  84. "page_banner_is_link" => TRUE,
  85. "menu_links" => array(
  86. 0 => array(
  87. "text" => "Back to Course Search",
  88. "path" => "tools/course-search",
  89. ),
  90. 1 => array(
  91. "text" => "Back to Course Edit List",
  92. "path" => "tools/course-search/edit-list",
  93. ),
  94. ),
  95. ),
  96. "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
  97. "type" => MENU_TYPE_CALLBACK,
  98. );
  99. $items["tools/course-search/view-reports"] = array(
  100. "title" => "View Reports",
  101. "page_callback" => "course_search_display_view_reports",
  102. "access_arguments" => array("can_update_course_info_details"),
  103. "page_settings" => array(
  104. "page_has_search" => FALSE,
  105. "menu_links" => array(
  106. 0 => array(
  107. "text" => "Back to Course Search",
  108. "path" => "tools/course-search",
  109. ),
  110. 1 => array(
  111. "text" => "Back to Course Edit List",
  112. "path" => "tools/course-search/edit-list",
  113. ),
  114. ),
  115. ),
  116. "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
  117. "type" => MENU_TYPE_CALLBACK,
  118. );
  119. // Simple callback to download CSV
  120. $items["tools/course-search/get-offering-csv"] = array(
  121. "page_callback" => "course_search_get_offering_csv",
  122. "access_arguments" => array("can_update_course_info_details"),
  123. "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
  124. "type" => MENU_TYPE_CALLBACK,
  125. );
  126. return $items;
  127. }
  128. function course_search_perm() {
  129. return array(
  130. "administer_course_search" => array(
  131. "title" => t("Administer course search"),
  132. "description" => t("Users with this setting will be able
  133. to modify settings for the Course Search module."),
  134. ),
  135. "can_update_course_info_details" => array(
  136. "title" => t("Can update course info details"),
  137. "description" => t("Allows users to update the 'course info' details,
  138. like the course's sample syllabus and rotation
  139. schedule."),
  140. ),
  141. );
  142. }
  143. /**
  144. * The system settins form for course_search settings.
  145. */
  146. function course_search_settings_form() {
  147. $form = array();
  148. $form["course_search_avail_term_id_suffix_order"] = array(
  149. "type" => "textfield",
  150. "label" => t("Available Term ID Suffixes & Order"),
  151. "value" => variable_get("course_search_avail_term_id_suffix_order", ""),
  152. "description" => t("Enter the order of term ID suffixes, so that they will display
  153. in the correct order in the table of available course
  154. offerings. Separate by comma.") . "
  155. <br>
  156. Ex: 60, 40, 41, 80, 81, mm",
  157. );
  158. $form["course_search_avail_term_headers"] = array(
  159. "type" => "textfield",
  160. "label" => t("Available Term Table Headers"),
  161. "value" => variable_get("course_search_avail_term_headers", ""),
  162. "description" => t("Enter the table headers for the available table, in the same
  163. order as the suffix order above.") . "
  164. <br>
  165. Ex: Spring, May, Summer 1, Summer 2, Fall, Winter",
  166. );
  167. $form["course_search_avail_term_mobile_headers"] = array(
  168. "type" => "textfield",
  169. "label" => t("Available Term Mobile Table Headers"),
  170. "value" => variable_get("course_search_avail_term_mobile_headers", ""),
  171. "description" => t("Enter the table headers for the available table, in the same
  172. order as the suffix order above, as it should be displayed on
  173. a mobile device (with a smaller screen).") . "
  174. <br>
  175. Ex: Spr, May, Sum1, Sum2, Fall, Win",
  176. );
  177. return $form;
  178. }
  179. /**
  180. * This function will actually deliver a syllabus to the user's browser
  181. * for download.
  182. *
  183. */
  184. function course_search_download_syllabus() {
  185. // Get our global variables...
  186. $c = trim(mysql_real_escape_string($_REQUEST["c"]));
  187. $id = trim(mysql_real_escape_string($_REQUEST["id"]));
  188. $db = get_global_database_handler();
  189. $temp = explode("_", $c);
  190. $subject_id = $temp[0];
  191. $course_num = $temp[1];
  192. // Get the filename in question...
  193. $query = "select * from course_syllabi
  194. where course_perm_id = '$subject_id" . "_$course_num' ";
  195. if ($id != "") {
  196. $query = "select * from course_syllabi
  197. where course_id = '$id' ";
  198. }
  199. $res = db_query($query);
  200. $cur = db_fetch_array($res);
  201. $filename = $cur["filename"];
  202. $course_id = $cur["course_id"];
  203. // Get the latest subject_id and course_num for this course!
  204. $new_course = new Course();
  205. $new_course->course_id = $course_id;
  206. $new_course->catalog_year = variable_get("current_catalog_year", 2006);
  207. $new_course->load_descriptive_data(false, false, true);
  208. $subject_id = $new_course->subject_id;
  209. $course_num = $new_course->course_num;
  210. $files_path = $GLOBALS["fp_system_settings"]["file_system_path"];
  211. if ($filename == "" || !file_exists("$files_path/custom/files/syllabi/$filename"))
  212. { // Check to make sure the src file actually exists.
  213. // Display a message, letting the user know it does not
  214. // exist.
  215. watchdog("syllabus", "fail,$c", array(), WATCHDOG_ERROR);
  216. fp_add_message(t("Sorry, the syllabus for @course could not be found.", array("@course" => "$subject_id $course_num")));
  217. // Just so admins can see:
  218. fpm("Admin: file path attempted: $files_path/custom/files/syllabi/$filename");
  219. return;
  220. }
  221. watchdog("syllabus", "get,$c", array(), WATCHDOG_DEBUG);
  222. $content_type = "application/plain"; // default, save as generic binary file.
  223. $temp = explode("\.", $filename);
  224. $ext = $temp[count($temp) - 1]; // get the original file extension.
  225. // attempt to match to the correct content_type...
  226. if ($ext == "pdf"){ $content_type = "application/pdf"; }
  227. if ($ext == "doc") { $content_type = "application/msword"; }
  228. if ($ext == "docx") { $content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; }
  229. if ($ext == "txt") { $content_type = "text/plain"; }
  230. if ($ext == "pot") { $content_type = "application/mspowerpoint"; }
  231. if ($ext == "ppt") { $content_type = "application/powerpoint"; }
  232. if (strstr($ext,"xl")) { $content_type = "application/excel"; }
  233. $fn = urlencode($subject_id . "_" . $course_num . "_SAMPLE_SYLLABUS") .".$ext"; // make it a safe filename.
  234. $fn = str_replace("+"," ",$fn); // restore spaces from + symbols...
  235. // Give it to the browser!
  236. header('Content-type: ' . $content_type . '');
  237. header('Content-Disposition: attachment; filename="' . $fn . '"');
  238. readfile("$files_path/custom/files/syllabi/" . $filename . "");
  239. die;
  240. }
  241. /**
  242. * Show the user their select of courses.
  243. */
  244. function course_search_display_courses() {
  245. $rtn = "";
  246. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
  247. if (fp_screen_is_mobile()) {
  248. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_mobile_style.css");
  249. }
  250. $rtn .= "";
  251. $rtn .= fp_render_curved_line(t("Course Search"));
  252. $settings = fp_get_system_settings();
  253. $current_catalog_year = $settings["current_catalog_year"];
  254. // catalog_year is always just whatever the current year is.
  255. $catalog_year = $current_catalog_year;
  256. $subject_id = $_REQUEST["subject_id"];
  257. // Try to find out the title to this subject, if one exists
  258. // in our subjects table.
  259. $res = db_query("SELECT * FROM subjects
  260. WHERE subject_id ='?' ", $subject_id);
  261. $cur = db_fetch_array($res);
  262. $title = $cur["title"];
  263. if ($title == "") $title = $subject_id;
  264. /*
  265. $query = "SELECT DISTINCT a.* from subjects a,
  266. courses b
  267. WHERE a.subject_id = '?'
  268. AND a.subject_id = b.subject_id
  269. AND catalog_year = '?'
  270. AND exclude = 0
  271. ORDER BY title ";
  272. $result = db_query($query, $subject_id, $catalog_year);
  273. $cur = db_fetch_array($result);
  274. $title = trim($cur["title"]);
  275. */
  276. $rtn .= t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year +1) . "</b>
  277. ";
  278. $important_notice = "
  279. <div class='tenpt hypo' style='padding: 5px;'>
  280. <b>Important Notice:</b> <ul style='margin-top: 5px;'>
  281. <li>Course descriptions are intended for unofficial use only. Consult your catalog for the official listing.</li>
  282. <li>Anticipated course availability reflects current plans but actual offerings may change because of factors
  283. unknown at planning time. Consult the schedule of classes for final offerings.</li>
  284. <li>Sample syllabi are provided for planning purposes only. The syllabus used by an instructor may vary from this sample.</li>
  285. <li>Please ask your advisor if you have any questions about a course.</li>
  286. </ul>
  287. </div>
  288. ";
  289. if (fp_screen_is_mobile()) {
  290. // TODO: implement the fieldset thingy.
  291. //$pC .= $screen->draw_c_fieldset($important_notice, "View important notice", true);
  292. }
  293. else {
  294. $rtn .= $important_notice;
  295. }
  296. $rtn .= "
  297. <div>
  298. <div style='margin: 10px 0 20px 10px; border-bottom: 2px solid black;'>
  299. <span style='font-size: 14pt; font-weight:bold;'>$title</span>
  300. " . l("[change]", "tools/course-search", "", array("class" => "nounderline")) . "
  301. </div>
  302. ";
  303. // Draw the term selector.
  304. $only_term = $_REQUEST["only_term"];
  305. $rtn .= "<form id='term_form' action='" . fp_url("/tools/course-search/courses", "") . "' method='GET'>
  306. <input type='hidden' name='mode' value='$subject_id'>
  307. <input type='hidden' name='subject_id' value='$subject_id'>
  308. View courses offered:
  309. <select name='only_term' onChange='document.getElementById(\"term_form\").submit();'>
  310. <option value=''>Any term</option>
  311. ";
  312. //$term_array = get_term_id_suffixes();
  313. $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
  314. for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
  315. {
  316. $rtn .= "<option value=''>---------------------</option>";
  317. foreach($term_array as $x)
  318. {
  319. $schedule_text .= "<td class='tenpt' align='center'>";
  320. $the_term_id = $t . $x;
  321. $temp_course = new Course();
  322. $temp_course->term_id = $the_term_id;
  323. $term_desc = $temp_course->get_term_description(false);
  324. $sel = "";
  325. if ($only_term != "" && $only_term == "$the_term_id") {
  326. $sel = " selected";
  327. }
  328. $rtn .= "<option value='$the_term_id' $sel>$term_desc</option> \n";
  329. }
  330. }
  331. $rtn .= "
  332. </select>
  333. </form>";
  334. if ($only_term != "") {
  335. $temp_course = new Course();
  336. $temp_course->term_id = $only_term;
  337. $term_desc = $temp_course->get_term_description(false);
  338. $rtn .= "<div style='font-weight: bold; padding-bottom: 20px;'>
  339. The following courses are currently scheduled to be offered during " . $term_desc . ".
  340. </div>";
  341. }
  342. $term_structures = get_term_structures();
  343. $grad_notice_flag = false;
  344. $temp_course = new Course();
  345. // removed course_num < 500 and
  346. $result = db_query("SELECT * FROM courses
  347. WHERE `catalog_year`='?' AND
  348. `subject_id`='?' AND
  349. `exclude`='0' ORDER BY `course_num` ", $catalog_year, $subject_id);
  350. if ($result)
  351. {
  352. while ($cur = db_fetch_array($result))
  353. {
  354. $n_subject_id = trim($cur["subject_id"]);
  355. $n_course_num = trim($cur["course_num"]);
  356. $n_course_id = $cur["course_id"];
  357. $bool_hide = FALSE;
  358. $title = ucwords(strtolower(trim($cur["title"])));
  359. // Fix formatting problems introduced by the ucwords command...
  360. $title = $temp_course->fix_title($title);
  361. $description = trim($cur["description"]);
  362. if ($description == "")
  363. {
  364. $description = t("No description is available at this time. Consult
  365. the official course catalog for listings.");
  366. }
  367. $syllabus_text = "";
  368. $syllabus_array = course_search_get_course_syllabus_details("", "", $n_course_id);
  369. if ($syllabus_array["url"] != "")
  370. {
  371. $syllabus_text = "<div class='course-search-sample-syllabus'>
  372. <a href='{$syllabus_array["url"]}' class='nounderline'>
  373. <img src='" . fp_theme_location() . "/images/document_icon.gif' border='0' height='12'>
  374. " . t("Sample Syllabus") . "</a>
  375. </div>
  376. ";
  377. }
  378. // Look for all 5 years.
  379. $long_schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year, 100, true);
  380. // Only grab next 2 years.
  381. $schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year);
  382. $full_schedule_array = course_search_get_course_rotation_schedule($n_course_id);
  383. $schedule_text = "";
  384. if (count($long_schedule_array) > 0)
  385. {
  386. $schedule_text .= "
  387. <div>
  388. <b>" . t("Anticipated availability:") . "</b>
  389. ";
  390. $s_disp = "auto";
  391. if ($mode != "advanced")
  392. { // only show this in the basic mode, not advanced.
  393. foreach ($schedule_array as $term_id)
  394. {
  395. $temp_course = new Course();
  396. $temp_course->term_id = $term_id;
  397. $schedule_text .= " " . $temp_course->get_term_description(true) . ",";
  398. }
  399. $schedule_text = substr($schedule_text, 0, -1); // take off comma.
  400. $rnd_div_id = rand(1,999999);
  401. $schedule_text .= "
  402. &nbsp; | &nbsp;
  403. <a href='javascript: toggleHideDiv(\"$rnd_div_id\");' class='nounderline'>
  404. <span id='SPAN$rnd_div_id'>
  405. more&raquo;
  406. </span></a> ";
  407. $s_disp = "none";
  408. }
  409. // Consult our settings to find out what order our terms should be in.
  410. $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
  411. // Get our table headers
  412. $avail_headers = variable_get("course_search_avail_term_headers");
  413. $avail_mobile_headers = variable_get("course_search_avail_term_mobile_headers");
  414. $th = explode(",", $avail_headers);
  415. $twidth = "90%";
  416. $mleft = "20px;";
  417. if (fp_screen_is_mobile()) {
  418. $th = explode(",", $avail_mobile_headers);
  419. $twidth = "100%";
  420. $mleft = "0";
  421. }
  422. $schedule_text .= "
  423. </div>
  424. <div id='$rnd_div_id' style='display: $s_disp; margin-left: $mleft;'>
  425. <table border='1' width='$twidth' class='fp-course-search-avail'>
  426. <tr>
  427. <td>" . t("Year") . "</td>
  428. ";
  429. foreach ($th as $header_text) {
  430. $schedule_text .= "<td>" . trim($header_text) . "</td>";
  431. }
  432. $schedule_text .= " </tr>";
  433. for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
  434. {
  435. $schedule_text .= "<tr>
  436. <td class='tenpt' align='center'>
  437. <b>$t</b>
  438. </td>";
  439. foreach($term_array as $x)
  440. {
  441. $schedule_text .= "<td class='tenpt' align='center'>";
  442. $the_term_id = $t . $x;
  443. // Does the term suffix ($x) call for the year to be
  444. // subtracted by 1? This is the case at ULM for fall.
  445. // Ex: 201340 is Fall of *2012*, not 2013.
  446. // We can tell this because the term structure (from admin settings)
  447. //fpm($term_structures);
  448. if (strtoupper($term_structures[$x]["disp_adjust"]) == "[Y-1]") {
  449. //fpm("here for $x");
  450. $the_term_id = ($t + 1) . $x;
  451. }
  452. if (in_array($the_term_id, $full_schedule_array))
  453. {
  454. $schedule_text .= "<img src='" . fp_theme_location() . "/images/small_check.gif'>";
  455. }
  456. else {
  457. if ($only_term != "" && $only_term == $the_term_id) {
  458. // Meaning, the term that the user selected is NOT in this
  459. // course's schedule. So, we should hide it.
  460. $bool_hide = TRUE;
  461. }
  462. }
  463. $schedule_text .= "&nbsp;</td>";
  464. }
  465. $schedule_text .= "</tr>";
  466. }
  467. $schedule_text .= "
  468. </table>
  469. </div>
  470. ";
  471. }
  472. else if ($only_term != "") {
  473. // This is if there are NO schedule offerings, yet the user
  474. // selected to view a particular term.
  475. $bool_hide = TRUE;
  476. }
  477. if (course_search_get_course_rotation_schedule_not_anticipated($n_course_id))
  478. {
  479. // This course has no anticipated offerings!
  480. $schedule_text = "<div><b>" . t("Anticipated availability:") . "</b>
  481. " . t("There are no anticipated course offerings
  482. at this time.") . "</div>";
  483. if ($only_term != "") $bool_hide = TRUE;
  484. }
  485. $min_hours = trim($cur["min_hours"]);
  486. $max_hours = trim($cur["max_hours"]);
  487. if ($min_hours == $max_hours)
  488. {
  489. $hours = $min_hours;
  490. } else {
  491. $hours = "$min_hours to $max_hours";
  492. }
  493. $repeat = "";
  494. if (trim($cur["repeat_hours"]) > $min_hours)
  495. {
  496. $repeat = "<div class='course-search-repeat'>" . t("May be repeated for up to @repeat hours of credit.", array("@repeat" => $cur["repeat_hours"])) . "</div>";
  497. }
  498. // Draw it on screen...
  499. if ($bool_hide != true) {
  500. if ($grad_notice_flag == false && $course_num > 4999)
  501. {
  502. $grad_notice_flag = true;
  503. $rtn .= "<div style='font-size: 10pt; font-weight: bold;
  504. border-bottom: 1px solid black;
  505. margin-left: 10px;
  506. margin-bottom: 20px;
  507. margin-top: 50px;'>
  508. " . t("The following courses are for Graduate Students only.") . "
  509. </div>";
  510. }
  511. $details = $schedule_text . $syllabus_text;
  512. $hyp1 = " - ";
  513. $on_click = "";
  514. if (fp_screen_is_mobile()) {
  515. $on_click = "onClick='toggleCourseExtra(this);'";
  516. $hyp1 = "";
  517. }
  518. $rtn .= "<div class='course-search-course-block'>
  519. <div class='course-search-course-title-row'
  520. $on_click>
  521. <span class='course-search-course-name'>$n_subject_id $n_course_num</span>
  522. $hyp1
  523. <span class='course-search-course-title'>$title</span> - $hours " . t("hrs.") . "$repeat </div>
  524. <div class='course-search-course-extra'>
  525. <div class='course-search-course-description'>$description</div>
  526. <div class='course-search-course-details'>$details</div>
  527. ";
  528. if (user_has_permission("can_update_course_info_details") && !fp_screen_is_mobile()) {
  529. $rtn .= "<div class='course-search-admin-options'>
  530. " . t("Administrative options:") . "
  531. " . l(t("Edit syllabus and rotation schedule"), "tools/course-search/edit-info-details", "course_id=$n_course_id&subject_id=$n_subject_id&course_num=$n_course_num") . "
  532. </div>";
  533. }
  534. $rtn .= "</div>";
  535. $rtn .= "</div>";
  536. }
  537. }
  538. }
  539. watchdog("course_search", "User viewed courses in subject: @subject", array("@subject" => $subject_id), WATCHDOG_DEBUG);
  540. //$pC .= $screen->get_java_script_code();
  541. $rtn .= '
  542. <script type="text/javascript">
  543. function toggleHideDiv(rndDivID)
  544. {
  545. var d = document.getElementById(rndDivID);
  546. if (d.style.display == "none")
  547. {
  548. d.style.display = "";
  549. document.getElementById("SPAN" + rndDivID).innerHTML = "&laquo;less";
  550. } else {
  551. d.style.display = "none";
  552. document.getElementById("SPAN" + rndDivID).innerHTML = "more&raquo;";
  553. }
  554. }
  555. function toggleCourseExtra(e) {
  556. $(e).siblings(".course-search-course-extra").slideToggle("medium");
  557. }
  558. </script>
  559. ';
  560. return $rtn;
  561. }
  562. function course_search_get_course_rotation_schedule_not_anticipated($course_id)
  563. {
  564. // Returns TRUE if not is NOT ANTICIPATED. False, if this
  565. // is a normal courses which has an offering, or a blank
  566. // offering. This will
  567. // only return true if NOTA is set as a term for this course.
  568. $res = db_query("SELECT * FROM course_rotation_schedule
  569. WHERE course_id = '?'
  570. AND term_id = 'NOTA'
  571. ", $course_id);
  572. if (db_num_rows($res) > 0) {
  573. return true;
  574. }
  575. return false;
  576. }
  577. function course_search_get_course_rotation_schedule($course_id, $year = "", $limit = 20, $bool_include_next_five_years = false)
  578. {
  579. // return an array containing the terms that this course
  580. // is going to be offered, if any.
  581. $rtn_array = array();
  582. $arr = array();
  583. if ($year != "")
  584. { // if a year is entered, we will get the next few years, and the previous
  585. // one for good measure.
  586. $year_line = "and (`term_id` LIKE '$year%' or `term_id` LIKE '" . ($year+1) . "%') ";
  587. if ($bool_include_next_five_years)
  588. {
  589. $yearm1 = $year - 1;
  590. $year2 = $year + 1;
  591. $year3 = $year + 2;
  592. $year4 = $year + 3;
  593. $year5 = $year + 4;
  594. $year6 = $year + 5;
  595. $year_line = "and (`term_id` LIKE '$year%'
  596. or `term_id` LIKE '$yearm1%'
  597. or `term_id` LIKE '$year2%'
  598. or `term_id` LIKE '$year3%'
  599. or `term_id` LIKE '$year4%'
  600. or `term_id` LIKE '$year5%'
  601. or `term_id` LIKE '$year6%'
  602. ) ";
  603. }
  604. }
  605. $res = db_query("SELECT * FROM course_rotation_schedule
  606. WHERE `course_id`='?'
  607. $year_line
  608. ORDER BY term_id
  609. LIMIT $limit", $course_id);
  610. while($cur = db_fetch_array($res))
  611. {
  612. $t = $cur["term_id"];
  613. // Get the term from the end.
  614. $ss = trim(substr($t,4,1));
  615. if ($ss == "m"){$ss = "1.5";}
  616. $ss = $ss * 10;
  617. $year = trim(substr($t,0,4));
  618. // We do all this so we can establish an order to the terms
  619. // by using a sort() command later.
  620. $arr[] = $year . "~" . $ss . "~" . $t;
  621. }
  622. sort($arr);
  623. // Now we want to get out JUST the terms...
  624. foreach($arr as $line)
  625. {
  626. $temp = explode("~",$line);
  627. $rtn_array[] = trim($temp[2]);
  628. }
  629. return $rtn_array;
  630. }
  631. function course_search_get_course_syllabus_details($subject_id = "", $course_num = "", $course_id = -1)
  632. {
  633. // This will return an array containing information
  634. // about a course's syllabus, if it exists.
  635. $rtn_array = FALSE;
  636. // Does this course have a syllabus?
  637. $query = "SELECT * FROM course_syllabi
  638. WHERE `course_perm_id`='$subject_id" . "_$course_num'";
  639. if ($course_id != -1) {
  640. $query = "SELECT * FROM course_syllabi
  641. WHERE `course_id`='$course_id' ";
  642. }
  643. $res = db_query($query);
  644. $cur = db_fetch_array($res);
  645. //$url = $GLOBALS["fp_system_settings"]["selfURL"] . "/" . get_module_path("course_search") . "/syllabus.php?id=" . $cur["course_id"];
  646. if ($cur["filename"] != "") {
  647. $rtn_array = array();
  648. $rtn_array["url"] = $GLOBALS["fp_system_settings"]["base_url"] . "/" . fp_url("course-search/get-syllabus", "id=" . $cur["course_id"], FALSE);
  649. $rtn_array["filename"] = $cur["filename"];
  650. $rtn_array["posted"] = $cur["posted"];
  651. }
  652. return $rtn_array;
  653. }
  654. /**
  655. * Displays the search pulldown for the user to use to find courses.
  656. */
  657. function course_search_display_search() {
  658. $rtn = "";
  659. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
  660. if (fp_screen_is_mobile()) {
  661. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_mobile_style.css");
  662. }
  663. $rtn .= "";
  664. if (user_has_permission("can_update_course_info_details")) {
  665. $rtn .= "<div>" . t("Administrators:") . " " . l(t("Edit course schedules and syllabi"), "tools/course-search/edit-list") . "</div>";
  666. }
  667. $rtn .= fp_render_curved_line("Course Search");
  668. $settings = fp_get_system_settings();
  669. $current_catalog_year = $settings["current_catalog_year"];
  670. // catalog_year is always just whatever the current year is.
  671. $catalog_year = $current_catalog_year;
  672. if ($catalog_year == "")
  673. {
  674. $rtn .= "Please select an available catalog year from the
  675. list below.<br><br>
  676. <form action='" . $GLOBALS["fp_system_settings"]["base_path"] . "/tools/course-search' method='GET' name='mainform' id='myform'>
  677. <table align='center'>
  678. <td width='150' valign='bottom'>
  679. <select name='catalog_year'>";
  680. for ($t = $current_catalog_year; $t >= $GLOBALS["fp_system_settings"]["earliest_catalog_year"]; $t--)
  681. {
  682. $rtn .= "<option value='$t'>$t - " . ($t+1) . "</option> \n";
  683. }
  684. $rtn .= "</select>
  685. </td>
  686. <td valign='bottom'>
  687. <input type='submit' value='Select ->'>
  688. </td>
  689. </table>
  690. </form>";
  691. }
  692. else {
  693. // Catalog year has been selected.
  694. $rtn .= "Current catalog year: <b>$catalog_year-" . ($catalog_year +1) . "</b>
  695. <br><br>
  696. Please select an available subject from the list below.<br>
  697. <br>
  698. <form action='" . $GLOBALS["fp_system_settings"]["base_path"] . "/tools/course-search/courses' method='GET' name='mainform' id='myform'>";
  699. if (!fp_screen_is_mobile()) {
  700. $rtn .= "
  701. <div align='center'>
  702. <select name='subject_id' style='width: 80%;'>
  703. ";
  704. }
  705. // We want to make a pull-down list of all available subjects.
  706. // Keep in mind with this join-- we may have courses who have
  707. // a subject_id, for which we don't have that subject in the subjects
  708. // table.
  709. $query = "SELECT DISTINCT b.subject_id, a.title FROM courses b LEFT JOIN subjects a
  710. ON (a.subject_id = b.subject_id)
  711. WHERE exclude = 0
  712. AND catalog_year = '?'
  713. ";
  714. $subjects = array();
  715. $result = db_query($query, $catalog_year);
  716. while ($cur = db_fetch_array($result))
  717. {
  718. //fpm($cur);
  719. $title = trim($cur["title"]);
  720. $subject_id = trim($cur["subject_id"]);
  721. if ($title == "") {
  722. $title = $subject_id;
  723. }
  724. $subjects[$subject_id] = $title;
  725. }
  726. asort($subjects);
  727. foreach ($subjects as $subject_id => $title) {
  728. if (!fp_screen_is_mobile()) {
  729. $rtn .= "<option value='$subject_id'>$title ($subject_id)</option>";
  730. }
  731. else {
  732. $rtn .= "<a class='course-search-subject-select-line'
  733. href='" . fp_url("tools/course-search/courses", "subject_id=$subject_id") . "'>
  734. <div class='course-search-dept-name'>$title ($subject_id)</div>
  735. </a>";
  736. }
  737. }
  738. if (!fp_screen_is_mobile()) {
  739. $rtn .= "
  740. </select>
  741. <input type='hidden' name='mode' value='$mode'>
  742. </div><br><br><br>
  743. <div align='right'>
  744. <input type='submit' value='Select ->'>
  745. </div>";
  746. }
  747. $rtn .= "</form>";
  748. }
  749. return $rtn;
  750. }

Functions

Namesort descending Description
course_search_display_courses Show the user their select of courses.
course_search_display_search Displays the search pulldown for the user to use to find courses.
course_search_download_syllabus This function will actually deliver a syllabus to the user's browser for download.
course_search_get_course_rotation_schedule
course_search_get_course_rotation_schedule_not_anticipated
course_search_get_course_syllabus_details
course_search_menu
course_search_perm
course_search_settings_form The system settins form for course_search settings.