course_search.module

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

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

Functions & methods

NameDescription
course_search_display_coursesShow the user their select of courses.
course_search_display_searchDisplays the search pulldown for the user to use to find courses.
course_search_download_syllabusThis 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_formThe system settins form for course_search settings.

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_get_module_path('course_search') . "/icons/book_go.png",
  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_get_module_path('course_search') . "/icons/book_go.png",
  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($_REQUEST["c"]);
  187. $id = trim($_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 = '?' ";
  195. $params = array($subject_id . "_" . $course_num);
  196. if ($id != "") {
  197. $query = "select * from course_syllabi
  198. where course_id = '?' ";
  199. $params = array($id);
  200. }
  201. $res = db_query($query, $params);
  202. $cur = db_fetch_array($res);
  203. $filename = $cur["filename"];
  204. $course_id = $cur["course_id"];
  205. // Get the latest subject_id and course_num for this course!
  206. $new_course = new Course();
  207. $new_course->course_id = $course_id;
  208. $new_course->catalog_year = variable_get("current_catalog_year", 2006);
  209. $new_course->load_descriptive_data(false, false, true);
  210. $subject_id = $new_course->subject_id;
  211. $course_num = $new_course->course_num;
  212. $files_path = $GLOBALS["fp_system_settings"]["file_system_path"];
  213. if ($filename == "" || !file_exists("$files_path/custom/files/syllabi/$filename"))
  214. { // Check to make sure the src file actually exists.
  215. // Display a message, letting the user know it does not
  216. // exist.
  217. watchdog("syllabus", "fail,$c", array(), WATCHDOG_ERROR);
  218. fp_add_message(t("Sorry, the syllabus for @course could not be found.", array("@course" => "$subject_id $course_num")));
  219. // Just so admins can see:
  220. fpm("Admin: file path attempted: $files_path/custom/files/syllabi/$filename");
  221. return;
  222. }
  223. watchdog("syllabus", "get,$c", array(), WATCHDOG_DEBUG);
  224. $content_type = "application/plain"; // default, save as generic binary file.
  225. $temp = explode("\.", $filename);
  226. $ext = $temp[count($temp) - 1]; // get the original file extension.
  227. // attempt to match to the correct content_type...
  228. if ($ext == "pdf"){ $content_type = "application/pdf"; }
  229. if ($ext == "doc") { $content_type = "application/msword"; }
  230. if ($ext == "docx") { $content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; }
  231. if ($ext == "txt") { $content_type = "text/plain"; }
  232. if ($ext == "pot") { $content_type = "application/mspowerpoint"; }
  233. if ($ext == "ppt") { $content_type = "application/powerpoint"; }
  234. if (strstr($ext,"xl")) { $content_type = "application/excel"; }
  235. $fn = urlencode($subject_id . "_" . $course_num . "_SAMPLE_SYLLABUS") .".$ext"; // make it a safe filename.
  236. $fn = str_replace("+"," ",$fn); // restore spaces from + symbols...
  237. // Give it to the browser!
  238. header('Content-type: ' . $content_type . '');
  239. header('Content-Disposition: attachment; filename="' . $fn . '"');
  240. readfile("$files_path/custom/files/syllabi/" . $filename . "");
  241. die;
  242. }
  243. /**
  244. * Show the user their select of courses.
  245. */
  246. function course_search_display_courses() {
  247. $rtn = "";
  248. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
  249. if (fp_screen_is_mobile()) {
  250. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_mobile_style.css");
  251. }
  252. $mode = "";
  253. // We are going to be setting up a render array for this screen, so other modules can alter it later.
  254. $render = array();
  255. $render["#id"] = "course_search_display_courses";
  256. $rtn .= fp_render_curved_line(t("Course Search"));
  257. $settings = fp_get_system_settings();
  258. $current_catalog_year = $settings["current_catalog_year"];
  259. // catalog_year is always just whatever the current year is.
  260. $catalog_year = $current_catalog_year;
  261. $subject_id = $_REQUEST["subject_id"];
  262. $render["#catalog_year"] = array(
  263. "type" => "do_not_render",
  264. "value" => $catalog_year,
  265. );
  266. $render["#subject_id"] = array(
  267. "type" => "do_not_render",
  268. "value" => $subject_id,
  269. );
  270. $clean_urls = variable_get("clean_urls", FALSE);
  271. // Try to find out the title to this subject, if one exists
  272. // in our subjects table.
  273. $res = db_query("SELECT * FROM subjects
  274. WHERE subject_id ='?' ", $subject_id);
  275. $cur = db_fetch_array($res);
  276. $title = $cur["title"];
  277. if ($title == "") $title = $subject_id;
  278. //$rtn .= t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year +1) . "</b>
  279. // ";
  280. $render["current_cat_year"] = array(
  281. "value" => t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year +1) . "</b>",
  282. );
  283. $important_notice = "
  284. <div class='tenpt hypo' style='padding: 5px;'>
  285. <b>Important Notice:</b> <ul style='margin-top: 5px;'>
  286. <li>Course descriptions are intended for unofficial use only. Consult your catalog for the official listing.</li>
  287. <li>Anticipated course availability reflects current plans but actual offerings may change because of factors
  288. unknown at planning time. Consult the schedule of classes for final offerings.</li>
  289. <li>Sample syllabi are provided for planning purposes only. The syllabus used by an instructor may vary from this sample.</li>
  290. <li>Please ask your advisor if you have any questions about a course.</li>
  291. </ul>
  292. </div>
  293. ";
  294. if (fp_screen_is_mobile()) {
  295. // TODO: implement the fieldset thingy.
  296. //$pC .= $screen->draw_c_fieldset($important_notice, "View important notice", true);
  297. }
  298. else {
  299. //$rtn .= $important_notice;
  300. $render["important_notice"] = array(
  301. "value" => $important_notice,
  302. );
  303. }
  304. /*
  305. $rtn .= "
  306. <!-- <div> -->
  307. <div style='margin: 10px 0 20px 10px; border-bottom: 2px solid black;'>
  308. <span style='font-size: 14pt; font-weight:bold;'>$title</span>
  309. " . l("[change]", "tools/course-search", "", array("class" => "nounderline")) . "
  310. </div>
  311. ";
  312. */
  313. $render["subject_change"] = array(
  314. "value" => "<div style='margin: 10px 0 20px 10px; border-bottom: 2px solid black;'>
  315. <span style='font-size: 14pt; font-weight:bold;'>$title</span>
  316. " . l("[change]", "tools/course-search", "", array("class" => "nounderline")) . "
  317. </div>",
  318. );
  319. // Draw the term selector.
  320. $html = "";
  321. $only_term = @$_REQUEST["only_term"];
  322. $html .= "<form id='term_form' action='" . fp_url("tools/course-search/courses") . "' method='GET'>
  323. <input type='hidden' name='mode' value='$subject_id'>
  324. <input type='hidden' name='subject_id' value='$subject_id'>
  325. ";
  326. if (!$clean_urls) {
  327. // Hack for if clean URLs isn't enabled
  328. $html .= "<input type='hidden' name='q' value='tools/course-search/courses'>";
  329. }
  330. $html .= "
  331. View courses offered:
  332. <select name='only_term' onChange='document.getElementById(\"term_form\").submit();'>
  333. <option value=''>Any term</option>
  334. ";
  335. //$term_array = get_term_id_suffixes();
  336. $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
  337. $schedule_text = "";
  338. for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
  339. {
  340. $html .= "<option value=''>---------------------</option>";
  341. foreach($term_array as $x)
  342. {
  343. $schedule_text .= "<td class='tenpt' align='center'>";
  344. $the_term_id = $t . $x;
  345. $temp_course = new Course();
  346. $temp_course->term_id = $the_term_id;
  347. $term_desc = $temp_course->get_term_description(false);
  348. $sel = "";
  349. if ($only_term != "" && $only_term == "$the_term_id") {
  350. $sel = " selected";
  351. }
  352. $html .= "<option value='$the_term_id' $sel>$term_desc</option> \n";
  353. }
  354. }
  355. $html .= "
  356. </select>
  357. </form>";
  358. $render["term_selector_form"] = array(
  359. "value" => $html,
  360. );
  361. if ($only_term != "") {
  362. $temp_course = new Course();
  363. $temp_course->term_id = $only_term;
  364. $term_desc = $temp_course->get_term_description(false);
  365. /*
  366. $rtn .= "<div style='font-weight: bold; padding-bottom: 20px;'>
  367. The following courses are currently scheduled to be offered during " . $term_desc . ".
  368. </div>";
  369. */
  370. $render["term_selected_only_term"] = array(
  371. "value" => "<div style='font-weight: bold; padding-bottom: 20px;'>
  372. " . t("The following courses are currently scheduled to be offered during") . $term_desc . "
  373. </div>",
  374. );
  375. }
  376. $term_structures = get_term_structures();
  377. $grad_notice_flag = false;
  378. $temp_course = new Course();
  379. // removed course_num < 500 and
  380. $result = db_query("SELECT * FROM courses
  381. WHERE `catalog_year`='?' AND
  382. `subject_id`='?' AND
  383. `exclude`='0' ORDER BY `course_num` ", $catalog_year, $subject_id);
  384. if ($result)
  385. {
  386. while ($cur = db_fetch_array($result))
  387. {
  388. $n_subject_id = trim($cur["subject_id"]);
  389. $n_course_num = trim($cur["course_num"]);
  390. $n_course_id = $cur["course_id"];
  391. $bool_hide = FALSE;
  392. $title = trim($cur["title"]);
  393. $title = $temp_course->fix_title($title);
  394. $description = trim($cur["description"]);
  395. if ($description == "")
  396. {
  397. $description = t("No description is available at this time. Consult
  398. the official course catalog for listings.");
  399. }
  400. $syllabus_text = "";
  401. $syllabus_array = course_search_get_course_syllabus_details("", "", $n_course_id);
  402. if ($syllabus_array["url"] != "")
  403. {
  404. $syllabus_text = "<div class='course-search-sample-syllabus'>
  405. <a href='{$syllabus_array["url"]}' class='nounderline'>
  406. <img src='" . fp_theme_location() . "/images/document_icon.gif' border='0' height='12'>
  407. " . t("Sample Syllabus") . "</a>
  408. </div>
  409. ";
  410. }
  411. // Look for all 5 years.
  412. $long_schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year, 100, true);
  413. // Only grab next 2 years.
  414. $schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year);
  415. $full_schedule_array = course_search_get_course_rotation_schedule($n_course_id);
  416. $schedule_text = "";
  417. if (count($long_schedule_array) > 0)
  418. {
  419. $schedule_text .= "
  420. <div>
  421. <b>" . t("Anticipated availability:") . "</b>
  422. ";
  423. $s_disp = "auto";
  424. if ($mode != "advanced")
  425. { // only show this in the basic mode, not advanced.
  426. foreach ($schedule_array as $term_id)
  427. {
  428. $temp_course = new Course();
  429. $temp_course->term_id = $term_id;
  430. $schedule_text .= " " . $temp_course->get_term_description(true) . ",";
  431. }
  432. $schedule_text = substr($schedule_text, 0, -1); // take off comma.
  433. $rnd_div_id = rand(1,999999);
  434. $schedule_text .= "
  435. &nbsp; | &nbsp;
  436. <a href='javascript: toggleHideDiv(\"$rnd_div_id\");' class='nounderline'>
  437. <span id='SPAN$rnd_div_id'>
  438. more&raquo;
  439. </span></a> ";
  440. $s_disp = "none";
  441. }
  442. // Consult our settings to find out what order our terms should be in.
  443. $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
  444. // Get our table headers
  445. $avail_headers = variable_get("course_search_avail_term_headers");
  446. $avail_mobile_headers = variable_get("course_search_avail_term_mobile_headers");
  447. $th = explode(",", $avail_headers);
  448. $twidth = "90%";
  449. $mleft = "20px;";
  450. if (fp_screen_is_mobile()) {
  451. $th = explode(",", $avail_mobile_headers);
  452. $twidth = "100%";
  453. $mleft = "0";
  454. }
  455. $schedule_text .= "
  456. </div>
  457. <div id='$rnd_div_id' style='display: $s_disp; margin-left: $mleft;'>
  458. <table border='1' width='$twidth' class='fp-course-search-avail'>
  459. <tr>
  460. <td>" . t("Year") . "</td>
  461. ";
  462. foreach ($th as $header_text) {
  463. $schedule_text .= "<td>" . trim($header_text) . "</td>";
  464. }
  465. $schedule_text .= " </tr>";
  466. for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
  467. {
  468. $schedule_text .= "<tr>
  469. <td class='tenpt' align='center'>
  470. <b>$t</b>
  471. </td>";
  472. foreach($term_array as $x)
  473. {
  474. $schedule_text .= "<td class='tenpt' align='center'>";
  475. $the_term_id = $t . $x;
  476. // Does the term suffix ($x) call for the year to be
  477. // subtracted by 1, or modified at all? This is the case at ULM for fall.
  478. // Ex: 201340 is Fall of *2012*, not 2013.
  479. // We can tell this because the term structure (from admin settings)
  480. //fpm($term_structures);
  481. if (strtoupper($term_structures[$x]["disp_adjust"]) == "[Y-1]" || strtoupper($term_structures[$x]["disp_adjust"]) == "[Y4-1]") {
  482. // It is subtracted by one. So the year for "XYZ of 2016" is actually recorded as 2017xyz
  483. $the_term_id = ($t + 1) . $x;
  484. }
  485. if (strtoupper($term_structures[$x]["disp_adjust"]) == "[Y+1]" || strtoupper($term_structures[$x]["disp_adjust"]) == "[Y4+1]") {
  486. // It is added by one. So the year for "XYZ of 2016" is actually recorded as 2015xyz
  487. $the_term_id = ($t - 1) . $x;
  488. }
  489. if (in_array($the_term_id, $full_schedule_array))
  490. {
  491. $schedule_text .= "<img src='" . fp_theme_location() . "/images/small_check.gif'>";
  492. }
  493. else {
  494. if ($only_term != "" && $only_term == $the_term_id) {
  495. // Meaning, the term that the user selected is NOT in this
  496. // course's schedule. So, we should hide it.
  497. $bool_hide = TRUE;
  498. }
  499. }
  500. $schedule_text .= "&nbsp;</td>";
  501. }
  502. $schedule_text .= "</tr>";
  503. }
  504. $schedule_text .= "
  505. </table>
  506. </div>
  507. ";
  508. }
  509. else if ($only_term != "") {
  510. // This is if there are NO schedule offerings, yet the user
  511. // selected to view a particular term.
  512. $bool_hide = TRUE;
  513. }
  514. if (course_search_get_course_rotation_schedule_not_anticipated($n_course_id))
  515. {
  516. // This course has no anticipated offerings!
  517. $schedule_text = "<div><b>" . t("Anticipated availability:") . "</b>
  518. " . t("There are no anticipated course offerings
  519. at this time.") . "</div>";
  520. if ($only_term != "") $bool_hide = TRUE;
  521. }
  522. $min_hours = trim($cur["min_hours"]*1);
  523. $max_hours = trim($cur["max_hours"]*1);
  524. if ($min_hours == $max_hours)
  525. {
  526. $hours = $min_hours;
  527. } else {
  528. $hours = "$min_hours to $max_hours";
  529. }
  530. $repeat = "";
  531. if (trim($cur["repeat_hours"]*1) > $min_hours)
  532. {
  533. $repeat = "<div class='course-search-repeat'>" . t("May be repeated for up to @repeat hours of credit.", array("@repeat" => $cur["repeat_hours"]*1)) . "</div>";
  534. if (trim($cur["repeat_hours"]*1) > 20) {
  535. $repeat = "<div class='course-search-repeat'>" . t("May be repeated for credit.") . "</div>";
  536. }
  537. }
  538. // Draw it on screen...
  539. if ($bool_hide != true) {
  540. /*
  541. *
  542. * TODO: This section should really only be if the course is designated as a graduate course or not, not based on course_num.
  543. *
  544. if ($grad_notice_flag == false && $course_num > 4999)
  545. {
  546. $grad_notice_flag = true;
  547. $rtn .= "<div style='font-size: 10pt; font-weight: bold;
  548. border-bottom: 1px solid black;
  549. margin-left: 10px;
  550. margin-bottom: 20px;
  551. margin-top: 50px;'>
  552. " . t("The following courses are for Graduate Students only.") . "
  553. </div>";
  554. }
  555. * */
  556. $details = $schedule_text . $syllabus_text;
  557. $hyp1 = " - ";
  558. $on_click = "";
  559. if (fp_screen_is_mobile()) {
  560. $on_click = "onClick='toggleCourseExtra(this);'";
  561. $hyp1 = "";
  562. }
  563. $html = "";
  564. // Note, the HTML comments are so other modules, that wish to manipulate this block, have something easy to find/replace
  565. $html .= "<div class='course-search-course-block'>
  566. <!-- TITLE-ROW -->
  567. <div class='course-search-course-title-row'
  568. $on_click>
  569. <!-- COURSE-NAME -->
  570. <span class='course-search-course-name'>$n_subject_id $n_course_num</span>
  571. $hyp1
  572. <!-- END-COURSE-NAME ->
  573. <!-- COURSE-TITLE -->
  574. <span class='course-search-course-title'>$title</span> - $hours " . t("hrs.") . "$repeat
  575. <!-- END-COURSE-TITLE -->
  576. </div>
  577. <!-- END-TITLE-ROW -->
  578. <!-- COURSE-EXTRA -->
  579. <div class='course-search-course-extra'>
  580. <!-- DESC -->
  581. <div class='course-search-course-description'>$description</div>
  582. <!-- END-DESC -->
  583. <!-- DETAILS -->
  584. <div class='course-search-course-details'>$details</div>
  585. <!-- END-DETAILS -->
  586. ";
  587. if (user_has_permission("can_update_course_info_details") && !fp_screen_is_mobile()) {
  588. $html .= "<!-- ADMIN-OPTIONS -->
  589. <div class='course-search-admin-options'>
  590. " . t("Administrative options:") . "
  591. " . 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") . "
  592. </div>
  593. <!-- END-ADMIN-OPTIONS -->";
  594. }
  595. $html .= "</div>
  596. <!-- END-COURSE-EXTRA -->"; // div course-search-course-extra
  597. $html .= "</div>"; // div course-search-course-block
  598. $render["course_search_course_block__$n_course_id"] = array(
  599. "value" => $html,
  600. );
  601. }
  602. }
  603. }
  604. watchdog("course_search", "User viewed courses in subject: @subject", array("@subject" => $subject_id), WATCHDOG_DEBUG);
  605. //$pC .= $screen->get_java_script_code();
  606. $html = '
  607. <script type="text/javascript">
  608. function toggleHideDiv(rndDivID)
  609. {
  610. var d = document.getElementById(rndDivID);
  611. if (d.style.display == "none")
  612. {
  613. d.style.display = "";
  614. document.getElementById("SPAN" + rndDivID).innerHTML = "&laquo;less";
  615. } else {
  616. d.style.display = "none";
  617. document.getElementById("SPAN" + rndDivID).innerHTML = "more&raquo;";
  618. }
  619. }
  620. function toggleCourseExtra(e) {
  621. $(e).siblings(".course-search-course-extra").slideToggle("medium");
  622. }
  623. </script>
  624. ';
  625. $render["extra_javascript"] = array(
  626. "value" => $html,
  627. );
  628. $rtn .= fp_render_content($render);
  629. return $rtn;
  630. }
  631. function course_search_get_course_rotation_schedule_not_anticipated($course_id)
  632. {
  633. // Returns TRUE if not is NOT ANTICIPATED. False, if this
  634. // is a normal courses which has an offering, or a blank
  635. // offering. This will
  636. // only return true if NOTA is set as a term for this course.
  637. $res = db_query("SELECT * FROM course_rotation_schedule
  638. WHERE course_id = '?'
  639. AND term_id = 'NOTA'
  640. ", $course_id);
  641. if (db_num_rows($res) > 0) {
  642. return true;
  643. }
  644. return false;
  645. }
  646. function course_search_get_course_rotation_schedule($course_id, $year = "", $limit = 20, $bool_include_next_five_years = false)
  647. {
  648. // return an array containing the terms that this course
  649. // is going to be offered, if any.
  650. $rtn_array = array();
  651. $arr = array();
  652. $year_line = "";
  653. if ($year != "")
  654. { // if a year is entered, we will get the next few years, and the previous
  655. // one for good measure.
  656. $year_line = "and (`term_id` LIKE '$year%' or `term_id` LIKE '" . ($year+1) . "%') ";
  657. if ($bool_include_next_five_years)
  658. {
  659. $yearm1 = $year - 1;
  660. $year2 = $year + 1;
  661. $year3 = $year + 2;
  662. $year4 = $year + 3;
  663. $year5 = $year + 4;
  664. $year6 = $year + 5;
  665. $year_line = "and (`term_id` LIKE '$year%'
  666. or `term_id` LIKE '$yearm1%'
  667. or `term_id` LIKE '$year2%'
  668. or `term_id` LIKE '$year3%'
  669. or `term_id` LIKE '$year4%'
  670. or `term_id` LIKE '$year5%'
  671. or `term_id` LIKE '$year6%'
  672. ) ";
  673. }
  674. }
  675. $res = db_query("SELECT * FROM course_rotation_schedule
  676. WHERE `course_id`= ?
  677. $year_line
  678. ORDER BY term_id DESC
  679. LIMIT $limit", $course_id);
  680. while($cur = db_fetch_array($res))
  681. {
  682. $t = $cur["term_id"];
  683. // Get the term from the end.
  684. $ss = trim(substr($t,4,1));
  685. if ($ss == "m"){$ss = "1.5";}
  686. $ss = $ss * 10;
  687. $year = trim(substr($t,0,4));
  688. // We do all this so we can establish an order to the terms
  689. // by using a sort() command later.
  690. $arr[] = $year . "~" . $ss . "~" . $t;
  691. }
  692. sort($arr);
  693. // Now we want to get out JUST the terms...
  694. foreach($arr as $line)
  695. {
  696. $temp = explode("~",$line);
  697. $rtn_array[] = trim($temp[2]);
  698. }
  699. return $rtn_array;
  700. }
  701. function course_search_get_course_syllabus_details($subject_id = "", $course_num = "", $course_id = -1)
  702. {
  703. // This will return an array containing information
  704. // about a course's syllabus, if it exists.
  705. $rtn_array = FALSE;
  706. // Does this course have a syllabus?
  707. $query = "SELECT * FROM course_syllabi
  708. WHERE `course_perm_id`='$subject_id" . "_$course_num'";
  709. if ($course_id != -1) {
  710. $query = "SELECT * FROM course_syllabi
  711. WHERE `course_id`='$course_id' ";
  712. }
  713. $res = db_query($query);
  714. $cur = db_fetch_array($res);
  715. //$url = $GLOBALS["fp_system_settings"]["selfURL"] . "/" . get_module_path("course_search") . "/syllabus.php?id=" . $cur["course_id"];
  716. if ($cur["filename"] != "") {
  717. $rtn_array = array();
  718. $rtn_array["url"] = $GLOBALS["fp_system_settings"]["base_url"] . "/" . fp_url("course-search/get-syllabus", "id=" . $cur["course_id"], FALSE);
  719. $rtn_array["filename"] = $cur["filename"];
  720. $rtn_array["posted"] = $cur["posted"];
  721. }
  722. return $rtn_array;
  723. }
  724. /**
  725. * Displays the search pulldown for the user to use to find courses.
  726. */
  727. function course_search_display_search() {
  728. $rtn = "";
  729. $mode = "";
  730. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
  731. if (fp_screen_is_mobile()) {
  732. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_mobile_style.css");
  733. }
  734. $rtn .= "";
  735. if (user_has_permission("can_update_course_info_details")) {
  736. $rtn .= "<div>" . t("Administrators:") . " " . l(t("Edit course schedules and syllabi"), "tools/course-search/edit-list") . "</div>";
  737. }
  738. $rtn .= fp_render_curved_line("Course Search");
  739. $settings = fp_get_system_settings();
  740. $current_catalog_year = $settings["current_catalog_year"];
  741. // catalog_year is always just whatever the current year is.
  742. $catalog_year = $current_catalog_year;
  743. $clean_urls = variable_get("clean_urls", FALSE); // are clean URLs enabled?
  744. if ($catalog_year == "")
  745. {
  746. $rtn .= "Please select an available catalog year from the
  747. list below.<br><br>
  748. <form action='" . fp_url("tools/course-search") . "' method='GET' name='mainform' id='myform'>
  749. <table align='center'>
  750. <td width='150' valign='bottom'>
  751. <select name='catalog_year'>";
  752. for ($t = $current_catalog_year; $t >= $GLOBALS["fp_system_settings"]["earliest_catalog_year"]; $t--)
  753. {
  754. $rtn .= "<option value='$t'>$t - " . ($t+1) . "</option> \n";
  755. }
  756. $rtn .= "</select>
  757. </td>
  758. <td valign='bottom'>
  759. <input type='submit' value='Select ->'>
  760. </td>
  761. </table>";
  762. if (!$clean_urls) {
  763. // Hack for if clean URLs isn't enabled
  764. $rtn .= "<input type='hidden' name='q' value='tools/course-search'>";
  765. }
  766. $rtn .= " </form>";
  767. }
  768. else {
  769. // Catalog year has been selected.
  770. $rtn .= "Current catalog year: <b>$catalog_year-" . ($catalog_year +1) . "</b>
  771. <br><br>
  772. Please select an available subject from the list below.<br>
  773. <br>
  774. <form action='" . fp_url("tools/course-search/courses") . "' method='GET' name='mainform' id='myform'>";
  775. if (!$clean_urls) {
  776. // Hack for if clean URLs isn't enabled
  777. $rtn .= "<input type='hidden' name='q' value='tools/course-search/courses'>";
  778. }
  779. if (!fp_screen_is_mobile()) {
  780. $rtn .= "
  781. <div align='center'>
  782. <select name='subject_id' style='width: 80%;'>
  783. ";
  784. }
  785. // We want to make a pull-down list of all available subjects.
  786. // Keep in mind with this join-- we may have courses who have
  787. // a subject_id, for which we don't have that subject in the subjects
  788. // table.
  789. $query = "SELECT DISTINCT b.subject_id, a.title FROM courses b LEFT JOIN subjects a
  790. ON (a.subject_id = b.subject_id)
  791. WHERE exclude = 0
  792. AND catalog_year = '?'
  793. ";
  794. $subjects = array();
  795. $result = db_query($query, $catalog_year);
  796. while ($cur = db_fetch_array($result))
  797. {
  798. //fpm($cur);
  799. $title = trim($cur["title"]);
  800. $subject_id = trim($cur["subject_id"]);
  801. if ($title == "") {
  802. $title = $subject_id;
  803. }
  804. $subjects[$subject_id] = $title;
  805. }
  806. asort($subjects);
  807. foreach ($subjects as $subject_id => $title) {
  808. if (!fp_screen_is_mobile()) {
  809. $rtn .= "<option value='$subject_id'>$title ($subject_id)</option>";
  810. }
  811. else {
  812. $rtn .= "<a class='course-search-subject-select-line'
  813. href='" . fp_url("tools/course-search/courses", "subject_id=$subject_id") . "'>
  814. <div class='course-search-dept-name'>$title ($subject_id)</div>
  815. </a>";
  816. }
  817. }
  818. if (!fp_screen_is_mobile()) {
  819. $rtn .= "
  820. </select>
  821. <input type='hidden' name='mode' value='$mode'>
  822. </div><br><br><br>
  823. <div align='right'>
  824. <input type='submit' value='Select ->'>
  825. </div>";
  826. }
  827. $rtn .= "</form>";
  828. }
  829. return $rtn;
  830. }