Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/database/table/user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3. @version        $Id: user.php 6529 2007-02-08 06:57:00Z pasamio $
  4. @package        Joomla.Framework
  5. @subpackage    Table
  6. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. @license        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. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Users table
  20.  *
  21.  * @package     Joomla.Framework
  22.  * @subpackage        Table
  23.  * @since    1.0
  24.  */
  25. class JTableUser extends JTable
  26. {
  27.     /**
  28.      * Unique id
  29.      *
  30.      * @var int 
  31.      */
  32.     var $id                = null;
  33.  
  34.     /**
  35.      * The users real name (or nickname)
  36.      *
  37.      * @var string 
  38.      */
  39.     var $name            = null;
  40.  
  41.     /**
  42.      * The login name
  43.      *
  44.      * @var string 
  45.      */
  46.     var $username        = null;
  47.  
  48.     /**
  49.      * The email
  50.      *
  51.      * @var string 
  52.      */
  53.     var $email            = null;
  54.  
  55.     /**
  56.      * MD5 encrypted password
  57.      *
  58.      * @var string 
  59.      */
  60.     var $password        = null;
  61.  
  62.     /**
  63.      * Description
  64.      *
  65.      * @var string 
  66.      */
  67.     var $usertype        = null;
  68.  
  69.     /**
  70.      * Description
  71.      *
  72.      * @var int 
  73.      */
  74.     var $block            = null;
  75.  
  76.     /**
  77.      * Description
  78.      *
  79.      * @var int 
  80.      */
  81.     var $sendEmail        = null;
  82.  
  83.     /**
  84.      * The group id number
  85.      *
  86.      * @var int 
  87.      */
  88.     var $gid            = null;
  89.  
  90.     /**
  91.      * Description
  92.      *
  93.      * @var datetime 
  94.      */
  95.     var $registerDate    = null;
  96.  
  97.     /**
  98.      * Description
  99.      *
  100.      * @var datetime 
  101.      */
  102.     var $lastvisitDate    = null;
  103.  
  104.     /**
  105.      * Description
  106.      *
  107.      * @var string activation hash
  108.      */
  109.     var $activation        = null;
  110.  
  111.     /**
  112.      * Description
  113.      *
  114.      * @var string 
  115.      */
  116.     var $params            = null;
  117.  
  118.     /**
  119.     * @param database A database connector object
  120.     */
  121.     function __construct&$db )
  122.     {
  123.         parent::__construct'#__users''id'$db );
  124.  
  125.         //initialise
  126.         $this->id        = 0;
  127.         $this->gid       = 0;
  128.         $this->sendEmail = 1;
  129.     }
  130.  
  131.     /**
  132.      * Validation and filtering
  133.      *
  134.      * @return boolean True is satisfactory
  135.      */
  136.     function check()
  137.     {
  138.         // Validate user information
  139.         if (trim$this->name == ''{
  140.             $this->_error = JText::_'Please enter your name.' );
  141.             return false;
  142.         }
  143.  
  144.         if (trim$this->username == ''{
  145.             $this->_error = JText::_'Please enter a user name.');
  146.             return false;
  147.         }
  148.  
  149.  
  150.         if (eregi"[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]"$this->username|| JString::strlen$this->username 2{
  151.             $this->_error = JText::sprintf'VALID_AZ09'JText::_'Username' ));
  152.             return false;
  153.         }
  154.  
  155.         if ((trim($this->email == "")) || (preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/"$this->email )==false)) {
  156.             $this->_error = JText::_'WARNREG_MAIL' );
  157.             return false;
  158.         }
  159.  
  160.         // check for existing username
  161.         $query 'SELECT id'
  162.         . ' FROM #__users '
  163.         . ' WHERE username = "' $this->username . '"'
  164.         . ' AND id != '$this->id;
  165.         ;
  166.         $this->_db->setQuery$query );
  167.         $xid intval$this->_db->loadResult() );
  168.         if ($xid && $xid != intval$this->id )) {
  169.             $this->_error = JText::_'WARNREG_INUSE' );
  170.             return false;
  171.         }
  172.  
  173.  
  174.         // check for existing email
  175.         $query 'SELECT id'
  176.             . ' FROM #__users '
  177.             . ' WHERE email = "'$this->email . '"'
  178.             . ' AND id != '$this->id
  179.             ;
  180.         $this->_db->setQuery$query );
  181.         $xid intval$this->_db->loadResult() );
  182.         if ($xid && $xid != intval$this->id )) {
  183.             $this->_error = JText::_'WARNREG_EMAIL_INUSE' );
  184.             return false;
  185.         }
  186.  
  187.         return true;
  188.     }
  189.  
  190.     function store$updateNulls=false )
  191.     {
  192.         $acl =JFactory::getACL();
  193.  
  194.         $section_value 'users';
  195.         $k $this->_tbl_key;
  196.         $key =  $this->$k;
  197.  
  198.         if ($key)
  199.         {
  200.             // existing record
  201.             $ret $this->_db->updateObject$this->_tbl$this$this->_tbl_key$updateNulls );
  202.  
  203.             // syncronise ACL
  204.             // single group handled at the moment
  205.             // trivial to expand to multiple groups
  206.             $object_id $acl->get_object_id$section_value$this->$k'ARO' );
  207.  
  208.             $groups $acl->get_object_groups$object_id'ARO' );
  209.             $acl->del_group_object$groups[0]$section_value$this->$k'ARO' );
  210.             $acl->add_group_object$this->gid$section_value$this->$k'ARO' );
  211.  
  212.             $acl->edit_object$object_id$section_value$this->_db->getEscaped$this->name )$this->$k00'ARO' );
  213.         }
  214.         else
  215.         {
  216.             // new record
  217.             $ret $this->_db->insertObject$this->_tbl$this$this->_tbl_key );
  218.             // syncronise ACL
  219.             $acl->add_object$section_value$this->name$this->$knullnull'ARO' );
  220.             $acl->add_group_object$this->gid$section_value$this->$k'ARO' );
  221.         }
  222.  
  223.         if!$ret )
  224.         {
  225.             $this->_error = strtolower(get_class$this ))."::"JText::_'store failed' ."<br />" $this->_db->getErrorMsg();
  226.             return false;
  227.         }
  228.         else
  229.         {
  230.             return true;
  231.         }
  232.     }
  233.  
  234.     function delete$oid=null )
  235.     {
  236.         $acl =JFactory::getACL();
  237.  
  238.         $k $this->_tbl_key;
  239.         if ($oid{
  240.             $this->$k intval$oid );
  241.         }
  242.         $aro_id $acl->get_object_id'users'$this->$k'ARO' );
  243.         $acl->del_object$aro_id'ARO'true );
  244.  
  245.         $query 'DELETE FROM '$this->_tbl
  246.         . ' WHERE  '$this->_tbl_key .' = "'$this->$k .'"';
  247.         ;
  248.         $this->_db->setQuery$query );
  249.  
  250.         if ($this->_db->query()) {
  251.             // cleanup related data
  252.  
  253.             // private messaging
  254.             $query 'DELETE FROM #__messages_cfg'
  255.             . ' WHERE user_id = '$this->$k
  256.             ;
  257.             $this->_db->setQuery$query );
  258.             if (!$this->_db->query()) {
  259.                 $this->_error = $this->_db->getErrorMsg();
  260.                 return false;
  261.             }
  262.             $query 'DELETE FROM #__messages'
  263.             . ' WHERE user_id_to = '$this->$k
  264.             ;
  265.             $this->_db->setQuery$query );
  266.             if (!$this->_db->query()) {
  267.                 $this->_error = $this->_db->getErrorMsg();
  268.                 return false;
  269.             }
  270.  
  271.             return true;
  272.         else {
  273.             $this->_error = $this->_db->getErrorMsg();
  274.             return false;
  275.         }
  276.     }
  277.  
  278.     /**
  279.      * Updates last visit time of user
  280.      *
  281.      * @param int The timestamp, defaults to 'now'
  282.      * @return boolean False if an error occurs
  283.      */
  284.     function setLastVisit$timeStamp=null$id=null )
  285.     {
  286.         // check for User ID
  287.         if (is_null$id )) {
  288.             if (isset$this )) {
  289.                 $id $this->id;
  290.             else {
  291.                 // do not translate
  292.                 die'WARNMOSUSER' );
  293.             }
  294.         }
  295.         // data check
  296.         $id intval$id );
  297.  
  298.         // if no timestamp value is passed to functon, than current time is used
  299.         if $timeStamp {
  300.             $dateTime date'Y-m-d H:i:s'$timeStamp );
  301.         else {
  302.             $dateTime date'Y-m-d H:i:s' );
  303.         }
  304.  
  305.         // updates user lastvistdate field with date and time
  306.         $query 'UPDATE '$this->_tbl
  307.         . ' SET lastvisitDate = "'.$dateTime.'"'
  308.         . ' WHERE id = '.$id
  309.         ;
  310.         $this->_db->setQuery$query );
  311.         if (!$this->_db->query()) {
  312.             $this->_error = $this->_db->getErrorMsg();
  313.             return false;
  314.         }
  315.  
  316.         return true;
  317.     }
  318.  
  319.     /**
  320.     * Overloaded bind function
  321.     *
  322.     * @access public
  323.     * @param array $hash named array
  324.     * @return null|string   null is operation was satisfactory, otherwise returns an error
  325.     * @see JTable:bind
  326.     * @since 1.5
  327.     */
  328.  
  329.     function bind($array$ignore '')
  330.     {
  331.         if (key_exists'params'$array && is_array$array['params')) {
  332.             $registry new JRegistry();
  333.             $registry->loadArray($array['params']);
  334.             $array['params'$registry->toString();
  335.         }
  336.  
  337.         return parent::bind($array$ignore);
  338.     }
  339.  
  340.     /**
  341.      * Returns a complete user list
  342.      *
  343.      * @return array 
  344.      */
  345.     function getUserList()
  346.     {
  347.         $this->_db->setQuery("SELECT username FROM #__users");
  348.         return $this->_db->loadAssocList();
  349.     }
  350.  
  351.     /**
  352.      * Gets the users from a group
  353.      *
  354.      * @param string The value for the group (not used 1.0)
  355.      * @param string The name for the group
  356.      * @param string If RECURSE, will drill into child groups
  357.      * @param string Ordering for the list
  358.      * @return array 
  359.      */
  360.     function getUserListFromGroup$value$name$recurse='NO_RECURSE'$order='name' )
  361.     {
  362.         $acl =JFactory::getACL();
  363.  
  364.         // Change back in
  365.         $group_id $acl->get_group_id$name$group_type 'ARO');
  366.         $objects $acl->get_group_objects$group_id'ARO''RECURSE');
  367.  
  368.         if (isset$objects['users'))
  369.         {
  370.             $gWhere '(id =' implode' OR id ='$objects['users'')';
  371.  
  372.             $query 'SELECT id AS value, name AS text'
  373.             . ' FROM #__users'
  374.             . ' WHERE block = "0"'
  375.             . ' AND ' $gWhere
  376.             . ' ORDER BY '$order
  377.             ;
  378.             $this->_db->setQuery$query );
  379.             $options $this->_db->loadObjectList();
  380.             return $options;
  381.         else {
  382.             return array();
  383.         }
  384.     }
  385. }
  386. ?>

Documentation generated on Mon, 05 Mar 2007 21:30:35 +0000 by phpDocumentor 1.3.1