index.php 5.88 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
6
 *
Francois Marier's avatar
Francois Marier committed
7
8
9
10
 * 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 3 of the License, or
 * (at your option) any later version.
11
 *
Francois Marier's avatar
Francois Marier committed
12
13
14
15
 * 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.
16
 *
Francois Marier's avatar
Francois Marier committed
17
18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21
 *
 * @package    mahara
 * @subpackage core
22
 * @author     Catalyst IT Ltd
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
25
26
27
28
 *
 */

define('INTERNAL', 1);
29
define('MENUITEM', 'inbox');
30
31
32
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'account');
define('SECTION_PAGE', 'activity');
33
34

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
35
require_once('pieforms/pieform.php');
36
define('TITLE', get_string('inbox'));
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
$installedtypes = get_records_assoc(
    'activity_type', '', '',
    'plugintype,pluginname,name',
    'name,admin,plugintype,pluginname'
);

$options = array(
    'all' => get_string('alltypes', 'activity'),
);

foreach ($installedtypes as &$t) {
    if (!$t->admin) {
        $section = $t->pluginname ? "{$t->plugintype}.{$t->pluginname}" : 'activity';
        $options[$t->name] = get_string('type' . $t->name, $section);
52
    }
53
}
54

55
if ($USER->get('admin')) {
56
    $options['adminmessages'] = get_string('typeadminmessages', 'activity');
57
58
}

59
60
61
$type = param_variable('type', 'all');
if (!isset($options[$type])) {
    // Comma-separated list; filter out anything that's not an installed type
62
    $type = join(',', array_unique(array_filter(
63
64
65
        split(',', $type),
        create_function('$a', 'global $installedtypes; return isset($installedtypes[$a]);')
    )));
66
}
67

68
69
require_once('activity.php');
$activitylist = activitylist_html($type);
70

71
$star = json_encode($THEME->get_url('images/star.png'));
72
$strread = json_encode(get_string('read', 'activity'));
73

74
75
$javascript = <<<JAVASCRIPT

76
77
78
function markread(form, action) {

    var e = getElementsByTagAndClassName(null,'tocheck'+action,form);
79
80
81
82
83
84
85
86
    var pd = {};
    
    for (cb in e) {
        if (e[cb].checked == true) {
            pd[e[cb].name] = 1;
        }
    }

87
88
89
90
91
    if (action == 'read') {
        pd['markasread'] = 1;
    } else if (action == 'del') {
        pd['delete'] = 1;
    }
92
93
94
95
96
97

    if (paginatorData) {
        for (p in paginatorData.params) {
            pd[p] = paginatorData.params[p];
        }
    }
98
    
99
    sendjsonrequest('index.json.php', pd, 'GET', function (data) {
100
101
102
        paginator.updateResults(data);
        if (data.newunreadcount && typeof(data.newunreadcount) != 'undefined') {
            updateUnreadCount(data.newunreadcount, 'reset');
103
        }
104
    });
105
106
}

107
function showHideMessage(id) {
108
109
110
111
112
113
114
115
    var message = $('message-' + id);
    if (!message) {
        return;
    }
    if (hasElementClass(message, 'hidden')) {
        var unread = getFirstElementByTagAndClassName(
            'input', 'tocheckread', message.parentNode.parentNode
        );
116
        if (unread) {
117
            var pd = {'readone':id};
118
            sendjsonrequest('index.json.php', pd, 'GET', function(data) {
119
120
                swapDOM(unread, IMG({'src' : {$star}, 'alt' : {$strread}}));
                updateUnreadCount(1, 'decrement');
121
122
            });
        }
123
        removeElementClass(message, 'hidden');
124
125
    }
    else {
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
        addElementClass(message, 'hidden');
    }
}

function changeactivitytype() {
    var params = {'type': this.options[this.selectedIndex].value};
    sendjsonrequest('index.json.php', params, 'GET', function(data) {
        paginator.updateResults(data);
    });
}

// We want the paginator to tell us when a page gets changed.
// @todo: remember checked/unchecked state when changing pages
function PaginatorData() {
    var self = this;
    var params = {};

    this.pageChanged = function(data) {
        self.params = {
            'offset': data.offset,
            'limit': data.limit,
            'type': data.type
        }
149
    }
150
151
152

    paginatorProxy.addObserver(self);
    connect(self, 'pagechanged', self.pageChanged);
153
154
}

155
156
157
158
159
160
161
162
var paginator;
var paginatorData = new PaginatorData();

addLoadEvent(function () {
    paginator = {$activitylist['pagination_js']}
    connect('notifications_type', 'onchange', changeactivitytype);
});

163
164
JAVASCRIPT;

165
166
167
168
169
170
171
172
173
174
$deleteall = pieform(array(
    'name'        => 'delete_all_notifications',
    'method'      => 'post',
    'plugintype'  => 'core',
    'pluginname'  => 'account',
    'elements'    => array(
        'submit' => array(
            'type' => 'submit',
            'value' => get_string('deleteallnotifications', 'activity'),
            'confirm' => get_string('reallydeleteallnotifications', 'activity'),
175
            'class' => 'btn-del',
176
177
178
179
180
181
182
183
184
185
186
187
        ),
    ),
));

function delete_all_notifications_submit() {
    global $USER, $SESSION;
    $count = count_records('notification_internal_activity', 'usr', $USER->get('id'));
    delete_records('notification_internal_activity', 'usr', $USER->get('id'));
    $SESSION->add_ok_msg(get_string('deletednotifications', 'activity', $count));
    redirect(get_config('wwwroot') . 'account/activity/index.php');
}

188
$smarty = smarty(array('paginator'));
189
190
$smarty->assign('options', $options);
$smarty->assign('type', $type);
191
$smarty->assign('INLINEJAVASCRIPT', $javascript);
192
$smarty->assign('PAGEHEADING', TITLE);
193
$smarty->assign('deleteall', $deleteall);
194
$smarty->assign('activitylist', $activitylist);
195
$smarty->display('account/activity/index.tpl');
196
?>