| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: session.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 * Session table 20 * 21 * @package Joomla.Framework 22 * @subpackage Table 23 * @since 1.0 24 */ 25 class JTableSession extends JTable 26 { 27 /** 28 * 29 * @var int Primary key 30 */ 31 var $session_id = null; 32 33 /** 34 * 35 * @var string 36 */ 37 var $time = null; 38 39 /** 40 * 41 * @var string 42 */ 43 var $userid = null; 44 45 /** 46 * 47 * @var string 48 */ 49 var $usertype = null; 50 51 /** 52 * 53 * @var string 54 */ 55 var $username = null; 56 57 /** 58 * 59 * @var time 60 */ 61 var $gid = null; 62 63 /** 64 * 65 * @var int 66 */ 67 var $guest = null; 68 69 /** 70 * 71 * @var int 72 */ 73 var $client_id = null; 74 75 /** 76 * 77 * @var string 78 */ 79 var $data = null; 80 81 /** 82 * Constructor 83 * @param database A database connector object 84 */ 85 function __construct( &$db ) 86 { 87 parent::__construct( '#__session', 'session_id', $db ); 88 89 $this->guest = 1; 90 $this->username = ''; 91 $this->gid = 0; 92 } 93 94 function insert($sessionId, $clientId) 95 { 96 $this->session_id = $sessionId; 97 $this->client_id = $clientId; 98 99 $this->time = time(); 100 $ret = $this->_db->insertObject( $this->_tbl, $this, 'session_id' ); 101 102 if( !$ret ) { 103 $this->setError(strtolower(get_class( $this ))."::". JText::_( 'store failed' ) ."<br />" . $this->_db->stderr()); 104 return false; 105 } else { 106 return true; 107 } 108 } 109 110 function update( $updateNulls = false ) 111 { 112 $this->time = time(); 113 $ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls ); 114 115 if( !$ret ) { 116 $this->setError(strtolower(get_class( $this ))."::". JText::_( 'store failed' ) ." <br />" . $this->_db->stderr()); 117 return false; 118 } else { 119 return true; 120 } 121 } 122 123 /** 124 * Destroys the pesisting session 125 */ 126 function destroy($userId, $clientIds = array()) 127 { 128 $clientIds = implode( ',', $clientIds ); 129 130 $query = 'DELETE FROM #__session' 131 . ' WHERE userid = '. $this->_db->Quote( $userId ) 132 . ' AND client_id IN ( '.$clientIds.' )' 133 ; 134 $this->_db->setQuery( $query ); 135 136 if ( !$this->_db->query() ) { 137 $this->setError( $this->_db->stderr()); 138 return false; 139 } 140 141 return true; 142 } 143 144 /** 145 * Purge old sessions 146 * 147 * @param int Session age in seconds 148 * @return mixed Resource on success, null on fail 149 */ 150 function purge( $maxLifetime = 1440 ) 151 { 152 $past = time() - $maxLifetime; 153 $query = 'DELETE FROM '. $this->_tbl .' WHERE ( time < \''. (int) $past .'\' )'; // Index on 'VARCHAR' 154 $this->_db->setQuery($query); 155 156 return $this->_db->query(); 157 } 158 159 /** 160 * Find out if a user has a one or more active sessions 161 * 162 * @param int $userid The identifier of the user 163 * @return boolean True if a session for this user exists 164 */ 165 function exists($userid) 166 { 167 $query = 'SELECT COUNT(userid) FROM #__session' 168 . ' WHERE userid = '. $this->_db->Quote( $userid ); 169 $this->_db->setQuery( $query ); 170 171 if ( !$result = $this->_db->loadResult() ) { 172 $this->setError($this->_db->stderr()); 173 return false; 174 } 175 176 return (boolean) $result; 177 } 178 179 /** 180 * Overloaded delete method 181 * 182 * We must override it because of the non-integer primary key 183 * 184 * @access public 185 * @return true if successful otherwise returns and error message 186 */ 187 function delete( $oid=null ) 188 { 189 //if (!$this->canDelete( $msg )) 190 //{ 191 // return $msg; 192 //} 193 194 $k = $this->_tbl_key; 195 if ($oid) { 196 $this->$k = $oid; 197 } 198 199 $query = 'DELETE FROM '.$this->_db->nameQuote( $this->_tbl ). 200 ' WHERE '.$this->_tbl_key.' = '. $this->_db->Quote($this->$k); 201 $this->_db->setQuery( $query ); 202 203 if ($this->_db->query()) 204 { 205 return true; 206 } 207 else 208 { 209 $this->setError($this->_db->getErrorMsg()); 210 return false; 211 } 212 } 213 }
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 |