|
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 $instanceid = optional_param('id', 0, PARAM_INT); // instanceid 00033 00034 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 00035 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); 00036 00037 require_login($course); 00038 require_capability('enrol/self:config', $context); 00039 00040 $PAGE->set_url('/enrol/self/edit.php', array('courseid'=>$course->id, 'id'=>$instanceid)); 00041 $PAGE->set_pagelayout('admin'); 00042 00043 $return = new moodle_url('/enrol/instances.php', array('id'=>$course->id)); 00044 if (!enrol_is_enabled('self')) { 00045 redirect($return); 00046 } 00047 00048 $plugin = enrol_get_plugin('self'); 00049 00050 if ($instanceid) { 00051 $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'self', 'id'=>$instanceid), '*', MUST_EXIST); 00052 } else { 00053 require_capability('moodle/course:enrolconfig', $context); 00054 // no instance yet, we have to add new instance 00055 navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); 00056 $instance = new stdClass(); 00057 $instance->id = null; 00058 $instance->courseid = $course->id; 00059 } 00060 00061 $mform = new enrol_self_edit_form(NULL, array($instance, $plugin, $context)); 00062 00063 if ($mform->is_cancelled()) { 00064 redirect($return); 00065 00066 } else if ($data = $mform->get_data()) { 00067 if ($instance->id) { 00068 $reset = ($instance->status != $data->status); 00069 00070 $instance->status = $data->status; 00071 $instance->name = $data->name; 00072 $instance->password = $data->password; 00073 $instance->customint1 = $data->customint1; 00074 $instance->customint2 = $data->customint2; 00075 $instance->customint3 = $data->customint3; 00076 $instance->customint4 = $data->customint4; 00077 $instance->customtext1 = $data->customtext1; 00078 $instance->roleid = $data->roleid; 00079 $instance->enrolperiod = $data->enrolperiod; 00080 $instance->enrolstartdate = $data->enrolstartdate; 00081 $instance->enrolenddate = $data->enrolenddate; 00082 $instance->timemodified = time(); 00083 $DB->update_record('enrol', $instance); 00084 00085 if ($reset) { 00086 $context->mark_dirty(); 00087 } 00088 00089 } else { 00090 $fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2, 00091 'customint3'=>$data->customint3, 'customint4'=>$data->customint4, 'customtext1'=>$data->customtext1, 00092 'roleid'=>$data->roleid, 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate); 00093 $plugin->add_instance($course, $fields); 00094 } 00095 00096 redirect($return); 00097 } 00098 00099 $PAGE->set_heading($course->fullname); 00100 $PAGE->set_title(get_string('pluginname', 'enrol_self')); 00101 00102 echo $OUTPUT->header(); 00103 echo $OUTPUT->heading(get_string('pluginname', 'enrol_self')); 00104 $mform->display(); 00105 echo $OUTPUT->footer();