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