function course_search_display_courses
Search API
7.x course_search.module | course_search_display_courses() |
6.x course_search.module | course_search_display_courses() |
4.x course_search.module | course_search_display_courses() |
5.x course_search.module | course_search_display_courses() |
Show the user their select of courses.
File
- modules/
course_search/ course_search.module, line 304 - This module allows users to search for courses, descriptions, and, if supported, rotation schedules and sample syllabi.
Code
function course_search_display_courses() {
$rtn = "";
fp_add_css(fp_get_module_path("course_search") . "/css/course_search_style.css");
if (fp_screen_is_mobile()) {
fp_add_css(fp_get_module_path("course_search") . "/css/course_search_mobile_style.css");
}
$rtn .= "";
$rtn .= fp_render_curved_line(t("Course Search"));
$settings = fp_get_system_settings();
$current_catalog_year = $settings ["current_catalog_year"];
// catalog_year is always just whatever the current year is.
$catalog_year = $current_catalog_year;
$subject_id = $_REQUEST ["subject_id"];
// 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 ='?' ", $subject_id);
$cur = db_fetch_array($res);
$title = $cur ["title"];
if ($title == "") {
$title = $subject_id;
}
/*
$query = "SELECT DISTINCT a.* from subjects a,
courses b
WHERE a.subject_id = '?'
AND a.subject_id = b.subject_id
AND catalog_year = '?'
AND exclude = 0
ORDER BY title ";
$result = db_query($query, $subject_id, $catalog_year);
$cur = db_fetch_array($result);
$title = trim($cur["title"]);
*/
$rtn .= t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year + 1) . "</b>
";
$important_notice = "
<div class='tenpt hypo' style='padding: 5px;'>
<b>Important Notice:</b> <ul style='margin-top: 5px;'>
<li>Course descriptions are intended for unofficial use only. Consult your catalog for the official listing.</li>
<li>Anticipated course availability reflects current plans but actual offerings may change because of factors
unknown at planning time. Consult the schedule of classes for final offerings.</li>
<li>Sample syllabi are provided for planning purposes only. The syllabus used by an instructor may vary from this sample.</li>
<li>Please ask your advisor if you have any questions about a course.</li>
</ul>
</div>
";
if (fp_screen_is_mobile()) {
// TODO: implement the fieldset thingy.
//$pC .= $screen->draw_c_fieldset($important_notice, "View important notice", true);
}
else {
$rtn .= $important_notice;
}
$rtn .= "
<div>
<div style='margin: 10px 0 20px 10px; border-bottom: 2px solid black;'>
<span style='font-size: 14pt; font-weight:bold;'>$title</span>
" . l("[change]", "tools/course-search", "", array("class" => "nounderline")) . "
</div>
";
// Draw the term selector.
$only_term = $_REQUEST ["only_term"];
$rtn .= "<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'>
View courses offered:
<select name='only_term' onChange='document.getElementById(\"term_form\").submit();'>
<option value=''>Any term</option>
";
//$term_array = get_term_id_suffixes();
$term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));
for ($t = $catalog_year; $t <= $catalog_year + 4; $t++)
{
$rtn .= "<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";
}
$rtn .= "<option value='$the_term_id' $sel>$term_desc</option> \n";
}
}
$rtn .= "
</select>
</form>";
if ($only_term != "") {
$temp_course = new Course();
$temp_course->term_id = $only_term;
$term_desc = $temp_course->get_term_description(false);
$rtn .= "<div style='font-weight: bold; padding-bottom: 20px;'>
The following courses are currently scheduled to be offered during " . $term_desc . ".
</div>";
}
$term_structures = get_term_structures();
$grad_notice_flag = false;
$temp_course = new Course();
// removed course_num < 500 and
$result = db_query("SELECT * FROM courses
WHERE `catalog_year`='?' AND
`subject_id`='?' AND
`exclude`='0' ORDER BY `course_num` ", $catalog_year, $subject_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"];
$bool_hide = FALSE;
$title = ucwords(strtolower(trim($cur ["title"])));
// Fix formatting problems introduced by the ucwords command...
$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'>
<img src='" . fp_theme_location() . "/images/document_icon.gif' border='0' height='12'>
" . 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);
// Only grab next 2 years.
$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:") . "</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 = rand(1, 999999);
$schedule_text .= "
|
<a href='javascript: toggleHideDiv(\"$rnd_div_id\");' class='nounderline'>
<span id='SPAN$rnd_div_id'>
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("course_search_avail_term_id_suffix_order"));
// Get our table headers
$avail_headers = variable_get("course_search_avail_term_headers");
$avail_mobile_headers = variable_get("course_search_avail_term_mobile_headers");
$th = explode(",", $avail_headers);
$twidth = "90%";
$mleft = "20px;";
if (fp_screen_is_mobile()) {
$th = explode(",", $avail_mobile_headers);
$twidth = "100%";
$mleft = "0";
}
$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? 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]") {
//fpm("here for $x");
$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"]);
$max_hours = trim($cur ["max_hours"]);
if ($min_hours == $max_hours)
{
$hours = $min_hours;
}
else {
$hours = "$min_hours to $max_hours";
}
$repeat = "";
if (trim($cur ["repeat_hours"]) > $min_hours)
{
$repeat = "<div class='course-search-repeat'>" . t("May be repeated for up to @repeat hours of credit.", array("@repeat" => $cur ["repeat_hours"])) . "</div>";
}
// Draw it on screen...
if ($bool_hide != true) {
if ($grad_notice_flag == false && $course_num > 4999)
{
$grad_notice_flag = true;
$rtn .= "<div style='font-size: 10pt; font-weight: bold;
border-bottom: 1px solid black;
margin-left: 10px;
margin-bottom: 20px;
margin-top: 50px;'>
" . t("The following courses are for Graduate Students only.") . "
</div>";
}
$details = $schedule_text . $syllabus_text;
$hyp1 = " - ";
$on_click = "";
if (fp_screen_is_mobile()) {
$on_click = "onClick='toggleCourseExtra(this);'";
$hyp1 = "";
}
$rtn .= "<div class='course-search-course-block'>
<div class='course-search-course-title-row'
$on_click>
<span class='course-search-course-name'>$n_subject_id $n_course_num</span>
$hyp1
<span class='course-search-course-title'>$title</span> - $hours " . t("hrs.") . "$repeat </div>
<div class='course-search-course-extra'>
<div class='course-search-course-description'>$description</div>
<div class='course-search-course-details'>$details</div>
";
if (user_has_permission("can_update_course_info_details") && !fp_screen_is_mobile()) {
$rtn .= "<div class='course-search-admin-options'>
" . t("Administrative options:") . "
" . 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") . "
</div>";
}
$rtn .= "</div>";
$rtn .= "</div>";
}
}
}
watchdog("course_search", "User viewed courses in subject: @subject", array("@subject" => $subject_id), WATCHDOG_DEBUG);
//$pC .= $screen->get_java_script_code();
$rtn .= '
<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>
';
return $rtn;
}