function 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 332
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");

  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" => t("Current catalog year:") . " <b>$catalog_year-" . ($catalog_year + 1) . "</b>",
  );


  $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 .= "
            &nbsp; | &nbsp;
            <a href='javascript: toggleHideDiv(\"$rnd_div_id\");' class='nounderline'>
              <span id='SPAN$rnd_div_id'>
                " . t("more&raquo;") . "
                </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 .= "&nbsp;</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 = "&laquo;less";
      } else {
        d.style.display = "none";
        document.getElementById("SPAN" + rndDivID).innerHTML = "more&raquo;";
      }
      
    }
    
    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;
}