diff --git a/admin/cron.php b/admin/cron.php
index 5932eec72b2..06ee75d9294 100644
--- a/admin/cron.php
+++ b/admin/cron.php
@@ -247,11 +247,19 @@
}
/// Run the enrolment cron, if any
- require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");
- $enrol = new enrolment_plugin();
- $enrol->cron();
- if (!empty($enrol->log)) {
- mtrace($enrol->log);
+ if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
+ $plugins = array($CFG->enrol);
+ }
+ require_once($CFG->dirroot .'/enrol/enrol.class.php');
+ foreach ($plugins as $p) {
+ $enrol = enrolment_factory::factory($p);
+ if (method_exists($enrol, 'cron')) {
+ $enrol->cron();
+ }
+ if (!empty($enrol->log)) {
+ mtrace($enrol->log);
+ }
+ unset($enrol);
}
if (!empty($CFG->enablestats)) {
diff --git a/admin/enrol.php b/admin/enrol.php
index 92404f09235..6d97c63e846 100644
--- a/admin/enrol.php
+++ b/admin/enrol.php
@@ -20,27 +20,33 @@
error(get_string('confirmsesskeybad', 'error'));
}
- require_once("$CFG->dirroot/enrol/$enrol/enrol.php"); /// Open the class
+ require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
- $enrolment = new enrolment_plugin();
-
-
-/// If data submitted, then process and store.
+/// Save settings
if ($frm = data_submitted()) {
- if ($enrolment->process_config($frm)) {
- set_config('enrol', $frm->enrol);
- redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
+ if (empty($frm->enable)) {
+ $frm->enable = array();
}
- } else {
- $frm = $CFG;
+ if (empty($frm->default)) {
+ $frm->default = '';
+ }
+ if ($frm->default && !in_array($frm->default, $frm->enable)) {
+ $frm->enable[] = $frm->default;
+ }
+ asort($frm->enable);
+ set_config('enrol_plugins_enabled', implode(',', $frm->enable));
+ set_config('enrol', $frm->default);
+ redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
}
-/// Otherwise fill and print the form.
+/// Print the form
- /// get language strings
- $str = get_strings(array('enrolments', 'users', 'administration', 'settings'));
+ $str = get_strings(array('enrolmentplugins', 'users', 'administration', 'settings', 'edit'));
+ print_header("$site->shortname: $str->enrolmentplugins", "$site->fullname",
+ "$str->administration ->
+ $str->users -> $str->enrolmentplugins");
$modules = get_list_of_plugins("enrol");
$options = array();
@@ -49,41 +55,49 @@
}
asort($options);
- print_header("$site->shortname: $str->enrolments", "$site->fullname",
- "$str->administration ->
- $str->users -> $str->enrolments");
+ print_simple_box("blah", 'center', '700');
echo "
'.get_string('enrolments').
+ $userdata .= ' ';
$userdata .= '';
@@ -430,6 +430,7 @@
}
$table->data[] = array(''.get_string('environment','admin').' ',
''.get_string('adminhelpenvironment').'
');
+
if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
$table->data[] = array("dbtype/frame.php\">".get_string('managedatabase').' ',
get_string('adminhelpmanagedatabase'));
diff --git a/admin/users.php b/admin/users.php
index 2f00a1a980c..607a14a6955 100644
--- a/admin/users.php
+++ b/admin/users.php
@@ -32,7 +32,7 @@
$table->data[] = array("wwwroot/$CFG->admin/uploaduser.php?sesskey=$USER->sesskey\">".get_string("uploadusers")." ",
get_string("adminhelpuploadusers"));
$table->data[] = array('', ' ');
- $table->data[] = array("sesskey\">".get_string("enrolments")." ",
+ $table->data[] = array("sesskey\">".get_string("enrolmentplugins")." ",
get_string("adminhelpenrolments"));
$table->data[] = array("sesskey\">".get_string("assignstudents")." ",
get_string("adminhelpassignstudents"));
diff --git a/course/edit.html b/course/edit.html
index 179a2bac578..5ad997cc775 100644
--- a/course/edit.html
+++ b/course/edit.html
@@ -15,6 +15,9 @@
if (!isset($form->theme)) {
$form->theme = '';
}
+ if (!isset($form->enrol)) {
+ $form->enrol = '';
+ }
if (!isset($form->enrollable)) {
$form->enrollable = 1;
}
@@ -109,6 +112,25 @@
helpbutton("coursestartdate", get_string("startdate"));
?>
+
+ :
+ get_string('sitedefault')), $choices);
+ choose_from_menu ($choices, "enrol", "$form->enrol", "");
+ helpbutton("courseenrolmentplugins", get_string("enrolmentplugins"));
+ ?>
+
:
enrol != 'internal') {
+ if (method_exists(enrolment_factory::factory($course->enrol), 'print_entry') && $course->enrol != 'internal') {
?>
:
diff --git a/course/edit.php b/course/edit.php
index d196164e318..9c22c070a24 100644
--- a/course/edit.php
+++ b/course/edit.php
@@ -4,6 +4,7 @@
require_once("../config.php");
require_once("lib.php");
require_once("$CFG->libdir/blocklib.php");
+ require_once("$CFG->dirroot/enrol/enrol.class.php");
$id = optional_param('id', 0, PARAM_INT); // course id
$category = optional_param('category', 0, PARAM_INT); // possible default category
diff --git a/course/enrol.php b/course/enrol.php
index 91fd039fff4..f62ff9b8429 100644
--- a/course/enrol.php
+++ b/course/enrol.php
@@ -5,7 +5,7 @@
require_once("../config.php");
require_once("lib.php");
- require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");
+ require_once("$CFG->dirroot/enrol/enrol.class.php");
$id = required_param('id',PARAM_INT);
@@ -27,12 +27,23 @@
check_for_restricted_user($USER->username);
- $enrol = new enrolment_plugin();
-
/// Refreshing enrolment data in the USER session
- $enrol->get_student_courses($USER);
- $enrol->get_teacher_courses($USER);
+ if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
+ $plugins = array($CFG->enrol);
+ }
+ require_once($CFG->dirroot .'/enrol/enrol.class.php');
+ foreach ($plugins as $p) {
+ $enrol = enrolment_factory::factory($p);
+ if (method_exists($enrol, 'get_student_courses')) {
+ $enrol->get_student_courses($USER);
+ }
+ if (method_exists($enrol, 'get_teacher_courses')) {
+ $enrol->get_teacher_courses($USER);
+ }
+ unset($enrol);
+ }
+ $enrol = enrolment_factory::factory($course->enrol);
/// Double check just in case they are actually enrolled already
/// This might occur if they were enrolled during this session
@@ -66,6 +77,11 @@
}
/// Check if the course is enrollable
+ if (!method_exists($enrol, 'print_entry')) {
+ print_header_simple();
+ notice(get_string('enrolmentnointernal'), $CFG->wwwroot);
+ }
+
if (!$course->enrollable ||
($course->enrollable == 2 && $course->enrolstartdate > 0 && $course->enrolstartdate > time()) ||
($course->enrollable == 2 && $course->enrolenddate > 0 && $course->enrolenddate <= time())
diff --git a/course/lib.php b/course/lib.php
index 4f6903e79e5..cfc889a2b1d 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1401,14 +1401,7 @@ function print_courses($category, $width="100%", $hidesitecourse = false) {
print_course($course, $width);
}
} else {
- print_heading(get_string('nocoursesyet'));
- if (iscreator()) {
- $options = array();
- $options['category'] = $category->id;
- echo '';
- print_single_button($CFG->wwwroot.'/course/edit.php', $options, get_string('addnewcourse'));
- echo '
';
- }
+ print_heading(get_string("nocoursesyet"));
}
}
@@ -1418,12 +1411,9 @@ function print_course($course, $width="100%") {
global $CFG, $USER;
- static $enrol;
+ require_once("$CFG->dirroot/enrol/enrol.class.php");
- if (empty($enrol)) {
- require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");
- $enrol = new enrolment_plugin;
- }
+ $enrol = enrolment_factory::factory($course->enrol);
print_simple_box_start("center", "$width", '', 5, "coursebox");
diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php
index a6d16f57e4b..c82c8199b11 100755
--- a/enrol/authorize/enrol.php
+++ b/enrol/authorize/enrol.php
@@ -7,7 +7,7 @@ require_once $CFG->dirroot.'/enrol/authorize/const.php';
* enrolment_plugin_authorize
*
*/
-class enrolment_plugin extends enrolment_base
+class enrolment_plugin_authorize
{
/**
* Credit card error messages.
@@ -36,9 +36,10 @@ class enrolment_plugin extends enrolment_base
{
global $CFG, $USER, $form;
- if ($this->zero_cost($course) || isguest()) {
- parent::print_entry($course);
- return; // No money for guests ;)
+ if ($this->zero_cost($course) || isguest()) { // No money for guests ;)
+ $internal = enrolment_factory::factory('internal');
+ $internal->print_entry($course);
+ return;
}
$this->prevent_double_paid($course);
@@ -82,8 +83,9 @@ class enrolment_plugin extends enrolment_base
* @access public
*/
function check_entry($form, $course) {
- if ((!empty($form->password)) || isguest() || $this->zero_cost($course)) {
- parent::check_entry($form, $course);
+ if ($this->zero_cost($course) || isguest() || (!empty($form->password))) {
+ $internal = enrolment_factory::factory('internal');
+ $internal->print_entry($course);
} elseif ((!empty($form->ccsubmit)) && $this->validate_enrol_form($form)) {
$this->cc_submit($form, $course);
}
@@ -371,7 +373,9 @@ class enrolment_plugin extends enrolment_base
*/
function get_access_icons($course) {
- $str = parent::get_access_icons($course);
+
+ $internal = enrolment_factory::factory('internal');
+ $str = $internal->get_access_icons($course);
$curcost = $this->get_course_cost($course);
if (abs($curcost['cost']) > 0.00) {
@@ -570,7 +574,8 @@ class enrolment_plugin extends enrolment_base
function cron()
{
global $CFG;
- parent::cron();
+ $internal = enrolment_factory::factory('internal');
+ $internal->cron();
require_once $CFG->dirroot.'/enrol/authorize/action.php';
$oneday = 86400;
diff --git a/enrol/database/config.html b/enrol/database/config.html
index 0a9ad32735b..1de83de1039 100644
--- a/enrol/database/config.html
+++ b/enrol/database/config.html
@@ -167,14 +167,5 @@
-
- enrol_allowinternal:
-
- enrol_allowinternal) echo "checked=\"true\"" ?> />
-
-
-
-
-
diff --git a/enrol/database/enrol.php b/enrol/database/enrol.php
index dda6b6a7bd9..0b8f3bc9adc 100644
--- a/enrol/database/enrol.php
+++ b/enrol/database/enrol.php
@@ -5,24 +5,14 @@ require_once("$CFG->dirroot/course/lib.php");
require_once("$CFG->dirroot/lib/blocklib.php");
require_once("$CFG->dirroot/lib/pagelib.php");
-class enrolment_plugin extends enrolment_base {
+class enrolment_plugin_database {
var $log;
-/// Leave get_teacher_courses() function unchanged for the time being
-
-
-/// Leave cron() function unchanged
-
-
-
/// Overide the base get_student_courses() function
function get_student_courses(&$user) {
global $CFG;
- parent::get_student_courses($user); /// Start with the list of known enrolments
- /// If the database fails we can at least use this
-
// NOTE: if $this->enrol_connect() succeeds you MUST remember to call
// $this->enrol_disconnect() as it is doing some nasty vodoo with $CFG->prefix
if ($enroldb = $this->enrol_connect()) {
@@ -282,30 +272,6 @@ function sync_enrolments($type='student') {
return true;
}
-
-/// Override the base print_entry() function
-function print_entry($course) {
- global $CFG;
-
- if (! empty($CFG->enrol_allowinternal) ) {
- parent::print_entry($course);
- } else {
- print_header();
- notice(get_string("enrolmentnointernal"), $CFG->wwwroot);
- }
-}
-
-
-/// Override the base check_entry() function
-function check_entry($form, $course) {
- global $CFG;
-
- if (! empty($CFG->enrol_allowinternal) ) {
- parent::check_entry($form, $course);
- }
-}
-
-
/// Overide the get_access_icons() function
function get_access_icons($course) {
}
@@ -320,7 +286,8 @@ function config_form($frm) {
'enrol_localcoursefield', 'enrol_localuserfield',
'enrol_remotecoursefield', 'enrol_remoteuserfield',
'enrol_db_autocreate', 'enrol_db_category', 'enrol_db_template',
- 'enrol_allowinternal');
+ 'enrol_remotecoursefield', 'enrol_remoteuserfield');
+
foreach ($vars as $var) {
if (!isset($frm->$var)) {
$frm->$var = '';
@@ -396,11 +363,6 @@ function process_config($config) {
$config->enrol_db_template = '';
}
set_config('enrol_db_template', $config->enrol_db_template);
-
- if (!isset($config->enrol_allowinternal)) {
- $config->enrol_allowinternal = '';
- }
- set_config('enrol_allowinternal', $config->enrol_allowinternal);
return true;
}
@@ -510,7 +472,6 @@ function enrol_connect() {
}
// Try to connect to the external database
-
$enroldb = &ADONewConnection($CFG->enrol_dbtype);
if ($enroldb->PConnect($CFG->enrol_dbhost,$CFG->enrol_dbuser,$CFG->enrol_dbpass,$CFG->enrol_dbname)) {
return $enroldb;
diff --git a/enrol/flatfile/config.html b/enrol/flatfile/config.html
index 19d3aa0ea28..cac3ba271c6 100644
--- a/enrol/flatfile/config.html
+++ b/enrol/flatfile/config.html
@@ -40,14 +40,4 @@
-
- enrol_allowinternal:
-
- enrol_allowinternal) echo "checked=\"true\"" ?> />
-
-
-
-
-
-
diff --git a/enrol/flatfile/enrol.php b/enrol/flatfile/enrol.php
index 8b51a767e50..e4c0f261464 100644
--- a/enrol/flatfile/enrol.php
+++ b/enrol/flatfile/enrol.php
@@ -1,42 +1,16 @@
dirroot/enrol/enrol.class.php");
-
// The following flags are set in the configuration
// $CFG->enrol_flatfilelocation: where is the file we are looking for?
-// $CFG->enrol_allowinternal: allow internal enrolment in courses
// $CFG->enrol_emailstudents: send email to students when they are enrolled in a course
// $CFG->enrol_emailteachers: send email to teachers when they are enrolled in a course
// $CFG->enrol_emailadmins: email the log from the cron job to the admin
-class enrolment_plugin extends enrolment_base {
+class enrolment_plugin_flatfile {
var $log;
-/// Override the base print_entry() function
-function print_entry($course) {
- global $CFG;
-
- if (! empty($CFG->enrol_allowinternal) ) {
- parent::print_entry($course);
- } else {
- print_header();
- notice(get_string("enrolmentnointernal"), $CFG->wwwroot);
- }
-}
-
-
-/// Override the base check_entry() function
-function check_entry($form, $course) {
- global $CFG;
-
- if (! empty($CFG->enrol_allowinternal) ) {
- parent::check_entry($form, $course);
- }
-}
-
-
/// Override the base config_form() function
function config_form($frm) {
global $CFG;
@@ -74,15 +48,14 @@ function process_config($config) {
}
set_config('enrol_mailadmins', $config->enrol_mailadmins);
- if (!isset($config->enrol_allowinternal)) {
- $config->enrol_allowinternal = '';
- }
- set_config('enrol_allowinternal', $config->enrol_allowinternal);
-
return true;
}
+/// Override the get_access_icons() function
+function get_access_icons($course) {
+}
+
/**
* Override the base cron() function to read in a file
*
@@ -99,9 +72,6 @@ function process_config($config) {
function cron() {
global $CFG;
- /// call the base class
- parent::cron();
-
if (empty($CFG->enrol_flatfilelocation)) {
$filename = "$CFG->dataroot/1/enrolments.txt"; // Default location
} else {
diff --git a/enrol/internal/enrol.php b/enrol/internal/enrol.php
index 038393c9713..0800229539b 100644
--- a/enrol/internal/enrol.php
+++ b/enrol/internal/enrol.php
@@ -1,8 +1,432 @@
-dirroot/enrol/enrol.class.php");
+student course array
+* Set the $user->timeaccess course array
+*
+* @param user referenced object, must contain $user->id already set
+*/
+function get_student_courses(&$user) {
+
+ if ($students = get_records("user_students", "userid", $user->id)) {
+ $currenttime = time();
+ foreach ($students as $student) {
+
+ /// Is course visible?
+
+ if (get_field("course", "visible", "id", $student->course)) {
+
+ /// Is the student enrolment active right now?
+
+ if ( ( $student->timestart == 0 or ( $currenttime > $student->timestart )) and
+ ( $student->timeend == 0 or ( $currenttime < $student->timeend )) ) {
+ $user->student[$student->course] = true;
+ $user->timeaccess[$student->course] = $student->timeaccess;
+ }
+ }
+ }
+ }
}
+
+
+/**
+* Returns information about the courses a student has access to
+*
+* Set the $user->teacher course array
+* Set the $user->teacheredit course array
+* Set the $user->timeaccess course array
+*
+* @param user referenced object, must contain $user->id already set
+*/
+function get_teacher_courses(&$user) {
+
+ if ($teachers = get_records("user_teachers", "userid", $user->id)) {
+ $currenttime = time();
+ foreach ($teachers as $teacher) {
+
+ /// Is teacher only teaching this course for a specific time period?
+
+ if ( ( $teacher->timestart == 0 or ( $currenttime > $teacher->timestart )) and
+ ( $teacher->timeend == 0 or ( $currenttime < $teacher->timeend )) ) {
+
+ $user->teacher[$teacher->course] = true;
+
+ if ($teacher->editall) {
+ $user->teacheredit[$teacher->course] = true;
+ }
+
+ $user->timeaccess[$teacher->course] = $teacher->timeaccess;
+ }
+ }
+ }
+}
+
+
+
+
+/**
+* Prints the entry form/page for this enrolment
+*
+* This is only called from course/enrol.php
+* Most plugins will probably override this to print payment
+* forms etc, or even just a notice to say that manual enrolment
+* is disabled
+*
+* @param course current course object
+*/
+function print_entry($course) {
+ global $CFG, $USER, $SESSION, $THEME;
+
+ $strloginto = get_string("loginto", "", $course->shortname);
+ $strcourses = get_string("courses");
+
+
+
+/// Automatically enrol into courses without password
+
+ if ($course->password == "") { // no password, so enrol
+
+ if (isguest()) {
+ add_to_log($course->id, "course", "guest", "view.php?id=$course->id", "$USER->id");
+
+ } else if (empty($_GET['confirm']) && empty($_GET['cancel'])) {
+
+ print_header($strloginto, $course->fullname, " $strcourses -> $strloginto");
+ echo "
";
+ notice_yesno(get_string("enrolmentconfirmation"), "enrol.php?id=$course->id&confirm=1", "enrol.php?id=$course->id&cancel=1");
+ print_footer();
+ exit;
+
+ } elseif (!empty($_GET['confirm'])) {
+ if ($course->enrolperiod) {
+ $timestart = time();
+ $timeend = time() + $course->enrolperiod;
+ } else {
+ $timestart = $timeend = 0;
+ }
+
+ if (! enrol_student($USER->id, $course->id, $timestart, $timeend, 'manual')) {
+ error("An error occurred while trying to enrol you.");
+ }
+
+ $subject = get_string("welcometocourse", "", $course->fullname);
+ $a->coursename = $course->fullname;
+ $a->profileurl = "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id";
+ $message = get_string("welcometocoursetext", "", $a);
+ if (! $teacher = get_teacher($course->id)) {
+ $teacher = get_admin();
+ }
+ email_to_user($USER, $teacher, $subject, $message);
+
+ add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
+
+ $USER->student[$course->id] = true;
+
+ if ($SESSION->wantsurl) {
+ $destination = $SESSION->wantsurl;
+ unset($SESSION->wantsurl);
+ } else {
+ $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
+ }
+
+ redirect($destination);
+ } elseif (!empty($_GET['cancel'])) {
+ unset($SESSION->wantsurl);
+ redirect($CFG->wwwroot);
+ }
+ }
+
+ $teacher = get_teacher($course->id);
+ if (!isset($password)) {
+ $password = "";
+ }
+
+
+ print_header($strloginto, $course->fullname, "
$strcourses -> $strloginto", "form.password");
+
+ print_course($course, "80%");
+
+ include("$CFG->dirroot/enrol/internal/enrol.html");
+
+ print_footer();
+
+}
+
+
+
+/**
+* The other half to print_entry, this checks the form data
+*
+* This function checks that the user has completed the task on the
+* enrolment entry page and then enrolls them.
+*
+* @param form the form data submitted, as an object
+* @param course the current course, as an object
+*/
+function check_entry($form, $course) {
+ global $CFG, $USER, $SESSION, $THEME;
+
+ if (empty($form->password)) {
+ $form->password = '';
+ }
+
+ $groupid = $this->check_group_entry($course->id, $form->password);
+ if (($form->password == $course->password) or ($groupid !== false) ) {
+
+ if (isguest()) {
+
+ add_to_log($course->id, "course", "guest", "view.php?id=$course->id", $_SERVER['REMOTE_ADDR']);
+
+ } else { /// Update or add new enrolment
+
+ if ($course->enrolperiod) {
+ $timestart = time();
+ $timeend = $timestart + $course->enrolperiod;
+ } else {
+ $timestart = $timeend = 0;
+ }
+
+ if (! enrol_student($USER->id, $course->id, $timestart, $timeend, 'manual')) {
+ error("An error occurred while trying to enrol you.");
+ }
+
+ if ($groupid !== false) {
+ if (add_user_to_group($groupid, $USER->id)) {
+ $USER->groupmember[$course->id] = $groupid;
+ } else {
+ error("An error occurred while trying to add you to a group");
+ }
+ }
+
+ $subject = get_string("welcometocourse", "", $course->fullname);
+ $a->coursename = $course->fullname;
+ $a->profileurl = "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id";
+ $message = get_string("welcometocoursetext", "", $a);
+
+ if (! $teacher = get_teacher($course->id)) {
+ $teacher = get_admin();
+ }
+
+ email_to_user($USER, $teacher, $subject, $message);
+ add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
+ }
+
+ $USER->student[$course->id] = true;
+
+ if ($SESSION->wantsurl) {
+ $destination = $SESSION->wantsurl;
+ unset($SESSION->wantsurl);
+ } else {
+ $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
+ }
+
+ redirect($destination);
+
+ } else {
+ $this->errormsg = get_string("enrolmentkeyhint", "", substr($course->password,0,1));
+ }
+
+}
+
+
+/**
+* Check if the given enrolment key matches a group enrolment key for the given course
+*
+* Check if the given enrolment key matches a group enrolment key for the given course
+*
+* @param courseid the current course id
+* @param password the submitted enrolment key
+*/
+function check_group_entry ($courseid, $password) {
+ $ingroup = false;
+ if ( ($groups = get_groups($courseid)) !== false ) {
+ foreach ($groups as $group)
+ if ( !empty($group->password) and ($password == $group->password) )
+ $ingroup = $group->id;
+ }
+ return $ingroup;
+}
+
+
+/**
+* Prints a form for configuring the current enrolment plugin
+*
+* This function is called from admin/enrol.php, and outputs a
+* full page with a form for defining the current enrolment plugin.
+*
+* @param page an object containing all the data for this page
+*/
+function config_form($page) {
+
+}
+
+
+/**
+* Processes and stored configuration data for the enrolment plugin
+*
+* Processes and stored configuration data for the enrolment plugin
+*
+* @param config all the configuration data as entered by the admin
+*/
+function process_config($config) {
+
+ $return = true;
+
+ foreach ($config as $name => $value) {
+ if (!set_config($name, $value)) {
+ $return = false;
+ }
+ }
+
+ return $return;
+}
+
+
+/**
+* This function is run by admin/cron.php every time
+*
+* The cron function can perform regular checks for the current
+* enrollment plugin. For example it can check a foreign database,
+* all look for a file to pull data in from
+*
+*/
+function cron() {
+ // Delete students from all courses where their enrolment period has expired
+
+ $select = "timeend > '0' AND timeend < '" . time() . "'";
+
+ if ($students = get_records_select('user_students', $select)) {
+ foreach ($students as $student) {
+ if ($course = get_record('course', 'id', $student->course)) {
+ if (empty($course->enrolperiod)) { // This overrides student timeend
+ continue;
+ }
+ }
+ unenrol_student($student->userid, $student->course);
+ }
+ }
+ if ($teachers = get_records_select('user_teachers', $select)) {
+ foreach ($teachers as $teacher) {
+ remove_teacher($teacher->userid, $teacher->course);
+ }
+ }
+
+ // Notify teachers/students about students who's enrolment are going to expire
+ global $CFG;
+ if ($CFG->lastexpirynotify < date('Ymd') && ($courses = get_records_select('course', 'enrolperiod > 0 AND expirynotify > 0 AND expirythreshold > 0'))) {
+ $site = get_site();
+ $admin = get_admin();
+ $strexpirynotify = get_string('expirynotify');
+ foreach ($courses as $course) {
+ $a = new stdClass();
+ $a->course = $course->shortname .' '. $course->fullname;
+ $a->threshold = $course->expirythreshold / 86400;
+ $a->extendurl = $CFG->wwwroot . '/user/index.php?id=' . $course->id;
+ $a->current = array();
+ $a->past = array();
+ $a->current = $a->past = array();
+ $expiry = time() + $course->expirythreshold;
+ $sql = "SELECT * FROM {$CFG->prefix}user u INNER JOIN {$CFG->prefix}user_students s ON u.id=s.userid WHERE s.course = $course->id AND s.timeend > 0 AND s.timeend <= $expiry";
+ if ($students = get_records_sql($sql)) {
+ $teacher = get_teacher($course->id);
+ $strexpirynotifystudentsemail = get_string('expirynotifystudentsemail', '', $a);
+ foreach ($students as $student) {
+ if ($student->timeend < ($expiry - 86400)) {
+ $a->past[] = fullname($student) . " <$student->email>";
+ } else {
+ $a->current[] = fullname($student) . " <$student->email>";
+ if ($course->notifystudents) {
+ // Send this guy notice
+ email_to_user($student, $teacher, $site->fullname .' '. $strexpirynotify, $strexpirynotifystudentsemail);
+ }
+ }
+ }
+ }
+ $a->current = implode("\n", $a->current);
+ $a->past = implode("\n", $a->past);
+ $strexpirynotifyemail = get_string('expirynotifyemail', '', $a);
+ if ($a->current || $a->past) {
+ $sql = "SELECT u.* FROM {$CFG->prefix}user u INNER JOIN {$CFG->prefix}user_teachers t ON u.id=t.userid WHERE t.course = $course->id";
+ if ($teachers = get_records_sql($sql)) {
+ foreach ($teachers as $teacher) {
+ email_to_user($teacher, $admin, $a->course .' '. $strexpirynotify, $strexpirynotifyemail);
+ }
+ }
+ }
+ set_config('lastexpirynotify', date('Ymd'));
+ }
+ }
+}
+
+
+/**
+* Returns the relevant icons for a course
+*
+* Returns the relevant icons for a course
+*
+* @param course the current course, as an object
+*/
+function get_access_icons($course) {
+ global $CFG;
+
+ $str = '';
+
+ if (!empty($course->guest)) {
+ $strallowguests = get_string("allowguests");
+ $str .= '
';
+ $str .= ' pixpath.'/i/guest.gif" /> ';
+ }
+ if (!empty($course->password)) {
+ $strrequireskey = get_string("requireskey");
+ $str .= '
';
+ $str .= ' ';
+ }
+
+ return $str;
+}
+
+
+} /// end of class
+
?>
diff --git a/enrol/ldap/config.html b/enrol/ldap/config.html
index 3a94e5ea23d..464b2990f64 100755
--- a/enrol/ldap/config.html
+++ b/enrol/ldap/config.html
@@ -73,19 +73,10 @@ if (!isset ($frm->enrol_ldap_course_summary_editlock)) {
$frm->enrol_ldap_course_summary_editlock = false;
}
// autocreate
-if (!isset ($frm->enrol_ldap_autocreate)) {
- $frm->enrol_ldap_autocreate = false;
-}
-if (!isset ($frm->enrol_ldap_category)) {
- $frm->enrol_ldap_category = 1;
-}
-if (!isset ($frm->enrol_ldap_template)) {
- $frm->enrol_ldap_template = '';
-}
-// general options
-if (!isset ($frm->enrol_allowinternal)) {
- $frm->enrol_allowinternal = false;
-}
+optional_variable($frm->enrol_ldap_autocreate, false);
+optional_variable($frm->enrol_ldap_category, 1);
+optional_variable($frm->enrol_ldap_template, '');
+
?>
diff --git a/enrol/ldap/enrol.php b/enrol/ldap/enrol.php
index aa4c1d43431..01fe5636193 100755
--- a/enrol/ldap/enrol.php
+++ b/enrol/ldap/enrol.php
@@ -3,34 +3,24 @@
require_once("$CFG->dirroot/enrol/enrol.class.php");
require_once("$CFG->dirroot/course/lib.php");
require_once("$CFG->dirroot/lib/blocklib.php");
-require_once("$CFG->dirroot//lib/pagelib.php");
+require_once("$CFG->dirroot/lib/pagelib.php");
$CFG->enrol_localcoursefield = 'idnumber';
-class enrolment_plugin extends enrolment_base {
+class enrolment_plugin_ldap {
var $log;
-/// Leave get_teacher_courses() function unchanged for the time being
-
-
-/// Leave cron() function unchanged
-
-
/// Overide the base get_student_courses() function
function get_student_courses(&$user) {
global $CFG;
- parent::get_student_courses($user); // populate known enrolments
- $this->get_user_courses($user, 'student');
- return parent::get_student_courses($user);
+ return $this->get_user_courses($user, 'student');
}
/// Overide the base get_teacher_courses() function
function get_teacher_courses(&$user) {
global $CFG;
- parent::get_teacher_courses($user); // populate known enrolments
- $this->get_user_courses($user, 'teacher');
- return parent::get_teacher_courses($user);
+ return $this->get_user_courses($user, 'teacher');
}
/// Overide the base get_student_courses() function
@@ -327,28 +317,6 @@ function sync_enrolments($type, $enrol) {
}
-/// Override the base print_entry() function
-function print_entry($course) {
- global $CFG;
-
- if (! empty($CFG->enrol_allowinternal) ) {
- parent::print_entry($course);
- } else {
- print_header();
- notice(get_string("enrolmentnointernal"), $CFG->wwwroot);
- }
-}
-
-/// Override the base check_entry() function
-function check_entry($form, $course) {
- global $CFG;
-
- if (! empty($CFG->enrol_allowinternal) ) {
- parent::check_entry($form, $course);
- }
-}
-
-
/// Overide the get_access_icons() function
function get_access_icons($course) {
}
@@ -455,12 +423,7 @@ function process_config($config) {
$config->enrol_ldap_autocreate = '0';
}
set_config('enrol_ldap_autocreate', $config->enrol_ldap_autocreate);
-
- if (!isset($config->enrol_allowinternal)) {
- $config->enrol_allowinternal = '';
- }
- set_config('enrol_allowinternal', $config->enrol_allowinternal);
-
+
return true;
}
diff --git a/enrol/ldap/enrol_ldap_sync.php b/enrol/ldap/enrol_ldap_sync.php
index 31d0a5af238..a8a5621e39a 100755
--- a/enrol/ldap/enrol_ldap_sync.php
+++ b/enrol/ldap/enrol_ldap_sync.php
@@ -11,12 +11,12 @@
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/lib/moodlelib.php');
require_once($CFG->dirroot . '/lib/datalib.php');
- require_once($CFG->dirroot . "/enrol/" . $CFG->enrol . "/enrol.php");
+ require_once($CFG->dirroot . "/enrol/ldap/enrol.php");
// ensure errors are well explained
$CFG->debug=10;
// update enrolments -- these handlers should autocreate courses if required
- $enrol = new enrolment_plugin();
+ $enrol = new enrolment_plugin_ldap();
$enrol->enrol_ldap_connect();
$enrol->sync_enrolments('student', true);
$enrol->sync_enrolments('teacher', true);
diff --git a/enrol/paypal/enrol.php b/enrol/paypal/enrol.php
index 1a902f68bfa..1ce836c713e 100644
--- a/enrol/paypal/enrol.php
+++ b/enrol/paypal/enrol.php
@@ -4,7 +4,7 @@
require_once("$CFG->dirroot/enrol/enrol.class.php");
-class enrolment_plugin extends enrolment_base {
+class enrolment_plugin_paypal {
/// Override the base print_entry() function
@@ -29,8 +29,8 @@ function print_entry($course) {
if (abs($cost) < 0.01) { // no cost, default to base class entry to course
-
- parent::print_entry($course);
+ $internal = enrolment_factory::factory('internal');
+ $internal->print_entry($course);
} else {
@@ -83,7 +83,8 @@ function get_access_icons($course) {
}
if (abs($cost) < 0.01) {
- $str = parent::get_access_icons($course);
+ $internal = enrolment_factory::factory('internal');
+ $str = $internal->get_access_icons($course);
} else {
@@ -178,20 +179,20 @@ function sanitise_for_paypal($text) {
if (!empty($CFG->sanitise_for_paypal)) {
//Array of characters to replace (not allowed by PayPal)
//Can be expanded as necessary to add other diacritics
- $replace = array('á' => 'a', //Spanish characters
- 'é' => 'e',
- 'í' => 'i',
- 'ó' => 'o',
- 'ú' => 'u',
- 'Á' => 'A',
- 'É' => 'E',
- 'Í' => 'I',
- 'Ó' => 'O',
- 'Ú' => 'U',
- 'ñ' => 'n',
- 'Ñ' => 'N',
- 'ü' => 'u',
- 'Ü' => 'U');
+ $replace = array('�' => 'a', //Spanish characters
+ '�' => 'e',
+ '�' => 'i',
+ '�' => 'o',
+ '�' => 'u',
+ '�' => 'A',
+ '�' => 'E',
+ '�' => 'I',
+ '�' => 'O',
+ '�' => 'U',
+ '�' => 'n',
+ '�' => 'N',
+ '�' => 'u',
+ '�' => 'U');
$text = strtr($text, $replace);
//Make here other sanities if necessary
diff --git a/enrol/paypal/return.php b/enrol/paypal/return.php
index 4ee264e7e5d..e6d5ebecf81 100644
--- a/enrol/paypal/return.php
+++ b/enrol/paypal/return.php
@@ -1,7 +1,7 @@
dirroot/enrol/$CFG->enrol/enrol.php");
+ require_once("$CFG->dirroot/enrol/paypal/enrol.php");
require_variable($id);
@@ -12,7 +12,7 @@
require_login();
/// Refreshing enrolment data in the USER session
- $enrol = new enrolment_plugin();
+ $enrol = new enrolment_plugin_paypal();
$enrol->get_student_courses($USER);
if ($SESSION->wantsurl) {
diff --git a/lang/en/help/courseenrolmentplugins.html b/lang/en/help/courseenrolmentplugins.html
new file mode 100644
index 00000000000..b3d6e445bf8
--- /dev/null
+++ b/lang/en/help/courseenrolmentplugins.html
@@ -0,0 +1 @@
+
Choose default interactive enrolment plugin used in this course
diff --git a/lang/en_utf8/help/courseenrolmentplugins.html b/lang/en_utf8/help/courseenrolmentplugins.html
new file mode 100644
index 00000000000..b3d6e445bf8
--- /dev/null
+++ b/lang/en_utf8/help/courseenrolmentplugins.html
@@ -0,0 +1 @@
+
Choose default interactive enrolment plugin used in this course
diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php
index f67e4aaf8a3..f4d7a1f1b07 100644
--- a/lang/en_utf8/moodle.php
+++ b/lang/en_utf8/moodle.php
@@ -161,17 +161,19 @@ $string['changedpassword'] = 'Changed password';
$string['changepassword'] = 'Change password';
$string['changessaved'] = 'Changes saved';
$string['check'] = 'Check';
+$string['checkall'] = 'Check all';
$string['checkingbackup'] = 'Checking backup';
$string['checkingcourse'] = 'Checking course';
$string['checkingforbbexport'] = 'Checking for BlackBoard export';
$string['checkinginstances'] = 'Checking instances';
$string['checkingsections'] = 'Checking sections';
$string['checklanguage'] = 'Check language';
+$string['checknone'] = 'Check none';
$string['childcourses'] = 'Child courses';
$string['childcoursenotfound'] = 'Child course not found!';
$string['choose'] = 'Choose';
$string['choosecourse'] = 'Choose a course';
-$string['chooseenrolmethod'] = 'Primary method of enrolment';
+$string['chooseenrolmethod'] = 'Choose enrolment plugin';
$string['chooselivelogs'] = 'Or watch current activity';
$string['chooselogs'] = 'Choose which logs you want to see';
$string['choosereportfilter'] = 'Choose a filter for the report';
@@ -456,6 +458,7 @@ $string['enrolmentnew'] = 'New enrolment in $a';
$string['enrolmentnewuser'] = '$a->user has enrolled in course \"$a->course\"';
$string['enrolmentnointernal'] = 'Manual enrolments are currently not enabled';
$string['enrolmentnotyet'] = 'Sorry, you can not access this course until
$a';
+$string['enrolmentplugins'] = 'Enrolment Plugins';
$string['enrolments'] = 'Enrolments';
$string['enrolmentstart'] = 'Enrolment Started';
$string['enrolperiod'] = 'Enrolment duration';
@@ -527,7 +530,6 @@ $string['forcepasswordchangehelp'] = 'Prompt user to change it on their next log
$string['forcepasswordchangenotice'] = 'You must change your password to proceed.';
$string['forcetheme'] = 'Force theme';
$string['forgotten'] = 'Forgotten your username or password?';
-$string['forgottenduplicate'] = 'Automatic password recovery can not be completed as your email address appears in the database more than once. Please contact your administrator
email\">$a->firstname $a->lastname .';
$string['forgotaccount'] = 'Lost password?';
$string['format'] = 'Format';
$string['formathtml'] = 'HTML format';
diff --git a/lib/db/mysql.php b/lib/db/mysql.php
index d89721bdfd0..6c473825f76 100644
--- a/lib/db/mysql.php
+++ b/lib/db/mysql.php
@@ -1649,7 +1649,7 @@ function main_upgrade($oldversion=0) {
table_column('course','','enrolenddate','int');
}
- if ($oldversion < 2005101200) { # add enrolment key to course_request.
+ if ($oldversion < 2005101200) { // add enrolment key to course_request.
table_column('course_request','','password','varchar',50);
}
@@ -1658,6 +1658,10 @@ function main_upgrade($oldversion=0) {
modify_database('',"ALTER TABLE prefix_log ADD INDEX info (info);");
}
+ if ($oldversion < 2006030900) {
+ table_column('course','','enrol','varchar','20','','');
+ }
+
return $result;
}
diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql
index 38e0d7797aa..de3b7dd9264 100644
--- a/lib/db/mysql.sql
+++ b/lib/db/mysql.sql
@@ -85,6 +85,7 @@ CREATE TABLE `prefix_course` (
`enrollable` tinyint(1) unsigned NOT NULL default '1',
`enrolstartdate` int(10) unsigned NOT NULL default '0',
`enrolenddate` int(10) unsigned NOT NULL default '0',
+ `enrol` varchar(20) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `category` (`category`),
KEY `idnumber` (`idnumber`),
diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php
index eb2a07e8906..603537d62c3 100644
--- a/lib/db/postgres7.php
+++ b/lib/db/postgres7.php
@@ -1391,7 +1391,8 @@ function main_upgrade($oldversion=0) {
table_column('course','','enrolenddate','integer');
}
- if ($oldversion < 2005101200) { # add enrolment key to course_request.
+
+ if ($oldversion < 2005101200) { // add enrolment key to course_request.
table_column('course_request','','password','text');
}
@@ -1399,6 +1400,10 @@ function main_upgrade($oldversion=0) {
modify_database('',"CREATE INDEX prefix_log_userid_idx ON prefix_log (userid);");
modify_database('',"CREATE INDEX prefix_log_info_idx ON prefix_log (info);");
}
+
+ if ($oldversion < 2006030900) {
+ table_column('course','','enrol','varchar','20','','');
+ }
return $result;
}
diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql
index 43993851c98..0314d20bf81 100644
--- a/lib/db/postgres7.sql
+++ b/lib/db/postgres7.sql
@@ -55,7 +55,8 @@ CREATE TABLE prefix_course (
notifystudents integer NOT NULL default '0',
enrollable integer NOT NULL default '1',
enrolstartdate integer NOT NULL default '0',
- enrolenddate integer NOT NULL default '0'
+ enrolenddate integer NOT NULL default '0',
+ enrol varchar(20) NOT NULL default ''
);
CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course (category,sortorder);
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index a714d54f079..3cd275b0d35 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -2674,12 +2674,22 @@ function get_complete_user_data($field, $value) {
$user->student[SITEID] = isstudent(SITEID, $user->id);
-/// Determine enrolments based on current enrolment module
+/// Load the list of enrolment plugin enabled
- require_once($CFG->dirroot .'/enrol/'. $CFG->enrol .'/enrol.php');
- $enrol = new enrolment_plugin();
- $enrol->get_student_courses($user);
- $enrol->get_teacher_courses($user);
+ if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
+ $plugins = array($CFG->enrol);
+ }
+ require_once($CFG->dirroot .'/enrol/enrol.class.php');
+ foreach ($plugins as $p) {
+ $enrol = enrolment_factory::factory($p);
+ if (method_exists($enrol, 'get_student_courses')) {
+ $enrol->get_student_courses($user);
+ }
+ if (method_exists($enrol, 'get_teacher_courses')) {
+ $enrol->get_teacher_courses($user);
+ }
+ unset($enrol);
+ }
/// Get various settings and preferences
diff --git a/version.php b/version.php
index d5716cc3b20..06e809f3b6f 100644
--- a/version.php
+++ b/version.php
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2006030800; // YYYYMMDD = date
+ $version = 2006030900; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.6 development'; // Human-friendly version name