OSB enhancements to date
This commit is contained in:
@@ -1,416 +1,409 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AgileBill - Open Billing Software
|
||||
*
|
||||
* This body of work is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Open AgileBill License
|
||||
* License as published at http://www.agileco.com/agilebill/license1-4.txt
|
||||
*
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Agileco community forums at http://forum.agileco.com/
|
||||
*
|
||||
* Originally authored by Tony Landis, AgileBill LLC
|
||||
*
|
||||
* Recent modifications by Deon George
|
||||
*
|
||||
* @author Deon George <deonATleenooksDOTnet>
|
||||
* @copyright 2009 Deon George
|
||||
* @link http://osb.leenooks.net
|
||||
*
|
||||
* @link http://www.agileco.com/
|
||||
* @copyright 2004-2008 Agileco, LLC.
|
||||
* @license http://www.agileco.com/agilebill/license1-4.txt
|
||||
* @author Tony Landis <tony@agileco.com>
|
||||
* @author Tony Landis <tony@agileco.com>
|
||||
* @package AgileBill
|
||||
* @version 1.4.93
|
||||
* @subpackage Core:Session
|
||||
*/
|
||||
|
||||
class CORE_session
|
||||
{
|
||||
var $id;
|
||||
|
||||
function CORE_session()
|
||||
{
|
||||
global $C_debug, $_GET, $_POST,$_COOKIE, $HTTP_COOKIE_VARS, $VAR;
|
||||
/**
|
||||
* The main AgileBill Session Class
|
||||
*
|
||||
* @package AgileBill
|
||||
* @subpackage Core:Session
|
||||
*/
|
||||
class CORE_session {
|
||||
# Our session ID
|
||||
private $id = '';
|
||||
# The time our session expires
|
||||
private $sess_date_expire = 0;
|
||||
|
||||
if (isset($_GET['s']))
|
||||
$session_arr[] = $_GET['s'];
|
||||
else if (isset($_POST['s']))
|
||||
$session_arr[] = $_POST['s'];
|
||||
else if(isset($_COOKIE[COOKIE_NAME]))
|
||||
$session_arr[] = $_COOKIE[COOKIE_NAME];
|
||||
else if (isset($HTTP_COOKIE_VARS[COOKIE_NAME]))
|
||||
$session_arr[] = $HTTP_COOKIE_VARS[COOKIE_NAME];
|
||||
public function __construct() {
|
||||
global $C_debug,$VAR;
|
||||
|
||||
if(isset($session_arr)) {
|
||||
for($i=0; $i<count($session_arr); $i++) {
|
||||
if($session_arr[$i] != '') {
|
||||
$validate = $this->validate($session_arr[$i]);
|
||||
if($validate != FALSE) {
|
||||
$this->id = $session_arr[$i];
|
||||
$i = count($session_arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$session_arr = array();
|
||||
|
||||
@$this->sess_date_expire = time() + (SESSION_EXPIRE*60);
|
||||
if(!isset($this->id))
|
||||
{
|
||||
empty($VAR['tid']) ? $this->sess_theme_id = DEFAULT_THEME : $this->sess_theme_id = $VAR['tid'];
|
||||
empty($VAR['lid']) ? $this->sess_language_id = DEFAULT_LANGUAGE : $this->sess_language_id = $VAR['lid'];
|
||||
empty($VAR['cid']) ? $this->sess_country_id = DEFAULT_COUNTRY : $this->sess_country_id = $VAR['cid'];
|
||||
empty($VAR['cyid']) ? $this->sess_currency_id = DEFAULT_CURRENCY : $this->sess_currency_id = $this->get_currency($VAR['cyid']);
|
||||
empty($VAR['wid']) ? $this->sess_weight_id = DEFAULT_WEIGHT : $this->sess_weight_id = $VAR['wid'];
|
||||
@$this->sess_reseller_id = $VAR['rid'];
|
||||
@$this->sess_affiliate_id = $this->get_affiliate(0);
|
||||
@$this->sess_campaign_id = $this->get_campaign(0);
|
||||
$this->sess_logged = false;
|
||||
$this->sess_account_id = false;
|
||||
$this->session();
|
||||
# Get our SESSION ID, either as a GET/POST or COOKIE
|
||||
if (isset($_GET['s']) && trim($_GET['s']))
|
||||
array_push($session_arr,$_GET['s']);
|
||||
|
||||
elseif (isset($_POST['s']) && trim($_POST['s']))
|
||||
array_push($session_arr,$_POST['s']);
|
||||
|
||||
elseif(isset($_COOKIE[COOKIE_NAME]) && trim($_COOKIE[COOKIE_NAME])) {
|
||||
array_push($session_arr,$_COOKIE[COOKIE_NAME]);
|
||||
|
||||
# Clear the cookie, as we'll validate it
|
||||
$this->id = $_COOKIE[COOKIE_NAME];
|
||||
$this->setcookies(true);
|
||||
$this->id = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
empty($VAR['tid']) ? $this->sess_theme_id = $validate['theme_id'] : $this->sess_theme_id = $VAR['tid'];
|
||||
empty($VAR['lid']) ? $this->sess_language_id = $validate['language_id'] : $this->sess_language_id = $VAR['lid'];
|
||||
empty($VAR['cid']) ? $this->sess_country_id = $validate['country_id'] : $this->sess_country_id = $VAR['cid'];
|
||||
empty($VAR['cyid']) ? $this->sess_currency_id = $validate['currency_id'] : $this->sess_currency_id = $this->get_currency($VAR['cyid']);
|
||||
empty($VAR['wid']) ? $this->sess_weight_id = $validate['weight_id'] : $this->sess_weight_id = $VAR['wid'];
|
||||
empty($VAR['rid']) ? $this->sess_reseller_id = $validate['reseller_id'] : $this->sess_reseller_id = $VAR['rid'];
|
||||
empty($VAR['aid']) ? $this->sess_affiliate_id = $validate['affiliate_id'] : $this->sess_affiliate_id = $this->get_affiliate($validate['affiliate_id']);
|
||||
empty($VAR['caid']) ? $this->sess_campaign_id = $validate['campaign_id'] : $this->sess_campaign_id = $this->get_campaign($validate['campaign_id']);
|
||||
|
||||
$this->sess_account_id = $validate['account_id'];
|
||||
$this->sess_logged = $validate['logged'];
|
||||
foreach ($session_arr as $s)
|
||||
if ($validate = $this->validate($s))
|
||||
$this->id = $s;
|
||||
|
||||
$this->sess_date_expire = time()+(SESSION_EXPIRE*60);
|
||||
|
||||
if (! $this->id) {
|
||||
$this->tid = empty($VAR['tid']) ? DEFAULT_THEME : $VAR['tid'];
|
||||
$this->lid = empty($VAR['lid']) ? DEFAULT_LANGUAGE : $VAR['lid'];
|
||||
$this->cid = empty($VAR['cid']) ? DEFAULT_COUNTRY : $VAR['cid'];
|
||||
$this->cyid = empty($VAR['cyid']) ? DEFAULT_CURRENCY : $this->get_currency($VAR['cyid']);
|
||||
$this->wid = empty($VAR['wid']) ? DEFAULT_WEIGHT : $VAR['wid'];
|
||||
$this->rid = empty($VAR['rid']) ? null : $VAR['rid'];
|
||||
$this->aid = $this->get_session_link(0,'affiliate');
|
||||
$this->caid = $this->get_session_link(0,'campaign');
|
||||
$this->sess_logged = false;
|
||||
$this->sess_account_id = false;
|
||||
$this->session();
|
||||
|
||||
} else {
|
||||
$this->tid = empty($VAR['tid']) ? $validate['theme_id'] : $VAR['tid'];
|
||||
$this->lid = empty($VAR['lid']) ? $validate['language_id'] : $VAR['lid'];
|
||||
$this->cid = empty($VAR['cid']) ? $validate['country_id'] : $VAR['cid'];
|
||||
$this->cyid = empty($VAR['cyid']) ? $validate['currency_id'] : $this->get_currency($VAR['cyid']);
|
||||
$this->wid = empty($VAR['wid']) ? $validate['weight_id'] : $VAR['wid'];
|
||||
$this->rid = empty($VAR['rid']) ? $validate['reseller_id'] : $VAR['rid'];
|
||||
$this->aid = empty($VAR['aid']) ? $validate['affiliate_id'] : $this->get_session_link($validate['affiliate_id'],'affiliate');
|
||||
$this->caid = empty($VAR['caid']) ? $validate['campaign_id'] : $this->get_session_link($validate['campaign_id'],'campaign');
|
||||
$this->sess_logged = $validate['logged'];
|
||||
$this->sess_account_id = $validate['account_id'];
|
||||
|
||||
$db = &DB();
|
||||
$q = "UPDATE " . AGILE_DB_PREFIX . "session SET
|
||||
date_last = " . $db->qstr(time()) . ",
|
||||
date_expire = " . $db->qstr($this->sess_date_expire) . ",
|
||||
ip = " . $db->qstr(USER_IP) . ",
|
||||
theme_id = " . $db->qstr($this->sess_theme_id) . ",
|
||||
country_id = " . $db->qstr($this->sess_country_id) . ",
|
||||
language_id = " . $db->qstr($this->sess_language_id) . ",
|
||||
currency_id = " . $db->qstr($this->sess_currency_id) . ",
|
||||
weight_id = " . $db->qstr($this->sess_weight_id) . ",
|
||||
reseller_id = " . $db->qstr($this->sess_reseller_id) . ",
|
||||
affiliate_id = " . $db->qstr($this->sess_affiliate_id). ",
|
||||
campaign_id = " . $db->qstr($this->sess_campaign_id) . "
|
||||
WHERE
|
||||
id = " . $db->qstr($this->id) . "
|
||||
AND
|
||||
site_id = " . $db->qstr(DEFAULT_SITE);
|
||||
|
||||
// update the old session ONLY if info has changed or expires/no update in the past 5 minutes.
|
||||
if (!empty($VAR['tid']) || !empty($VAR['lid']) || !empty($VAR['cid']) || !empty($VAR['cyid']) ||
|
||||
!empty($VAR['wid']) || !empty($VAR['rid']) || !empty($VAR['aid']) || !empty($VAR['caid']) ) {
|
||||
$result = $db->Execute($q);
|
||||
} else if ($validate['logged'] == '0' && !empty($this->sess_date_expire) && $this->sess_date_expire+60*5 < time()) {
|
||||
$result = $db->Execute($q);
|
||||
} else if (!empty($validate['date_last']) && $validate['date_last']+60*5 < time()) {
|
||||
$result = $db->Execute($q);
|
||||
}
|
||||
# Only update the session (every 5 mins) if we are logged in
|
||||
if ($validate['logged'] && $this->sess_date_expire+60*5 < time())
|
||||
$db->Execute(
|
||||
sqlUpdate($db,'session',array(
|
||||
'date_last'=>time(),
|
||||
'date_expire'=>$this->sess_date_expire,
|
||||
'ip'=>USER_IP,
|
||||
'theme_id'=>$this->tid,
|
||||
'country_id'=>$this->cid,
|
||||
'language_id'=>$this->lid,
|
||||
'currency_id'=>$this->cyid,
|
||||
'weight_id'=>$this->wid,
|
||||
'reseller_id'=>$this->rid,
|
||||
'affiliate_id'=>$this->aid,
|
||||
'campaign_id'=>$this->caid,
|
||||
),array('id'=>$this->id)));
|
||||
}
|
||||
|
||||
if(!defined("SESS")) define ('SESS', $this->id);
|
||||
$this->setcookies();
|
||||
if (! defined('SESS'))
|
||||
define('SESS',$this->id);
|
||||
|
||||
$this->setcookies();
|
||||
}
|
||||
|
||||
|
||||
function validate($session_id) {
|
||||
private function validate($session_id) {
|
||||
global $C_debug;
|
||||
|
||||
$db = &DB();
|
||||
$q = "SELECT
|
||||
" . AGILE_DB_PREFIX . "session.*,
|
||||
" . AGILE_DB_PREFIX . "account.id AS acct_id,
|
||||
" . AGILE_DB_PREFIX . "account.status,
|
||||
" . AGILE_DB_PREFIX . "account.date_expire AS account_date_expire,
|
||||
" . AGILE_DB_PREFIX . "session_auth_cache.date_expire AS sess_auth_date_expire,
|
||||
" . AGILE_DB_PREFIX . "session_auth_cache.group_arr,
|
||||
" . AGILE_DB_PREFIX . "session_auth_cache.module_arr
|
||||
FROM
|
||||
" . AGILE_DB_PREFIX . "session
|
||||
LEFT JOIN " . AGILE_DB_PREFIX . "account ON ".AGILE_DB_PREFIX."account.id = ".AGILE_DB_PREFIX."session.account_id
|
||||
LEFT JOIN " . AGILE_DB_PREFIX . "session_auth_cache ON " . AGILE_DB_PREFIX . "session.id = " . AGILE_DB_PREFIX . "session_auth_cache.session_id
|
||||
WHERE
|
||||
" . AGILE_DB_PREFIX . "session.id = " . $db->qstr($session_id) . "
|
||||
AND
|
||||
" . AGILE_DB_PREFIX . "session.site_id = " . $db->qstr(DEFAULT_SITE) . "
|
||||
AND ((
|
||||
" . AGILE_DB_PREFIX . "account.site_id = " . $db->qstr(DEFAULT_SITE) . "
|
||||
AND
|
||||
" . AGILE_DB_PREFIX . "session.account_id IS NOT NULL
|
||||
) OR (
|
||||
" . AGILE_DB_PREFIX . "account.site_id IS NULL
|
||||
AND
|
||||
" . AGILE_DB_PREFIX . "session.account_id IS NULL
|
||||
))
|
||||
AND
|
||||
" . AGILE_DB_PREFIX . "session_auth_cache.site_id = " . $db->qstr(DEFAULT_SITE);
|
||||
$result = $db->Execute($q);
|
||||
if ($result === false) {
|
||||
$C_debug->error('session.inc.php','validate', $db->ErrorMsg());
|
||||
echo '<BR>Unable to start session: Database Error: ' . $db->ErrorMsg();
|
||||
return;
|
||||
} else if ($result->RecordCount() == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set the auth caching for use in the auth module to save a query there:
|
||||
$this->auth_cache['date_expire'] = $result->fields["sess_auth_date_expire"];
|
||||
$this->auth_cache['group_arr'] = $result->fields["group_arr"];
|
||||
$this->auth_cache['module_arr'] = $result->fields["module_arr"];
|
||||
$q = str_replace('{p}',AGILE_DB_PREFIX,str_replace('{s}',DEFAULT_SITE,sprintf(
|
||||
'SELECT A.*,B.id AS acct_id,B.status,B.date_expire AS account_date_expire,C.date_expire AS sess_auth_date_expire,C.group_arr,C.module_arr
|
||||
FROM {p}session AS A
|
||||
LEFT JOIN {p}account AS B ON B.id=A.account_id LEFT JOIN {p}session_auth_cache AS C ON A.id=C.session_id
|
||||
WHERE A.id=%s AND A.site_id={s} AND ((B.site_id={s} AND A.account_id IS NOT NULL) OR (B.site_id IS NULL AND A.account_id IS NULL)) AND C.site_id={s}',$db->qstr($session_id)
|
||||
)));
|
||||
|
||||
if($result->fields['id'] == $session_id) {
|
||||
if($result->fields["logged"] == "1") {
|
||||
if($result->fields['status'] != "1") {
|
||||
return FALSE;
|
||||
} else if(!empty($result->fields['account_date_expire']) && $result->fields['account_date_expire'] < time()) {
|
||||
return FALSE;
|
||||
} else if(SESSION_EXPIRE != 0 && $result->fields['date_expire'] <= time()) {
|
||||
$this->logout($session_id);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
$rs = $db->Execute($q);
|
||||
if (! $rs) {
|
||||
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
||||
printf('Unable to start session: Database Error: %s',$db->ErrorMsg());
|
||||
|
||||
if(SESSION_IP_MATCH) {
|
||||
if($result->fields['ip'] != USER_IP) {
|
||||
$this->delete($session_id);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
} else {
|
||||
return FALSE;
|
||||
} elseif ($rs->RecordCount() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result->fields;
|
||||
# Set the auth caching for use in the auth module to save a query there:
|
||||
$this->auth_cache['date_expire'] = $rs->fields['sess_auth_date_expire'];
|
||||
$this->auth_cache['group_arr'] = $rs->fields['group_arr'];
|
||||
$this->auth_cache['module_arr'] = $rs->fields['module_arr'];
|
||||
|
||||
if ($rs->fields['logged'] == 1) {
|
||||
if ($rs->fields['status'] != 1)
|
||||
return false;
|
||||
|
||||
elseif (! empty($rs->fields['account_date_expire']) && $rs->fields['account_date_expire'] < time())
|
||||
return false;
|
||||
|
||||
elseif (SESSION_EXPIRE != 0 && $rs->fields['date_expire'] <= time()) {
|
||||
$this->logout($session_id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (SESSION_IP_MATCH && ($rs->fields['ip'] != USER_IP)) {
|
||||
$this->delete($session_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $rs->fields;
|
||||
}
|
||||
|
||||
|
||||
function setcookies() {
|
||||
|
||||
if(defined("AGILE_COOKIE") && AGILE_COOKIE != '') {
|
||||
/**
|
||||
* Set or expire cookies
|
||||
*/
|
||||
private function setcookies($expire=false) {
|
||||
if (defined('AGILE_COOKIE') && AGILE_COOKIE != '') {
|
||||
$domain = AGILE_COOKIE;
|
||||
} else {
|
||||
global $_SERVER;
|
||||
if(isset($_SERVER)) {
|
||||
@$domain = $_SERVER['HTTP_HOST'];
|
||||
} else {
|
||||
$server = getallheaders();
|
||||
$domain = $server['Host'];
|
||||
}
|
||||
$domain = '.'.preg_replace('/^www./', '', $domain);
|
||||
}
|
||||
|
||||
if(COOKIE_EXPIRE == 0 )
|
||||
$cookie_expire = (time() + 86400*365);
|
||||
} else {
|
||||
global $_SERVER;
|
||||
|
||||
if (isset($_SERVER['HTTP_HOST'])) {
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
} elseif (isset($_SERVER['SERVER_NAME'])) {
|
||||
$domain = $_SERVER['SERVER_NAME'];
|
||||
} elseif (function_exists('getallheaders')) {
|
||||
$server = getallheaders();
|
||||
$domain = $server['Host'];
|
||||
} else {
|
||||
echo '<PRE>';print_r($_SERVER);echo '</PRE>';
|
||||
echo 'ERROR: Cant work out our domain?';
|
||||
die();
|
||||
}
|
||||
|
||||
$domain = '.'.preg_replace('/^www./','',$domain);
|
||||
}
|
||||
|
||||
if ($expire)
|
||||
$cookie_expire = 0;
|
||||
elseif (COOKIE_EXPIRE == 0)
|
||||
$cookie_expire = (time()+86400*365);
|
||||
else
|
||||
$cookie_expire = (time() + (COOKIE_EXPIRE*60));
|
||||
if(empty($domain) || preg_match('/localhost/', $domain))
|
||||
setcookie(COOKIE_NAME,$this->id,$cookie_expire,'/');
|
||||
$cookie_expire = (time()+(COOKIE_EXPIRE*60));
|
||||
|
||||
if (empty($domain) || preg_match('/localhost/',$domain))
|
||||
setcookie(COOKIE_NAME,$this->id,$cookie_expire,'/');
|
||||
else
|
||||
setcookie(COOKIE_NAME,$this->id,$cookie_expire,'/', $domain);
|
||||
setcookie(COOKIE_NAME,$this->id,$cookie_expire,'/',$domain);
|
||||
|
||||
# Affiliate Cookie
|
||||
if(!empty($this->sess_affiliate_id)) {
|
||||
$aid_expire = time()+86400*720;
|
||||
$aid_cookie_name = COOKIE_NAME . 'aid';
|
||||
if(empty($domain) || eregi('localhost', $domain))
|
||||
setcookie($aid_cookie_name, $this->sess_affiliate_id, $aid_expire,'/');
|
||||
if (! empty($this->aid)) {
|
||||
$aid_cookie_name = COOKIE_NAME.'aid';
|
||||
if ($expire)
|
||||
$aid_expire = 0;
|
||||
else
|
||||
setcookie($aid_cookie_name, $this->sess_affiliate_id, $aid_expire,'/', $domain);
|
||||
$aid_expire = time()+86400*720;
|
||||
|
||||
if (empty($domain) || preg_match('/localhost/',$domain))
|
||||
setcookie($aid_cookie_name,$this->aid,$aid_expire,'/');
|
||||
else
|
||||
setcookie($aid_cookie_name,$this->aid,$aid_expire,'/',$domain);
|
||||
}
|
||||
|
||||
# Campaign Cookie
|
||||
if(!empty($this->sess_campaign_id)) {
|
||||
$cid_expire = time()+86400*720;
|
||||
$cid_cookie_name = COOKIE_NAME . 'caid';
|
||||
if(empty($domain) || eregi('localhost', $domain))
|
||||
setcookie($cid_cookie_name, $this->sess_campaign_id, $cid_expire,'/');
|
||||
if (! empty($this->caid)) {
|
||||
$cid_cookie_name = COOKIE_NAME.'caid';
|
||||
if ($expire)
|
||||
$cid_expire = 0;
|
||||
else
|
||||
setcookie($cid_cookie_name, $this->sess_campaign_id, $cid_expire,'/', $domain);
|
||||
$cid_expire = time()+86400*720;
|
||||
|
||||
if (empty($domain) || preg_match('/localhost/',$domain))
|
||||
setcookie($cid_cookie_name,$this->caid,$cid_expire,'/');
|
||||
else
|
||||
setcookie($cid_cookie_name,$this->caid,$cid_expire,'/',$domain);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_session_link($id,$type) {
|
||||
global $VAR;
|
||||
|
||||
function get_affiliate($old_aid) {
|
||||
global $_COOKIE, $VAR;
|
||||
$aid_cookie_name = COOKIE_NAME.'aid';
|
||||
if(isset($VAR['aid']))
|
||||
$aid = $VAR['aid'];
|
||||
else if(isset($_COOKIE[$aid_cookie_name]))
|
||||
@$aid = $_COOKIE[$aid_cookie_name];
|
||||
else if(isset($HTTP_COOKIE_VARS[$aid_cookie_name]))
|
||||
@$aid = $HTTP_COOKIE_VARS[$aid_cookie_name];
|
||||
if ($aid == $old_aid) {
|
||||
return $aid;
|
||||
} else if (empty($aid)) {
|
||||
switch($type) {
|
||||
case 'affiliate' : $var = 'aid'; $table = 'affiliate'; break;
|
||||
case 'campaign' : $var = 'caid'; $table = 'campaign'; break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
$cookie_name = sprintf('%s%s',COOKIE_NAME,$var);
|
||||
|
||||
if (isset($VAR[$var]))
|
||||
$i = $VAR[$var];
|
||||
elseif (isset($_COOKIE[$cookie_name]))
|
||||
$i = $_COOKIE[$cookie_name];
|
||||
|
||||
if (empty($i))
|
||||
return '';
|
||||
} else {
|
||||
// validate
|
||||
elseif ($i == $id)
|
||||
return $i;
|
||||
|
||||
# Validate
|
||||
else {
|
||||
$db = &DB();
|
||||
$q = "SELECT id,account_id FROM " . AGILE_DB_PREFIX . "affiliate
|
||||
WHERE id = ".$db->qstr($aid)." AND
|
||||
site_id = ".$db->qstr(DEFAULT_SITE);
|
||||
@$result = $db->Execute($q);
|
||||
if(@$result->fields['id'] == $aid)
|
||||
return $aid;
|
||||
$rs = $db->Execute(sqlSelect($table,'id',array('where'=>array('id'=>$i))));
|
||||
if ($rs && $rs->RecordCount())
|
||||
return $i;
|
||||
else
|
||||
return '';
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_campaign($old_cid) {
|
||||
global $_COOKIE, $VAR;
|
||||
$cid_cookie_name = COOKIE_NAME.'caid';
|
||||
if(isset($VAR['caid']))
|
||||
$cid = $VAR['caid'];
|
||||
else if(isset($_COOKIE[$cid_cookie_name]))
|
||||
@$cid = $_COOKIE[$cid_cookie_name];
|
||||
else if(isset($HTTP_COOKIE_VARS[$cid_cookie_name]))
|
||||
@$cid = $HTTP_COOKIE_VARS[$cid_cookie_name];
|
||||
if ($cid == $old_cid) {
|
||||
return $cid;
|
||||
} else if (empty($cid)) {
|
||||
return '';
|
||||
} else {
|
||||
// validate
|
||||
$db = &DB();
|
||||
$q = "SELECT id FROM " . AGILE_DB_PREFIX . "campaign
|
||||
WHERE id = ".$db->qstr($cid)." AND
|
||||
site_id = ".$db->qstr(DEFAULT_SITE);
|
||||
@$result = $db->Execute($q);
|
||||
if(@$result->fields['id'] == $cid)
|
||||
return $cid;
|
||||
else
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_currency($id) {
|
||||
$db = &DB();
|
||||
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'currency WHERE id = ' . $db->qstr($id) . ' AND site_id = ' . $db->qstr(DEFAULT_SITE);
|
||||
$result = $db->Execute($sql);
|
||||
if($result->fields['status'] == 1) return $id;
|
||||
global $VAR; $VAR['cyid'] = DEFAULT_CURRENCY;
|
||||
return DEFAULT_CURRENCY;
|
||||
}
|
||||
|
||||
|
||||
function session() {
|
||||
global $C_debug;
|
||||
mt_srand ((double) microtime() * 1000000);
|
||||
$this->id = md5(uniqid(mt_rand(),1));
|
||||
private function get_currency($id) {
|
||||
$db = &DB();
|
||||
$q = "SELECT id FROM " . AGILE_DB_PREFIX . "session
|
||||
WHERE id = ".$db->qstr($this->id)." AND
|
||||
site_id = '" . DEFAULT_SITE . "'";
|
||||
$result = $db->Execute($q);
|
||||
if ($result === false) {
|
||||
echo "SESSION FAILED: Unable to connect to database";
|
||||
$rs = $db->Execute(sqlSelect('currency','status',array('where'=>array('id'=>$id))));
|
||||
if ($rs && $rs->RecordCount() && $rs->fields['status'] == 1)
|
||||
return $id;
|
||||
|
||||
global $VAR;
|
||||
$VAR['cyid'] = DEFAULT_CURRENCY;
|
||||
|
||||
return DEFAULT_CURRENCY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a session
|
||||
*/
|
||||
private function session() {
|
||||
global $C_debug;
|
||||
$db = &DB();
|
||||
|
||||
mt_srand((double)microtime()*1000000);
|
||||
$this->id = md5(uniqid(mt_rand(),1));
|
||||
|
||||
$rs = $db->Execute(sqlSelect('session','id',array('where'=>array('id'=>$this->id))));
|
||||
if (! $rs) {
|
||||
echo 'SESSION FAILED: Unable to connect to database';
|
||||
|
||||
exit;
|
||||
} if($result->RecordCount() == 0) {
|
||||
$expires = time() + (SESSION_EXPIRE*60);
|
||||
$db = &DB();
|
||||
$q = "INSERT INTO " . AGILE_DB_PREFIX . "session SET
|
||||
id = ".$db->qstr($this->id).",
|
||||
date_orig = ".$db->qstr(time()).",
|
||||
date_last = ".$db->qstr(time()).",
|
||||
date_expire = ".$db->qstr($expires).",
|
||||
logged = ".$db->qstr('0').",
|
||||
ip = ".$db->qstr(USER_IP).",
|
||||
site_id = ".$db->qstr(DEFAULT_SITE).",
|
||||
affiliate_id= ".$db->qstr($this->sess_affiliate_id).",
|
||||
reseller_id = ".$db->qstr($this->sess_reseller_id).",
|
||||
country_id = ".$db->qstr($this->sess_country_id).",
|
||||
language_id = ".$db->qstr($this->sess_language_id).",
|
||||
currency_id = ".$db->qstr($this->sess_currency_id).",
|
||||
weight_id = ".$db->qstr($this->sess_weight_id).",
|
||||
theme_id = ".$db->qstr($this->sess_theme_id).",
|
||||
campaign_id = ".$db->qstr($this->sess_campaign_id);
|
||||
$result = $db->Execute($q);
|
||||
if ($result === false) {
|
||||
$C_debug->error('session.inc.php','validate', $db->ErrorMsg());
|
||||
echo 'Unable to start session: Db error<RB><BR>' . $q . '<BR><BR>' . $db->ErrorMsg();
|
||||
}
|
||||
|
||||
if (! $rs->RecordCount()) {
|
||||
$rs = $db->Execute(
|
||||
sqlInsert($db,'session',array(
|
||||
'date_orig'=>time(),
|
||||
'date_last'=>time(),
|
||||
'date_expire'=>$this->sess_date_expire,
|
||||
'affiliate_id'=>$this->aid,
|
||||
'reseller_id'=>$this->rid,
|
||||
'country_id'=>$this->cid,
|
||||
'language_id'=>$this->lid,
|
||||
'currency_id'=>$this->cyid,
|
||||
'weight_id'=>$this->wid,
|
||||
'theme_id'=>$this->tid,
|
||||
'campaign_id'=>$this->caid,
|
||||
'logged'=>0,
|
||||
'ip'=>USER_IP
|
||||
),$this->id));
|
||||
|
||||
if (! $rs) {
|
||||
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
||||
printf('Unable to start session: Db error<br/><br/>%s<br/><br/>%s',$q,$db->ErrorMsg());
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function logout($sess) {
|
||||
private function logout($sess) {
|
||||
$db = &DB();
|
||||
$q = "UPDATE " . AGILE_DB_PREFIX . "session SET logged = '0' WHERE
|
||||
id = '$sess' AND
|
||||
site_id = '" . DEFAULT_SITE . "'";
|
||||
$result = $db->Execute($q);
|
||||
if ($result === false) {
|
||||
|
||||
$rs = $db->Execute(sqlUpdate($db,'session',array('logged'=>0),array('id'=>$sess)));
|
||||
if (! $rs) {
|
||||
global $C_debug;
|
||||
$C_debug->error('session.inc.php','logout', $db->ErrorMsg());
|
||||
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$q = 'DELETE FROM '.AGILE_DB_PREFIX.'session_auth_cache WHERE
|
||||
session_id = '. $db->qstr($sess) .' AND
|
||||
site_id = '. $db->qstr(DEFAULT_SITE);
|
||||
$db->Execute($q);
|
||||
$db->Execute(sqlDelete($db,'session_auth_cache',array('session_id'=>$sess)));
|
||||
|
||||
define('FORCE_SESS_ACCOUNT', 0);
|
||||
define('FORCE_SESS_LOGGED', FALSE);
|
||||
define('FORCE_SESS_ACCOUNT',0);
|
||||
define('FORCE_SESS_LOGGED',false);
|
||||
|
||||
if (CACHE_SESSIONS == '1') {
|
||||
$VAR['_login'] = '1';
|
||||
$force = true;
|
||||
$C_auth = new CORE_auth($force);
|
||||
|
||||
if(CACHE_SESSIONS == '1') {
|
||||
$VAR['_login'] = '1';
|
||||
$force = true;
|
||||
$C_auth = new CORE_auth($force);
|
||||
global $C_auth2;
|
||||
$C_auth2 = $C_auth;
|
||||
}
|
||||
$C_auth2 = $C_auth;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function delete($sess) {
|
||||
global $C_debug;
|
||||
|
||||
/**
|
||||
* Delete a session
|
||||
*/
|
||||
private function delete($sess) {
|
||||
$db = &DB();
|
||||
$q = "DELETE FROM " . AGILE_DB_PREFIX . "session WHERE id = '$sess' AND site_id = '" . DEFAULT_SITE . "'";
|
||||
$result = $db->Execute($q);
|
||||
if ($result === false) $C_debug->error('session.inc.php','delete', $db->ErrorMsg());
|
||||
}
|
||||
|
||||
|
||||
function session_constant() {
|
||||
# Define the constants
|
||||
define ('SESS_THEME', $this->sess_theme_id);
|
||||
define ('SESS_COUNTRY', $this->sess_country_id);
|
||||
define ('SESS_LANGUAGE', $this->sess_language_id);
|
||||
define ('SESS_CURRENCY', $this->sess_currency_id);
|
||||
define ('SESS_WEIGHT', $this->sess_weight_id);
|
||||
define ('SESS_RESELLER', $this->sess_reseller_id);
|
||||
define ('SESS_AFFILIATE', $this->sess_affiliate_id);
|
||||
define ('SESS_CAMPAIGN', $this->sess_campaign_id);
|
||||
}
|
||||
|
||||
|
||||
function session_constant_log() {
|
||||
global $VAR;
|
||||
if(isset($VAR['_login']) || isset($VAR['_logout'])) {
|
||||
$db = &DB();
|
||||
$q = "SELECT logged,account_id FROM " . AGILE_DB_PREFIX . "session
|
||||
WHERE id = " . $db->qstr($this->id) . "
|
||||
AND site_id = " . $db->qstr(DEFAULT_SITE);
|
||||
$result = $db->Execute($q);
|
||||
$rs = $db->Execute(sqlDelete($db,'session',array('id'=>$sess)));
|
||||
if (! $rs === false) {
|
||||
global $C_debug;
|
||||
if ($result === false) $C_debug->error('session.inc.php','session_constant', $db->ErrorMsg());
|
||||
if(!defined("SESS_LOGGED"))
|
||||
define ('SESS_LOGGED', $result->fields['logged']);
|
||||
if(!defined("SESS_ACCOUNT"))
|
||||
define ('SESS_ACCOUNT', $result->fields['account_id']);
|
||||
} else {
|
||||
if(!defined("SESS_LOGGED"))
|
||||
define ('SESS_LOGGED', $this->sess_logged);
|
||||
if(!defined("SESS_ACCOUNT"))
|
||||
define ('SESS_ACCOUNT', $this->sess_account_id);
|
||||
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the session constants
|
||||
*/
|
||||
public function session_constant() {
|
||||
# Define the constants
|
||||
define('SESS_THEME',$this->tid);
|
||||
define('SESS_LANGUAGE',$this->lid);
|
||||
define('SESS_COUNTRY',$this->cid);
|
||||
define('SESS_CURRENCY',$this->cyid);
|
||||
define('SESS_WEIGHT',$this->wid);
|
||||
define('SESS_RESELLER',$this->rid);
|
||||
define('SESS_AFFILIATE',$this->aid);
|
||||
define('SESS_CAMPAIGN',$this->caid);
|
||||
}
|
||||
|
||||
public function session_constant_log() {
|
||||
global $VAR;
|
||||
|
||||
if (isset($VAR['_login']) || isset($VAR['_logout'])) {
|
||||
$db = &DB();
|
||||
|
||||
$rs = $db->Execute(sqlSelect('session','logged,account_id',array('where'=>array('id'=>$this->id))));
|
||||
|
||||
if (! $rs) {
|
||||
global $C_debug;
|
||||
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! defined('SESS_LOGGED'))
|
||||
define('SESS_LOGGED',$rs->fields['logged']);
|
||||
if (! defined('SESS_ACCOUNT'))
|
||||
define('SESS_ACCOUNT',$rs->fields['account_id']);
|
||||
|
||||
} else {
|
||||
if (! defined('SESS_LOGGED'))
|
||||
define('SESS_LOGGED',$this->sess_logged);
|
||||
if (! defined('SESS_ACCOUNT'))
|
||||
define('SESS_ACCOUNT',$this->sess_account_id);
|
||||
}
|
||||
|
||||
if(SESS_LOGGED)
|
||||
define ('SESS_EXPIRES', $this->sess_date_expire);
|
||||
if (SESS_LOGGED)
|
||||
define('SESS_EXPIRES',$this->sess_date_expire);
|
||||
else
|
||||
define ('SESS_EXPIRES', 0);
|
||||
}
|
||||
define('SESS_EXPIRES',0);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user