options.php 13.8 KB
Newer Older
Nigel McNie's avatar
Nigel McNie committed
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
Nigel McNie's avatar
Nigel McNie committed
6
 *
Francois Marier's avatar
Francois Marier committed
7
8
9
10
 * 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 3 of the License, or
 * (at your option) any later version.
Nigel McNie's avatar
Nigel McNie committed
11
 *
Francois Marier's avatar
Francois Marier committed
12
13
14
15
 * 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.
Nigel McNie's avatar
Nigel McNie committed
16
 *
Francois Marier's avatar
Francois Marier committed
17
18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Nigel McNie's avatar
Nigel McNie committed
19
20
21
 *
 * @package    mahara
 * @subpackage admin
22
 * @author     Catalyst IT Ltd
Nigel McNie's avatar
Nigel McNie committed
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
Nigel McNie's avatar
Nigel McNie committed
25
26
27
 *
 */

28
29
define('INTERNAL', 1);
define('ADMIN', 1);
30
define('MENUITEM', 'configsite/siteoptions');
31
32
33
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'siteoptions');
Nigel McNie's avatar
Nigel McNie committed
34
35
36

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
37
require_once('searchlib.php');
Nigel McNie's avatar
Nigel McNie committed
38
define('TITLE', get_string('siteoptions', 'admin'));
Nigel McNie's avatar
Nigel McNie committed
39
40
41
42
43
44

$langoptions = get_languages();
$themeoptions = get_themes();
$yesno = array(true  => get_string('yes'),
               false => get_string('no'));

45
46
$searchpluginoptions = get_search_plugins();

47
$siteoptionform = array(
Penny Leach's avatar
Penny Leach committed
48
49
50
51
52
    'name'       => 'siteoptions',
    'jsform'     => true,
    'renderer'   => 'table',
    'plugintype' => 'core',
    'pluginname' => 'admin',
53
    'jssuccesscallback' => 'checkReload',
Penny Leach's avatar
Penny Leach committed
54
    'elements'   => array(
Nigel McNie's avatar
Nigel McNie committed
55
56
        'sitename' => array(
            'type'         => 'text',
57
58
            'title'        => get_string('sitename', 'admin'),
            'description'  => get_string('sitenamedescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
59
            'defaultvalue' => get_config('sitename'),
Penny Leach's avatar
Penny Leach committed
60
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
61
        ),
62
        'lang' => array(
Nigel McNie's avatar
Nigel McNie committed
63
            'type'         => 'select',
64
65
            'title'        => get_string('language', 'admin'),
            'description'  => get_string('sitelanguagedescription', 'admin'),
66
            'defaultvalue' => get_config('lang'),
Nigel McNie's avatar
Nigel McNie committed
67
68
            'collapseifoneoption' => true,
            'options'      => $langoptions,
Penny Leach's avatar
Penny Leach committed
69
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
70
        ),
71
72
73
74
75
76
77
78
        'country' => array(
            'type'         => 'select',
            'title'        => get_string('country', 'admin'),
            'description'  => get_string('sitecountrydescription', 'admin'),
            'defaultvalue' => 'nz',
            'options'      => getoptions_country(),
            'help'         => true,
        ),
Nigel McNie's avatar
Nigel McNie committed
79
80
        'theme' => array(
            'type'         => 'select',
81
82
            'title'        => get_string('theme', 'admin'),
            'description'  => get_string('sitethemedescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
83
84
85
            'defaultvalue' => get_config('theme'),
            'collapseifoneoption' => true,
            'options'      => $themeoptions,
Penny Leach's avatar
Penny Leach committed
86
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
87
        ),
88
89
        'searchplugin' => array(
            'type'         => 'select',
90
91
            'title'        => get_string('searchplugin', 'admin'),
            'description'  => get_string('searchplugindescription', 'admin'),
92
93
94
            'defaultvalue' => get_config('searchplugin'),
            'collapseifoneoption' => true,
            'options'      => $searchpluginoptions,
Penny Leach's avatar
Penny Leach committed
95
            'help'         => true,
96
        ),
Nigel McNie's avatar
Nigel McNie committed
97
98
        'viruschecking' => array(
            'type'         => 'checkbox',
99
100
            'title'        => get_string('viruschecking', 'admin'),
            'description'  => get_string('viruscheckingdescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
101
            'defaultvalue' => get_config('viruschecking'),
Penny Leach's avatar
Penny Leach committed
102
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
103
104
105
        ),
        'pathtoclam' => array(
            'type'         => 'text',
106
107
            'title'        => get_string('pathtoclam', 'admin'),
            'description'  => get_string('pathtoclamdescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
108
            'defaultvalue' => get_config('pathtoclam'),
Penny Leach's avatar
Penny Leach committed
109
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
110
111
112
113
        ),
        'sessionlifetime' => array(
            'type'         => 'text',
            'size'         => 4,
114
115
            'title'        => get_string('sessionlifetime', 'admin'),
            'description'  => get_string('sessionlifetimedescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
116
            'defaultvalue' => get_config('session_timeout') / 60,
117
            'rules'        => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 10000000),
Penny Leach's avatar
Penny Leach committed
118
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
119
120
121
        ),
        'allowpublicviews' => array(
            'type'         => 'select',
122
123
            'title'        => get_string('allowpublicviews', 'admin'),
            'description'  => get_string('allowpublicviewsdescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
124
125
            'defaultvalue' => get_config('allowpublicviews'),
            'options'      => $yesno,
Penny Leach's avatar
Penny Leach committed
126
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
127
        ),
128
129
130
131
132
133
134
135
        'allowpublicprofiles' => array(
            'type'         => 'select',
            'title'        => get_string('allowpublicprofiles', 'admin'),
            'description'  => get_string('allowpublicprofilesdescription', 'admin'),
            'defaultvalue' => get_config('allowpublicprofiles'),
            'options'      => $yesno,
            'help'         => true,
        ),
136
137
138
139
140
141
142
143
144
145
146
        'creategroups' => array(
            'type'         => 'select',
            'title'        => get_string('whocancreategroups', 'admin'),
            'description'  => get_string('whocancreategroupsdescription', 'admin'),
            'defaultvalue' => get_config('creategroups'),
            'options'      => array(
                'admins' => get_string('adminsonly', 'admin'),
                'staff'  => get_string('adminsandstaffonly', 'admin'),
                'all'    => get_string('Everyone', 'admin'),
            ),
        ),
147
148
149
150
151
152
153
154
155
156
157
        'createpublicgroups' => array(
            'type'         => 'select',
            'title'        => get_string('whocancreatepublicgroups', 'admin'),
            'description'  => get_string('whocancreatepublicgroupsdescription', 'admin'),
            'defaultvalue' => get_config('createpublicgroups'),
            'options'      => array(
                'admins' => get_string('adminsonly', 'admin'),
                'all' => get_string('Everyone', 'admin'),
            ),
            'help'         => true,
        ),
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
        'defaultaccountlifetime' => array(
            'type'         => 'expiry',
            'title'        => get_string('defaultaccountlifetime', 'admin'),
            'description'  => get_string('defaultaccountlifetimedescription', 'admin'),
            'defaultvalue' => get_config('defaultaccountlifetime'),
            'help'         => true,
        ),
        'defaultaccountinactiveexpire' => array(
            'type'         => 'expiry',
            'title'        => get_string('defaultaccountinactiveexpire', 'admin'),
            'description'  => get_string('defaultaccountinactiveexpiredescription', 'admin'),
            'defaultvalue' => get_config('defaultaccountinactiveexpire'),
            'help'         => true,
        ),
        'defaultaccountinactivewarn' => array(
            'type'         => 'expiry',
            'title'        => get_string('defaultaccountinactivewarn', 'admin'),
            'description'  => get_string('defaultaccountinactivewarndescription', 'admin'),
            'defaultvalue' => get_config('defaultaccountinactivewarn'),
            'help'         => true,
        ),
179
180
        'usersallowedmultipleinstitutions' => array(
            'type'         => 'checkbox',
181
182
            'title'        => get_string('usersallowedmultipleinstitutions', 'admin'),
            'description'  => get_string('usersallowedmultipleinstitutionsdescription', 'admin'),
183
            'defaultvalue' => get_config('usersallowedmultipleinstitutions'),
184
            'help'         => true,
185
        ),
186
187
188
189
190
191
192
        'registration_sendweeklyupdates' => array(
            'type'         => 'checkbox',
            'title'        => get_string('sendweeklyupdates', 'admin'),
            'description'  => get_string('sendweeklyupdatesdescription', 'admin'),
            'defaultvalue' => get_config('registration_sendweeklyupdates'),
            'help'         => true,
        ),
193
194
195
196
197
198
199
        'institutionexpirynotification' => array(
            'type'         => 'expiry',
            'title'        => get_string('institutionexpirynotification', 'admin'),
            'description'  => get_string('institutionexpirynotificationdescription', 'admin'),
            'defaultvalue' => is_null(get_config('institutionexpirynotification')) ? '2592000' : get_config('institutionexpirynotification'),
            'help'         => true,
        ),
200
201
202
203
204
205
206
        'institutionautosuspend' => array(
            'type'         => 'checkbox',
            'title'        => get_string('institutionautosuspend', 'admin'),
            'description'  => get_string('institutionautosuspenddescription', 'admin'),
            'defaultvalue' => get_config('institutionautosuspend'),
            'help'         => true,
        ),
207
208
209
210
211
212
213
214
215
216
217
218
        'captchaonregisterform' => array(
            'type'         => 'checkbox',
            'title'        => get_string('captchaonregisterform', 'admin'),
            'description'  => get_string('captchaonregisterformdescription', 'admin'),
            'defaultvalue' => get_config('captchaonregisterform'),
        ),
        'captchaoncontactform' => array(
            'type'         => 'checkbox',
            'title'        => get_string('captchaoncontactform', 'admin'),
            'description'  => get_string('captchaoncontactformdescription', 'admin'),
            'defaultvalue' => get_config('captchaoncontactform'),
        ),
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
        'showselfsearchsideblock' => array(
            'type'         => 'checkbox',
            'title'        => get_string('showselfsearchsideblock', 'admin'),
            'description'  => get_string('showselfsearchsideblockdescription', 'admin'),
            'defaultvalue' => get_config('showselfsearchsideblock'),
        ),
        'showtagssideblock' => array(
            'type'         => 'checkbox',
            'title'        => get_string('showtagssideblock', 'admin'),
            'description'  => get_string('showtagssideblockdescription', 'admin'),
            'defaultvalue' => get_config('showtagssideblock'),
        ),
        'tagssideblockmaxtags' => array(
            'type'         => 'text',
            'size'         => 4,
            'title'        => get_string('tagssideblockmaxtags', 'admin'),
            'description'  => get_string('tagssideblockmaxtagsdescription', 'admin'),
            'defaultvalue' => get_config('tagssideblockmaxtags'),
            'rules'        => array('integer' => true, 'minvalue' => 0, 'maxvalue' => 1000),
        ),
Nigel McNie's avatar
Nigel McNie committed
239
    )
240
241
242
243
244
245
246
247
);

$siteoptionform['elements']['submit'] = array(
    'type'  => 'submit',
    'value' => get_string('updatesiteoptions', 'admin')
);

$siteoptionform = pieform($siteoptionform);
Nigel McNie's avatar
Nigel McNie committed
248

249
function siteoptions_fail(Pieform $form, $field) {
250
251
252
253
    $form->reply(PIEFORM_ERR, array(
        'message' => get_string('setsiteoptionsfailed', 'admin', get_string($field, 'admin')),
        'goto'    => '/admin/site/options.php',
    ));
Nigel McNie's avatar
Nigel McNie committed
254
255
}

256
function siteoptions_submit(Pieform $form, $values) {
257
258
259
    $fields = array(
        'sitename','lang','theme', 'pathtoclam',
        'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
260
        'allowpublicviews', 'allowpublicprofiles', 'creategroups', 'createpublicgroups', 'searchplugin',
261
        'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend',
262
263
        'captchaonregisterform', 'captchaoncontactform', 'showselfsearchsideblock', 'showtagssideblock',
        'tagssideblockmaxtags'
264
    );
265
    $oldlanguage = get_config('lang');
266
    $oldtheme = get_config('theme');
Nigel McNie's avatar
Nigel McNie committed
267
268
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
269
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
270
271
        }
    }
272
273
274
275
276
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
    
Nigel McNie's avatar
Nigel McNie committed
277
278
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
279
        siteoptions_fail($form, 'sessionlifetime');
Nigel McNie's avatar
Nigel McNie committed
280
281
    }
    // Submitted value is on/off; database entry should be 1/0
282
283
284
285
    foreach(array('viruschecking', 'usersallowedmultipleinstitutions') as $checkbox) {
        if (!set_config($checkbox, (int) ($values[$checkbox] == 'on'))) {
            siteoptions_fail($form, $checkbox);
        }
Nigel McNie's avatar
Nigel McNie committed
286
    }
287

288
289
290
291
292
293
294
295
296
297
    if ($values['viruschecking'] == 'on') {
        $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
        if (!$pathtoclam || !file_exists($pathtoclam) && !is_executable($pathtoclam)) {
            $form->reply(PIEFORM_ERR, array(
                'message' => get_string('clamlost', 'mahara', $pathtoclam),
                'goto'    => '/admin/site/options.php',
            ));
        }
    }

298
299
    $message = get_string('siteoptionsset', 'admin');
    if ($oldtheme != $values['theme']) {
300
        global $USER;
301
        $message .= '  ' . get_string('usersseenewthemeonlogin', 'admin');
302
        $USER->update_theme();
303
304
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php'));
Nigel McNie's avatar
Nigel McNie committed
305
306
}

307
308
309
$thispage = json_encode(get_config('wwwroot') . 'admin/site/options.php');
$smarty = smarty(array('adminsiteoptions'));
$smarty->assign('siteoptionform', $siteoptionform);
Richard Mansfield's avatar
Richard Mansfield committed
310
$smarty->assign('PAGEHEADING', hsc(get_string('siteoptions', 'admin')));
311
$smarty->display('admin/site/options.tpl');
Nigel McNie's avatar
Nigel McNie committed
312
313

?>