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

$siteoptionform['elements']['submit'] = array(
767 768
    'type'  => 'button',
    'usebuttontag' => true,
769
    'class' => 'btn-primary',
770 771 772 773
    'value' => get_string('updatesiteoptions', 'admin')
);

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

775
function siteoptions_fail(Pieform $form, $field) {
776 777 778 779
    $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
780 781
}

782
function siteoptions_submit(Pieform $form, $values) {
783
    $fields = array(
784
        'sitename','lang','theme', 'dropdownmenu',
785
        'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
786
        'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap',
787
        'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
788
        'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock',
789
        'tagssideblockmaxtags', 'country', 'userscanchooseviewthemes',
790 791
        'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments',
        'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources',
792
        'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure',
793
        'noreplyaddress', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers',
794
        'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
795
        'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay',
796
        'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic',
797
        'eventloglevel', 'eventlogexpiry', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs',
798
    );
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
    $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();
        }
    }
835 836 837 838
    // if public views are disabled, sitemap generation must also be disabled.
    if ($values['allowpublicviews'] == false) {
        $values['generatesitemap'] = false;
    }
839 840 841 842
    else {
        // Ensure allowpublicprofiles is set as well
        $values['allowpublicprofiles'] = 1;
    }
843

844
    $oldsearchplugin = get_config('searchplugin');
845
    $oldlanguage = get_config('lang');
846
    $oldtheme = get_config('theme');
Nigel McNie's avatar
Nigel McNie committed
847 848
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
849
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
850 851
        }
    }
852 853 854 855
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
856

857 858
    save_notification_settings($values, null, true);

859 860
    if ($oldsearchplugin != $values['searchplugin']) {
        // Call the old search plugin's sitewide cleanup method
Aaron Wells's avatar
Aaron Wells committed
861
        safe_require('search', $oldsearchplugin);
862 863 864
        call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide');
        // Call the new search plugin's sitewide initialize method
        safe_require('search', $values['searchplugin']);
865 866 867
        $initialize = call_static_method(generate_class_name('search', $value