enrol.php 5.31 KB
Newer Older
1
2
3
4
<?PHP  // $Id$
       // enrol.php - allows admin to edit all enrollment variables
       //             Yes, enrol is correct English spelling.

skodak's avatar
skodak committed
5
    require_once('../config.php');
6
    require_once($CFG->libdir.'/adminlib.php');
moodler's avatar
moodler committed
7

8
9
10
    $enrol        = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR);
    $savesettings = optional_param('savesettings', 0, PARAM_BOOL);

11
    admin_externalpage_setup('enrolment');
12

13
14
15
    if (!isset($CFG->sendcoursewelcomemessage)) {
        set_config('sendcoursewelcomemessage', 1);
    }
16

17

18
    require_once("$CFG->dirroot/enrol/enrol.class.php");   /// Open the factory class
19

20
/// Save settings
21

22
    if ($frm = data_submitted() and !$savesettings) {
vinkmar's avatar
vinkmar committed
23
        if (!confirm_sesskey()) {
Francois Marier's avatar
Francois Marier committed
24
            print_error('confirmsesskeybad', 'error');
25
        }
26
27
28
29
30
31
        if (empty($frm->enable)) {
            $frm->enable = array();
        }
        if (empty($frm->default)) {
            $frm->default = '';
        }
32
        if ($frm->default && $frm->default != 'manual' && !in_array($frm->default, $frm->enable)) {
33
            $frm->enable[] = $frm->default;
34
        }
35
        asort($frm->enable);
36
        $frm->enable = array_merge(array('manual'), $frm->enable); // make sure manual plugin is called first
37
38
        set_config('enrol_plugins_enabled', implode(',', $frm->enable));
        set_config('enrol', $frm->default);
vinkmar's avatar
vinkmar committed
39
        redirect("enrol.php", get_string("changessaved"), 1);
40
41
42
43
44
45

    } else if ($frm = data_submitted() and $savesettings) {
        if (!confirm_sesskey()) {
            print_error('confirmsesskeybad', 'error');
        }
        set_config('sendcoursewelcomemessage', required_param('sendcoursewelcomemessage', PARAM_BOOL));
46
    }
47

48
/// Print the form
49

50
    $str = get_strings(array('enrolmentplugins', 'users', 'administration', 'settings', 'edit'));
51

52
    admin_externalpage_print_header();
53

54
    $modules = get_plugin_list('enrol');
skodak's avatar
skodak committed
55
    $options = array();
56
    foreach ($modules as $module => $moduledir) {
57
        $options[$module] = get_string("enrolname", "enrol_$module");
58
    }
59
    asort($options);
60

61
    print_simple_box(get_string('configenrolmentplugins', 'admin'), 'center', '700');
62

63
    echo "<form $CFG->frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
toyomoyo's avatar
toyomoyo committed
64
    echo "<div>";
skodak's avatar
skodak committed
65
    echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
66

67
68
69
70
71
72
    $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();
73

74
    $enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
75
    foreach ($modules as $module => $moduledir) {
76
77

        // skip if directory is empty
78
        if (!file_exists("$moduledir/enrol.php")) {
79
80
81
            continue;
        }

82
83
84
        $name = get_string("enrolname", "enrol_$module");
        $plugin = enrolment_factory::factory($module);
        $enable = '<input type="checkbox" name="enable[]" value="'.$module.'"';
85
        if (in_array($module, $enabledplugins)) {
86
87
            $enable .= ' checked="checked"';
        }
88
        if ($module == 'manual') {
89
            $enable .= ' disabled="disabled"';
90
91
92
93
94
95
96
97
98
99
100
101
        }
        $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,
vinkmar's avatar
vinkmar committed
102
                                '<a href="enrol_config.php?enrol='.$module.'">'.$str->edit.'</a>');
103
104
    }
    asort($table->data);
105

106
    print_table($table);
107

toyomoyo's avatar
toyomoyo committed
108
109
    echo "<div style=\"text-align:center\"><input type=\"submit\" value=\"".get_string("savechanges")."\" /></div>\n";
    echo "</div>";
110
111
    echo "</form>";

112
113
114
115
116
117
    echo '<hr />';

    $yesnooptions = array(0=>get_string('no'), 1=>get_string('yes'));

    echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="enrol.php">';
    echo '<div class="settingsform clearfix">';
118
    echo $OUTPUT->heading(get_string('commonsettings', 'admin'));
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
    echo '<input type="hidden" name="savesettings" value="1" />';
    echo '<fieldset>';
    echo '<div class="form-item clearfix" id="admin-sendcoursewelcomemessage">';
    
    echo '<div class="form-label"><label for = "menusendcoursewelcomemessage">' . get_string('sendcoursewelcomemessage', 'admin');
    echo '<span class="form-shortname">sendcoursewelcomemessage</span>';
    echo '</label></div>';
    echo '<div class="form-setting"><div class="form-checkbox defaultsnext">';
    choose_from_menu($yesnooptions, 'sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, '');
    echo '</div><div class="form-defaultinfo">'.get_string('defaultsettinginfo', 'admin', get_string('yes')).'</div></div>';
    echo '<div class="form-description">' . get_string('configsendcoursewelcomemessage', 'admin') . '</div>';
    echo '</div>';

    echo '</fieldset>';

    echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
    echo '</div>';
    echo '</form>';

139
    echo $OUTPUT->footer();
140

Francois Marier's avatar
Francois Marier committed
141
?>