XOOPS  2.6.0
update.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
21 include dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'mainfile.php';
22 
25 
26 // RMV-NOTIFY
27 
28 // This module expects the following arguments:
29 //
30 // not_submit
31 // not_redirect (to return back after update)
32 // not_mid (TODO)
33 // not_uid (TODO)
34 // not_list[1][params] = {category},{itemid},{event}
35 // not_list[1][status] = 1 if selected; 0 or missing if not selected
36 // etc...
37 // TODO: can we put arguments in the not_redirect argument??? do we need
38 // to specially encode them first???
39 // TODO: allow 'GET' also so we can process 'unsubscribe' requests??
40 
41 if (!isset($_POST['not_submit']) || !isset($_POST['mid'])) {
42  $xoops->redirect($_POST['not_redirect'], 3, XoopsLocale::E_NO_ACCESS_PERMISSION);
43 }
44 
45 if (!$xoops->security()->check()) {
46  $xoops->redirect($_POST['not_redirect'], 3, implode('<br />', $xoops->security()->getErrors()));
47 }
48 
49 // NOTE: in addition to the templates provided in the block and view
50 // modes, we can have buttons, etc. which load the arguments to be
51 // read by this script. That way a module can really customize its
52 // look as to where/how the notification options are made available.
53 $update_list = $_POST['not_list'];
54 $module_handler = $xoops->getHandlerModule();
55 $module = $xoops->getModuleById(intval($_POST['mid']));
56 $module_id = $module->getVar('mid');
57 $user_id = $xoops->isUser() ? $xoops->user->getVar('uid') : 0;
58 
59 // For each event, update the notification depending on the status.
60 // If status=1, subscribe to the event; otherwise, unsubscribe.
61 
62 // FIXME: right now I just ignore database errors (e.g. if already
63 // subscribed)... deal with this more gracefully?
64 $notification_handler = $helper->getHandlerNotification();
65 foreach ($update_list as $update_item) {
66  list($category, $item_id, $event) = preg_split('/,/', $update_item['params']);
67  $status = !empty($update_item['status']) ? 1 : 0;
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, null, $module_id);
72  }
73 }
74 
75 // TODO: something like grey box summary of actions (like multiple comment
76 // deletion), with a button to return back... NOTE: we need some arguments
77 // to help us get back to where we were...
78 
79 // TODO: finish integration with comments... i.e. need calls to
80 // notifyUsers at appropriate places... (need to figure out where
81 // comment submit occurs and where comment approval occurs)...
82 $redirect_args = array();
83 foreach ($update_list as $update_item) {
84  list($category, $item_id, $event) = preg_split('/,/', $update_item['params']);
85  $category_info = $helper->getCategory($category, $module->getVar('dirname'));
86  if (!empty($category_info['item_name'])) {
87  $redirect_args[$category_info['item_name']] = $item_id;
88  }
89 }
90 
91 // TODO: write a central function to put together args with '?' and '&'
92 // symbols...
95 foreach (array_keys($redirect_args) as $arg) {
96  if ($first_arg) {
97  $argstring .= "?" . $arg . "=" . $redirect_args[$arg];
98  $first_arg = 0;
99  } else {
100  $argstring .= "&" . $arg . "=" . $redirect_args[$arg];
101  }
102 }
103 
104 $xoops->redirect($_POST['not_redirect'] . $argstring, 3, _MD_NOTIFICATIONS_UPDATEOK);
$module_handler
Definition: update.php:54
static getInstance()
Definition: Xoops.php:160
foreach($update_list as $update_item) $redirect_args
Definition: update.php:82
$module_id
Definition: update.php:56
$notification_handler
Definition: update.php:64
static getInstance()
Definition: helper.php:47
foreach($update_list as $update_item) $argstring
Definition: update.php:93
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
$module
Definition: update.php:55
$status
$helper
Definition: update.php:24
if(!isset($_POST['not_submit'])||!isset($_POST['mid'])) if(!$xoops->security() ->check()) $update_list
Definition: update.php:53
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$first_arg
Definition: update.php:94
const _MD_NOTIFICATIONS_UPDATEOK
Definition: main.php:39
$user_id
Definition: update.php:57
$xoops
Definition: update.php:23