$strsearch = get_string("search");
$strshowallusers = get_string("showallusers");
- print_header("$site->shortname: $stredituser", $site->fullname,
- "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $stredituser");
+ if ($firstinitial or $lastinitial or $search or $page) {
+ print_header("$site->shortname: $stredituser", $site->fullname,
+ "<a href=\"index.php\">$stradministration</a> -> ".
+ "<a href=\"users.php\">$strusers</a> -> ".
+ "<a href=\"user.php\">$stredituser</a>");
+ } else {
+ print_header("$site->shortname: $stredituser", $site->fullname,
+ "<a href=\"index.php\">$stradministration</a> -> ".
+ "<a href=\"users.php\">$strusers</a> -> $stredituser");
+ }
if ($confirmuser) {
if (!$user = get_record("user", "id", "$confirmuser")) {
$sort = "firstname";
}
- if (!$users = get_course_students(0, $sort, $dir, $page*$perpage, $perpage, $firstinitial, $lastinitial, NULL, $search)) {
- if (!$users = get_course_students(0, $sort, $dir, $page*$perpage, $perpage, $firstinitial, $lastinitial)) {
- error("No users found!");
- } else {
- notify(get_string("nousersmatching", "", $search));
- }
- $search = "";
- }
-
+ $users = get_users_listing($sort, $dir, $page*$perpage, $perpage, $search, $firstinitial, $lastinitial);
$usercount = get_users(false);
+ $usersearchcount = get_users(false, $search, true, "", "", $firstinitial, $lastinitial);
- if ($firstinitial or $lastinitial) {
- $course->id = 0; // don't look in user_students table, but just user table
- $usercount = count_course_students($course, "", $firstinitial, $lastinitial);
- }
-
- if ($search) {
- $usersearchcount = get_users(false, $search);
+ if ($search or $firstinitial or $lastinitial) {
print_heading("$usersearchcount / $usercount ".get_string("users"));
$usercount = $usersearchcount;
} else {
print_heading("$usercount ".get_string("users"));
}
- if ($usercount > $perpage) {
- $alphabet = explode(',', get_string('alphabet'));
- $strall = get_string("all");
+ $alphabet = explode(',', get_string('alphabet'));
+ $strall = get_string("all");
/// Bar of first initials
- echo "<center><p align=\"center\">";
- echo get_string("firstname")." : ";
- if ($firstinitial) {
- echo " <a href=\"user.php?sort=firstname&dir=ASC&".
- "perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
+ echo "<center><p align=\"center\">";
+ echo get_string("firstname")." : ";
+ if ($firstinitial) {
+ echo " <a href=\"user.php?sort=firstname&dir=ASC&".
+ "perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
+ } else {
+ echo " <b>$strall</b> ";
+ }
+ foreach ($alphabet as $letter) {
+ if ($letter == $firstinitial) {
+ echo " <b>$letter</b> ";
} else {
- echo " <b>$strall</b> ";
- }
- foreach ($alphabet as $letter) {
- if ($letter == $firstinitial) {
- echo " <b>$letter</b> ";
- } else {
- echo " <a href=\"user.php?sort=firstname&dir=ASC&".
- "perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
- }
+ echo " <a href=\"user.php?sort=firstname&dir=ASC&".
+ "perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
}
- echo "<br />";
+ }
+ echo "<br />";
/// Bar of last initials
- echo get_string("lastname")." : ";
- if ($lastinitial) {
- echo " <a href=\"user.php?sort=lastname&dir=ASC&".
- "perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
+ echo get_string("lastname")." : ";
+ if ($lastinitial) {
+ echo " <a href=\"user.php?sort=lastname&dir=ASC&".
+ "perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
+ } else {
+ echo " <b>$strall</b> ";
+ }
+ foreach ($alphabet as $letter) {
+ if ($letter == $lastinitial) {
+ echo " <b>$letter</b> ";
} else {
- echo " <b>$strall</b> ";
- }
- foreach ($alphabet as $letter) {
- if ($letter == $lastinitial) {
- echo " <b>$letter</b> ";
- } else {
- echo " <a href=\"user.php?sort=lastname&dir=ASC&".
- "perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
- }
+ echo " <a href=\"user.php?sort=lastname&dir=ASC&".
+ "perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
}
- echo "</p>";
- echo "</center>";
-
- print_paging_bar($usercount, $page, $perpage,
- "user.php?sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
}
+ echo "</p>";
+ echo "</center>";
+
+ print_paging_bar($usercount, $page, $perpage,
+ "user.php?sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&search=$search&");
flush();
- $countries = get_list_of_countries();
- foreach ($users as $key => $user) {
- if (!empty($user->country)) {
- $users[$key]->country = $countries[$user->country];
+ if (!$users) {
+ $match = array();
+ if ($search) {
+ $match[] = $search;
}
- }
- if ($sort == "country") { // Need to resort by full country name, not code
- foreach ($users as $user) {
- $susers[$user->id] = $user->country;
+ if ($firstinitial) {
+ $match[] = get_string("firstname").": $firstinitial"."___";
}
- asort($susers);
- foreach ($susers as $key => $value) {
- $nusers[] = $users[$key];
+ if ($lastinitial) {
+ $match[] = get_string("lastname").": $lastinitial"."___";
}
- $users = $nusers;
- }
+ $matchstring = implode(", ", $match);
+ print_heading(get_string("nousersmatching", "", $matchstring));
- $table->head = array ("$firstname / $lastname", $email, $city, $country, $lastaccess, "", "", "");
- $table->align = array ("left", "left", "left", "left", "left", "center", "center", "center");
- $table->width = "95%";
- foreach ($users as $user) {
- if ($user->id == $USER->id or $user->username == "changeme") {
- $deletebutton = "";
- } else {
- $deletebutton = "<a href=\"user.php?delete=$user->id\">$strdelete</a>";
+ } else {
+
+ $countries = get_list_of_countries();
+
+ foreach ($users as $key => $user) {
+ if (!empty($user->country)) {
+ $users[$key]->country = $countries[$user->country];
+ }
}
- if ($user->lastaccess) {
- $strlastaccess = format_time(time() - $user->lastaccess);
- } else {
- $strlastaccess = get_string("never");
+ if ($sort == "country") { // Need to resort by full country name, not code
+ foreach ($users as $user) {
+ $susers[$user->id] = $user->country;
+ }
+ asort($susers);
+ foreach ($susers as $key => $value) {
+ $nusers[] = $users[$key];
+ }
+ $users = $nusers;
}
- if ($user->confirmed == 0) {
- $confirmbutton = "<a href=\"user.php?confirmuser=$user->id\">" . get_string("confirm") . "</a>";
- } else {
- $confirmbutton = "";
+
+ $table->head = array ("$firstname / $lastname", $email, $city, $country, $lastaccess, "", "", "");
+ $table->align = array ("left", "left", "left", "left", "left", "center", "center", "center");
+ $table->width = "95%";
+ foreach ($users as $user) {
+ if ($user->id == $USER->id or $user->username == "changeme") {
+ $deletebutton = "";
+ } else {
+ $deletebutton = "<a href=\"user.php?delete=$user->id\">$strdelete</a>";
+ }
+ if ($user->lastaccess) {
+ $strlastaccess = format_time(time() - $user->lastaccess);
+ } else {
+ $strlastaccess = get_string("never");
+ }
+ if ($user->confirmed == 0) {
+ $confirmbutton = "<a href=\"user.php?confirmuser=$user->id\">" . get_string("confirm") . "</a>";
+ } else {
+ $confirmbutton = "";
+ }
+ $fullname = fullname($user, true);
+ $table->data[] = array ("<a href=\"../user/view.php?id=$user->id&course=$site->id\">$fullname</a>",
+ "$user->email",
+ "$user->city",
+ "$user->country",
+ $strlastaccess,
+ "<a href=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</a>",
+ $deletebutton,
+ $confirmbutton);
}
- $fullname = fullname($user, true);
- $table->data[] = array ("<a href=\"../user/view.php?id=$user->id&course=$site->id\">$fullname</a>",
- "$user->email",
- "$user->city",
- "$user->country",
- $strlastaccess,
- "<a href=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</a>",
- $deletebutton,
- $confirmbutton);
- }
- echo "<table align=center cellpadding=10><tr><td>";
- echo "<form action=user.php method=post>";
- echo "<input type=text name=search value=\"$search\" size=20>";
- echo "<input type=submit value=\"$strsearch\">";
- if ($search) {
- echo "<input type=\"button\" onclick=\"document.location='user.php';\" value=\"$strshowallusers\">";
- }
- echo "</form>";
- echo "</td></tr></table>";
+ echo "<table align=center cellpadding=10><tr><td>";
+ echo "<form action=user.php method=post>";
+ echo "<input type=text name=search value=\"$search\" size=20>";
+ echo "<input type=submit value=\"$strsearch\">";
+ if ($search) {
+ echo "<input type=\"button\" onclick=\"document.location='user.php';\" value=\"$strshowallusers\">";
+ }
+ echo "</form>";
+ echo "</td></tr></table>";
- print_table($table);
+ print_table($table);
- print_paging_bar($usercount, $page, $perpage,
- "user.php?sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
+ print_paging_bar($usercount, $page, $perpage,
+ "user.php?sort=$sort&dir=$dir&perpage=$perpage".
+ "&firstinitial=$firstinitial&lastinitial=$lastinitial&search=$search&");
+
+ }
if ($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){
print_heading("<a href=\"user.php?newuser=true\">".get_string("addnewuser")."</a>");
}
$groupmembers = '';
- $userstudents = '';
- $userstudentcolumns = '';
- $select = " u.deleted = '0' ";
+ $select = "s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0' ";
if ($search) {
$search = " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%') ";
$select .= " AND u.id = gm.userid AND gm.groupid = '$group'";
}
- if ($courseid != 0) {
- $userstudents = ", {$CFG->prefix}user_students s ";
- $select .= " AND s.course = '$courseid' AND s.userid = u.id";
- $userstudentcolumns = ", s.timeaccess as lastaccess";
- } else {
- $userstudentcolumns = ", u.lastaccess as lastaccess";
- }
-
-
if ($sort) {
$sort = " ORDER BY $sort ";
}
return get_records_sql("SELECT u.id, u.confirmed, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
u.email, u.city, u.country, u.picture, u.department, u.institution,
- u.emailstop, u.lang, u.timezone $userstudentcolumns
- FROM {$CFG->prefix}user u $userstudents $groupmembers
+ u.emailstop, u.lang, u.timezone, s.timeaccess as lastaccess
+ FROM {$CFG->prefix}user u,
+ {$CFG->prefix}user_students s
+ $groupmembers
WHERE $select $search $sort $dir $limit");
}
switch ($CFG->dbtype) {
case "mysql":
+ $fullname = " CONCAT(firstname,\" \",lastname) ";
$LIKE = "LIKE";
break;
default:
+ $fullname = " firstname||\' \'||lastname ";
$LIKE = "ILIKE";
}
-
$groupmembers = "";
- $userstudents = "";
- $select = " u.deleted = '0'";
+ $select = "s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'";
if ($search) {
- $select .= " AND u.firstname $LIKE '%$search%' OR u.lastname $LIKE '%$search%'";
+ $search = " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%') ";
}
if ($firstinitial) {
$select .= " AND u.firstname $LIKE '$firstinitial%'";
$select .= " AND u.id = gm.userid AND gm.groupid = '$group'";
}
- if ($course->id != 0) {
- $userstudents = ", {$CFG->prefix}user_students s ";
- $select .= " AND s.course = '$course->id' AND s.userid = u.id";
- }
-
return count_records_sql("SELECT COUNT(*)
- FROM {$CFG->prefix}user u $userstudents $groupmembers
+ FROM {$CFG->prefix}user u,
+ {$CFG->prefix}user_students s $groupmembers
WHERE $select");
}
* @param array(int) $exceptions a list of IDs to ignore, eg 2,4,5,8,9,10
* @param string $sort a SQL snippet for the sorting criteria to use
*/
-function get_users($get=true, $search="", $confirmed=false, $exceptions="", $sort="firstname ASC") {
+function get_users($get=true, $search="", $confirmed=false, $exceptions="", $sort="firstname ASC",
+ $firstinitial="", $lastinitial="") {
global $CFG;
$LIKE = "ILIKE";
}
+ $select = "username <> 'guest' AND deleted = 0";
+
if ($search) {
- $search = " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%') ";
+ $select .= " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%') ";
}
if ($confirmed) {
- $confirmed = " AND confirmed = '1' ";
+ $select .= " AND confirmed = '1' ";
}
if ($exceptions) {
- $exceptions = " AND id NOT IN ($exceptions) ";
+ $select .= " AND id NOT IN ($exceptions) ";
}
+ if ($firstinitial) {
+ $select .= " AND firstname $LIKE '$firstinitial%'";
+ }
+ if ($lastinitial) {
+ $select .= " AND lastname $LIKE '$lastinitial%'";
+ }
+
if ($sort and $get) {
$sort = " ORDER BY $sort ";
} else {
}
if ($get) {
- return get_records_select("user", "username <> 'guest' AND deleted = 0 $search $confirmed $exceptions $sort");
+ return get_records_select("user", "$select $sort");
} else {
- return count_records_select("user", "username <> 'guest' AND deleted = 0 $search $confirmed $exceptions $sort");
+ return count_records_select("user", "$select $sort");
}
}
*
* @param type description
*/
-function get_users_listing($sort, $dir="ASC", $page=1, $recordsperpage=20, $search="") {
+function get_users_listing($sort="lastaccess", $dir="ASC", $page=0, $recordsperpage=99999,
+ $search="", $firstinitial="", $lastinitial="") {
+
global $CFG;
switch ($CFG->dbtype) {
break;
default:
$limit = "LIMIT $recordsperpage,$page";
- $fullname = " firstname||\" \"||lastname ";
+ $fullname = " firstname||' '||lastname ";
$LIKE = "LIKE";
}
+ $select = 'deleted <> 1';
+
if ($search) {
- $search = " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%') ";
+ $select .= " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%') ";
+ }
+
+ if ($firstinitial) {
+ $select .= " AND firstname $LIKE '$firstinitial%' ";
+ }
+
+ if ($lastinitial) {
+ $select .= " AND lastname $LIKE '$lastinitial%' ";
}
-/// warning: will return unconfirmed users
+ if ($sort) {
+ $sort = " ORDER BY $sort $dir";
+ }
+
+/// warning: will return UNCONFIRMED USERS
return get_records_sql("SELECT id, username, email, firstname, lastname, city, country, lastaccess, confirmed
FROM {$CFG->prefix}user
- WHERE username <> 'guest'
- AND deleted <> 1 $search
- ORDER BY $sort $dir $limit");
+ WHERE $select $sort $limit ");
}
+
/**
* shortdesc
*