function user_display_student_users

6.x user.student.inc user_display_student_users()
4.x user.module user_display_student_users()
5.x user.module user_display_student_users()

Similar to user_display_users, except only for student users.

File

modules/user/user.module, line 1248

Code

function user_display_student_users() {
  global $db, $screen;
  $de_catalog_year = $GLOBALS ["de_catalog_year"];

  $cc = 1;

  $rtn = "";

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

  // First, let's get our list of departments...
  $major_code_array = array();
  $d = 0;

  // Let's pull the needed variables out of our settings, so we know what
  // to query, because this is a non-FlightPath table.
  //$tsettings = $GLOBALS["fp_system_settings"]["extra_tables"]["human_resources:faculty_staff"];
  //$tf = (object) $tsettings["fields"];  //Convert to object, makes it easier to work with.  
  //$table_name = $tsettings["table_name"];    

  $res = db_query("SELECT DISTINCT major_code FROM students ORDER BY major_code ");
  while ($cur = db_fetch_array($res)) {
    if (trim($cur ["major_code"]) == "") 
     { // skip if blank
      continue;
    }

    $major_code_array [$d] = trim(ucwords($cur ["major_code"]));
    $d++;
  }


  $rtn .= "<h2 class='title' style='margin-bottom:0;'>" . t("Edit Student Users") . "</h2>";

  $rtn .= "<div class='add-new-student-user'>" . l(t("Create a new student user"), "admin/users/edit-student-user", "student_cwid=new&de_catalog_year=$de_catalog_year") . "</div>";


  $letter_ranges = array(
    "A" => array("A", "AZZZZ"),
    "B" => array("B", "BZZZZ"),
    "C" => array("C", "CZZZ"),
    "D" => array("D", "DZZZZ"),
    "E" => array("E", "EZZZZ"),
    "F" => array("F", "FZZZZ"),
    "G" => array("G", "GZZZZ"),
    "H" => array("H", "HZZZZ"),
    "I" => array("I", "IZZZ"),
    "J" => array("J", "JZZZ"),
    "K" => array("K", "KZZZ"),
    "L" => array("L", "LZZZ"),
    "M" => array("M", "MZZZ"),
    "N" => array("N", "NZZZ"),
    "O" => array("O", "OZZZ"),
    "P" => array("P", "PZZZ"),
    "Q-R" => array("Q", "RZZZZ"),
    "S" => array("S", "SZZZ"),
    "T" => array("T", "TZZZZ"),
    "U" => array("U", "UZZZ"),
    "V-Z" => array("V", "ZZZZ"),
  );


  $rtn .= "<div class='user-select-letter-bar' style='padding-top: 20px;'>
          ";
  foreach ($letter_ranges as $disp => $vals) {
    $rtn .= l($disp, "admin/users/students", "de_catalog_year=$de_catalog_year&ur=" . $vals [0] . "&lr=" . $vals [1], array("class" => "admin-courses-letter-link")) . " &nbsp; ";
  }

  // Figure out what type of students to display-- active, inactive, or both
  $set_disp = $_REQUEST ["set_disp"];
  if ($set_disp == "") {
    $set_disp = $_SESSION ["user_set_disp"];
    if ($set_disp == "") {
      $set_disp = "only_active";
    }
  }
  // Save into session for ease later
  $_SESSION ["user_set_disp"] = $set_disp;
  $in_active_query_line = "";

  $sel_only_active = $sel_only_inactive = $sel_both = "";
  if ($set_disp == "only_active") {
    $sel_only_active = "selected";
    $in_active_query_line = " AND is_active = '1' ";
  }
  if ($set_disp == "only_inactive") {
    $sel_only_inactive = "selected";
    $in_active_query_line = " AND is_active = '0' ";
  }
  if ($set_disp == "both") {
    $sel_both = "selected";
  }


  $rtn .= "</div>";
  $rtn .= "                             
                        <form class='filters' action='" . base_path() . "/admin/users/students' method='GET' >
                        <input type='hidden' name='performAction' value='editUsers'>
                         " . t("Search:") . " <input type='text' class='smallinput' name='search' value='{$_GET ["search"]}' size='15'>
                        <input type='submit' name='searchsubmit' class='smallinput' value=' -> '>
                       
                        &nbsp; &nbsp; " . t("or") . " &nbsp; &nbsp;
                       <select name='major_code' class='smallinput'>
                        <option value=''>" . t("Select a major code...") . "</option>
                        <option value=''>--------------------------</option>
                    <!--MAJORCODESEARCH-->
                       </select>
                       <input type='submit' name='major_code_submit' class='smallinput' value=' -> '>
                       
                       &nbsp; &nbsp; " . t("Set disp:") . "
                       <select name='set_disp'>
                        <option value='only_active' $sel_only_active>" . t("only active") . "</option>                        
                        <option value='only_inactive' $sel_only_inactive>" . t("only inactive") . "</option>
                        <option value='both' $sel_both>" . t("show both") . "</option>
                       </select>
                       <input type='submit' name='show_inactive_submit' class='smallinput' value=' -> '>                                              
                       
                       </form>
                       </div>
                       <br>
                      ";



  $displaying = "";



  $ur = trim($_GET ["ur"]);
  $lr = trim($_GET ["lr"]);

  if ($ur != "" || $lr != "") 
   {
    $_SESSION ["prev_user_search"] = "";
  }


  if ($ur == "") 
   { // meaning, no range was set.  Use A - C
    $ur = $_SESSION ["ur"];
    $lr = $_SESSION ["lr"];
    if ($ur == "") 
     { // if still blank, assign it..
      $ur = "A";
      $lr = "AZZZZ";
    }

  }
  $_SESSION ["ur"] = $ur;
  $_SESSION ["lr"] = $lr;

  $search = trim($_GET ["search"]);
  $major_code = trim($_GET ["major_code"]);

  if ($search != "" || $major_code != "") 
   {
    $_SESSION ["prev_user_search"] = "";
  }


  if ($_SESSION ["prev_user_search"] != "") 
   {
    $temp = explode("%%", $_SESSION ["prev_user_search"]);
    if ($temp [0] == "search") 
     {
      $search = $temp [1];
    }
    if ($temp [0] == "major_code") 
     {
      $_GET ["major_codesubmit"] = "1";
      $major_code = $temp [1];
    }
  }


  $_SESSION ["prev_user_search"] = "";


  // Let's pull the needed variables out of our settings, so we know what
  // to query, because this is a non-FlightPath table.
  //$tsettings = $GLOBALS["fp_system_settings"]["extra_tables"]["human_resources:faculty_staff"];
  //$tf = (object) $tsettings["fields"];  //Convert to object, makes it easier to work with.  
  //$table_name = $tsettings["table_name"];  

  // TODO:  Check if we are searching through "active" as well!


  if ($search != "" && !($_GET ["major_code_submit"])) 
   {
    // Something was searched for, and the major_code submit button was not pushed.
    $major_code = "";
    $temp = explode(" ", $search);
    $search1 = $temp [0];
    $search2 = trim($temp [1]);

    $_SESSION ["prev_user_search"] = "search%%$search";
    $displaying = $search;
    $second_part = "";
    if ($search2 != "") 
     {
      // Two search terms, probably a name...
      $result = db_query("SELECT * FROM users u, students s
          WHERE
          u.is_student = 1  
          AND u.cwid = s.cwid
          $in_active_query_line
          AND (l_name LIKE '%?%'
                AND f_name LIKE '%?%')
          ORDER BY l_name, f_name ", $search2, $search1);

    }
    else {

      // One search term....
      $result = db_query("SELECT * FROM users u, students s
          WHERE 
          u.is_student = 1
          AND u.cwid = s.cwid
          $in_active_query_line
          AND (u.cwid LIKE '%?%' 
                OR l_name LIKE '%?%'
                OR f_name LIKE '%?%')
          ORDER BY l_name, f_name ", $search1, $search1, $search1);
    }

  }
  else if ($major_code != "" && $_GET ["major_code_submit"]) {
    // User select a major_code.  Look for it...
    $search = "";
    $_SESSION ["prev_user_search"] = "major_code%%$major_code";
    $result = db_query("SELECT * FROM users a, students b
          WHERE a.cwid = b.cwid
          AND a.is_student = 1
          AND major_code = '?' 
          $in_active_query_line
          ORDER BY l_name, f_name ", $major_code);
    $displaying = $major_code;
  }
  else 
   { // No search, so look for the range...
    $result = db_query("SELECT * FROM users u, students s
                        WHERE
                          u.is_student = 1
                        AND u.cwid = s.cwid
                        $in_active_query_line
                        AND l_name BETWEEN '?' AND '?'
                        ORDER BY l_name, f_name ", $ur, $lr);
    $displaying = $ur;
  }
  $rtn .= "<div class='tenpt' style='padding-bottom: 5px;'><b>" . t("Displaying:") . "</b> $displaying</div>
      <table border='0' width='100%' cellpadding='3' cellspacing='0' class='user-list'>
    
        <tr>
          <th>CWID</th>
          <th>Name</th>
          <th></th>
          <th>Major code</th>
          <th>Active?</th>
          <th>&nbsp;</th>
        </tr>
    
    ";
  while ($cur = db_fetch_array($result)) {

    $user_id = $cur ["user_id"];
    $l_name = trim(ucwords(strtolower($cur ["l_name"])));
    $f_name = trim(ucwords(strtolower($cur ["f_name"])));
    $student_cwid = trim($cur ["cwid"]);
    $disp_major_code = trim($cur ["major_code"]);
    $is_active = ($cur ["is_active"] == "1") ? "Y" : "N";





    $ast = "";
    $reason = "";


    $fgcol = "black";


    $rtn .= "<tr class='is-active-$is_active'>
              
              <td valign='top' width='15%'>$student_cwid</td>
          <td valign='top' width='15%'>$f_name</td>
          <td valign='top' width='15%'>$l_name</td>
          <td valign='top'>$disp_major_code</td>
          <td valign='top'>$is_active</td>
          <td valign='top'>" . l(t("edit"), "admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "</td>
          
          
        </tr>";

  } // while
  $rtn .= "</table>";



  // Put in the major_code pulldown....
  $bC = "";
  for ($t = 0; $t < count($major_code_array); $t++) 
   {
    $dd = $major_code_array [$t];

    $sel = "";
    if ($dd == $major_code) 
     {
      $sel = "selected";
    }
    $bC .= "<option value='$dd' $sel>{$major_code_array [$t]}</option> \n";
  }
  $rtn = str_replace("<!--MAJORCODESEARCH-->", $bC, $rtn);


  return $rtn;

}