user_display_users

5.x user.module user_display_users()
4.x user.module user_display_users()

Display our list of faculty/staff users in the system.

File

modules/user/user.module, line 1572

Code

function user_display_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...
  $dept_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 department FROM faculty ORDER BY department ");
  while ($cur = db_fetch_array($res)) {
    if (trim($cur["department"]) == "") { // skip if blank
      continue;
    }

    $dept_array[$d] = trim(ucwords(strtolower($cur["department"])));
    $d++;
  }


  $rtn .= "<h2 class='title' style='margin-bottom: 0;'>" . t("Edit Faculty / Staff Users") . "</h2>";
  $rtn .= "<div class='add-new-user'>" . l(t("Create a new faculty/staff user"), "admin/users/edit-user", "faculty_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/faculty", "de_catalog_year=$de_catalog_year&ur=" . $vals[0] . "&lr=" . $vals[1], array("class" => "admin-courses-letter-link")) . " &nbsp; ";
  }


  $rtn .= "</div>";
  $rtn .= "                             
                        <form class='filters' action='" . base_path() . "/admin/users/faculty' 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='department' class='smallinput'>
                        <option value=''>" . t("Select a department:") . "</option>
                        <option value=''>--------------------------</option>
                    <!--DEPTSEARCH-->
                       </select>
                       <input type='submit' name='deptsubmit' class='smallinput' value=' -> '>
                       
                       &nbsp;&nbsp;" . t("or") . "&nbsp;&nbsp;
                       <select name='role' class='smallinput'>
                       <option value=''>" . t("Select a role:") . "</option>
                       <option value=''>--------------------------</option>
                       ";
  // Show list of roles
  $res = db_query("SELECT * FROM roles ORDER BY rid");
  while ($cur = db_fetch_array($res)) {
    $key = $cur["rid"];
    $value = $cur["name"];
    $dispval = $value;

    // Skip anonymous and authenticated
    if ($key == 1 || $key == 2) {
      continue;
    }

    if (strlen($dispval) > 25) {
      $dispval = trim(substr($dispval, 0, 22)) . "...";
    }

    $sel = "";
    if ($key == $_GET["role"] * 1) {
      $sel = "selected";
    }

    $rtn .= "<option value='$key' $sel>$dispval</option>";
  }
  $rtn .= "</select>
                       
                       <input type='submit' name='rolesubmit' 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"]);
  $dept = trim($_GET["department"]);
  $role = trim($_GET["role"]);

  if ($search != "" || $dept != "") {
    $_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] == "dept") {
      $_GET["deptsubmit"] = "1";
      $dept = $temp[1];
    }
    if ($temp[0] == "role") {
      $_GET["rolesubmit"] = "1";
      $role = $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"];  


  if ($search != "" && !($_GET["deptsubmit"]) && !($_GET["rolesubmit"])) {
    // Something was searched for, and the dept submit button was not pushed, nor role submit
    $dept = "";
    $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, faculty f
          WHERE
          u.is_faculty = 1  
          AND u.cwid = f.cwid
          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, faculty f
          WHERE 
          u.is_faculty = 1
          AND u.cwid = f.cwid
          AND (u.cwid LIKE '%?%' 
                OR l_name LIKE '%?%'
                OR f_name LIKE '%?%')
          ORDER BY l_name, f_name ", $search1, $search1, $search1);
    }

  }
  else if ($dept != "" && $_GET["deptsubmit"]) {
    // User select a department.  Look for it...
    $search = "";
    $_SESSION["prev_user_search"] = "dept%%$dept";
    $result = db_query("SELECT * FROM users a, faculty b
          WHERE a.cwid = b.cwid
          AND a.is_faculty = 1
          AND department = '?' 
          ORDER BY l_name, f_name ", $dept);
    $displaying = $dept;
  }
  else if ($role != "" && $_GET["rolesubmit"]) {
    // User select a role.  Look for it...
    $search = "";
    $_SESSION["prev_user_search"] = "role%%$role";

    $result = db_query("SELECT * FROM users a, faculty b, user_roles c
          WHERE a.cwid = b.cwid
          AND a.is_faculty = 1
          AND a.user_id = c.user_id
          AND c.rid = '?'
          ORDER BY l_name, f_name ", $role);

    $displaying = user_get_role_name($role);
  }
  else { // No search, so look for the range...
    $result = db_query("SELECT * FROM users u, faculty f
                        WHERE
                          u.is_faculty = 1
                        AND u.cwid = f.cwid
                        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>Department</th>
          <th>Roles</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"])));
    $faculty_cwid = trim($cur["cwid"]);
    $dept_name = trim(ucwords(strtolower($cur["department"])));



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


    $fgcol = "black";

    $roles = "";
    $roles_classes = "no-roles";
    $temp = system_get_roles_for_user($user_id);

    if (count($temp) > 1) {
      $roles_classes = "";
    }

    foreach ($temp as $rid => $t) {
      if ($rid > 2) {
        // rid 1 and 2 are anonymous and authenticated-- no need to show them.
        $roles .= "<div class='list-role'>$t</div>";
        $roles_classes .= " role-" . fp_get_machine_readable($t);
      }
    }



    //      $pC .= "<a href='edit_users.php?action=load&course_id=$course_id'> user: $f_name $mid_name $l_name </a><br>";

    $rtn .= "<tr class='$roles_classes'>
              
              <td valign='top' width='15%'>$faculty_cwid</td>
          <td valign='top' width='15%'>$f_name</td>
          <td valign='top' width='15%'>$l_name</td>
          <td valign='top'>$dept_name</td>
          <td valign='top'>$roles</td>
          <td valign='top'>" . l(t("edit"), "admin/users/edit-user", "faculty_cwid=$faculty_cwid&de_catalog_year=$de_catalog_year") . "</td>
          
          
        </tr>";

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



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

    $sel = "";
    if ($dd == $dept) {
      $sel = "selected";
    }

    $dispval = $dd;
    if (strlen($dispval) > 40) {
      $dispval = trim(substr($dispval, 0, 37)) . "...";
    }


    $bC .= "<option value='$dd' $sel>$dispval</option> \n";
  }
  $rtn = str_replace("<!--DEPTSEARCH-->", $bC, $rtn);



  return $rtn;

}