options.php 7.63 KB
Newer Older
Nigel McNie's avatar
Nigel McNie committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
/**
 * This program is part of Mahara
 *
 *  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 2 of the License, or
 *  (at your option) any later version.
 *
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
 * @subpackage admin
 * @author     Nigel McNie <nigel@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

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
42
$searchpluginoptions = get_search_plugins();

Nigel McNie's avatar
Nigel McNie committed
43
$siteoptionform = pieform(array(
Penny Leach's avatar
Penny Leach committed
44
45
46
47
48
49
    'name'       => 'siteoptions',
    'jsform'     => true,
    'renderer'   => 'table',
    'plugintype' => 'core',
    'pluginname' => 'admin',
    'elements'   => array(
Nigel McNie's avatar
Nigel McNie committed
50
51
52
53
54
        'sitename' => array(
            'type'         => 'text',
            'title'        => get_string('sitename','admin'),
            'description'  => get_string('sitenamedescription','admin'),
            'defaultvalue' => get_config('sitename'),
Penny Leach's avatar
Penny Leach committed
55
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
56
        ),
57
        'lang' => array(
Nigel McNie's avatar
Nigel McNie committed
58
59
60
            'type'         => 'select',
            'title'        => get_string('language','admin'),
            'description'  => get_string('sitelanguagedescription','admin'),
61
            'defaultvalue' => get_config('lang'),
Nigel McNie's avatar
Nigel McNie committed
62
63
            'collapseifoneoption' => true,
            'options'      => $langoptions,
Penny Leach's avatar
Penny Leach committed
64
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
65
66
67
68
69
70
71
72
        ),
        'theme' => array(
            'type'         => 'select',
            'title'        => get_string('theme','admin'),
            'description'  => get_string('sitethemedescription','admin'),
            'defaultvalue' => get_config('theme'),
            'collapseifoneoption' => true,
            'options'      => $themeoptions,
Penny Leach's avatar
Penny Leach committed
73
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
74
        ),
75
76
77
78
79
80
81
        'searchplugin' => array(
            'type'         => 'select',
            'title'        => get_string('searchplugin','admin'),
            'description'  => get_string('searchplugindescription','admin'),
            'defaultvalue' => get_config('searchplugin'),
            'collapseifoneoption' => true,
            'options'      => $searchpluginoptions,
Penny Leach's avatar
Penny Leach committed
82
            'help'         => true,
83
        ),
84
85
86
87
88
        'pathtofile' => array(
            'type'         => 'text',
            'title'        => get_string('pathtofile','admin'),
            'description'  => get_string('pathtofiledescription','admin'),
            'defaultvalue' => get_config('pathtofile'),
Penny Leach's avatar
Penny Leach committed
89
            'help'         => true,
90
        ),
Nigel McNie's avatar
Nigel McNie committed
91
92
93
94
95
        'viruschecking' => array(
            'type'         => 'checkbox',
            'title'        => get_string('viruschecking','admin'),
            'description'  => get_string('viruscheckingdescription','admin'),
            'defaultvalue' => get_config('viruschecking'),
Penny Leach's avatar
Penny Leach committed
96
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
97
98
99
100
101
102
        ),
        'pathtoclam' => array(
            'type'         => 'text',
            'title'        => get_string('pathtoclam','admin'),
            'description'  => get_string('pathtoclamdescription','admin'),
            'defaultvalue' => get_config('pathtoclam'),
Penny Leach's avatar
Penny Leach committed
103
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
104
105
106
107
108
109
110
        ),
        'sessionlifetime' => array(
            'type'         => 'text',
            'size'         => 4,
            'title'        => get_string('sessionlifetime','admin'),
            'description'  => get_string('sessionlifetimedescription','admin'),
            'defaultvalue' => get_config('session_timeout') / 60,
Penny Leach's avatar
Penny Leach committed
111
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
112
113
114
115
116
117
118
        ),
        'allowpublicviews' => array(
            'type'         => 'select',
            'title'        => get_string('allowpublicviews','admin'),
            'description'  => get_string('allowpublicviewsdescription','admin'),
            'defaultvalue' => get_config('allowpublicviews'),
            'options'      => $yesno,
Penny Leach's avatar
Penny Leach committed
119
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
120
121
122
123
124
125
        ),
        'artefactviewinactivitytime' => array(
            'type'         => 'expiry',
            'title'        => get_string('artefactviewinactivitytime','admin'),
            'description'  => get_string('artefactviewinactivitytimedescription','admin'),
            'defaultvalue' => get_config('artefactviewinactivitytime'),
Penny Leach's avatar
Penny Leach committed
126
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
127
        ),
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
        '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,
        ),
Nigel McNie's avatar
Nigel McNie committed
149
150
151
152
153
154
155
        'submit' => array(
            'type'  => 'submit',
            'value' => get_string('updatesiteoptions','admin')
        ),
    )
));

156
function siteoptions_fail(Pieform $form, $field) {
Richard Mansfield's avatar
Richard Mansfield committed
157
    $form->json_reply(PIEFORM_ERR, get_string('setsiteoptionsfailed','admin', get_string($field)), array($field => get_string($field . 'invalid', 'admin')));
Nigel McNie's avatar
Nigel McNie committed
158
159
}

160
function siteoptions_submit(Pieform $form, $values) {
161
    $fields = array('sitename','lang','theme','pathtofile', 'pathtoclam',
162
                    'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 
163
                    'allowpublicviews','artefactviewinactivitytime', 'searchplugin');
Nigel McNie's avatar
Nigel McNie committed
164
165
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
166
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
167
168
169
170
        }
    }
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
171
        siteoptions_fail($form, 'sessionlifetime');
Nigel McNie's avatar
Nigel McNie committed
172
173
174
    }
    // Submitted value is on/off; database entry should be 1/0
    if (!set_config('viruschecking', (int) ($values['viruschecking'] == 'on'))) {
175
        siteoptions_fail($form, 'viruschecking');
Nigel McNie's avatar
Nigel McNie committed
176
    }
177
    $form->json_reply(PIEFORM_OK, get_string('siteoptionsset','admin'));
Nigel McNie's avatar
Nigel McNie committed
178
179
180
}

$smarty = smarty();
181
182
$smarty->assign('SITEOPTIONFORM', $siteoptionform);
$smarty->display('admin/site/options.tpl');
Nigel McNie's avatar
Nigel McNie committed
183
184

?>