options.php 6.46 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
29
30
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite');
define('SUBMENUITEM', 'siteoptions');
Nigel McNie's avatar
Nigel McNie committed
31
32
33

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

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

42
43
$searchpluginoptions = get_search_plugins();

Nigel McNie's avatar
Nigel McNie committed
44
$siteoptionform = pieform(array(
Penny Leach's avatar
Penny Leach committed
45
46
47
48
49
50
    'name'       => 'siteoptions',
    'jsform'     => true,
    'renderer'   => 'table',
    'plugintype' => 'core',
    'pluginname' => 'admin',
    'elements'   => array(
Nigel McNie's avatar
Nigel McNie committed
51
52
53
54
55
        '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
56
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
57
58
59
60
61
62
63
64
        ),
        'language' => array(
            'type'         => 'select',
            'title'        => get_string('language','admin'),
            'description'  => get_string('sitelanguagedescription','admin'),
            'defaultvalue' => get_config('language'),
            'collapseifoneoption' => true,
            'options'      => $langoptions,
Penny Leach's avatar
Penny Leach committed
65
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
66
67
68
69
70
71
72
73
        ),
        '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
74
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
75
        ),
76
77
78
79
80
81
82
        '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
83
            'help'         => true,
84
        ),
85
86
87
88
89
        '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
90
            'help'         => true,
91
        ),
Nigel McNie's avatar
Nigel McNie committed
92
93
94
95
96
        '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
97
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
98
99
100
101
102
103
        ),
        '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
104
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
105
106
107
108
109
110
111
        ),
        '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
112
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
113
114
115
116
117
118
119
        ),
        '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
120
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
121
122
123
124
125
126
        ),
        '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
127
            'help'         => true,
Nigel McNie's avatar
Nigel McNie committed
128
129
130
131
132
133
134
135
        ),
        'submit' => array(
            'type'  => 'submit',
            'value' => get_string('updatesiteoptions','admin')
        ),
    )
));

136
function siteoptions_fail(Pieform $form, $field) {
Richard Mansfield's avatar
Richard Mansfield committed
137
    $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
138
139
}

140
function siteoptions_submit(Pieform $form, $values) {
141
    $fields = array('sitename','language','theme','pathtofile', 'pathtoclam',
142
                    'allowpublicviews','artefactviewinactivitytime', 'searchplugin');
Nigel McNie's avatar
Nigel McNie committed
143
144
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
145
            siteoptions_fail($form, $field);
Nigel McNie's avatar
Nigel McNie committed
146
147
148
149
        }
    }
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
150
        siteoptions_fail($form, 'sessionlifetime');
Nigel McNie's avatar
Nigel McNie committed
151
152
153
    }
    // Submitted value is on/off; database entry should be 1/0
    if (!set_config('viruschecking', (int) ($values['viruschecking'] == 'on'))) {
154
        siteoptions_fail($form, 'viruschecking');
Nigel McNie's avatar
Nigel McNie committed
155
    }
156
    $form->json_reply(PIEFORM_OK, get_string('siteoptionsset','admin'));
Nigel McNie's avatar
Nigel McNie committed
157
158
159
}

$smarty = smarty();
160
161
$smarty->assign('SITEOPTIONFORM', $siteoptionform);
$smarty->display('admin/site/options.tpl');
Nigel McNie's avatar
Nigel McNie committed
162
163

?>