options.php 5.24 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
34
35
36
37
38
39
40
41
42

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');

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

$siteoptionform = pieform(array(
    'name'     => 'siteoptions',
    'ajaxpost' => true,
43
    'renderer' => 'table',
Nigel McNie's avatar
Nigel McNie committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    'elements' => array(
        'sitename' => array(
            'type'         => 'text',
            'title'        => get_string('sitename','admin'),
            'description'  => get_string('sitenamedescription','admin'),
            'defaultvalue' => get_config('sitename'),
        ),
        'language' => array(
            'type'         => 'select',
            'title'        => get_string('language','admin'),
            'description'  => get_string('sitelanguagedescription','admin'),
            'defaultvalue' => get_config('language'),
            'collapseifoneoption' => true,
            'options'      => $langoptions,
        ),
        'theme' => array(
            'type'         => 'select',
            'title'        => get_string('theme','admin'),
            'description'  => get_string('sitethemedescription','admin'),
            'defaultvalue' => get_config('theme'),
            'collapseifoneoption' => true,
            'options'      => $themeoptions,
        ),
        'viruschecking' => array(
            'type'         => 'checkbox',
            'title'        => get_string('viruschecking','admin'),
            'description'  => get_string('viruscheckingdescription','admin'),
            'defaultvalue' => get_config('viruschecking'),
        ),
        'pathtoclam' => array(
            'type'         => 'text',
            'title'        => get_string('pathtoclam','admin'),
            'description'  => get_string('pathtoclamdescription','admin'),
            'defaultvalue' => get_config('pathtoclam'),
        ),
        'sessionlifetime' => array(
            'type'         => 'text',
            'size'         => 4,
            'title'        => get_string('sessionlifetime','admin'),
            'description'  => get_string('sessionlifetimedescription','admin'),
            'defaultvalue' => get_config('session_timeout') / 60,
        ),
        'allowpublicviews' => array(
            'type'         => 'select',
            'title'        => get_string('allowpublicviews','admin'),
            'description'  => get_string('allowpublicviewsdescription','admin'),
            'defaultvalue' => get_config('allowpublicviews'),
            'options'      => $yesno,
        ),
        'artefactviewinactivitytime' => array(
            'type'         => 'expiry',
            'title'        => get_string('artefactviewinactivitytime','admin'),
            'description'  => get_string('artefactviewinactivitytimedescription','admin'),
            'defaultvalue' => get_config('artefactviewinactivitytime'),
        ),
        'submit' => array(
            'type'  => 'submit',
            'value' => get_string('updatesiteoptions','admin')
        ),
    )
));

106
107
function siteoptions_fail($field, Pieform $form) {
    $form->json_reply(PIEFORM_ERR, get_string('siteoptionsfailed','admin', get_string($field)), array($field => get_string($field . 'invalid', 'admin')));
Nigel McNie's avatar
Nigel McNie committed
108
109
}

110
function siteoptions_submit($values, Pieform $form) {
Nigel McNie's avatar
Nigel McNie committed
111
    $fields = array('sitename','language','theme','pathtoclam',
112
                    'allowpublicviews','artefactviewinactivitytime');
Nigel McNie's avatar
Nigel McNie committed
113
114
115
116
117
118
119
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
            siteoptions_fail($field);
        }
    }
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
120
        siteoptions_fail('sessionlifetime', $form);
Nigel McNie's avatar
Nigel McNie committed
121
122
123
    }
    // Submitted value is on/off; database entry should be 1/0
    if (!set_config('viruschecking', (int) ($values['viruschecking'] == 'on'))) {
124
        siteoptions_fail('viruschecking', $form);
Nigel McNie's avatar
Nigel McNie committed
125
    }
126
    $form->json_reply(PIEFORM_OK, get_string('siteoptionsset','admin'));
Nigel McNie's avatar
Nigel McNie committed
127
128
129
}

$smarty = smarty();
130
131
$smarty->assign('SITEOPTIONFORM', $siteoptionform);
$smarty->display('admin/site/options.tpl');
Nigel McNie's avatar
Nigel McNie committed
132
133

?>