Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mnet/service/enrol/host.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 
00031 require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
00032 require_once($CFG->libdir.'/adminlib.php');
00033 require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
00034 
00035 $hostid   = required_param('id', PARAM_INT); // remote host id
00036 $usecache = optional_param('usecache', true, PARAM_BOOL); // use cached list of courses
00037 
00038 admin_externalpage_setup('mnetenrol', '', array('id'=>$hostid, 'usecache'=>1),
00039         new moodle_url('/mnet/service/enrol/host.php'));
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 
00056 if (!$usecache) {
00057     // our local database will be changed
00058     require_sesskey();
00059 }
00060 $courses = $service->get_remote_courses($host->id, $usecache);
00061 if (is_string($courses)) {
00062     print_error('fetchingcourses', 'mnetservice_enrol', '', null, $service->format_error_message($courses));
00063 }
00064 
00065 echo $OUTPUT->header();
00066 echo $OUTPUT->heading(get_string('availablecourseson', 'mnetservice_enrol', s($host->hostname)));
00067 if (empty($courses)) {
00068     $a = (object)array('hostname' => s($host->hostname), 'hosturl' => s($host->hosturl));
00069     echo $OUTPUT->box(get_string('availablecoursesonnone','mnetservice_enrol', $a), 'noticebox');
00070     if ($usecache) {
00071         echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('usecache'=>0, 'sesskey'=>sesskey())),
00072                                     get_string('refetch', 'mnetservice_enrol'), 'get');
00073     }
00074     echo $OUTPUT->footer();
00075     die();
00076 }
00077 
00078 $table = new html_table();
00079 $table->head = array(
00080     get_string('shortnamecourse'),
00081     get_string('fullnamecourse'),
00082     get_string('role'),
00083     get_string('action')
00084 );
00085 $table->attributes['class'] = 'generaltable remotecourses';
00086 $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/course'), 'alt' => get_string('category')));
00087 $prevcat = null;
00088 foreach ($courses as $course) {
00089     $course = (object)$course;
00090     if ($prevcat !== $course->categoryid) {
00091         $row = new html_table_row();
00092         $cell = new html_table_cell($icon . s($course->categoryname));
00093         $cell->header = true;
00094         $cell->attributes['class'] = 'categoryname';
00095         $cell->colspan = 4;
00096         $row->cells = array($cell);
00097         $table->data[] = $row;
00098         $prevcat = $course->categoryid;
00099     }
00100     $editbtn = $OUTPUT->single_button(new moodle_url('/mnet/service/enrol/course.php',
00101                                       array('host'=>$host->id, 'course'=>$course->id, 'usecache'=>0, 'sesskey'=>sesskey())),
00102                                       get_string('editenrolments', 'mnetservice_enrol'), 'get');
00103     $row = new html_table_row();
00104     $row->cells = array(
00105         s($course->shortname),
00106         s($course->fullname),
00107         s($course->rolename),
00108         $editbtn
00109     );
00110     $table->data[] = $row;
00111 }
00112 echo html_writer::table($table);
00113 
00114 if ($usecache) {
00115     echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('usecache'=>0, 'sesskey'=>sesskey())),
00116                                 get_string('refetch', 'mnetservice_enrol'), 'get');
00117 }
00118 
00119 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations