options.php 52.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 168
                    'title'        => get_string('staffaccessreports', 'admin'),
                    'description'  => get_string('staffaccessreportsdescription', '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
                'requireregistrationconfirm' => array(
290
                    'type'         => 'switchbox',
291
                    'title'        => get_string('requireregistrationconfirm', 'admin'),
292
                    'description'  => get_string('requireregistrationconfirmdescription1', 'admin'),
293
                    'defaultvalue' => get_config('requireregistrationconfirm'),
294
                    'help'         => true,
295
                ),
296
                'usersallowedmultipleinstitutions' => array(
297
                    'type'         => 'switchbox',
298
                    'title'        => get_string('usersallowedmultipleinstitutions', 'admin'),
299
                    'description'  => get_string('usersallowedmultipleinstitutionsdescription1', 'admin'),
300 301
                    'defaultvalue' => get_config('usersallowedmultipleinstitutions'),
                    'help'         => true,
302
                    'disabled'     => in_array('usersallowedmultipleinstitutions', $OVERRIDDEN),
303 304 305 306
                ),
                'institutionexpirynotification' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('institutionexpirynotification', 'admin'),
307
                    'description'  => get_string('institutionexpirynotificationdescriptioninfo', 'admin'),
308 309
                    'defaultvalue' => get_config('institutionexpirynotification'),
                    'help'         => true,
310
                    'disabled'     => in_array('institutionexpirynotification', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
311
                    'class'        => 'double'
312 313
                ),
                'institutionautosuspend' => array(
314
                    'type'         => 'switchbox',
315
                    'title'        => get_string('institutionautosuspend', 'admin'),
316
                    'description'  => get_string('institutionautosuspenddescription1', 'admin'),
317 318
                    'defaultvalue' => get_config('institutionautosuspend'),
                    'help'         => true,
319
                    'disabled'     => in_array('institutionautosuspend', $OVERRIDDEN),
320 321
                ),
            ),
322
        ),
323
        'accountsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
324
            'iconclass'=>'clock-o',
325 326
            'type'         => 'fieldset',
            'collapsible'  => true,
327
            'collapsed'    => true,
328 329 330 331 332 333 334 335
            '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,
336 337
                    // Largest amount allowed is 30 days.
                    'rules'        => array('integer' => true, 'minvalue' => 1, 'maxvalue' => (30 * 24 * 60)),
338
                    'help'         => true,
339
                    'disabled'     => in_array('session_timeout', $OVERRIDDEN),
340
                ),
341 342 343 344 345 346 347
                '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
348
                    'class'        => 'double'
349
                ),
350 351 352 353 354 355
                'defaultaccountlifetime' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountlifetime', 'admin'),
                    'description'  => get_string('defaultaccountlifetimedescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountlifetime'),
                    'help'         => true,
356
                    'disabled'     => in_array('defaultaccountlifetime', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
357
                    'class'        => 'double'
358
                ),
359 360 361 362 363 364 365 366 367 368 369 370
                '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,
                ),
371 372 373 374 375 376
                'defaultaccountinactiveexpire' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountinactiveexpire', 'admin'),
                    'description'  => get_string('defaultaccountinactiveexpiredescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountinactiveexpire'),
                    'help'         => true,
377
                    'disabled'     => in_array('defaultaccountinactiveexpire', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
378
                    'class'        => 'double'
379 380 381 382 383 384 385
                ),
                'defaultaccountinactivewarn' => array(
                    'type'         => 'expiry',
                    'title'        => get_string('defaultaccountinactivewarn', 'admin'),
                    'description'  => get_string('defaultaccountinactivewarndescription', 'admin'),
                    'defaultvalue' => get_config('defaultaccountinactivewarn'),
                    'help'         => true,
386
                    'disabled'     => in_array('defaultaccountinactivewarn', $OVERRIDDEN),
Naomi Guyer's avatar
Naomi Guyer committed
387
                    'class'        => 'double'
388 389
                ),
            ),
390
        ),
391
        'securitysettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
392
            'iconclass'=>'lock',
393 394
            'type'         => 'fieldset',
            'collapsible'  => true,
395
            'collapsed'    => true,
396 397 398
            'legend'       => get_string('securitysettingslegend', 'admin'),
            'elements'     => array(
                'viruschecking' => array(
399
                    'type'         => 'switchbox',
400
                    'title'        => get_string('viruschecking', 'admin'),
401
                    'description'  => get_string('viruscheckingdescription1', 'admin'),
402 403
                    'defaultvalue' => get_config('viruschecking'),
                    'help'         => true,
404
                    'disabled'     => in_array('viruschecking', $OVERRIDDEN),
405
                ),
406 407 408 409 410 411 412
                '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,
                ),
413 414 415 416 417 418 419
                'antispam' => array(
                    'type'         => 'select',
                    'title'        => get_string('antispam', 'admin'),
                    'description'  => get_string('antispamdescription', 'admin'),
                    'defaultvalue' => get_config('antispam'),
                    'options'      => $spamtraps,
                    'help'         => true,
420
                    'disabled'     => in_array('antispam', $OVERRIDDEN),
421 422
                ),
                'spamhaus' => array(
423 424 425
                    'type'         => 'switchbox',
                    'title'        => get_string('spamhaus1', 'admin'),
                    'description'  => get_string('spamhausdescription1', 'admin'),
426 427
                    'defaultvalue' => get_config('spamhaus'),
                    'help'         => true,
428
                    'disabled'     => in_array('spamhaus', $OVERRIDDEN),
429 430
                ),
                'surbl' => array(
431 432 433
                    'type'         => 'switchbox',
                    'title'        => get_string('surbl1', 'admin'),
                    'description'  => get_string('surbldescription1', 'admin'),
434 435
                    'defaultvalue' => get_config('surbl'),
                    'help'         => true,
436
                    'disabled'     => in_array('surbl', $OVERRIDDEN),
437
                ),
438
                'disableexternalresources' => array(
439
                    'type'         => 'switchbox',
440
                    'title'        => get_string('disableexternalresources', 'admin'),
441
                    'description'  => get_string('disableexternalresourcesdescription1', 'admin'),
442 443 444 445
                    'defaultvalue' => get_config('disableexternalresources'),
                    'help'         => true,
                    'disabled'     => in_array('disableexternalresources', $OVERRIDDEN),
                ),
446
                'recaptchaonregisterform' => array(
447
                    'type' => 'switchbox',
448
                    'title' => get_string('recaptchaonregisterform', 'admin'),
449
                    'description' => get_string('recaptchaonregisterformdesc1', 'admin'),
450
                    'defaultvalue' => get_config('recaptchaonregisterform'),
451 452 453 454 455
                    'help' => true,
                    'disabled' => in_array('recaptchaonregisterform', $OVERRIDDEN)
                ),
                'recaptchapublickey' => array(
                    'type' => 'text',
456 457
                    'title' => get_string('recaptchapublickey1', 'admin'),
                    'description' => get_string('recaptchapublickeydesc1', 'admin'),
458 459 460 461 462
                    'defaultvalue' => get_config('recaptchapublickey'),
                    'disabled' => in_array('recaptchapublickey', $OVERRIDDEN)
                ),
                'recaptchaprivatekey' => array(
                    'type' => 'text',
463 464
                    'title' => get_string('recaptchaprivatekey1', 'admin'),
                    'description' => get_string('recaptchaprivatekeydesc1', 'admin'),
465 466 467
                    'defaultvalue' => get_config('recaptchaprivatekey'),
                    'disabled' => in_array('recaptchaprivatekey', $OVERRIDDEN)
                ),
468
            ),
469
        ),
470 471
        # TODO: this should become "Network Settings" at some point
        'proxysettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
472
            'iconclass'=>'exchange',
473 474 475 476 477 478 479 480 481 482
            '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'),
483
                   'disabled'      => in_array('proxyaddress', $OVERRIDDEN),
484 485 486 487 488 489 490
                ),
                'proxyauthmodel' => array(
                    'type'          => 'select',
                    'title'         => get_string('proxyauthmodel', 'admin'),
                    'description'   => get_string('proxyauthmodeldescription', 'admin'),
                    'defaultvalue'  => get_config('proxyauthmodel'),
                    'options'       => array(
491 492
                                        '' => get_string('none', 'admin'),
                                        'basic' => get_string('proxyauthmodelbasic', 'admin'),
493
                                    ),
494
                    'disabled'      => in_array('proxyauthmodel', $OVERRIDDEN),
495 496 497 498 499 500
                ),
                'proxyauthcredentials' => array(
                    'type'          => 'text',
                    'title'         => get_string('proxyauthcredentials', 'admin'),
                    'description'   => get_string('proxyauthcredentialsdescription', 'admin'),
                    'defaultvalue'  => get_config('proxyauthcredentials'),
501
                    'disabled'      => in_array('proxyauthcredentials', $OVERRIDDEN),
502 503 504
                ),
            ),
        ),
505
        'emailsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
506
            'iconclass'=>'envelope',
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
            '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(
536
                    'type'          => 'password',
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
                    '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,
                ),
554 555 556 557 558 559 560 561
                '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,
                ),
562 563
            ),
        ),
564
        'notificationsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
565
            'iconclass'=>'bell',
566 567 568 569
            'type'         => 'fieldset',
            'collapsible'  => true,
            'collapsed'    => true,
            'legend'       => get_string('notificationsettings', 'admin'),
570 571 572 573 574 575 576 577 578
            'elements'     => array_merge(
                array(
                    'activitydescription' => array(
                        'type' => 'html',
                        'class' => 'description',
                        'value' => get_string('notificationsettingsdescription', 'admin'),
                    )
                ),
                $notificationelements),
579
        ),
580
        'generalsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
581
            'iconclass'=>'cog',
582 583
            'type'         => 'fieldset',
            'collapsible'  => true,
584
            'collapsed'    => true,
585 586 587
            'legend'       => get_string('generalsettingslegend', 'admin'),
            'elements'     => array(
                'allowpublicviews' => array(
588
                    'type'         => 'switchbox',
589
                    'title'        => get_string('allowpublicviews', 'admin'),
590
                    'description'  => get_string('allowpublicviewsdescription1', 'admin'),
591 592
                    'defaultvalue' => get_config('allowpublicviews'),
                    'help'         => true,
593
                    'disabled'     => in_array('allowpublicviews', $OVERRIDDEN),
594 595
                ),
                'allowpublicprofiles' => array(
596
                    'type'         => 'switchbox',
597
                    'title'        => get_string('allowpublicprofiles', 'admin'),
598
                    'description'  => get_string('allowpublicprofilesdescription1', 'admin'),
599 600
                    'defaultvalue' => get_config('allowpublicprofiles'),
                    'help'         => true,
601
                    'disabled'     => in_array('allowpublicprofiles', $OVERRIDDEN) || get_config('allowpublicviews'),
602
                ),
603
                'allowanonymouspages' => array(
604
                    'type'         => 'switchbox',
605
                    'title'        => get_string('allowanonymouspages', 'admin'),
606
                    'description'  => get_string('allowanonymouspagesdescription1', 'admin'),
607 608 609 610
                    'defaultvalue' => get_config('allowanonymouspages'),
                    'help'         => true,
                    'disabled'     => in_array('allowanonymouspages', $OVERRIDDEN),
                ),
611
                'generatesitemap' => array(
612 613
                    'type'         => 'switchbox',
                    'title'        => get_string('generatesitemap1', 'admin'),
614 615 616 617 618
                    'description'  => get_string('generatesitemapdescription', 'admin'),
                    'defaultvalue' => get_config('generatesitemap'),
                    'help'         => true,
                    'disabled'     => in_array('generatesitemap', $OVERRIDDEN) || !get_config('allowpublicviews'),
                ),
619
                'showselfsearchsideblock' => array(
620 621
                    'type'         => 'switchbox',
                    'title'        => get_string('showselfsearchsideblock1', 'admin'),
622
                    'description'  => get_string('showselfsearchsideblockdescription1', 'admin'),
623 624 625
                    'defaultvalue' => get_config('showselfsearchsideblock'),
                    'disabled'     => in_array('showselfsearchsideblock', $OVERRIDDEN),
                ),
626
                'showtagssideblock' => array(
627 628 629
                    'type'         => 'switchbox',
                    'title'        => get_string('showtagssideblock1', 'admin'),
                    'description'  => get_string('showtagssideblockdescription2', 'admin'),
630
                    'defaultvalue' => get_config('showtagssideblock'),
631
                    'disabled'     => in_array('showtagssideblock', $OVERRIDDEN),
632 633 634 635 636 637 638 639
                ),
                '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),
640
                    'disabled'     => in_array('tagssideblockmaxtags', $OVERRIDDEN),
641
                ),
642
                'showonlineuserssideblock' => array(
643
                    'type'         => 'switchbox',
644
                    'title'        => get_string('showonlineuserssideblock', 'admin'),
645
                    'description'  => get_string('showonlineuserssideblockdescriptionmessage1', 'admin'),
646 647
                    'defaultvalue' => get_config('showonlineuserssideblock'),
                    'disabled'     => in_array('showonlineuserssideblock', $OVERRIDDEN),
648
                ),
649 650 651 652 653 654 655 656 657
                '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),
                ),
658
                'registerterms' => array(
659
                    'type'         => 'switchbox',
660 661 662 663 664
                    'title'        => get_string('registerterms', 'admin'),
                    'description'  => get_string('registertermsdescription', 'admin'),
                    'defaultvalue' => get_config('registerterms'),
                    'disabled'     => in_array('registerterms', $OVERRIDDEN),
                ),
665
                'licensemetadata' => array(
666
                    'type'         => 'switchbox',
667 668 669 670 671 672 673
                    'title'        => get_string('licensemetadata', 'admin'),
                    'description'  => get_string('licensemetadatadescription', 'admin'),
                    'defaultvalue' => get_config('licensemetadata'),
                    'help'         => true,
                    'disabled'     => in_array('licensemetadata', $OVERRIDDEN),
                ),
                'licenseallowcustom' => array(
674 675
                    'type'         => 'switchbox',
                    'title'        => get_string('licenseallowcustom1', 'admin'),
676 677 678 679
                    'description'  => get_string('licenseallowcustomdescription', 'admin'),
                    'defaultvalue' => get_config('licenseallowcustom'),
                    'disabled'     => in_array('licenseallowcustom', $OVERRIDDEN),
                ),
680
                'allowmobileuploads' => array(
681 682 683
                    'type'         => 'switchbox',
                    'title'        => get_string('allowmobileuploads1', 'admin'),
                    'description'  => get_string('allowmobileuploadsdescription1', 'admin'),
684 685 686
                    'defaultvalue' => get_config('allowmobileuploads'),
                    'disabled'     => in_array('allowmobileuploads', $OVERRIDDEN),
                ),
687 688 689 690 691 692 693 694 695 696 697
                '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,
698
                    'disabled'     => in_array('wysiwyg', $OVERRIDDEN),
699
                ),
700 701 702 703 704 705 706 707
                '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),
                ),
708
                'sitefilesaccess' => array(
709
                    'type'         => 'switchbox',
710
                    'title'        => get_string('sitefilesaccess', 'admin'),
711
                    'description'  => get_string('sitefilesaccessdescription1', 'admin'),
712 713 714
                    'defaultvalue' => get_config('sitefilesaccess'),
                    'disabled'     => in_array('sitefilesaccess', $OVERRIDDEN),
                ),
715 716 717 718 719 720 721
                '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),
                ),
722
            ),
723
        ),
724
        'loggingsettings' => array(
Naomi Guyer's avatar
Naomi Guyer committed
725
            'iconclass'=>'exclamation-triangle',
726
            'class' => 'last',
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
            '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
752
                    'class'        => 'double'
753
                ),
754 755 756 757 758 759 760 761
                'eventlogenhancedsearch' => array(
                    'type'         => 'switchbox',
                    'title'        => get_string('eventlogenhancedsearch', 'admin'),
                    'description'  => get_string('eventlogenhancedsearchdescription', 'admin'),
                    'defaultvalue' => get_config('eventlogenhancedsearch'),
                    'help'         => true,
                    'disabled'     => (get_config('searchplugin') != 'elasticsearch' || in_array('eventlogenhancedsearch', $OVERRIDDEN)),
                ),
762 763
            ),
        ),
Nigel McNie's avatar
Nigel McNie committed
764
    )
765 766
);

767 768 769 770 771 772 773 774 775 776
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),
    );
}

777
$siteoptionform['elements']['submit'] = array(
778 779
    'type'  => 'button',
    'usebuttontag' => true,
780
    'class' => 'btn-primary',
781 782 783 784
    'value' => get_string('updatesiteoptions', 'admin')
);

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

786
function siteoptions_fail(Pieform $form, $field) {
787 788 789 790
    $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
791 792
}

793
function siteoptions_submit(Pieform $form, $values) {
794
    $fields = array(
795
        'sitename','lang','theme',
796
        'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
797
        'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap',
798
        'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
799
        'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock',
800
        'tagssideblockmaxtags', 'country', 'userscanchooseviewthemes',
801 802
        'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments',
        'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources',
803
        'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure',
804
        'noreplyaddress', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers',
805
        'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
806
        'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay',
807
        'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic',
808
        'eventloglevel', 'eventlogexpiry', 'eventlogenhancedsearch', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs',
809
    );
810 811 812
    if (get_config('dropdownmenuenabled')) {
      $fields = array_merge($fields, array('dropdownmenu'));
    }
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
    $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();
        }
    }
849 850 851 852
    // if public views are disabled, sitemap generation must also be disabled.
    if ($values['allowpublicviews'] == false) {
        $values['generatesitemap'] = false;
    }
853 854 855 856
    else {
        // Ensure allowpublicprofiles is set as well
        $values['allowpublicprofiles'] = 1;
    }
857 858 859 860
    // Can only set advanced event log searching if search plugin is elasticsearch
    if (!empty($values['eventlogenhancedsearch']) && $values['searchplugin'] != 'elasticsearch') {
        $values['eventlogenhancedsearch'] = false;
    }
861
    $oldsearchplugin = get_config('searchplugin');
862
    $oldlanguage = get_config('lang');
863
    $oldtheme = get_config('theme');
Nigel McNie's avatar
Nigel McNie committed
864 865
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
866
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
867 868
        }
    }
869 870 871 872
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
873

874 875
    save_notification_settings($values, null, true);

876 877
    if ($oldsearchplugin != $values['searchplugin']) {
        // Call the old search plugin's sitewide cleanup method
Aaron Wells's avatar
Aaron Wells committed
878
        safe_require('search', $oldsearchplugin);
879 880