[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/course/ -> enrol.php (source)

   1  <?php // $Id: enrol.php,v 1.50.2.1 2008/03/03 05:27:36 moodler Exp $
   2        // Depending on the current enrolment method, this page
   3        // presents the user with whatever they need to know when
   4        // they try to enrol in a course.
   5  
   6      require_once("../config.php");
   7      require_once ("lib.php");
   8      require_once("$CFG->dirroot/enrol/enrol.class.php");
   9  
  10      $id           = required_param('id', PARAM_INT);
  11      $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed?
  12  
  13      if (!isloggedin()) {
  14          $wwwroot = $CFG->wwwroot;
  15          if (!empty($CFG->loginhttps)) {
  16              $wwwroot = str_replace('http:','https:', $wwwroot);
  17          }
  18          // do not use require_login here because we are usually comming from it
  19          redirect($wwwroot.'/login/index.php');
  20      }
  21  
  22      if (! $course = get_record('course', 'id', $id) ) {
  23          error("That's an invalid course id");
  24      }
  25  
  26      if (! $context = get_context_instance(CONTEXT_COURSE, $course->id) ) {
  27          error("That's an invalid course id");
  28      }
  29  
  30  /// do not use when in course login as
  31      if (!empty($USER->realuser) and $USER->loginascontext->contextlevel == CONTEXT_COURSE) {
  32          print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid);
  33      }
  34  
  35      $enrol = enrolment_factory::factory($course->enrol); // do not use if (!$enrol... here, it can not work in PHP4 - see MDL-7529
  36  
  37  /// Refreshing all current role assignments for the current user
  38  
  39      load_all_capabilities();
  40  
  41  /// Double check just in case they are actually enrolled already and
  42  /// thus got to this script by mistake.  This might occur if enrolments
  43  /// changed during this session or something
  44  
  45      if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context, NULL, false)) {
  46          if (!empty($SESSION->wantsurl)) {
  47              $destination = $SESSION->wantsurl;
  48              unset($SESSION->wantsurl);
  49          } else {
  50              $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
  51          }
  52          redirect($destination);   // Bye!
  53      }
  54  
  55  /// Check if the course is a meta course  (bug 5734)
  56      if ($course->metacourse) {
  57          print_header_simple();
  58          notice(get_string('coursenotaccessible'), "$CFG->wwwroot/index.php");
  59      }
  60  
  61  /// Users can't enroll to site course
  62      if ($course->id == SITEID) {
  63          print_header_simple();
  64          notice(get_string('enrollfirst'), "$CFG->wwwroot/index.php");
  65      }
  66  
  67  /// Double check just in case they are enrolled to start in the future
  68  
  69      if ($course->enrolperiod) {   // Only active if the course has an enrolment period in effect
  70          if ($roles = get_user_roles($context, $USER->id)) {
  71              foreach ($roles as $role) {
  72                  if ($role->timestart and ($role->timestart >= time())) {
  73                      $message = get_string('enrolmentnotyet', '', userdate($student->timestart));
  74                      print_header();
  75                      notice($message, "$CFG->wwwroot/index.php");
  76                  }
  77              }
  78          }
  79      }
  80  
  81  /// Check if the course is enrollable
  82      if (!method_exists($enrol, 'print_entry')) {
  83          print_header_simple();
  84          notice(get_string('enrolmentnointernal'), "$CFG->wwwroot/index.php");
  85      }
  86  
  87      if (!$course->enrollable ||
  88              ($course->enrollable == 2 && $course->enrolstartdate > 0 && $course->enrolstartdate > time()) ||
  89              ($course->enrollable == 2 && $course->enrolenddate > 0 && $course->enrolenddate <= time())
  90              ) {
  91          print_header($course->shortname, $course->fullname, build_navigation(array(array('name'=>$course->shortname,'link'=>'','type'=>'misc'))) );
  92          notice(get_string('notenrollable'), "$CFG->wwwroot/index.php");
  93      }
  94  
  95  /// Check the submitted enrolment information if there is any (eg could be enrolment key)
  96  
  97      if ($form = data_submitted()) {
  98          $enrol->check_entry($form, $course);   // Should terminate/redirect in here if it's all OK
  99      }
 100  
 101  /// Otherwise, we print the entry form.
 102  
 103      $enrol->print_entry($course);
 104  
 105  /// Easy!
 106  
 107  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7