|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 require_once(dirname(__FILE__) . '/../../../config.php'); 00028 require_once($CFG->libdir.'/adminlib.php'); 00029 00030 $action = optional_param('action', '', PARAM_ACTION); 00031 00032 $syscontext = get_context_instance(CONTEXT_SYSTEM); 00033 00034 require_login(); 00035 admin_externalpage_setup('toolunsuproles'); // checks permissions specified in settings.php 00036 00037 if ($action === 'delete') { 00038 $contextlevel = required_param('contextlevel', PARAM_INT); 00039 $roleid = required_param('roleid', PARAM_INT); 00040 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00041 00042 $role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST); 00043 00044 if ($confirm and confirm_sesskey()) { 00045 $sql = "SELECT ra.* 00046 FROM {role_assignments} ra 00047 JOIN {context} c ON c.id = ra.contextid 00048 LEFT JOIN {role_context_levels} rcl ON (rcl.roleid = ra.roleid AND rcl.contextlevel = c.contextlevel) 00049 WHERE rcl.id IS NULL AND ra.roleid = :roleid AND c.contextlevel = :contextlevel"; 00050 $ras = $DB->get_records_sql($sql, array('roleid'=>$roleid, 'contextlevel'=>$contextlevel)); 00051 foreach ($ras as $ra) { 00052 if (!empty($ra->component)) { 00053 //bad luck, we can not mess with plugin ras! 00054 //TODO: explain why not possible to remove ras 00055 continue; 00056 } 00057 role_unassign($ra->roleid, $ra->userid, $ra->contextid); 00058 } 00059 redirect($PAGE->url); 00060 } 00061 //show confirmation 00062 echo $OUTPUT->header(); 00063 $yesurl = new moodle_url($PAGE->url, array('roleid'=>$roleid, 'contextlevel'=>$contextlevel, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey())); 00064 $levelname = get_contextlevel_name($contextlevel); 00065 $rolename = format_string($role->name); 00066 $message = get_string('confirmdelete', 'tool_unsuproles', array('level'=>$levelname, 'role'=>$rolename)); 00067 echo $OUTPUT->confirm($message, $yesurl, $PAGE->url); 00068 echo $OUTPUT->footer(); 00069 die(); 00070 } 00071 00072 00073 echo $OUTPUT->header(); 00074 echo $OUTPUT->heading(get_string('pluginname', 'tool_unsuproles')); 00075 00076 $sql = "SELECT r.id AS roleid, c.contextlevel, r.sortorder, COUNT(ra.id) AS racount 00077 FROM {role} r 00078 JOIN {role_assignments} ra ON ra.roleid = r.id 00079 JOIN {context} c ON c.id = ra.contextid 00080 LEFT JOIN {role_context_levels} rcl ON (rcl.roleid = r.id AND rcl.contextlevel = c.contextlevel) 00081 WHERE rcl.id IS NULL 00082 GROUP BY r.id, c.contextlevel, r.sortorder 00083 ORDER BY c.contextlevel ASC, r.sortorder ASC"; 00084 //print the overview table 00085 00086 $problems = array(); 00087 $rs = $DB->get_recordset_sql($sql); 00088 foreach ($rs as $problem) { 00089 $problems[] = $problem; 00090 } 00091 $rs->close(); 00092 00093 if (!$problems) { 00094 echo $OUTPUT->notification(get_string('noprolbems', 'tool_unsuproles'), 'notifysuccess'); 00095 } else { 00096 $roles = get_all_roles(); 00097 $data = array(); 00098 foreach ($problems as $problem) { 00099 $levelname = get_contextlevel_name($problem->contextlevel); 00100 $rolename = format_string($roles[$problem->roleid]->name); 00101 //TODO: show list of users if count low 00102 $count = $problem->racount; 00103 $edit = array(); 00104 $aurl = new moodle_url('/admin/roles/define.php', array('roleid'=>$problem->roleid, 'action'=>'edit')); 00105 $edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>get_string('edit'), 'class'=>'smallicon'))); 00106 $aurl = new moodle_url($PAGE->url, array('roleid'=>$problem->roleid, 'contextlevel'=>$problem->contextlevel, 'action'=>'delete')); 00107 $edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>get_string('delete'), 'class'=>'smallicon'))); 00108 $data[] = array($levelname, $rolename, $count, implode(' ', $edit)); 00109 } 00110 $table = new html_table(); 00111 $table->head = array(get_string('contextlevel', 'tool_unsuproles'), get_string('role'), get_string('count', 'tool_unsuproles'), get_string('edit')); 00112 $table->size = array('40%', '40%', '10%', '10%'); 00113 $table->align = array('left', 'left', 'center', 'center'); 00114 $table->width = '90%'; 00115 $table->data = $data; 00116 echo html_writer::table($table); 00117 } 00118 00119 echo $OUTPUT->footer();