XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
notification_update.php
Go to the documentation of this file.
1 <?php
20 if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
21  die('Restricted access');
22 }
23 // RMV-NOTIFY
24 
25 // This module expects the following arguments:
26 //
27 // not_submit
28 // not_redirect (to return back after update)
29 // not_mid (TODO)
30 // not_uid (TODO)
31 // not_list[1][params] = {category},{itemid},{event}
32 // not_list[1][status] = 1 if selected; 0 or missing if not selected
33 // etc...
34 // TODO: can we put arguments in the not_redirect argument??? do we need
35 // to specially encode them first???
36 // TODO: allow 'GET' also so we can process 'unsubscribe' requests??
37 
38 include_once $GLOBALS['xoops']->path('include/notification_constants.php');
39 include_once $GLOBALS['xoops']->path('include/notification_functions.php');
40 xoops_loadLanguage('notification');
41 
42 if (!isset($_POST['not_submit'])) {
43  redirect_header($_POST['not_redirect'], 3, _NOPERM);
44  exit();
45 }
46 
47 if (!$GLOBALS['xoopsSecurity']->check()) {
48  redirect_header($_POST['not_redirect'], 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
49  exit();
50 }
51 
52 // NOTE: in addition to the templates provided in the block and view
53 // modes, we can have buttons, etc. which load the arguments to be
54 // read by this script. That way a module can really customize its
55 // look as to where/how the notification options are made available.
56 $update_list = $_POST['not_list'];
57 $module_id = $xoopsModule->getVar('mid');
58 $user_id = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
59 
60 // For each event, update the notification depending on the status.
61 // If status=1, subscribe to the event; otherwise, unsubscribe.
62 
63 // FIXME: right now I just ignore database errors (e.g. if already
64 // subscribed)... deal with this more gracefully?
66 foreach ($update_list as $update_item) {
67  list($category, $item_id, $event) = preg_split('/,/', $update_item['params']);
68  $status = !empty($update_item['status']) ? 1 : 0;
69  if (!$status) {
70  $notification_handler->unsubscribe($category, $item_id, $event, $module_id, $user_id);
71  } else {
72  $notification_handler->subscribe($category, $item_id, $event);
73  }
74 
75 }
76 
77 // TODO: something like grey box summary of actions (like multiple comment
78 // deletion), with a button to return back... NOTE: we need some arguments
79 // to help us get back to where we were...
80 
81 // TODO: finish integration with comments... i.e. need calls to
82 // notifyUsers at appropriate places... (need to figure out where
83 // comment submit occurs and where comment approval occurs)...
84 $redirect_args = array();
85 foreach ($update_list as $update_item) {
86  list($category, $item_id, $event) = preg_split('/,/', $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 '&'
94 // symbols...
97 foreach (array_keys($redirect_args) as $arg) {
98  if ($first_arg) {
99  $argstring .= "?" . $arg . "=" . $redirect_args[$arg];
100  $first_arg = 0;
101  } else {
102  $argstring .= "&" . $arg . "=" . $redirect_args[$arg];
103  }
104 }
105 
106 redirect_header ($_POST['not_redirect'].$argstring, 3, _NOT_UPDATEOK);
107 exit();
108 
109 ?>