when inserting 'Give Up' button, if site encoding is not iso-8859-1, then set page...
[moodle.git] / admin / creators.php
blob13f4ab337953733dc031d615d5ccf1bea3df64b1
1 <?PHP // $Id$
2 // Admin only script to assign course creator 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 /// assign all of the configurable language strings
25 $stringstoload = array (
26 "assigncreators",
27 "administration",
28 "existingcreators",
29 "potentialcreators",
30 "search",
31 "users",
32 "searchresults",
33 "showall"
36 foreach ($stringstoload as $stringtoload){
37 $strstringtoload = "str" . $stringtoload;
38 $$strstringtoload = get_string($stringtoload);
41 print_header("$site->shortname: $strassigncreators",
42 "$site->fullname",
43 "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> ->
44 $strassigncreators", "creatorsform.searchtext");
47 if (!$frm = data_submitted()) {
48 print_simple_box("<center>".get_string("adminhelpassigncreators")."</center>", "center", "50%");
49 $frm = new object();
51 /// A form was submitted so process the input
53 } else {
54 if (!empty($frm->add) and !empty($frm->addselect)) {
55 foreach ($frm->addselect as $addcreator) {
56 if (! add_creator($addcreator)) {
57 error("Could not add course creator with user id $addcreator!");
60 } else if (!empty($frm->remove) and !empty($frm->removeselect)) {
61 foreach ($frm->removeselect as $removecreator) {
62 if (! remove_creator($removecreator)) {
63 error("Could not remove course creator with user id $removecreator!");
66 } else if (!empty($frm->showall)) {
67 unset($frm->searchtext);
68 $frm->previoussearch = 0;
72 /// Is there a current search?
73 $previoussearch = (!empty($frm->search) or (isset($frm->previoussearch) && $frm->previoussearch == 1)) ;
76 /// Get all existing creators
77 if (! $creators = get_creators()) {
78 $creators = array();
81 $creatorsarray = array();
82 foreach ($creators as $creator) {
83 $creatorsarray[] = $creator->id;
85 $creatorlist = implode(',', $creatorsarray);
87 unset($creatorarray);
90 /// Get search results excluding any current admins
91 if (!empty($frm->searchtext) and $previoussearch) {
92 $searchusers = get_users(true, $frm->searchtext, true, $creatorlist, 'firstname ASC, lastname ASC',
93 '', '', 0, 99999, 'id, firstname, lastname, email');
94 $usercount = get_users(false, '', true, $creatorlist);
97 /// If no search results then get potential users excluding current creators
98 if (empty($searchusers)) {
99 if (!$users = get_users(true, '', true, $creatorlist, 'firstname ASC, lastname ASC', '', '',
100 0, 99999, 'id, firstname, lastname, email') ) {
101 $users = array();
103 $usercount = count($users);
106 $searchtext = (isset($frm->searchtext)) ? $frm->searchtext : "";
107 $previoussearch = ($previoussearch) ? '1' : '0';
109 include('./creators.html');
111 print_footer();