[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/ -> index.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   * This page shows all course enrolment options for current user.
  19   *
  20   * @package    core_enrol
  21   * @copyright  2010 Petr Skoda {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require('../config.php');
  26  require_once("$CFG->libdir/formslib.php");
  27  
  28  $id = required_param('id', PARAM_INT);
  29  
  30  if (!isloggedin()) {
  31      // do not use require_login here because we are usually coming from it,
  32      // it would also mess up the SESSION->wantsurl
  33      redirect(get_login_url());
  34  }
  35  
  36  $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
  37  $context = context_course::instance($course->id, MUST_EXIST);
  38  
  39  // Everybody is enrolled on the frontpage
  40  if ($course->id == SITEID) {
  41      redirect("$CFG->wwwroot/");
  42  }
  43  
  44  if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
  45      print_error('coursehidden');
  46  }
  47  
  48  $PAGE->set_course($course);
  49  $PAGE->set_pagelayout('incourse');
  50  $PAGE->set_url('/enrol/index.php', array('id'=>$course->id));
  51  
  52  // do not allow enrols when in login-as session
  53  if (\core\session\manager::is_loggedinas() and $USER->loginascontext->contextlevel == CONTEXT_COURSE) {
  54      print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid);
  55  }
  56  
  57  // get all enrol forms available in this course
  58  $enrols = enrol_get_plugins(true);
  59  $enrolinstances = enrol_get_instances($course->id, true);
  60  $forms = array();
  61  foreach($enrolinstances as $instance) {
  62      if (!isset($enrols[$instance->enrol])) {
  63          continue;
  64      }
  65      $form = $enrols[$instance->enrol]->enrol_page_hook($instance);
  66      if ($form) {
  67          $forms[$instance->id] = $form;
  68      }
  69  }
  70  
  71  // Check if user already enrolled
  72  if (is_enrolled($context, $USER, '', true)) {
  73      if (!empty($SESSION->wantsurl)) {
  74          $destination = $SESSION->wantsurl;
  75          unset($SESSION->wantsurl);
  76      } else {
  77          $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
  78      }
  79      redirect($destination);   // Bye!
  80  }
  81  
  82  $PAGE->set_title($course->shortname);
  83  $PAGE->set_heading($course->fullname);
  84  $PAGE->navbar->add(get_string('enrolmentoptions','enrol'));
  85  
  86  echo $OUTPUT->header();
  87  echo $OUTPUT->heading(get_string('enrolmentoptions','enrol'));
  88  
  89  $courserenderer = $PAGE->get_renderer('core', 'course');
  90  echo $courserenderer->course_info_box($course);
  91  
  92  //TODO: find if future enrolments present and display some info
  93  
  94  foreach ($forms as $form) {
  95      echo $form;
  96  }
  97  
  98  if (!$forms) {
  99      if (isguestuser()) {
 100          notice(get_string('noguestaccess', 'enrol'), get_login_url());
 101      } else {
 102          notice(get_string('notenrollable', 'enrol'), "$CFG->wwwroot/index.php");
 103      }
 104  }
 105  
 106  echo $OUTPUT->footer();


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