}
/// 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)) {
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();
+ }
+ if (empty($frm->default)) {
+ $frm->default = '';
+ }
+ if ($frm->default && !in_array($frm->default, $frm->enable)) {
+ $frm->enable[] = $frm->default;
}
- } else {
- $frm = $CFG;
+ 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",
+ "<a href=\"index.php\">$str->administration</a> ->
+ <a href=\"users.php\">$str->users</a> -> $str->enrolmentplugins");
$modules = get_list_of_plugins("enrol");
$options = array();
}
asort($options);
- print_header("$site->shortname: $str->enrolments", "$site->fullname",
- "<a href=\"index.php\">$str->administration</a> ->
- <a href=\"users.php\">$str->users</a> -> $str->enrolments");
+ print_simple_box("blah", 'center', '700');
echo "<form target=\"{$CFG->framename}\" name=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">";
- echo "<div align=\"center\"><p><b>";
-
-
-/// Choose an enrolment method
- echo get_string('chooseenrolmethod').': ';
- choose_from_menu ($options, "enrol", $enrol, "",
- "document.location='enrol.php?sesskey=$USER->sesskey&enrol='+document.enrolmenu.enrol.options[document.enrolmenu.enrol.selectedIndex].value", "");
- echo "</b></p></div>";
-
-/// Print current enrolment type description
- print_simple_box_start("center", "80%");
- print_heading($options[$enrol]);
+ $table = new stdClass();
+ $table->head = array(get_string('name'), get_string('enable'), get_string('default'), $str->settings);
+ $table->align = array('left', 'center', 'center', 'center');
+ $table->size = array('60%', '', '', '15%');
+ $table->width = '700';
+ $table->data = array();
- print_simple_box_start("center", "60%", '', 5, 'informationbox');
- print_string("description", "enrol_$enrol");
- print_simple_box_end();
+ $modules = get_list_of_plugins("enrol");
+ foreach ($modules as $module) {
+ $name = get_string("enrolname", "enrol_$module");
+ $plugin = enrolment_factory::factory($module);
+ $enable = '<input type="checkbox" name="enable[]" value="'.$module.'"';
+ if (stristr($CFG->enrol_plugins_enabled, $module) !== false) {
+ $enable .= ' checked="checked"';
+ }
+ if ($module == 'internal') {
+ $enable .= ' disabled="disabled" /><input type="hidden" name="enable[]" value="'.$module.'"';
+ }
+ $enable .= ' />';
+ if (method_exists($plugin, 'print_entry')) {
+ $default = '<input type="radio" name="default" value="'.$module.'"';
+ if ($CFG->enrol == $module) {
+ $default .= ' checked="checked"';
+ }
+ $default .= ' />';
+ } else {
+ $default = '';
+ }
+ $table->data[$name] = array($name, $enable, $default,
+ '<a href="enrol_config.php?sesskey='.$USER->sesskey.'&enrol='.$module.'">'.$str->edit.'</a>');
+ }
+ asort($table->data);
- echo "<hr />";
- // print_heading($str->settings);
-
- $enrolment->config_form($frm);
+ print_table($table);
- echo "<center><p><input type=\"submit\" value=\"".get_string("savechanges")."\"></p></center>\n";
+ echo "<center><input type=\"submit\" value=\"".get_string("savechanges")."\"></center>\n";
echo "</form>";
- print_simple_box_end();
-
print_footer();
- exit;
-?>
+?>
\ No newline at end of file
--- /dev/null
+<?PHP // $Id$
+ // enrol_config.php - allows admin to edit all enrollment variables
+ // Yes, enrol is correct English spelling.
+
+ include("../config.php");
+
+ $enrol = required_param('enrol', PARAM_ALPHA);
+
+ require_login();
+
+ if (!$site = get_site()) {
+ redirect("index.php");
+ }
+
+ if (!isadmin()) {
+ error("Only the admin can use this page");
+ }
+
+ if (!confirm_sesskey()) {
+ error(get_string('confirmsesskeybad', 'error'));
+ }
+
+ require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
+
+ $enrolment = enrolment_factory::factory($enrol);
+
+/// If data submitted, then process and store.
+
+ if ($frm = data_submitted()) {
+ if ($enrolment->process_config($frm)) {
+ redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
+ }
+ } else {
+ $frm = $CFG;
+ }
+
+/// Otherwise fill and print the form.
+
+ /// get language strings
+ $str = get_strings(array('enrolmentplugins', 'configuration', 'users', 'administration'));
+
+
+ $modules = get_list_of_plugins("enrol");
+ foreach ($modules as $module) {
+ $options[$module] = get_string("enrolname", "enrol_$module");
+ }
+ asort($options);
+
+ print_header("$site->shortname: $str->enrolmentplugins", "$site->fullname",
+ "<a href=\"index.php\">$str->administration</a> ->
+ <a href=\"users.php\">$str->users</a> ->
+ <a href=\"enrol.php\">$str->enrolmentplugins</a> ->
+ $str->configuration");
+
+ echo "<form target=\"{$CFG->framename}\" name=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">";
+ echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">";
+ echo "<div align=\"center\"><p><b>";
+
+
+/// Choose an enrolment method
+ echo get_string('chooseenrolmethod').': ';
+ choose_from_menu ($options, "enrol", $enrol, "",
+ "document.location='enrol_config.php?sesskey=$USER->sesskey&enrol='+document.enrolmenu.enrol.options[document.enrolmenu.enrol.selectedIndex].value", "");
+
+ echo "</b></p></div>";
+
+/// Print current enrolment type description
+ print_simple_box_start("center", "80%");
+ print_heading($options[$enrol]);
+
+ print_simple_box_start("center", "60%", '', 5, 'informationbox');
+ print_string("description", "enrol_$enrol");
+ print_simple_box_end();
+
+ echo "<hr />";
+
+ $enrolment->config_form($frm);
+
+ echo "<center><p><input type=\"submit\" value=\"".get_string("savechanges")."\"></p></center>\n";
+ echo "</form>";
+
+ print_simple_box_end();
+
+ print_footer();
+
+ exit;
+?>
$userdata .= '<div class="adminlink"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/uploaduser.php?sesskey='.$USER->sesskey.'">'.
get_string('uploadusers').'</a> - <span class="explanation">'.get_string('adminhelpuploadusers').'</span></div>';
- $userdata .= '<hr /><div class="adminlink"><a href="enrol.php?sesskey='.$USER->sesskey.'">'.get_string('enrolments').
+ $userdata .= '<hr /><div class="adminlink"><a href="enrol.php?sesskey='.$USER->sesskey.'">'.get_string('enrolmentplugins').
'</a> - <span class="explanation">'.get_string('adminhelpenrolments').'</span></div>';
$userdata .= '<div class="adminlink"><a href="../course/index.php?edit=off&sesskey='.$USER->sesskey.'">'.
get_string('assignstudents').'</a> - <span class="explanation">'.get_string('adminhelpassignstudents').'</span></div>';
}
$table->data[] = array('<strong><a href="environment.php">'.get_string('environment','admin').'</a></strong>',
'<div class="explanation">'.get_string('adminhelpenvironment').'</div>');
+
if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
$table->data[] = array("<strong><a href=\"$CFG->dbtype/frame.php\">".get_string('managedatabase').'</a></strong>',
get_string('adminhelpmanagedatabase'));
$table->data[] = array("<b><a href=\"$CFG->wwwroot/$CFG->admin/uploaduser.php?sesskey=$USER->sesskey\">".get_string("uploadusers")."</a></b>",
get_string("adminhelpuploadusers"));
$table->data[] = array('', '<hr />');
- $table->data[] = array("<b><a href=\"enrol.php?sesskey=$USER->sesskey\">".get_string("enrolments")."</a></b>",
+ $table->data[] = array("<b><a href=\"enrol.php?sesskey=$USER->sesskey\">".get_string("enrolmentplugins")."</a></b>",
get_string("adminhelpenrolments"));
$table->data[] = array("<b><a href=\"../course/index.php?edit=off&sesskey=$USER->sesskey\">".get_string("assignstudents")."</a></b>",
get_string("adminhelpassignstudents"));
if (!isset($form->theme)) {
$form->theme = '';
}
+ if (!isset($form->enrol)) {
+ $form->enrol = '';
+ }
if (!isset($form->enrollable)) {
$form->enrollable = 1;
}
helpbutton("coursestartdate", get_string("startdate"));
?></td>
</tr>
+<tr valign="top">
+ <td align="right"><?php print_string("enrolmentplugins") ?>:</td>
+ <td><?php
+ unset($choices);
+ $modules = get_list_of_plugins("enrol");
+ foreach ($modules as $module) {
+ $name = get_string("enrolname", "enrol_$module");
+ $plugin = enrolment_factory::factory($module);
+ if (method_exists($plugin, 'print_entry')) {
+ $choices[$name] = $module;
+ }
+ }
+ asort($choices);
+ $choices = array_flip($choices);
+ $choices = array_merge(array('' => get_string('sitedefault')), $choices);
+ choose_from_menu ($choices, "enrol", "$form->enrol", "");
+ helpbutton("courseenrolmentplugins", get_string("enrolmentplugins"));
+ ?></td>
+</tr>
<tr valign="top">
<td align="right"><?php print_string("enrollable") ?>:</td>
<td><?php
</td>
</tr>
<?php
- if ($CFG->enrol != 'internal') {
+ if (method_exists(enrolment_factory::factory($course->enrol), 'print_entry') && $course->enrol != 'internal') {
?>
<tr valign="top">
<td align="right"><?php print_string("cost") ?>:</td>
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
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);
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
}
/// 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())
print_course($course, $width);
}
} else {
- print_heading(get_string('nocoursesyet'));
- if (iscreator()) {
- $options = array();
- $options['category'] = $category->id;
- echo '<div class="addcoursebutton" align="center">';
- print_single_button($CFG->wwwroot.'/course/edit.php', $options, get_string('addnewcourse'));
- echo '</div>';
- }
+ print_heading(get_string("nocoursesyet"));
}
}
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");
* enrolment_plugin_authorize
*
*/
-class enrolment_plugin extends enrolment_base
+class enrolment_plugin_authorize
{
/**
* Credit card error messages.
{
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);
* @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);
}
*/
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) {
function cron()
{
global $CFG;
- parent::cron();
+ $internal = enrolment_factory::factory('internal');
+ $internal->cron();
require_once $CFG->dirroot.'/enrol/authorize/action.php';
$oneday = 86400;
<th colspan="2">
<?php print_string("general_options", "enrol_database") ?>
</td>
-<tr valign="top">
- <td align="right">enrol_allowinternal:</td>
- <td>
- <input type="checkbox" name="enrol_allowinternal" <?php if ($frm->enrol_allowinternal) echo "checked=\"true\"" ?> />
- </td>
- <td>
- <?php print_string('allowinternal') ?>
- </td>
-</tr>
</table>
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()) {
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) {
}
'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 = '';
$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;
}
}
// 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;
</td>
</tr>
-<tr valign="top">
- <td align="right">enrol_allowinternal:</td>
- <td>
- <input type="checkbox" value="1" name="enrol_allowinternal" <?php if ($frm->enrol_allowinternal) echo "checked=\"true\"" ?> />
- </td>
- <td>
- <?php print_string('allowinternal') ?>
- </td>
-</tr>
-
</table>
<?php
-require_once("$CFG->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;
}
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
*
function cron() {
global $CFG;
- /// call the base class
- parent::cron();
-
if (empty($CFG->enrol_flatfilelocation)) {
$filename = "$CFG->dataroot/1/enrolments.txt"; // Default location
} else {
-<?php
-require_once("$CFG->dirroot/enrol/enrol.class.php");
+<?php /// $Id$
+///////////////////////////////////////////////////////////////////////////
+// //
+// NOTICE OF COPYRIGHT //
+// //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment //
+// http://moodle.org //
+// //
+// Copyright (C) 2004 Martin Dougiamas http://moodle.com //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation; either version 2 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details: //
+// //
+// http://www.gnu.org/copyleft/gpl.html //
+// //
+///////////////////////////////////////////////////////////////////////////
-class enrolment_plugin extends enrolment_base {
- /// nothing to do - it's already perfect!
+
+/**
+* enrolment_plugin_internal is the default enrolment plugin
+*
+* This class provides all the functionality for an enrolment plugin
+* In fact it includes all the code for the default, "internal" method
+* so that other plugins can override these as necessary.
+*/
+
+class enrolment_plugin_internal {
+
+var $errormsg;
+
+
+
+/**
+* Returns information about the courses a student has access to
+*
+* Set the $user->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, "<a href=\".\">$strcourses</a> -> $strloginto");
+ echo "<br />";
+ 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, "<a href=\".\">$strcourses</a> -> $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 .= '<a title="'.$strallowguests.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
+ $str .= '<img vspace="4" alt="'.$strallowguests.'" height="16" width="16" border="0" '.
+ 'src="'.$CFG->pixpath.'/i/guest.gif" /></a> ';
+ }
+ if (!empty($course->password)) {
+ $strrequireskey = get_string("requireskey");
+ $str .= '<a title="'.$strrequireskey.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
+ $str .= '<img vspace="4" alt="'.$strrequireskey.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/key.gif" /></a>';
+ }
+
+ return $str;
+}
+
+
+} /// end of class
+
?>
$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, '');
+
?>
<table cellspacing="0" cellpadding="5" border="0" align="center">
</td>
</tr>
-<tr valign="top">
- <td align="right">enrol_allowinternal:</td>
- <td>
- <input type="checkbox" name="enrol_allowinternal" <?php if ($frm->enrol_allowinternal) echo "checked=\"true\"" ?> />
- </td>
- <td>
- <?php print_string('allowinternal') ?>
- </td>
-</tr>
-
</table>
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
}
-/// 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) {
}
$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;
}
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);
require_once("$CFG->dirroot/enrol/enrol.class.php");
-class enrolment_plugin extends enrolment_base {
+class enrolment_plugin_paypal {
/// Override the base print_entry() function
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 {
}
if (abs($cost) < 0.01) {
- $str = parent::get_access_icons($course);
+ $internal = enrolment_factory::factory('internal');
+ $str = $internal->get_access_icons($course);
} else {
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
<?php // $Id$
require("../../config.php");
- require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");
+ require_once("$CFG->dirroot/enrol/paypal/enrol.php");
require_variable($id);
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) {
--- /dev/null
+<p>Choose default interactive enrolment plugin used in this course</p>
--- /dev/null
+<p>Choose default interactive enrolment plugin used in this course</p>
$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';
$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 <br /> $a';
+$string['enrolmentplugins'] = 'Enrolment Plugins';
$string['enrolments'] = 'Enrolments';
$string['enrolmentstart'] = 'Enrolment Started';
$string['enrolperiod'] = 'Enrolment duration';
$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 <a href=\"mailto:$a->email\">$a->firstname $a->lastname</a> .';
$string['forgotaccount'] = 'Lost password?';
$string['format'] = 'Format';
$string['formathtml'] = 'HTML format';
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);
}
modify_database('',"ALTER TABLE prefix_log ADD INDEX info (info);");
}
+ if ($oldversion < 2006030900) {
+ table_column('course','','enrol','varchar','20','','');
+ }
+
return $result;
}
`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`),
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');
}
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;
}
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);
$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
// 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