From f9667a5aeafbbf9cb9911579a686a70ac8705bbd Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Thu, 9 Mar 2006 02:48:29 +0000 Subject: [PATCH] [multienrol]Initial commit for multi enrolment plugin feature --- admin/cron.php | 18 +- admin/enrol.php | 94 ++-- admin/enrol_config.php | 87 ++++ admin/index.php | 3 +- admin/users.php | 2 +- course/edit.html | 24 +- course/edit.php | 1 + course/enrol.php | 26 +- course/lib.php | 16 +- enrol/authorize/enrol.php | 21 +- enrol/database/config.html | 9 - enrol/database/enrol.php | 45 +- enrol/flatfile/config.html | 10 - enrol/flatfile/enrol.php | 40 +- enrol/internal/enrol.php | 432 +++++++++++++++++- enrol/ldap/config.html | 27 +- enrol/ldap/enrol.php | 47 +- enrol/ldap/enrol_ldap_sync.php | 4 +- enrol/paypal/enrol.php | 37 +- enrol/paypal/return.php | 4 +- lang/en/help/courseenrolmentplugins.html | 1 + lang/en_utf8/help/courseenrolmentplugins.html | 1 + lang/en_utf8/moodle.php | 6 +- lib/db/mysql.php | 6 +- lib/db/mysql.sql | 1 + lib/db/postgres7.php | 7 +- lib/db/postgres7.sql | 3 +- lib/moodlelib.php | 20 +- version.php | 2 +- 29 files changed, 722 insertions(+), 272 deletions(-) create mode 100644 admin/enrol_config.php create mode 100644 lang/en/help/courseenrolmentplugins.html create mode 100644 lang/en_utf8/help/courseenrolmentplugins.html 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 "
framename}\" name=\"enrolmenu\" method=\"post\" action=\"enrol.php\">"; echo "sesskey."\">"; - echo "

"; + $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(); -/// 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", ""); + $modules = get_list_of_plugins("enrol"); + foreach ($modules as $module) { + $name = get_string("enrolname", "enrol_$module"); + $plugin = enrolment_factory::factory($module); + $enable = 'enrol_plugins_enabled, $module) !== false) { + $enable .= ' checked="checked"'; + } + if ($module == 'internal') { + $enable .= ' disabled="disabled" />enrol == $module) { + $default .= ' checked="checked"'; + } + $default .= ' />'; + } else { + $default = ''; + } + $table->data[$name] = array($name, $enable, $default, + ''.$str->edit.''); + } + asort($table->data); - echo "

"; - -/// Print current enrolment type description - print_simple_box_start("center", "80%"); - print_heading($options[$enrol]); + print_table($table); - print_simple_box_start("center", "60%", '', 5, 'informationbox'); - print_string("description", "enrol_$enrol"); - print_simple_box_end(); - - echo "
"; - // print_heading($str->settings); - - $enrolment->config_form($frm); - - echo "

\n"; + echo "
\n"; echo "
"; - print_simple_box_end(); - print_footer(); - exit; -?> +?> \ No newline at end of file diff --git a/admin/enrol_config.php b/admin/enrol_config.php new file mode 100644 index 00000000000..7148f6c03b5 --- /dev/null +++ b/admin/enrol_config.php @@ -0,0 +1,87 @@ +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", + "$str->administration -> + $str->users -> + $str->enrolmentplugins -> + $str->configuration"); + + echo "
framename}\" name=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">"; + echo "sesskey."\">"; + echo "

"; + + +/// 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 "

"; + +/// 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 "
"; + + $enrolment->config_form($frm); + + echo "

\n"; + echo "
"; + + print_simple_box_end(); + + print_footer(); + + exit; +?> diff --git a/admin/index.php b/admin/index.php index 2967841e156..b36b8288f9a 100644 --- a/admin/index.php +++ b/admin/index.php @@ -401,7 +401,7 @@ $userdata .= ''; - $userdata .= '