[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/mnet/ -> addinstance.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_mnet into the specified course
  19   *
  20   * @package    enrol_mnet
  21   * @copyright  2010 David Mudrak <[email protected]>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require(dirname(dirname(dirname(__FILE__))).'/config.php');
  26  require_once($CFG->dirroot.'/enrol/mnet/addinstance_form.php');
  27  require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
  28  
  29  $id = required_param('id', PARAM_INT); // course id
  30  
  31  $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
  32  $context = context_course::instance($course->id, MUST_EXIST);
  33  
  34  require_login($course);
  35  require_capability('moodle/course:enrolconfig', $context);
  36  
  37  $PAGE->set_url('/enrol/mnet/addinstance.php', array('id'=>$course->id));
  38  $PAGE->set_pagelayout('standard');
  39  
  40  // Try and make the manage instances node on the navigation active
  41  $courseadmin = $PAGE->settingsnav->get('courseadmin');
  42  if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) {
  43      $courseadmin->get('users')->get('manageinstances')->make_active();
  44  }
  45  
  46  $enrol = enrol_get_plugin('mnet');
  47  // make sure we were allowed to get here form the Enrolment methods page
  48  if (!$enrol->get_newinstance_link($course->id)) {
  49      redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
  50  }
  51  $service = mnetservice_enrol::get_instance();
  52  $mform = new enrol_mnet_addinstance_form(null, array('course'=>$course, 'enrol'=>$enrol, 'service'=>$service));
  53  
  54  if ($mform->is_cancelled()) {
  55      redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
  56  
  57  } else if ($data = $mform->get_data()) {
  58      $enrol->add_instance($course, array('customint1'=>$data->hostid, 'roleid'=>$data->roleid, 'name'=>$data->name));
  59      redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
  60  }
  61  
  62  $PAGE->set_heading($course->fullname);
  63  $PAGE->set_title(get_string('pluginname', 'enrol_mnet'));
  64  
  65  echo $OUTPUT->header();
  66  $mform->display();
  67  echo $OUTPUT->footer();


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