[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_messages/tables/ -> message.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: message.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6   * @license        GNU/GPL, see LICENSE.php
   7   * Joomla! is free software. This version may have been modified pursuant
   8   * to the GNU General Public License, and as distributed it includes or
   9   * is derivative of works licensed under the GNU General Public License or
  10   * other free or open source software licenses.
  11   * See COPYRIGHT.php for copyright notices and details.
  12   */
  13  
  14  // Check to ensure this file is included in Joomla!
  15  defined('_JEXEC') or die( 'Restricted access' );
  16  
  17  jimport('joomla.database.table');
  18  
  19  class TableMessage extends JTable
  20  {
  21      /**
  22       * Primary Key
  23       *
  24       * @access    public
  25       * @var        int
  26       */
  27      var $message_id    = null;
  28  
  29      /**
  30       * Sender's userid
  31       *
  32       * @access    public
  33       * @var        int
  34       */
  35      var $user_id_from    = null;
  36  
  37      /**
  38       * Recipient's userid
  39       *
  40       * @access    public
  41       * @var        int
  42       */
  43      var $user_id_to        = null;
  44  
  45      /**
  46       * @access    public
  47       * @var        int
  48       */
  49      var $folder_id            = null;
  50  
  51      /**
  52       * Message creation timestamp
  53       *
  54       * @access    public
  55       * @var        datetime
  56       */
  57      var $date_time        = null;
  58  
  59      /**
  60       * Message state
  61       *
  62       * @access    public
  63       * @var        int
  64       */
  65      var $state                = null;
  66  
  67      /**
  68       * Priority level of the message
  69       *
  70       * @access    public
  71       * @var        int
  72       */
  73      var $priority            = null;
  74  
  75      /**
  76       * The message subject
  77       *
  78       * @access    public
  79       * @var        string
  80       */
  81      var $subject            = null;
  82  
  83      /**
  84       * The message body
  85       *
  86       * @access    public
  87       * @var        text
  88       */
  89      var $message            = null;
  90  
  91      /**
  92       * Constructor
  93       *
  94       * @access    protected
  95       * @param database A database connector object
  96       */
  97  	function __construct(& $db)
  98      {
  99          parent::__construct('#__messages', 'message_id', $db);
 100      }
 101  
 102      /**
 103      * Validation and filtering
 104      */
 105  	function check() {
 106          return true;
 107      }
 108  
 109      /**
 110       * Method to send a private message
 111       *
 112       * @access    public
 113       * @param    int        $fromId        Sender's userid
 114       * @param    int        $toId        Recipient's userid
 115       * @param    string    $subject    The message subject
 116       * @param    string    $message    The message body
 117       * @return    boolean    True on success
 118       * @since    1.5
 119       */
 120  	function send($fromId = null, $toId = null, $subject = null, $message = null, $mailfrom = null, $fromname = null)
 121      {
 122          global $mainframe;
 123          $db =& JFactory::getDBO();
 124  
 125          if (is_object($this))
 126          {
 127              $fromId        = $fromId    ? $fromId    : $this->user_id_from;
 128              $toId        = $toId        ? $toId        : $this->user_id_to;
 129              $subject    = $subject    ? $subject    : $this->subject;
 130              $message    = $message    ? $message    : $this->message;
 131          }
 132  
 133          $query = 'SELECT cfg_name, cfg_value' .
 134                  ' FROM #__messages_cfg' .
 135                  ' WHERE user_id = '.(int) $toId;
 136          $db->setQuery($query);
 137  
 138          $config = $db->loadObjectList('cfg_name');
 139          $locked = @ $config['lock']->cfg_value;
 140          $domail = @ $config['mail_on_new']->cfg_value;
 141  
 142          if (!$locked)
 143          {
 144              $this->user_id_from    = $fromId;
 145              $this->user_id_to    = $toId;
 146              $this->subject        = $subject;
 147              $this->message        = $message;
 148              $date =& JFactory::getDate();
 149              $this->date_time    = $date->toMySQL();
 150  
 151              if ($this->store())
 152              {
 153                  if ($domail)
 154                  {
 155                      $query = 'SELECT name, email' .
 156                              ' FROM #__users' .
 157                              ' WHERE id = '.(int) $fromId;
 158                      $db->setQuery($query);
 159                      $fromObject = $db->loadObject();
 160                      $fromname    = $fromObject->name;
 161                      $mailfrom    = $fromObject->email;
 162                      $siteURL        = JURI::base();
 163                      $sitename         = $mainframe->getCfg( 'sitename' );
 164  
 165                      $query = 'SELECT email' .
 166                              ' FROM #__users' .
 167                              ' WHERE id = '.(int) $toId;
 168                      $db->setQuery($query);
 169                      $recipient    = $db->loadResult();
 170  
 171                      $subject    = sprintf (JText::_('A new private message has arrived'), $sitename);
 172                      $msg        = sprintf (JText::_('Please login to read your message'), $siteURL);
 173  
 174                      JUtility::sendMail($mailfrom, $fromname, $recipient, $subject, $msg);
 175                  }
 176                  return true;
 177              }
 178          }
 179          else
 180          {
 181              if (is_object($this)) {
 182                  $this->setError(JText::_('MESSAGE_FAILED'));
 183              }
 184          }
 185          return false;
 186      }
 187  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1