Skip to content

Commit

Permalink
Some fixes to the functions for fetching users (some of it is backing
Browse files Browse the repository at this point in the history
out Scott's changes, sorry Scott!) and some fixes to the interface
for the admin user page.
  • Loading branch information
moodler committed Mar 20, 2004
1 parent 1579586 commit 488acd1
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 142 deletions.
223 changes: 118 additions & 105 deletions admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@
$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")) {
Expand Down Expand Up @@ -189,143 +197,148 @@
$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>");
Expand Down
Loading

0 comments on commit 488acd1

Please sign in to comment.