home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / notifications.php < prev    next >
Encoding:
PHP Script  |  2005-11-03  |  9.5 KB  |  217 lines

  1. <?php
  2. // $Id: notifications.php 2 2005-11-02 18:23:29Z skalpa $
  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';
  29. include 'mainfile.php';
  30.  
  31. if (empty($xoopsUser)) {
  32.     redirect_header('index.php', 3, _NOT_NOACCESS);
  33.     exit();
  34. }
  35.  
  36. $uid = $xoopsUser->getVar('uid');
  37.  
  38. $op = 'list';
  39.  
  40. if (isset($_POST['op'])) {
  41.     $op = trim($_POST['op']);
  42. } elseif (isset($_GET['op'])) {
  43.     $op = trim($_GET['op']);
  44. }
  45. if (isset($_POST['delete'])) {
  46.     $op = 'delete';
  47. } elseif (isset($_GET['delete'])) {
  48.     $op = 'delete';
  49. }
  50. if (isset($_POST['delete_ok'])) {
  51.     $op = 'delete_ok';
  52. }
  53. if (isset($_POST['delete_cancel'])) {
  54.     $op = 'cancel';
  55. }
  56.  
  57. switch ($op) {
  58.  
  59. case 'cancel':
  60.  
  61.     // FIXME: does this always go back to correct location??
  62.     redirect_header ('index.php');
  63.     break;
  64.  
  65. case '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.     $xoopsTpl->assign ('notification_token', $GLOBALS['xoopsSecurity']->createToken());
  156.     include XOOPS_ROOT_PATH.'/footer.php';
  157.  
  158. // TODO: another display mode... instead of one notification per line,
  159. // show one line per item_id, with checkboxes for the available options...
  160. // and an update button to change them...  And still have the delete box
  161. // to delete all notification for that item
  162.  
  163. // How about one line per ID, showing category, name, id, and list of
  164. // events...
  165.  
  166. // TODO: it would also be useful to provide links to other available
  167. // options so we can say switch from new_message to 'bookmark' if we
  168. // are receiving too many emails.  OR, if we click on 'change options'
  169. // we get a form for that page...
  170.  
  171. // TODO: option to specify one-time??? or other modes??
  172.  
  173.     break;
  174.  
  175. //case 'delete':
  176. case 'delete_ok':
  177.  
  178.     if (empty($_POST['del_not'])) {
  179.         redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
  180.     }
  181.     include XOOPS_ROOT_PATH.'/header.php';
  182.     $hidden_vars = array('uid'=>$uid, 'delete_ok'=>1, 'del_not'=>$_POST['del_not']);
  183.     print '<h4>'._NOT_DELETINGNOTIFICATIONS.'</h4>';
  184.     xoops_confirm($hidden_vars, xoops_getenv('PHP_SELF'), _NOT_RUSUREDEL);
  185.     include XOOPS_ROOT_PATH.'/footer.php';
  186.  
  187. // FIXME: There is a problem here... in xoops_confirm it treats arrays as
  188. // optional radio arguments on the confirmation page... change this or
  189. // write new function...
  190.  
  191.     break;
  192.  
  193. //case 'delete_ok':
  194. case 'delete':
  195.     if (!$GLOBALS['xoopsSecurity']->check()) {
  196.         redirect_header('notifications.php', 2, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
  197.     }
  198.     if (empty($_POST['del_not'])) {
  199.         redirect_header('notifications.php', 2, _NOT_NOTHINGTODELETE);
  200.     }
  201.     $notification_handler =& xoops_gethandler('notification');
  202.     foreach ($_POST['del_not'] as $n_array) {
  203.         foreach ($n_array as $n) {
  204.             $notification =& $notification_handler->get($n);
  205.             if ($notification->getVar('not_uid') == $uid) {
  206.                 $notification_handler->delete($notification);
  207.             }
  208.         }
  209.     }
  210.     redirect_header('notifications.php', 2, _NOT_DELETESUCCESS);
  211.     break;
  212. default:
  213.     break;
  214. }
  215.  
  216. ?>
  217.