options.php 55.3 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

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
20
require_once('searchlib.php');
21
require_once('antispam.php');
22
require_once(get_config('libroot') . 'activity.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

29
30
$searchpluginoptions = get_search_plugins();

31
32
$countries = getoptions_country();

33
$notificationelements = get_notification_settings_elements(null, true);
34

35
36
validate_theme(get_config('theme'));

37
$spamtraps = available_spam_traps();
38
$siteoptionform = array(
Penny Leach's avatar
Penny Leach committed
39
40
    'name'       => 'siteoptions',
    'jsform'     => true,
Naomi Guyer's avatar
Naomi Guyer committed
41
    'renderer'   => 'div',
Penny Leach's avatar
Penny Leach committed
42
43
    'plugintype' => 'core',
    'pluginname' => 'admin',
44
    'jssuccesscallback' => 'checkReload',
Penny Leach's avatar
Penny Leach committed
45
    'elements'   => array(
46
        'sitesettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
47
            'iconclass' => 'globe',
48
49
            'type'         => 'fieldset',
            'collapsible'  => true,
50
            'collapsed'    => true,
51
52
53
54
55
56
57
58
            '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,
59
                    'disabled'     => in_array('sitename', $OVERRIDDEN),
60
61
62
63
64
65
66
67
68
                ),
                'lang' => array(
                    'type'         => 'select',
                    'title'        => get_string('language', 'admin'),
                    'description'  => get_string('sitelanguagedescription', 'admin'),
                    'defaultvalue' => get_config('lang'),
                    'collapseifoneoption' => true,
                    'options'      => $langoptions,
                    'help'         => true,
69
                    'disabled'     => in_array('lang', $OVERRIDDEN),
70
71
72
73
74
75
76
77
                ),
                '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,
78
                    'disabled'     => in_array('country', $OVERRIDDEN),
79
80
81
82
83
84
85
86
87
                ),
                'theme' => array(
                    'type'         => 'select',
                    'title'        => get_string('theme'),
                    'description'  => get_string('sitethemedescription', 'admin'),
                    'defaultvalue' => get_config('theme'),
                    'collapseifoneoption' => true,
                    'options'      => $themeoptions,
                    'help'         => true,
88
                    'disabled'     => in_array('theme', $OVERRIDDEN),
89
90
                ),
                'homepageinfo' => array(
91
                    'type'         => 'switchbox',
92
                    'title'        => get_string('homepageinfo1', 'admin'),
93
                    'description'  => get_string('homepageinfodescription3', 'admin'),
94
                    'defaultvalue' => get_config('homepageinfo'),
95
                    'disabled'     => in_array('homepageinfo', $OVERRIDDEN),
96
97
                ),
                'registration_sendweeklyupdates' => array(
98
                    'type'         => 'switchbox',
99
                    'title'        => get_string('sendweeklyupdates', 'admin'),
100
                    'description'  => get_string('sendweeklyupdatesdescription2', 'admin'),
101
102
                    'defaultvalue' => get_config('registration_sendweeklyupdates'),
                    'help'         => true,
103
                    'disabled'     => in_array('registration_sendweeklyupdates', $OVERRIDDEN),
104
                ),
105
106
            ),
        ),
107
        'usersettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
108
            'iconclass' => 'user',
109
110
            'type'         => 'fieldset',
            'collapsible'  => true,
111
            'collapsed'    => true,
112
113
114
            'legend'       => get_string('usersettingslegend', 'admin'),
            'elements'     => array(
                'userscanchooseviewthemes' => array(
115
                    'type'         => 'switchbox',
116
                    'title'        => get_string('userscanchooseviewthemes', 'admin'),
117
                    'description'  => get_string('userscanchooseviewthemesdescription1', 'admin'),
118
                    'defaultvalue' => get_config('userscanchooseviewthemes'),
119
                    'disabled'     => in_array('userscanchooseviewthemes', $OVERRIDDEN),
120
121
                ),
                'remoteavatars' => array(
122
                    'type'         => 'switchbox',
123
                    'title'        => get_string('remoteavatars', 'admin'),
124
                    'description'  => get_string('remoteavatarsdescription1', 'admin'),
125
126
                    'defaultvalue' => get_config('remoteavatars'),
                    'help'         => true,
127
                    'disabled'     => in_array('remoteavatars', $OVERRIDDEN),
128
129
                ),
                'userscanhiderealnames' => array(
130
                    'type'         => 'switchbox',
131
                    'title'        => get_string('userscanhiderealnames', 'admin'),
132
                    'description'  => get_string('userscanhiderealnamesdescription1', 'admin'),
133
                    'defaultvalue' => get_config('userscanhiderealnames'),
134
                    'disabled'     => in_array('userscanhiderealnames', $OVERRIDDEN),
135
                ),
136
                'nousernames' => array(
137
                    'type'         => 'switchbox',
138
                    'title'        => get_string('nousernames', 'admin'),
139
                    'description'  => get_string('nousernamesdescription1', 'admin'),
140
141
142
                    'defaultvalue' => get_config('nousernames'),
                    'disabled'     => in_array('nousernames', $OVERRIDDEN),
                ),
143
                'searchuserspublic' => array(
144
                    'type'         => 'switchbox',
145
146
147
148
149
                    'title'        => get_string('searchuserspublic', 'admin'),
                    'description'  => get_string('searchuserspublicdescription', 'admin'),
                    'defaultvalue' => get_config('searchuserspublic'),
                    'disabled'     => in_array('searchuserspublic', $OVERRIDDEN),
                ),
150
                'anonymouscomments' => array(
151
                    'type'         => 'switchbox',
152
                    'title'        => get_string('anonymouscomments', 'admin'),
153
                    'description'  => get_string('anonymouscommentsdescription1', 'admin'),
154
                    'defaultvalue' => get_config('anonymouscomments'),
155
                    'disabled'     => in_array('anonymouscomments', $OVERRIDDEN),
156
                ),
157
                'loggedinprofileviewaccess' => array(
158
                    'type'         => 'switchbox',
159
                    'title'        => get_string('loggedinprofileviewaccess1', 'admin'),
160
                    'description'  => get_string('loggedinprofileviewaccessdescription1', 'admin'),
161
162
                    'defaultvalue' => get_config('loggedinprofileviewaccess'),
                    'disabled'     => in_array('loggedinprofileviewaccess', $OVERRIDDEN),
163
                    'help'         => true,
164
                ),
165
                'staffreports' => array(
166
                    'type'         => 'switchbox',
167
                    'title'        => get_string('staffaccessreports', 'admin'),
168
                    'description'  => get_string('staffaccessreportsdescription1', 'admin'),
169
170
171
                    'defaultvalue' => get_config('staffreports'),
                    'disabled'     => in_array('staffreports', $OVERRIDDEN),
                ),
Hugh Davenport's avatar
Hugh Davenport committed
172
                'staffstats' => array(
173
                    'type'         => 'switchbox',
174
175
                    'title'        => get_string('institutionstaffallreports', 'admin'),
                    'description'  => get_string('institutionstaffallreportsdescription', 'admin'),
Hugh Davenport's avatar
Hugh Davenport committed
176
177
178
                    'defaultvalue' => get_config('staffstats'),
                    'disabled'     => in_array('staffstats', $OVERRIDDEN),
                ),
179
                'userscandisabledevicedetection' => array(
180
                    'type'         => 'switchbox',
181
                    'title'        => get_string('userscandisabledevicedetection', 'admin'),
182
                    'description'  => get_string('userscandisabledevicedetectiondescription1', 'admin'),
183
184
185
                    'defaultvalue' => get_config('userscandisabledevicedetection'),
                    'disabled'     => in_array('userscandisabledevicedetection', $OVERRIDDEN),
                ),
186
                'masqueradingreasonrequired' => array(
187
                    'type'         => 'switchbox',
188
                    'title'        => get_string('masqueradingreasonrequired', 'admin'),
189
                    'description'  => get_string('masqueradingreasonrequireddescription3', 'admin'),
190
191
192
193
                    'defaultvalue' => get_config('masqueradingreasonrequired'),
                    'disabled'     => in_array('masqueradingreasonrequired', $OVERRIDDEN),
                ),
                'masqueradingnotified' => array(
194
                    'type'         => 'switchbox',
195
                    'title'        => get_string('masqueradingnotified', 'admin'),
196
                    'description'  => get_string('masqueradingnotifielddescription', 'admin'),
197
198
199
                    'defaultvalue' => get_config('masqueradingnotified'),
                    'disabled'     => in_array('masqueradingnotified', $OVERRIDDEN),
                ),
200
                'showprogressbar' => array(
201
                    'type'         => 'switchbox',
202
                    'title'        => get_string('showprogressbar', 'admin'),
203
                    'description'  => get_string('showprogressbardescription1', 'admin'),
204
205
206
                    'defaultvalue' => get_config('showprogressbar'),
                    'disabled'     => in_array('showprogressbar', $OVERRIDDEN),
                ),
207
                'exporttoqueue' => array(
208
                    'type'         => 'switchbox',
209
                    'title'        => get_string('exporttoqueue', 'admin'),
210
                    'description'  => get_string('exporttoqueuedescription2', 'admin'),
211
212
213
                    'defaultvalue' => get_config('exporttoqueue'),
                    'disabled'     => in_array('exporttoqueue', $OVERRIDDEN),
                ),
214
                'defaultmultipleblogs' => array(
215
                    'type'         => 'switchbox',
216
                    'title'        => get_string('defaultmultipleblogs', 'admin'),
217
                    'description'  => get_string('defaultmultipleblogsdescription1', 'admin'),
218
219
220
                    'defaultvalue' => get_config('defaultmultipleblogs'),
                    'disabled'     => in_array('defaultmultipleblogs', $OVERRIDDEN),
                ),
221
            ),
222
        ),
223
        'searchsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
224
            'iconclass' => 'search',
225
226
            'type'         => 'fieldset',
            'collapsible'  => true,
227
            'collapsed'    => true,
228
229
230
231
232
233
234
235
236
237
            '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,
238
                    'disabled'     => in_array('searchplugin', $OVERRIDDEN),
239
                ),
240
            ),
241
        ),
242
        'groupsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
243
            'iconclass' => 'users',
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
            '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'),
                    ),
259
                    'disabled'     => in_array('creategroups', $OVERRIDDEN),
260
261
262
263
264
265
266
267
268
269
270
                ),
                '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,
271
                    'disabled'     => in_array('createpublicgroups', $OVERRIDDEN),
272
273
                ),
                'allowgroupcategories' => array(
274
                    'type'         => 'switchbox',
275
                    'title'        => get_string('allowgroupcategories', 'admin'),
276
                    'description'  => get_string('allowgroupcategoriesdescription1', 'admin'),
277
                    'defaultvalue' => get_config('allowgroupcategories'),
278
                    'disabled'     => in_array('allowgroupcategories', $OVERRIDDEN),
279
280
                ),
            ),
281
        ),
282
        'institutionsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
283
            'iconclass' => 'university',
284
285
            'type'         => 'fieldset',
            'collapsible'  => true,
286
            'collapsed'    => true,
287
288
            'legend'       => get_string('institutionsettingslegend', 'admin'),
            'elements'     => array(
289
                'institutionstrictprivacy' => array(
290
                    'type'         => 'switchbox',
291
292
293
                    'title'        => get_string('institutionstrictprivacy', 'admin'),
                    'description'  => get_string('institutionstrictprivacydescription', 'admin'),
                    'defaultvalue' => get_config('institutionstrictprivacy'),
294
                    'help'         => true,
295
                    'disabled'     => users_in_multiple_institutions() || get_config('usersallowedmultipleinstitutions'),
296
                ),
297
                'usersallowedmultipleinstitutions' => array(
298
                    'type'         => 'switchbox',
299
                    'title'        => get_string('usersallowedmultipleinstitutions', 'admin'),
300
                    'description'  => get_string('usersallowedmultipleinstitutionsdescription1', 'admin'),
301
302
                    'defaultvalue' => get_config('usersallowedmultipleinstitutions'),
                    'help'         => true,
303
                    'disabled'     => in_array('usersallowedmultipleinstitutions', $OVERRIDDEN),
304
                ),
305
306
307
308
309
310
311
                'requireregistrationconfirm' => array(
                  'type'         => 'switchbox',
                  'title'        => get_string('requireregistrationconfirm', 'admin'),
                  'description'  => get_string('requireregistrationconfirmdescription1', 'admin'),
                  'defaultvalue' => get_config('requireregistrationconfirm'),
                  'help'         => true,
                ),
312
313
314
                'institutionexpirynotification' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('institutionexpirynotification', 'admin'),
315
                    'description'  => get_string('institutionexpirynotificationdescriptioninfo', 'admin'),
316
317
                    'defaultvalue' => get_config('institutionexpirynotification'),
                    'help'         => true,
318
                    'disabled'     => in_array('institutionexpirynotification', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
319
                    'class'        => 'double'
320
321
                ),
                'institutionautosuspend' => array(
322
                    'type'         => 'switchbox',
323
                    'title'        => get_string('institutionautosuspend', 'admin'),
324
                    'description'  => get_string('institutionautosuspenddescription1', 'admin'),
325
326
                    'defaultvalue' => get_config('institutionautosuspend'),
                    'help'         => true,
327
                    'disabled'     => in_array('institutionautosuspend', $OVERRIDDEN),
328
                ),
329
330
331
332
333
334
335
                'defaultreviewselfdeletion' => array(
                    'type'         => 'switchbox',
                    'title'        => get_string('defaultreviewselfdeletion', 'admin'),
                    'description'  => get_string('defaultreviewselfdeletiondescription', 'admin'),
                    'defaultvalue' => get_config('defaultreviewselfdeletion'),
                    'disabled'     => in_array('defaultreviewselfdeletion', $OVERRIDDEN),
                ),
336
            ),
337
        ),
338
        'accountsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
339
            'iconclass'=>'clock-o',
340
341
            'type'         => 'fieldset',
            'collapsible'  => true,
342
            'collapsed'    => true,
343
344
345
346
347
348
349
350
            '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,
351
352
                    // Largest amount allowed is 30 days.
                    'rules'        => array('integer' => true, 'minvalue' => 1, 'maxvalue' => (30 * 24 * 60)),
353
                    'help'         => true,
354
                    'disabled'     => in_array('session_timeout', $OVERRIDDEN),
355
                ),
356
357
358
359
360
361
362
                '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),
Naomi Guyer's avatar
Naomi Guyer committed
363
                    'class'        => 'double'
364
                ),
365
366
367
368
369
370
                'defaultaccountlifetime' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountlifetime', 'admin'),
                    'description'  => get_string('defaultaccountlifetimedescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountlifetime'),
                    'help'         => true,
371
                    'disabled'     => in_array('defaultaccountlifetime', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
372
                    'class'        => 'double'
373
                ),
374
375
376
377
378
379
380
381
382
383
384
385
                'defaultaccountlifetimeupdate' => array(
                    'type'         => 'radio',
                    'title'        => get_string('defaultaccountlifetimeupdate', 'admin'),
                    'description'  => get_string('defaultaccountlifetimeupdatedescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountlifetimeupdate'),
                    'options'      => array(
                        'none'     => get_string('defaultaccountlifetimeupdatenone', 'admin'),
                        'some'     => get_string('defaultaccountlifetimeupdatesome', 'admin'),
                        'all'      => get_string('defaultaccountlifetimeupdateall', 'admin')
                    ),
                    'help'         => true,
                ),
386
387
388
389
390
391
                'defaultaccountinactiveexpire' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountinactiveexpire', 'admin'),
                    'description'  => get_string('defaultaccountinactiveexpiredescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountinactiveexpire'),
                    'help'         => true,
392
                    'disabled'     => in_array('defaultaccountinactiveexpire', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
393
                    'class'        => 'double'
394
395
396
397
398
399
400
                ),
                'defaultaccountinactivewarn' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountinactivewarn', 'admin'),
                    'description'  => get_string('defaultaccountinactivewarndescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountinactivewarn'),
                    'help'         => true,
401
                    'disabled'     => in_array('defaultaccountinactivewarn', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
402
                    'class'        => 'double'
403
404
                ),
            ),
405
        ),
406
        'securitysettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
407
            'iconclass'=>'lock',
408
409
            'type'         => 'fieldset',
            'collapsible'  => true,
410
            'collapsed'    => true,
411
412
            'legend'       => get_string('securitysettingslegend', 'admin'),
            'elements'     => array(
Gregor Anzelj's avatar
Gregor Anzelj committed
413
414
415
416
417
418
419
420
421
422
                'passwordpolicy' => array(
                    'type' => 'passwordpolicy',
                    'minlength' => 8,
                    'maxlength' => 20,
                    'title' => get_string('passwordpolicy', 'admin'),
                    'description' => get_string('passwordpolicydesc', 'admin'),
                    'defaultvalue' => get_config('passwordpolicy'),
                    'disabled' => in_array('passwordpolicy', $OVERRIDDEN),
                    'class' => 'double'
                ),
423
                'viruschecking' => array(
424
                    'type'         => 'switchbox',
425
                    'title'        => get_string('viruschecking', 'admin'),
426
                    'description'  => get_string('viruscheckingdescription1', 'admin'),
427
428
                    'defaultvalue' => get_config('viruschecking'),
                    'help'         => true,
429
                    'disabled'     => in_array('viruschecking', $OVERRIDDEN),
430
                ),
431
432
433
434
435
436
437
                '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,
                ),
438
439
440
441
442
443
444
                'antispam' => array(
                    'type'         => 'select',
                    'title'        => get_string('antispam', 'admin'),
                    'description'  => get_string('antispamdescription', 'admin'),
                    'defaultvalue' => get_config('antispam'),
                    'options'      => $spamtraps,
                    'help'         => true,
445
                    'disabled'     => in_array('antispam', $OVERRIDDEN),
446
447
                ),
                'spamhaus' => array(
448
449
450
                    'type'         => 'switchbox',
                    'title'        => get_string('spamhaus1', 'admin'),
                    'description'  => get_string('spamhausdescription1', 'admin'),
451
452
                    'defaultvalue' => get_config('spamhaus'),
                    'help'         => true,
453
                    'disabled'     => in_array('spamhaus', $OVERRIDDEN),
454
455
                ),
                'surbl' => array(
456
457
458
                    'type'         => 'switchbox',
                    'title'        => get_string('surbl1', 'admin'),
                    'description'  => get_string('surbldescription1', 'admin'),
459
460
                    'defaultvalue' => get_config('surbl'),
                    'help'         => true,
461
                    'disabled'     => in_array('surbl', $OVERRIDDEN),
462
                ),
463
                'disableexternalresources' => array(
464
                    'type'         => 'switchbox',
465
                    'title'        => get_string('disableexternalresources', 'admin'),
466
                    'description'  => get_string('disableexternalresourcesdescription1', 'admin'),
467
468
469
470
                    'defaultvalue' => get_config('disableexternalresources'),
                    'help'         => true,
                    'disabled'     => in_array('disableexternalresources', $OVERRIDDEN),
                ),
471
                'recaptchaonregisterform' => array(
472
                    'type' => 'switchbox',
473
474
                    'title' => get_string('recaptchaonregisterform1', 'admin'),
                    'description' => get_string('recaptchaonregisterformdesc2', 'admin'),
475
                    'defaultvalue' => get_config('recaptchaonregisterform'),
476
477
478
479
480
                    'help' => true,
                    'disabled' => in_array('recaptchaonregisterform', $OVERRIDDEN)
                ),
                'recaptchapublickey' => array(
                    'type' => 'text',
481
482
                    'title' => get_string('recaptchapublickey1', 'admin'),
                    'description' => get_string('recaptchapublickeydesc1', 'admin'),
483
484
485
486
487
                    'defaultvalue' => get_config('recaptchapublickey'),
                    'disabled' => in_array('recaptchapublickey', $OVERRIDDEN)
                ),
                'recaptchaprivatekey' => array(
                    'type' => 'text',
488
489
                    'title' => get_string('recaptchaprivatekey1', 'admin'),
                    'description' => get_string('recaptchaprivatekeydesc1', 'admin'),
490
491
492
                    'defaultvalue' => get_config('recaptchaprivatekey'),
                    'disabled' => in_array('recaptchaprivatekey', $OVERRIDDEN)
                ),
493
            ),
494
        ),
495
496
        # TODO: this should become "Network Settings" at some point
        'proxysettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
497
            'iconclass'=>'exchange',
498
499
500
501
502
503
504
505
506
507
            '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'),
508
                   'disabled'      => in_array('proxyaddress', $OVERRIDDEN),
509
510
511
512
513
514
515
                ),
                'proxyauthmodel' => array(
                    'type'          => 'select',
                    'title'         => get_string('proxyauthmodel', 'admin'),
                    'description'   => get_string('proxyauthmodeldescription', 'admin'),
                    'defaultvalue'  => get_config('proxyauthmodel'),
                    'options'       => array(
516
517
                                        '' => get_string('none', 'admin'),
                                        'basic' => get_string('proxyauthmodelbasic', 'admin'),
518
                                    ),
519
                    'disabled'      => in_array('proxyauthmodel', $OVERRIDDEN),
520
521
522
523
524
525
                ),
                'proxyauthcredentials' => array(
                    'type'          => 'text',
                    'title'         => get_string('proxyauthcredentials', 'admin'),
                    'description'   => get_string('proxyauthcredentialsdescription', 'admin'),
                    'defaultvalue'  => get_config('proxyauthcredentials'),
526
                    'disabled'      => in_array('proxyauthcredentials', $OVERRIDDEN),
527
528
529
                ),
            ),
        ),
530
        'emailsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
531
            'iconclass'=>'envelope',
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
            '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(
561
                    'type'          => 'password',
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
                    '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,
                ),
579
580
581
582
583
584
585
586
                '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,
                ),
587
588
            ),
        ),
589
        'notificationsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
590
            'iconclass'=>'bell',
591
592
593
594
            'type'         => 'fieldset',
            'collapsible'  => true,
            'collapsed'    => true,
            'legend'       => get_string('notificationsettings', 'admin'),
595
596
            'elements'     => array_merge(
                array(
597
598
599
600
601
602
603
604
                    'internalnotificationexpire' => array(
                        'type' => 'text',
                        'size'         => 4,
                        'title'         => get_string('internalnotificationexpire', 'admin'),
                        'description'   => get_string('internalnotificationexpiredescription', 'admin'),
                        'defaultvalue'  => get_config('internalnotificationexpire') ? get_config('internalnotificationexpire') : 182,
                        'help'          => true,
                    ),
605
606
607
608
609
610
611
                    'activitydescription' => array(
                        'type' => 'html',
                        'class' => 'description',
                        'value' => get_string('notificationsettingsdescription', 'admin'),
                    )
                ),
                $notificationelements),
612
        ),
613
        'generalsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
614
            'iconclass'=>'cog',
615
616
            'type'         => 'fieldset',
            'collapsible'  => true,
617
            'collapsed'    => true,
618
619
620
            'legend'       => get_string('generalsettingslegend', 'admin'),
            'elements'     => array(
                'allowpublicviews' => array(
621
                    'type'         => 'switchbox',
622
                    'title'        => get_string('allowpublicviews', 'admin'),
623
                    'description'  => get_string('allowpublicviewsdescription1', 'admin'),
624
625
                    'defaultvalue' => get_config('allowpublicviews'),
                    'help'         => true,
626
                    'disabled'     => in_array('allowpublicviews', $OVERRIDDEN),
627
628
                ),
                'allowpublicprofiles' => array(
629
                    'type'         => 'switchbox',
630
                    'title'        => get_string('allowpublicprofiles', 'admin'),
631
                    'description'  => get_string('allowpublicprofilesdescription1', 'admin'),
632
633
                    'defaultvalue' => get_config('allowpublicprofiles'),
                    'help'         => true,
634
                    'disabled'     => in_array('allowpublicprofiles', $OVERRIDDEN) || get_config('allowpublicviews'),
635
                ),
636
                'allowanonymouspages' => array(
637
                    'type'         => 'switchbox',
638
                    'title'        => get_string('allowanonymouspages', 'admin'),
639
                    'description'  => get_string('allowanonymouspagesdescription1', 'admin'),
640
641
642
643
                    'defaultvalue' => get_config('allowanonymouspages'),
                    'help'         => true,
                    'disabled'     => in_array('allowanonymouspages', $OVERRIDDEN),
                ),
644
                'generatesitemap' => array(
645
646
                    'type'         => 'switchbox',
                    'title'        => get_string('generatesitemap1', 'admin'),
647
648
649
650
651
                    'description'  => get_string('generatesitemapdescription', 'admin'),
                    'defaultvalue' => get_config('generatesitemap'),
                    'help'         => true,
                    'disabled'     => in_array('generatesitemap', $OVERRIDDEN) || !get_config('allowpublicviews'),
                ),
652
                'showselfsearchsideblock' => array(
653
654
                    'type'         => 'switchbox',
                    'title'        => get_string('showselfsearchsideblock1', 'admin'),
655
                    'description'  => get_string('showselfsearchsideblockdescription1', 'admin'),
656
657
658
                    'defaultvalue' => get_config('showselfsearchsideblock'),
                    'disabled'     => in_array('showselfsearchsideblock', $OVERRIDDEN),
                ),
659
                'showtagssideblock' => array(
660
661
662
                    'type'         => 'switchbox',
                    'title'        => get_string('showtagssideblock1', 'admin'),
                    'description'  => get_string('showtagssideblockdescription2', 'admin'),
663
                    'defaultvalue' => get_config('showtagssideblock'),
664
                    'disabled'     => in_array('showtagssideblock', $OVERRIDDEN),
665
666
667
668
669
670
671
672
                ),
                '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),
673
                    'disabled'     => in_array('tagssideblockmaxtags', $OVERRIDDEN),
674
                ),
675
                'showonlineuserssideblock' => array(
676
                    'type'         => 'switchbox',
677
                    'title'        => get_string('showonlineuserssideblock', 'admin'),
678
                    'description'  => get_string('showonlineuserssideblockdescriptionmessage1', 'admin'),
679
680
                    'defaultvalue' => get_config('showonlineuserssideblock'),
                    'disabled'     => in_array('showonlineuserssideblock', $OVERRIDDEN),
681
                ),
682
683
684
685
686
687
688
689
690
                '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),
                ),
691
                'registerterms' => array(
692
                    'type'         => 'switchbox',
693
694
695
696
697
                    'title'        => get_string('registerterms', 'admin'),
                    'description'  => get_string('registertermsdescription', 'admin'),
                    'defaultvalue' => get_config('registerterms'),
                    'disabled'     => in_array('registerterms', $OVERRIDDEN),
                ),
698
                'licensemetadata' => array(
699
                    'type'         => 'switchbox',
700
701
702
703
704
705
706
                    'title'        => get_string('licensemetadata', 'admin'),
                    'description'  => get_string('licensemetadatadescription', 'admin'),
                    'defaultvalue' => get_config('licensemetadata'),
                    'help'         => true,
                    'disabled'     => in_array('licensemetadata', $OVERRIDDEN),
                ),
                'licenseallowcustom' => array(
707
708
                    'type'         => 'switchbox',
                    'title'        => get_string('licenseallowcustom1', 'admin'),
709
710
711
712
                    'description'  => get_string('licenseallowcustomdescription', 'admin'),
                    'defaultvalue' => get_config('licenseallowcustom'),
                    'disabled'     => in_array('licenseallowcustom', $OVERRIDDEN),
                ),
713
714
715
716
717
718
719
720
721
722
723
                '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,
724
                    'disabled'     => in_array('wysiwyg', $OVERRIDDEN),
725
                ),
726
727
728
729
730
731
732
733
                'mathjax' => array(
                    'type'         => 'switchbox',
                    'title'        => get_string('mathjax', 'admin'),
                    'description'  => get_string('mathjaxdescription', 'admin'),
                    'defaultvalue' => get_config('mathjax'),
                    'help'         => true,
                    'disabled'     => in_array('mathjax', $OVERRIDDEN),
                ),
734
                'sitefilesaccess' => array(
735
                    'type'         => 'switchbox',
736
                    'title'        => get_string('sitefilesaccess', 'admin'),
737
                    'description'  => get_string('sitefilesaccessdescription1', 'admin'),
738
739
740
                    'defaultvalue' => get_config('sitefilesaccess'),
                    'disabled'     => in_array('sitefilesaccess', $OVERRIDDEN),
                ),
741
742
743
744
745
746
747
                '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),
                ),
748
            ),
749
        ),
750
        'loggingsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
751
            'iconclass'=>'exclamation-triangle',
752
            'class' => 'last',
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
            '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),
Naomi Guyer's avatar
Naomi Guyer committed
778
                    'class'        => 'double'
779
                ),
780
781
782
                'eventlogenhancedsearch' => array(
                    'type'         => 'switchbox',
                    'title'        => get_string('eventlogenhancedsearch', 'admin'),
783
                    'description'  => get_string('eventlogenhancedsearchdescription1', 'admin'),
784
785
786
787
                    'defaultvalue' => get_config('eventlogenhancedsearch'),
                    'help'         => true,
                    'disabled'     => (get_config('searchplugin') != 'elasticsearch' || in_array('eventlogenhancedsearch', $OVERRIDDEN)),
                ),
788
789
            ),
        ),
Nigel McNie's avatar
Nigel McNie committed
790
    )
791
792
);

793
794
795
796
797
798
799
800
801
802
if (get_config('dropdownmenuenabled')) {
    $siteoptionform['elements']['sitesettings']['elements']['dropdownmenu'] = array(
        'type'         => 'switchbox',
        'title'        => get_string('dropdownmenu', 'admin'),
        'description'  => get_string('dropdownmenudescription2', 'admin'),
        'defaultvalue' => get_config('dropdownmenu'),
        'disabled'     => in_array('dropdownmenu', $OVERRIDDEN),
    );
}

803
$siteoptionform['elements']['submit'] = array(
804
805
    'type'  => 'button',
    'usebuttontag' => true,
806
    'class' => 'btn-primary',
807
808
809
810
    'value' => get_string('updatesiteoptions', 'admin')
);

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

812
function siteoptions_fail(Pieform $form, $field) {
813
814
815
816
    $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
817
818
}

819
function siteoptions_submit(Pieform $form, $values) {
Gregor Anzelj's avatar
Gregor Anzelj committed
820
    global $USER;
821
    $fields = array(
822
        'sitename','lang','theme',
823
        'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
824
        'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap',
825
        'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
826
        'institutionstrictprivacy',
827
        'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock',
828
        'tagssideblockmaxtags', 'country', 'userscanchooseviewthemes', 'internalnotificationexpire',
Gregor Anzelj's avatar
Gregor Anzelj committed
829
        'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'passwordpolicy',
830
        'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources',
831
        'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure',
832
        'noreplyaddress', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers',
833
        'registerterms', 'licensemetadata', 'licenseallowcustom', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
834
        'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay',
835
        'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic',
836
        'eventloglevel', 'eventlogexpiry', 'eventlogenhancedsearch', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs',
837
        'defaultreviewselfdeletion'
838
    );
839
840
841
    if (get_config('dropdownmenuenabled')) {
      $fields = array_merge($fields, array('dropdownmenu'));
    }
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
    $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();
        }
    }
878
879
880
881
882
883
884
885
886
    // Make sure we have valid strict privacy and multi institutions settings
    if (users_in_multiple_institutions()) {
        $values['institutionstrictprivacy'] = false;
    }
    else {
        if (!empty($values['institutionstrictprivacy'])) {
            $values['usersallowedmultipleinstitutions'] = false;
        }
    }
887
888
889
890
    // if public views are disabled, sitemap generation must also be disabled.
    if ($values['allowpublicviews'] == false) {
        $values['generatesitemap'] = false;
    }
891
892
893
894
    else {
        // Ensure allowpublicprofiles is set as well
        $values['allowpublicprofiles'] = 1;
    }
895
896
897
898
    // Can only set advanced event log searching if search plugin is elasticsearch
    if (!empty($values['eventlogenhancedsearch']) && $values['searchplugin'] != 'elasticsearch') {
        $values['eventlogenhancedsearch'] = false;
    }
Gregor Anzelj's avatar
Gregor Anzelj committed
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
    // If password policy is changed, force reset password for all users with internal authentication.
    if ($values['passwordpolicy'] != get_password_policy()) {
        db_begin();
        execute_sql("
            UPDATE {usr} SET passwordchange = 1
            WHERE authinstance IN (
                SELECT ai.id
                FROM {auth_instance} ai
                WHERE ai.authname = 'internal'
            )
            AND id NOT IN (0, ?)
        ", array($USER->get('id'))); // Ignore the root and current admin user
        db_commit();
    }

914
    $oldsearchplugin = get_config('searchplugin');
915
    $oldlanguage = get_config('lang');
916
    $oldtheme = get_config('theme');
Nigel McNie's avatar
Nigel McNie committed
917
918
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
919
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
920
921
        }
    }
922
923
924
925
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
926

927
928
    save_notification_settings($values, null, true);

929
930
    if ($oldsearchplugin != $values['searchplugin']) {
        // Call the old search plugin's sitewide cleanup method
Aaron Wells's avatar
Aaron Wells committed
931
        safe_require('search', $oldsearchplugin);