<?php
/*
Last change in version: 2.1 Alpha 1
#########################################################################################
# ADbNewsSender 2 #
# Copyright (C) 2010 Florian Grannemann (E-mail: hide@address.com) #
# Website: http://adbnewssender.sf.net #
# #
# This program 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 3 of the License, or #
# any later version. #
# #
# This program 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, see http://www.gnu.org/licenses/ #
#########################################################################################
*/
/*
This file defines the session handler for the admin area
*/
//session_start() has to be called before creating an object
//autogenerated session key names:
//general global keys: $keyname
//general moduleeeee specific keys $modulename.$KeyNameSeperator.$keyname
//global nl specific keys: $NLID.$KeyNameSeperator.$keyname
//moduleeee and nl specific keys: $NLID.$KeyNameSeperator.$moduletype.$KeyNameSeperator.$modulenumber.$KeyNameSeperator.$keyname
class ADBNS_SessionHandler{
private $NLIDKeyName="";
private $CurrentModuleTypeKeyName="";
private $CurrentModuleNrKeyName="";
private $KeyNameSeperator="";
function setKey($name, $value)
{
$_SESSION[$name]=$value;
}
function getKeyValue($name)
{
return $_SESSION[$name];
}
function removeKey($name)
{
unset($_SESSION[$name]);
}
function setCurrentModuleType($type)
{
$this->setKey($this->CurrentModuleTypeKeyName,$type);
}
function getCurrentModuleType()
{
return $this->getKeyValue($this->CurrentModuleTypeKeyName);
}
function setCurrentModuleNumber($number)
{
$this->setKey($this->CurrentModuleNrKeyName,intval($number));
}
function getCurrentModuleNumber()
{
return intval($this->getKeyValue($this->CurrentModuleNrKeyName));
}
function getCurrentModule($seperator="|")
{
return $this->getKeyValue($this->CurrentModuleTypeKeyName).$seperator.intval($this->getKeyValue($this->CurrentModuleNrKeyName));
}
function setModuleKey($name, $value)
{
$curModule=$this->getCurrentModule($this->KeyNameSeperator);
if($curModule==$this->KeyNameSeperator)
{
user_error(__CLASS__.": ERROR: The current module is not stored in SESSION! (In method: <b>".__METHOD__."</b>)",E_USER_ERROR);
}
$this->setKey($curModule.$this->KeyNameSeperator.$name,$value);
}
function getModuleKeyValue($name)
{
return $this->getKeyValue($this->getCurrentModule($this->KeyNameSeperator).$this->KeyNameSeperator.$name);
}
function removeModuleKey($name)
{
$this->removeKey($this->getCurrentModule($this->KeyNameSeperator).$this->KeyNameSeperator.$name);
}
function setNLID($nlID)
{
$this->setKey($this->NLIDKeyName,intval($nlID));
}
function getNLID()
{
return intval($this->getKeyValue($this->NLIDKeyName));
}
function setNLKey($name, $value)
{
$nlID=$this->getNLID();
if(!$nlID)
{
user_error(__CLASS__.": ERROR: Newsletter ID is not stored in SESSION! (In method: <b>".__METHOD__."</b>)",E_USER_ERROR);
}
$this->setKey($this->getNLID().$this->KeyNameSeperator.$name,$value);
}
function getNLKeyValue($name)
{
return $this->getKeyValue($this->getNLID().$this->KeyNameSeperator.$name);
}
function removeNLKey($name)
{
$this->removeKey($this->getNLID().$this->KeyNameSeperator.$name);
}
function setNLModuleKey($name, $value)
{
$curModule=$this->getCurrentModule($this->KeyNameSeperator);
if($curModule==$this->KeyNameSeperator)
{
user_error(__CLASS__.": ERROR: The current module is not stored in SESSION! (In method: <b>".__METHOD__."</b>)",E_USER_ERROR);
}
$this->setNLKey($curModule.$this->KeyNameSeperator.$name, $value);
}
function getNLModuleKeyValue($name)
{
return $this->getNLKeyValue($this->getCurrentModule($this->KeyNameSeperator).$this->KeyNameSeperator.$name);
}
function removeNLModuleKey($name)
{
$this->removeNLKey($this->getCurrentModule($this->KeyNameSeperator).$this->KeyNameSeperator.$name);
}
function __construct($nlIDKeyName="CurrentNL",$currentModuleTypeKeyName="currentModuleType", $currentModuleNrKeyName="currentModuleNr", $keyNameSeperator="_")
{
$this->NLIDKeyName=$nlIDKeyName;
$this->CurrentModuleNrKeyName=$currentModuleNrKeyName;
$this->CurrentModuleTypeKeyName=$currentModuleTypeKeyName;
$this->KeyNameSeperator=$keyNameSeperator;
}
}