| 1 | <?php |
|---|
| 2 | // $Id: notification_update.php,v 1.3 2005/08/03 12:39:11 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 | // RMV-NOTIFY |
|---|
| 29 | |
|---|
| 30 | // This module expects the following arguments: |
|---|
| 31 | // |
|---|
| 32 | // not_submit |
|---|
| 33 | // not_redirect (to return back after update) |
|---|
| 34 | // not_mid (TODO) |
|---|
| 35 | // not_uid (TODO) |
|---|
| 36 | // not_list[1][params] = {category},{itemid},{event} |
|---|
| 37 | // not_list[1][status] = 1 if selected; 0 or missing if not selected |
|---|
| 38 | // etc... |
|---|
| 39 | |
|---|
| 40 | // TODO: can we put arguments in the not_redirect argument??? do we need |
|---|
| 41 | // to specially encode them first??? |
|---|
| 42 | |
|---|
| 43 | // TODO: allow 'GET' also so we can process 'unsubscribe' requests?? |
|---|
| 44 | |
|---|
| 45 | if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) { |
|---|
| 46 | exit(); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | include_once XOOPS_ROOT_PATH.'/include/notification_constants.php'; |
|---|
| 50 | include_once XOOPS_ROOT_PATH.'/include/notification_functions.php'; |
|---|
| 51 | include_once XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/notification.php'; |
|---|
| 52 | |
|---|
| 53 | if (!isset($_POST['not_submit'])) { |
|---|
| 54 | exit(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | // NOTE: in addition to the templates provided in the block and view |
|---|
| 58 | // modes, we can have buttons, etc. which load the arguments to be |
|---|
| 59 | // read by this script. That way a module can really customize its |
|---|
| 60 | // look as to where/how the notification options are made available. |
|---|
| 61 | |
|---|
| 62 | $update_list = $_POST['not_list']; |
|---|
| 63 | |
|---|
| 64 | $module_id = $xoopsModule->getVar('mid'); |
|---|
| 65 | $user_id = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
|---|
| 66 | |
|---|
| 67 | // For each event, update the notification depending on the status. |
|---|
| 68 | // If status=1, subscribe to the event; otherwise, unsubscribe. |
|---|
| 69 | |
|---|
| 70 | // FIXME: right now I just ignore database errors (e.g. if already |
|---|
| 71 | // subscribed)... deal with this more gracefully? |
|---|
| 72 | |
|---|
| 73 | $notification_handler =& xoops_gethandler('notification'); |
|---|
| 74 | |
|---|
| 75 | foreach ($update_list as $update_item) { |
|---|
| 76 | |
|---|
| 77 | list($category, $item_id, $event) = split (',', $update_item['params']); |
|---|
| 78 | $status = !empty($update_item['status']) ? 1 : 0; |
|---|
| 79 | |
|---|
| 80 | if (!$status) { |
|---|
| 81 | $notification_handler->unsubscribe($category, $item_id, $event, $module_id, $user_id); |
|---|
| 82 | } else { |
|---|
| 83 | $notification_handler->subscribe($category, $item_id, $event); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | // TODO: something like grey box summary of actions (like multiple comment |
|---|
| 89 | // deletion), with a button to return back... NOTE: we need some arguments |
|---|
| 90 | // to help us get back to where we were... |
|---|
| 91 | |
|---|
| 92 | // TODO: finish integration with comments... i.e. need calls to |
|---|
| 93 | // notifyUsers at appropriate places... (need to figure out where |
|---|
| 94 | // comment submit occurs and where comment approval occurs)... |
|---|
| 95 | |
|---|
| 96 | include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; |
|---|
| 97 | |
|---|
| 98 | $redirect_args = array(); |
|---|
| 99 | foreach ($update_list as $update_item) { |
|---|
| 100 | list($category,$item_id,$event) = split(',',$update_item['params']); |
|---|
| 101 | $category_info =& notificationCategoryInfo($category); |
|---|
| 102 | if (!empty($category_info['item_name'])) { |
|---|
| 103 | $redirect_args[$category_info['item_name']] = $item_id; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | // TODO: write a central function to put together args with '?' and '&' |
|---|
| 108 | // symbols... |
|---|
| 109 | $argstring = ''; |
|---|
| 110 | $first_arg = 1; |
|---|
| 111 | foreach (array_keys($redirect_args) as $arg) { |
|---|
| 112 | if ($first_arg) { |
|---|
| 113 | $argstring .= "?" . $arg . "=" . $redirect_args[$arg]; |
|---|
| 114 | $first_arg = 0; |
|---|
| 115 | } else { |
|---|
| 116 | $argstring .= "&" . $arg . "=" . $redirect_args[$arg]; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | redirect_header ($_POST['not_redirect'].$argstring, 3, _NOT_UPDATEOK); |
|---|
| 121 | exit(); |
|---|
| 122 | |
|---|
| 123 | ?> |
|---|