XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
notification_update.php
1<?php
13
14
15// RMV-NOTIFY
16
17// This module expects the following arguments:
18//
19// not_submit
20// not_redirect (to return back after update)
21// not_mid (TODO)
22// not_uid (TODO)
23// not_list[1][params] = {category},{itemid},{event}
24// not_list[1][status] = 1 if selected; 0 or missing if not selected
25// etc...
26
27// TODO: can we put arguments in the not_redirect argument??? do we need
28// to specially encode them first???
29
30// TODO: allow 'GET' also so we can process 'unsubscribe' requests??
31
32if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
33 exit();
34}
35
36include_once XOOPS_ROOT_PATH.'/include/notification_constants.php';
37include_once XOOPS_ROOT_PATH.'/include/notification_functions.php';
38
39$root =& XCube_Root::getSingleton();
40$root->mLanguageManager->loadPageTypeMessageCatalog('notification');
41
42if (!isset($_POST['not_submit'])) {
43 exit();
44}
45
46// NOTE: in addition to the templates provided in the block and view
47// modes, we can have buttons, etc. which load the arguments to be
48// read by this script. That way a module can really customize its
49// look as to where/how the notification options are made available.
50
51$update_list = $_POST['not_list'];
52
53$module_id = $xoopsModule->getVar('mid');
54$user_id = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
55
56// For each event, update the notification depending on the status.
57// If status=1, subscribe to the event; otherwise, unsubscribe.
58
59// FIXME: right now I just ignore database errors (e.g. if already
60// subscribed)... deal with this more gracefully?
61
62$notification_handler =& xoops_gethandler('notification');
63
64foreach ($update_list as $update_item) {
65 [$category, $item_id, $event] = explode(',', $update_item['params']);
66 $status = !empty($update_item['status']) ? 1 : 0;
67
68 if (!$status) {
69 $notification_handler->unsubscribe($category, $item_id, $event, $module_id, $user_id);
70 } else {
71 $notification_handler->subscribe($category, $item_id, $event);
72 }
73}
74
75// TODO: something like grey box summary of actions (like multiple comment deletion), with a button to return back...
76// NOTE: we need some arguments to help us get back to where we were...
77
78// TODO: finish integration with comments... i.e. need calls to
79// notifyUsers at appropriate places... (need to figure out where
80// comment submit occurs and where comment approval occurs)...
81
82include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
83
84$redirect_args = [];
85foreach ($update_list as $update_item) {
86 [$category, $item_id, $event] = explode(',', $update_item['params']);
87 $category_info =& notificationCategoryInfo($category);
88 if (!empty($category_info['item_name'])) {
89 $redirect_args[$category_info['item_name']] = $item_id;
90 }
91}
92
93// TODO: write a central function to put together args with '?' and '&amp;'
94// symbols...
95$argstring = '';
96$first_arg = 1;
97foreach (array_keys($redirect_args) as $arg) {
98 if ($first_arg) {
99 $argstring .= '?' . $arg . '=' . $redirect_args[$arg];
100 $first_arg = 0;
101 } else {
102 $argstring .= '&amp;' . $arg . '=' . $redirect_args[$arg];
103 }
104}
105
106redirect_header($_POST['not_redirect'].$argstring, 2, _NOT_UPDATEOK);
107exit();