[ Index ]

PHP Cross Reference of Joomla 1.5.25

title

Body

[close]

/administrator/components/com_messages/ -> admin.messages.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: admin.messages.php 19343 2010-11-03 18:12:02Z ian $
   4  * @package        Joomla
   5  * @subpackage    Messages
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // no direct access
  16  defined( '_JEXEC' ) or die( 'Restricted access' );
  17  
  18  require_once( JApplicationHelper::getPath( 'admin_html' ) );
  19  
  20  $task    = JRequest::getCmd( 'task' );
  21  $cid    = JRequest::getVar( 'cid', array(0), '', 'array' );
  22  JArrayHelper::toInteger($cid, array(0));
  23  
  24  switch ($task)
  25  {
  26      case 'view':
  27          viewMessage( $cid[0], $option );
  28          break;
  29  
  30      case 'add':
  31          newMessage( $option, NULL, NULL );
  32          break;
  33  
  34      case 'reply':
  35          newMessage(
  36              $option,
  37              JRequest::getVar( 'userid', 0, '', 'int' ),
  38              JRequest::getString( 'subject' )
  39          );
  40          break;
  41  
  42      case 'save':
  43          saveMessage( $option );
  44          break;
  45  
  46      case 'remove':
  47          removeMessage( $cid, $option );
  48          break;
  49  
  50      case 'config':
  51          editConfig( $option );
  52          break;
  53  
  54      case 'saveconfig':
  55          saveConfig( $option );
  56          break;
  57  
  58      default:
  59          showMessages( $option );
  60          break;
  61  }
  62  
  63  function showMessages( $option )
  64  {
  65      global $mainframe;
  66  
  67      $db                    =& JFactory::getDBO();
  68      $user                 =& JFactory::getUser();
  69  
  70      $context            = 'com_messages.list';
  71      $filter_order        = $mainframe->getUserStateFromRequest( $context.'.filter_order',    'filter_order',        'a.date_time',    'cmd' );
  72      $filter_order_Dir    = $mainframe->getUserStateFromRequest( $context.'.filter_order_Dir','filter_order_Dir',    'DESC',            'word' );
  73      $filter_state        = $mainframe->getUserStateFromRequest( $context.'.filter_state',    'filter_state',        '',                'word' );
  74      $limit                = $mainframe->getUserStateFromRequest( 'global.list.limit',            'limit',            $mainframe->getCfg('list_limit'), 'int' );
  75      $limitstart            = $mainframe->getUserStateFromRequest( $context.'.limitstart',        'limitstart',        0,                'int' );
  76      $search                = $mainframe->getUserStateFromRequest( $context.'search',            'search',            '',                'string' );
  77      if (strpos($search, '"') !== false) {
  78          $search = str_replace(array('=', '<'), '', $search);
  79      }
  80      $search = JString::strtolower($search);
  81  
  82      if (!in_array($filter_order, array('a.date_time', 'a.state', 'a.subject', 'user_from'))) {
  83          $filter_order = 'a.date_time';
  84      }
  85  
  86      if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
  87          $filter_order_Dir = 'DESC';
  88      }
  89  
  90      $where = array();
  91      $where[] = ' a.user_id_to='.(int) $user->get('id');
  92  
  93      if ($search != '') {
  94          $searchEscaped = $db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
  95          $where[] = '( a.subject LIKE '.$searchEscaped.' OR a.message LIKE '.$searchEscaped.' )';
  96      }
  97      if ( $filter_state ) {
  98          if ( $filter_state == 'P' ) {
  99              $where[] = 'a.state = 1';
 100          } else if ($filter_state == 'U' ) {
 101              $where[] = 'a.state = 0';
 102          }
 103      }
 104  
 105      $where         = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
 106  
 107      $orderby     = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', a.date_time DESC';
 108  
 109      $query = 'SELECT COUNT(*)'
 110      . ' FROM #__messages AS a'
 111      . ' INNER JOIN #__users AS u ON u.id = a.user_id_from'
 112      . $where
 113      ;
 114      $db->setQuery( $query );
 115      $total = $db->loadResult();
 116  
 117      jimport('joomla.html.pagination');
 118      $pageNav = new JPagination( $total, $limitstart, $limit );
 119  
 120      $query = 'SELECT a.*, u.name AS user_from'
 121      . ' FROM #__messages AS a'
 122      . ' INNER JOIN #__users AS u ON u.id = a.user_id_from'
 123      . $where
 124      . $orderby
 125      ;
 126      $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 127      $rows = $db->loadObjectList();
 128      if ($db->getErrorNum()) {
 129          echo $db->stderr();
 130          return false;
 131      }
 132  
 133      // state filter
 134      $lists['state']    = JHTML::_('grid.state',  $filter_state, 'Read', 'Unread' );
 135  
 136      // table ordering
 137      $lists['order_Dir']    = $filter_order_Dir;
 138      $lists['order']        = $filter_order;
 139  
 140      // search filter
 141      $lists['search']= $search;
 142  
 143      HTML_messages::showMessages( $rows, $pageNav, $option, $lists );
 144  }
 145  
 146  function editConfig( $option )
 147  {
 148      $db        =& JFactory::getDBO();
 149      $user    =& JFactory::getUser();
 150  
 151      $query = 'SELECT cfg_name, cfg_value'
 152      . ' FROM #__messages_cfg'
 153      . ' WHERE user_id = '.(int) $user->get('id')
 154      ;
 155      $db->setQuery( $query );
 156      $data = $db->loadObjectList( 'cfg_name' );
 157  
 158      // initialize values if they do not exist
 159      if (!isset($data['lock']->cfg_value)) {
 160          $data['lock']->cfg_value         = 0;
 161      }
 162      if (!isset($data['mail_on_new']->cfg_value)) {
 163          $data['mail_on_new']->cfg_value = 0;
 164      }
 165      if (!isset($data['auto_purge']->cfg_value)) {
 166          $data['auto_purge']->cfg_value     = 7;
 167      }
 168  
 169      $vars                     = array();
 170      $vars['lock']             = JHTML::_('select.booleanlist',  "vars[lock]", '', $data['lock']->cfg_value, 'yes', 'no', 'varslock' );
 171      $vars['mail_on_new']     = JHTML::_('select.booleanlist',  "vars[mail_on_new]", '', $data['mail_on_new']->cfg_value, 'yes', 'no', 'varsmail_on_new' );
 172      $vars['auto_purge']     = $data['auto_purge']->cfg_value;
 173  
 174      HTML_messages::editConfig( $vars, $option );
 175  
 176  }
 177  
 178  function saveConfig( $option )
 179  {
 180      global $mainframe;
 181  
 182      // Check for request forgeries
 183      JRequest::checkToken() or jexit( 'Invalid Token' );
 184  
 185      $db        =& JFactory::getDBO();
 186      $user    =& JFactory::getUser();
 187  
 188      $query = 'DELETE FROM #__messages_cfg'
 189      . ' WHERE user_id = '.(int) $user->get('id')
 190      ;
 191      $db->setQuery( $query );
 192      $db->query();
 193  
 194      $vars = JRequest::getVar( 'vars', array(), 'post', 'array' );
 195      foreach ($vars as $k=>$v) {
 196          $v = $db->getEscaped( $v );
 197          $query = 'INSERT INTO #__messages_cfg'
 198          . ' ( user_id, cfg_name, cfg_value )'
 199          . ' VALUES ( '.(int) $user->get('id').', '.$db->Quote($k).', '.$db->Quote($v).' )'
 200          ;
 201          $db->setQuery( $query );
 202          $db->query();
 203      }
 204      $mainframe->redirect( "index.php?option=$option" );
 205  }
 206  
 207  function newMessage( $option, $user, $subject )
 208  {
 209      $db        =& JFactory::getDBO();
 210      $acl    =& JFactory::getACL();
 211  
 212      // get available backend user groups
 213      $gid     = $acl->get_group_id( 'Public Backend', 'ARO' );
 214      $gids     = $acl->get_group_children( $gid, 'ARO', 'RECURSE' );
 215      JArrayHelper::toInteger($gids, array(0));
 216      $gids     = implode( ',', $gids );
 217  
 218      // get list of usernames
 219      $recipients = array( JHTML::_('select.option',  '0', '- '. JText::_( 'Select User' ) .' -' ) );
 220      $query = 'SELECT id AS value, username AS text FROM #__users'
 221      . ' WHERE gid IN ( '.$gids.' )'
 222      . ' ORDER BY name'
 223      ;
 224      $db->setQuery( $query );
 225      $recipients = array_merge( $recipients, $db->loadObjectList() );
 226  
 227      $recipientslist =
 228          JHTML::_('select.genericlist', $recipients, 'user_id_to', 'class="inputbox" size="1"', 'value', 'text', $user);
 229      HTML_messages::newMessage($option, $recipientslist, $subject );
 230  }
 231  
 232  function saveMessage( $option )
 233  {
 234      global $mainframe;
 235  
 236      // Check for request forgeries
 237      JRequest::checkToken() or jexit( 'Invalid Token' );
 238  
 239      require_once(dirname(__FILE__).DS.'tables'.DS.'message.php');
 240  
 241      $db =& JFactory::getDBO();
 242      $row = new TableMessage( $db );
 243  
 244      if (!$row->bind(JRequest::get('post'))) {
 245          JError::raiseError(500, $row->getError() );
 246      }
 247  
 248      if (!$row->check()) {
 249          JError::raiseError(500, $row->getError() );
 250      }
 251  
 252      if (!$row->send()) {
 253          $mainframe->redirect( "index.php?option=com_messages", $row->getError() );
 254      }
 255      $mainframe->redirect( "index.php?option=com_messages" );
 256  }
 257  
 258  function viewMessage( $uid='0', $option )
 259  {
 260      $db    =& JFactory::getDBO();
 261  
 262      $query = 'SELECT a.*, u.name AS user_from'
 263      . ' FROM #__messages AS a'
 264      . ' INNER JOIN #__users AS u ON u.id = a.user_id_from'
 265      . ' WHERE a.message_id = '.(int) $uid
 266      . ' ORDER BY date_time DESC'
 267      ;
 268      $db->setQuery( $query );
 269      $row = $db->loadObject();
 270  
 271      $query = 'UPDATE #__messages'
 272      . ' SET state = 1'
 273      . ' WHERE message_id = '.(int) $uid
 274      ;
 275      $db->setQuery( $query );
 276      $db->query();
 277  
 278      HTML_messages::viewMessage( $row, $option );
 279  }
 280  
 281  function removeMessage( $cid, $option )
 282  {
 283      global $mainframe;
 284  
 285      // Check for request forgeries
 286      JRequest::checkToken() or jexit( 'Invalid Token' );
 287  
 288      $db =& JFactory::getDBO();
 289  
 290      JArrayHelper::toInteger($cid);
 291  
 292      if (count( $cid ) < 1) {
 293          JError::raiseError(500, JText::_( 'Select an item to delete' ) );
 294      }
 295  
 296      if (count( $cid ))
 297      {
 298          $cids = implode( ',', $cid );
 299          $query = 'DELETE FROM #__messages'
 300          . ' WHERE message_id IN ( '. $cids .' )'
 301          ;
 302          $db->setQuery( $query );
 303          if (!$db->query()) {
 304              echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
 305          }
 306      }
 307  
 308      $limit         = JRequest::getVar( 'limit', 10, '', 'int' );
 309      $limitstart    = JRequest::getVar( 'limitstart', 0, '', 'int' );
 310  
 311      $mainframe->redirect( 'index.php?option='.$option.'&limit='.$limit.'&limitstart='.$limitstart );
 312  }


Generated: Mon Nov 14 16:47:20 2011 Cross-referenced by PHPXref 0.7.1