Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Source code for file /joomla/database/table/user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3. @version        $Id: user.php 9860 2008-01-04 20:46:05Z louis $
  4. @package        Joomla.Framework
  5. @subpackage    Table
  6. @copyright    Copyright (C) 2005 - 2008 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.         jimport('joomla.mail.helper');
  139.  
  140.         // Validate user information
  141.         if (trim$this->name == ''{
  142.             $this->setErrorJText::_'Please enter your name.' ) );
  143.             return false;
  144.         }
  145.  
  146.         if (trim$this->username == ''{
  147.             $this->setErrorJText::_'Please enter a user name.') );
  148.             return false;
  149.         }
  150.  
  151.  
  152.         if (eregi"[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]"$this->username|| strlen(utf8_decode($this->username )) 2{
  153.             $this->setErrorJText::sprintf'VALID_AZ09'JText::_'Username' )) );
  154.             return false;
  155.         }
  156.  
  157.         if ((trim($this->email== ""|| JMailHelper::isEmailAddress($this->email) ) {
  158.             $this->setErrorJText::_'WARNREG_MAIL' ) );
  159.             return false;
  160.         }
  161.  
  162.         // check for existing username
  163.         $query 'SELECT id'
  164.         . ' FROM #__users '
  165.         . ' WHERE username = ' $this->_db->Quote($this->username)
  166.         . ' AND id != '. (int) $this->id;
  167.         ;
  168.         $this->_db->setQuery$query );
  169.         $xid intval$this->_db->loadResult() );
  170.         if ($xid && $xid != intval$this->id )) {
  171.             $this->setError(  JText::_('WARNREG_INUSE'));
  172.             return false;
  173.         }
  174.  
  175.  
  176.         // check for existing email
  177.         $query 'SELECT id'
  178.             . ' FROM #__users '
  179.             . ' WHERE email = '$this->_db->Quote($this->email)
  180.             . ' AND id != '. (int) $this->id
  181.             ;
  182.         $this->_db->setQuery$query );
  183.         $xid intval$this->_db->loadResult() );
  184.         if ($xid && $xid != intval$this->id )) {
  185.             $this->setErrorJText::_'WARNREG_EMAIL_INUSE' ) );
  186.             return false;
  187.         }
  188.  
  189.         return true;
  190.     }
  191.  
  192.     function store$updateNulls=false )
  193.     {
  194.         $acl =JFactory::getACL();
  195.  
  196.         $section_value 'users';
  197.         $k $this->_tbl_key;
  198.         $key =  $this->$k;
  199.  
  200.         if ($key)
  201.         {
  202.             // existing record
  203.             $ret $this->_db->updateObject$this->_tbl$this$this->_tbl_key$updateNulls );
  204.  
  205.             // syncronise ACL
  206.             // single group handled at the moment
  207.             // trivial to expand to multiple groups
  208.             $object_id $acl->get_object_id$section_value$this->$k'ARO' );
  209.  
  210.             $groups $acl->get_object_groups$object_id'ARO' );
  211.             $acl->del_group_object$groups[0]$section_value$this->$k'ARO' );
  212.             $acl->add_group_object$this->gid$section_value$this->$k'ARO' );
  213.  
  214.             $acl->edit_object$object_id$section_value$this->_db->getEscaped$this->name )$this->$k00'ARO' );
  215.         }
  216.         else
  217.         {
  218.             // new record
  219.             $ret $this->_db->insertObject$this->_tbl$this$this->_tbl_key );
  220.             // syncronise ACL
  221.             $acl->add_object$section_value$this->name$this->$knullnull'ARO' );
  222.             $acl->add_group_object$this->gid$section_value$this->$k'ARO' );
  223.         }
  224.  
  225.         if!$ret )
  226.         {
  227.             $this->setErrorstrtolower(get_class$this ))."::"JText::_'store failed' ."<br />" $this->_db->getErrorMsg() );
  228.             return false;
  229.         }
  230.         else
  231.         {
  232.             return true;
  233.         }
  234.     }
  235.  
  236.     function delete$oid=null )
  237.     {
  238.         $acl =JFactory::getACL();
  239.  
  240.         $k $this->_tbl_key;
  241.         if ($oid{
  242.             $this->$k intval$oid );
  243.         }
  244.         $aro_id $acl->get_object_id'users'$this->$k'ARO' );
  245.         $acl->del_object$aro_id'ARO'true );
  246.  
  247.         $query 'DELETE FROM '$this->_tbl
  248.         . ' WHERE '$this->_tbl_key .' = '. (int) $this->$k
  249.         ;
  250.         $this->_db->setQuery$query );
  251.  
  252.         if ($this->_db->query()) {
  253.             // cleanup related data
  254.  
  255.             // private messaging
  256.             $query 'DELETE FROM #__messages_cfg'
  257.             . ' WHERE user_id = '. (int) $this->$k
  258.             ;
  259.             $this->_db->setQuery$query );
  260.             if (!$this->_db->query()) {
  261.                 $this->setError$this->_db->getErrorMsg() );
  262.                 return false;
  263.             }
  264.             $query 'DELETE FROM #__messages'
  265.             . ' WHERE user_id_to = '. (int) $this->$k
  266.             ;
  267.             $this->_db->setQuery$query );
  268.             if (!$this->_db->query()) {
  269.                 $this->setError$this->_db->getErrorMsg() );
  270.                 return false;
  271.             }
  272.  
  273.             return true;
  274.         else {
  275.             $this->setError$this->_db->getErrorMsg() );
  276.             return false;
  277.         }
  278.     }
  279.  
  280.     /**
  281.      * Updates last visit time of user
  282.      *
  283.      * @param int The timestamp, defaults to 'now'
  284.      * @return boolean False if an error occurs
  285.      */
  286.     function setLastVisit$timeStamp=null$id=null )
  287.     {
  288.         // check for User ID
  289.         if (is_null$id )) {
  290.             if (isset$this )) {
  291.                 $id $this->id;
  292.             else {
  293.                 // do not translate
  294.                 die'WARNMOSUSER' );
  295.             }
  296.         }
  297.  
  298.         // if no timestamp value is passed to functon, than current time is used
  299.         $date new JDate($timeStamp);
  300.  
  301.         // updates user lastvistdate field with date and time
  302.         $query 'UPDATE '$this->_tbl
  303.         . ' SET lastvisitDate = '.$this->_db->Quote($date->toMySQL())
  304.         . ' WHERE id = '. (int) $id
  305.         ;
  306.         $this->_db->setQuery$query );
  307.         if (!$this->_db->query()) {
  308.             $this->setError$this->_db->getErrorMsg() );
  309.             return false;
  310.         }
  311.  
  312.         return true;
  313.     }
  314.  
  315.     /**
  316.     * Overloaded bind function
  317.     *
  318.     * @access public
  319.     * @param array $hash named array
  320.     * @return null|string   null is operation was satisfactory, otherwise returns an error
  321.     * @see JTable:bind
  322.     * @since 1.5
  323.     */
  324.  
  325.     function bind($array$ignore '')
  326.     {
  327.         if (key_exists'params'$array && is_array$array['params')) {
  328.             $registry new JRegistry();
  329.             $registry->loadArray($array['params']);
  330.             $array['params'$registry->toString();
  331.         }
  332.  
  333.         return parent::bind($array$ignore);
  334.     }
  335. }

Documentation generated on Tue, 29 Jan 2008 18:52:30 +0000 by phpDocumentor 1.3.1