Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/libraries/joomla/database/table/session.php
c7d7e38b2269
4.1 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | <?php
/**
* @version $Id: session.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla.Framework
* @subpackage Table
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
/**
* Session table
*
* @package Joomla.Framework
* @subpackage Table
* @since 1.0
*/
class JTableSession extends JTable
{
/**
*
* @var int Primary key
*/
var $session_id = null;
/**
*
* @var string
*/
var $time = null;
/**
*
* @var string
*/
var $userid = null;
/**
*
* @var string
*/
var $usertype = null;
/**
*
* @var string
*/
var $username = null;
/**
*
* @var time
*/
var $gid = null;
/**
*
* @var int
*/
var $guest = null;
/**
*
* @var int
*/
var $client_id = null;
/**
*
* @var string
*/
var $data = null;
/**
* Constructor
* @param database A database connector object
*/
function __construct( &$db )
{
parent::__construct( '#__session', 'session_id', $db );
$this->guest = 1;
$this->username = '';
$this->gid = 0;
}
function insert($sessionId, $clientId)
{
$this->session_id = $sessionId;
$this->client_id = $clientId;
$this->time = time();
$ret = $this->_db->insertObject( $this->_tbl, $this, 'session_id' );
if( !$ret ) {
$this->setError(strtolower(get_class( $this ))."::". JText::_( 'store failed' ) ."<br />" . $this->_db->stderr());
return false;
} else {
return true;
}
}
function update( $updateNulls = false )
{
$this->time = time();
$ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls );
if( !$ret ) {
$this->setError(strtolower(get_class( $this ))."::". JText::_( 'store failed' ) ." <br />" . $this->_db->stderr());
return false;
} else {
return true;
}
}
/**
* Destroys the pesisting session
*/
function destroy($userId, $clientIds = array())
{
$clientIds = implode( ',', $clientIds );
$query = 'DELETE FROM #__session'
. ' WHERE userid = '. $this->_db->Quote( $userId )
. ' AND client_id IN ( '.$clientIds.' )'
;
$this->_db->setQuery( $query );
if ( !$this->_db->query() ) {
$this->setError( $this->_db->stderr());
return false;
}
return true;
}
/**
* Purge old sessions
*
* @param int Session age in seconds
* @return mixed Resource on success, null on fail
*/
function purge( $maxLifetime = 1440 )
{
$past = time() - $maxLifetime;
$query = 'DELETE FROM '. $this->_tbl .' WHERE ( time < \''. (int) $past .'\' )'; // Index on 'VARCHAR'
$this->_db->setQuery($query);
return $this->_db->query();
}
/**
* Find out if a user has a one or more active sessions
*
* @param int $userid The identifier of the user
* @return boolean True if a session for this user exists
*/
function exists($userid)
{
$query = 'SELECT COUNT(userid) FROM #__session'
. ' WHERE userid = '. $this->_db->Quote( $userid );
$this->_db->setQuery( $query );
if ( !$result = $this->_db->loadResult() ) {
$this->setError($this->_db->stderr());
return false;
}
return (boolean) $result;
}
/**
* Overloaded delete method
*
* We must override it because of the non-integer primary key
*
* @access public
* @return true if successful otherwise returns and error message
*/
function delete( $oid=null )
{
//if (!$this->canDelete( $msg ))
//{
// return $msg;
//}
$k = $this->_tbl_key;
if ($oid) {
$this->$k = $oid;
}
$query = 'DELETE FROM '.$this->_db->nameQuote( $this->_tbl ).
' WHERE '.$this->_tbl_key.' = '. $this->_db->Quote($this->$k);
$this->_db->setQuery( $query );
if ($this->_db->query())
{
return true;
}
else
{
$this->setError($this->_db->getErrorMsg());
return false;
}
}
}
|