Noted that xml format can now handle images.
[moodle-linuxchix.git] / admin / admin.php
blob68568dff4809b8b9cb9810b751c2c595b089d68c
1 <?PHP // $Id$
2 // Admin-only script to assign administrative rights to users
4 require_once('../config.php');
6 define("MAX_USERS_PER_PAGE", 50);
8 if (! $site = get_site()) {
9 redirect("$CFG->wwwroot/$CFG->admin/index.php");
12 require_login();
14 if (!isadmin()) {
15 error("You must be an administrator to use this page.");
18 if (!confirm_sesskey()) {
19 error(get_string('confirmsesskeybad', 'error'));
22 $primaryadmin = get_admin();
24 /// If you want any administrator to have the ability to assign admin
25 /// rights, then comment out the following if statement
26 if ($primaryadmin->id != $USER->id) {
27 error("You must be the primary administrator to use this page.");
30 /// assign all of the configurable language strings
31 $stringstoload = array (
32 "assignadmins",
33 "administration",
34 "existingadmins",
35 "potentialadmins",
36 "search",
37 "users",
38 "searchresults",
39 "showall"
42 foreach ($stringstoload as $stringtoload){
43 $strstringtoload = "str" . $stringtoload;
44 $$strstringtoload = get_string($stringtoload);
47 print_header("$site->shortname: $strassignadmins",
48 "$site->fullname",
49 "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $strassignadmins", "adminform.searchtext");
52 if (!$frm = data_submitted()) {
53 print_simple_box("<center>".get_string("adminhelpassignadmins")."</center>", "center", "50%");
55 /// A form was submitted so process the input
57 } else {
58 if (!empty($frm->add) and !empty($frm->addselect)) {
59 foreach ($frm->addselect as $addadmin) {
60 if (! add_admin($addadmin)) {
61 error("Could not add admin with user id $addadmin!");
64 } else if (!empty($frm->remove) and !empty($frm->removeselect)) {
65 $admins = get_admins();
66 if (count($admins) > count($frm->removeselect)) {
67 foreach ($frm->removeselect as $removeadmin) {
68 if (! remove_admin($removeadmin)) {
69 error("Could not remove admin with user id $removeadmin!");
73 } else if (!empty($frm->showall)) {
74 unset($frm->searchtext);
75 $frm->previoussearch = 0;
79 /// Is there a current search?
80 $previoussearch = (!empty($frm->search) or ($frm->previoussearch == 1)) ;
82 /// Get all existing admins
83 $admins = get_admins();
86 $adminarray = array();
87 foreach ($admins as $admin) {
88 $adminarray[] = $admin->id;
90 $adminlist = implode(',', $adminarray);
92 unset($adminarray);
95 /// Get search results excluding any current admins
96 if (!empty($frm->searchtext) and $previoussearch) {
97 $searchusers = get_users(true, $frm->searchtext, true, $adminlist, 'firstname ASC, lastname ASC',
98 '', '', 0, 99999, 'id, firstname, lastname, email');
99 $usercount = get_users(false, '', true, $adminlist);
102 /// If no search results then get potential users excluding current admins
103 if (empty($searchusers)) {
105 $usercount = get_users(false, '', true, $adminlist, 'firstname ASC, lastname ASC', '', '',
106 0, 99999, 'id, firstname, lastname, email');
108 $users = array();
110 if ($usercount <= MAX_USERS_PER_PAGE) {
111 if (!$users = get_users(true, '', true, $adminlist, 'firstname ASC, lastname ASC', '', '',
112 0, 99999, 'id, firstname, lastname, email') ) {
113 $users = array();
118 $searchtext = (isset($frm->searchtext)) ? $frm->searchtext : "";
119 $previoussearch = ($previoussearch) ? '1' : '0';
121 include('./admin.html');
123 print_footer();