options.php 48.8 KB
Newer Older
Nigel McNie's avatar
Nigel McNie committed
1
2
3
4
5
<?php
/**
 *
 * @package    mahara
 * @subpackage admin
6
 * @author     Catalyst IT Ltd
7
8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
Nigel McNie's avatar
Nigel McNie committed
9
10
11
 *
 */

12
13
define('INTERNAL', 1);
define('ADMIN', 1);
14
define('MENUITEM', 'configsite/siteoptions');
15
16
17
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'siteoptions');
Nigel McNie's avatar
Nigel McNie committed
18
19
20

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
21
require_once('searchlib.php');
22
require_once('antispam.php');
Nigel McNie's avatar
Nigel McNie committed
23
define('TITLE', get_string('siteoptions', 'admin'));
Nigel McNie's avatar
Nigel McNie committed
24
25

$langoptions = get_languages();
26
$themeoptions = get_all_themes();
27
28
unset($themeoptions['custom']); // Only available for institution configurable themes

Nigel McNie's avatar
Nigel McNie committed
29
30
31
$yesno = array(true  => get_string('yes'),
               false => get_string('no'));

32
33
$searchpluginoptions = get_search_plugins();

34
35
$countries = getoptions_country();

36
37
38
39
40
41
42
43
$notificationmethods = array();
foreach (array_keys(plugins_installed('notification')) as $n) {
    $notificationmethods[$n] = get_string('name', 'notification.' . $n);
}
if (!$notificationdefault = get_config('defaultnotificationmethod')) {
    $notificationdefault = isset($notificationmethods['email']) ? 'email' : 'internal';
}

44
$spamtraps = available_spam_traps();
45
$siteoptionform = array(
Penny Leach's avatar
Penny Leach committed
46
47
48
49
50
    'name'       => 'siteoptions',
    'jsform'     => true,
    'renderer'   => 'table',
    'plugintype' => 'core',
    'pluginname' => 'admin',
51
    'jssuccesscallback' => 'checkReload',
Penny Leach's avatar
Penny Leach committed
52
    'elements'   => array(
53
54
55
        'sitesettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
56
            'collapsed'    => true,
57
58
59
60
61
62
63
64
            'legend'       => get_string('sitesettingslegend', 'admin'),
            'elements'     => array(
                'sitename' => array(
                    'type'         => 'text',
                    'title'        => get_string('sitename', 'admin'),
                    'description'  => get_string('sitenamedescription', 'admin'),
                    'defaultvalue' => get_config('sitename'),
                    'help'         => true,
65
                    'disabled'     => in_array('sitename', $OVERRIDDEN),
66
67
68
69
70
71
72
73
74
                ),
                'lang' => array(
                    'type'         => 'select',
                    'title'        => get_string('language', 'admin'),
                    'description'  => get_string('sitelanguagedescription', 'admin'),
                    'defaultvalue' => get_config('lang'),
                    'collapseifoneoption' => true,
                    'options'      => $langoptions,
                    'help'         => true,
75
                    'disabled'     => in_array('lang', $OVERRIDDEN),
76
77
78
79
80
81
82
83
                ),
                'country' => array(
                    'type'         => 'select',
                    'title'        => get_string('country', 'admin'),
                    'description'  => get_string('sitecountrydescription', 'admin'),
                    'defaultvalue' => get_config('country'),
                    'options'      => array('' => get_string('nocountryselected')) + $countries,
                    'help'         => true,
84
                    'disabled'     => in_array('country', $OVERRIDDEN),
85
86
87
88
89
90
91
92
93
                ),
                'theme' => array(
                    'type'         => 'select',
                    'title'        => get_string('theme'),
                    'description'  => get_string('sitethemedescription', 'admin'),
                    'defaultvalue' => get_config('theme'),
                    'collapseifoneoption' => true,
                    'options'      => $themeoptions,
                    'help'         => true,
94
                    'disabled'     => in_array('theme', $OVERRIDDEN),
95
                ),
96
97
98
99
100
101
102
                'dropdownmenu' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('dropdownmenu', 'admin'),
                    'description'  => get_string('dropdownmenudescription', 'admin'),
                    'defaultvalue' => get_config('dropdownmenu'),
                    'disabled'     => in_array('dropdownmenu', $OVERRIDDEN),
                ),
103
104
105
106
107
                'homepageinfo' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('homepageinfo', 'admin'),
                    'description'  => get_string('homepageinfodescription', 'admin'),
                    'defaultvalue' => get_config('homepageinfo'),
108
                    'disabled'     => in_array('homepageinfo', $OVERRIDDEN),
109
110
111
112
113
114
115
                ),
                'registration_sendweeklyupdates' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('sendweeklyupdates', 'admin'),
                    'description'  => get_string('sendweeklyupdatesdescription', 'admin'),
                    'defaultvalue' => get_config('registration_sendweeklyupdates'),
                    'help'         => true,
116
                    'disabled'     => in_array('registration_sendweeklyupdates', $OVERRIDDEN),
117
                ),
118
119
            ),
        ),
120
121
122
        'usersettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
123
            'collapsed'    => true,
124
125
            'legend'       => get_string('usersettingslegend', 'admin'),
            'elements'     => array(
126
127
128
129
130
131
132
                'requireregistrationconfirm' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('requireregistrationconfirm', 'admin'),
                    'description'  => get_string('requireregistrationconfirmdescription', 'admin'),
                    'defaultvalue' => get_config('requireregistrationconfirm'),
                    'help'         => true,
                ),
133
134
135
136
137
                'userscanchooseviewthemes' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('userscanchooseviewthemes', 'admin'),
                    'description'  => get_string('userscanchooseviewthemesdescription', 'admin'),
                    'defaultvalue' => get_config('userscanchooseviewthemes'),
138
                    'disabled'     => in_array('userscanchooseviewthemes', $OVERRIDDEN),
139
140
141
142
143
144
145
                ),
                'remoteavatars' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('remoteavatars', 'admin'),
                    'description'  => get_string('remoteavatarsdescription', 'admin'),
                    'defaultvalue' => get_config('remoteavatars'),
                    'help'         => true,
146
                    'disabled'     => in_array('remoteavatars', $OVERRIDDEN),
147
148
149
150
151
152
                ),
                'userscanhiderealnames' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('userscanhiderealnames', 'admin'),
                    'description'  => get_string('userscanhiderealnamesdescription', 'admin'),
                    'defaultvalue' => get_config('userscanhiderealnames'),
153
                    'disabled'     => in_array('userscanhiderealnames', $OVERRIDDEN),
154
                ),
155
156
157
158
159
160
161
                'searchusernames' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('searchusernames', 'admin'),
                    'description'  => get_string('searchusernamesdescription', 'admin'),
                    'defaultvalue' => get_config('searchusernames'),
                    'disabled'     => in_array('searchusernames', $OVERRIDDEN),
                ),
162
163
164
165
166
167
168
                'searchuserspublic' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('searchuserspublic', 'admin'),
                    'description'  => get_string('searchuserspublicdescription', 'admin'),
                    'defaultvalue' => get_config('searchuserspublic'),
                    'disabled'     => in_array('searchuserspublic', $OVERRIDDEN),
                ),
169
170
171
172
173
                'anonymouscomments' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('anonymouscomments', 'admin'),
                    'description'  => get_string('anonymouscommentsdescription', 'admin'),
                    'defaultvalue' => get_config('anonymouscomments'),
174
                    'disabled'     => in_array('anonymouscomments', $OVERRIDDEN),
175
                ),
176
177
178
179
180
181
                'loggedinprofileviewaccess' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('loggedinprofileviewaccess', 'admin'),
                    'description'  => get_string('loggedinprofileviewaccessdescription', 'admin'),
                    'defaultvalue' => get_config('loggedinprofileviewaccess'),
                    'disabled'     => in_array('loggedinprofileviewaccess', $OVERRIDDEN),
182
                    'help'         => true,
183
                ),
184
185
186
187
188
189
190
                'staffreports' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('staffuserreports', 'admin'),
                    'description'  => get_string('staffuserreportsdescription', 'admin'),
                    'defaultvalue' => get_config('staffreports'),
                    'disabled'     => in_array('staffreports', $OVERRIDDEN),
                ),
Hugh Davenport's avatar
Hugh Davenport committed
191
192
193
194
195
196
197
                'staffstats' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('staffuserstats', 'admin'),
                    'description'  => get_string('staffuserstatsdescription', 'admin'),
                    'defaultvalue' => get_config('staffstats'),
                    'disabled'     => in_array('staffstats', $OVERRIDDEN),
                ),
198
199
200
201
202
203
204
                'userscandisabledevicedetection' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('userscandisabledevicedetection', 'admin'),
                    'description'  => get_string('userscandisabledevicedetectiondescription', 'admin'),
                    'defaultvalue' => get_config('userscandisabledevicedetection'),
                    'disabled'     => in_array('userscandisabledevicedetection', $OVERRIDDEN),
                ),
205
206
207
                'masqueradingreasonrequired' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('masqueradingreasonrequired', 'admin'),
208
                    'description'  => get_string('masqueradingreasonrequireddescription1', 'admin'),
209
210
211
212
213
214
                    'defaultvalue' => get_config('masqueradingreasonrequired'),
                    'disabled'     => in_array('masqueradingreasonrequired', $OVERRIDDEN),
                ),
                'masqueradingnotified' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('masqueradingnotified', 'admin'),
215
                    'description'  => get_string('masqueradingnotifieddescription1', 'admin'),
216
217
218
                    'defaultvalue' => get_config('masqueradingnotified'),
                    'disabled'     => in_array('masqueradingnotified', $OVERRIDDEN),
                ),
219
220
221
222
223
224
225
                'showprogressbar' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('showprogressbar', 'admin'),
                    'description'  => get_string('showprogressbardescription', 'admin'),
                    'defaultvalue' => get_config('showprogressbar'),
                    'disabled'     => in_array('showprogressbar', $OVERRIDDEN),
                ),
226
            ),
227
        ),
228
        'searchsettings' => array(
229
230
            'type'         => 'fieldset',
            'collapsible'  => true,
231
            'collapsed'    => true,
232
233
234
235
236
237
238
239
240
241
            'legend'       => get_string('searchsettingslegend', 'admin'),
            'elements'     => array(
                'searchplugin' => array(
                    'type'         => 'select',
                    'title'        => get_string('searchplugin', 'admin'),
                    'description'  => get_string('searchplugindescription', 'admin'),
                    'defaultvalue' => get_config('searchplugin'),
                    'collapseifoneoption' => true,
                    'options'      => $searchpluginoptions,
                    'help'         => true,
242
                    'disabled'     => in_array('searchplugin', $OVERRIDDEN),
243
                ),
244
            ),
245
        ),
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
        'groupsettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
            'collapsed'    => true,
            'legend'       => get_string('groupsettingslegend', 'admin'),
            'elements'     => array(
                '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'),
                    ),
262
                    'disabled'     => in_array('creategroups', $OVERRIDDEN),
263
264
265
266
267
268
269
270
271
272
273
                ),
                '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,
274
                    'disabled'     => in_array('createpublicgroups', $OVERRIDDEN),
275
276
                ),
                'allowgroupcategories' => array(
277
                    'type'         => 'checkbox',
278
279
280
                    'title'        => get_string('allowgroupcategories', 'admin'),
                    'description'  => get_string('allowgroupcategoriesdescription', 'admin'),
                    'defaultvalue' => get_config('allowgroupcategories'),
281
                    'disabled'     => in_array('allowgroupcategories', $OVERRIDDEN),
282
283
                ),
            ),
284
        ),
285
286
287
        'institutionsettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
288
            'collapsed'    => true,
289
290
291
292
293
294
295
296
            'legend'       => get_string('institutionsettingslegend', 'admin'),
            'elements'     => array(
                'usersallowedmultipleinstitutions' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('usersallowedmultipleinstitutions', 'admin'),
                    'description'  => get_string('usersallowedmultipleinstitutionsdescription', 'admin'),
                    'defaultvalue' => get_config('usersallowedmultipleinstitutions'),
                    'help'         => true,
297
                    'disabled'     => in_array('usersallowedmultipleinstitutions', $OVERRIDDEN),
298
299
300
301
                ),
                'institutionexpirynotification' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('institutionexpirynotification', 'admin'),
302
                    'description'  => get_string('institutionexpirynotificationdescriptioninfo', 'admin'),
303
304
                    'defaultvalue' => get_config('institutionexpirynotification'),
                    'help'         => true,
305
                    'disabled'     => in_array('institutionexpirynotification', $OVERRIDDEN),
306
307
308
309
310
311
312
                ),
                'institutionautosuspend' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('institutionautosuspend', 'admin'),
                    'description'  => get_string('institutionautosuspenddescription', 'admin'),
                    'defaultvalue' => get_config('institutionautosuspend'),
                    'help'         => true,
313
                    'disabled'     => in_array('institutionautosuspend', $OVERRIDDEN),
314
315
                ),
            ),
316
        ),
317
318
319
        'accountsettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
320
            'collapsed'    => true,
321
322
323
324
325
326
327
328
329
330
            'legend'       => get_string('accountsettingslegend', 'admin'),
            'elements'     => array(
                'sessionlifetime' => array(
                    'type'         => 'text',
                    'size'         => 4,
                    'title'        => get_string('sessionlifetime', 'admin'),
                    'description'  => get_string('sessionlifetimedescription', 'admin'),
                    'defaultvalue' => get_config('session_timeout') / 60,
                    'rules'        => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 10000000),
                    'help'         => true,
331
                    'disabled'     => in_array('session_timeout', $OVERRIDDEN),
332
                ),
333
334
335
336
337
338
339
340
                'defaultregistrationexpirylifetime' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultregistrationexpirylifetime', 'admin'),
                    'description'  => get_string('defaultregistrationexpirylifetimedescription', 'admin'),
                    'defaultvalue' => get_config('defaultregistrationexpirylifetime'),
                    'help'         => false,
                    'disabled'     => in_array('defaultregistrationexpirylifetime', $OVERRIDDEN),
                ),
341
342
343
344
345
346
                'defaultaccountlifetime' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountlifetime', 'admin'),
                    'description'  => get_string('defaultaccountlifetimedescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountlifetime'),
                    'help'         => true,
347
                    'disabled'     => in_array('defaultaccountlifetime', $OVERRIDDEN),
348
                ),
349
350
351
352
353
354
355
356
357
358
359
360
361
                'defaultaccountlifetimeupdate' => array(
                    'type'         => 'radio',
                    'title'        => get_string('defaultaccountlifetimeupdate', 'admin'),
                    'description'  => get_string('defaultaccountlifetimeupdatedescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountlifetimeupdate'),
                    'separator'    => '<br>',
                    'options'      => array(
                        'none'     => get_string('defaultaccountlifetimeupdatenone', 'admin'),
                        'some'     => get_string('defaultaccountlifetimeupdatesome', 'admin'),
                        'all'      => get_string('defaultaccountlifetimeupdateall', 'admin')
                    ),
                    'help'         => true,
                ),
362
363
364
365
366
367
                'defaultaccountinactiveexpire' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountinactiveexpire', 'admin'),
                    'description'  => get_string('defaultaccountinactiveexpiredescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountinactiveexpire'),
                    'help'         => true,
368
                    'disabled'     => in_array('defaultaccountinactiveexpire', $OVERRIDDEN),
369
370
371
372
373
374
375
                ),
                'defaultaccountinactivewarn' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountinactivewarn', 'admin'),
                    'description'  => get_string('defaultaccountinactivewarndescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountinactivewarn'),
                    'help'         => true,
376
                    'disabled'     => in_array('defaultaccountinactivewarn', $OVERRIDDEN),
377
378
                ),
            ),
379
        ),
380
381
382
        'securitysettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
383
            'collapsed'    => true,
384
385
386
387
388
389
390
391
            'legend'       => get_string('securitysettingslegend', 'admin'),
            'elements'     => array(
                'viruschecking' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('viruschecking', 'admin'),
                    'description'  => get_string('viruscheckingdescription', 'admin'),
                    'defaultvalue' => get_config('viruschecking'),
                    'help'         => true,
392
                    'disabled'     => in_array('viruschecking', $OVERRIDDEN),
393
                ),
394
395
396
397
398
399
400
                'pathtoclam' => array(
                    'type' => 'html',
                    'title' => get_string('pathtoclam', 'admin'),
                    'description' => get_string('pathtoclamdescription', 'admin'),
                    'value' => (get_config('pathtoclam') ? get_config('pathtoclam') : get_string('pathtoclamnotset', 'admin')),
                    'help' => true,
                ),
401
402
403
404
405
406
407
                'antispam' => array(
                    'type'         => 'select',
                    'title'        => get_string('antispam', 'admin'),
                    'description'  => get_string('antispamdescription', 'admin'),
                    'defaultvalue' => get_config('antispam'),
                    'options'      => $spamtraps,
                    'help'         => true,
408
                    'disabled'     => in_array('antispam', $OVERRIDDEN),
409
410
411
412
413
414
415
                ),
                'spamhaus' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('spamhaus', 'admin'),
                    'description'  => get_string('spamhausdescription', 'admin'),
                    'defaultvalue' => get_config('spamhaus'),
                    'help'         => true,
416
                    'disabled'     => in_array('spamhaus', $OVERRIDDEN),
417
418
419
420
421
422
423
                ),
                'surbl' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('surbl', 'admin'),
                    'description'  => get_string('surbldescription', 'admin'),
                    'defaultvalue' => get_config('surbl'),
                    'help'         => true,
424
                    'disabled'     => in_array('surbl', $OVERRIDDEN),
425
                ),
426
427
428
429
430
431
432
433
                'disableexternalresources' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('disableexternalresources', 'admin'),
                    'description'  => get_string('disableexternalresourcesdescription', 'admin'),
                    'defaultvalue' => get_config('disableexternalresources'),
                    'help'         => true,
                    'disabled'     => in_array('disableexternalresources', $OVERRIDDEN),
                ),
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
                'recaptchaonregisterform' => array(
                    'type' => 'checkbox',
                    'title' => get_string('recaptchaonregisterform', 'admin'),
                    'description' => get_string('recaptchaonregisterformdesc', 'admin'),
                    'defaultvalue' => get_config('recaptchaonregisterform', 'admin'),
                    'help' => true,
                    'disabled' => in_array('recaptchaonregisterform', $OVERRIDDEN)
                ),
                'recaptchapublickey' => array(
                    'type' => 'text',
                    'title' => get_string('recaptchapublickey', 'admin'),
                    'description' => get_string('recaptchapublickeydesc', 'admin'),
                    'defaultvalue' => get_config('recaptchapublickey'),
                    'disabled' => in_array('recaptchapublickey', $OVERRIDDEN)
                ),
                'recaptchaprivatekey' => array(
                    'type' => 'text',
                    'title' => get_string('recaptchaprivatekey', 'admin'),
                    'description' => get_string('recaptchaprivatekeydesc', 'admin'),
                    'defaultvalue' => get_config('recaptchaprivatekey'),
                    'disabled' => in_array('recaptchaprivatekey', $OVERRIDDEN)
                ),
456
            ),
457
        ),
458
459
460
461
462
463
464
465
466
467
468
469
        # TODO: this should become "Network Settings" at some point
        'proxysettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
            'collapsed'    => true,
            'legend'       => get_string('proxysettings', 'admin'),
            'elements'     => array(
                'proxyaddress' => array(
                   'type'          => 'text',
                   'title'         => get_string('proxyaddress', 'admin'),
                   'description'   => get_string('proxyaddressdescription', 'admin'),
                   'defaultvalue'  => get_config('proxyaddress'),
470
                   'disabled'      => in_array('proxyaddress', $OVERRIDDEN),
471
472
473
474
475
476
477
                ),
                'proxyauthmodel' => array(
                    'type'          => 'select',
                    'title'         => get_string('proxyauthmodel', 'admin'),
                    'description'   => get_string('proxyauthmodeldescription', 'admin'),
                    'defaultvalue'  => get_config('proxyauthmodel'),
                    'options'       => array(
478
479
                                        '' => get_string('none', 'admin'),
                                        'basic' => get_string('proxyauthmodelbasic', 'admin'),
480
                                    ),
481
                    'disabled'      => in_array('proxyauthmodel', $OVERRIDDEN),
482
483
484
485
486
487
                ),
                'proxyauthcredentials' => array(
                    'type'          => 'text',
                    'title'         => get_string('proxyauthcredentials', 'admin'),
                    'description'   => get_string('proxyauthcredentialsdescription', 'admin'),
                    'defaultvalue'  => get_config('proxyauthcredentials'),
488
                    'disabled'      => in_array('proxyauthcredentials', $OVERRIDDEN),
489
490
491
                ),
            ),
        ),
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
        'emailsettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
            'collapsed'    => true,
            'legend'       => get_string('emailsettings', 'admin'),
            'elements'     => array(
                'smtphosts' => array(
                   'type'           => 'text',
                   'title'          => get_string('emailsmtphosts', 'admin'),
                   'description'    => get_string('emailsmtphostsdescription', 'admin'),
                   'defaultvalue'   => get_config('smtphosts'),
                   'disabled'       => in_array('smtphosts', $OVERRIDDEN),
                   'help'           => true,
                ),
                'smtpport' => array(
                    'type'          => 'text',
                    'title'         => get_string('emailsmtpport', 'admin'),
                    'description'   => get_string('emailsmtpportdescription', 'admin'),
                    'defaultvalue'  => get_config('smtpport'),
                    'disabled'      => in_array('smtpport', $OVERRIDDEN),
                    'help'          => true,
                ),
                'smtpuser' => array(
                    'type'          => 'text',
                    'title'         => get_string('emailsmtpuser', 'admin'),
                    'description'   => get_string('emailsmtpuserdescription', 'admin'),
                    'defaultvalue'  => get_config('smtpuser'),
                    'disabled'      => in_array('smtpuser', $OVERRIDDEN),
                ),
                'smtppass' => array(
                    'type'          => 'text',
                    'title'         => get_string('emailsmtppass', 'admin'),
                    'defaultvalue'  => get_config('smtppass'),
                    'disabled'      => in_array('smtppass', $OVERRIDDEN),
                ),
                'smtpsecure' => array(
                    'type'          => 'select',
                    'title'         => get_string('emailsmtpsecure', 'admin'),
                    'description'   => get_string('emailsmtpsecuredescription', 'admin'),
                    'defaultvalue'  => get_config('smtpsecure'),
                    'disabled'      => in_array('smtpsecure', $OVERRIDDEN),
                    'options'       => array(
                        '' => get_string('none', 'admin'),
                        'ssl' => get_string('emailsmtpsecuressl', 'admin'),
                        'tls' => get_string('emailsmtpsecuretls', 'admin'),
                        ),
                    'help'          => true,
                ),
540
541
542
543
544
545
546
547
                'noreplyaddress' => array(
                    'type'          => 'text',
                    'title'         => get_string('emailnoreplyaddress', 'admin'),
                    'description'   => get_string('emailnoreplyaddressdescription', 'admin'),
                    'defaultvalue'  => get_config('noreplyaddress'),
                    'disabled'      => in_array('noreplyaddress', $OVERRIDDEN),
                    'help'          => true,
                ),
548
549
550
551
552
553
554
555
556
                'defaultnotificationmethod' => array(
                    'type'          => 'select',
                    'title'         => get_string('defaultnotificationmethod', 'admin'),
                    'description'   => get_string('defaultnotificationmethoddescription', 'admin'),
                    'defaultvalue'  => $notificationdefault,
                    'disabled'      => in_array('defaultnotificationmethod', $OVERRIDDEN),
                    'options'       => $notificationmethods,
                    'help'          => true,
                ),
557
558
            ),
        ),
559
560
561
        'generalsettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
562
            'collapsed'    => true,
563
564
565
            'legend'       => get_string('generalsettingslegend', 'admin'),
            'elements'     => array(
                'allowpublicviews' => array(
566
                    'type'         => 'checkbox',
567
568
569
570
                    'title'        => get_string('allowpublicviews', 'admin'),
                    'description'  => get_string('allowpublicviewsdescription', 'admin'),
                    'defaultvalue' => get_config('allowpublicviews'),
                    'help'         => true,
571
                    'disabled'     => in_array('allowpublicviews', $OVERRIDDEN),
572
573
                ),
                'allowpublicprofiles' => array(
574
                    'type'         => 'checkbox',
575
576
577
578
                    'title'        => get_string('allowpublicprofiles', 'admin'),
                    'description'  => get_string('allowpublicprofilesdescription', 'admin'),
                    'defaultvalue' => get_config('allowpublicprofiles'),
                    'help'         => true,
579
                    'disabled'     => in_array('allowpublicprofiles', $OVERRIDDEN) || get_config('allowpublicviews'),
580
                ),
581
582
583
584
585
586
587
588
                'generatesitemap' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('generatesitemap', 'admin'),
                    'description'  => get_string('generatesitemapdescription', 'admin'),
                    'defaultvalue' => get_config('generatesitemap'),
                    'help'         => true,
                    'disabled'     => in_array('generatesitemap', $OVERRIDDEN) || !get_config('allowpublicviews'),
                ),
589
590
591
                'showselfsearchsideblock' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('showselfsearchsideblock', 'admin'),
592
                    'description'  => get_string('showselfsearchsideblockdescription1', 'admin'),
593
594
595
                    'defaultvalue' => get_config('showselfsearchsideblock'),
                    'disabled'     => in_array('showselfsearchsideblock', $OVERRIDDEN),
                ),
596
597
598
                'showtagssideblock' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('showtagssideblock', 'admin'),
599
                    'description'  => get_string('showtagssideblockdescription1', 'admin'),
600
                    'defaultvalue' => get_config('showtagssideblock'),
601
                    'disabled'     => in_array('showtagssideblock', $OVERRIDDEN),
602
603
604
605
606
607
608
609
                ),
                '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),
610
                    'disabled'     => in_array('tagssideblockmaxtags', $OVERRIDDEN),
611
612
613
614
615
616
                ),
                'viewmicroheaders' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('smallviewheaders', 'admin'),
                    'description'  => get_string('smallviewheadersdescription', 'admin'),
                    'defaultvalue' => get_config('viewmicroheaders'),
617
618
619
620
621
                    'disabled'     => in_array('viewmicroheaders', $OVERRIDDEN),
                ),
                'showonlineuserssideblock' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('showonlineuserssideblock', 'admin'),
622
                    'description'  => get_string('showonlineuserssideblockdescriptionmessage', 'admin'),
623
624
                    'defaultvalue' => get_config('showonlineuserssideblock'),
                    'disabled'     => in_array('showonlineuserssideblock', $OVERRIDDEN),
625
                ),
626
627
628
629
630
631
632
633
634
                'onlineuserssideblockmaxusers' => array(
                    'type'         => 'text',
                    'size'         => 4,
                    'title'        => get_string('onlineuserssideblockmaxusers', 'admin'),
                    'description'  => get_string('onlineuserssideblockmaxusersdescription', 'admin'),
                    'defaultvalue' => get_config('onlineuserssideblockmaxusers'),
                    'rules'        => array('integer' => true, 'minvalue' => 0, 'maxvalue' => 100),
                    'disabled'     => in_array('onlineuserssideblockmaxusers', $OVERRIDDEN),
                ),
635
636
637
638
639
640
641
                'registerterms' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('registerterms', 'admin'),
                    'description'  => get_string('registertermsdescription', 'admin'),
                    'defaultvalue' => get_config('registerterms'),
                    'disabled'     => in_array('registerterms', $OVERRIDDEN),
                ),
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
                'licensemetadata' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('licensemetadata', 'admin'),
                    'description'  => get_string('licensemetadatadescription', 'admin'),
                    'defaultvalue' => get_config('licensemetadata'),
                    'help'         => true,
                    'disabled'     => in_array('licensemetadata', $OVERRIDDEN),
                ),
                'licenseallowcustom' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('licenseallowcustom', 'admin'),
                    'description'  => get_string('licenseallowcustomdescription', 'admin'),
                    'defaultvalue' => get_config('licenseallowcustom'),
                    'disabled'     => in_array('licenseallowcustom', $OVERRIDDEN),
                ),
657
658
659
660
661
662
663
                'allowmobileuploads' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('allowmobileuploads', 'admin'),
                    'description'  => get_string('allowmobileuploadsdescription', 'admin'),
                    'defaultvalue' => get_config('allowmobileuploads'),
                    'disabled'     => in_array('allowmobileuploads', $OVERRIDDEN),
                ),
664
665
666
667
668
669
670
671
672
673
674
                'wysiwyg' => array(
                    'type'         => 'select',
                    'title'        => get_string('wysiwyg', 'admin'),
                    'description'  => get_string('wysiwygdescription', 'admin'),
                    'defaultvalue' => get_config('wysiwyg'),
                    'options'      => array(
                                        '' => get_string('wysiwyguserdefined', 'admin'),
                                        'disable' => get_string('disable'),
                                        'enable' => get_string('enable'),
                                    ),
                    'help'         => true,
675
                    'disabled'     => in_array('wysiwyg', $OVERRIDDEN),
676
                ),
677
678
679
680
681
682
683
                'sitefilesaccess' => array(
                    'type'         => 'checkbox',
                    'title'        => get_string('sitefilesaccess', 'admin'),
                    'description'  => get_string('sitefilesaccessdescription', 'admin'),
                    'defaultvalue' => get_config('sitefilesaccess'),
                    'disabled'     => in_array('sitefilesaccess', $OVERRIDDEN),
                ),
684
685
686
687
688
689
690
                'watchlistnotification_delay' => array(
                    'type'         => 'text',
                    'title'        => get_string('watchlistdelaytitle', 'admin'),
                    'description'  => get_string('watchlistdelaydescription', 'admin'),
                    'defaultvalue' => get_config('watchlistnotification_delay'),
                    'disabled'     => in_array('watchlistnotification_delay', $OVERRIDDEN),
                ),
691
            ),
692
        ),
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
        'loggingsettings' => array(
            'type'         => 'fieldset',
            'collapsible'  => true,
            'collapsed'    => true,
            'legend'       => get_string('loggingsettingslegend', 'admin'),
            'elements'     => array(
                'eventloglevel' => array(
                    'type'         => 'select',
                    'title'        => get_string('eventloglevel', 'admin'),
                    'description'  => get_string('eventlogleveldescription', 'admin'),
                    'defaultvalue' => get_config('eventloglevel'),
                    'options'      => array(
                        'none' => get_string('eventloglevelnone', 'admin'),
                        'masq' => get_string('eventloglevelmasq', 'admin'),
                        'all' => get_string('eventloglevelall', 'admin'),
                    ),
                    'help'         => true,
                    'disabled'     => in_array('eventloglevel', $OVERRIDDEN),
                ),
                'eventlogexpiry' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('eventlogexpiry', 'admin'),
                    'description'  => get_string('eventlogexpirydescription', 'admin'),
                    'defaultvalue' => get_config('eventlogexpiry'),
                    'help'         => false,
                    'disabled'     => in_array('eventlogexpiry', $OVERRIDDEN),
                ),
            ),
        ),
Nigel McNie's avatar
Nigel McNie committed
722
    )
723
724
725
726
727
728
729
730
);

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

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

732
function siteoptions_fail(Pieform $form, $field) {
733
734
735
736
    $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
737
738
}

739
function siteoptions_submit(Pieform $form, $values) {
740
    $fields = array(
741
        'sitename','lang','theme', 'dropdownmenu',
742
        'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
743
        'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'generatesitemap',
744
        'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
745
        'showselfsearchsideblock', 'searchusernames', 'searchplugin', 'showtagssideblock',
746
        'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes',
747
748
        'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments',
        'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources',
749
        'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure',
750
        'noreplyaddress', 'defaultnotificationmethod', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers',
751
        'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
752
        'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay',
753
        'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic',
754
        'eventloglevel', 'eventlogexpiry', 'sitefilesaccess',
755
    );
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
    $count = 0;
    $where_sql = " WHERE admin = 0 AND id != 0";
    // if default account lifetime expiry has no end date
    if (empty($values['defaultaccountlifetime'])) {
        if ($values['defaultaccountlifetimeupdate'] == 'all') {
            // need to remove user expiry
            db_begin();
            $count = count_records_sql("SELECT COUNT(*) FROM {usr} $where_sql");
            execute_sql("UPDATE {usr} SET expiry = NULL $where_sql");
            db_commit();
        }
        else {
            // make the 'some' option the same as 'none' as it is meaningless to
            // update existing users without expiry date to having 'no end date'
            $values['defaultaccountlifetimeupdate'] = 'none';
        }
    }
    else {
        // fetch all the users that are not siteadmins
        $user_expiry = mktime(0, 0, 0, date('n'), date('j'), date('Y')) + (int)$values['defaultaccountlifetime'];
        if ($values['defaultaccountlifetimeupdate'] == 'some') {
            // and the user's expiry is not set
            $where_sql .= " AND expiry IS NULL";
            $count = count_records_sql("SELECT COUNT(*) FROM {usr} $where_sql");
            db_begin();
            execute_sql("UPDATE {usr} SET expiry = ? $where_sql", array(format_date($user_expiry)));
            db_commit();
        }
        else if ($values['defaultaccountlifetimeupdate'] == 'all') {
            // and the user's expiry is set
            db_begin();
            $count = count_records_sql("SELECT COUNT(*) FROM {usr} $where_sql");
            execute_sql("UPDATE {usr} SET expiry = ? $where_sql", array(format_date($user_expiry)));
            db_commit();
        }
    }
792
793
794
795
    // if public views are disabled, sitemap generation must also be disabled.
    if ($values['allowpublicviews'] == false) {
        $values['generatesitemap'] = false;
    }
796
797
798
799
    else {
        // Ensure allowpublicprofiles is set as well
        $values['allowpublicprofiles'] = 1;
    }
800

801
    $oldsearchplugin = get_config('searchplugin');
802
    $oldlanguage = get_config('lang');
803
    $oldtheme = get_config('theme');
Nigel McNie's avatar
Nigel McNie committed
804
805
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
806
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
807
808
        }
    }
809
810
811
812
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
813

814
815
816
    // If they've changed the search plugin, give the new plugin a chance to initialize.
    if ($oldsearchplugin != $values['searchplugin']) {
        // Call the old search plugin's sitewide cleanup method
Aaron Wells's avatar
Aaron Wells committed
817
        safe_require('search', $oldsearchplugin);
818
819
820
        call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide');
        // Call the new search plugin's sitewide initialize method
        safe_require('search', $values['searchplugin']);
821
822
823
        $initialize = call_static_method(generate_class_name('search', $values['searchplugin']), 'initialize_sitewide');
        if (!$initialize) {
            $form->reply(PIEFORM_ERR, array(
824
                'message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']),
825
826
827
                'goto'    => '/admin/site/options.php',
            ));
        }
828
829
    }

Nigel McNie's avatar
Nigel McNie committed
830
831
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
832
        siteoptions_fail($form, 'sessionlifetime');
Nigel McNie's avatar
Nigel McNie committed
833
834
    }
    // Submitted value is on/off; database entry should be 1/0
835
836
837
838
    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
839
    }
840

841
842
    if ($values['viruschecking'] == 'on') {
        $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
843
844
845
846
847
848
849
        if (!$pathtoclam ) {
            $form->reply(PIEFORM_ERR, array(
                'message' => get_string('clamnotset', 'mahara', $pathtoclam),
                'goto'    => '/admin/site/options.php',
            ));
        }
        else if (!file_exists($pathtoclam) && !is_executable($pathtoclam)) {
850
851
852
853
854
855
856
            $form->reply(PIEFORM_ERR, array(
                'message' => get_string('clamlost', 'mahara', $pathtoclam),
                'goto'    => '/admin/site/options.php',
            ));
        }
    }

857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
    if (get_config('recaptchaonregisterform')
            && !(
                    get_config('recaptchapublickey')
                    && get_config('recaptchaprivatekey')
            )
    ) {
        $form->reply(
            PIEFORM_ERR,
            array(
                'message' => get_string('recaptchakeysmissing', 'admin'),
                'goto' => '/admin/site/options.php',
            )
        );
    }

872
873
    $message = get_string('siteoptionsset', 'admin');
    if ($oldtheme != $values['theme']) {
874
        global $USER;
875
        $message .= '  ' . get_string('usersseenewthemeonlogin', 'admin');
876
        $USER->reset_institutions();
877
    }
878
879
880
    if ($count) {
        $message .= ' ' . get_string('numberusersupdated','admin', $count);
    }
881
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php'));
Nigel McNie's avatar
Nigel McNie committed
882
883
}

884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
$js = <<<EOF
jQuery(document).ready(function() {
    var j = jQuery.noConflict();
    var overrideuseraccountlifetime = j('#siteoptions input[name=defaultaccountlifetimeupdate]');
    var defaultaccountlifetime = j('#siteoptions_defaultaccountlifetime_units');
    function overrideuseraccountlife(v) {
        // if default account lifetime is set to 'noenddate' disable the override options
        if (v == 'noenddate') {
            var value = j('#siteoptions input[name=defaultaccountlifetimeupdate]:checked').val();
            j('#siteoptions input[name=defaultaccountlifetimeupdate][value=some]').attr('disabled',true);
            j('#siteoptions input[name=defaultaccountlifetimeupdate][value=some]').attr('checked', false);
            if (value != 'some') {
                j('#siteoptions input[name=defaultaccountlifetimeupdate][value=' + value + ']').attr('checked', true);
            }
        }
        else {
            // enable the radio buttons
            overrideuseraccountlifetime.attr('disabled',false);
            if (!j('#siteoptions input[name=defaultaccountlifetimeupdate]:checked').val()) {
                overrideuseraccountlifetime.each(function() {
                    if (typeof j(this).attr('checked') === 'undefined' || j(this).attr('checked') === false) {
                        // if no radio button already selected then choose the 'only for new users' option by default
                        if (j(this).val() == 'none') {
                            j(this).attr('checked',true);
                        }
                    }
                });
            }
        }
    }
    // when default account lifetime changes rerun the override account lifetime checks
    defaultaccountlifetime.change(function() {
        overrideuseraccountlife(defaultaccountlifetime.val());
    });
    // initial setup
    overrideuseraccountlife(defaultaccountlifetime.val());
});
EOF;

923
924
925
$thispage = json_encode(get_config('wwwroot') . 'admin/site/options.php');
$smarty = smarty(array('adminsiteoptions'));
$smarty->assign('siteoptionform', $siteoptionform);
926
$smarty->assign('PAGEHEADING', TITLE);
927
$smarty->assign('INLINEJAVASCRIPT', $js);
928
$smarty->display('admin/site/options.tpl');