2004-10-03 17:19:36 +00:00
|
|
|
<?php // $Id$
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-08-18 07:52:56 +00:00
|
|
|
require_once('../config.php');
|
2006-09-24 11:55:11 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2006-03-07 16:42:30 +00:00
|
|
|
|
|
|
|
$newuser = optional_param('newuser', 0, PARAM_BOOL);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT);
|
|
|
|
$confirm = optional_param('confirm', '', PARAM_ALPHANUM); //md5 confirmation hash
|
|
|
|
$confirmuser = optional_param('confirmuser', 0, PARAM_INT);
|
|
|
|
$sort = optional_param('sort', 'name', PARAM_ALPHA);
|
|
|
|
$dir = optional_param('dir', 'ASC', PARAM_ALPHA);
|
|
|
|
$page = optional_param('page', 0, PARAM_INT);
|
|
|
|
$perpage = optional_param('perpage', 30, PARAM_INT); // how many per page
|
2006-09-24 11:55:11 +00:00
|
|
|
$search = trim(optional_param('search', '', PARAM_RAW));
|
2006-03-07 16:42:30 +00:00
|
|
|
$lastinitial = optional_param('lastinitial', '', PARAM_CLEAN); // only show students with this last initial
|
|
|
|
$firstinitial = optional_param('firstinitial', '', PARAM_CLEAN); // only show students with this first initial
|
2007-01-04 03:19:49 +00:00
|
|
|
$ru = optional_param('ru', '2', PARAM_INT); // show remote users
|
|
|
|
$lu = optional_param('lu', '2', PARAM_INT); // show local users
|
|
|
|
$acl = optional_param('acl', '0', PARAM_INT); // id of user to tweak mnet ACL (requires $access)
|
|
|
|
|
|
|
|
// Determine which users we are looking at (local, remote, or both). Start with both.
|
|
|
|
if (!isset($_SESSION['admin-user-remoteusers'])) {
|
|
|
|
$_SESSION['admin-user-remoteusers'] = 1;
|
|
|
|
$_SESSION['admin-user-localusers'] = 1;
|
|
|
|
}
|
|
|
|
if ($ru == 0 or $ru == 1) {
|
|
|
|
$_SESSION['admin-user-remoteusers'] = $ru;
|
|
|
|
}
|
|
|
|
if ($lu == 0 or $lu == 1) {
|
|
|
|
$_SESSION['admin-user-localusers'] = $lu;
|
|
|
|
}
|
|
|
|
$remoteusers = $_SESSION['admin-user-remoteusers'];
|
|
|
|
$localusers = $_SESSION['admin-user-localusers'];
|
|
|
|
|
|
|
|
// if neither remote nor local, set to sensible local only
|
|
|
|
if (!$remoteusers and !$localusers) {
|
|
|
|
$_SESSION['admin-user-localusers'] = 1;
|
|
|
|
$localusers = 1;
|
|
|
|
}
|
2003-07-24 14:52:41 +00:00
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID)) { // Should never happen
|
2006-09-03 14:45:57 +00:00
|
|
|
redirect('index.php');
|
|
|
|
}
|
2006-08-11 02:44:42 +00:00
|
|
|
|
2006-10-19 22:18:22 +00:00
|
|
|
if (empty($CFG->rolesactive)) { // No admin user yet.
|
2003-07-24 08:36:43 +00:00
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
$user = new object();
|
|
|
|
$user->firstname = get_string('admin');
|
|
|
|
$user->lastname = get_string('user');
|
|
|
|
$user->username = 'admin';
|
|
|
|
$user->password = hash_internal_user_password('admin');
|
|
|
|
$user->email = 'root@localhost';
|
2006-03-07 16:42:30 +00:00
|
|
|
$user->confirmed = 1;
|
2007-01-04 03:19:49 +00:00
|
|
|
$user->mnethostid = $CFG->mnet_localhost_id;
|
2006-03-07 16:42:30 +00:00
|
|
|
$user->lang = $CFG->lang;
|
|
|
|
$user->maildisplay = 1;
|
2001-11-22 06:23:56 +00:00
|
|
|
$user->timemodified = time();
|
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
if (! $user->id = insert_record('user', $user)) {
|
2002-08-08 14:17:55 +00:00
|
|
|
error("SERIOUS ERROR: Could not create admin user record !!!");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2006-09-24 11:55:11 +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)");
|
|
|
|
}
|
|
|
|
|
2006-08-11 02:44:42 +00:00
|
|
|
|
|
|
|
// Assign the default admin role to the new user.
|
2006-08-11 03:58:52 +00:00
|
|
|
if (!$adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW)) {
|
|
|
|
error('No admin role could be found');
|
|
|
|
}
|
|
|
|
foreach ($adminroles as $adminrole) {
|
2006-09-24 11:55:11 +00:00
|
|
|
role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
|
2006-08-11 03:58:52 +00:00
|
|
|
}
|
2006-08-11 02:44:42 +00:00
|
|
|
set_config('rolesactive', 1);
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2006-09-24 11:55:11 +00:00
|
|
|
|
2006-08-11 02:44:42 +00:00
|
|
|
// Log the user in.
|
2001-11-22 06:23:56 +00:00
|
|
|
$USER = $user;
|
|
|
|
$USER->loggedin = true;
|
2005-01-12 11:33:45 +00:00
|
|
|
$USER->sessionIP = md5(getremoteaddr()); // Store the current IP in the session
|
2002-09-05 02:04:00 +00:00
|
|
|
$USER->site = $CFG->wwwroot;
|
2001-11-22 06:23:56 +00:00
|
|
|
$USER->admin = true;
|
2003-05-06 15:58:20 +00:00
|
|
|
$USER->newadminuser = true;
|
2006-09-03 14:45:57 +00:00
|
|
|
|
2006-08-11 02:44:42 +00:00
|
|
|
sesskey(); // For added security, used to check script parameters
|
|
|
|
|
2006-10-23 15:17:31 +00:00
|
|
|
load_all_capabilities();
|
2002-08-08 14:17:55 +00:00
|
|
|
|
2006-09-03 14:45:57 +00:00
|
|
|
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id"); // Edit thyself
|
2003-05-06 15:58:20 +00:00
|
|
|
exit;
|
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();
|
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
$adminroot = admin_get_root();
|
|
|
|
|
|
|
|
if ($newuser) {
|
|
|
|
admin_externalpage_setup('addnewuser', $adminroot);
|
|
|
|
} else {
|
|
|
|
admin_externalpage_setup('editusers', $adminroot);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-03 14:45:57 +00:00
|
|
|
if ($newuser) { // Create a new user
|
2006-09-24 11:55:11 +00:00
|
|
|
|
|
|
|
if (!has_capability('moodle/user:create', $sitecontext)) {
|
2006-08-11 02:44:42 +00:00
|
|
|
error('You do not have the required permission to create new users.');
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-09-03 14:45:57 +00:00
|
|
|
if (!$user = get_record('user', 'username', 'changeme')) { // half finished user from another time
|
2006-09-24 11:55:11 +00:00
|
|
|
|
|
|
|
$user = new object();
|
2006-09-03 14:45:57 +00:00
|
|
|
$user->auth = 'manual';
|
|
|
|
$user->firstname = '';
|
|
|
|
$user->lastname = '';
|
|
|
|
$user->username = 'changeme';
|
|
|
|
$user->password = '';
|
|
|
|
$user->email = '';
|
|
|
|
$user->lang = $CFG->lang;
|
|
|
|
$user->confirmed = 1;
|
|
|
|
$user->timemodified = time();
|
2007-01-04 03:19:49 +00:00
|
|
|
$user->mnethostid = $CFG->mnet_localhost_id;
|
2006-09-03 14:45:57 +00:00
|
|
|
|
|
|
|
if (! $user->id = insert_record('user', $user)) {
|
|
|
|
error('Could not start a new user!');
|
2002-08-08 15:51:23 +00:00
|
|
|
}
|
2002-08-08 14:17:55 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-09-16 17:13:57 +00:00
|
|
|
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
} else { // List all users for editing
|
2006-09-24 11:55:11 +00:00
|
|
|
|
|
|
|
if (!has_capability('moodle/user:update', $sitecontext) and !has_capability('moodle/user:delete', $sitecontext)) {
|
|
|
|
error('You do not have the required permission to edit/delete users.');
|
2006-08-18 07:52:56 +00:00
|
|
|
}
|
2002-09-22 03:01:17 +00:00
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
$stredit = get_string('edit');
|
|
|
|
$strdelete = get_string('delete');
|
|
|
|
$strdeletecheck = get_string('deletecheck');
|
|
|
|
$strsearch = get_string('search');
|
|
|
|
$strshowallusers = get_string('showallusers');
|
|
|
|
|
|
|
|
admin_externalpage_print_header($adminroot);
|
|
|
|
|
2004-10-04 13:50:37 +00:00
|
|
|
if ($confirmuser and confirm_sesskey()) {
|
2006-09-24 11:55:11 +00:00
|
|
|
if (!$user = get_record('user', 'id', $confirmuser)) {
|
2004-03-09 21:43:09 +00:00
|
|
|
error("No such user!");
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:42:30 +00:00
|
|
|
$confirmeduser = new object();
|
2004-03-09 21:43:09 +00:00
|
|
|
$confirmeduser->id = $confirmuser;
|
|
|
|
$confirmeduser->confirmed = 1;
|
|
|
|
$confirmeduser->timemodified = time();
|
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
if (update_record('user', $confirmeduser)) {
|
|
|
|
notify(get_string('userconfirmed', '', fullname($user, true)) );
|
2004-03-09 21:43:09 +00:00
|
|
|
} else {
|
2006-09-24 11:55:11 +00:00
|
|
|
notify(get_string('usernotconfirmed', '', fullname($user, true)));
|
2004-03-09 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 02:44:42 +00:00
|
|
|
} else if ($delete and confirm_sesskey()) { // Delete a selected user, after confirmation
|
2006-09-24 11:55:11 +00:00
|
|
|
|
|
|
|
if (!has_capability('moodle/user:delete', $sitecontext)) {
|
2006-08-11 02:44:42 +00:00
|
|
|
error('You do not have the required permission to delete a user.');
|
|
|
|
}
|
2006-09-24 11:55:11 +00:00
|
|
|
|
|
|
|
if (!$user = get_record('user', 'id', $delete)) {
|
2002-09-22 14:06:38 +00:00
|
|
|
error("No such user!");
|
|
|
|
}
|
2003-06-21 04:09:20 +00:00
|
|
|
|
|
|
|
$primaryadmin = get_admin();
|
|
|
|
if ($user->id == $primaryadmin->id) {
|
|
|
|
error("You are not allowed to delete the primary admin user!");
|
|
|
|
}
|
|
|
|
|
2002-09-22 14:06:38 +00:00
|
|
|
if ($confirm != md5($delete)) {
|
2003-11-19 16:15:56 +00:00
|
|
|
$fullname = fullname($user, true);
|
2006-09-24 11:55:11 +00:00
|
|
|
print_heading(get_string('deleteuser', 'admin'));
|
|
|
|
$optionsyes = array('delete'=>$delete, 'confirm'=>md5($delete), 'sesskey'=>sesskey());
|
|
|
|
notice_yesno(get_string('deletecheckfull', '', "'$fullname'"), 'user.php', 'user.php', $optionsyes, NULL, 'post', 'get');
|
|
|
|
admin_externalpage_print_footer($adminroot);
|
|
|
|
die;
|
|
|
|
} else if (data_submitted() and !$user->deleted) {
|
2006-03-07 16:42:30 +00:00
|
|
|
$updateuser = new object();
|
2003-07-28 12:08:31 +00:00
|
|
|
$updateuser->id = $user->id;
|
2006-09-24 11:55:11 +00:00
|
|
|
$updateuser->deleted = 1;
|
2006-10-18 21:46:14 +00:00
|
|
|
$updateuser->username = addslashes("$user->email.".time()); // Remember it just in case
|
2006-09-24 11:55:11 +00:00
|
|
|
$updateuser->email = ''; // Clear this field to free it up
|
|
|
|
$updateuser->idnumber = ''; // Clear this field to free it up
|
2003-07-28 12:08:31 +00:00
|
|
|
$updateuser->timemodified = time();
|
2006-09-24 11:55:11 +00:00
|
|
|
if (update_record('user', $updateuser)) {
|
2006-09-19 01:44:33 +00:00
|
|
|
// not sure if this is needed. unenrol_student($user->id); // From all courses
|
|
|
|
delete_records('role_assignments', 'userid', $user->id); // unassign all roles
|
2006-09-24 11:55:11 +00:00
|
|
|
// remove all context assigned on this user?
|
|
|
|
notify(get_string('deletedactivity', '', fullname($user, true)) );
|
2002-09-22 14:06:38 +00:00
|
|
|
} else {
|
2006-09-24 11:55:11 +00:00
|
|
|
notify(get_string('deletednot', '', fullname($user, true)));
|
2002-09-22 03:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-04 03:19:49 +00:00
|
|
|
} else if ($acl and confirm_sesskey()) {
|
|
|
|
if (!has_capability('moodle/user:delete', $sitecontext)) {
|
|
|
|
// TODO: this should be under a separate capability
|
|
|
|
error('You are not permitted to modify the MNET access control list.');
|
|
|
|
}
|
|
|
|
if (!$user = get_record('user', 'id', $acl)) {
|
|
|
|
error("No such user.");
|
|
|
|
}
|
|
|
|
if (!is_mnet_remote_user($user)) {
|
|
|
|
error('Users in the MNET access control list must be remote MNET users.');
|
|
|
|
}
|
|
|
|
$access = strtolower(required_param('access', PARAM_ALPHA));
|
|
|
|
if ($access != 'allow' and $access != 'deny') {
|
|
|
|
error('Invalid access parameter.');
|
|
|
|
}
|
|
|
|
$aclrecord = get_record('mnet_sso_access_control', 'username', $user->username, 'mnet_host_id', $user->mnethostid);
|
|
|
|
if (empty($aclrecord)) {
|
|
|
|
$aclrecord = new object();
|
|
|
|
$aclrecord->mnet_host_id = $user->mnethostid;
|
|
|
|
$aclrecord->username = $user->username;
|
|
|
|
$aclrecord->access = $access;
|
|
|
|
if (!insert_record('mnet_sso_access_control', $aclrecord)) {
|
|
|
|
error("Database error - Couldn't modify the MNET access control list.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$aclrecord->access = $access;
|
|
|
|
if (!update_record('mnet_sso_access_control', $aclrecord)) {
|
|
|
|
error("Database error - Couldn't modify the MNET access control list.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mnethosts = get_records('mnet_host', '', '', 'id', 'id,wwwroot,name');
|
|
|
|
notify("MNET access control list updated: username '$user->username' from host '"
|
|
|
|
. $mnethosts[$user->mnethostid]->name
|
|
|
|
. "' access now set to '$access'.");
|
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
|
|
|
|
|
2004-03-19 04:29:00 +00:00
|
|
|
$columns = array("firstname", "lastname", "email", "city", "country", "lastaccess");
|
2002-09-22 14:06:38 +00:00
|
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
$string[$column] = get_string("$column");
|
2004-03-19 04:29:00 +00:00
|
|
|
if ($sort != $column) {
|
|
|
|
$columnicon = "";
|
|
|
|
if ($column == "lastaccess") {
|
|
|
|
$columndir = "DESC";
|
|
|
|
} else {
|
|
|
|
$columndir = "ASC";
|
|
|
|
}
|
2002-09-22 14:06:38 +00:00
|
|
|
} else {
|
2004-07-02 02:46:17 +00:00
|
|
|
$columndir = $dir == "ASC" ? "DESC":"ASC";
|
2004-03-19 04:29:00 +00:00
|
|
|
if ($column == "lastaccess") {
|
2004-07-02 02:46:17 +00:00
|
|
|
$columnicon = $dir == "ASC" ? "up":"down";
|
2004-03-19 04:29:00 +00:00
|
|
|
} else {
|
2004-07-02 02:46:17 +00:00
|
|
|
$columnicon = $dir == "ASC" ? "down":"up";
|
2004-03-19 04:29:00 +00:00
|
|
|
}
|
2004-09-16 17:13:57 +00:00
|
|
|
$columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" alt=\"\" />";
|
2004-03-19 04:29:00 +00:00
|
|
|
|
2002-09-22 14:06:38 +00:00
|
|
|
}
|
2006-03-07 16:42:30 +00:00
|
|
|
$$column = "<a href=\"user.php?sort=$column&dir=$columndir&search=".urlencode(stripslashes($search))."&firstinitial=$firstinitial&lastinitial=$lastinitial\">".$string[$column]."</a>$columnicon";
|
2002-09-22 14:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($sort == "name") {
|
|
|
|
$sort = "firstname";
|
|
|
|
}
|
2007-01-04 03:19:49 +00:00
|
|
|
|
|
|
|
// tell the query which users we are looking at (local, remote, or both)
|
|
|
|
$remotewhere = '';
|
|
|
|
if ($localusers) {
|
|
|
|
$remotewhere .= " and mnethostid = {$CFG->mnet_localhost_id} ";
|
|
|
|
}
|
|
|
|
if ($remoteusers) {
|
|
|
|
if ($localusers) {
|
|
|
|
$remotewhere = ''; // more efficient SQL
|
|
|
|
} else {
|
|
|
|
$remotewhere .= " and mnethostid <> {$CFG->mnet_localhost_id} ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$users = get_users_listing($sort, $dir, $page*$perpage, $perpage, $search, $firstinitial, $lastinitial, $remotewhere);
|
2003-05-14 15:19:04 +00:00
|
|
|
$usercount = get_users(false);
|
2004-03-20 06:58:52 +00:00
|
|
|
$usersearchcount = get_users(false, $search, true, "", "", $firstinitial, $lastinitial);
|
2003-03-21 10:08:23 +00:00
|
|
|
|
2004-03-20 06:58:52 +00:00
|
|
|
if ($search or $firstinitial or $lastinitial) {
|
2006-09-24 11:55:11 +00:00
|
|
|
print_heading("$usersearchcount / $usercount ".get_string('users'));
|
2003-03-21 10:08:23 +00:00
|
|
|
$usercount = $usersearchcount;
|
|
|
|
} else {
|
2006-09-24 11:55:11 +00:00
|
|
|
print_heading("$usercount ".get_string('users'));
|
2003-03-21 10:08:23 +00:00
|
|
|
}
|
2004-03-19 04:29:00 +00:00
|
|
|
|
2004-03-20 06:58:52 +00:00
|
|
|
$alphabet = explode(',', get_string('alphabet'));
|
2006-09-24 11:55:11 +00:00
|
|
|
$strall = get_string('all');
|
2004-03-19 04:29:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Bar of first initials
|
|
|
|
|
2004-03-20 06:58:52 +00:00
|
|
|
echo "<center><p align=\"center\">";
|
|
|
|
echo get_string("firstname")." : ";
|
|
|
|
if ($firstinitial) {
|
2005-06-24 13:02:32 +00:00
|
|
|
echo " <a href=\"user.php?sort=firstname&dir=ASC&".
|
2004-09-16 17:13:57 +00:00
|
|
|
"perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
|
2004-03-20 06:58:52 +00:00
|
|
|
} else {
|
|
|
|
echo " <b>$strall</b> ";
|
|
|
|
}
|
|
|
|
foreach ($alphabet as $letter) {
|
|
|
|
if ($letter == $firstinitial) {
|
|
|
|
echo " <b>$letter</b> ";
|
2004-03-19 04:29:00 +00:00
|
|
|
} else {
|
2005-06-24 13:02:32 +00:00
|
|
|
echo " <a href=\"user.php?sort=firstname&dir=ASC&".
|
2004-09-16 17:13:57 +00:00
|
|
|
"perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
|
2004-03-19 04:29:00 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
}
|
|
|
|
echo "<br />";
|
2004-03-19 04:29:00 +00:00
|
|
|
|
|
|
|
/// Bar of last initials
|
|
|
|
|
2004-03-20 06:58:52 +00:00
|
|
|
echo get_string("lastname")." : ";
|
|
|
|
if ($lastinitial) {
|
2005-06-24 13:02:32 +00:00
|
|
|
echo " <a href=\"user.php?sort=lastname&dir=ASC&".
|
2004-09-16 17:13:57 +00:00
|
|
|
"perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
|
2004-03-20 06:58:52 +00:00
|
|
|
} else {
|
|
|
|
echo " <b>$strall</b> ";
|
|
|
|
}
|
|
|
|
foreach ($alphabet as $letter) {
|
|
|
|
if ($letter == $lastinitial) {
|
|
|
|
echo " <b>$letter</b> ";
|
2004-03-19 04:29:00 +00:00
|
|
|
} else {
|
2005-06-24 13:02:32 +00:00
|
|
|
echo " <a href=\"user.php?sort=lastname&dir=ASC&".
|
2004-09-16 17:13:57 +00:00
|
|
|
"perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
|
2004-03-19 04:29:00 +00:00
|
|
|
}
|
2003-03-21 09:42:42 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
echo "</p>";
|
|
|
|
echo "</center>";
|
|
|
|
|
|
|
|
print_paging_bar($usercount, $page, $perpage,
|
2006-03-07 16:42:30 +00:00
|
|
|
"user.php?sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&search=".urlencode(stripslashes($search))."&");
|
2002-08-08 14:17:55 +00:00
|
|
|
|
2003-03-21 09:42:42 +00:00
|
|
|
flush();
|
2002-11-11 07:58:11 +00:00
|
|
|
|
2003-09-26 08:04:48 +00:00
|
|
|
|
2004-03-20 06:58:52 +00:00
|
|
|
if (!$users) {
|
|
|
|
$match = array();
|
2006-03-07 16:42:30 +00:00
|
|
|
if ($search !== '') {
|
|
|
|
$match[] = s($search);
|
2003-05-29 03:06:10 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
if ($firstinitial) {
|
2006-09-24 11:55:11 +00:00
|
|
|
$match[] = get_string('firstname').": $firstinitial"."___";
|
2002-11-11 07:58:11 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
if ($lastinitial) {
|
2006-09-24 11:55:11 +00:00
|
|
|
$match[] = get_string('lastname').": $lastinitial"."___";
|
2002-11-11 07:58:11 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
$matchstring = implode(", ", $match);
|
2006-09-24 11:55:11 +00:00
|
|
|
print_heading(get_string('nousersmatching', '', $matchstring));
|
2002-11-11 07:58:11 +00:00
|
|
|
|
2005-02-21 13:50:06 +00:00
|
|
|
$table = NULL;
|
|
|
|
|
2004-03-20 06:58:52 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
$countries = get_list_of_countries();
|
2007-01-04 03:19:49 +00:00
|
|
|
if (empty($mnethosts)) {
|
|
|
|
$mnethosts = get_records('mnet_host', '', '', 'id', 'id,wwwroot,name');
|
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
|
|
|
|
foreach ($users as $key => $user) {
|
|
|
|
if (!empty($user->country)) {
|
|
|
|
$users[$key]->country = $countries[$user->country];
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
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;
|
2003-03-21 09:42:42 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
|
|
|
|
$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) {
|
2006-09-24 11:58:28 +00:00
|
|
|
if ($user->username == 'changeme' or $user->username == 'guest') {
|
|
|
|
continue; // do not dispaly dummy new user and guest here
|
2006-09-24 11:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($user->id == $USER->id) {
|
2004-03-20 06:58:52 +00:00
|
|
|
$deletebutton = "";
|
|
|
|
} else {
|
2006-09-24 11:55:11 +00:00
|
|
|
if (has_capability('moodle/user:delete', $sitecontext)) {
|
|
|
|
$deletebutton = "<a href=\"user.php?delete=$user->id&sesskey=$USER->sesskey\">$strdelete</a>";
|
|
|
|
} else {
|
|
|
|
$deletebutton ="";
|
2006-08-08 05:13:06 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
}
|
2006-09-24 11:55:11 +00:00
|
|
|
|
2007-01-04 03:19:49 +00:00
|
|
|
if (has_capability('moodle/user:update', $sitecontext) and ! is_mnet_remote_user($user)) {
|
2006-09-24 11:55:11 +00:00
|
|
|
$editbutton = "<a href=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</a>";
|
|
|
|
if ($user->confirmed == 0) {
|
|
|
|
$confirmbutton = "<a href=\"user.php?confirmuser=$user->id&sesskey=$USER->sesskey\">" . get_string('confirm') . "</a>";
|
|
|
|
} else {
|
|
|
|
$confirmbutton = "";
|
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
} else {
|
2006-09-24 11:55:11 +00:00
|
|
|
$editbutton ="";
|
|
|
|
if ($user->confirmed == 0) {
|
|
|
|
$confirmbutton = "<span class=\"dimmed_text\">".get_string('confirm')."</span>";
|
|
|
|
} else {
|
|
|
|
$confirmbutton = "";
|
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
}
|
2006-09-24 11:55:11 +00:00
|
|
|
|
2007-01-04 03:19:49 +00:00
|
|
|
// for remote users, shuffle columns around and display MNET stuff
|
|
|
|
if (is_mnet_remote_user($user)) {
|
|
|
|
$access = 'allow';
|
|
|
|
if ($acl = get_record('mnet_sso_access_control', 'username', $user->username, 'mnet_host_id', $user->mnethostid)) {
|
|
|
|
$access = $acl->access;
|
|
|
|
}
|
|
|
|
$changeaccessto = ($access == 'deny' ? 'allow' : 'deny');
|
|
|
|
// delete button in confirm column - remote users should already be confirmed
|
|
|
|
// TODO: no delete for remote users, for now. new userid, delete flag, unique on username/host...
|
|
|
|
$confirmbutton = "";
|
|
|
|
// ACL in delete column
|
|
|
|
$deletebutton = ucfirst($access);
|
|
|
|
if (has_capability('moodle/user:delete', $sitecontext)) {
|
|
|
|
// TODO: this should be under a separate capability
|
|
|
|
$deletebutton .= " (<a href=\"?acl={$user->id}&access=$changeaccessto&sesskey={$USER->sesskey}\">"
|
|
|
|
. ucfirst($changeaccessto) . " access</a>)";
|
|
|
|
}
|
|
|
|
// mnet info in edit column
|
|
|
|
$editbutton = $mnethosts[$user->mnethostid]->name;
|
|
|
|
}
|
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
if ($user->lastaccess) {
|
|
|
|
$strlastaccess = format_time(time() - $user->lastaccess);
|
2004-03-20 06:58:52 +00:00
|
|
|
} else {
|
2006-09-24 11:55:11 +00:00
|
|
|
$strlastaccess = get_string('never');
|
2004-03-20 06:58:52 +00:00
|
|
|
}
|
|
|
|
$fullname = fullname($user, true);
|
2006-09-24 11:55:11 +00:00
|
|
|
|
|
|
|
$table->data[] = array ("<a href=\"../user/view.php?id=$user->id&course=$site->id\">$fullname</a>",
|
|
|
|
"$user->email",
|
|
|
|
"$user->city",
|
|
|
|
"$user->country",
|
|
|
|
$strlastaccess,
|
|
|
|
$editbutton,
|
|
|
|
$deletebutton,
|
|
|
|
$confirmbutton);
|
2004-03-09 21:43:09 +00:00
|
|
|
}
|
2005-02-21 13:50:06 +00:00
|
|
|
}
|
2002-08-09 09:09:36 +00:00
|
|
|
|
2007-01-04 03:19:49 +00:00
|
|
|
echo "<p style=\"text-align:center\">";
|
|
|
|
if ($remoteusers == 1) {
|
|
|
|
echo "<a href=\"?ru=0\">Hide remote users</a> | ";
|
|
|
|
} else {
|
|
|
|
echo "<a href=\"?ru=1\">Show remote users</a> | ";
|
|
|
|
}
|
|
|
|
if ($localusers == 1) {
|
|
|
|
echo "<a href=\"?lu=0\">Hide local users</a>";
|
|
|
|
} else {
|
|
|
|
echo "<a href=\"?lu=1\">Show local users</a>";
|
|
|
|
}
|
|
|
|
echo "</p>";
|
|
|
|
|
2005-02-21 13:50:06 +00:00
|
|
|
echo "<table class=\"searchbox\" align=\"center\" cellpadding=\"10\"><tr><td>";
|
|
|
|
echo "<form action=\"user.php\" method=\"get\">";
|
2006-04-26 21:25:50 +00:00
|
|
|
echo "<input type=\"text\" name=\"search\" value=\"".s($search, true)."\" size=\"20\" />";
|
2005-06-24 13:02:32 +00:00
|
|
|
echo "<input type=\"submit\" value=\"$strsearch\" />";
|
2005-02-21 13:50:06 +00:00
|
|
|
if ($search) {
|
2005-06-24 13:02:32 +00:00
|
|
|
echo "<input type=\"button\" onclick=\"document.location='user.php';\" value=\"$strshowallusers\" />";
|
2005-02-21 13:50:06 +00:00
|
|
|
}
|
|
|
|
echo "</form>";
|
|
|
|
echo "</td></tr></table>";
|
2006-09-24 11:55:11 +00:00
|
|
|
|
|
|
|
if (has_capability('moodle/user:create', $sitecontext)) {
|
|
|
|
print_heading("<a href=\"user.php?newuser=true&sesskey=$USER->sesskey\">".get_string('addnewuser')."</a>");
|
2006-08-09 13:18:33 +00:00
|
|
|
}
|
2005-02-21 13:50:06 +00:00
|
|
|
if (!empty($table)) {
|
2004-03-20 06:58:52 +00:00
|
|
|
print_table($table);
|
|
|
|
print_paging_bar($usercount, $page, $perpage,
|
2004-09-16 17:13:57 +00:00
|
|
|
"user.php?sort=$sort&dir=$dir&perpage=$perpage".
|
2006-03-07 16:42:30 +00:00
|
|
|
"&firstinitial=$firstinitial&lastinitial=$lastinitial&search=".urlencode(stripslashes($search))."&");
|
2006-09-24 11:55:11 +00:00
|
|
|
if (has_capability('moodle/user:create', $sitecontext)) {
|
2006-08-09 13:18:33 +00:00
|
|
|
print_heading("<a href=\"user.php?newuser=true&sesskey=$USER->sesskey\">".get_string("addnewuser")."</a>");
|
2006-08-08 05:13:06 +00:00
|
|
|
}
|
2004-03-20 06:58:52 +00:00
|
|
|
}
|
2004-03-19 04:29:00 +00:00
|
|
|
|
2003-03-21 09:42:42 +00:00
|
|
|
|
2006-09-24 11:55:11 +00:00
|
|
|
admin_externalpage_print_footer($adminroot);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2006-08-18 07:52:56 +00:00
|
|
|
?>
|