[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/self/ -> 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_self to specified course
  19   * or edits current instance.
  20   *
  21   * @package    enrol_self
  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);
  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/self:config', $context);
  37  
  38  $PAGE->set_url('/enrol/self/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('self')) {
  43      redirect($return);
  44  }
  45  
  46  /** @var enrol_self_plugin $plugin */
  47  $plugin = enrol_get_plugin('self');
  48  
  49  if ($instanceid) {
  50      $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'self', 'id'=>$instanceid), '*', MUST_EXIST);
  51  
  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  
  57      $instance = (object)$plugin->get_instance_defaults();
  58      $instance->id       = null;
  59      $instance->courseid = $course->id;
  60      $instance->status   = ENROL_INSTANCE_ENABLED; // Do not use default for automatically created instances here.
  61  }
  62  
  63  // Merge these two settings to one value for the single selection element.
  64  if ($instance->notifyall and $instance->expirynotify) {
  65      $instance->expirynotify = 2;
  66  }
  67  unset($instance->notifyall);
  68  
  69  $mform = new enrol_self_edit_form(NULL, array($instance, $plugin, $context));
  70  
  71  if ($mform->is_cancelled()) {
  72      redirect($return);
  73  
  74  } else if ($data = $mform->get_data()) {
  75      if ($data->expirynotify == 2) {
  76          $data->expirynotify = 1;
  77          $data->notifyall = 1;
  78      } else {
  79          $data->notifyall = 0;
  80      }
  81      if (!$data->expirynotify) {
  82          // Keep previous/default value of disabled expirythreshold option.
  83          $data->expirythreshold = $instance->expirythreshold;
  84      }
  85      if (!isset($data->customint6)) {
  86          // Add previous value of newenrols if disabled.
  87          $data->customint6 = $instance->customint6;
  88      }
  89  
  90      if ($instance->id) {
  91          $reset = ($instance->status != $data->status);
  92  
  93          $instance->status         = $data->status;
  94          $instance->name           = $data->name;
  95          $instance->password       = $data->password;
  96          $instance->customint1     = $data->customint1;
  97          $instance->customint2     = $data->customint2;
  98          $instance->customint3     = $data->customint3;
  99          $instance->customint4     = $data->customint4;
 100          $instance->customint5     = $data->customint5;
 101          $instance->customint6     = $data->customint6;
 102          $instance->customtext1    = $data->customtext1;
 103          $instance->roleid         = $data->roleid;
 104          $instance->enrolperiod    = $data->enrolperiod;
 105          $instance->expirynotify   = $data->expirynotify;
 106          $instance->notifyall      = $data->notifyall;
 107          $instance->expirythreshold = $data->expirythreshold;
 108          $instance->enrolstartdate = $data->enrolstartdate;
 109          $instance->enrolenddate   = $data->enrolenddate;
 110          $instance->timemodified   = time();
 111          $DB->update_record('enrol', $instance);
 112  
 113          if ($reset) {
 114              $context->mark_dirty();
 115          }
 116  
 117      } else {
 118          $fields = array(
 119              'status'          => $data->status,
 120              'name'            => $data->name,
 121              'password'        => $data->password,
 122              'customint1'      => $data->customint1,
 123              'customint2'      => $data->customint2,
 124              'customint3'      => $data->customint3,
 125              'customint4'      => $data->customint4,
 126              'customint5'      => $data->customint5,
 127              'customint6'      => $data->customint6,
 128              'customtext1'     => $data->customtext1,
 129              'roleid'          => $data->roleid,
 130              'enrolperiod'     => $data->enrolperiod,
 131              'expirynotify'    => $data->expirynotify,
 132              'notifyall'       => $data->notifyall,
 133              'expirythreshold' => $data->expirythreshold,
 134              'enrolstartdate'  => $data->enrolstartdate,
 135              'enrolenddate'    => $data->enrolenddate);
 136          $plugin->add_instance($course, $fields);
 137      }
 138  
 139      redirect($return);
 140  }
 141  
 142  $PAGE->set_heading($course->fullname);
 143  $PAGE->set_title(get_string('pluginname', 'enrol_self'));
 144  
 145  echo $OUTPUT->header();
 146  echo $OUTPUT->heading(get_string('pluginname', 'enrol_self'));
 147  $mform->display();
 148  echo $OUTPUT->footer();


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