XOOPS  2.6.0
index.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 
22 include dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'mainfile.php';
23 
26 
27 if (!$xoops->isUser()) {
28  $xoops->redirect('index.php', 3, _MD_NOTIFICATIONS_NOACCESS);
29 }
30 
31 $uid = $xoops->user->getVar('uid');
32 
33 $op = 'list';
34 if (isset($_POST['op'])) {
35  $op = trim($_POST['op']);
36 } else {
37  if (isset($_GET['op'])) {
38  $op = trim($_GET['op']);
39  }
40 }
41 if (isset($_POST['delete'])) {
42  $op = 'delete';
43 } else {
44  if (isset($_GET['delete'])) {
45  $op = 'delete';
46  }
47 }
48 if (isset($_POST['delete_ok'])) {
49  $op = 'delete_ok';
50 }
51 if (isset($_POST['delete_cancel'])) {
52  $op = 'cancel';
53 }
54 
55 switch ($op) {
56  case 'cancel':
57  // FIXME: does this always go back to correct location??
58  $xoops->redirect('index.php');
59  break;
60 
61  case 'list':
62  // Do we allow other users to see our notifications? Nope, but maybe
63  // see who else is monitoring a particular item (or at least how many)?
64  // Well, maybe admin can see all...
65  // TODO: need to span over multiple pages...???
66  // Get an array of all notifications for the selected user
67  $criteria = new Criteria('uid', $uid);
68  $criteria->setSort('modid,category,itemid');
69  $notification_handler = $helper->getHandlerNotification();
70  $notifications = $notification_handler->getObjectsArray($criteria);
71 
72  // Generate the info for the template
73  $module_handler = $xoops->getHandlerModule();
74  $modules = array();
75  $prev_modid = -1;
76  $prev_category = -1;
77  $prev_item = -1;
78  $modulesObj = array();
79  foreach ($notifications as $n) {
80  /* @var $n NotificationsNotification */
81  $modid = $n->getVar('modid');
82  if ($modid != $prev_modid) {
83  $prev_modid = $modid;
84  $prev_category = -1;
85  $prev_item = -1;
86  $module = $xoops->getModuleById($modid);
87  $modulesObj[$modid] = $module;
88  $modules[$modid] = array(
89  'id' => $modid, 'name' => $module->getVar('name'), 'categories' => array()
90  );
91  // TODO: note, we could auto-generate the url from the id
92  // and category info... (except when category has multiple
93  // subscription scripts defined...)
94  // OR, add one more option to xoops_version 'view_from'
95  // which tells us where to redirect... BUT, e.g. forums, it
96  // still wouldn't give us all the required info... e.g. the
97  // topic ID doesn't give us the ID of the forum which is
98  // a required argument...
99  // Get the lookup function, if exists
100  }
101  $category = $n->getVar('category');
102  if ($category != $prev_category) {
103  $category_info = array();
104  $prev_category = $category;
105  $prev_item = -1;
106  $category_info = $helper->getCategory($category, $modulesObj[$modid]->getVar('dirname'));
107  $modules[$modid]['categories'][$category] = array(
108  'name' => $category, 'title' => $category_info['title'], 'items' => array()
109  );
110  }
111  $item = $n->getVar('itemid');
112  if ($item != $prev_item) {
113  $prev_item = $item;
114 
115  $item_info = $helper->getItem($category, $item, $modulesObj[$modid]->getVar('dirname'));
116  $modules[$modid]['categories'][$category]['items'][$item] = array(
117  'id' => $item, 'name' => $item_info['name'], 'url' => $item_info['url'], 'notifications' => array()
118  );
119  }
120  $event_info = $helper->getEvent($category, $n->getVar('event'), $modulesObj[$n->getVar('modid')]->getVar('dirname'));
121  $modules[$modid]['categories'][$category]['items'][$item]['notifications'][] = array(
122  'id' => $n->getVar('id'), 'module_id' => $n->getVar('modid'),
123  'category' => $n->getVar('category'), 'category_title' => $category_info['title'],
124  'item_id' => $n->getVar('itemid'), 'event' => $n->getVar('event'),
125  'event_title' => $event_info['title'], 'user_id' => $n->getVar('uid')
126  );
127  }
128  $xoops->header('module:notifications/list.tpl');
129  $xoops->tpl()->assign('modules', $modules);
130  $user_info = array('uid' => $xoops->user->getVar('uid'));
131  $xoops->tpl()->assign('user', $user_info);
132  $xoops->tpl()->assign('lang_cancel', XoopsLocale::A_CANCEL);
133  $xoops->tpl()->assign('lang_clear', _MD_NOTIFICATIONS_CLEAR);
134  $xoops->tpl()->assign('lang_delete', XoopsLocale::A_DELETE);
135  $xoops->tpl()->assign('lang_checkall', _MD_NOTIFICATIONS_CHECKALL);
136  $xoops->tpl()->assign('lang_module', _MD_NOTIFICATIONS_MODULE);
137  $xoops->tpl()->assign('lang_event', _MD_NOTIFICATIONS_EVENT);
138  $xoops->tpl()->assign('lang_events', _MD_NOTIFICATIONS_EVENTS);
139  $xoops->tpl()->assign('lang_category', _MD_NOTIFICATIONS_CATEGORY);
140  $xoops->tpl()->assign('lang_itemid', _MD_NOTIFICATIONS_ITEMID);
141  $xoops->tpl()->assign('lang_itemname', _MD_NOTIFICATIONS_ITEMNAME);
142  $xoops->tpl()->assign('lang_activenotifications', _MD_NOTIFICATIONS_ACTIVENOTIFICATIONS);
143  $xoops->tpl()->assign('notification_token', $xoops->security()->createToken());
144  $xoops->footer();
145 
146  // TODO: another display mode... instead of one notification per line,
147  // show one line per item_id, with checkboxes for the available options...
148  // and an update button to change them... And still have the delete box
149  // to delete all notification for that item
150  // How about one line per ID, showing category, name, id, and list of
151  // events...
152  // TODO: it would also be useful to provide links to other available
153  // options so we can say switch from new_message to 'bookmark' if we
154  // are receiving too many emails. OR, if we click on 'change options'
155  // we get a form for that page...
156  // TODO: option to specify one-time??? or other modes??
157  break;
158 
159  case 'delete_ok':
160  if (empty($_POST['del_not'])) {
161  $helper->redirect('index.php', 2, _MD_NOTIFICATIONS_NOTHINGTODELETE);
162  }
163  $xoops->header();
164  $hidden_vars = array(
165  'uid' => $uid, 'delete_ok' => 1, 'del_not' => $_POST['del_not']
166  );
167  echo '<h4>' . _MD_NOTIFICATIONS_DELETINGNOTIFICATIONS . '</h4>';
168  echo $xoops->confirm($hidden_vars, $xoops->getEnv('PHP_SELF'), _MD_NOTIFICATIONS_RUSUREDEL);
169  $xoops->footer();
170  // FIXME: There is a problem here... in $xoops->confirm it treats arrays as
171  // optional radio arguments on the confirmation page... change this or
172  // write new function...
173  break;
174 
175  case 'delete':
176  if (!$xoops->security()->check()) {
177  $helper->redirect('index.php', 2, implode('<br />', $xoops->security()->getErrors()));
178  }
179  if (empty($_POST['del_not'])) {
180  $helper->redirect('index.php', 2, _MD_NOTIFICATIONS_NOTHINGTODELETE);
181  }
182  $notification_handler = $helper->getHandlerNotification();
183  foreach ($_POST['del_not'] as $n_array) {
184  foreach ($n_array as $n) {
185  $notification = $notification_handler->get($n);
186  if ($notification->getVar('uid') == $uid) {
187  $notification_handler->delete($notification);
188  }
189  }
190  }
191  $helper->redirect('index.php', 2, _MD_NOTIFICATIONS_DELETESUCCESS);
192  break;
193  default:
194  break;
195 }
const _MD_NOTIFICATIONS_RUSUREDEL
Definition: main.php:86
$op
Definition: index.php:33
static getInstance()
Definition: Xoops.php:160
$notification_handler
Definition: update.php:64
static getInstance()
Definition: helper.php:47
const _MD_NOTIFICATIONS_ITEMNAME
Definition: main.php:28
$modid
Definition: groupperm.php:27
const _MD_NOTIFICATIONS_ACTIVENOTIFICATIONS
Definition: main.php:31
const _MD_NOTIFICATIONS_DELETESUCCESS
Definition: main.php:38
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
const _MD_NOTIFICATIONS_EVENTS
Definition: main.php:30
const _MD_NOTIFICATIONS_NOTHINGTODELETE
Definition: main.php:83
const _MD_NOTIFICATIONS_CLEAR
Definition: main.php:23
const _MD_NOTIFICATIONS_NOACCESS
Definition: main.php:45
const A_CANCEL
Definition: en_US.php:82
$criteria
Definition: index.php:30
$module
Definition: main.php:52
if(!$xoops->isUser()) $uid
Definition: index.php:31
const _MD_NOTIFICATIONS_EVENT
Definition: main.php:29
const _MD_NOTIFICATIONS_ITEMID
Definition: main.php:27
$helper
Definition: index.php:25
$modules
Definition: userinfo.php:185
const A_DELETE
Definition: en_US.php:89
$module_handler
Definition: main.php:55
const _MD_NOTIFICATIONS_MODULE
Definition: main.php:25
const _MD_NOTIFICATIONS_DELETINGNOTIFICATIONS
Definition: main.php:37
const _MD_NOTIFICATIONS_CHECKALL
Definition: main.php:24
const _MD_NOTIFICATIONS_CATEGORY
Definition: main.php:26
if(file_exists($mainfile)) elseif(file_exists(__DIR__. '/install/index.php')) $xoops
Definition: index.php:36