[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  /**
   3  * @version $Id: admin.messages.php 300 2005-10-02 05:46:21Z Levis $
   4  * @package Joomla
   5  * @subpackage Messages
   6  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   7  * @license http://www.gnu.org/copyleft/gpl.html 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( '_VALID_MOS' ) or die( 'Restricted access' );
  17  
  18  require_once( $mainframe->getPath( 'admin_html' ) );
  19  require_once( $mainframe->getPath( 'class' ) );
  20  
  21  $cid = josGetArrayInts( 'cid' );
  22  
  23  switch ($task) {
  24      case 'view':
  25          viewMessage( $cid[0], $option );
  26          break;
  27  
  28      case 'new':
  29          newMessage( $option, NULL, NULL );
  30          break;
  31  
  32      case 'reply':
  33          newMessage( $option );
  34          break;
  35  
  36      case 'save':
  37          saveMessage( $option );
  38          break;
  39  
  40      case 'remove':
  41          removeMessage( $cid, $option );
  42          break;
  43  
  44      case 'config':
  45          editConfig( $option );
  46          break;
  47  
  48      case 'saveconfig':
  49          saveConfig( $option );
  50          break;
  51  
  52      default:
  53          showMessages( $option );
  54          break;
  55  }
  56  
  57  function editConfig( $option ) {
  58      global $database, $my;
  59  
  60      $query = "SELECT cfg_name, cfg_value"
  61      . "\n FROM #__messages_cfg"
  62      . "\n WHERE user_id = " . (int) $my->id
  63      ;
  64      $database->setQuery( $query );
  65      $data = $database->loadObjectList( 'cfg_name' );
  66  
  67      // initialize values if they do not exist
  68      if (!isset($data['lock']->cfg_value)) {
  69          $data['lock']->cfg_value         = 0;
  70      }
  71      if (!isset($data['mail_on_new']->cfg_value)) {
  72          $data['mail_on_new']->cfg_value = 0;
  73      }
  74      if (!isset($data['auto_purge']->cfg_value)) {
  75          $data['auto_purge']->cfg_value     = 7;
  76      }
  77      
  78      $vars                     = array();
  79      $vars['lock']             = mosHTML::yesnoSelectList( "vars[lock]", 'class="inputbox" size="1"', $data['lock']->cfg_value );
  80      $vars['mail_on_new']     = mosHTML::yesnoSelectList( "vars[mail_on_new]", 'class="inputbox" size="1"', $data['mail_on_new']->cfg_value );
  81      $vars['auto_purge']     = (int) $data['auto_purge']->cfg_value;
  82  
  83      HTML_messages::editConfig( $vars, $option );
  84  
  85  }
  86  
  87  function saveConfig( $option ) {
  88      global $database, $my;
  89  
  90      $query = "DELETE FROM #__messages_cfg"
  91      . "\n WHERE user_id = " . (int) $my->id
  92      ;
  93      $database->setQuery( $query );
  94      $database->query();
  95  
  96      $vars = mosGetParam( $_POST, 'vars', array() );
  97      foreach ($vars as $k=>$v) {
  98          if (get_magic_quotes_gpc()) {
  99              $k = stripslashes( $k );
 100              $v = stripslashes( $v );
 101          }
 102          $query = "INSERT INTO #__messages_cfg"
 103          . "\n ( user_id, cfg_name, cfg_value )"
 104          . "\n VALUES ( " . (int) $my->id . ", " . $database->Quote( $k ) . ", " . $database->Quote( $v ) . " )"
 105          ;
 106          $database->setQuery( $query );
 107          $database->query();
 108      }
 109      mosRedirect( "index2.php?option=$option" );
 110  }
 111  
 112  function newMessage( $option ) {
 113      global $database, $acl;
 114      
 115      $user         = intval( mosGetParam( $_REQUEST, 'userid', 0 ) );
 116      $subject     = stripslashes( strval( mosGetParam( $_REQUEST, 'subject', '' ) ) );
 117      
 118      // get available backend user groups
 119      $gid     = $acl->get_group_id( 'Public Backend', 'ARO' );
 120      $gids     = $acl->get_group_children( $gid, 'ARO', 'RECURSE' );
 121  
 122      // get list of usernames
 123      $recipients = array( mosHTML::makeOption( '0', '- Select User -' ) );
 124  
 125      mosArrayToInts( $gids );
 126      $gids = 'gid=' . implode( ' OR gid=', $gids );
 127  
 128      $query = "SELECT id AS value, name AS text FROM #__users"
 129      . "\n WHERE ( $gids )"
 130      . "\n ORDER BY name"
 131      ;
 132      $database->setQuery( $query );
 133      $recipients = array_merge( $recipients, $database->loadObjectList() );
 134  
 135      $recipientslist = mosHTML::selectList( $recipients, 'user_id_to', 'class="inputbox" size="1"', 'value', 'text', $user );
 136          
 137      HTML_messages::newMessage($option, $recipientslist, $subject );
 138  }
 139  
 140  function saveMessage( $option ) {
 141      global $database, $mainframe, $my;
 142  
 143      $row = new mosMessage( $database );
 144      if (!$row->bind( $_POST )) {
 145          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 146          exit();
 147      }
 148      
 149       if (!$row->check()) {
 150          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 151          exit();
 152      }
 153  
 154      if (!$row->send()) {
 155          mosRedirect( 'index2.php?option=com_messages&mosmsg=' . $row->getError() );
 156      }
 157      mosRedirect( 'index2.php?option=com_messages' );
 158  }
 159  
 160  function showMessages( $option ) {
 161      global $database, $mainframe, $my, $mosConfig_list_limit;
 162  
 163      $limit         = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
 164      $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
 165      $search     = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
 166      if (get_magic_quotes_gpc()) {
 167          $search            = stripslashes( $search );
 168      }
 169  
 170      $wheres = array();
 171      $wheres[] = " a.user_id_to = " . (int) $my->id;
 172  
 173      if (isset($search) && $search!= "") {
 174          $searchEscaped = $database->getEscaped( trim( strtolower( $search ) ) );
 175          $wheres[] = "( u.username LIKE '%$searchEscaped%' OR email LIKE '%$searchEscaped%' OR u.name LIKE '%$searchEscaped%' )";
 176      }
 177  
 178      $query = "SELECT COUNT(*)"
 179      . "\n FROM #__messages AS a"
 180      . "\n INNER JOIN #__users AS u ON u.id = a.user_id_from"
 181      . ( $wheres ? " WHERE " . implode( " AND ", $wheres ) : '' )
 182      ;
 183      $database->setQuery( $query );
 184      $total = $database->loadResult();
 185  
 186      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 187      $pageNav = new mosPageNav( $total, $limitstart, $limit  );
 188  
 189      $query = "SELECT a.*, u.name AS user_from"
 190      . "\n FROM #__messages AS a"
 191      . "\n INNER JOIN #__users AS u ON u.id = a.user_id_from"
 192      . ($wheres ? "\n WHERE " . implode( " AND ", $wheres ) : "" )
 193      . "\n ORDER BY date_time DESC"
 194      ;
 195      $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 196  
 197      $rows = $database->loadObjectList();
 198      if ($database->getErrorNum()) {
 199          echo $database->stderr();
 200          return false;
 201      }
 202  
 203      HTML_messages::showMessages( $rows, $pageNav, $search, $option );
 204  }
 205  
 206  function viewMessage( $uid='0', $option ) {
 207      global $database, $my, $acl;
 208  
 209      $row = null;
 210      $query = "SELECT a.*, u.name AS user_from"
 211      . "\n FROM #__messages AS a"
 212      . "\n INNER JOIN #__users AS u ON u.id = a.user_id_from"
 213      . "\n WHERE a.message_id = " . (int) $uid
 214      . "\n ORDER BY date_time DESC"
 215      ;
 216      $database->setQuery( $query );
 217      $database->loadObject( $row );
 218  
 219      $query = "UPDATE #__messages"
 220      . "\n SET state = 1"
 221      . "\n WHERE message_id = " . (int) $uid
 222      ;
 223      $database->setQuery( $query );
 224      $database->query();
 225  
 226      HTML_messages::viewMessage( $row, $option );
 227  }
 228  
 229  function removeMessage( $cid, $option ) {
 230      global $database;
 231  
 232      if (!is_array( $cid ) || count( $cid ) < 1) {
 233          echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>\n";
 234          exit;
 235      }
 236      if (count( $cid )) {
 237          mosArrayToInts( $cid );
 238          $cids = 'message_id=' . implode( ' OR message_id=', $cid );
 239          $query = "DELETE FROM #__messages"
 240          . "\n WHERE ( $cids )"
 241          ;
 242          $database->setQuery( $query );
 243          if (!$database->query()) {
 244              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 245          }
 246      }
 247  
 248      $limit         = intval( mosGetParam( $_REQUEST, 'limit', 10 ) );
 249      $limitstart    = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) );
 250  
 251      mosRedirect( "index2.php?option=$option&limit=$limit&limitstart=$limitstart" );
 252  }
 253  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics