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

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

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

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

29 30
$searchpluginoptions = get_search_plugins();

31 32
$countries = getoptions_country();

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

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

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

776 777 778 779 780 781 782 783 784 785
if (get_config('dropdownmenuenabled')) {
    $siteoptionform['elements']['sitesettings']['elements']['dropdownmenu'] = array(
        'type'         => 'switchbox',
        'title'        => get_string('dropdownmenu', 'admin'),
        'description'  => get_string('dropdownmenudescription2', 'admin'),
        'defaultvalue' => get_config('dropdownmenu'),
        'disabled'     => in_array('dropdownmenu', $OVERRIDDEN),
    );
}

786
$siteoptionform['elements']['submit'] = array(
787 788
    'type'  => 'button',
    'usebuttontag' => true,
789
    'class' => 'btn-primary',
790 791 792 793
    'value' => get_string('updatesiteoptions', 'admin')
);

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

795
function siteoptions_fail(Pieform $form, $field) {
796 797 798 799
    $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
800 801
}

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

893 894
    save_notification_settings($values, null, true);

895 896
    if ($oldsearchplugin != $values['searchplugin']) {
        // Call the old search plugin's sitewide cleanup method
Aaron Wells's avatar
Aaron Wells committed
897
        safe_require('search', $oldsearchplugin);
898 899 900
        call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide');
        // Call the new search plugin's sitewide initialize method
        safe_require('search', $values['searchplugin']);
901 902 903
        $initialize = call_static_method(generate_class_name('search', $values['searchplugin']), 'initialize_sitewide');
        if (!$initialize) {
            $form->reply(PIEFORM_ERR, array(
904
                'message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']),
905 906 907
                'goto'    => '/admin/site/options.php',
            ));
        }
908
    }
909 910 911 912 913 914 915 916 917
    // Call the new search plugin's can connect
    safe_require('search', $values['searchplugin']);
    $connect = call_static_method(generate_class_name('search', $values['searchplugin']), 'can_connect');
    if (!$connect) {
        $form->reply(PIEFORM_ERR, array(
            'message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']),
            'goto'    => '/admin/site/options.php',
        ));
    }
918

Nigel McNie's avatar
Nigel McNie committed
919 920
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
921
        siteoptions_fail($form, 'sessionlifetime');
Nigel McNie's avatar
Nigel McNie committed
922 923
    }
    // Submitted value is on/off; database entry should be 1/0
924 925 926 927
    foreach(array('viruschecking', 'usersallowedmultipleinstitutions') as $checkbox) {
        if (!set_config($checkbox, (int) ($values[$checkbox] == 'on'))) {
            siteoptions_fail($form, $checkbox);
        }
Nigel McNie's avatar
Nigel McNie committed
928
    }
929

930 931
    if ($values['viruschecking'] == 'on') {
        $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
932 933 934 935 936 937 938
        if (!$pathtoclam ) {
            $form->reply(PIEFORM_ERR, array(
                'message' => get_string('clamnotset', 'mahara', $pathtoclam),
                'goto'    => '/admin/site/options.php',
            ));
        }
        else if (!file_exists($pathtoclam) && !is_executable($pathtoclam)) {
939 940 941 942 943 944 945
            $form->reply(PIEFORM_ERR, array(
                'message' => get_string('clamlost', 'mahara', $pathtoclam),
                'goto'    => '/admin/site/options.php',
            ));
        }
    }

946 947 948 949 950 951 952 953 954
    if (get_config('recaptchaonregisterform')
            && !(
                    get_config('recaptchapublickey')
                    && get_config('recaptchaprivatekey')
            )
    ) {
        $form->reply(
            PIEFORM_ERR,
            array(
955
                'message' => get_string('recaptchakeysmissing1', 'admin'),
956 957 958 959
                'goto' => '/admin/site/options.php',
            )
        );
    }
960 961
    // Need to clear the cached menus in case site config changes effect them.
    clear_menu_cache();
962

963 964
    $message = get_string('siteoptionsset', 'admin');
    if ($oldtheme != $values['theme']) {
965
        global $USER;
966
        $message .= '  ' . get_string('usersseenewthemeonlogin', 'admin');
967
        $USER->reset_institutions();
968
    }
969 970 971
    if ($count) {
        $message .= ' ' . get_string('numberusersupdated','admin', $count);
    }
972
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php'));
Nigel McNie's avatar
Nigel McNie committed
973 974
}

975 976
$usermultipleinstitutions = (!empty(users_in_multiple_institutions()) ? "true" : "false");

977
$js = <<<EOF
978
var usersinmultipleinstitutions = {$usermultipleinstitutions};
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
jQuery(document).ready(function() {
    var j = jQuery.noConflict();
    var overrideuseraccountlifetime = j('#siteoptions input[name=defaultaccountlifetimeupdate]');
    var defaultaccountlifetime = j('#siteoptions_defaultaccountlifetime_units');
    function overrideuseraccountlife(v) {
        // if default account lifetime is set to 'noenddate' disable the override options
        if (v == 'noenddate') {
            var value = j('#siteoptions input[name=defaultaccountlifetimeupdate]:checked').val();
            j('#siteoptions input[name=defaultaccountlifetimeupdate][value=some]').attr('disabled',true);
            j('#siteoptions input[name=defaultaccountlifetimeupdate][value=some]').attr('checked', false);
            if (value != 'some') {
                j('#siteoptions input[name=defaultaccountlifetimeupdate][value=' + value + ']').attr('checked', true);
            }
        }
        else {
            // enable the radio buttons
            overrideuseraccountlifetime.attr('disabled',false);
            if (!j('#siteoptions input[name=defaultaccountlifetimeupdate]:checked').val()) {
                overrideuseraccountlifetime.each(function() {
                    if (typeof j(this).attr('checked') === 'undefined' || j(this).attr('checked') === false) {
                        // if no radio button already selected then choose the 'only for new users' option by default
                        if (j(this).val() == 'none') {
                            j(this).attr('checked',true);
                        }
                    }
                });
            }
        }
    }
    // when default account lifetime changes rerun the override account lifetime checks
    defaultaccountlifetime.change(function() {
        overrideuseraccountlife(defaultaccountlifetime.val());
    });
    // initial setup
    overrideuseraccountlife(defaultaccountlifetime.val());