forked from MaharaProject/mahara
/
index.php
159 lines (138 loc) · 4.74 KB
/
index.php
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
32
33
34
35
36
37
38
39
40
41
42
43
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'inbox');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'account');
define('SECTION_PAGE', 'activity');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('inbox'));
// Make sure the unread message count is up to date whenever the
// user hits this page.
$USER->reload_background_fields();
$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);
}
}
if ($USER->get('admin')) {
$options['adminmessages'] = get_string('typeadminmessages', 'activity');
}
$type = param_variable('type', 'all');
if ($type == '') {
$type = 'all';
}
if (!isset($options[$type])) {
// Comma-separated list; filter out anything that's not an installed type
$type = join(',', array_unique(array_filter(
explode(',', $type),
create_function('$a', 'global $installedtypes; return isset($installedtypes[$a]);')
)));
}
require_once('activity.php');
$activitylist = activitylist_html($type);
$strread = json_encode(get_string('read', 'activity'));
$javascript = <<<JAVASCRIPT
JAVASCRIPT;
$deleteall = pieform(array(
'name' => 'delete_all_notifications',
'method' => 'post',
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => array(
'type' => array(
'type' => 'hidden',
'value' => $type,
),
'submit' => array(
'type' => 'submit',
'class' => 'btn-primary',
'value' => get_string('deleteallnotifications', 'activity'),
'confirm' => get_string('reallydeleteallnotifications', 'activity'),
),
),
));
function delete_all_notifications_submit() {
global $USER, $SESSION;
$userid = $USER->get('id');
$type = param_variable('type', 'all');
$typesql = '';
if ($type != 'all') {
// Treat as comma-separated list of activity type names
$types = explode(',', preg_replace('/[^a-z,]+/', '', $type));
if ($types) {
$typesql = ' at.name IN (' . join(',', array_map('db_quote', $types)) . ')';
if (in_array('adminmessages', $types)) {
$typesql = '(' . $typesql . ' OR at.admin = 1)';
}
$typesql = ' AND ' . $typesql;
}
}
$from = "
FROM {notification_internal_activity} a
JOIN {activity_type} at ON a.type = at.id
WHERE a.usr = ? $typesql";
$values = array($userid);
db_begin();
$count = 0;
$records = get_records_sql_array('SELECT a.id ' . $from, $values);
if ($records) {
$count = sizeof($records);
$ids = array();
foreach ($records as $row) {
$ids[] = $row->id;
}
// Remove parent pointers to messages we're about to delete
execute_sql('
UPDATE {notification_internal_activity}
SET parent = NULL
WHERE parent IN (
' . join(',', array_map('db_quote', $ids)) . '
)'
);
// delete
execute_sql('
DELETE FROM {notification_internal_activity}
WHERE id IN (
' . join(',', array_map('db_quote', $ids)) . '
)'
);
// The update_unread_delete db trigger on notification_internal_activity
// will update the unread column on the usr table.
}
db_commit();
$SESSION->add_ok_msg(get_string('deletednotifications1', 'activity', $count));
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
redirect(get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type='.$type);
}
else {
redirect(get_config('wwwroot') . 'account/activity/index.php?type='.$type);
}
}
$smarty = smarty(array('paginator'));
$smarty->assign('options', $options);
$smarty->assign('type', $type);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('deleteall', $deleteall);
$smarty->assign('activitylist', $activitylist);
$smarty->display('account/activity/index.tpl');