function student_search_display_majors_search

7.x student_search.module student_search_display_majors_search($limit = 20)
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 285

Code

function student_search_display_majors_search() {
  global $user;

  $rtn = "";

  fp_add_css(fp_get_module_path("student_search") . "/css/student_search.css");


  $_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);
  }


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


  // Do we have any extra settings for this search?
  $current_catalog_year = mysql_real_escape_string(variable_get("current_catalog_year", 2006));
  $cur_only = variable_get("student_search_major_search_cur_year", FALSE);
  $extra_line = "";
  if ($cur_only == TRUE) {
    $extra_line = " AND catalog_year = '$current_catalog_year' ";
  }



  $res = db_query("SELECT * FROM degrees
                   WHERE exclude = '0'
                   AND major_code NOT LIKE '%|%'
                   $extra_line
                   GROUP BY major_code
                   ");
  while ($cur = db_fetch_object($res)) {
    $sel = ($major_code == $cur->major_code) ? "selected" : "";

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


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




  $rtn .= student_search_get_advanced_search_tips();

  $query = "SELECT u.user_id, f_name, l_name, u.cwid, major_code, rank_code, a.catalog_year
              FROM users u, students a
              WHERE 
                 substring_index(major_code, '|', 1) = '$major_code'
                 AND u.cwid = a.cwid
                 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);
  $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;


}