PageRenderTime 27ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/html/include/notification_update.php

http://xoopscube-modules.googlecode.com/
PHP | 125 lines | 46 code | 25 blank | 54 comment | 8 complexity | 0ea9dd1268cd93db8c432fe2f75a4f61 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. // $Id: notification_update.php,v 1.1 2007/05/15 02:34:18 minahito 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. // RMV-NOTIFY
  28. // This module expects the following arguments:
  29. //
  30. // not_submit
  31. // not_redirect (to return back after update)
  32. // not_mid (TODO)
  33. // not_uid (TODO)
  34. // not_list[1][params] = {category},{itemid},{event}
  35. // not_list[1][status] = 1 if selected; 0 or missing if not selected
  36. // etc...
  37. // TODO: can we put arguments in the not_redirect argument??? do we need
  38. // to specially encode them first???
  39. // TODO: allow 'GET' also so we can process 'unsubscribe' requests??
  40. if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
  41. exit();
  42. }
  43. include_once XOOPS_ROOT_PATH.'/include/notification_constants.php';
  44. include_once XOOPS_ROOT_PATH.'/include/notification_functions.php';
  45. $root =& XCube_Root::getSingleton();
  46. $root->mLanguageManager->loadPageTypeMessageCatalog('notification');
  47. if (!isset($_POST['not_submit'])) {
  48. exit();
  49. }
  50. // NOTE: in addition to the templates provided in the block and view
  51. // modes, we can have buttons, etc. which load the arguments to be
  52. // read by this script. That way a module can really customize its
  53. // look as to where/how the notification options are made available.
  54. $update_list = $_POST['not_list'];
  55. $module_id = $xoopsModule->getVar('mid');
  56. $user_id = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
  57. // For each event, update the notification depending on the status.
  58. // If status=1, subscribe to the event; otherwise, unsubscribe.
  59. // FIXME: right now I just ignore database errors (e.g. if already
  60. // subscribed)... deal with this more gracefully?
  61. $notification_handler =& xoops_gethandler('notification');
  62. foreach ($update_list as $update_item) {
  63. list($category, $item_id, $event) = split (',', $update_item['params']);
  64. $status = !empty($update_item['status']) ? 1 : 0;
  65. if (!$status) {
  66. $notification_handler->unsubscribe($category, $item_id, $event, $module_id, $user_id);
  67. } else {
  68. $notification_handler->subscribe($category, $item_id, $event);
  69. }
  70. }
  71. // TODO: something like grey box summary of actions (like multiple comment
  72. // deletion), with a button to return back... NOTE: we need some arguments
  73. // to help us get back to where we were...
  74. // TODO: finish integration with comments... i.e. need calls to
  75. // notifyUsers at appropriate places... (need to figure out where
  76. // comment submit occurs and where comment approval occurs)...
  77. include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
  78. $redirect_args = array();
  79. foreach ($update_list as $update_item) {
  80. list($category,$item_id,$event) = split(',',$update_item['params']);
  81. $category_info =& notificationCategoryInfo($category);
  82. if (!empty($category_info['item_name'])) {
  83. $redirect_args[$category_info['item_name']] = $item_id;
  84. }
  85. }
  86. // TODO: write a central function to put together args with '?' and '&amp;'
  87. // symbols...
  88. $argstring = '';
  89. $first_arg = 1;
  90. foreach (array_keys($redirect_args) as $arg) {
  91. if ($first_arg) {
  92. $argstring .= "?" . $arg . "=" . $redirect_args[$arg];
  93. $first_arg = 0;
  94. } else {
  95. $argstring .= "&amp;" . $arg . "=" . $redirect_args[$arg];
  96. }
  97. }
  98. redirect_header ($_POST['not_redirect'].$argstring, 3, _NOT_UPDATEOK);
  99. exit();
  100. ?>