[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/kernel/ -> privmessage.php (source)

   1  <?php
   2  // $Id: privmessage.php 763 2006-09-24 22:09:05Z 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        $Revision: 763 $ - $Date: 2006-09-24 18:09:05 -0400 (Sun, 24 Sep 2006) $

  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: 763 $ - $Date: 2006-09-24 18:09:05 -0400 (Sun, 24 Sep 2006) $

  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          if (strtolower(get_class($pm)) != 'xoopsprivmessage') {
 127              return false;
 128          }
 129          if (!$pm->isDirty()) {
 130              return true;
 131          }
 132          if (!$pm->cleanVars()) {
 133              return false;
 134          }
 135          foreach ($pm->cleanVars as $k => $v) {
 136              ${$k} = $v;
 137          }
 138          if ($pm->isNew()) {
 139              $msg_id = $this->db->genId('priv_msgs_msg_id_seq');
 140              $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);
 141          } else {
 142              $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);
 143          }
 144          $queryFunc = empty($force)?"query":"queryF";
 145          if (!$result = $this->db->{$queryFunc}($sql)) {
 146              return false;
 147          }
 148          if (empty($msg_id)) {
 149              $msg_id = $this->db->getInsertId();
 150          }
 151          $pm->assignVar('msg_id', $msg_id);
 152          return true;
 153      }
 154  
 155  /**

 156   * Delete from the database

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

 158   * @return     bool

 159   **/
 160      function delete(&$pm)
 161      {
 162          if (strtolower(get_class($pm)) != 'xoopsprivmessage') {
 163              return false;
 164          }
 165          if (!$result = $this->db->query(sprintf("DELETE FROM %s WHERE msg_id = %u", $this->db->prefix('priv_msgs'), $pm->getVar('msg_id')))) {
 166              return false;
 167          }
 168          return true;
 169      }
 170  
 171  /**

 172   * Load messages from the database

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

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

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

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

 207   * Count message

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

 209   * @return     int

 210   **/
 211      function getCount($criteria = null)
 212      {
 213          $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('priv_msgs');
 214          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 215              $sql .= ' '.$criteria->renderWhere();
 216          }
 217          if (!$result = $this->db->query($sql)) {
 218              return 0;
 219          }
 220          list($count) = $this->db->fetchRow($result);
 221          return $count;
 222      }
 223  
 224  /**

 225   * Mark a message as read

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

 227   * @return     bool

 228   **/
 229      function setRead(&$pm)
 230      {
 231          if (strtolower(get_class($pm)) != 'xoopsprivmessage') {
 232              return false;
 233          }
 234          $sql = sprintf("UPDATE %s SET read_msg = 1 WHERE msg_id = %u", $this->db->prefix('priv_msgs'), $pm->getVar('msg_id'));
 235          if (!$this->db->queryF($sql)) {
 236              return false;
 237          }
 238          return true;
 239      }
 240  }
 241  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics