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");
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 (
36 foreach ($stringstoload as $stringtoload){
37 $strstringtoload = "str" . $stringtoload;
38 $
$strstringtoload = get_string($stringtoload);
41 print_header("$site->shortname: $strassigncreators",
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%");
51 /// A form was submitted so process the input
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()) {
81 $creatorsarray = array();
82 foreach ($creators as $creator) {
83 $creatorsarray[] = $creator->id
;
85 $creatorlist = implode(',', $creatorsarray);
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') ) {
103 $usercount = count($users);
106 $searchtext = (isset($frm->searchtext
)) ?
$frm->searchtext
: "";
107 $previoussearch = ($previoussearch) ?
'1' : '0';
109 include('./creators.html');