|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00028 require('../../config.php'); 00029 require_once('edit_form.php'); 00030 00031 $courseid = required_param('courseid', PARAM_INT); 00032 00033 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 00034 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); 00035 00036 require_login($course); 00037 require_capability('enrol/manual:config', $context); 00038 00039 $PAGE->set_url('/enrol/manual/edit.php', array('courseid'=>$course->id)); 00040 $PAGE->set_pagelayout('admin'); 00041 00042 $return = new moodle_url('/enrol/instances.php', array('id'=>$course->id)); 00043 if (!enrol_is_enabled('manual')) { 00044 redirect($return); 00045 } 00046 00047 $plugin = enrol_get_plugin('manual'); 00048 00049 if ($instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'enrol'=>'manual'), 'id ASC')) { 00050 $instance = array_shift($instances); 00051 if ($instances) { 00052 // oh - we allow only one instance per course!! 00053 foreach ($instances as $del) { 00054 $plugin->delete_instance($del); 00055 } 00056 } 00057 } else { 00058 require_capability('moodle/course:enrolconfig', $context); 00059 // no instance yet, we have to add new instance 00060 navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); 00061 $instance = new stdClass(); 00062 $instance->id = null; 00063 $instance->courseid = $course->id; 00064 } 00065 00066 $mform = new enrol_manual_edit_form(NULL, array($instance, $plugin, $context)); 00067 00068 if ($mform->is_cancelled()) { 00069 redirect($return); 00070 00071 } else if ($data = $mform->get_data()) { 00072 if ($instance->id) { 00073 $reset = ($instance->status != $data->status); 00074 00075 $instance->status = $data->status; 00076 $instance->enrolperiod = $data->enrolperiod; 00077 $instance->roleid = $data->roleid; 00078 $instance->timemodified = time(); 00079 $DB->update_record('enrol', $instance); 00080 00081 if ($reset) { 00082 $context->mark_dirty(); 00083 } 00084 00085 } else { 00086 $fields = array('status'=>$data->status, 'enrolperiod'=>$data->enrolperiod, 'roleid'=>$data->roleid); 00087 $plugin->add_instance($course, $fields); 00088 } 00089 00090 redirect($return); 00091 } 00092 00093 $PAGE->set_title(get_string('pluginname', 'enrol_manual')); 00094 $PAGE->set_heading($course->fullname); 00095 00096 echo $OUTPUT->header(); 00097 echo $OUTPUT->heading(get_string('pluginname', 'enrol_manual')); 00098 $mform->display(); 00099 echo $OUTPUT->footer();