rolesactive) { // No admin user yet. $user->firstname = get_string("admin"); $user->lastname = get_string("user"); $user->username = "admin"; $user->password = hash_internal_user_password("admin"); $user->email = "root@localhost"; $user->confirmed = 1; $user->lang = $CFG->lang; $user->maildisplay = 1; $user->timemodified = time(); if (! $user->id = insert_record("user", $user)) { error("SERIOUS ERROR: Could not create admin user record !!!"); } $admin->userid = $user->id; if (! $user = get_record("user", "id", $user->id)) { // Double check. error("User ID was incorrect (can't find it)"); } // Assign the default admin role to the new user. if (!$adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW)) { error('No admin role could be found'); } foreach ($adminroles as $adminrole) { role_assign($adminrole->id, $user->id, 0, $context->id); } set_config('rolesactive', 1); if (! $site = get_site()) { error("Could not find site-level course"); } // Log the user in. $USER = $user; $USER->loggedin = true; $USER->sessionIP = md5(getremoteaddr()); // Store the current IP in the session $USER->site = $CFG->wwwroot; $USER->admin = true; //$USER->teacher["$site->id"] = true; $USER->newadminuser = true; sesskey(); // For added security, used to check script parameters load_user_capability(); redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id"); // Edit thyself exit; } else { if (! $site = get_site()) { error("Could not find site-level course"); } } require_login(); if ($newuser) { // Create a new user if (!has_capability('moodle/user:create', $context)) { error('You do not have the required permission to create new users.'); } if (!$user = get_record('user', 'username', 'changeme')) { // half finished user from another time $user = new object; $user->auth = 'manual'; $user->firstname = ''; $user->lastname = ''; $user->username = 'changeme'; $user->password = ''; $user->email = ''; $user->lang = $CFG->lang; $user->confirmed = 1; $user->timemodified = time(); if (! $user->id = insert_record('user', $user)) { error('Could not start a new user!'); } } redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id"); } else { // List all users for editing if (!has_capability('moodle/user:update', $context)) { error('You do not have the required permission to edit users.'); } $stredituser = get_string("edituser"); $stradministration = get_string("administration"); $strusers = get_string("users"); $stredit = get_string("edit"); $strdelete = get_string("delete"); $strdeletecheck = get_string("deletecheck"); $strsearch = get_string("search"); $strshowallusers = get_string("showallusers"); if ($firstinitial or $lastinitial or $search or $page) { print_header("$site->shortname: $stredituser", $site->fullname, "$stradministration -> ". "$strusers -> ". "$stredituser"); } else { print_header("$site->shortname: $stredituser", $site->fullname, "$stradministration -> ". "$strusers -> $stredituser"); } if ($confirmuser and confirm_sesskey()) { if (!$user = get_record("user", "id", "$confirmuser")) { error("No such user!"); } $confirmeduser = new object(); $confirmeduser->id = $confirmuser; $confirmeduser->confirmed = 1; $confirmeduser->timemodified = time(); if (update_record("user", $confirmeduser)) { notify(get_string("userconfirmed", "", fullname($user, true)) ); } else { notify(get_string("usernotconfirmed", "", fullname($user, true))); } } else if ($delete and confirm_sesskey()) { // Delete a selected user, after confirmation if (!has_capability('moodle/user:delete', $context)) { error('You do not have the required permission to delete a user.'); } if (!$user = get_record("user", "id", "$delete")) { error("No such user!"); } $primaryadmin = get_admin(); if ($user->id == $primaryadmin->id) { error("You are not allowed to delete the primary admin user!"); } if ($confirm != md5($delete)) { $fullname = fullname($user, true); notice_yesno(get_string("deletecheckfull", "", "'$fullname'"), "user.php?delete=$delete&confirm=".md5($delete)."&sesskey=$USER->sesskey", "user.php"); exit; } else if (!$user->deleted) { $updateuser = new object(); $updateuser->id = $user->id; $updateuser->deleted = "1"; $updateuser->username = "$user->email.".time(); // Remember it just in case $updateuser->email = ""; // Clear this field to free it up $updateuser->idnumber = ""; // Clear this field to free it up $updateuser->timemodified = time(); if (update_record("user", $updateuser)) { unenrol_student($user->id); // From all courses remove_teacher($user->id); // From all courses remove_admin($user->id); notify(get_string("deletedactivity", "", fullname($user, true)) ); } else { notify(get_string("deletednot", "", fullname($user, true))); } } } // Carry on with the user listing $columns = array("firstname", "lastname", "email", "city", "country", "lastaccess"); foreach ($columns as $column) { $string[$column] = get_string("$column"); if ($sort != $column) { $columnicon = ""; if ($column == "lastaccess") { $columndir = "DESC"; } else { $columndir = "ASC"; } } else { $columndir = $dir == "ASC" ? "DESC":"ASC"; if ($column == "lastaccess") { $columnicon = $dir == "ASC" ? "up":"down"; } else { $columnicon = $dir == "ASC" ? "down":"up"; } $columnicon = " pixpath/t/$columnicon.gif\" alt=\"\" />"; } $$column = "".$string[$column]."$columnicon"; } if ($sort == "name") { $sort = "firstname"; } $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 ($search or $firstinitial or $lastinitial) { print_heading("$usersearchcount / $usercount ".get_string("users")); $usercount = $usersearchcount; } else { print_heading("$usercount ".get_string("users")); } $alphabet = explode(',', get_string('alphabet')); $strall = get_string("all"); /// Bar of first initials echo "
";
echo get_string("firstname")." : ";
if ($firstinitial) {
echo " $strall ";
} else {
echo " $strall ";
}
foreach ($alphabet as $letter) {
if ($letter == $firstinitial) {
echo " $letter ";
} else {
echo " $letter ";
}
}
echo "
";
/// Bar of last initials
echo get_string("lastname")." : ";
if ($lastinitial) {
echo " $strall ";
} else {
echo " $strall ";
}
foreach ($alphabet as $letter) {
if ($letter == $lastinitial) {
echo " $letter ";
} else {
echo " $letter ";
}
}
echo "
"; echo ""; echo " |