2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Adds new instance of enrol_paypal to specified course
19 * or edits current instance.
21 * @package enrol_paypal
22 * @copyright 2010 Petr Skoda {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require('../../config.php');
27 require_once('edit_form.php');
29 $courseid = required_param('courseid', PARAM_INT
);
30 $instanceid = optional_param('id', 0, PARAM_INT
); // instanceid
32 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST
);
33 $context = context_course
::instance($course->id
, MUST_EXIST
);
35 require_login($course);
36 require_capability('enrol/paypal:config', $context);
38 $PAGE->set_url('/enrol/paypal/edit.php', array('courseid'=>$course->id
, 'id'=>$instanceid));
39 $PAGE->set_pagelayout('admin');
41 $return = new moodle_url('/enrol/instances.php', array('id'=>$course->id
));
42 if (!enrol_is_enabled('paypal')) {
46 $plugin = enrol_get_plugin('paypal');
49 $instance = $DB->get_record('enrol', array('courseid'=>$course->id
, 'enrol'=>'paypal', 'id'=>$instanceid), '*', MUST_EXIST
);
50 $instance->cost
= format_float($instance->cost
, 2, true);
52 require_capability('moodle/course:enrolconfig', $context);
53 // no instance yet, we have to add new instance
54 navigation_node
::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id
)));
55 $instance = new stdClass();
57 $instance->courseid
= $course->id
;
60 $mform = new enrol_paypal_edit_form(NULL, array($instance, $plugin, $context));
62 if ($mform->is_cancelled()) {
65 } else if ($data = $mform->get_data()) {
67 $reset = ($instance->status
!= $data->status
);
69 $instance->status
= $data->status
;
70 $instance->name
= $data->name
;
71 $instance->cost
= unformat_float($data->cost
);
72 $instance->currency
= $data->currency
;
73 $instance->roleid
= $data->roleid
;
74 $instance->enrolperiod
= $data->enrolperiod
;
75 $instance->enrolstartdate
= $data->enrolstartdate
;
76 $instance->enrolenddate
= $data->enrolenddate
;
77 $instance->timemodified
= time();
78 $DB->update_record('enrol', $instance);
81 $context->mark_dirty();
85 $fields = array('status'=>$data->status
, 'name'=>$data->name
, 'cost'=>unformat_float($data->cost
), 'currency'=>$data->currency
, 'roleid'=>$data->roleid
,
86 'enrolperiod'=>$data->enrolperiod
, 'enrolstartdate'=>$data->enrolstartdate
, 'enrolenddate'=>$data->enrolenddate
);
87 $plugin->add_instance($course, $fields);
93 $PAGE->set_heading($course->fullname
);
94 $PAGE->set_title(get_string('pluginname', 'enrol_paypal'));
96 echo $OUTPUT->header();
97 echo $OUTPUT->heading(get_string('pluginname', 'enrol_paypal'));
99 echo $OUTPUT->footer();