Skip to content

Commit

Permalink
[multienrol]Initial commit for multi enrolment plugin feature
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlanghoff committed Mar 9, 2006
1 parent 379bf73 commit f9667a5
Show file tree
Hide file tree
Showing 29 changed files with 722 additions and 272 deletions.
18 changes: 13 additions & 5 deletions admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
94 changes: 54 additions & 40 deletions admin/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
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();
Expand All @@ -49,41 +55,49 @@
}
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.'&amp;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;
?>
?>
87 changes: 87 additions & 0 deletions admin/enrol_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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;
?>
3 changes: 2 additions & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
$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&amp;sesskey='.$USER->sesskey.'">'.
get_string('assignstudents').'</a> - <span class="explanation">'.get_string('adminhelpassignstudents').'</span></div>';
Expand Down Expand Up @@ -430,6 +430,7 @@
}
$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'));
Expand Down
2 changes: 1 addition & 1 deletion admin/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$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&amp;sesskey=$USER->sesskey\">".get_string("assignstudents")."</a></b>",
get_string("adminhelpassignstudents"));
Expand Down
24 changes: 23 additions & 1 deletion course/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
if (!isset($form->theme)) {
$form->theme = '';
}
if (!isset($form->enrol)) {
$form->enrol = '';
}
if (!isset($form->enrollable)) {
$form->enrollable = 1;
}
Expand Down Expand Up @@ -109,6 +112,25 @@
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
Expand Down Expand Up @@ -249,7 +271,7 @@
</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>
Expand Down
1 change: 1 addition & 0 deletions course/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions course/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down
16 changes: 3 additions & 13 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="addcoursebutton" align="center">';
print_single_button($CFG->wwwroot.'/course/edit.php', $options, get_string('addnewcourse'));
echo '</div>';
}
print_heading(get_string("nocoursesyet"));
}

}
Expand All @@ -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");

Expand Down
Loading

0 comments on commit f9667a5

Please sign in to comment.