course_search.module
Search API
- 7.x modules/course_search/course_search.module
- 6.x modules/course_search/course_search.module
- 4.x modules/course_search/course_search.module
- 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.moduleView source
- <?php
-
- /**
- * @file
- * This module allows users to search for courses, descriptions, and, if supported, rotation schedules
- * and sample syllabi.
- */
-
-
- function course_search_menu() {
- $items = array();
-
- $items["tools/course-search"] = array(
- "title" => "Course Search",
- "description" => "Use this tool to view course descriptions, sample syllabi, and projected course offering schedules.",
- "page_callback" => "course_search_display_search",
- "access_arguments" => array('access_course_search'),
- "page_settings" => array(
- "page_hide_report_error" => TRUE,
- "target" => "_blank",
- "menu_icon" => fp_get_module_path('course_search') . "/icons/book_go.png",
- ),
- "type" => MENU_TYPE_NORMAL_ITEM,
- );
-
-
- $items["course-search/get-syllabus"] = array(
- "title" => "Course Search",
- "page_callback" => "course_search_download_syllabus",
- "access_arguments" => array('access_course_search'),
- "type" => MENU_TYPE_CALLBACK,
- );
-
-
-
- $items["admin/config/course-search"] = array(
- "title" => "Course Search settings",
- "description" => "Administer the Course Search module's settings",
- "page_callback" => "fp_render_form",
- "page_arguments" => array("course_search_settings_form", "system_settings"),
- "access_arguments" => array("administer_course_search"),
- "page_settings" => array(
-
-
- "page_hide_report_error" => TRUE,
- "menu_icon" => fp_get_module_path('course_search') . "/icons/book_go.png",
- "menu_links" => array(
- 0 => array(
- "text" => "Admin Console",
- "path" => "admin-tools/admin",
- "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
- ),
- ),
- ),
- "type" => MENU_TYPE_NORMAL_ITEM,
- );
-
- $items["tools/course-search/courses"] = array(
- "title" => "Course Search",
- "page_callback" => "course_search_display_courses",
- "access_arguments" => array('access_course_search'),
- "page_settings" => array(
-
-
- "page_hide_report_error" => TRUE,
- ),
- "type" => MENU_TYPE_CALLBACK,
- );
-
-
- $items["tools/course-search/edit-list"] = array(
- "title" => "Update Course Information",
- "page_callback" => "course_search_display_edit_courses",
- "access_arguments" => array("can_update_course_info_details"),
- "page_settings" => array(
-
- "menu_links" => array(
- 0 => array(
- "text" => "Back to Course Search",
- "path" => "tools/course-search",
- ),
- ),
- ),
- "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
- "type" => MENU_TYPE_CALLBACK,
- );
-
-
- $items["tools/course-search/edit-info-details"] = array(
- "title" => "Edit Course Info Details",
- "page_callback" => "fp_render_form",
- "page_arguments" => array("course_search_edit_course_details_form"),
- "access_arguments" => array("can_update_course_info_details"),
- "page_settings" => array(
-
-
- "menu_links" => array(
- 0 => array(
- "text" => "Back to Course Search",
- "path" => "tools/course-search",
- ),
- 1 => array(
- "text" => "Back to Course Edit List",
- "path" => "tools/course-search/edit-list",
- "query" =>"school_id=%SCHOOL_ID%",
- ),
- ),
- ),
- "file" => menu_get_module_path("course_search") . "/course_search.edit.inc",
- "type" => MENU_TYPE_CALLBACK,
- );
-
-
- return $items;
- }
-
- /**
- * Implements hook
- */
- function course_search_menu_handle_replacement_pattern($str) {
-
- if (strpos($str, "%SCHOOL_ID%") !== 0) {
- if (!isset($_SESSION['last_saved_school_id'])) $_SESSION['last_saved_school_id'] = 0;
- // It contains this replacement pattern!
- $str = str_replace("%SCHOOL_ID%", intval($_SESSION['last_saved_school_id']), $str);
- unset($_SESSION['last_saved_school_id']);
- }
-
- if (strpos($str, "%SEV_FILTER%") !== 0) {
- // It contains this replacement pattern!
- $str = str_replace("%SEV_FILTER%", @$_GET["sev_filter"], $str);
- }
-
- if (strpos($str, "%TYPE_FILTER%") !== 0) {
- // It contains this replacement pattern!
- $str = str_replace("%TYPE_FILTER%", @$_GET["type_filter"], $str);
- }
-
-
- if (strpos($str, "%PAGE%") !== 0) {
- // It contains this replacement pattern!
- $str = str_replace("%PAGE%", @$_GET["page"], $str);
- }
-
-
-
- return $str;
- }
-
-
-
-
-
-
-
- function course_search_perm() {
- return array(
- "access_course_search" => array(
- 'title' => t('Access course search'),
- 'description' => t('Users with this setting are allowed to actually view the course search link,
- descriptions, syllabi, etc.'),
- ),
- "administer_course_search" => array(
- "title" => t("Administer course search"),
- "description" => t("Users with this setting will be able
- to modify settings for the Course Search module."),
- ),
- "can_update_course_info_details" => array(
- "title" => t("Can update course info details"),
- "description" => t("Allows users to update the 'course info' details,
- like the course's sample syllabus and rotation
- schedule."),
- ),
-
-
- );
- }
-
-
-
- /**
- * The system settins form for course_search settings.
- */
- function course_search_settings_form($school_id = 0) {
- $form = array();
-
- $school_id = intval($school_id);
-
- $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.
- if (module_enabled("schools")) {
- $school_name = schools_get_school_name_for_id($school_id);
- fp_set_title(t("Configure %school Course Search settings", array('%school' => $school_name)));
- if ($school_id !== 0) {
- $fs = "~~school_" . $school_id;
- }
- }
-
- $form['school_id'] = array(
- 'type' => 'hidden',
- 'value' => $school_id,
- );
-
-
-
- $form["course_search_avail_term_id_suffix_order" . $fs] = array(
- "type" => "textfield",
- "label" => t("Available Term ID Suffixes & Order"),
- "value" => variable_get_for_school("course_search_avail_term_id_suffix_order", "", $school_id, TRUE),
- "description" => t("Enter the order of term ID suffixes, so that they will display
- in the correct order in the table of available course
- offerings. Separate by comma.") . "
- <br>
- Ex: 60, 40, 41, 80, 81, mm",
- );
-
-
- $form["course_search_avail_term_headers" . $fs] = array(
- "type" => "textfield",
- "label" => t("Available Term Table Headers"),
- "value" => variable_get_for_school("course_search_avail_term_headers", "", $school_id, TRUE),
- "description" => t("Enter the table headers for the available table, in the same
- order as the suffix order above.") . "
- <br>
- Ex: Spring, May, Summer 1, Summer 2, Fall, Winter",
- );
-
-
- // TODO: I am not sure this is even used anymore. If not, get rid of it.
- $form["course_search_avail_term_mobile_headers" . $fs] = array(
- "type" => "textfield",
- "label" => t("Available Term Mobile Table Headers"),
- "value" => variable_get_for_school("course_search_avail_term_mobile_headers", "", $school_id, TRUE),
- "description" => t("Enter the table headers for the available table, in the same
- order as the suffix order above, as it should be displayed on
- a mobile device (with a smaller screen).") . "
- <br>
- Ex: Spr, May, Sum1, Sum2, Fall, Win",
- );
-
-
-
-
-
-
- return $form;
- }
-
-
-
- /**
- * This function will actually deliver a syllabus to the user's browser
- * for download.
- *
- */
- function course_search_download_syllabus() {
- // Get our global variables...
-
-
- $id = trim($_REQUEST["id"]);
-
- $db = get_global_database_handler();
-
-
- $query = "select * from course_syllabi
- where course_id = ? ";
- $params = array($id);
-
-
- $res = db_query($query, $params);
- $cur = db_fetch_array($res);
- $filename = $cur["filename"];
-
- $course_id = $cur["course_id"];
- $school_id = $db->get_school_id_for_course_id($course_id);
-
- // Get the latest subject_id and course_num for this course!
- $new_course = new Course();
- $new_course->course_id = $course_id;
- $new_course->school_id = $school_id;
- $new_course->catalog_year = variable_get_for_school("current_catalog_year", 2006, $school_id);
- $new_course->load_descriptive_data(false, false, true);
-
- $subject_id = $new_course->subject_id;
- $course_num = $new_course->course_num;
-
- $files_path = $GLOBALS["fp_system_settings"]["file_system_path"];
-
- if ($filename == "" || !file_exists("$files_path/custom/files/syllabi/$filename"))
- { // Check to make sure the src file actually exists.
- // Display a message, letting the user know it does not
- // exist.
- watchdog("syllabus", "fail,$course_id", array(), WATCHDOG_ERROR);
- fp_add_message(t("Sorry, the syllabus for @course could not be found.", array("@course" => "$subject_id $course_num")));
- // Just so admins can see:
- fpm("Admin: file path attempted: $files_path/custom/files/syllabi/$filename");
- return;
- }
-
- watchdog("syllabus", "get,$course_id");
-
- $content_type = "application/plain"; // default, save as generic binary file.
- $temp = explode("\.", $filename);
- $ext = $temp[count($temp) - 1]; // get the original file extension.
-
- // attempt to match to the correct content_type...
- if ($ext == "pdf"){ $content_type = "application/pdf"; }
- if ($ext == "doc") { $content_type = "application/msword"; }
- if ($ext == "docx") { $content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; }
- if ($ext == "txt") { $content_type = "text/plain"; }
- if ($ext == "pot") { $content_type = "application/mspowerpoint"; }
- if ($ext == "ppt") { $content_type = "application/powerpoint"; }
- if (strstr($ext,"xl")) { $content_type = "application/excel"; }
-
-
-
-
- $fn = urlencode($subject_id . "_" . $course_num . "_SAMPLE_SYLLABUS") .".$ext"; // make it a safe filename.
- $fn = str_replace("+"," ",$fn); // restore spaces from + symbols...
-
- // Give it to the browser!
- header('Content-type: ' . $content_type . '');
- header('Content-Disposition: attachment; filename="' . $fn . '"');
- readfile("$files_path/custom/files/syllabi/" . $filename . "");
- die;
- }
-
-
-
- /**
- * Show the user their select of courses.
- */
- function course_search_display_courses() {
- $rtn = "";
-
- fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
-
- fp_set_title('');
-
- $mode = "";
-
-
- // We are going to be setting up a render array for this screen, so other modules can alter it later.
- $render = array();
- $render["#id"] = "course_search_display_courses";
-
- $school_id = intval(@$_REQUEST["school_id"]);
-
-
- $current_catalog_year = variable_get_for_school("current_catalog_year",'', $school_id);
-
- // catalog_year is always just whatever the current year is.
- $catalog_year = $current_catalog_year;
- $subject_id = $_REQUEST["subject_id"];
-
-
- $render["#catalog_year"] = $catalog_year;
- $render["#school_id"] = $school_id;
- $render["#subject_id"] = $subject_id;
-
-
-
-
-
- $clean_urls = variable_get("clean_urls", FALSE);
-
- // Try to find out the title to this subject, if one exists
- // in our subjects table.
- $res = db_query("SELECT * FROM subjects
- WHERE subject_id =?
- AND school_id = ? ", $subject_id, $school_id);
- $cur = db_fetch_array($res);
- $title = $cur["title"];
- if ($title == "") $title = strip_tags($subject_id);
-
-
- //$rtn .= t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year +1) . "</b>
- // ";
-
- if (module_enabled("schools")) {
- $render['selected_school_name'] = array(
- 'value' => "<div class='current-school'>" . t("Current school: ") . "<strong>" . schools_get_school_name_for_id($school_id) . "</strong>
- - " . l(t("Change?"), "tools/course-search") . "</div>",
-
- );
- }
-
- $render["current_cat_year"] = array(
- "value" => "<div class='current-cat-year-line'>" . t("Current catalog year:") . " <strong>$catalog_year-" . ($catalog_year +1) . "</strong></div>",
- );
-
-
- $render["subject_title"] = array(
- "value" => "<div class='subject-title'><h2>$title</h2></div>",
- );
-
- // Draw the term selector.
- $html = "";
- $only_term = @strip_tags($_REQUEST["only_term"]);
- $html .= "<form id='term_form' action='" . fp_url("tools/course-search/courses") . "' method='GET'>
- <input type='hidden' name='mode' value='$subject_id'>
- <input type='hidden' name='subject_id' value='$subject_id'>
- <input type='hidden' name='school_id' value='$school_id'>
- ";
-
- if (!$clean_urls) {
- // Hack for if clean URLs isn't enabled
- $html .= "<input type='hidden' name='q' value='tools/course-search/courses'>";
- }
-
- $html .= "
- View courses offered:
- <select name='only_term' onChange='document.getElementById(\"term_form\").submit();'>
- <option value=''>Any term</option>
- ";
-
- $term_array = csv_to_array(variable_get_for_school("course_search_avail_term_id_suffix_order", '', $school_id));
-
- $schedule_text = "";
-
- for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
- {
- $html .= "<option value=''>---------------------</option>";
- foreach($term_array as $x)
- {
- $schedule_text .= "<td class='tenpt' align='center'>";
- $the_term_id = $t . $x;
-
- $temp_course = new Course();
- $temp_course->term_id = $the_term_id;
- $term_desc = $temp_course->get_term_description(false);
-
- $sel = "";
- if ($only_term != "" && $only_term == "$the_term_id") {
- $sel = " selected";
- }
-
- $html .= "<option value='$the_term_id' $sel>$term_desc</option> \n";
- }
-
- }
- $html .= "
- </select>
- </form>";
-
-
- $render["term_selector_form"] = array(
- "value" => $html,
- );
-
-
-
- if ($only_term != "") {
- $temp_course = new Course();
- $temp_course->term_id = $only_term;
- $term_desc = $temp_course->get_term_description(false);
-
-
- $render["term_selected_only_term"] = array(
- "value" => "<div style='font-weight: bold; padding-bottom: 20px;'>
- " . t("The following courses are currently scheduled to be offered during @termdesc", array("@termdesc" => $term_desc)) . "
- </div>",
-
- );
-
- }
-
- $term_structures = get_term_structures($school_id);
-
- $grad_notice_flag = false;
- $temp_course = new Course();
-
- $result = db_query("SELECT * FROM courses
- WHERE catalog_year = ?
- AND subject_id = ?
- AND exclude = 0
- AND delete_flag = 0
- AND school_id = ?
- ORDER BY course_num ", $catalog_year, $subject_id, $school_id);
- if ($result)
- {
- while ($cur = db_fetch_array($result))
- {
- $n_subject_id = trim($cur["subject_id"]);
- $n_course_num = trim($cur["course_num"]);
- $n_course_id = $cur["course_id"];
- $n_school_id = $cur['school_id'];
- $bool_hide = FALSE;
-
- $title = trim($cur["title"]);
-
- $title = $temp_course->fix_title($title);
-
- $description = trim($cur["description"]);
- if ($description == "") {
- $description = t("No description is available at this time. Consult
- the official course catalog for listings.");
- }
-
- $syllabus_text = "";
- $syllabus_array = course_search_get_course_syllabus_details($n_course_id);
-
- if (@$syllabus_array["url"] != "")
- {
- $syllabus_text = "<div class='course-search-sample-syllabus'>
- <a href='{$syllabus_array["url"]}' class='nounderline'>
- <i class='fa fa-file-text-o'></i>
- " . t("Sample Syllabus") . "</a>
-
- </div>
- ";
- }
-
- // Look for all 5 years.
- $long_schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year, 100, TRUE);
-
- $schedule_array = course_search_get_course_rotation_schedule($n_course_id, $catalog_year);
-
- $full_schedule_array = course_search_get_course_rotation_schedule($n_course_id);
- $schedule_text = "";
-
- if (count($long_schedule_array) > 0) {
- $schedule_text .= "
- <div>
- <b>" . t("Anticipated availability:", array("@cat" => $catalog_year)) . "</b>
- ";
- $s_disp = "auto";
- if ($mode != "advanced")
- { // only show this in the basic mode, not advanced.
- foreach ($schedule_array as $term_id)
- {
-
- $temp_course = new Course();
- $temp_course->term_id = $term_id;
- $schedule_text .= " " . $temp_course->get_term_description(true) . ",";
- }
- $schedule_text = substr($schedule_text, 0, -1); // take off comma.
- $rnd_div_id = sha1(rand(1,999999) . time());
- $schedule_text .= "
- |
- <a href='javascript: toggleHideDiv(\"$rnd_div_id\");' class='nounderline'>
- <span id='SPAN$rnd_div_id'>
- " . t("more»") . "
- </span></a> ";
- $s_disp = "none";
- }
-
-
- // Consult our settings to find out what order our terms should be in.
- $term_array = csv_to_array(variable_get_for_school("course_search_avail_term_id_suffix_order", '', $school_id));
-
- // Get our table headers
- $avail_headers = variable_get_for_school("course_search_avail_term_headers", '', $school_id);
- $avail_mobile_headers = variable_get_for_school("course_search_avail_term_mobile_headers", '', $school_id);
-
-
- $th = explode(",", $avail_headers);
-
- $twidth = "90%";
- $mleft = "20px;";
-
- $schedule_text .= "
- </div>
- <div id='$rnd_div_id' style='display: $s_disp; margin-left: $mleft;'>
- <table border='1' width='$twidth' class='fp-course-search-avail'>
- <tr>
- <td>" . t("Year") . "</td>
- ";
- foreach ($th as $header_text) {
- $schedule_text .= "<td>" . trim($header_text) . "</td>";
- }
- $schedule_text .= " </tr>";
-
- for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
- {
- $schedule_text .= "<tr>
- <td class='tenpt' align='center'>
- <b>$t</b>
- </td>";
- foreach($term_array as $x)
- {
- $schedule_text .= "<td class='tenpt' align='center'>";
- $the_term_id = $t . $x;
-
- // Does the term suffix ($x) call for the year to be
- // subtracted by 1, or modified at all? This is the case at ULM for fall.
- // Ex: 201340 is Fall of *2012*, not 2013.
- // We can tell this because the term structure (from admin settings)
- //fpm($term_structures);
- if (strtoupper($term_structures[$x]["disp_adjust"]) == "[Y-1]" || strtoupper($term_structures[$x]["disp_adjust"]) == "[Y4-1]") {
- // It is subtracted by one. So the year for "XYZ of 2016" is actually recorded as 2017xyz
- $the_term_id = ($t + 1) . $x;
- }
- if (strtoupper($term_structures[$x]["disp_adjust"]) == "[Y+1]" || strtoupper($term_structures[$x]["disp_adjust"]) == "[Y4+1]") {
- // It is added by one. So the year for "XYZ of 2016" is actually recorded as 2015xyz
- $the_term_id = ($t - 1) . $x;
- }
-
-
-
-
- if (in_array($the_term_id, $full_schedule_array))
- {
- $schedule_text .= "<img src='" . fp_theme_location() . "/images/small_check.gif'>";
- }
- else {
- if ($only_term != "" && $only_term == $the_term_id) {
- // Meaning, the term that the user selected is NOT in this
- // course's schedule. So, we should hide it.
- $bool_hide = TRUE;
- }
- }
- $schedule_text .= " </td>";
-
- }
- $schedule_text .= "</tr>";
- }
-
-
- $schedule_text .= "
- </table>
- </div>
- ";
-
-
-
- }
- else if ($only_term != "") {
- // This is if there are NO schedule offerings, yet the user
- // selected to view a particular term.
- $bool_hide = TRUE;
- }
-
-
- if (course_search_get_course_rotation_schedule_not_anticipated($n_course_id))
- {
-
- // This course has no anticipated offerings!
- $schedule_text = "<div><b>" . t("Anticipated availability:") . "</b>
- " . t("There are no anticipated course offerings
- at this time.") . "</div>";
- if ($only_term != "") $bool_hide = TRUE;
- }
-
-
- $min_hours = trim($cur["min_hours"]*1);
- $max_hours = trim($cur["max_hours"]*1);
- if ($min_hours == $max_hours)
- {
- $hours = $min_hours;
- } else {
- $hours = "$min_hours to $max_hours";
- }
-
- $repeat = "";
- if (trim($cur["repeat_hours"]*1) > $min_hours)
- {
- $repeat = "<div class='course-search-repeat'>" . t("May be repeated for up to @repeat hours of credit.", array("@repeat" => $cur["repeat_hours"]*1)) . "</div>";
- if (trim($cur["repeat_hours"]*1) > 20) {
- $repeat = "<div class='course-search-repeat'>" . t("May be repeated for credit.") . "</div>";
- }
- }
-
-
- // Draw it on screen...
- if ($bool_hide != true) {
-
-
- $details = $schedule_text . $syllabus_text;
-
- $hyp1 = " - ";
- $on_click = "";
-
- $html = "";
-
- // Note, the HTML comments are so other modules, that wish to manipulate this block, have something easy to find/replace
-
- $html .= "<div class='course-search-course-block'>
- <!-- TITLE-ROW -->
- <div class='course-search-course-title-row'
- $on_click>
- <!-- COURSE-NAME -->
- <span class='course-search-course-name'>$n_subject_id $n_course_num</span>
- $hyp1
- <!-- END-COURSE-NAME ->
- <!-- COURSE-TITLE -->
- <span class='course-search-course-title'>$title</span> - $hours " . t("hrs.") . "$repeat
- <!-- END-COURSE-TITLE -->
- </div>
- <!-- END-TITLE-ROW -->
- <!-- COURSE-EXTRA -->
- <div class='course-search-course-extra'>
- <!-- DESC -->
- <div class='course-search-course-description'>$description</div>
- <!-- END-DESC -->
- <!-- DETAILS -->
- <div class='course-search-course-details'>$details</div>
- <!-- END-DETAILS -->
- ";
-
-
-
-
- $html .= "</div>
- <!-- END-COURSE-EXTRA -->"; // div course-search-course-extra
-
- $html .= "</div>"; // div course-search-course-block
-
- $render["course_search_course_block__$n_course_id"] = array(
- "value" => $html,
- );
-
-
- }
-
- }
- }
-
-
- watchdog("course_search", "User viewed courses in subject: @subject", array("@subject" => $subject_id));
-
-
- //$pC .= $screen->get_java_script_code();
- $html = '
- <script type="text/javascript">
- function toggleHideDiv(rndDivID)
- {
- var d = document.getElementById(rndDivID);
- if (d.style.display == "none")
- {
- d.style.display = "";
- document.getElementById("SPAN" + rndDivID).innerHTML = "«less";
- } else {
- d.style.display = "none";
- document.getElementById("SPAN" + rndDivID).innerHTML = "more»";
- }
-
- }
-
- function toggleCourseExtra(e) {
- $(e).siblings(".course-search-course-extra").slideToggle("medium");
- }
-
- </script>
-
- ';
-
-
- $render["extra_javascript"] = array(
- "value" => $html,
- );
-
- $rtn .= fp_render_content($render);
-
-
-
- // Let's set our breadcrumbs
- $crumbs = array();
- $crumbs[] = array(
- 'text' => 'Courses',
- 'path' => 'tools/course-search',
- );
- fp_set_breadcrumbs($crumbs);
-
-
-
-
-
-
- return $rtn;
- }
-
-
-
- function course_search_get_course_rotation_schedule_not_anticipated($course_id)
- {
- $rtn = FALSE;
-
- // Returns TRUE if not is NOT ANTICIPATED. False, if this
- // is a normal courses which has an offering, or a blank
- // offering. This will
- // only return true if NOTA is set as a term for this course.
- $res = db_query("SELECT * FROM course_rotation_schedule
- WHERE course_id = '?'
- AND term_id = 'NOTA'
- ", $course_id);
- if (db_num_rows($res) > 0) {
- $rtn = TRUE;
- }
-
-
- //////////////////////////////////////
- // Okay, now we invoke a hook, to see if any other modules
- // would like to add or alter our answer
- invoke_hook("course_search_get_course_rotation_schedule_not_anticipated", array(&$rtn, $course_id));
-
- return $rtn;
-
- }
-
-
-
- function course_search_get_course_capacity($course_id, $term_id) {
-
- // Return from cache if we already have it.
- if (isset($GLOBALS['fp_cache_course_capacity'][$course_id])) {
- return $GLOBALS['fp_cache_course_capacity'][$course_id];
- }
-
-
- $cap = db_result(db_query("SELECT capacity FROM course_rotation_schedule
- WHERE course_id = ?
- AND term_id = ?", array($course_id, $term_id)));
-
- $cap = intval($cap);
- $GLOBALS['fp_cache_course_capacity'][$course_id] = $cap; // save to simple globals cache
-
- return $cap;
-
- }
-
-
- function course_search_get_course_rotation_schedule($course_id, $year = "", $limit = 20, $bool_include_next_five_years = FALSE)
- {
-
- // Has this already been saved to our globals cache? If so, just return that.
- if (isset($GLOBALS['cache_course_search_rotation_schedule'][$course_id][$year][$limit][intval($bool_include_next_five_years)])) {
- return $GLOBALS['cache_course_search_rotation_schedule'][$course_id][$year][$limit][intval($bool_include_next_five_years)];
- }
-
-
- $year = intval($year);
- $limit = intval($limit);
-
-
- // return an array containing the terms that this course
- // is going to be offered, if any.
- $rtn_array = array();
- $arr = array();
- $year_line = "";
- if ($year != "")
- { // if a year is entered, we will get the next few years, and the previous
- // one for good measure.
- $year_line = "and (`term_id` LIKE '$year%' or `term_id` LIKE '" . ($year+1) . "%') ";
- if ($bool_include_next_five_years)
- {
- $yearm1 = $year - 1;
- $year2 = $year + 1;
- $year3 = $year + 2;
- $year4 = $year + 3;
- $year5 = $year + 4;
- $year6 = $year + 5;
-
- $year_line = "and (`term_id` LIKE '$year%'
- or `term_id` LIKE '$yearm1%'
- or `term_id` LIKE '$year2%'
- or `term_id` LIKE '$year3%'
- or `term_id` LIKE '$year4%'
- or `term_id` LIKE '$year5%'
- or `term_id` LIKE '$year6%'
- ) ";
- }
-
- }
-
- $res = db_query("SELECT * FROM course_rotation_schedule
- WHERE `course_id`= ?
- $year_line
- ORDER BY term_id DESC
- LIMIT $limit", $course_id);
- while($cur = db_fetch_array($res))
- {
- $t = $cur["term_id"];
- // Get the term from the end.
- $ss = trim(substr($t,4,1));
- if ($ss == "m"){$ss = "1.5";}
-
- if (is_numeric($ss)) {
- $ss = $ss * 10;
- }
-
- $year = trim(substr($t,0,4));
-
- // We do all this so we can establish an order to the terms
- // by using a sort() command later.
- $arr[] = $year . "~" . $ss . "~" . $t;
- }
-
- sort($arr);
- // Now we want to get out JUST the terms...
- foreach($arr as $line)
- {
- $temp = explode("~",$line);
- $rtn_array[] = trim($temp[2]);
- }
-
-
- //////////////////////////////////////
- // Okay, now we invoke a hook, to see if any other modules
- // would like to add or alter our rotation schedule (notice $rtn_array is passed by reference)
- invoke_hook("course_search_get_course_rotation_schedule", array(&$rtn_array, $course_id, $year, $limit, $bool_include_next_five_years));
-
-
- // Save to globals cache to make it faster lookup
- $GLOBALS['cache_course_search_rotation_schedule'][$course_id][$year][$limit][intval($bool_include_next_five_years)] = $rtn_array;
-
-
- return $rtn_array;
- }
-
-
-
- function course_search_get_course_syllabus_details($course_id)
- {
-
- // This will return an array containing information
- // about a course's syllabus, if it exists.
- $rtn_array = FALSE;
-
- // Does this course have a syllabus?
- $query = "SELECT * FROM course_syllabi
- WHERE course_id = ? ";
-
- $res = db_query($query, $course_id);
- $cur = db_fetch_array($res);
-
-
-
- if (isset($cur["filename"]) && $cur['filename'] != "") {
- $rtn_array = array();
- $rtn_array["url"] = $GLOBALS["fp_system_settings"]["base_url"] . "/" . fp_url("course-search/get-syllabus", "id=" . $course_id, FALSE);
- $rtn_array["filename"] = $cur["filename"];
- $rtn_array["posted"] = $cur["posted"];
- }
-
-
- return $rtn_array;
-
- }
-
-
-
- function course_search_select_school_form() {
- $form = array();
-
- $options = schools_get_schools_for_fapi(TRUE, FALSE); // we don't need special permissions to view.
- $form['school_id'] = array(
- 'type' => 'select',
- 'label' => t('Please begin by selecting a school:'),
- 'options' => $options,
- 'value' => @$_REQUEST['school_id'],
- 'hide_please_select' => TRUE,
- 'required' => TRUE,
- );
-
- $form['submit_btn'] = array(
- 'type' => 'submit',
- 'value' => t("Continue"),
- );
-
- return $form;
- }
-
-
- function course_search_select_school_form_submit($form, $form_state) {
- $values = $form_state['values'];
- fp_goto('tools/course-search', 'school_id=' . $values['school_id']);
- }
-
-
- /**
- * Displays the search pulldown for the user to use to find courses.
- */
- function course_search_display_search() {
-
-
- fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
-
-
- // We are going to be setting up a render array for this screen, so other modules can alter it later.
- $render = array();
- $render["#id"] = "course_search_display_search";
-
- $school_id = 0;
-
- if (module_enabled("schools")) { // The schools module is enabled. We need to first ask what school we want to look at.
- if (!isset($_REQUEST['school_id'])) {
-
- $rtn .= fp_render_form('course_search_select_school_form');
- return $rtn;
- } // not isset school_id
- $school_id = intval($_REQUEST['school_id']);
- $render['current_school'] = array(
- 'value' => "<div class='current-school'>" . t("Current school: ") . "<strong>" . schools_get_school_name_for_id($school_id) . "</strong>
- - " . l(t("Change?"), "tools/course-search") . "</div>",
-
- 'weight' => 0,
- );
- }
-
- $clean_urls = variable_get("clean_urls", FALSE);
-
- $school_id = intval(@$_REQUEST['school_id']);
- $current_catalog_year = variable_get_for_school('current_catalog_year', 2006, $school_id);
- // catalog_year is always just whatever the current year is.
- $catalog_year = $current_catalog_year;
-
- $render['#school_id'] = $school_id;
- $render['#catalog_year'] = $catalog_year;
-
-
- if (user_has_permission("can_update_course_info_details")) {
- $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>";
- $render['edit_course_schedules'] = array(
- 'value' => $html,
- 'weight' => 100,
- );
- }
-
-
- // Catalog year has been selected.
-
- $html = "<div class='current-cat-year-line'>" . t("Current catalog year: <strong>@cat</strong></div>", array('@cat' => "$catalog_year-" . ($catalog_year +1)));
- $render['current_catalog_line'] = array(
- 'value' => $html,
- 'weight' => 200,
- );
-
- $html = "";
- $html .= "<br><br>
- <label>Please select an available subject from the list below.</label>
-
- <form action='" . fp_url("tools/course-search/courses") . "' method='GET' name='mainform' id='myform'>
- <input type='hidden' name='school_id' value='$school_id'> ";
-
-
- if (!$clean_urls) {
- // Hack for if clean URLs isn't enabled
- $html .= "<input type='hidden' name='q' value='tools/course-search/courses'>";
- }
-
-
- $html .= "
- <div id='element-inner-wrapper-course-search-subject' class='form-element element-type-select '>
- <select class='course-search-subject' name='subject_id'>
- ";
-
-
-
- // We want to make a pull-down list of all available subjects.
- // Keep in mind with this join-- we may have courses who have
- // a subject_id, for which we don't have that subject in the subjects
- // table.
-
-
- $query = "SELECT DISTINCT b.subject_id, a.title FROM courses b LEFT JOIN subjects a
- ON (a.subject_id = b.subject_id)
- WHERE exclude = 0
- AND catalog_year = ?
- AND a.school_id = b.school_id
- AND b.school_id = ?
- ";
-
- $subjects = array();
- $result = db_query($query, $catalog_year, $school_id);
- while ($cur = db_fetch_array($result))
- {
- //fpm($cur);
- $title = trim($cur["title"]);
- $subject_id = trim($cur["subject_id"]);
-
- if ($title == "") {
- $title = $subject_id;
- }
-
- $subjects[$subject_id] = $title;
- }
-
- asort($subjects);
-
- foreach ($subjects as $subject_id => $title) {
-
- $html .= "<option value='$subject_id'>$title ($subject_id)</option>";
-
-
-
- }
-
-
- $html .= " </select>
- </div>
-
- <div class='course-search-buttons buttons form-element element-type-submit'>
- <input type='submit' value='Select'>
- </div>
-
- </form>";
-
- $render['selection_form'] = array(
- 'value' => $html,
- 'weight' => 300,
- );
-
-
- $rtn = fp_render_content($render);
-
- return $rtn;
- }
-
-
Functions
Name | 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_capacity | |
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_menu_handle_replacement_pattern | Implements hook |
course_search_perm | |
course_search_select_school_form | |
course_search_select_school_form_submit | |
course_search_settings_form | The system settins form for course_search settings. |