Merge branch 'w24_MDL-33635_m23_sort' of git://github.com/skodak/moodle
[moodle.git] / enrol / paypal / edit.php
blob91c89e2fe2469fec2e6259bb23718076995be360
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Adds new instance of enrol_paypal to specified course
20 * or edits current instance.
22 * @package enrol
23 * @subpackage paypal
24 * @copyright 2010 Petr Skoda {@link http://skodak.org}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require('../../config.php');
29 require_once('edit_form.php');
31 $courseid = required_param('courseid', PARAM_INT);
32 $instanceid = optional_param('id', 0, PARAM_INT); // instanceid
34 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
35 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
37 require_login($course);
38 require_capability('enrol/paypal:config', $context);
40 $PAGE->set_url('/enrol/paypal/edit.php', array('courseid'=>$course->id, 'id'=>$instanceid));
41 $PAGE->set_pagelayout('admin');
43 $return = new moodle_url('/enrol/instances.php', array('id'=>$course->id));
44 if (!enrol_is_enabled('paypal')) {
45 redirect($return);
48 $plugin = enrol_get_plugin('paypal');
50 if ($instanceid) {
51 $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'paypal', 'id'=>$instanceid), '*', MUST_EXIST);
52 } else {
53 require_capability('moodle/course:enrolconfig', $context);
54 // no instance yet, we have to add new instance
55 navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
56 $instance = new stdClass();
57 $instance->id = null;
58 $instance->courseid = $course->id;
61 $mform = new enrol_paypal_edit_form(NULL, array($instance, $plugin, $context));
63 if ($mform->is_cancelled()) {
64 redirect($return);
66 } else if ($data = $mform->get_data()) {
67 if ($instance->id) {
68 $reset = ($instance->status != $data->status);
70 $instance->status = $data->status;
71 $instance->name = $data->name;
72 $instance->cost = $data->cost;
73 $instance->currency = $data->currency;
74 $instance->roleid = $data->roleid;
75 $instance->enrolperiod = $data->enrolperiod;
76 $instance->enrolstartdate = $data->enrolstartdate;
77 $instance->enrolenddate = $data->enrolenddate;
78 $instance->timemodified = time();
79 $DB->update_record('enrol', $instance);
81 if ($reset) {
82 $context->mark_dirty();
85 } else {
86 $fields = array('status'=>$data->status, 'name'=>$data->name, 'cost'=>$data->cost, 'currency'=>$data->currency, 'roleid'=>$data->roleid,
87 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate);
88 $plugin->add_instance($course, $fields);
91 redirect($return);
94 $PAGE->set_heading($course->fullname);
95 $PAGE->set_title(get_string('pluginname', 'enrol_paypal'));
97 echo $OUTPUT->header();
98 echo $OUTPUT->heading(get_string('pluginname', 'enrol_paypal'));
99 $mform->display();
100 echo $OUTPUT->footer();