index.php 3.79 KB
Newer Older
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
27
28
29
30
31
<?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 core
 * @author     Penny Leach <penny@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

define('INTERNAL', 1);
define('MENUITEM', 'account');
define('SUBMENUITEM', 'accountprefs');

require(dirname(dirname(__FILE__)) . '/init.php');
32
require_once('form.php');
33

Penny Leach's avatar
Penny Leach committed
34
35
36
37
38
39
40
41
42
43
44
45
// load up user preferences
$prefs = (object)($SESSION->get('accountprefs'));

$prefsform = array(
    'name'        => 'accountprefs',
    'method'      => 'post',
    'ajaxpost'    => true,
    'plugintype ' => 'core',
    'pluginname'  => 'account',
    'elements'    => array(
        'friendscontrol' => array(
            'type' => 'radio',
Penny Leach's avatar
Penny Leach committed
46
            'defaultvalue' => $prefs->friendscontrol, 
Penny Leach's avatar
Penny Leach committed
47
48
49
50
51
52
53
54
55
56
57
58
59
            'title'  => get_string('friendsdescr', 'account'),
            'separator' => HTML_BR,
            'options' => array(
                'nobody' => get_string('friendsnobody', 'account'),
                'auth'   => get_string('friendsauth', 'account'),
                'auto'   => get_string('friendsauto', 'account')
            ),
           'rules' => array(
                'required' => true
            )
        ),
        'wysiwyg' => array(
            'type' => 'radio',
Penny Leach's avatar
Penny Leach committed
60
            'defaultvalue' => $prefs->wysiwyg,
Penny Leach's avatar
Penny Leach committed
61
62
63
64
65
66
67
68
69
70
71
            'title' => get_string('wysiwygdescr', 'account'),
            'options' => array(
                1 => get_string('on', 'account'),
                0 => get_string('off', 'account'),
            ),
           'rules' => array(
                'required' => true
            )
        ),
        'messages' => array(
            'type' => 'radio',
Penny Leach's avatar
Penny Leach committed
72
            'defaultvalue' => $prefs->messages,
Penny Leach's avatar
Penny Leach committed
73
            'title' => get_string('messagesdescr', 'account'),
74
            'separator' => HTML_BR,
Penny Leach's avatar
Penny Leach committed
75
76
77
78
79
80
81
82
83
            'options' => array(
                'nobody' => get_string('messagesnobody', 'account'),
                'friends' => get_string('messagesfriends', 'account'),
                'allow' => get_string('messagesallow', 'account'),
            ),
           'rules' => array(
                'required' => true
            )
        ),
Penny Leach's avatar
Penny Leach committed
84
85
86
87
88
89
90
91
92
        'lang' => array(
            'type' => 'select',
            'defaultvalue' => $prefs->lang,
            'title' => get_string('language', 'account'),
            'options' => get_languages(),
            'rules' => array(
                'required' => true
            )
        ),                        
Penny Leach's avatar
Penny Leach committed
93
94
95
96
97
98
        'submit' => array(
            'type' => 'submit',
            'value' => get_string('save'),
        ),
    ),
);
99

Penny Leach's avatar
Penny Leach committed
100
101
102

$smarty = smarty();
$smarty->assign('form', form($prefsform));
103
104
$smarty->display('account/index.tpl');

105
function accountprefs_submit($values) {
Penny Leach's avatar
Penny Leach committed
106
    global $SESSION;
107
108
    // use this as looping through values is not safe.
    $expectedprefs = expected_account_preferences(); 
Penny Leach's avatar
Penny Leach committed
109
110
    foreach (array_keys($expectedprefs) as $pref) {
        $SESSION->set_account_preference($pref, $values[$pref]);
111
    }
112
    json_reply(false, get_string('prefssaved', 'account'));
Penny Leach's avatar
Penny Leach committed
113
    exit;
Penny Leach's avatar
Penny Leach committed
114
115
116
}


117
?>