|
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 00026 require('../config.php'); 00027 00028 $id = required_param('id', PARAM_INT); // course id 00029 $action = optional_param('action', '', PARAM_ACTION); 00030 $instanceid = optional_param('instance', 0, PARAM_INT); 00031 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00032 00033 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); 00034 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); 00035 00036 if ($course->id == SITEID) { 00037 redirect("$CFG->wwwroot/"); 00038 } 00039 00040 require_login($course); 00041 require_capability('moodle/course:enrolreview', $context); 00042 00043 $canconfig = has_capability('moodle/course:enrolconfig', $context); 00044 00045 $PAGE->set_url('/enrol/instances.php', array('id'=>$course->id)); 00046 $PAGE->set_pagelayout('admin'); 00047 $PAGE->set_title(get_string('enrolmentinstances', 'enrol')); 00048 $PAGE->set_heading($course->fullname); 00049 00050 $instances = enrol_get_instances($course->id, false); 00051 $plugins = enrol_get_plugins(false); 00052 00053 if ($canconfig and $action and confirm_sesskey()) { 00054 if (isset($instances[$instanceid]) and isset($plugins[$instances[$instanceid]->enrol])) { 00055 if ($action === 'up') { 00056 $order = array_keys($instances); 00057 $order = array_flip($order); 00058 $pos = $order[$instanceid]; 00059 if ($pos > 0) { 00060 $switch = $pos - 1; 00061 $resorted = array_values($instances); 00062 $temp = $resorted[$pos]; 00063 $resorted[$pos] = $resorted[$switch]; 00064 $resorted[$switch] = $temp; 00065 // now update db sortorder 00066 foreach ($resorted as $sortorder=>$instance) { 00067 if ($instance->sortorder != $sortorder) { 00068 $instance->sortorder = $sortorder; 00069 $DB->update_record('enrol', $instance); 00070 } 00071 } 00072 } 00073 redirect($PAGE->url); 00074 00075 } else if ($action === 'down') { 00076 $order = array_keys($instances); 00077 $order = array_flip($order); 00078 $pos = $order[$instanceid]; 00079 if ($pos < count($instances) - 1) { 00080 $switch = $pos + 1; 00081 $resorted = array_values($instances); 00082 $temp = $resorted[$pos]; 00083 $resorted[$pos] = $resorted[$switch]; 00084 $resorted[$switch] = $temp; 00085 // now update db sortorder 00086 foreach ($resorted as $sortorder=>$instance) { 00087 if ($instance->sortorder != $sortorder) { 00088 $instance->sortorder = $sortorder; 00089 $DB->update_record('enrol', $instance); 00090 } 00091 } 00092 } 00093 redirect($PAGE->url); 00094 00095 } else if ($action === 'delete') { 00096 $instance = $instances[$instanceid]; 00097 $plugin = $plugins[$instance->enrol]; 00098 00099 if ($confirm) { 00100 $plugin->delete_instance($instance); 00101 redirect($PAGE->url); 00102 } 00103 00104 echo $OUTPUT->header(); 00105 $yesurl = new moodle_url('/enrol/instances.php', array('id'=>$course->id, 'action'=>'delete', 'instance'=>$instance->id, 'confirm'=>1,'sesskey'=>sesskey())); 00106 $displayname = $plugin->get_instance_name($instance); 00107 $users = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id)); 00108 $message = get_string('deleteinstanceconfirm', 'enrol', array('name'=>$displayname, 'users'=>$users)); 00109 echo $OUTPUT->confirm($message, $yesurl, $PAGE->url); 00110 echo $OUTPUT->footer(); 00111 die(); 00112 00113 } else if ($action === 'disable') { 00114 $instance = $instances[$instanceid]; 00115 $plugin = $plugins[$instance->enrol]; 00116 if ($instance->status != ENROL_INSTANCE_DISABLED) { 00117 $plugin->update_status($instance, ENROL_INSTANCE_DISABLED); 00118 redirect($PAGE->url); 00119 } 00120 00121 } else if ($action === 'enable') { 00122 $instance = $instances[$instanceid]; 00123 $plugin = $plugins[$instance->enrol]; 00124 if ($instance->status != ENROL_INSTANCE_ENABLED) { 00125 $plugin->update_status($instance, ENROL_INSTANCE_ENABLED); 00126 redirect($PAGE->url); 00127 } 00128 } 00129 } 00130 } 00131 00132 00133 echo $OUTPUT->header(); 00134 echo $OUTPUT->heading(get_string('enrolmentinstances', 'enrol')); 00135 00136 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal'); 00137 00138 // display strings 00139 $strup = get_string('up'); 00140 $strdown = get_string('down'); 00141 $strdelete = get_string('delete'); 00142 $strenable = get_string('enable'); 00143 $strdisable = get_string('disable'); 00144 $strmanage = get_string('manageinstance', 'enrol'); 00145 00146 $table = new html_table(); 00147 $table->head = array(get_string('name'), get_string('users'), $strup.'/'.$strdown, get_string('edit')); 00148 $table->align = array('left', 'center', 'center', 'center'); 00149 $table->width = '100%'; 00150 $table->data = array(); 00151 00152 // iterate through enrol plugins and add to the display table 00153 $updowncount = 1; 00154 $icount = count($instances); 00155 $url = new moodle_url('/enrol/instances.php', array('sesskey'=>sesskey(), 'id'=>$course->id)); 00156 foreach ($instances as $instance) { 00157 if (!isset($plugins[$instance->enrol])) { 00158 continue; 00159 } 00160 $plugin = $plugins[$instance->enrol]; 00161 00162 $displayname = $plugin->get_instance_name($instance); 00163 if (!enrol_is_enabled($instance->enrol) or $instance->status != ENROL_INSTANCE_ENABLED) { 00164 $displayname = html_writer::tag('span', $displayname, array('class'=>'dimmed_text')); 00165 } 00166 00167 $users = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id)); 00168 00169 $updown = array(); 00170 $edit = array(); 00171 00172 if ($canconfig) { 00173 // up/down link 00174 $updown = ''; 00175 if ($updowncount > 1) { 00176 $aurl = new moodle_url($url, array('action'=>'up', 'instance'=>$instance->id)); 00177 $updown[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/up'), 'alt'=>$strup, 'class'=>'smallicon'))); 00178 } else { 00179 $updown[] = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('spacer'), 'alt'=>'', 'class'=>'smallicon')); 00180 } 00181 if ($updowncount < $icount) { 00182 $aurl = new moodle_url($url, array('action'=>'down', 'instance'=>$instance->id)); 00183 $updown[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/down'), 'alt'=>$strdown, 'class'=>'smallicon'))); 00184 } else { 00185 $updown[] = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('spacer'), 'alt'=>'', 'class'=>'smallicon')); 00186 } 00187 ++$updowncount; 00188 00189 // edit links 00190 if ($plugin->instance_deleteable($instance)) { 00191 $aurl = new moodle_url($url, array('action'=>'delete', 'instance'=>$instance->id)); 00192 $edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>$strdelete, 'class'=>'smallicon'))); 00193 } 00194 00195 if (enrol_is_enabled($instance->enrol)) { 00196 if ($instance->status == ENROL_INSTANCE_ENABLED) { 00197 $aurl = new moodle_url($url, array('action'=>'disable', 'instance'=>$instance->id)); 00198 $edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/hide'), 'alt'=>$strdisable, 'class'=>'smallicon'))); 00199 } else if ($instance->status == ENROL_INSTANCE_DISABLED) { 00200 $aurl = new moodle_url($url, array('action'=>'enable', 'instance'=>$instance->id)); 00201 $edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>$strenable, 'class'=>'smallicon'))); 00202 } else { 00203 // plugin specific state - do not mess with it! 00204 $edit[] = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>'', 'class'=>'smallicon')); 00205 } 00206 00207 } 00208 } 00209 00210 // link to instance management 00211 if (enrol_is_enabled($instance->enrol)) { 00212 if ($icons = $plugin->get_action_icons($instance)) { 00213 $edit = array_merge($edit, $icons); 00214 } 00215 } 00216 00217 // add a row to the table 00218 $table->data[] = array($displayname, $users, implode(' ', $updown), implode(' ', $edit)); 00219 00220 } 00221 echo html_writer::table($table); 00222 00223 // access security is in each plugin 00224 $candidates = array(); 00225 foreach (enrol_get_plugins(true) as $name=>$plugin) { 00226 if (!$link = $plugin->get_newinstance_link($course->id)) { 00227 continue; 00228 } 00229 $candidates[$link->out(false)] = get_string('pluginname', 'enrol_'.$name); 00230 } 00231 00232 if ($candidates) { 00233 $select = new url_select($candidates); 00234 $select->set_label(get_string('addinstance', 'enrol')); 00235 echo $OUTPUT->render($select); 00236 } 00237 00238 echo $OUTPUT->box_end(); 00239 00240 echo $OUTPUT->footer();