[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/paypal/ -> edit.php (source)

   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_paypal to specified course
  19   * or edits current instance.
  20   *
  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
  24   */
  25  
  26  require('../../config.php');
  27  require_once ('edit_form.php');
  28  
  29  $courseid   = required_param('courseid', PARAM_INT);
  30  $instanceid = optional_param('id', 0, PARAM_INT); // instanceid
  31  
  32  $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
  33  $context = context_course::instance($course->id, MUST_EXIST);
  34  
  35  require_login($course);
  36  require_capability('enrol/paypal:config', $context);
  37  
  38  $PAGE->set_url('/enrol/paypal/edit.php', array('courseid'=>$course->id, 'id'=>$instanceid));
  39  $PAGE->set_pagelayout('admin');
  40  
  41  $return = new moodle_url('/enrol/instances.php', array('id'=>$course->id));
  42  if (!enrol_is_enabled('paypal')) {
  43      redirect($return);
  44  }
  45  
  46  $plugin = enrol_get_plugin('paypal');
  47  
  48  if ($instanceid) {
  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);
  51  } else {
  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();
  56      $instance->id       = null;
  57      $instance->courseid = $course->id;
  58  }
  59  
  60  $mform = new enrol_paypal_edit_form(NULL, array($instance, $plugin, $context));
  61  
  62  if ($mform->is_cancelled()) {
  63      redirect($return);
  64  
  65  } else if ($data = $mform->get_data()) {
  66      if ($instance->id) {
  67          $reset = ($instance->status != $data->status);
  68  
  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);
  79  
  80          if ($reset) {
  81              $context->mark_dirty();
  82          }
  83  
  84      } else {
  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);
  88      }
  89  
  90      redirect($return);
  91  }
  92  
  93  $PAGE->set_heading($course->fullname);
  94  $PAGE->set_title(get_string('pluginname', 'enrol_paypal'));
  95  
  96  echo $OUTPUT->header();
  97  echo $OUTPUT->heading(get_string('pluginname', 'enrol_paypal'));
  98  $mform->display();
  99  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1