MDL-10689:
[moodle-linuxchix.git] / admin / enrol.php
blob8e0cfdfd6bf42aa40695160403ea1a8e78e71793
1 <?PHP // $Id$
2 // enrol.php - allows admin to edit all enrollment variables
3 // Yes, enrol is correct English spelling.
5 require_once('../config.php');
6 require_once($CFG->libdir.'/adminlib.php');
8 $enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR);
9 $CFG->pagepath = 'enrol';
11 admin_externalpage_setup('enrolment');
15 require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
17 /// Save settings
19 if ($frm = data_submitted()) {
20 if (!confirm_sesskey()) {
21 error(get_string('confirmsesskeybad', 'error'));
23 if (empty($frm->enable)) {
24 $frm->enable = array();
26 if (empty($frm->default)) {
27 $frm->default = '';
29 if ($frm->default && $frm->default != 'manual' && !in_array($frm->default, $frm->enable)) {
30 $frm->enable[] = $frm->default;
32 asort($frm->enable);
33 $frm->enable = array_merge(array('manual'), $frm->enable); // make sure manual plugin is called first
34 set_config('enrol_plugins_enabled', implode(',', $frm->enable));
35 set_config('enrol', $frm->default);
36 redirect("enrol.php", get_string("changessaved"), 1);
39 /// Print the form
41 $str = get_strings(array('enrolmentplugins', 'users', 'administration', 'settings', 'edit'));
43 admin_externalpage_print_header();
45 $modules = get_list_of_plugins("enrol");
46 $options = array();
47 foreach ($modules as $module) {
48 $options[$module] = get_string("enrolname", "enrol_$module");
50 asort($options);
52 print_simple_box(get_string('configenrolmentplugins', 'admin'), 'center', '700');
54 echo "<form $CFG->frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
55 echo "<div>";
56 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />";
58 $table = new stdClass();
59 $table->head = array(get_string('name'), get_string('enable'), get_string('default'), $str->settings);
60 $table->align = array('left', 'center', 'center', 'center');
61 $table->size = array('60%', '', '', '15%');
62 $table->width = '700';
63 $table->data = array();
65 $modules = get_list_of_plugins("enrol");
66 $enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
67 foreach ($modules as $module) {
69 // skip if directory is empty
70 if (!file_exists("$CFG->dirroot/enrol/$module/enrol.php")) {
71 continue;
74 $name = get_string("enrolname", "enrol_$module");
75 $plugin = enrolment_factory::factory($module);
76 $enable = '<input type="checkbox" name="enable[]" value="'.$module.'"';
77 if (in_array($module, $enabledplugins)) {
78 $enable .= ' checked="checked"';
80 if ($module == 'manual') {
81 $enable .= ' disabled="disabled"';
83 $enable .= ' />';
84 if (method_exists($plugin, 'print_entry')) {
85 $default = '<input type="radio" name="default" value="'.$module.'"';
86 if ($CFG->enrol == $module) {
87 $default .= ' checked="checked"';
89 $default .= ' />';
90 } else {
91 $default = '';
93 $table->data[$name] = array($name, $enable, $default,
94 '<a href="enrol_config.php?enrol='.$module.'">'.$str->edit.'</a>');
96 asort($table->data);
98 print_table($table);
100 echo "<div style=\"text-align:center\"><input type=\"submit\" value=\"".get_string("savechanges")."\" /></div>\n";
101 echo "</div>";
102 echo "</form>";
104 admin_externalpage_print_footer();