Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/paypal/edit.php
Go to the documentation of this file.
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/paypal:config', $context);
00039 
00040 $PAGE->set_url('/enrol/paypal/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('paypal')) {
00045     redirect($return);
00046 }
00047 
00048 $plugin = enrol_get_plugin('paypal');
00049 
00050 if ($instanceid) {
00051     $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'paypal', '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_paypal_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->cost           = $data->cost;
00073         $instance->currency       = $data->currency;
00074         $instance->roleid         = $data->roleid;
00075         $instance->enrolperiod    = $data->enrolperiod;
00076         $instance->enrolstartdate = $data->enrolstartdate;
00077         $instance->enrolenddate   = $data->enrolenddate;
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, 'name'=>$data->name, 'cost'=>$data->cost, 'currency'=>$data->currency, 'roleid'=>$data->roleid,
00087                         'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate);
00088         $plugin->add_instance($course, $fields);
00089     }
00090 
00091     redirect($return);
00092 }
00093 
00094 $PAGE->set_heading($course->fullname);
00095 $PAGE->set_title(get_string('pluginname', 'enrol_paypal'));
00096 
00097 echo $OUTPUT->header();
00098 echo $OUTPUT->heading(get_string('pluginname', 'enrol_paypal'));
00099 $mform->display();
00100 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations