Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/manual/manage.php
Go to the documentation of this file.
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 require_once($CFG->dirroot.'/enrol/manual/locallib.php');
00028 
00029 $enrolid      = required_param('enrolid', PARAM_INT);
00030 $roleid       = optional_param('roleid', -1, PARAM_INT);
00031 $extendperiod = optional_param('extendperiod', 0, PARAM_INT);
00032 $extendbase   = optional_param('extendbase', 3, PARAM_INT);
00033 
00034 $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST);
00035 $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
00036 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
00037 
00038 require_login($course);
00039 require_capability('enrol/manual:enrol', $context);
00040 require_capability('enrol/manual:manage', $context);
00041 require_capability('enrol/manual:unenrol', $context);
00042 
00043 if ($roleid < 0) {
00044     $roleid = $instance->roleid;
00045 }
00046 $roles = get_assignable_roles($context);
00047 $roles = array('0'=>get_string('none')) + $roles;
00048 
00049 if (!isset($roles[$roleid])) {
00050     // weird - security always first!
00051     $roleid = 0;
00052 }
00053 
00054 if (!$enrol_manual = enrol_get_plugin('manual')) {
00055     throw new coding_exception('Can not instantiate enrol_manual');
00056 }
00057 
00058 $instancename = $enrol_manual->get_instance_name($instance);
00059 
00060 $PAGE->set_url('/enrol/manual/manage.php', array('enrolid'=>$instance->id));
00061 $PAGE->set_pagelayout('admin');
00062 $PAGE->set_title($enrol_manual->get_instance_name($instance));
00063 $PAGE->set_heading($course->fullname);
00064 navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id'=>$course->id)));
00065 
00066 // Create the user selector objects.
00067 $options = array('enrolid' => $enrolid);
00068 
00069 $potentialuserselector = new enrol_manual_potential_participant('addselect', $options);
00070 $currentuserselector = new enrol_manual_current_participant('removeselect', $options);
00071 
00072 // Build the list of options for the enrolment period dropdown.
00073 $unlimitedperiod = get_string('unlimited');
00074 $periodmenu = array();
00075 for ($i=1; $i<=365; $i++) {
00076     $seconds = $i * 86400;
00077     $periodmenu[$seconds] = get_string('numdays', '', $i);
00078 }
00079 // Work out the apropriate default setting.
00080 if ($extendperiod) {
00081     $defaultperiod = $extendperiod;
00082 } else {
00083     $defaultperiod = $instance->enrolperiod;
00084 }
00085 
00086 // Build the list of options for the starting from dropdown.
00087 $timeformat = get_string('strftimedatefullshort');
00088 $today = time();
00089 $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
00090 
00091 // enrolment start
00092 $basemenu = array();
00093 if ($course->startdate > 0) {
00094     $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')';
00095 }
00096 $basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
00097 
00098 // process add and removes
00099 if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
00100     $userstoassign = $potentialuserselector->get_selected_users();
00101     if (!empty($userstoassign)) {
00102         foreach($userstoassign as $adduser) {
00103             switch($extendbase) {
00104                 case 2:
00105                     $timestart = $course->startdate;
00106                     break;
00107                 case 3:
00108                 default:
00109                     $timestart = $today;
00110                     break;
00111             }
00112 
00113             if ($extendperiod <= 0) {
00114                 $timeend = 0;
00115             } else {
00116                 $timeend = $timestart + $extendperiod;
00117             }
00118             $enrol_manual->enrol_user($instance, $adduser->id, $roleid, $timestart, $timeend);
00119             add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
00120         }
00121 
00122         $potentialuserselector->invalidate_selected_users();
00123         $currentuserselector->invalidate_selected_users();
00124 
00125         //TODO: log
00126     }
00127 }
00128 
00129 // Process incoming role unassignments
00130 if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
00131     $userstounassign = $currentuserselector->get_selected_users();
00132     if (!empty($userstounassign)) {
00133         foreach($userstounassign as $removeuser) {
00134             $enrol_manual->unenrol_user($instance, $removeuser->id);
00135             add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
00136         }
00137 
00138         $potentialuserselector->invalidate_selected_users();
00139         $currentuserselector->invalidate_selected_users();
00140 
00141         //TODO: log
00142     }
00143 }
00144 
00145 
00146 echo $OUTPUT->header();
00147 echo $OUTPUT->heading($instancename);
00148 
00149 ?>
00150 <form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div>
00151   <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
00152 
00153   <table summary="" class="roleassigntable generaltable generalbox boxaligncenter" cellspacing="0">
00154     <tr>
00155       <td id="existingcell">
00156           <p><label for="removeselect"><?php print_string('enrolledusers', 'enrol'); ?></label></p>
00157           <?php $currentuserselector->display() ?>
00158       </td>
00159       <td id="buttonscell">
00160           <div id="addcontrols">
00161               <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
00162 
00163               <div class="enroloptions">
00164 
00165               <p><label for="roleid"><?php print_string('assignrole', 'enrol_manual') ?></label><br />
00166               <?php echo html_writer::select($roles, 'roleid', $roleid, false); ?></p>
00167 
00168               <p><label for="extendperiod"><?php print_string('enrolperiod', 'enrol') ?></label><br />
00169               <?php echo html_writer::select($periodmenu, 'extendperiod', $defaultperiod, $unlimitedperiod); ?></p>
00170 
00171               <p><label for="extendbase"><?php print_string('startingfrom') ?></label><br />
00172               <?php echo html_writer::select($basemenu, 'extendbase', $extendbase, false); ?></p>
00173 
00174               </div>
00175           </div>
00176 
00177           <div id="removecontrols">
00178               <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
00179           </div>
00180       </td>
00181       <td id="potentialcell">
00182           <p><label for="addselect"><?php print_string('enrolcandidates', 'enrol'); ?></label></p>
00183           <?php $potentialuserselector->display() ?>
00184       </td>
00185     </tr>
00186   </table>
00187 </div></form>
00188 <?php
00189 
00190 
00191 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations