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 20

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

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

30 31
$searchpluginoptions = get_search_plugins();

32 33
$countries = getoptions_country();

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

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

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

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

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

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

781
function siteoptions_submit(Pieform $form, $values) {
782
    $fields = array(
783
        'sitename','lang','theme', 'dropdownmenu',
784
        'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
785
        'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap',
786
        'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
787
        'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock',
788
        'tagssideblockmaxtags', 'country', 'userscanchooseviewthemes',
789 790
        'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments',
        'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources',
791
        'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure',
792
        'noreplyaddress', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers',
793
        'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
794
        'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay',
795
        'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic',
796
        'eventloglevel', 'eventlogexpiry', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs',
797
    );
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
    $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();
        }
    }
834 835 836 837
    // if public views are disabled, sitemap generation must also be disabled.
    if ($values['allowpublicviews'] == false) {
        $values['generatesitemap'] = false;
    }
838 839 840 841
    else {
        // Ensure allowpublicprofiles is set as well
        $values['allowpublicprofiles'] = 1;
    }
842

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

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

858 859
    if ($oldsearchplugin != $values['searchplugin']) {
        // Call the old search plugin's sitewide cleanup method
Aaron Wells's avatar
Aaron Wells committed
860
        safe_require('search', $oldsearchplugin);
861 862 863
        call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide');
        // Call the new search plugin's sitewide initialize method
        safe_require('search', $values['searchplugin']);
864 865 866
        $initialize = call_static_method(generate_class_name('search', $values['searchplugin']), 'initialize_sitewide');
        if (!$initialize) {
            $form->reply(PIEFORM_ERR, array(
867
                'message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']),
868 869 870
                'goto'    => '/admin/site/options.php',
            ));
        }
871
    }
872 873 874 875 876 877 878 879 880
    // Call the new search plugin's can connect