options.php 11.4 KB
Newer Older
Nigel McNie's avatar
Nigel McNie committed
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
Nigel McNie's avatar
Nigel McNie committed
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Nigel McNie's avatar
Nigel McNie committed
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
Nigel McNie's avatar
Nigel McNie committed
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Nigel McNie's avatar
Nigel McNie committed
18
19
20
 *
 * @package    mahara
 * @subpackage admin
21
 * @author     Catalyst IT Ltd
Nigel McNie's avatar
Nigel McNie committed
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
Nigel McNie's avatar
Nigel McNie committed
24
25
26
 *
 */

27
28
define('INTERNAL', 1);
define('ADMIN', 1);
29
define('MENUITEM', 'configsite/siteoptions');
Nigel McNie's avatar
Nigel McNie committed
30
31
32

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
33
require_once('searchlib.php');
Nigel McNie's avatar
Nigel McNie committed
34
define('TITLE', get_string('siteoptions', 'admin'));
Nigel McNie's avatar
Nigel McNie committed
35
36
37
38
39
40

$langoptions = get_languages();
$themeoptions = get_themes();
$yesno = array(true  => get_string('yes'),
               false => get_string('no'));

41
$allowedfilters = array('YouTube', 'GoogleVideo', 'TeacherTube', 'SciVee', 'Skype', 'Twitter');  //@todo read from the htmlpurifiercustom directory
42
43
44
45
46
47
48
49
$enabledfilters = get_config('filters');
if ($enabledfilters) {
    $enabledfilters = unserialize($enabledfilters);
}
else {
    $enabledfilters = array();
}

50
51
$searchpluginoptions = get_search_plugins();

52
$siteoptionform = array(
Penny Leach's avatar
Penny Leach committed
53
54
55
56
57
    'name'       => 'siteoptions',
    'jsform'     => true,
    'renderer'   => 'table',
    'plugintype' => 'core',
    'pluginname' => 'admin',
58
    'jssuccesscallback' => 'checkReload',
Penny Leach's avatar
Penny Leach committed
59
    'elements'   => array(
Nigel McNie's avatar
Nigel McNie committed
60
61
        'sitename' => array(
            'type'         => 'text',
62
63
            'title'        => get_string('sitename', 'admin'),
            'description'  => get_string('sitenamedescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
64
            'defaultvalue' => get_config('sitename'),
Penny Leach's avatar
Penny Leach committed
65
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
66
        ),
67
        'lang' => array(
Nigel McNie's avatar
Nigel McNie committed
68
            'type'         => 'select',
69
70
            'title'        => get_string('language', 'admin'),
            'description'  => get_string('sitelanguagedescription', 'admin'),
71
            'defaultvalue' => get_config('lang'),
Nigel McNie's avatar
Nigel McNie committed
72
73
            'collapseifoneoption' => true,
            'options'      => $langoptions,
Penny Leach's avatar
Penny Leach committed
74
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
75
76
77
        ),
        'theme' => array(
            'type'         => 'select',
78
79
            'title'        => get_string('theme', 'admin'),
            'description'  => get_string('sitethemedescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
80
81
82
            'defaultvalue' => get_config('theme'),
            'collapseifoneoption' => true,
            'options'      => $themeoptions,
Penny Leach's avatar
Penny Leach committed
83
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
84
        ),
85
86
        'searchplugin' => array(
            'type'         => 'select',
87
88
            'title'        => get_string('searchplugin', 'admin'),
            'description'  => get_string('searchplugindescription', 'admin'),
89
90
91
            'defaultvalue' => get_config('searchplugin'),
            'collapseifoneoption' => true,
            'options'      => $searchpluginoptions,
Penny Leach's avatar
Penny Leach committed
92
            'help'         => true,
93
        ),
Nigel McNie's avatar
Nigel McNie committed
94
95
        'viruschecking' => array(
            'type'         => 'checkbox',
96
97
            'title'        => get_string('viruschecking', 'admin'),
            'description'  => get_string('viruscheckingdescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
98
            'defaultvalue' => get_config('viruschecking'),
Penny Leach's avatar
Penny Leach committed
99
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
100
101
102
        ),
        'pathtoclam' => array(
            'type'         => 'text',
103
104
            'title'        => get_string('pathtoclam', 'admin'),
            'description'  => get_string('pathtoclamdescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
105
            'defaultvalue' => get_config('pathtoclam'),
Penny Leach's avatar
Penny Leach committed
106
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
107
108
109
110
        ),
        'sessionlifetime' => array(
            'type'         => 'text',
            'size'         => 4,
111
112
            'title'        => get_string('sessionlifetime', 'admin'),
            'description'  => get_string('sessionlifetimedescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
113
            'defaultvalue' => get_config('session_timeout') / 60,
Penny Leach's avatar
Penny Leach committed
114
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
115
116
117
        ),
        'allowpublicviews' => array(
            'type'         => 'select',
118
119
            'title'        => get_string('allowpublicviews', 'admin'),
            'description'  => get_string('allowpublicviewsdescription', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
120
121
            'defaultvalue' => get_config('allowpublicviews'),
            'options'      => $yesno,
Penny Leach's avatar
Penny Leach committed
122
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
123
        ),
124
125
126
127
128
129
130
131
        'allowpublicprofiles' => array(
            'type'         => 'select',
            'title'        => get_string('allowpublicprofiles', 'admin'),
            'description'  => get_string('allowpublicprofilesdescription', 'admin'),
            'defaultvalue' => get_config('allowpublicprofiles'),
            'options'      => $yesno,
            'help'         => true,
        ),
132
133
134
135
136
137
138
139
140
141
142
        '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,
        ),
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
        'defaultaccountlifetime' => array(
            'type'         => 'expiry',
            'title'        => get_string('defaultaccountlifetime', 'admin'),
            'description'  => get_string('defaultaccountlifetimedescription', 'admin'),
            'defaultvalue' => get_config('defaultaccountlifetime'),
            'help'         => true,
        ),
        'defaultaccountinactiveexpire' => array(
            'type'         => 'expiry',
            'title'        => get_string('defaultaccountinactiveexpire', 'admin'),
            'description'  => get_string('defaultaccountinactiveexpiredescription', 'admin'),
            'defaultvalue' => get_config('defaultaccountinactiveexpire'),
            'help'         => true,
        ),
        'defaultaccountinactivewarn' => array(
            'type'         => 'expiry',
            'title'        => get_string('defaultaccountinactivewarn', 'admin'),
            'description'  => get_string('defaultaccountinactivewarndescription', 'admin'),
            'defaultvalue' => get_config('defaultaccountinactivewarn'),
            'help'         => true,
        ),
164
165
        'usersallowedmultipleinstitutions' => array(
            'type'         => 'checkbox',
166
167
            'title'        => get_string('usersallowedmultipleinstitutions', 'admin'),
            'description'  => get_string('usersallowedmultipleinstitutionsdescription', 'admin'),
168
            'defaultvalue' => get_config('usersallowedmultipleinstitutions'),
169
            'help'         => true,
170
        ),
Nigel McNie's avatar
Nigel McNie committed
171
    )
172
173
174
175
176
);

// List of HTML Purifier filters to enable
$siteoptionform['elements']['filters'] = array(
    'type'        => 'fieldset',
177
    'legend'      => get_string('embeddedcontent', 'admin'),
178
179
180
    'collapsible' => true,
    'collapsed'   => true,
    'elements'    => array(
181
        'embeddedcontentdescription' => array(
182
            'type' => 'html',
183
184
185
            'title' => get_string('trustedsites', 'admin'),
            'value' => get_string('embeddedcontentdescription', 'admin'),
            'help' => true,
186
187
188
189
190
191
        ),
        'YouTube' => array(
            'type'         => 'checkbox',
            'title'        => 'http://www.youtube.com',
            'defaultvalue' => in_array('YouTube', $enabledfilters),
        ),
192
193
194
195
196
        'GoogleVideo' => array(
            'type'         => 'checkbox',
            'title'        => 'http://video.google.com',
            'defaultvalue' => in_array('GoogleVideo', $enabledfilters),
        ),
197
198
199
200
201
        'TeacherTube' => array(
            'type'         => 'checkbox',
            'title'        => 'http://www.teachertube.com',
            'defaultvalue' => in_array('TeacherTube', $enabledfilters),
        ),
202
203
204
205
206
        'SciVee' => array(
            'type'         => 'checkbox',
            'title'        => 'http://www.scivee.tv',
            'defaultvalue' => in_array('SciVee', $enabledfilters),
        ),
207
208
209
210
211
        'Skype' => array(
            'type'         => 'checkbox',
            'title'        => 'http://skype.com',
            'defaultvalue' => in_array('Skype', $enabledfilters),
        ),
212
213
214
215
216
        'Twitter' => array(
            'type'         => 'checkbox',
            'title'        => 'http://twitter.com',
            'defaultvalue' => in_array('Twitter', $enabledfilters),
        ),
217
218
219
220
221
222
223
224
225
    ),
);

$siteoptionform['elements']['submit'] = array(
    'type'  => 'submit',
    'value' => get_string('updatesiteoptions', 'admin')
);

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

227
function siteoptions_fail(Pieform $form, $field) {
228
229
230
231
    $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
232
233
}

234
function siteoptions_submit(Pieform $form, $values) {
235
    global $allowedfilters;
236
    $fields = array('sitename','lang','theme', 'pathtoclam',
237
                    'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 
238
                    'allowpublicviews', 'allowpublicprofiles', 'createpublicgroups', 'searchplugin');
239
    $oldlanguage = get_config('lang');
240
    $oldtheme = get_config('theme');
Nigel McNie's avatar
Nigel McNie committed
241
242
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
243
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
244
245
        }
    }
246
247
248
249
250
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
    
Nigel McNie's avatar
Nigel McNie committed
251
252
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
253
        siteoptions_fail($form, 'sessionlifetime');
Nigel McNie's avatar
Nigel McNie committed
254
255
    }
    // Submitted value is on/off; database entry should be 1/0
256
257
258
259
    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
260
    }
261
262
263
264
265
266
267
268
269
270
    // List of filters for HTMLPurifier
    $enabledfilters = array();
    foreach ($allowedfilters as $filter) {
        if ($values[$filter] == 'on') {
            $enabledfilters[] = $filter;
        }
    }
    if (!set_config('filters', serialize($enabledfilters))) {
        siteoptions_fail($form, 'filters');
    }
271
272
273
274
275
    $message = get_string('siteoptionsset', 'admin');
    if ($oldtheme != $values['theme']) {
        $message .= '  ' . get_string('usersseenewthemeonlogin', 'admin');
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php'));
Nigel McNie's avatar
Nigel McNie committed
276
277
}

278
279
280
$thispage = json_encode(get_config('wwwroot') . 'admin/site/options.php');
$smarty = smarty(array('adminsiteoptions'));
$smarty->assign('siteoptionform', $siteoptionform);
281
$smarty->display('admin/site/options.tpl');
Nigel McNie's avatar
Nigel McNie committed
282
283

?>