[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Adds new instance of enrol_manual to specified course 19 * or edits current instance. 20 * 21 * @package enrol_manual 22 * @copyright 2010 Petr Skoda {@link http://skodak.org} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require('../../config.php'); 27 require_once ('edit_form.php'); 28 29 $courseid = required_param('courseid', PARAM_INT); 30 31 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 32 $context = context_course::instance($course->id, MUST_EXIST); 33 34 require_login($course); 35 require_capability('enrol/manual:config', $context); 36 37 $PAGE->set_url('/enrol/manual/edit.php', array('courseid'=>$course->id)); 38 $PAGE->set_pagelayout('admin'); 39 40 $return = new moodle_url('/enrol/instances.php', array('id'=>$course->id)); 41 if (!enrol_is_enabled('manual')) { 42 redirect($return); 43 } 44 45 $plugin = enrol_get_plugin('manual'); 46 47 if ($instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'enrol'=>'manual'), 'id ASC')) { 48 $instance = array_shift($instances); 49 if ($instances) { 50 // Oh - we allow only one instance per course!! 51 foreach ($instances as $del) { 52 $plugin->delete_instance($del); 53 } 54 } 55 // Merge these two settings to one value for the single selection element. 56 if ($instance->notifyall and $instance->expirynotify) { 57 $instance->expirynotify = 2; 58 } 59 unset($instance->notifyall); 60 61 } else { 62 require_capability('moodle/course:enrolconfig', $context); 63 // No instance yet, we have to add new instance. 64 navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); 65 $instance = new stdClass(); 66 $instance->id = null; 67 $instance->courseid = $course->id; 68 $instance->expirynotify = $plugin->get_config('expirynotify'); 69 $instance->expirythreshold = $plugin->get_config('expirythreshold'); 70 } 71 72 $mform = new enrol_manual_edit_form(null, array($instance, $plugin, $context)); 73 74 if ($mform->is_cancelled()) { 75 redirect($return); 76 77 } else if ($data = $mform->get_data()) { 78 if ($data->expirynotify == 2) { 79 $data->expirynotify = 1; 80 $data->notifyall = 1; 81 } else { 82 $data->notifyall = 0; 83 } 84 if (!$data->expirynotify) { 85 // Keep previous/default value of disabled expirythreshold option. 86 $data->expirythreshold = $instance->expirythreshold; 87 } 88 if ($instance->id) { 89 $instance->roleid = $data->roleid; 90 $instance->enrolperiod = $data->enrolperiod; 91 $instance->expirynotify = $data->expirynotify; 92 $instance->notifyall = $data->notifyall; 93 $instance->expirythreshold = $data->expirythreshold; 94 $instance->timemodified = time(); 95 96 $DB->update_record('enrol', $instance); 97 98 // Use standard API to update instance status. 99 if ($instance->status != $data->status) { 100 $instance = $DB->get_record('enrol', array('id'=>$instance->id)); 101 $plugin->update_status($instance, $data->status); 102 $context->mark_dirty(); 103 } 104 105 } else { 106 $fields = array( 107 'status' => $data->status, 108 'roleid' => $data->roleid, 109 'enrolperiod' => $data->enrolperiod, 110 'expirynotify' => $data->expirynotify, 111 'notifyall' => $data->notifyall, 112 'expirythreshold' => $data->expirythreshold); 113 $plugin->add_instance($course, $fields); 114 } 115 116 redirect($return); 117 } 118 119 $PAGE->set_title(get_string('pluginname', 'enrol_manual')); 120 $PAGE->set_heading($course->fullname); 121 122 echo $OUTPUT->header(); 123 echo $OUTPUT->heading(get_string('pluginname', 'enrol_manual')); 124 $mform->display(); 125 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |