Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mnet/service/enrol/course.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
00028 require_once($CFG->libdir.'/adminlib.php');
00029 require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
00030 
00031 require_sesskey();
00032 
00033 $hostid   = required_param('host', PARAM_INT); // remote host id in our mnet_host table
00034 $courseid = required_param('course', PARAM_INT); // id of the course in our cache table
00035 $usecache = optional_param('usecache', true, PARAM_BOOL); // use cached list of enrolments
00036 
00037 admin_externalpage_setup('mnetenrol', '', array('host'=>$hostid, 'course'=>$courseid, 'usecache'=>1, 'sesskey'=>sesskey()),
00038                          new moodle_url('/mnet/service/enrol/course.php'));
00039 
00040 $service = mnetservice_enrol::get_instance();
00041 
00042 if (!$service->is_available()) {
00043     echo $OUTPUT->box(get_string('mnetdisabled','mnet'), 'noticebox');
00044     echo $OUTPUT->footer();
00045     die();
00046 }
00047 
00048 // remote hosts that may publish remote enrolment service and we are subscribed to it
00049 $hosts = $service->get_remote_publishers();
00050 
00051 if (empty($hosts[$hostid])) {
00052     print_error('wearenotsubscribedtothishost', 'mnetservice_enrol');
00053 }
00054 $host   = $hosts[$hostid];
00055 $course = $DB->get_record('mnetservice_enrol_courses', array('id'=>$courseid, 'hostid'=>$host->id), '*', MUST_EXIST);
00056 
00057 echo $OUTPUT->header();
00058 
00059 // course name
00060 $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/course'), 'alt' => get_string('category')));
00061 echo $OUTPUT->heading($icon . s($course->fullname));
00062 
00063 // collapsible course summary
00064 if (!empty($course->summary)) {
00065     unset($options);
00066     $options->trusted = false;
00067     $options->para    = false;
00068     $options->filter  = false;
00069     $options->noclean = false;
00070     $options->overflowdiv = true;
00071     print_collapsible_region_start('remotecourse summary', 'remotecourse-summary', get_string('coursesummary'), false, true);
00072     echo format_text($course->summary, $course->summaryformat, $options);
00073     print_collapsible_region_end();
00074 }
00075 
00076 $error = '';
00077 
00078 $lastfetchenrolments = get_config('mnetservice_enrol', 'lastfetchenrolments');
00079 if (!$usecache or empty($lastfetchenrolments) or (time()-$lastfetchenrolments > 600)) {
00080     // fetch fresh data from remote if we just came from the course selection screen
00081     // or every 10 minutes
00082     $usecache = false;
00083     $result = $service->req_course_enrolments($host->id, $course->remoteid, $usecache);
00084     if ($result !== true) {
00085         $error .= $service->format_error_message($result);
00086     }
00087 }
00088 
00089 // user selectors
00090 $currentuserselector = new mnetservice_enrol_existing_users_selector('removeselect', array('hostid'=>$host->id, 'remotecourseid'=>$course->remoteid));
00091 $potentialuserselector = new mnetservice_enrol_potential_users_selector('addselect', array('hostid'=>$host->id, 'remotecourseid'=>$course->remoteid));
00092 
00093 // process incoming enrol request
00094 if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
00095     $userstoassign = $potentialuserselector->get_selected_users();
00096     if (!empty($userstoassign)) {
00097         foreach($userstoassign as $adduser) {
00098             $user = $DB->get_record('user', array('id'=>$adduser->id));
00099             $result = $service->req_enrol_user($user, $course);
00100             if ($result !== true) {
00101                 $error .= $service->format_error_message($result);
00102             }
00103         }
00104 
00105         $potentialuserselector->invalidate_selected_users();
00106         $currentuserselector->invalidate_selected_users();
00107     }
00108 }
00109 
00110 // process incoming unenrol request
00111 if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
00112     $userstounassign = $currentuserselector->get_selected_users();
00113     if (!empty($userstounassign)) {
00114         foreach($userstounassign as $removeuser) {
00115             $user = $DB->get_record('user', array('id'=>$removeuser->id));
00116             $result = $service->req_unenrol_user($user, $course);
00117             if ($result !== true) {
00118                 $error .= $service->format_error_message($result);
00119             }
00120         }
00121 
00122         $potentialuserselector->invalidate_selected_users();
00123         $currentuserselector->invalidate_selected_users();
00124     }
00125 }
00126 
00127 if (!empty($error)) {
00128     echo $OUTPUT->box($error, 'generalbox error');
00129 }
00130 
00131 // print form to enrol our students
00132 ?>
00133 <form id="assignform" method="post" action="<?php echo $PAGE->url ?>">
00134 <div>
00135   <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
00136   <input type="hidden" name="hostid" value="<?php echo $host->id ?>" />
00137   <input type="hidden" name="courseid" value="<?php echo $course->id ?>" />
00138 
00139   <table summary="" class="roleassigntable generaltable generalbox boxaligncenter" cellspacing="0">
00140     <tr>
00141       <td id="existingcell">
00142           <p><label for="removeselect"><?php print_string('enrolledusers', 'enrol'); ?></label></p>
00143           <?php $currentuserselector->display() ?>
00144       </td>
00145       <td id="buttonscell">
00146           <div id="addcontrols">
00147               <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
00148 
00149               <div class="enroloptions">
00150                   <p><?php echo get_string('assignrole', 'role') .': '. s($course->rolename); ?></p>
00151               </div>
00152 
00153           </div>
00154 
00155           <div id="removecontrols">
00156               <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
00157           </div>
00158       </td>
00159       <td id="potentialcell">
00160           <p><label for="addselect"><?php print_string('enrolcandidates', 'enrol'); ?></label></p>
00161           <?php $potentialuserselector->display() ?>
00162       </td>
00163     </tr>
00164   </table>
00165 </div>
00166 </form>
00167 <?php
00168 
00169 // eventually display other enrolments of our users (manual, self etc.) in the remote course
00170 $sql = "SELECT e.id,e.enroltype AS plugin, u.firstname, u.lastname, u.email, u.id AS userid,
00171                e.enroltime AS timemodified, e.rolename
00172           FROM {mnetservice_enrol_enrolments} e
00173           JOIN {user} u ON u.id = e.userid
00174          WHERE e.hostid = ? AND e.remotecourseid = ? AND e.enroltype != 'mnet'
00175       ORDER BY u.lastname, u.firstname";
00176 $params = array($host->id, $course->remoteid);
00177 
00178 if ($enrolments = $DB->get_records_sql($sql, $params)) {
00179     echo $OUTPUT->heading(get_string('otherenrolledusers', 'mnetservice_enrol'), 3);
00180 
00181     $table = new html_table();
00182     $table->attributes['class'] = 'generaltable otherenrolledusers';
00183     $table->head = array(get_string('fullnameuser'), get_string('role'), get_string('plugin'));
00184     foreach ($enrolments as $enrolleduser) {
00185         $table->data[] = array(fullname($enrolleduser), s($enrolleduser->rolename), s($enrolleduser->plugin));
00186     }
00187     echo html_writer::table($table);
00188 }
00189 
00190 if ($usecache) {
00191     echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('usecache'=>0, 'sesskey'=>sesskey())),
00192                                 get_string('refetch', 'mnetservice_enrol'), 'get');
00193 }
00194 
00195 echo $OUTPUT->single_button(new moodle_url('/mnet/service/enrol/host.php', array('id'=>$host->id)),
00196                             get_string('availablecourseson', 'mnetservice_enrol', s($host->hostname)), 'get');
00197 
00198 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations