home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / kernel / user.php < prev   
Encoding:
PHP Script  |  2007-12-05  |  22.6 KB  |  678 lines

  1. <?php
  2. // $Id: user.php 1149 2007-12-04 15:08:23Z 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.  * Class for users
  36.  * @author Kazumi Ono <onokazu@xoops.org>
  37.  * @copyright copyright (c) 2000-2003 XOOPS.org
  38.  * @package kernel
  39.  */
  40. class XoopsUser extends XoopsObject
  41. {
  42.  
  43.     /**
  44.      * Array of groups that user belongs to
  45.      * @var array
  46.      * @access private
  47.      */
  48.     var $_groups = array();
  49.     /**
  50.      * @var bool is the user admin?
  51.      * @access private
  52.      */
  53.     var $_isAdmin = null;
  54.     /**
  55.      * @var string user's rank
  56.      * @access private
  57.      */
  58.     var $_rank = null;
  59.     /**
  60.      * @var bool is the user online?
  61.      * @access private
  62.      */
  63.     var $_isOnline = null;
  64.  
  65.     /**
  66.      * constructor
  67.      * @param array $id Array of key-value-pairs to be assigned to the user. (for backward compatibility only)
  68.      * @param int $id ID of the user to be loaded from the database.
  69.      */
  70.     function XoopsUser($id = null)
  71.     {
  72.         $this->initVar('uid', XOBJ_DTYPE_INT, null, false);
  73.         $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 60);
  74.         $this->initVar('uname', XOBJ_DTYPE_TXTBOX, null, true, 25);
  75.         $this->initVar('email', XOBJ_DTYPE_TXTBOX, null, true, 60);
  76.         $this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false, 100);
  77.         $this->initVar('user_avatar', XOBJ_DTYPE_TXTBOX, null, false, 30);
  78.         $this->initVar('user_regdate', XOBJ_DTYPE_INT, null, false);
  79.         $this->initVar('user_icq', XOBJ_DTYPE_TXTBOX, null, false, 15);
  80.         $this->initVar('user_from', XOBJ_DTYPE_TXTBOX, null, false, 100);
  81.         $this->initVar('user_sig', XOBJ_DTYPE_TXTAREA, null, false, null);
  82.         $this->initVar('user_viewemail', XOBJ_DTYPE_INT, 0, false);
  83.         $this->initVar('actkey', XOBJ_DTYPE_OTHER, null, false);
  84.         $this->initVar('user_aim', XOBJ_DTYPE_TXTBOX, null, false, 18);
  85.         $this->initVar('user_yim', XOBJ_DTYPE_TXTBOX, null, false, 25);
  86.         $this->initVar('user_msnm', XOBJ_DTYPE_TXTBOX, null, false, 100);
  87.         $this->initVar('pass', XOBJ_DTYPE_TXTBOX, null, false, 32);
  88.         $this->initVar('posts', XOBJ_DTYPE_INT, null, false);
  89.         $this->initVar('attachsig', XOBJ_DTYPE_INT, 0, false);
  90.         $this->initVar('rank', XOBJ_DTYPE_INT, 0, false);
  91.         $this->initVar('level', XOBJ_DTYPE_INT, 0, false);
  92.         $this->initVar('theme', XOBJ_DTYPE_OTHER, null, false);
  93.         $this->initVar('timezone_offset', XOBJ_DTYPE_OTHER, null, false);
  94.         $this->initVar('last_login', XOBJ_DTYPE_INT, 0, false);
  95.         $this->initVar('umode', XOBJ_DTYPE_OTHER, null, false);
  96.         $this->initVar('uorder', XOBJ_DTYPE_INT, 1, false);
  97.         // RMV-NOTIFY
  98.         $this->initVar('notify_method', XOBJ_DTYPE_OTHER, 1, false);
  99.         $this->initVar('notify_mode', XOBJ_DTYPE_OTHER, 0, false);
  100.         $this->initVar('user_occ', XOBJ_DTYPE_TXTBOX, null, false, 100);
  101.         $this->initVar('bio', XOBJ_DTYPE_TXTAREA, null, false, null);
  102.         $this->initVar('user_intrest', XOBJ_DTYPE_TXTBOX, null, false, 150);
  103.         $this->initVar('user_mailok', XOBJ_DTYPE_INT, 1, false);
  104.  
  105.         // for backward compatibility
  106.         if (isset($id)) {
  107.             if (is_array($id)) {
  108.                 $this->assignVars($id);
  109.             } else {
  110.                 $member_handler =& xoops_gethandler('member');
  111.                 $user =& $member_handler->getUser($id);
  112.                 foreach ($user->vars as $k => $v) {
  113.                     $this->assignVar($k, $v['value']);
  114.                 }
  115.             }
  116.         }
  117.     }
  118.  
  119.     /**
  120.      * check if the user is a guest user
  121.      *
  122.      * @return bool returns false
  123.      *
  124.      */
  125.     function isGuest()
  126.     {
  127.         return false;
  128.     }
  129.  
  130.  
  131.     /**
  132.      * Updated by Catzwolf 11 Jan 2004
  133.      * find the username for a given ID
  134.      *
  135.      * @param int $userid ID of the user to find
  136.      * @param int $usereal switch for usename or realname
  137.      * @return string name of the user. name for "anonymous" if not found.
  138.      */
  139.     function getUnameFromId( $userid, $usereal = 0 )
  140.     {
  141.         $userid = intval($userid);
  142.         $usereal = intval($usereal);
  143.         if ($userid > 0) {
  144.             $member_handler =& xoops_gethandler('member');
  145.             $user =& $member_handler->getUser($userid);
  146.             if (is_object($user)) {
  147.                 $ts =& MyTextSanitizer::getInstance();
  148.                 if ( $usereal ) {
  149.                     $name = $user->getVar('name');
  150.                      if($name != '') {
  151.                          return $ts->htmlSpecialChars($name);
  152.                      } else {
  153.                          return $ts->htmlSpecialChars($user->getVar('uname'));
  154.                      }
  155.                  } else {
  156.                      return $ts->htmlSpecialChars($user->getVar('uname'));
  157.                  }
  158.             }
  159.         }
  160.         return $GLOBALS['xoopsConfig']['anonymous'];
  161.     }
  162.     /**
  163.      * increase the number of posts for the user
  164.      *
  165.      * @deprecated
  166.      */
  167.     function incrementPost(){
  168.         $member_handler =& xoops_gethandler('member');
  169.         return $member_handler->updateUserByField($this, 'posts', $this->getVar('posts') + 1);
  170.     }
  171.     /**
  172.      * set the groups for the user
  173.      *
  174.      * @param array $groupsArr Array of groups that user belongs to
  175.      */
  176.     function setGroups($groupsArr)
  177.     {
  178.         if (is_array($groupsArr)) {
  179.             $this->_groups =& $groupsArr;
  180.         }
  181.     }
  182.     /**
  183.      * get the groups that the user belongs to
  184.      *
  185.      * @return array array of groups
  186.      */
  187.     function &getGroups()
  188.     {
  189.         if (empty($this->_groups)) {
  190.             $member_handler =& xoops_gethandler('member');
  191.             $this->_groups =& $member_handler->getGroupsByUser($this->getVar('uid'));
  192.         }
  193.         return $this->_groups;
  194.     }
  195.     /**
  196.      * alias for {@link getGroups()}
  197.      * @see getGroups()
  198.      * @return array array of groups
  199.      * @deprecated
  200.      */
  201.     function &groups()
  202.     {
  203.         $groups =& $this->getGroups();
  204.         return $groups;
  205.     }
  206.     /**
  207.      * Is the user admin ?
  208.      *
  209.      * This method will return true if this user has admin rights for the specified module.<br />
  210.      * - If you don't specify any module ID, the current module will be checked.<br />
  211.      * - If you set the module_id to -1, it will return true if the user has admin rights for at least one module
  212.      *
  213.      * @param int $module_id check if user is admin of this module
  214.      * @return bool is the user admin of that module?
  215.      */
  216.     function isAdmin( $module_id = null ) {
  217.         if ( is_null( $module_id ) ) {
  218.             $module_id = isset($GLOBALS['xoopsModule']) ? $GLOBALS['xoopsModule']->getVar( 'mid', 'n' ) : 1;
  219.         } elseif ( intval($module_id) < 1 ) {
  220.             $module_id = 0;
  221.         }
  222.         $moduleperm_handler =& xoops_gethandler('groupperm');
  223.         return $moduleperm_handler->checkRight('module_admin', $module_id, $this->getGroups());
  224.     }
  225.     /**
  226.      * get the user's rank
  227.      * @return array array of rank ID and title
  228.      */
  229.     function rank()
  230.     {
  231.         if (!isset($this->_rank)) {
  232.             $this->_rank = xoops_getrank($this->getVar('rank'), $this->getVar('posts'));
  233.         }
  234.         return $this->_rank;
  235.     }
  236.     /**
  237.      * is the user activated?
  238.      * @return bool
  239.      */
  240.     function isActive()
  241.     {
  242.         if ($this->getVar('level') == 0) {
  243.             return false;
  244.         }
  245.         return true;
  246.     }
  247.     /**
  248.      * is the user currently logged in?
  249.      * @return bool
  250.      */
  251.     function isOnline()
  252.     {
  253.         if (!isset($this->_isOnline)) {
  254.             $onlinehandler =& xoops_gethandler('online');
  255.             $this->_isOnline = ($onlinehandler->getCount(new Criteria('online_uid', $this->getVar('uid'))) > 0) ? true : false;
  256.         }
  257.         return $this->_isOnline;
  258.     }
  259.     /**#@+
  260.      * specialized wrapper for {@link XoopsObject::getVar()}
  261.      *
  262.      * kept for compatibility reasons.
  263.      *
  264.       * @see XoopsObject::getVar()
  265.      * @deprecated
  266.      */
  267.     /**
  268.      * get the users UID
  269.      * @return int
  270.      */
  271.     function uid()
  272.     {
  273.         return $this->getVar("uid");
  274.     }
  275.  
  276.     /**
  277.      * get the users name
  278.      * @param string $format format for the output, see {@link XoopsObject::getVar()}
  279.      * @return string
  280.      */
  281.     function name($format="S")
  282.     {
  283.         return $this->getVar("name", $format);
  284.     }
  285.  
  286.     /**
  287.      * get the user's uname
  288.      * @param string $format format for the output, see {@link XoopsObject::getVar()}
  289.      * @return string
  290.      */
  291.     function uname($format="S")
  292.     {
  293.         return $this->getVar("uname", $format);
  294.     }
  295.  
  296.     /**
  297.      * get the user's email
  298.      *
  299.      * @param string $format format for the output, see {@link XoopsObject::getVar()}
  300.      * @return string
  301.      */
  302.     function email($format="S")
  303.     {
  304.         return $this->getVar("email", $format);
  305.     }
  306.  
  307.     function url($format="S")
  308.     {
  309.         return $this->getVar("url", $format);
  310.     }
  311.  
  312.     function user_avatar($format="S")
  313.     {
  314.         return $this->getVar("user_avatar");
  315.     }
  316.  
  317.     function user_regdate()
  318.     {
  319.         return $this->getVar("user_regdate");
  320.     }
  321.  
  322.     function user_icq($format="S")
  323.     {
  324.         return $this->getVar("user_icq", $format);
  325.     }
  326.  
  327.     function user_from($format="S")
  328.     {
  329.         return $this->getVar("user_from", $format);
  330.     }
  331.     function user_sig($format="S")
  332.     {
  333.         return $this->getVar("user_sig", $format);
  334.     }
  335.  
  336.     function user_viewemail()
  337.     {
  338.         return $this->getVar("user_viewemail");
  339.     }
  340.  
  341.     function actkey()
  342.     {
  343.         return $this->getVar("actkey");
  344.     }
  345.  
  346.     function user_aim($format="S")
  347.     {
  348.         return $this->getVar("user_aim", $format);
  349.     }
  350.  
  351.     function user_yim($format="S")
  352.     {
  353.         return $this->getVar("user_yim", $format);
  354.     }
  355.  
  356.     function user_msnm($format="S")
  357.     {
  358.         return $this->getVar("user_msnm", $format);
  359.     }
  360.  
  361.     function pass()
  362.     {
  363.         return $this->getVar("pass");
  364.     }
  365.  
  366.     function posts()
  367.     {
  368.         return $this->getVar("posts");
  369.     }
  370.  
  371.     function attachsig()
  372.     {
  373.         return $this->getVar("attachsig");
  374.     }
  375.  
  376.     function level()
  377.     {
  378.         return $this->getVar("level");
  379.     }
  380.  
  381.     function theme()
  382.     {
  383.         return $this->getVar("theme");
  384.     }
  385.  
  386.     function timezone()
  387.     {
  388.         return $this->getVar("timezone_offset");
  389.     }
  390.  
  391.     function umode()
  392.     {
  393.         return $this->getVar("umode");
  394.     }
  395.  
  396.     function uorder()
  397.     {
  398.         return $this->getVar("uorder");
  399.     }
  400.  
  401.     // RMV-NOTIFY
  402.     function notify_method()
  403.     {
  404.         return $this->getVar("notify_method");
  405.     }
  406.  
  407.     function notify_mode()
  408.     {
  409.         return $this->getVar("notify_mode");
  410.     }
  411.  
  412.     function user_occ($format="S")
  413.     {
  414.         return $this->getVar("user_occ", $format);
  415.     }
  416.  
  417.     function bio($format="S")
  418.     {
  419.         return $this->getVar("bio", $format);
  420.     }
  421.  
  422.     function user_intrest($format="S")
  423.     {
  424.         return $this->getVar("user_intrest", $format);
  425.     }
  426.  
  427.     function last_login()
  428.     {
  429.         return $this->getVar("last_login");
  430.     }
  431.     /**#@-*/
  432.  
  433. }
  434.  
  435. /**
  436.  * Class that represents a guest user
  437.  * @author Kazumi Ono <onokazu@xoops.org>
  438.  * @copyright copyright (c) 2000-2003 XOOPS.org
  439.  * @package kernel
  440.  */
  441. class XoopsGuestUser extends XoopsUser
  442. {
  443.     /**
  444.      * check if the user is a guest user
  445.      *
  446.      * @return bool returns true
  447.      *
  448.      */
  449.     function isGuest()
  450.     {
  451.         return true;
  452.     }
  453. }
  454.  
  455.  
  456. /**
  457. * XOOPS user handler class.
  458. * This class is responsible for providing data access mechanisms to the data source
  459. * of XOOPS user class objects.
  460. *
  461. * @author  Kazumi Ono <onokazu@xoops.org>
  462. * @copyright copyright (c) 2000-2003 XOOPS.org
  463. * @package kernel
  464. */
  465. class XoopsUserHandler extends XoopsObjectHandler
  466. {
  467.  
  468.     /**
  469.      * create a new user
  470.      *
  471.      * @param bool $isNew flag the new objects as "new"?
  472.      * @return object XoopsUser
  473.      */
  474.     function &create($isNew = true)
  475.     {
  476.         $user = new XoopsUser();
  477.         if ($isNew) {
  478.             $user->setNew();
  479.         }
  480.         return $user;
  481.     }
  482.  
  483.     /**
  484.      * retrieve a user
  485.      *
  486.      * @param int $id UID of the user
  487.      * @return mixed reference to the {@link XoopsUser} object, FALSE if failed
  488.      */
  489.     function &get($id)
  490.     {
  491.       $id = intval($id);
  492.       $user = false;
  493.         if ($id > 0) {
  494.             $sql = 'SELECT * FROM '.$this->db->prefix('users').' WHERE uid='.$id;
  495.             if (!$result = $this->db->query($sql)) {
  496.                 return $user;
  497.             }
  498.             $numrows = $this->db->getRowsNum($result);
  499.             if ($numrows == 1) {
  500.                 $user = new XoopsUser();
  501.                 $user->assignVars($this->db->fetchArray($result));
  502.             }
  503.         }
  504.         return $user;
  505.     }
  506.  
  507.     /**
  508.      * insert a new user in the database
  509.      *
  510.      * @param object $user reference to the {@link XoopsUser} object
  511.      * @param bool $force
  512.      * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  513.      */
  514.     function insert(&$user, $force = false)
  515.     {
  516.         /**
  517.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  518.         */
  519.         if (!is_a($user, 'xoopsuser')) {
  520.             return false;
  521.         }
  522.         if (!$user->isDirty()) {
  523.             return true;
  524.         }
  525.         if (!$user->cleanVars()) {
  526.             return false;
  527.         }
  528.         foreach ($user->cleanVars as $k => $v) {
  529.             ${$k} = $v;
  530.         }
  531.         // RMV-NOTIFY
  532.         // Added two fields, notify_method, notify_mode
  533.         if ($user->isNew()) {
  534.             $uid = $this->db->genId($this->db->prefix('users').'_uid_seq');
  535.             $sql = sprintf("INSERT INTO %s (uid, uname, name, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, user_mailok) VALUES (%u, %s, %s, %s, %s, %s, %u, %s, %s, %s, %u, %s, %s, %s, %s, %s, %u, %u, %u, %u, %s, %.2f, %u, %s, %u, %u, %u, %s, %s, %s, %u)", $this->db->prefix('users'), $uid, $this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), time(), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail, $this->db->quoteString($actkey), $this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $this->db->quoteString($pass), $posts, $attachsig, $rank, $level, $this->db->quoteString($theme), $timezone_offset, 0, $this->db->quoteString($umode), $uorder, $notify_method, $notify_mode, $this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $user_mailok);
  536.         } else {
  537.             $sql = sprintf("UPDATE %s SET uname = %s, name = %s, email = %s, url = %s, user_avatar = %s, user_icq = %s, user_from = %s, user_sig = %s, user_viewemail = %u, user_aim = %s, user_yim = %s, user_msnm = %s, posts = %d,  pass = %s, attachsig = %u, rank = %u, level= %u, theme = %s, timezone_offset = %.2f, umode = %s, last_login = %u, uorder = %u, notify_method = %u, notify_mode = %u, user_occ = %s, bio = %s, user_intrest = %s, user_mailok = %u WHERE uid = %u", $this->db->prefix('users'), $this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail, $this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $posts, $this->db->quoteString($pass), $attachsig, $rank, $level, $this->db->quoteString($theme), $timezone_offset, $this->db->quoteString($umode), $last_login, $uorder, $notify_method, $notify_mode, $this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $user_mailok, $uid);
  538.         }
  539.         if (false != $force) {
  540.             $result = $this->db->queryF($sql);
  541.         } else {
  542.             $result = $this->db->query($sql);
  543.         }
  544.         if (!$result) {
  545.             return false;
  546.         }
  547.         if (empty($uid)) {
  548.             $uid = $this->db->getInsertId();
  549.         }
  550.         $user->assignVar('uid', $uid);
  551.         return true;
  552.     }
  553.  
  554.     /**
  555.      * delete a user from the database
  556.      *
  557.      * @param object $user reference to the user to delete
  558.      * @param bool $force
  559.      * @return bool FALSE if failed.
  560.      */
  561.     function delete(&$user, $force = false)
  562.     {
  563.         /**
  564.         * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
  565.         */
  566.         if (!is_a($user, 'xoopsuser')) {
  567.             return false;
  568.         }
  569.         $sql = sprintf("DELETE FROM %s WHERE uid = %u", $this->db->prefix("users"), $user->getVar('uid'));
  570.         if (false != $force) {
  571.             $result = $this->db->queryF($sql);
  572.         } else {
  573.             $result = $this->db->query($sql);
  574.         }
  575.         if (!$result) {
  576.             return false;
  577.         }
  578.         return true;
  579.     }
  580.  
  581.     /**
  582.      * retrieve users from the database
  583.      *
  584.      * @param object $criteria {@link CriteriaElement} conditions to be met
  585.      * @param bool $id_as_key use the UID as key for the array?
  586.      * @return array array of {@link XoopsUser} objects
  587.      */
  588.     function getObjects($criteria = null, $id_as_key = false)
  589.     {
  590.         $ret = array();
  591.         $limit = $start = 0;
  592.         $sql = 'SELECT * FROM '.$this->db->prefix('users');
  593.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  594.             $sql .= ' '.$criteria->renderWhere();
  595.             if ($criteria->getSort() != '') {
  596.                 $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
  597.             }
  598.             $limit = $criteria->getLimit();
  599.             $start = $criteria->getStart();
  600.         }
  601.         $result = $this->db->query($sql, $limit, $start);
  602.         if (!$result) {
  603.             return $ret;
  604.         }
  605.         while ($myrow = $this->db->fetchArray($result)) {
  606.             $user = new XoopsUser();
  607.             $user->assignVars($myrow);
  608.             if (!$id_as_key) {
  609.                 $ret[] =& $user;
  610.             } else {
  611.                 $ret[$myrow['uid']] =& $user;
  612.             }
  613.             unset($user);
  614.         }
  615.         return $ret;
  616.     }
  617.  
  618.     /**
  619.      * count users matching a condition
  620.      *
  621.      * @param object $criteria {@link CriteriaElement} to match
  622.      * @return int count of users
  623.      */
  624.     function getCount($criteria = null)
  625.     {
  626.         $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('users');
  627.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  628.             $sql .= ' '.$criteria->renderWhere();
  629.         }
  630.         $result = $this->db->query($sql);
  631.         if (!$result) {
  632.             return 0;
  633.         }
  634.         list($count) = $this->db->fetchRow($result);
  635.         return $count;
  636.     }
  637.  
  638.     /**
  639.      * delete users matching a set of conditions
  640.      *
  641.      * @param object $criteria {@link CriteriaElement}
  642.      * @return bool FALSE if deletion failed
  643.      */
  644.     function deleteAll($criteria = null)
  645.     {
  646.         $sql = 'DELETE FROM '.$this->db->prefix('users');
  647.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  648.             $sql .= ' '.$criteria->renderWhere();
  649.         }
  650.         if (!$result = $this->db->query($sql)) {
  651.             return false;
  652.         }
  653.         return true;
  654.     }
  655.  
  656.     /**
  657.      * Change a value for users with a certain criteria
  658.      *
  659.      * @param   string  $fieldname  Name of the field
  660.      * @param   string  $fieldvalue Value to write
  661.      * @param   object  $criteria   {@link CriteriaElement}
  662.      *
  663.      * @return  bool
  664.      **/
  665.     function updateAll($fieldname, $fieldvalue, $criteria = null)
  666.     {
  667.         $set_clause = is_numeric($fieldvalue) ? $fieldname.' = '.$fieldvalue : $fieldname.' = '.$this->db->quoteString($fieldvalue);
  668.         $sql = 'UPDATE '.$this->db->prefix('users').' SET '.$set_clause;
  669.         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
  670.             $sql .= ' '.$criteria->renderWhere();
  671.         }
  672.         if (!$result = $this->db->query($sql)) {
  673.             return false;
  674.         }
  675.         return true;
  676.     }
  677. }
  678. ?>