function course_search_display_search
Search API
6.x course_search.module | course_search_display_search() |
4.x course_search.module | course_search_display_search() |
5.x course_search.module | course_search_display_search() |
Displays the search pulldown for the user to use to find courses.
File
- modules/
course_search/ course_search.module, line 973 - This module allows users to search for courses, descriptions, and, if supported, rotation schedules and sample syllabi.
Code
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;
}