XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
notifications.php
Go to the documentation of this file.
1 <?php
19 $xoopsOption['pagetype'] = 'notification';
20 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php';
21 
22 if (!is_object($xoopsUser)) {
23  redirect_header('index.php', 3, _NOT_NOACCESS);
24  exit();
25 }
26 
27 $uid = $xoopsUser->getVar('uid');
28 
29 $op = 'list';
30 if (isset($_POST['op'])) {
31  $op = trim($_POST['op']);
32 } else if (isset($_GET['op'])) {
33  $op = trim($_GET['op']);
34 }
35 if (isset($_POST['delete'])) {
36  $op = 'delete';
37 } else if (isset($_GET['delete'])) {
38  $op = 'delete';
39 }
40 if (isset($_POST['delete_ok'])) {
41  $op = 'delete_ok';
42 }
43 if (isset($_POST['delete_cancel'])) {
44  $op = 'cancel';
45 }
46 
47 switch ($op) {
48  case 'cancel':
49  // FIXME: does this always go back to correct location??
50  redirect_header('index.php');
51  break;
52 
53  case 'list':
54  // Do we allow other users to see our notifications? Nope, but maybe
55  // see who else is monitoring a particular item (or at least how many)?
56  // Well, maybe admin can see all...
57  // TODO: need to span over multiple pages...???
58  // Get an array of all notifications for the selected user
59  $criteria = new Criteria('not_uid', $uid);
60  $criteria->setSort('not_modid,not_category,not_itemid');
61  $notification_handler =& xoops_gethandler('notification');
62  $notifications = $notification_handler->getObjects($criteria);
63 
64  // Generate the info for the template
65  $module_handler =& xoops_gethandler('module');
66  include_once $GLOBALS['xoops']->path('include/notification_functions.php');
67  $modules = array();
68  $prev_modid = - 1;
69  $prev_category = - 1;
70  $prev_item = - 1;
71  foreach ($notifications as $n) {
72  $modid = $n->getVar('not_modid');
73  if ($modid != $prev_modid) {
74  $prev_modid = $modid;
75  $prev_category = - 1;
76  $prev_item = - 1;
78  $modules[$modid] = array(
79  'id' => $modid ,
80  'name' => $module->getVar('name') ,
81  'categories' => array());
82  // TODO: note, we could auto-generate the url from the id
83  // and category info... (except when category has multiple
84  // subscription scripts defined...)
85  // OR, add one more option to xoops_version 'view_from'
86  // which tells us where to redirect... BUT, e.g. forums, it
87  // still wouldn't give us all the required info... e.g. the
88  // topic ID doesn't give us the ID of the forum which is
89  // a required argument...
90  // Get the lookup function, if exists
91  $not_config = $module->getInfo('notification');
92  $lookup_func = '';
93  if (! empty($not_config['lookup_file'])) {
94  $lookup_file = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file']);
95  if (file_exists($lookup_file)) {
96  include_once $lookup_file;
97  if (! empty($not_config['lookup_func']) && function_exists($not_config['lookup_func'])) {
98  $lookup_func = $not_config['lookup_func'];
99  }
100  }
101  }
102  }
103  $category = $n->getVar('not_category');
104  if ($category != $prev_category) {
105  $prev_category = $category;
106  $prev_item = - 1;
107  $category_info = & notificationCategoryInfo($category, $modid);
108  $modules[$modid]['categories'][$category] = array(
109  'name' => $category ,
110  'title' => $category_info['title'] ,
111  'items' => array());
112  }
113  $item = $n->getVar('not_itemid');
114  if ($item != $prev_item) {
115  $prev_item = $item;
116  if (! empty($lookup_func)) {
117  $item_info = $lookup_func($category, $item);
118  } else {
119  $item_info = array(
120  'name' => '[' . _NOT_NAMENOTAVAILABLE . ']' ,
121  'url' => '');
122  }
123  $modules[$modid]['categories'][$category]['items'][$item] = array(
124  'id' => $item ,
125  'name' => $item_info['name'] ,
126  'url' => $item_info['url'] ,
127  'notifications' => array());
128  }
129  $event_info =& notificationEventInfo($category, $n->getVar('not_event'), $n->getVar('not_modid'));
130  $modules[$modid]['categories'][$category]['items'][$item]['notifications'][] = array(
131  'id' => $n->getVar('not_id') ,
132  'module_id' => $n->getVar('not_modid') ,
133  'category' => $n->getVar('not_category') ,
134  'category_title' => $category_info['title'] ,
135  'item_id' => $n->getVar('not_itemid') ,
136  'event' => $n->getVar('not_event') ,
137  'event_title' => $event_info['title'] ,
138  'user_id' => $n->getVar('not_uid'));
139  }
140  $xoopsOption['template_main'] = 'system_notification_list.html';
141  include $GLOBALS['xoops']->path('header.php');
142  $xoopsTpl->assign('modules', $modules);
143  $user_info = array('uid' => $xoopsUser->getVar('uid'));
144  $xoopsTpl->assign('user', $user_info);
145  $xoopsTpl->assign('lang_cancel', _CANCEL);
146  $xoopsTpl->assign('lang_clear', _NOT_CLEAR);
147  $xoopsTpl->assign('lang_delete', _DELETE);
148  $xoopsTpl->assign('lang_checkall', _NOT_CHECKALL);
149  $xoopsTpl->assign('lang_module', _NOT_MODULE);
150  $xoopsTpl->assign('lang_event', _NOT_EVENT);
151  $xoopsTpl->assign('lang_events', _NOT_EVENTS);
152  $xoopsTpl->assign('lang_category', _NOT_CATEGORY);
153  $xoopsTpl->assign('lang_itemid', _NOT_ITEMID);
154  $xoopsTpl->assign('lang_itemname', _NOT_ITEMNAME);
155  $xoopsTpl->assign('lang_activenotifications', _NOT_ACTIVENOTIFICATIONS);
156  $xoopsTpl->assign('notification_token', $GLOBALS['xoopsSecurity']->createToken());
157  include $GLOBALS['xoops']->path('footer.php');
158 
159  // TODO: another display mode... instead of one notification per line,
160  // show one line per item_id, with checkboxes for the available options...
161  // and an update button to change them... And still have the delete box
162  // to delete all notification for that item
163  // How about one line per ID, showing category, name, id, and list of
164  // events...
165  // TODO: it would also be useful to provide links to other available
166  // options so we can say switch from new_message to 'bookmark' if we
167  // are receiving too many emails. OR, if we click on 'change options'
168  // we get a form for that page...
169  // TODO: option to specify one-time??? or other modes??
170  break;
171 
172  case 'delete_ok':
173  if (empty($_POST['del_not'])) {
174  redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
175  }
176  include $GLOBALS['xoops']->path('header.php');
177  $hidden_vars = array(
178  'uid' => $uid ,
179  'delete_ok' => 1 ,
180  'del_not' => $_POST['del_not']);
181  echo '<h4>' . _NOT_DELETINGNOTIFICATIONS . '</h4>';
182  xoops_confirm($hidden_vars, xoops_getenv('PHP_SELF'), _NOT_RUSUREDEL);
183  include $GLOBALS['xoops']->path('footer.php');
184  // FIXME: There is a problem here... in xoops_confirm it treats arrays as
185  // optional radio arguments on the confirmation page... change this or
186  // write new function...
187  break;
188 
189  case 'delete':
190  if (!$GLOBALS['xoopsSecurity']->check()) {
191  redirect_header('notifications.php', 2, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
192  }
193  if (empty($_POST['del_not'])) {
194  redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
195  }
196  $notification_handler =& xoops_gethandler('notification');
197  foreach ($_POST['del_not'] as $n_array) {
198  foreach ($n_array as $n) {
199  $notification =& $notification_handler->get($n);
200  if ($notification->getVar('not_uid') == $uid) {
201  $notification_handler->delete($notification);
202  }
203  }
204  }
205  redirect_header('notifications.php', 2, _NOT_DELETESUCCESS);
206  break;
207  default:
208  break;
209 }
210 
211 ?>