2001-11-22 06:23:56 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
require("../config.php");
|
|
|
|
require("../user/lib.php");
|
2002-08-03 04:57:45 +00:00
|
|
|
require("../lib/countries.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-11-10 10:19:06 +00:00
|
|
|
$recordsperpage = 100;
|
|
|
|
|
2002-09-22 14:06:38 +00:00
|
|
|
optional_variable($newuser, "");
|
|
|
|
optional_variable($delete, "");
|
|
|
|
optional_variable($confirm, "");
|
|
|
|
optional_variable($sort, "name");
|
|
|
|
optional_variable($dir, "ASC");
|
2002-11-10 10:19:06 +00:00
|
|
|
optional_variable($page, 0);
|
2002-09-22 14:06:38 +00:00
|
|
|
|
2002-08-22 06:41:30 +00:00
|
|
|
if (! record_exists_sql("SELECT * FROM user_admins")) { // No admin user yet
|
2001-11-22 06:23:56 +00:00
|
|
|
$user->firstname = "Admin";
|
|
|
|
$user->lastname = "User";
|
|
|
|
$user->username = "admin";
|
2002-09-05 02:04:00 +00:00
|
|
|
$user->password = md5("admin");
|
2001-11-22 06:23:56 +00:00
|
|
|
$user->email = "root@localhost";
|
|
|
|
$user->confirmed = 1;
|
2002-10-18 08:48:44 +00:00
|
|
|
$user->lang = $CFG->lang;
|
2002-08-22 06:41:30 +00:00
|
|
|
$user->maildisplay = 1;
|
2001-11-22 06:23:56 +00:00
|
|
|
$user->timemodified = time();
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (! $user->id = insert_record("user", $user)) {
|
|
|
|
error("SERIOUS ERROR: Could not create admin user record !!!");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
$admin->user = $user->id;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if (! insert_record("user_admins", $admin)) {
|
2002-08-08 14:17:55 +00:00
|
|
|
error("Could not make user $user->id an admin !!!");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (! $user = get_record("user", "id", $user->id)) { // Double check
|
2001-11-22 06:23:56 +00:00
|
|
|
error("User ID was incorrect (can't find it)");
|
|
|
|
}
|
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
if (! $site = get_site()) {
|
2001-11-22 06:23:56 +00:00
|
|
|
error("Could not find site-level course");
|
|
|
|
}
|
|
|
|
|
|
|
|
$teacher->user = $user->id;
|
2002-08-08 15:51:23 +00:00
|
|
|
$teacher->course = $site->id;
|
2001-11-22 06:23:56 +00:00
|
|
|
$teacher->authority = 1;
|
|
|
|
if (! insert_record("user_teachers", $teacher)) {
|
|
|
|
error("Could not make user $id a teacher of site-level course !!!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$USER = $user;
|
|
|
|
$USER->loggedin = true;
|
2002-09-05 02:04:00 +00:00
|
|
|
$USER->site = $CFG->wwwroot;
|
2001-11-22 06:23:56 +00:00
|
|
|
$USER->admin = true;
|
2002-08-08 15:51:23 +00:00
|
|
|
$USER->teacher["$site->id"] = true;
|
2002-08-06 17:23:45 +00:00
|
|
|
save_session("USER");
|
2002-08-08 14:17:55 +00:00
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
2002-08-08 14:17:55 +00:00
|
|
|
|
|
|
|
} else {
|
2002-08-08 15:51:23 +00:00
|
|
|
if (! $site = get_site()) {
|
2002-08-08 14:17:55 +00:00
|
|
|
error("Could not find site-level course");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
if (!isadmin()) {
|
|
|
|
error("You must be an administrator to edit users this way.");
|
|
|
|
}
|
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if ($newuser) { // Create a new user
|
2002-08-08 15:51:23 +00:00
|
|
|
$user->firstname = "";
|
|
|
|
$user->lastname = "";
|
|
|
|
$user->username = "changeme";
|
2002-08-08 14:17:55 +00:00
|
|
|
$user->password = "";
|
|
|
|
$user->email = "";
|
2002-10-18 08:48:44 +00:00
|
|
|
$user->lang = $CFG->lang;
|
2002-08-08 14:17:55 +00:00
|
|
|
$user->confirmed = 1;
|
|
|
|
$user->timemodified = time();
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if (! $user->id = insert_record("user", $user)) {
|
2002-08-08 15:51:23 +00:00
|
|
|
if (!$user = get_record("user", "username", "changeme")) { // half finished user from another time
|
|
|
|
error("Could not start a new user!");
|
|
|
|
}
|
2002-08-08 14:17:55 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
2002-08-08 14:17:55 +00:00
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
} else { // List all users for editing
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-09-22 03:01:17 +00:00
|
|
|
$stredituser = get_string("edituser");
|
|
|
|
$stradministration = get_string("administration");
|
|
|
|
$stredit = get_string("edit");
|
|
|
|
$strdelete = get_string("delete");
|
|
|
|
$strdeletecheck = get_string("deletecheck");
|
|
|
|
|
2002-09-27 14:26:02 +00:00
|
|
|
print_header("$site->shortname: $stredituser", $site->fullname,
|
2002-10-25 02:02:02 +00:00
|
|
|
"<A HREF=\"index.php\">$stradministration</A> -> $stredituser");
|
2002-09-22 03:01:17 +00:00
|
|
|
|
2002-09-22 14:06:38 +00:00
|
|
|
if ($delete) { // Delete a selected user, after confirmation
|
|
|
|
if (!$user = get_record("user", "id", "$delete")) {
|
|
|
|
error("No such user!");
|
|
|
|
}
|
|
|
|
if ($confirm != md5($delete)) {
|
|
|
|
notice_yesno(get_string("deletecheckfull", "", "'$user->firstname $user->lastname'"),
|
|
|
|
"user.php?delete=$delete&confirm=".md5($delete), "user.php");
|
|
|
|
|
|
|
|
exit;
|
2002-09-22 14:42:32 +00:00
|
|
|
} else if (!$user->deleted) {
|
2002-09-22 14:06:38 +00:00
|
|
|
$user->deleted = "1";
|
|
|
|
$user->username = $user->email; // Remember it just in case
|
|
|
|
$user->email = ""; // Clear this field to free it up
|
|
|
|
$user->timemodified = time();
|
|
|
|
if (update_record("user", $user)) {
|
|
|
|
unenrol_student($user->id); // From all courses
|
|
|
|
remove_teacher($user->id); // From all courses
|
|
|
|
remove_admin($user->id);
|
|
|
|
notify(get_string("deletedactivity", "", "$user->firstname $user->lastname"));
|
|
|
|
} else {
|
|
|
|
notify(get_string("deletednot", "", "$user->firstname $user->lastname"));
|
2002-09-22 03:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-08-08 14:17:55 +00:00
|
|
|
|
2002-09-22 14:06:38 +00:00
|
|
|
// Carry on with the user listing
|
|
|
|
|
|
|
|
$columns = array("name", "email", "city", "country", "lastaccess");
|
|
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
$string[$column] = get_string("$column");
|
|
|
|
$columnsort = "$column";
|
|
|
|
if ($column == "lastaccess") {
|
|
|
|
$columndir = "DESC";
|
|
|
|
} else {
|
|
|
|
$columndir = "ASC";
|
|
|
|
}
|
|
|
|
if ($columnsort == $sort) {
|
|
|
|
$$column = $string[$column];
|
|
|
|
} else {
|
|
|
|
$$column = "<A HREF=\"user.php?sort=$columnsort&dir=$columndir\">".$string[$column]."</A>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sort == "name") {
|
|
|
|
$sort = "firstname";
|
|
|
|
}
|
|
|
|
|
2002-11-10 10:19:06 +00:00
|
|
|
if ($users = get_records_sql("SELECT id, username, email, firstname, lastname, city, country, lastaccess from user WHERE username <> 'guest'
|
|
|
|
AND deleted <> '1' ORDER BY $sort $dir LIMIT $page,$recordsperpage")) {
|
2002-09-22 14:06:38 +00:00
|
|
|
|
2002-09-22 16:03:01 +00:00
|
|
|
foreach ($users as $key => $user) {
|
|
|
|
$users[$key]->country = $COUNTRIES[$user->country];
|
2002-09-22 15:57:23 +00:00
|
|
|
}
|
|
|
|
if ($sort == "country") { // Need to resort by full country name, not code
|
|
|
|
foreach ($users as $user) {
|
2002-09-22 16:12:49 +00:00
|
|
|
$susers[$user->id] = $user->country;
|
2002-09-22 15:57:23 +00:00
|
|
|
}
|
2002-09-22 16:12:49 +00:00
|
|
|
asort($susers);
|
|
|
|
foreach ($susers as $key => $value) {
|
|
|
|
$nusers[] = $users[$key];
|
|
|
|
}
|
|
|
|
$users = $nusers;
|
2002-09-22 15:57:23 +00:00
|
|
|
}
|
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
print_heading(get_string("chooseuser"));
|
2002-08-08 14:17:55 +00:00
|
|
|
|
2002-09-22 14:06:38 +00:00
|
|
|
$table->head = array ($name, $email, $city, $country, $lastaccess, "", "");
|
|
|
|
$table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "CENTER", "CENTER");
|
2002-09-22 14:11:45 +00:00
|
|
|
$table->width = "95%";
|
2002-08-08 14:17:55 +00:00
|
|
|
foreach ($users as $user) {
|
2002-09-22 14:06:38 +00:00
|
|
|
if ($user->id == $USER->id or $user->username == "changeme") {
|
|
|
|
$deletebutton = "";
|
|
|
|
} else {
|
|
|
|
$deletebutton = "<A HREF=\"user.php?delete=$user->id\" TARGET=\"$strdeletecheck\">$strdelete</A>";
|
|
|
|
}
|
|
|
|
if ($user->lastaccess) {
|
|
|
|
$strlastaccess = format_time(time() - $user->lastaccess);
|
|
|
|
} else {
|
|
|
|
$strlastaccess = get_string("never");
|
|
|
|
}
|
2002-08-11 04:30:25 +00:00
|
|
|
$table->data[] = array ("<A HREF=\"../user/view.php?id=$user->id&course=$site->id\">$user->firstname $user->lastname</A>",
|
2002-09-22 03:01:17 +00:00
|
|
|
"$user->email",
|
|
|
|
"$user->city",
|
2002-09-22 15:57:23 +00:00
|
|
|
"$user->country",
|
2002-09-22 14:06:38 +00:00
|
|
|
$strlastaccess,
|
2002-09-22 03:01:17 +00:00
|
|
|
"<A HREF=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</A>",
|
2002-09-22 14:06:38 +00:00
|
|
|
$deletebutton);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-08-08 14:17:55 +00:00
|
|
|
print_table($table);
|
2002-08-09 09:09:36 +00:00
|
|
|
|
|
|
|
print_heading("<A HREF=\"user.php?newuser=true\">".get_string("addnewuser")."</A>");
|
2002-08-08 14:17:55 +00:00
|
|
|
} else {
|
|
|
|
error("No users found!");
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-08-08 14:17:55 +00:00
|
|
|
print_footer();
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|