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_arguments" => array('access_course_search'),
  14. "page_settings" => array(
  15. "page_hide_report_error" => TRUE,
  16. "target" => "_blank",
  17. "menu_icon" => fp_get_module_path('course_search') . "/icons/book_go.png",
  18. ),
  19. "type" => MENU_TYPE_NORMAL_ITEM,
  20. );
  21. $items["course-search/get-syllabus"] = array(
  22. "title" => "Course Search",
  23. "page_callback" => "course_search_download_syllabus",
  24. "access_arguments" => array('access_course_search'),
  25. "type" => MENU_TYPE_CALLBACK,
  26. );
  27. $items["admin/config/course-search"] = array(
  28. "title" => "Course Search settings",
  29. "description" => "Administer the Course Search module's settings",
  30. "page_callback" => "fp_render_form",
  31. "page_arguments" => array("course_search_settings_form", "system_settings"),
  32. "access_arguments" => array("administer_course_search"),
  33. "page_settings" => array(
  34. "page_hide_report_error" => TRUE,
  35. "menu_icon" => fp_get_module_path('course_search') . "/icons/book_go.png",
  36. "menu_links" => array(
  37. 0 => array(
  38. "text" => "Admin Console",
  39. "path" => "admin-tools/admin",
  40. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  41. ),
  42. ),
  43. ),
  44. "type" => MENU_TYPE_NORMAL_ITEM,
  45. );
  46. $items["tools/course-search/courses"] = array(
  47. "title" => "Course Search",
  48. "page_callback" => "course_search_display_courses",
  49. "access_arguments" => array('access_course_search'),
  50. "page_settings" => array(
  51. "page_hide_report_error" => TRUE,
  52. ),
  53. "type" => MENU_TYPE_CALLBACK,
  54. );
  55. $items["tools/course-search/edit-list"] = array(
  56. "title" => "Update Course Information",
  57. "page_callback" => "course_search_display_edit_courses",
  58. "access_arguments" => array("can_update_course_info_details"),
  59. "page_settings" => array(
  60. "menu_links" => array(
  61. 0 => array(
  62. "text" => "Back to Course Search",
  63. "path" => "tools/course-search",
  64. ),
  65. ),
  66. ),
  67. "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
  68. "type" => MENU_TYPE_CALLBACK,
  69. );
  70. $items["tools/course-search/edit-info-details"] = array(
  71. "title" => "Edit Course Info Details",
  72. "page_callback" => "fp_render_form",
  73. "page_arguments" => array("course_search_edit_course_details_form"),
  74. "access_arguments" => array("can_update_course_info_details"),
  75. "page_settings" => array(
  76. "menu_links" => array(
  77. 0 => array(
  78. "text" => "Back to Course Search",
  79. "path" => "tools/course-search",
  80. ),
  81. 1 => array(
  82. "text" => "Back to Course Edit List",
  83. "path" => "tools/course-search/edit-list",
  84. "query" =>"school_id=%SCHOOL_ID%",
  85. ),
  86. ),
  87. ),
  88. "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
  89. "type" => MENU_TYPE_CALLBACK,
  90. );
  91. return $items;
  92. }
  93. /**
  94. * Implements hook
  95. */
  96. function course_search_menu_handle_replacement_pattern($str) {
  97. if (strpos($str, "%SCHOOL_ID%") !== 0) {
  98. if (!isset($_SESSION['last_saved_school_id'])) $_SESSION['last_saved_school_id'] = 0;
  99. // It contains this replacement pattern!
  100. $str = str_replace("%SCHOOL_ID%", intval($_SESSION['last_saved_school_id']), $str);
  101. unset($_SESSION['last_saved_school_id']);
  102. }
  103. if (strpos($str, "%SEV_FILTER%") !== 0) {
  104. // It contains this replacement pattern!
  105. $str = str_replace("%SEV_FILTER%", @$_GET["sev_filter"], $str);
  106. }
  107. if (strpos($str, "%TYPE_FILTER%") !== 0) {
  108. // It contains this replacement pattern!
  109. $str = str_replace("%TYPE_FILTER%", @$_GET["type_filter"], $str);
  110. }
  111. if (strpos($str, "%PAGE%") !== 0) {
  112. // It contains this replacement pattern!
  113. $str = str_replace("%PAGE%", @$_GET["page"], $str);
  114. }
  115. return $str;
  116. }
  117. function course_search_perm() {
  118. return array(
  119. "access_course_search" => array(
  120. 'title' => t('Access course search'),
  121. 'description' => t('Users with this setting are allowed to actually view the course search link,
  122. descriptions, syllabi, etc.'),
  123. ),
  124. "administer_course_search" => array(
  125. "title" => t("Administer course search"),
  126. "description" => t("Users with this setting will be able
  127. to modify settings for the Course Search module."),
  128. ),
  129. "can_update_course_info_details" => array(
  130. "title" => t("Can update course info details"),
  131. "description" => t("Allows users to update the 'course info' details,
  132. like the course's sample syllabus and rotation
  133. schedule."),
  134. ),
  135. );
  136. }
  137. /**
  138. * The system settins form for course_search settings.
  139. */
  140. function course_search_settings_form($school_id = 0) {
  141. $form = array();
  142. $school_id = intval($school_id);
  143. $fs = ""; // The field name suffix. We will add this to the end of all of our field names. If this is the default school, leave blank.
  144. if (module_enabled("schools")) {
  145. $school_name = schools_get_school_name_for_id($school_id);
  146. fp_set_title(t("Configure %school Course Search settings", array('%school' => $school_name)));
  147. if ($school_id !== 0) {
  148. $fs = "~~school_" . $school_id;
  149. }
  150. }
  151. $form['school_id'] = array(
  152. 'type' => 'hidden',
  153. 'value' => $school_id,
  154. );
  155. $form["course_search_avail_term_id_suffix_order" . $fs] = array(
  156. "type" => "textfield",
  157. "label" => t("Available Term ID Suffixes & Order"),
  158. "value" => variable_get_for_school("course_search_avail_term_id_suffix_order", "", $school_id, TRUE),
  159. "description" => t("Enter the order of term ID suffixes, so that they will display
  160. in the correct order in the table of available course
  161. offerings. Separate by comma.") . "
  162. <br>
  163. Ex: 60, 40, 41, 80, 81, mm",
  164. );
  165. $form["course_search_avail_term_headers" . $fs] = array(
  166. "type" => "textfield",
  167. "label" => t("Available Term Table Headers"),
  168. "value" => variable_get_for_school("course_search_avail_term_headers", "", $school_id, TRUE),
  169. "description" => t("Enter the table headers for the available table, in the same
  170. order as the suffix order above.") . "
  171. <br>
  172. Ex: Spring, May, Summer 1, Summer 2, Fall, Winter",
  173. );
  174. // TODO: I am not sure this is even used anymore. If not, get rid of it.
  175. $form["course_search_avail_term_mobile_headers" . $fs] = array(
  176. "type" => "textfield",
  177. "label" => t("Available Term Mobile Table Headers"),
  178. "value" => variable_get_for_school("course_search_avail_term_mobile_headers", "", $school_id, TRUE),
  179. "description" => t("Enter the table headers for the available table, in the same
  180. order as the suffix order above, as it should be displayed on
  181. a mobile device (with a smaller screen).") . "
  182. <br>
  183. Ex: Spr, May, Sum1, Sum2, Fall, Win",
  184. );
  185. return $form;
  186. }
  187. /**
  188. * This function will actually deliver a syllabus to the user's browser
  189. * for download.
  190. *
  191. */
  192. function course_search_download_syllabus() {
  193. // Get our global variables...
  194. $id = trim($_REQUEST["id"]);
  195. $db = get_global_database_handler();
  196. $query = "select * from course_syllabi
  197. where course_id = ? ";
  198. $params = array($id);
  199. $res = db_query($query, $params);
  200. $cur = db_fetch_array($res);
  201. $filename = $cur["filename"];
  202. $course_id = $cur["course_id"];
  203. $school_id = $db->get_school_id_for_course_id($course_id);
  204. // Get the latest subject_id and course_num for this course!
  205. $new_course = new Course();
  206. $new_course->course_id = $course_id;
  207. $new_course->school_id = $school_id;
  208. $new_course->catalog_year = variable_get_for_school("current_catalog_year", 2006, $school_id);
  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,$course_id", 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,$course_id");
  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. fp_set_title('');
  250. $mode = "";
  251. // We are going to be setting up a render array for this screen, so other modules can alter it later.
  252. $render = array();
  253. $render["#id"] = "course_search_display_courses";
  254. $school_id = intval(@$_REQUEST["school_id"]);
  255. $current_catalog_year = variable_get_for_school("current_catalog_year",'', $school_id);
  256. // catalog_year is always just whatever the current year is.
  257. $catalog_year = $current_catalog_year;
  258. $subject_id = $_REQUEST["subject_id"];
  259. $render["#catalog_year"] = $catalog_year;
  260. $render["#school_id"] = $school_id;
  261. $render["#subject_id"] = $subject_id;
  262. $clean_urls = variable_get("clean_urls", FALSE);
  263. // Try to find out the title to this subject, if one exists
  264. // in our subjects table.
  265. $res = db_query("SELECT * FROM subjects
  266. WHERE subject_id =?
  267. AND school_id = ? ", $subject_id, $school_id);
  268. $cur = db_fetch_array($res);
  269. $title = $cur["title"];
  270. if ($title == "") $title = strip_tags($subject_id);
  271. //$rtn .= t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year +1) . "</b>
  272. // ";
  273. if (module_enabled("schools")) {
  274. $render['selected_school_name'] = array(
  275. 'value' => "<div class='current-school'>" . t("Current school: ") . "<strong>" . schools_get_school_name_for_id($school_id) . "</strong>
  276. - " . l(t("Change?"), "tools/course-search") . "</div>",
  277. );
  278. }
  279. $render["current_cat_year"] = array(
  280. "value" => t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year +1) . "</b>",
  281. );
  282. $render["subject_title"] = array(
  283. "value" => "<div class='subject-title'><h2>$title</h2></div>",
  284. );
  285. // Draw the term selector.
  286. $html = "";
  287. $only_term = @strip_tags($_REQUEST["only_term"]);
  288. $html .= "<form id='term_form' action='" . fp_url("tools/course-search/courses") . "' method='GET'>
  289. <input type='hidden' name='mode' value='$subject_id'>
  290. <input type='hidden' name='subject_id' value='$subject_id'>
  291. <input type='hidden' name='school_id' value='$school_id'>
  292. ";
  293. if (!$clean_urls) {
  294. // Hack for if clean URLs isn't enabled
  295. $html .= "<input type='hidden' name='q' value='tools/course-search/courses'>";
  296. }
  297. $html .= "
  298. View courses offered:
  299. <select name='only_term' onChange='document.getElementById(\"term_form\").submit();'>
  300. <option value=''>Any term</option>
  301. ";
  302. $term_array = csv_to_array(variable_get_for_school("course_search_avail_term_id_suffix_order", '', $school_id));
  303. $schedule_text = "";
  304. for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
  305. {
  306. $html .= "<option value=''>---------------------</option>";
  307. foreach($term_array as $x)
  308. {
  309. $schedule_text .= "<td class='tenpt' align='center'>";
  310. $the_term_id = $t . $x;
  311. $temp_course = new Course();
  312. $temp_course->term_id = $the_term_id;
  313. $term_desc = $temp_course->get_term_description(false);
  314. $sel = "";
  315. if ($only_term != "" && $only_term == "$the_term_id") {
  316. $sel = " selected";
  317. }
  318. $html .= "<option value='$the_term_id' $sel>$term_desc</option> \n";
  319. }
  320. }
  321. $html .= "
  322. </select>
  323. </form>";
  324. $render["term_selector_form"] = array(
  325. "value" => $html,
  326. );
  327. if ($only_term != "") {
  328. $temp_course = new Course();
  329. $temp_course->term_id = $only_term;
  330. $term_desc = $temp_course->get_term_description(false);
  331. $render["term_selected_only_term"] = array(
  332. "value" => "<div style='font-weight: bold; padding-bottom: 20px;'>
  333. " . t("The following courses are currently scheduled to be offered during @termdesc", array("@termdesc" => $term_desc)) . "
  334. </div>",
  335. );
  336. }
  337. $term_structures = get_term_structures($school_id);
  338. $grad_notice_flag = false;
  339. $temp_course = new Course();
  340. $result = db_query("SELECT * FROM courses
  341. WHERE catalog_year = ?
  342. AND subject_id = ?
  343. AND exclude = 0
  344. AND delete_flag = 0
  345. AND school_id = ?
  346. ORDER BY course_num ", $catalog_year, $subject_id, $school_id);
  347. if ($result)
  348. {
  349. while ($cur = db_fetch_array($result))
  350. {
  351. $n_subject_id = trim($cur["subject_id"]);
  352. $n_course_num = trim($cur["course_num"]);
  353. $n_course_id = $cur["course_id"];
  354. $n_school_id = $cur['school_id'];
  355. $bool_hide = FALSE;
  356. $title = trim($cur["title"]);
  357. $title = $temp_course->fix_title($title);
  358. $description = trim($cur["description"]);
  359. if ($description == "") {
  360. $description = t("No description is available at this time. Consult
  361. the official course catalog for listings.");
  362. }
  363. $syllabus_text = "";
  364. $syllabus_array = course_search_get_course_syllabus_details($n_course_id);
  365. if (@$syllabus_array["url"] != "")
  366. {
  367. $syllabus_text = "<div class='course-search-sample-syllabus'>
  368. <a href='{$syllabus_array["url"]}' class='nounderline'>
  369. <i class='fa fa-file-text-o'></i>
  370. " . t("Sample Syllabus") . "</a>
  371. </div>
  372. ";
  373. }
  374. // Look for all 5 years.
  375. $long_schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year, 100, TRUE);
  376. $schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year);
  377. $full_schedule_array = course_search_get_course_rotation_schedule($n_course_id);
  378. $schedule_text = "";
  379. if (count($long_schedule_array) > 0) {
  380. $schedule_text .= "
  381. <div>
  382. <b>" . t("Anticipated availability:", array("@cat" => $catalog_year)) . "</b>
  383. ";
  384. $s_disp = "auto";
  385. if ($mode != "advanced")
  386. { // only show this in the basic mode, not advanced.
  387. foreach ($schedule_array as $term_id)
  388. {
  389. $temp_course = new Course();
  390. $temp_course->term_id = $term_id;
  391. $schedule_text .= " " . $temp_course->get_term_description(true) . ",";
  392. }
  393. $schedule_text = substr($schedule_text, 0, -1); // take off comma.
  394. $rnd_div_id = sha1(rand(1,999999) . time());
  395. $schedule_text .= "
  396. &nbsp; | &nbsp;
  397. <a href='javascript: toggleHideDiv(\"$rnd_div_id\");' class='nounderline'>
  398. <span id='SPAN$rnd_div_id'>
  399. " . t("more&raquo;") . "
  400. </span></a> ";
  401. $s_disp = "none";
  402. }
  403. // Consult our settings to find out what order our terms should be in.
  404. $term_array = csv_to_array(variable_get_for_school("course_search_avail_term_id_suffix_order", '', $school_id));
  405. // Get our table headers
  406. $avail_headers = variable_get_for_school("course_search_avail_term_headers", '', $school_id);
  407. $avail_mobile_headers = variable_get_for_school("course_search_avail_term_mobile_headers", '', $school_id);
  408. $th = explode(",", $avail_headers);
  409. $twidth = "90%";
  410. $mleft = "20px;";
  411. $schedule_text .= "
  412. </div>
  413. <div id='$rnd_div_id' style='display: $s_disp; margin-left: $mleft;'>
  414. <table border='1' width='$twidth' class='fp-course-search-avail'>
  415. <tr>
  416. <td>" . t("Year") . "</td>
  417. ";
  418. foreach ($th as $header_text) {
  419. $schedule_text .= "<td>" . trim($header_text) . "</td>";
  420. }
  421. $schedule_text .= " </tr>";
  422. for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
  423. {
  424. $schedule_text .= "<tr>
  425. <td class='tenpt' align='center'>
  426. <b>$t</b>
  427. </td>";
  428. foreach($term_array as $x)
  429. {
  430. $schedule_text .= "<td class='tenpt' align='center'>";
  431. $the_term_id = $t . $x;
  432. // Does the term suffix ($x) call for the year to be
  433. // subtracted by 1, or modified at all? This is the case at ULM for fall.
  434. // Ex: 201340 is Fall of *2012*, not 2013.
  435. // We can tell this because the term structure (from admin settings)
  436. //fpm($term_structures);
  437. if (strtoupper($term_structures[$x]["disp_adjust"]) == "[Y-1]" || strtoupper($term_structures[$x]["disp_adjust"]) == "[Y4-1]") {
  438. // It is subtracted by one. So the year for "XYZ of 2016" is actually recorded as 2017xyz
  439. $the_term_id = ($t + 1) . $x;
  440. }
  441. if (strtoupper($term_structures[$x]["disp_adjust"]) == "[Y+1]" || strtoupper($term_structures[$x]["disp_adjust"]) == "[Y4+1]") {
  442. // It is added by one. So the year for "XYZ of 2016" is actually recorded as 2015xyz
  443. $the_term_id = ($t - 1) . $x;
  444. }
  445. if (in_array($the_term_id, $full_schedule_array))
  446. {
  447. $schedule_text .= "<img src='" . fp_theme_location() . "/images/small_check.gif'>";
  448. }
  449. else {
  450. if ($only_term != "" && $only_term == $the_term_id) {
  451. // Meaning, the term that the user selected is NOT in this
  452. // course's schedule. So, we should hide it.
  453. $bool_hide = TRUE;
  454. }
  455. }
  456. $schedule_text .= "&nbsp;</td>";
  457. }
  458. $schedule_text .= "</tr>";
  459. }
  460. $schedule_text .= "
  461. </table>
  462. </div>
  463. ";
  464. }
  465. else if ($only_term != "") {
  466. // This is if there are NO schedule offerings, yet the user
  467. // selected to view a particular term.
  468. $bool_hide = TRUE;
  469. }
  470. if (course_search_get_course_rotation_schedule_not_anticipated($n_course_id))
  471. {
  472. // This course has no anticipated offerings!
  473. $schedule_text = "<div><b>" . t("Anticipated availability:") . "</b>
  474. " . t("There are no anticipated course offerings
  475. at this time.") . "</div>";
  476. if ($only_term != "") $bool_hide = TRUE;
  477. }
  478. $min_hours = trim($cur["min_hours"]*1);
  479. $max_hours = trim($cur["max_hours"]*1);
  480. if ($min_hours == $max_hours)
  481. {
  482. $hours = $min_hours;
  483. } else {
  484. $hours = "$min_hours to $max_hours";
  485. }
  486. $repeat = "";
  487. if (trim($cur["repeat_hours"]*1) > $min_hours)
  488. {
  489. $repeat = "<div class='course-search-repeat'>" . t("May be repeated for up to @repeat hours of credit.", array("@repeat" => $cur["repeat_hours"]*1)) . "</div>";
  490. if (trim($cur["repeat_hours"]*1) > 20) {
  491. $repeat = "<div class='course-search-repeat'>" . t("May be repeated for credit.") . "</div>";
  492. }
  493. }
  494. // Draw it on screen...
  495. if ($bool_hide != true) {
  496. $details = $schedule_text . $syllabus_text;
  497. $hyp1 = " - ";
  498. $on_click = "";
  499. $html = "";
  500. // Note, the HTML comments are so other modules, that wish to manipulate this block, have something easy to find/replace
  501. $html .= "<div class='course-search-course-block'>
  502. <!-- TITLE-ROW -->
  503. <div class='course-search-course-title-row'
  504. $on_click>
  505. <!-- COURSE-NAME -->
  506. <span class='course-search-course-name'>$n_subject_id $n_course_num</span>
  507. $hyp1
  508. <!-- END-COURSE-NAME ->
  509. <!-- COURSE-TITLE -->
  510. <span class='course-search-course-title'>$title</span> - $hours " . t("hrs.") . "$repeat
  511. <!-- END-COURSE-TITLE -->
  512. </div>
  513. <!-- END-TITLE-ROW -->
  514. <!-- COURSE-EXTRA -->
  515. <div class='course-search-course-extra'>
  516. <!-- DESC -->
  517. <div class='course-search-course-description'>$description</div>
  518. <!-- END-DESC -->
  519. <!-- DETAILS -->
  520. <div class='course-search-course-details'>$details</div>
  521. <!-- END-DETAILS -->
  522. ";
  523. $html .= "</div>
  524. <!-- END-COURSE-EXTRA -->"; // div course-search-course-extra
  525. $html .= "</div>"; // div course-search-course-block
  526. $render["course_search_course_block__$n_course_id"] = array(
  527. "value" => $html,
  528. );
  529. }
  530. }
  531. }
  532. watchdog("course_search", "User viewed courses in subject: @subject", array("@subject" => $subject_id));
  533. //$pC .= $screen->get_java_script_code();
  534. $html = '
  535. <script type="text/javascript">
  536. function toggleHideDiv(rndDivID)
  537. {
  538. var d = document.getElementById(rndDivID);
  539. if (d.style.display == "none")
  540. {
  541. d.style.display = "";
  542. document.getElementById("SPAN" + rndDivID).innerHTML = "&laquo;less";
  543. } else {
  544. d.style.display = "none";
  545. document.getElementById("SPAN" + rndDivID).innerHTML = "more&raquo;";
  546. }
  547. }
  548. function toggleCourseExtra(e) {
  549. $(e).siblings(".course-search-course-extra").slideToggle("medium");
  550. }
  551. </script>
  552. ';
  553. $render["extra_javascript"] = array(
  554. "value" => $html,
  555. );
  556. $rtn .= fp_render_content($render);
  557. // Let's set our breadcrumbs
  558. $crumbs = array();
  559. $crumbs[] = array(
  560. 'text' => 'Courses',
  561. 'path' => 'tools/course-search',
  562. );
  563. fp_set_breadcrumbs($crumbs);
  564. return $rtn;
  565. }
  566. function course_search_get_course_rotation_schedule_not_anticipated($course_id)
  567. {
  568. $rtn = FALSE;
  569. // Returns TRUE if not is NOT ANTICIPATED. False, if this
  570. // is a normal courses which has an offering, or a blank
  571. // offering. This will
  572. // only return true if NOTA is set as a term for this course.
  573. $res = db_query("SELECT * FROM course_rotation_schedule
  574. WHERE course_id = '?'
  575. AND term_id = 'NOTA'
  576. ", $course_id);
  577. if (db_num_rows($res) > 0) {
  578. $rtn = TRUE;
  579. }
  580. //////////////////////////////////////
  581. // Okay, now we invoke a hook, to see if any other modules
  582. // would like to add or alter our answer
  583. invoke_hook("course_search_get_course_rotation_schedule_not_anticipated", array(&$rtn, $course_id));
  584. return $rtn;
  585. }
  586. function course_search_get_course_capacity($course_id, $term_id) {
  587. // Return from cache if we already have it.
  588. if (isset($GLOBALS['fp_cache_course_capacity'][$course_id])) {
  589. return $GLOBALS['fp_cache_course_capacity'][$course_id];
  590. }
  591. $cap = db_result(db_query("SELECT capacity FROM course_rotation_schedule
  592. WHERE course_id = ?
  593. AND term_id = ?", array($course_id, $term_id)));
  594. $cap = intval($cap);
  595. $GLOBALS['fp_cache_course_capacity'][$course_id] = $cap; // save to simple globals cache
  596. return $cap;
  597. }
  598. function course_search_get_course_rotation_schedule($course_id, $year = "", $limit = 20, $bool_include_next_five_years = FALSE)
  599. {
  600. // Has this already been saved to our globals cache? If so, just return that.
  601. if (isset($GLOBALS['cache_course_search_rotation_schedule'][$course_id][$year][$limit][intval($bool_include_next_five_years)])) {
  602. return $GLOBALS['cache_course_search_rotation_schedule'][$course_id][$year][$limit][intval($bool_include_next_five_years)];
  603. }
  604. $year = intval($year);
  605. $limit = intval($limit);
  606. // return an array containing the terms that this course
  607. // is going to be offered, if any.
  608. $rtn_array = array();
  609. $arr = array();
  610. $year_line = "";
  611. if ($year != "")
  612. { // if a year is entered, we will get the next few years, and the previous
  613. // one for good measure.
  614. $year_line = "and (`term_id` LIKE '$year%' or `term_id` LIKE '" . ($year+1) . "%') ";
  615. if ($bool_include_next_five_years)
  616. {
  617. $yearm1 = $year - 1;
  618. $year2 = $year + 1;
  619. $year3 = $year + 2;
  620. $year4 = $year + 3;
  621. $year5 = $year + 4;
  622. $year6 = $year + 5;
  623. $year_line = "and (`term_id` LIKE '$year%'
  624. or `term_id` LIKE '$yearm1%'
  625. or `term_id` LIKE '$year2%'
  626. or `term_id` LIKE '$year3%'
  627. or `term_id` LIKE '$year4%'
  628. or `term_id` LIKE '$year5%'
  629. or `term_id` LIKE '$year6%'
  630. ) ";
  631. }
  632. }
  633. $res = db_query("SELECT * FROM course_rotation_schedule
  634. WHERE `course_id`= ?
  635. $year_line
  636. ORDER BY term_id DESC
  637. LIMIT $limit", $course_id);
  638. while($cur = db_fetch_array($res))
  639. {
  640. $t = $cur["term_id"];
  641. // Get the term from the end.
  642. $ss = trim(substr($t,4,1));
  643. if ($ss == "m"){$ss = "1.5";}
  644. if (is_numeric($ss)) {
  645. $ss = $ss * 10;
  646. }
  647. $year = trim(substr($t,0,4));
  648. // We do all this so we can establish an order to the terms
  649. // by using a sort() command later.
  650. $arr[] = $year . "~" . $ss . "~" . $t;
  651. }
  652. sort($arr);
  653. // Now we want to get out JUST the terms...
  654. foreach($arr as $line)
  655. {
  656. $temp = explode("~",$line);
  657. $rtn_array[] = trim($temp[2]);
  658. }
  659. //////////////////////////////////////
  660. // Okay, now we invoke a hook, to see if any other modules
  661. // would like to add or alter our rotation schedule (notice $rtn_array is passed by reference)
  662. invoke_hook("course_search_get_course_rotation_schedule", array(&$rtn_array, $course_id, $year, $limit, $bool_include_next_five_years));
  663. // Save to globals cache to make it faster lookup
  664. $GLOBALS['cache_course_search_rotation_schedule'][$course_id][$year][$limit][intval($bool_include_next_five_years)] = $rtn_array;
  665. return $rtn_array;
  666. }
  667. function course_search_get_course_syllabus_details($course_id)
  668. {
  669. // This will return an array containing information
  670. // about a course's syllabus, if it exists.
  671. $rtn_array = FALSE;
  672. // Does this course have a syllabus?
  673. $query = "SELECT * FROM course_syllabi
  674. WHERE course_id = ? ";
  675. $res = db_query($query, $course_id);
  676. $cur = db_fetch_array($res);
  677. if (isset($cur["filename"]) && $cur['filename'] != "") {
  678. $rtn_array = array();
  679. $rtn_array["url"] = $GLOBALS["fp_system_settings"]["base_url"] . "/" . fp_url("course-search/get-syllabus", "id=" . $course_id, FALSE);
  680. $rtn_array["filename"] = $cur["filename"];
  681. $rtn_array["posted"] = $cur["posted"];
  682. }
  683. return $rtn_array;
  684. }
  685. function course_search_select_school_form() {
  686. $form = array();
  687. $options = schools_get_schools_for_fapi(TRUE, FALSE); // we don't need special permissions to view.
  688. $form['school_id'] = array(
  689. 'type' => 'select',
  690. 'label' => t('Please begin by selecting a school:'),
  691. 'options' => $options,
  692. 'value' => @$_REQUEST['school_id'],
  693. 'hide_please_select' => TRUE,
  694. 'required' => TRUE,
  695. );
  696. $form['submit_btn'] = array(
  697. 'type' => 'submit',
  698. 'value' => t("Continue"),
  699. );
  700. return $form;
  701. }
  702. function course_search_select_school_form_submit($form, $form_state) {
  703. $values = $form_state['values'];
  704. fp_goto('tools/course-search', 'school_id=' . $values['school_id']);
  705. }
  706. /**
  707. * Displays the search pulldown for the user to use to find courses.
  708. */
  709. function course_search_display_search() {
  710. fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
  711. // We are going to be setting up a render array for this screen, so other modules can alter it later.
  712. $render = array();
  713. $render["#id"] = "course_search_display_search";
  714. $school_id = 0;
  715. if (module_enabled("schools")) { // The schools module is enabled. We need to first ask what school we want to look at.
  716. if (!isset($_REQUEST['school_id'])) {
  717. $rtn .= fp_render_form('course_search_select_school_form');
  718. return $rtn;
  719. } // not isset school_id
  720. $school_id = intval($_REQUEST['school_id']);
  721. $render['current_school'] = array(
  722. 'value' => "<div class='current-school'>" . t("Current school: ") . "<strong>" . schools_get_school_name_for_id($school_id) . "</strong>
  723. - " . l(t("Change?"), "tools/course-search") . "</div>",
  724. 'weight' => 0,
  725. );
  726. }
  727. $clean_urls = variable_get("clean_urls", FALSE);
  728. $school_id = intval(@$_REQUEST['school_id']);
  729. $current_catalog_year = variable_get_for_school('current_catalog_year', 2006, $school_id);
  730. // catalog_year is always just whatever the current year is.
  731. $catalog_year = $current_catalog_year;
  732. $render['#school_id'] = $school_id;
  733. $render['#catalog_year'] = $catalog_year;
  734. if (user_has_permission("can_update_course_info_details")) {
  735. $html = "<div>" . t("Administrators:") . " " . l("<i class='fa fa-pencil'></i> " . t("Edit course schedules, capacity, and syllabi"), "tools/course-search/edit-list", "school_id=$school_id") . "</div>";
  736. $render['edit_course_schedules'] = array(
  737. 'value' => $html,
  738. 'weight' => 100,
  739. );
  740. }
  741. // Catalog year has been selected.
  742. $html = "<div class='current-cat-year-line'>" . t("Current catalog year: <strong>@cat</strong></div>", array('@cat' => "$catalog_year-" . ($catalog_year +1)));
  743. $render['current_catalog_line'] = array(
  744. 'value' => $html,
  745. 'weight' => 200,
  746. );
  747. $html = "";
  748. $html .= "<br><br>
  749. <label>Please select an available subject from the list below.</label>
  750. <form action='" . fp_url("tools/course-search/courses") . "' method='GET' name='mainform' id='myform'>
  751. <input type='hidden' name='school_id' value='$school_id'> ";
  752. if (!$clean_urls) {
  753. // Hack for if clean URLs isn't enabled
  754. $html .= "<input type='hidden' name='q' value='tools/course-search/courses'>";
  755. }
  756. $html .= "
  757. <div id='element-inner-wrapper-course-search-subject' class='form-element element-type-select '>
  758. <select class='course-search-subject' name='subject_id'>
  759. ";
  760. // We want to make a pull-down list of all available subjects.
  761. // Keep in mind with this join-- we may have courses who have
  762. // a subject_id, for which we don't have that subject in the subjects
  763. // table.
  764. $query = "SELECT DISTINCT b.subject_id, a.title FROM courses b LEFT JOIN subjects a
  765. ON (a.subject_id = b.subject_id)
  766. WHERE exclude = 0
  767. AND catalog_year = ?
  768. AND a.school_id = b.school_id
  769. AND b.school_id = ?
  770. ";
  771. $subjects = array();
  772. $result = db_query($query, $catalog_year, $school_id);
  773. while ($cur = db_fetch_array($result))
  774. {
  775. //fpm($cur);
  776. $title = trim($cur["title"]);
  777. $subject_id = trim($cur["subject_id"]);
  778. if ($title == "") {
  779. $title = $subject_id;
  780. }
  781. $subjects[$subject_id] = $title;
  782. }
  783. asort($subjects);
  784. foreach ($subjects as $subject_id => $title) {
  785. $html .= "<option value='$subject_id'>$title ($subject_id)</option>";
  786. }
  787. $html .= " </select>
  788. </div>
  789. <div class='course-search-buttons buttons form-element element-type-submit'>
  790. <input type='submit' value='Select'>
  791. </div>
  792. </form>";
  793. $render['selection_form'] = array(
  794. 'value' => $html,
  795. 'weight' => 300,
  796. );
  797. $rtn = fp_render_content($render);
  798. return $rtn;
  799. }

Functions