/
notifications.php
209 lines (199 loc) · 9.15 KB
/
notifications.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* XOOPS notification
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* 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.
*
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @package core
* @since 2.0.0
* @version $Id: notifications.php 12033 2013-09-14 03:16:44Z beckmi $
*/
$xoopsOption['pagetype'] = 'notification';
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php';
if (!is_object($xoopsUser)) {
redirect_header('index.php', 3, _NOT_NOACCESS);
exit();
}
$uid = $xoopsUser->getVar('uid');
$op = 'list';
if (isset($_POST['op'])) {
$op = trim($_POST['op']);
} else if (isset($_GET['op'])) {
$op = trim($_GET['op']);
}
if (isset($_POST['delete'])) {
$op = 'delete';
} else if (isset($_GET['delete'])) {
$op = 'delete';
}
if (isset($_POST['delete_ok'])) {
$op = 'delete_ok';
}
if (isset($_POST['delete_cancel'])) {
$op = 'cancel';
}
switch ($op) {
case 'cancel':
// FIXME: does this always go back to correct location??
redirect_header('index.php');
break;
case 'list':
// Do we allow other users to see our notifications? Nope, but maybe
// see who else is monitoring a particular item (or at least how many)?
// Well, maybe admin can see all...
// TODO: need to span over multiple pages...???
// Get an array of all notifications for the selected user
$criteria = new Criteria('not_uid', $uid);
$criteria->setSort('not_modid,not_category,not_itemid');
$notification_handler =& xoops_gethandler('notification');
$notifications = $notification_handler->getObjects($criteria);
// Generate the info for the template
$module_handler =& xoops_gethandler('module');
include_once $GLOBALS['xoops']->path('include/notification_functions.php');
$modules = array();
$prev_modid = - 1;
$prev_category = - 1;
$prev_item = - 1;
foreach ($notifications as $n) {
$modid = $n->getVar('not_modid');
if ($modid != $prev_modid) {
$prev_modid = $modid;
$prev_category = - 1;
$prev_item = - 1;
$module =& $module_handler->get($modid);
$modules[$modid] = array(
'id' => $modid ,
'name' => $module->getVar('name') ,
'categories' => array());
// TODO: note, we could auto-generate the url from the id
// and category info... (except when category has multiple
// subscription scripts defined...)
// OR, add one more option to xoops_version 'view_from'
// which tells us where to redirect... BUT, e.g. forums, it
// still wouldn't give us all the required info... e.g. the
// topic ID doesn't give us the ID of the forum which is
// a required argument...
// Get the lookup function, if exists
$not_config = $module->getInfo('notification');
$lookup_func = '';
if (! empty($not_config['lookup_file'])) {
$lookup_file = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file']);
if (file_exists($lookup_file)) {
include_once $lookup_file;
if (! empty($not_config['lookup_func']) && function_exists($not_config['lookup_func'])) {
$lookup_func = $not_config['lookup_func'];
}
}
}
}
$category = $n->getVar('not_category');
if ($category != $prev_category) {
$prev_category = $category;
$prev_item = - 1;
$category_info = & notificationCategoryInfo($category, $modid);
$modules[$modid]['categories'][$category] = array(
'name' => $category ,
'title' => $category_info['title'] ,
'items' => array());
}
$item = $n->getVar('not_itemid');
if ($item != $prev_item) {
$prev_item = $item;
if (! empty($lookup_func)) {
$item_info = $lookup_func($category, $item);
} else {
$item_info = array(
'name' => '[' . _NOT_NAMENOTAVAILABLE . ']' ,
'url' => '');
}
$modules[$modid]['categories'][$category]['items'][$item] = array(
'id' => $item ,
'name' => $item_info['name'] ,
'url' => $item_info['url'] ,
'notifications' => array());
}
$event_info =& notificationEventInfo($category, $n->getVar('not_event'), $n->getVar('not_modid'));
$modules[$modid]['categories'][$category]['items'][$item]['notifications'][] = array(
'id' => $n->getVar('not_id') ,
'module_id' => $n->getVar('not_modid') ,
'category' => $n->getVar('not_category') ,
'category_title' => $category_info['title'] ,
'item_id' => $n->getVar('not_itemid') ,
'event' => $n->getVar('not_event') ,
'event_title' => $event_info['title'] ,
'user_id' => $n->getVar('not_uid'));
}
$xoopsOption['template_main'] = 'system_notification_list.html';
include $GLOBALS['xoops']->path('header.php');
$xoopsTpl->assign('modules', $modules);
$user_info = array('uid' => $xoopsUser->getVar('uid'));
$xoopsTpl->assign('user', $user_info);
$xoopsTpl->assign('lang_cancel', _CANCEL);
$xoopsTpl->assign('lang_clear', _NOT_CLEAR);
$xoopsTpl->assign('lang_delete', _DELETE);
$xoopsTpl->assign('lang_checkall', _NOT_CHECKALL);
$xoopsTpl->assign('lang_module', _NOT_MODULE);
$xoopsTpl->assign('lang_event', _NOT_EVENT);
$xoopsTpl->assign('lang_events', _NOT_EVENTS);
$xoopsTpl->assign('lang_category', _NOT_CATEGORY);
$xoopsTpl->assign('lang_itemid', _NOT_ITEMID);
$xoopsTpl->assign('lang_itemname', _NOT_ITEMNAME);
$xoopsTpl->assign('lang_activenotifications', _NOT_ACTIVENOTIFICATIONS);
$xoopsTpl->assign('notification_token', $GLOBALS['xoopsSecurity']->createToken());
include $GLOBALS['xoops']->path('footer.php');
// TODO: another display mode... instead of one notification per line,
// show one line per item_id, with checkboxes for the available options...
// and an update button to change them... And still have the delete box
// to delete all notification for that item
// How about one line per ID, showing category, name, id, and list of
// events...
// TODO: it would also be useful to provide links to other available
// options so we can say switch from new_message to 'bookmark' if we
// are receiving too many emails. OR, if we click on 'change options'
// we get a form for that page...
// TODO: option to specify one-time??? or other modes??
break;
case 'delete_ok':
if (empty($_POST['del_not'])) {
redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
}
include $GLOBALS['xoops']->path('header.php');
$hidden_vars = array(
'uid' => $uid ,
'delete_ok' => 1 ,
'del_not' => $_POST['del_not']);
echo '<h4>' . _NOT_DELETINGNOTIFICATIONS . '</h4>';
xoops_confirm($hidden_vars, xoops_getenv('PHP_SELF'), _NOT_RUSUREDEL);
include $GLOBALS['xoops']->path('footer.php');
// FIXME: There is a problem here... in xoops_confirm it treats arrays as
// optional radio arguments on the confirmation page... change this or
// write new function...
break;
case 'delete':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('notifications.php', 2, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
}
if (empty($_POST['del_not'])) {
redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
}
$notification_handler =& xoops_gethandler('notification');
foreach ($_POST['del_not'] as $n_array) {
foreach ($n_array as $n) {
$notification =& $notification_handler->get($n);
if ($notification->getVar('not_uid') == $uid) {
$notification_handler->delete($notification);
}
}
}
redirect_header('notifications.php', 2, _NOT_DELETESUCCESS);
break;
default:
break;
}