[ Index ]

PHP Cross Reference of Xoops v2.3.1

[Global whois Lookup]    [Ranchi, Jharkhand, India website]     [Hindi Magazine]     [Desi Community website in tristate area]    [B 4 Bollywood]    [Internet nation of India]

title

Body

[close]

/kernel/ -> privmessage.php (source)

   1  <?php
   2  // $Id: privmessage.php 1370 2008-03-04 03:09:58Z phppp $

   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  // Author: Kazumi Ono (AKA onokazu)                                          //

  28  // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //

  29  // Project: The XOOPS Project                                                //

  30  // ------------------------------------------------------------------------- //

  31  if (!defined('XOOPS_ROOT_PATH')) {
  32      exit();
  33  }
  34  /**

  35   * {description}

  36   *

  37   * @package        kernel

  38   *

  39   * @author        Kazumi Ono    <onokazu@xoops.org>

  40   * @copyright    copyright (c) 2000-2003 The XOOPS Project (http://www.xoops.org)

  41   *

  42   * @version        $Id: privmessage.php 1370 2008-03-04 03:09:58Z phppp $

  43   */
  44  class XoopsPrivmessage extends XoopsObject
  45  {
  46  
  47  /**

  48   * constructor

  49   **/
  50      function XoopsPrivmessage()
  51      {
  52          $this->XoopsObject();
  53          $this->initVar('msg_id', XOBJ_DTYPE_INT, null, false);
  54          $this->initVar('msg_image', XOBJ_DTYPE_OTHER, 'icon1.gif', false, 100);
  55          $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, true, 255);
  56          $this->initVar('from_userid', XOBJ_DTYPE_INT, null, true);
  57          $this->initVar('to_userid', XOBJ_DTYPE_INT, null, true);
  58          $this->initVar('msg_time', XOBJ_DTYPE_OTHER, null, false);
  59          $this->initVar('msg_text', XOBJ_DTYPE_TXTAREA, null, true);
  60          $this->initVar('read_msg', XOBJ_DTYPE_INT, 0, false);
  61      }
  62  }
  63  
  64  /**

  65   * XOOPS private message handler class.

  66   *

  67   * This class is responsible for providing data access mechanisms to the data source

  68   * of XOOPS private message class objects.

  69   *

  70   * @package        kernel

  71   *

  72   * @author        Kazumi Ono    <onokazu@xoops.org>

  73   * @copyright    copyright (c) 2000-2003 The XOOPS Project (http://www.xoops.org)

  74   *

  75   * @version        $Revision: 1217 $ - $Date: 2008-01-02 01:04:41 +0800 (星期三, 02 一月 2008) $

  76   */
  77  class XoopsPrivmessageHandler extends XoopsObjectHandler
  78  {
  79  
  80  /**

  81   * Create a new {@link XoopsPrivmessage} object

  82   * @param     bool     $isNew     Flag as "new"?

  83   * @return     object

  84   **/
  85      function &create($isNew = true)
  86      {
  87          $pm = new XoopsPrivmessage();
  88          if ($isNew) {
  89              $pm->setNew();
  90          }
  91          return $pm;
  92      }
  93  
  94  /**

  95   * Load a {@link XoopsPrivmessage} object

  96   * @param     int     $id ID of the message

  97   * @return     object

  98   **/
  99      function &get($id)
 100      {
 101          $pm = false;
 102          $id = intval($id);
 103          if ($id > 0) {
 104              $sql = 'SELECT * FROM '.$this->db->prefix('priv_msgs').' WHERE msg_id='.$id;
 105              if (!$result = $this->db->query($sql)) {
 106                  return $pm;
 107              }
 108              $numrows = $this->db->getRowsNum($result);
 109              if ($numrows == 1) {
 110                  $pm = new XoopsPrivmessage();
 111                  $pm->assignVars($this->db->fetchArray($result));
 112              }
 113          }
 114          return $pm;
 115      }
 116  
 117  /**

 118   * Insert a message in the database

 119   *

 120   * @param     object     $pm        {@link XoopsPrivmessage} object

 121   * @param     bool     $force     flag to force the query execution skip request method check, which might be required in some situations

 122   * @return     bool

 123   **/
 124      function insert(&$pm, $force = false)
 125      {
 126          /**

 127          * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5

 128          */
 129          if (!is_a($pm, 'xoopsprivmessage')) {
 130              return false;
 131          }
 132  
 133          if (!$pm->isDirty()) {
 134              return true;
 135          }
 136          if (!$pm->cleanVars()) {
 137              return false;
 138          }
 139          foreach ($pm->cleanVars as $k => $v) {
 140              ${$k} = $v;
 141          }
 142          if ($pm->isNew()) {
 143              $msg_id = $this->db->genId('priv_msgs_msg_id_seq');
 144              $sql = sprintf("INSERT INTO %s (msg_id, msg_image, subject, from_userid, to_userid, msg_time, msg_text, read_msg) VALUES (%u, %s, %s, %u, %u, %u, %s, %u)", $this->db->prefix('priv_msgs'), $msg_id, $this->db->quoteString($msg_image), $this->db->quoteString($subject), $from_userid, $to_userid, time(), $this->db->quoteString($msg_text), 0);
 145          } else {
 146              $sql = sprintf("UPDATE %s SET msg_image = %s, subject = %s, from_userid = %u, to_userid = %u, msg_text = %s, read_msg = %u WHERE msg_id = %u", $this->db->prefix('priv_msgs'), $this->db->quoteString($msg_image), $this->db->quoteString($subject), $from_userid, $to_userid, $this->db->quoteString($msg_text), $read_msg, $msg_id);
 147          }
 148          $queryFunc = empty($force)?"query":"queryF";
 149          if (!$result = $this->db->{$queryFunc}($sql)) {
 150              return false;
 151          }
 152          if (empty($msg_id)) {
 153              $msg_id = $this->db->getInsertId();
 154          }
 155          $pm->assignVar('msg_id', $msg_id);
 156          return true;
 157      }
 158  
 159  /**

 160   * Delete from the database

 161   * @param     object     $pm     {@link XoopsPrivmessage} object

 162   * @return     bool

 163   **/
 164      function delete(&$pm)
 165      {
 166          /**

 167          * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5

 168          */
 169          if (!is_a($pm, 'xoopsprivmessage')) {
 170              return false;
 171          }
 172  
 173          if (!$result = $this->db->query(sprintf("DELETE FROM %s WHERE msg_id = %u", $this->db->prefix('priv_msgs'), $pm->getVar('msg_id')))) {
 174              return false;
 175          }
 176          return true;
 177      }
 178  
 179  /**

 180   * Load messages from the database

 181   * @param     object     $criteria     {@link CriteriaElement} object

 182   * @param     bool     $id_as_key     use ID as key into the array?

 183   * @return     array    Array of {@link XoopsPrivmessage} objects

 184   **/
 185      function getObjects($criteria = null, $id_as_key = false)
 186      {
 187          $ret = array();
 188          $limit = $start = 0;
 189          $sql = 'SELECT * FROM '.$this->db->prefix('priv_msgs');
 190          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 191              $sql .= ' '.$criteria->renderWhere();
 192              $sort = !in_array($criteria->getSort(), array('msg_id', 'msg_time', 'from_userid')) ? 'msg_id' : $criteria->getSort();
 193              $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder();
 194              $limit = $criteria->getLimit();
 195              $start = $criteria->getStart();
 196          }
 197          $result = $this->db->query($sql, $limit, $start);
 198          if (!$result) {
 199              return $ret;
 200          }
 201          while ($myrow = $this->db->fetchArray($result)) {
 202              $pm = new XoopsPrivmessage();
 203              $pm->assignVars($myrow);
 204              if (!$id_as_key) {
 205                  $ret[] =& $pm;
 206              } else {
 207                  $ret[$myrow['msg_id']] =& $pm;
 208              }
 209              unset($pm);
 210          }
 211          return $ret;
 212      }
 213  
 214  /**

 215   * Count message

 216   * @param     object     $criteria = null     {@link CriteriaElement} object

 217   * @return     int

 218   **/
 219      function getCount($criteria = null)
 220      {
 221          $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('priv_msgs');
 222          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 223              $sql .= ' '.$criteria->renderWhere();
 224          }
 225          if (!$result = $this->db->query($sql)) {
 226              return 0;
 227          }
 228          list($count) = $this->db->fetchRow($result);
 229          return $count;
 230      }
 231  
 232  /**

 233   * Mark a message as read

 234   * @param     object     $pm     {@link XoopsPrivmessage} object

 235   * @return     bool

 236   **/
 237      function setRead(&$pm)
 238      {
 239          /**

 240          * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5

 241          */
 242          if (!is_a($pm, 'xoopsprivmessage')) {
 243              return false;
 244          }
 245  
 246          $sql = sprintf("UPDATE %s SET read_msg = 1 WHERE msg_id = %u", $this->db->prefix('priv_msgs'), $pm->getVar('msg_id'));
 247          if (!$this->db->queryF($sql)) {
 248              return false;
 249          }
 250          return true;
 251      }
 252  }
 253  ?>


[ Xoops]     [PhpNuke]     [PostNuke]     [Joomla]    [Drupal]    [E107]    [NucleusCms]
[Php-Fusion]     [PhpBB]     [WordPress]     [Typo3]
Generated: Mon Oct 27 11:51:45 2008
Open Source related documentation for developers.