function student_search_display_majors_search

6.x student_search.module student_search_display_majors_search($limit = 20)
4.x student_search.module student_search_display_majors_search()
5.x student_search.module student_search_display_majors_search()

Display the majors search sub-tab, where we can select a major and see the students assigned to it.

File

modules/student_search/student_search.module, line 307

Code

function student_search_display_majors_search() {
  global $user;

  $rtn = "";


  $_SESSION ["student_search_last_tab"] = "majors-search";

  // Get the $major_code from the REQUEST, or from the user's saved settings.
  $major_code = trim(@$_REQUEST ["major_code"]);
  if ($major_code == "") {
    // Get from their settings
    $major_code = db_get_user_setting($user->id, "major_search");
  }
  else {
    // They did set something in the post. Save it to their settings.
    db_set_user_setting($user->id, "major_search", $major_code);
  }

  $url = fp_url("student-search/majors-search");

  $rtn .= "
            <form method='POST' action='" . $url . "'
              class='major-search-form'>            
            <label>" . t("Select an available major from the list below:") . "</label>
            <br><select name='major_code'>
              <option value=''>- " . t("Please Select") . " -</option>
              ";


  // Do we have any extra settings for this search?
  $current_catalog_year = variable_get("current_catalog_year", 2006);
  $cur_only = variable_get("student_search_major_search_cur_year", FALSE);
  $extra_line = "";

  $params = array();
  if ($cur_only == TRUE) {
    $extra_line = " AND catalog_year = :cur_cat_year ";
    $params [":cur_cat_year"] = $current_catalog_year;
  }



  $res = db_query("SELECT * FROM degrees
                   WHERE exclude = '0'                   
                   $extra_line
                   GROUP BY major_code
                   ORDER BY title
                   ", $params);
  while ($cur = db_fetch_object($res)) {
    $sel = ($major_code == $cur->major_code) ? "selected" : "";

    $degree_class_details = fp_get_degree_classification_details($cur->degree_class);


    // Exclude major codes if they are "degree options", meaning, the code has an
    // underscore in it.
    if (strpos($cur->major_code, "_")) {
      continue;
    }

    // If the title is risking being too long, let's truncate it
    $title = $cur->title;
    $max_chars = 50;
    if (strlen($title) > $max_chars) {
      $title = trim(substr($title, 0, $max_chars)) . "...";
    }

    $rtn .= "<option value='$cur->major_code' $sel>$cur->major_code : $title ({$degree_class_details ["title"]})</option>";
  }


  $rtn .= "
            </select>
            <input type='submit' value='" . t("Search") . "'>
            </form>";




  $rtn .= student_search_get_advanced_search_tips();

  // Update the query to search for exact major code.  
  $query = "SELECT u.user_id, f_name, l_name, u.cwid, major_code, rank_code, a.catalog_year
              FROM users u, students a, student_degrees b
              WHERE 
                 major_code = :major_code
                 AND u.cwid = a.cwid
                 AND u.cwid = b.student_id
                 AND u.is_student = 1
                 AND u.is_disabled = 0                 
              AND rank_code IN %RANKIN%
              %EXTRA_STUDENTSEARCH_CONDITIONS%
              ORDER BY %ORDERBY%
              ";



  $adv_array = student_search_query_advisees($query, array(":major_code" => $major_code));
  $s = (count($adv_array) == 1) ? "" : "s";
  $rtn .= student_search_render_advisees($adv_array, t("Major @major Results", array("@major" => $major_code)) . " &nbsp; ( " . count($adv_array) . " " . t("student$s") . " )");




  return $rtn;


}