index.php 2.63 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', 'activityprefs');

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

34
35
36
37
38
39
$activitytypes = get_records('activity_type', 'admin', 0);
$notifications = plugins_installed('notification');

$elements = array();

foreach ($activitytypes as $type) {
40
    if (!$dv = $USER->get_activity_preference($type->name)) {
Penny Leach's avatar
Penny Leach committed
41
42
        $dv = 'internal';
    }
43
    $elements[$type->name] = array(
Penny Leach's avatar
Penny Leach committed
44
        'defaultvalue' => $dv,
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        'type' => 'select',
        'title' => get_string('type' . $type->name, 'activity'),
        'options' => array(),
        'rules' => array(
            'required' => true
        )
    );

    foreach ($notifications as $n) {
         $elements[$type->name]['options'][$n->name] = get_string('name', 'notification.' . $n->name);
    }
}

$elements['submit'] = array(
    'type' => 'submit',
    'value' => get_string('save'),
);
62

63
64
65
66
67
68
69
70
71
72
73
74

$prefsform = array(
    'name'        => 'activityprefs',
    'method'      => 'post',
    'ajaxpost'    => true,
    'plugintype ' => 'core',
    'pluginname'  => 'account',
    'elements'    => $elements,
);

$smarty = smarty();
$smarty->assign('prefsdescr', get_string('prefsdescr', 'activity'));
75
$smarty->assign('form', pieform($prefsform));
76
77
$smarty->display('account/activity/preferences/index.tpl');

78
function activityprefs_submit($values) {
79
    global $activitytypes, $USER;
80
    
81
    $userid = $USER->get('id');
Penny Leach's avatar
Penny Leach committed
82
    foreach ($activitytypes as $type) {
83
        $USER->set_activity_preference($type->name, $values[$type->name]);
84
    }
85
    json_reply(false, get_string('prefssaved', 'account'));
Penny Leach's avatar
Penny Leach committed
86
    exit;
87
88
89
}


90
?>