function user_display_student_users

7.x user.student.inc 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.student.inc, line 14
Keep track of functions dealing specifically with student user management

Code

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

  if (!$de_catalog_year) {
    $de_catalog_year = @intval($_REQUEST ['de_catalog_year']);
  }

  if ($db == NULL) {
    $db = get_global_database_handler();
  }

  $cc = 1;

  // Do this using $render array, so it can be altered
  // by hook_content_alter
  $render = array();
  $render ['#id'] = 'user_display_users';


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


  if (@$_REQUEST ['clear_filters'] == 'true') {
    // Meaning, a letter was specified, so let's reset the filter values.
    unset($_SESSION ['users_filter_name']);

    foreach ($_SESSION as $key => $val) {
      if ($key == 'users_filter_active') {
        continue; // we preserve the "active" filter setting
      }

      if (strstr($key, "users_filter_")) {
        unset($_SESSION [$key]);
      }
    }
  }




  $html = "";

  $html .= "<div class='add-new-student-user'>" . l("<i class='fa fa-plus'></i> " . 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"),
  );





  $ur = fp_trim(@$_GET ["ur"]);
  $lr = fp_trim(@$_GET ["lr"]);

  if ($ur == "" && !isset($_SESSION ['users_filter_submit'])) {
    //if ($ur == "") {
    $ur = "A";
    $lr = "AZZZZZ"; // first time through.
  }

  // If we are going by filters, show that as option and select it.
  if (isset($_SESSION ['users_filter_submit'])) {
    $letter_ranges [t(" - Filter -")] = array("filter", "filter");
  }


  $html .= "<div class='user-select-letter-bar' style='padding-top: 20px;'>
          ";
  foreach ($letter_ranges as $disp => $vals) {
    $selected_class = "";
    if ($ur == $vals [0]) {
      $selected_class = "selected";
    }

    if ($vals [0] == 'filter') {
      $selected_class = "selected";
      $html .= "<a href='javascript:void(0);' class='admin-courses-letter-link filter-indicator $selected_class'>$disp</a> &nbsp; ";
      continue;
    }


    $html .= l($disp, "admin/users/students", "de_catalog_year=$de_catalog_year&clear_filters=true&ur=" . $vals [0] . "&lr=" . $vals [1], array("class" => "admin-courses-letter-link $selected_class")) . " &nbsp; ";

  }


  $html .= "</div>";

  $render ['upper_links'] = array(
    'value' => $html,
  );






  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;




  $mark = "";
  $mark .= "<div class='degrees-filter'>";
  $mark .= fp_render_form("user_student_list_filter_form");
  $mark .= "</div>";


  $render ['users_filter'] = array(
    'value' => $mark,
  );




  $extra_where_conditions = "";
  $params = array();
  $params [":ur"] = $ur;
  $params [":lr"] = $lr;


  if (isset($_SESSION ['users_filter_submit'])) {
    // We clicked to filter, so the letter range should be ignored.
    $params [":ur"] = "A";
    $params [":lr"] = "ZZZZZZZZZZZZ";
  }


  $filter_name = @trim($_SESSION ['users_filter_name']);
  $filter_school = @intval($_SESSION ['users_filter_school']);
  $filter_major = @trim($_SESSION ['users_filter_major']);
  $filter_active = @trim($_SESSION ['users_filter_active']);




  if ($filter_name) {
    $extra_where_conditions .= " AND (l_name LIKE :search1 OR f_name LIKE :search2 OR u.cwid LIKE :search3) ";
    $params [":search1"] = "%$filter_name%";
    $params [":search2"] = "%$filter_name%";
    $params [":search3"] = "%$filter_name%";
    // If we are searching by name, then we do not care about what letters we selected.
    $params [":ur"] = "A";
    $params [":lr"] = "ZZZZZZZZZZZZZZ";
  }


  $extra_where_conditions .= " AND u.school_id = :school_id ";
  $params [":school_id"] = $filter_school;


  if ($filter_major != '') {
    $extra_where_conditions .= " AND major_code = :major_code ";
    $params [":major_code"] = $filter_major;
  }


  if ($filter_active) {
    $vals = array();
    if ($filter_active == 'active') {
      $vals [] = 1;
    }
    if ($filter_active == 'inactive') {
      $vals [] = 0;
    }
    if ($filter_active == 'all') {
      $vals = array(1, 0);
    }
    $extra_where_conditions .= " AND is_active IN (" . join(",", $vals) . ") ";
  }

  watchdog("user", "Viewed admin student user list. Range: $ur - $lr. Name: $filter_name. Major: $filter_major. Active: $filter_active. School: $filter_school", array(), WATCHDOG_DEBUG);


  $html = "";
  $html .= "
      <table border='0' width='100%' cellpadding='3' cellspacing='0' class='user-list'>
    
        <tr>
          <th width='5%'>Actions</th>
          <th>CWID</th>
          <th>Name</th>
          <th></th>
          <th>Major code(s)</th>
          <th>Active?</th>
          <th>Last Login</th>
          
        </tr>  
    ";

  $render ['users_table_top'] = array(
    'value' => $html,
  );


  $limit = 30;
  $result = pager_query("SELECT * FROM (users u, students s)
                        LEFT JOIN student_degrees d ON (s.cwid = d.student_id)
                      WHERE 
                        u.is_student = 1
                        AND u.cwid = s.cwid
                        AND l_name BETWEEN :ur AND :lr
                        $extra_where_conditions                        
                        GROUP BY u.cwid
                        ORDER BY l_name, f_name
                            ", $params, $limit, 0, NULL, "SELECT COUNT(DISTINCT(u.cwid))");
  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"]);
    $disp_major_code = join(", ", $db->get_student_majors_from_db($student_cwid, FALSE, FALSE));

    $is_active = ($cur ["is_active"] == "1") ? "Y" : "N";

    $last_login = intval($cur ['last_login']);
    if ($last_login == 0) {
      $last_login = t("Never");
    }
    else {
      $last_login = format_date(convert_time($last_login), 'short');
    }





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


    $fgcol = "black";


    $render ['user_row_' . $student_cwid] = array(
      'value' => "<tr class='is-active-$is_active'>          
                    <td valign='top'>" . l("<i class='fa fa-pencil' title='Edit'></i>", "admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "</td>              
                    <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'>$last_login</td>                    
                  </tr>",

      'data' => array(
        'is_student' => 1,
        'cwid' => $student_cwid,
        'db_row' => $cur,
      ),

    );


  } // while


  $render ['users_table_bottom'] = array(
    'value' => "</table>",
  );


  $render ['users_pager'] = array(
    'value' => theme_pager(),
  );


  $rtn = fp_render_content($render);


  return $rtn;

}