source: temp/test-xoops.ec-cube.net/html/notifications.php @ 405

Revision 405, 9.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: notifications.php,v 1.3 2005/09/04 20:46:08 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27
28$xoopsOption['pagetype'] = 'notification';
29include 'mainfile.php';
30
31if (empty($xoopsUser)) {
32    redirect_header('index.php', 3, _NOT_NOACCESS);
33    exit();
34}
35
36$uid = $xoopsUser->getVar('uid');
37
38$op = 'list';
39
40if (isset($_POST['op'])) {
41    $op = trim($_POST['op']);
42} elseif (isset($_GET['op'])) {
43    $op = trim($_GET['op']);
44}
45if (isset($_POST['delete'])) {
46    $op = 'delete';
47} elseif (isset($_GET['delete'])) {
48    $op = 'delete';
49}
50if (isset($_POST['delete_ok'])) {
51    $op = 'delete_ok';
52}
53if (isset($_POST['delete_cancel'])) {
54    $op = 'cancel';
55}
56
57switch ($op) {
58
59case 'cancel':
60
61    // FIXME: does this always go back to correct location??
62    redirect_header ('index.php');
63    break;
64
65case 'list':
66
67// Do we allow other users to see our notifications?  Nope, but maybe
68// see who else is monitoring a particular item (or at least how many)?
69// Well, maybe admin can see all...
70
71// TODO: need to span over multiple pages...???
72
73    // Get an array of all notifications for the selected user
74
75    $criteria = new Criteria ('not_uid', $uid);
76    $criteria->setSort ('not_modid,not_category,not_itemid');
77    $notification_handler =& xoops_gethandler('notification');
78    $notifications =& $notification_handler->getObjects($criteria);
79
80    // Generate the info for the template
81
82    $module_handler =& xoops_gethandler('module');
83    include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
84
85    $modules = array();
86    $prev_modid = -1;
87    $prev_category = -1;
88    $prev_item = -1;
89    foreach ($notifications as $n) {
90        $modid = $n->getVar('not_modid');
91        if ($modid != $prev_modid) {
92            $prev_modid = $modid;
93            $prev_category = -1;
94            $prev_item = -1;
95            $module =& $module_handler->get($modid);
96            $modules[$modid] = array ('id'=>$modid, 'name'=>$module->getVar('name'), 'categories'=>array());
97            // TODO: note, we could auto-generate the url from the id
98            // and category info... (except when category has multiple
99            // subscription scripts defined...)
100            // OR, add one more option to xoops_version 'view_from'
101            // which tells us where to redirect... BUT, e.g. forums, it
102            // still wouldn't give us all the required info... e.g. the
103            // topic ID doesn't give us the ID of the forum which is
104            // a required argument...
105
106            // Get the lookup function, if exists
107            $not_config = $module->getInfo('notification');
108            $lookup_func = '';
109            if (!empty($not_config['lookup_file'])) {
110                $lookup_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file'];
111                if (file_exists($lookup_file)) {
112                    include_once $lookup_file;
113                    if (!empty($not_config['lookup_func']) && function_exists($not_config['lookup_func'])) {
114                        $lookup_func = $not_config['lookup_func'];
115                    }
116                }
117            }
118        }
119        $category = $n->getVar('not_category');
120        if ($category != $prev_category) {
121            $prev_category = $category;
122            $prev_item = -1;
123            $category_info =& notificationCategoryInfo($category, $modid);
124            $modules[$modid]['categories'][$category] = array ('name'=>$category, 'title'=>$category_info['title'], 'items'=>array());
125        }
126        $item = $n->getVar('not_itemid');
127        if ($item != $prev_item) {
128            $prev_item = $item;
129            if (!empty($lookup_func)) {
130                $item_info = $lookup_func($category, $item);
131            } else {
132                $item_info = array ('name'=>'['._NOT_NAMENOTAVAILABLE.']', 'url'=>'');
133            }
134            $modules[$modid]['categories'][$category]['items'][$item] = array ('id'=>$item, 'name'=>$item_info['name'], 'url'=>$item_info['url'], 'notifications'=>array());
135        }
136        $event_info =& notificationEventInfo($category, $n->getVar('not_event'), $n->getVar('not_modid'));
137        $modules[$modid]['categories'][$category]['items'][$item]['notifications'][] = array ('id'=>$n->getVar('not_id'), 'module_id'=>$n->getVar('not_modid'), 'category'=>$n->getVar('not_category'), 'category_title'=>$category_info['title'], 'item_id'=>$n->getVar('not_itemid'), 'event'=>$n->getVar('not_event'), 'event_title'=>$event_info['title'], 'user_id'=>$n->getVar('not_uid'));
138    }
139    $xoopsOption['template_main'] = 'system_notification_list.html';
140    include XOOPS_ROOT_PATH.'/header.php';
141    $xoopsTpl->assign ('modules', $modules);   
142    $user_info = array ('uid' => $xoopsUser->getVar('uid'));
143    $xoopsTpl->assign ('user', $user_info);
144    $xoopsTpl->assign ('lang_cancel', _CANCEL);
145    $xoopsTpl->assign ('lang_clear', _NOT_CLEAR);
146    $xoopsTpl->assign ('lang_delete', _DELETE);
147    $xoopsTpl->assign ('lang_checkall', _NOT_CHECKALL);
148    $xoopsTpl->assign ('lang_module', _NOT_MODULE);
149    $xoopsTpl->assign ('lang_event', _NOT_EVENT);
150    $xoopsTpl->assign ('lang_events', _NOT_EVENTS);
151    $xoopsTpl->assign ('lang_category', _NOT_CATEGORY);
152    $xoopsTpl->assign ('lang_itemid', _NOT_ITEMID);
153    $xoopsTpl->assign ('lang_itemname', _NOT_ITEMNAME);
154    $xoopsTpl->assign ('lang_activenotifications', _NOT_ACTIVENOTIFICATIONS);
155    include XOOPS_ROOT_PATH.'/footer.php';
156
157// TODO: another display mode... instead of one notification per line,
158// show one line per item_id, with checkboxes for the available options...
159// and an update button to change them...  And still have the delete box
160// to delete all notification for that item
161
162// How about one line per ID, showing category, name, id, and list of
163// events...
164
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
170// TODO: option to specify one-time??? or other modes??
171
172    break;
173
174case 'delete':
175    if (empty($_POST['del_not'])||!is_array($_POST['del_not'])) {
176        redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
177    }
178    $del_notifications = array();
179    foreach($_POST['del_not'] as $not_modid => $not_ids) {
180        if (!is_array($not_ids)) {
181            redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
182        }
183        foreach ($not_ids as $not_id) {
184            $del_notifications[] = intval($not_modid).'|'.intval($not_id);
185        }
186    }
187    $del_not = implode(',', $del_notifications);
188    include XOOPS_ROOT_PATH.'/header.php';
189    $hidden_vars = array('delete_ok'=>1, 'del_not'=>$del_not);
190    print '<h4>'._NOT_DELETINGNOTIFICATIONS.'</h4>';
191    xoops_confirm($hidden_vars, xoops_getenv('PHP_SELF'), _NOT_RUSUREDEL);
192    include XOOPS_ROOT_PATH.'/footer.php';
193    break;
194
195case 'delete_ok':
196    if(!xoops_confirm_validate()) {
197        redirect_header('notifications.php',2,'Ticket Error');
198    }
199    if (empty($_POST['del_not'])) {
200        redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
201    }
202    $del_notifications = explode(',', $_POST['del_not']);
203    if (!is_array($del_notifications) || count($del_notifications)==0) {
204        redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
205    }
206    $notification_handler =& xoops_gethandler('notification');
207    foreach ($del_notifications as $del_notification) {
208        $del_notification_items = explode('|',$del_notification);
209        if (is_array($del_notification_items) && (count($del_notification_items)==2) && !empty($del_notification_items[0]) && !empty($del_notification_items[1])) {
210            $notification =& $notification_handler->get(intval($del_notification_items[1]));
211            if (!empty($notification) && ($notification->getVar('not_uid') == $uid) && ($notification->getVar('not_modid') == intval($del_notification_items[0]))) {
212                $notification_handler->delete($notification);
213            }
214        }
215    }
216    redirect_header('notifications.php', 2, _NOT_DELETESUCCESS);
217    break;
218default:
219    break;
220}
221
222?>
Note: See TracBrowser for help on using the repository browser.