<?php
/*
* Copyright (c) 2003 gencon Ltd, all rights reserved.
*
* This file is part of v-creator.
*
* v-creator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* v-creator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once(VC_ROOT."/classes/VCSession.php");
/**
* @ingroup VCmodules
* @brief Class for session information.
*
* $Revision: 1.11 $ $Date: 2006-03-13 11:15:47 $
*
* @author Andrew 'Diddymus' Rolfe
*
* This module is used to access information stored in the
* user's current session.
*/
class session {
/**
* @brief Function to setup defines.
*
* When called this function sets up the following
* defines for use with the user module:
*
* <dl>
* <dt>SESSION_LANGUAGE</dt>
* <dd>The user's preffered language.</dd>
* </dl>
*
* @static
*/
function defines() {}
/**
* @brief Function to retrieve session data.
*
* This function is used to retrieve data from the user's session.
* The dataSet values returned are:
*
* <DL>
* <DT>session_value
* <DD>The value of the requested session object.
* </DL>
*
* The following values from VC_data will be used if available:
*
* <DL>
* <DT>session_name
* <DD>The name of the session object to retrieve.
* </DL>
*
* @static
*/
function getDataSet() {
global $VC_data;
$name = VCPage::getVC_data("session_name");
if(!$name) return null;
$data = VCSession::get($VC_data['session_name']);
$VC_data['session_value'] = $data;
}
/**
* @brief Function to set a session value.
*
* This function is used to set the named session object
* to the specified value. The dataSet values returned are:
*
* None.
*
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>session_name</dt>
* <dd>The name of the session object to set.</dd>
* <dt>session_value</dt>
* <dd>The value the object will be set to.</dd>
* </dl>
*
* @static
*/
function set() {
global $VC_data;
$name = VCPage::getVC_data("session_name");
$value = VCPage::getVC_data("session_value");
if (!$name) return;
VCSession::set($name, $value);
}
/**
* @brief Function to get a session value.
*
* This function is used to get the value of a named session
* object. The dataSet values returned are:
*
* <dl>
* <dt>session_value</dt>
* <dd>The value of the named object.</dd>
* </dl>
*
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>session_name</dt>
* <dd>The name of the session object to set.</dd>
* </dl>
*
* @static
*/
function get() {
global $VC_data;
$name = VCPage::getVC_data("session_name");
if (!$name) return;
$VC_data["session_value"] = VCSession::get($name);
}
/**
* @brief Function to delete a session value.
*
* This function is used to delete a named session object.
* There are no dataSet values returned.
*
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>session_name</dt>
* <dd>The name of the session object to delete.</dd>
* </dl>
*
* @static
*/
function delete() {
global $VC_data;
$name = VCPage::getVC_data("session_name");
if (!$name) return;
VCSession::delete($name);
}
/**
* @brief Function to copy a session value.
*
* This function is used to copy a named session object.
* There are no dataSet values returned.
*
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>session_name</dt>
* <dd>The name of the session object to copied.</dd>
* <dt>session_name_new</dt>
* <dd>The name of the new session object.</dd>
* </dl>
*
* @static
*/
function copy() {
global $VC_data;
$name = VCPage::getSafeVC_data('session_name');
$new_name = VCPage::getSafeVC_data('session_name_new');
if (!$name || !$new_name) return;
$session_value = VCSession::get($name);
if ($session_value !== null) VCSession::set($new_name, $session_value);
}
/**
* @brief Function to rename a session value.
*
* This function is used to rename a named session object.
* There are no dataSet values returned.
*
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>session_name</dt>
* <dd>The name of the session object to renamed.</dd>
* <dt>session_name_new</dt>
* <dd>The new name of the session object.</dd>
* </dl>
*
* @static
*/
function rename() {
global $VC_data;
$name = VCPage::getSafeVC_data('session_name');
$new_name = VCPage::getSafeVC_data('session_name_new');
if (!$name || !$new_name) return;
$session_value = VCSession::get($name);
if ($session_value !== null) {
VCSession::set($new_name, $session_value);
}
VCSession::delete($name);
}
/**
* @brief Function to return current session ID if needed.
*
* This function is used to return a session ID but only if it
* is required because cookies are not being used. If called
* and the session ID is required then the current session name
* and session ID will be returned as a name/value pair. For
* example: PHPSESSID=0b5620271f38ae1e88ceea7e77e2b8ba
*
* @static
*/
function checkIdNeeded() {
global $HTTP_COOKIE_VARS;
global $VC_data;
$prefix = VCPage::getSafeVC_data('session_id_prefix');
$sessionName = ini_get('session.name');
if (array_key_exists($sessionName, $HTTP_COOKIE_VARS)) {
return '';
}
$id = ($prefix) ?$prefix:'';
$id .= strip_tags(SID);
return $id;
}
/**
* @brief Function to regenerate the current session ID.
*
* This is a convience function to allow the current session ID to be
* regenerated using a module tag. For example |{session:regenerateId}|
*
* @static
*
* @see VCSession::regenerate
*/
function regenerateId() {
VCSession::regenerate();
}
}
?>