<commit_before><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2008 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
* 																										*
* 	class_session.php																					*
* 	Session Management / Login/Logout Management														*
*																										*
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                            *
********************************************************************************************************/

/**
 * Manages all those session stuff as logins or logouts and access to session vars
 *
 * @package modul_system
 */
final class class_session {

	private $arrModul;
	private $objDB;
	private $strKey;

	private static  $objSession = null;


	private function __construct() 	{
		$this->arrModul["name"] 		= "class_session";
		$this->arrModul["author"] 		= "<EMAIL>";

		//Loading the needed Objects
		$objCarrier = class_carrier::getInstance();
		$this->objDB = $objCarrier->getObjDB();

		//Generating a session-key
		$this->strKey = md5(_realpath_);

		if($this->sessionStart()) {
			if(!$this->sessionIsset("status"))
				$this->setSession("status", "loggedout");
		}
	}

	/**
	 * Returns one Instance of the Session-Object, using a singleton pattern
	 *
	 * @return class_session The Session-Object
	 */
	public static function getInstance() {
		if(self::$objSession == null) {
			self::$objSession = new class_session();
		}

		return self::$objSession;
	}

	/**
	 * Starts a session
	 *
	 * @return bool
	 */
	private function sessionStart() {
		//New seesion needes, oder using the already started?
		if(!session_id()) {
			if(session_start())
				$bitReturn = true;
			else
				$bitReturn = false;
		}
		else
			$bitReturn = true;

		return $bitReturn;
	}

	/**
	 * Writes a value to the session
	 *
	 * @param string $strKey
	 * @param string $strValue
	 * @return bool
	 */
	public function setSession($strKey, $strValue) 	{
		if($_SESSION[$this->strKey][$strKey] = $strValue)
			return true;
		else
			return false;
	}

	/**
	 * Setter for captcha-codes. use ONLY this method to set the code.
	 *
	 * @param string $strCode
	 */
	public function setCaptchaCode($strCode) {
	    $this->setSession("kajonaCaptchaCode", $strCode);
	}

	/**
	 * Returns the captcha code generated the last time.
	 * the code is being reset, so later requests will return a new systemid
	 * forcing the comparison to fail.
	 *
	 * @return string
	 */
	public function getCaptchaCode() {
	    $strCode = $this->getSession("kajonaCaptchaCode");
	    //reset code
	    $this->setSession("kajonaCaptchaCode", "");
	    if($strCode == "")
	       $strCode = generateSystemid();
	       
	    return $strCode;
	}

	/**
	 * Returns a value from the session
	 *
	 * @param string $strKey
	 * @return string
	 */
	public function getSession($strKey) {
		if(!isset($_SESSION[$this->strKey][$strKey]))
			return false;
		else
			return $_SESSION[$this->strKey][$strKey];
	}

	/**
	 * Checks if a key exists in the current session
	 *
	 * @param string $strKey
	 * @return bool
	 */
	public function sessionIsset($strKey) {
		if(isset($_SESSION[$this->strKey][$strKey]))
			return true;
		else
			return false;
	}

	/**
	 * Deletes a value from the session
	 *
	 * @param string $strKey
	 */
	public function sessionUnset($strKey) {
		if($this->sessionIsset($strKey))
			unset($_SESSION[$this->strKey][$strKey]);
	}

	/**
	 * Checks if the current user is logged in
	 *
	 * @return bool
	 */
	public function isLoggedin() {
		if($this->sessionIsset("status") && $this->getSession("status") == $this->getLoggedinKey())<commit_msg>NEW: when writing values to class session, you can choose between the session or request lifecycle to hold the values. can be usefull to share values between different classes per request instead of holding them over the whole session<commit_after><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2008 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
* 																										*
* 	class_session.php																					*
* 	Session Management / Login/Logout Management														*
*																										*
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                            *
********************************************************************************************************/

/**
 * Manages all those session stuff as logins or logouts and access to session vars
 *
 * @package modul_system
 */
final class class_session {

	private $arrModul;
	private $objDB;
	private $strKey;
	
	private $arrRequestArray;
	
	public static $intScopeSession = 1;
	public static $intScopeRequest = 2;

	private static $objSession = null;


	private function __construct() 	{
		$this->arrModul["name"] 		= "class_session";
		$this->arrModul["author"] 		= "<EMAIL>";

		//Loading the needed Objects
		$objCarrier = class_carrier::getInstance();
		$this->objDB = $objCarrier->getObjDB();

		//Generating a session-key
		$this->strKey = md5(_realpath_);

		if($this->sessionStart()) {
			if(!$this->sessionIsset("status"))
				$this->setSession("status", "loggedout");
		}
		
		$this->arrRequestArray = array();
	}
	
	private function __desctruct() {
		$this->arrRequestArray = null;
	}

	/**
	 * Returns one Instance of the Session-Object, using a singleton pattern
	 *
	 * @return class_session The Session-Object
	 */
	public static function getInstance() {
		if(self::$objSession == null) {
			self::$objSession = new class_session();
		}

		return self::$objSession;
	}

	/**
	 * Starts a session
	 *
	 * @return bool
	 */
	private function sessionStart() {
		//New seesion needes, oder using the already started?
		if(!session_id()) {
			if(session_start())
				$bitReturn = true;
			else
				$bitReturn = false;
		}
		else
			$bitReturn = true;

		return $bitReturn;
	}

	/**
	 * Writes a value to the session
	 *
	 * @param string $strKey
	 * @param string $strValue
	 * @param int $intSessionScope one of class_session::$intScopeRequest or class_session::$intScopeSession
	 * @return bool
	 */
	public function setSession($strKey, $strValue, $intSessionScope = 1) 	{
		
		if($intSessionScope == class_session::$intScopeRequest) {
		    $this->arrRequestArray[$strKey] = $strValue;
		    return true;	
		}
		else {
			if($_SESSION[$this->strKey][$strKey] = $strValue)
				return true;
			else
				return false;
		}
	}

	/**
	 * Setter for captcha-codes. use ONLY this method to set the code.
	 *
	 * @param string $strCode
	 */
	public function setCaptchaCode($strCode) {
	    $this->setSession("kajonaCaptchaCode", $strCode);
	}

	/**
	 * Returns the captcha code generated the last time.
	 * the code is being reset, so later requests will return a new systemid
	 * forcing the comparison to fail.
	 *
	 * @return string
	 */
	public function getCaptchaCode() {
	    $strCode = $this->getSession("kajonaCaptchaCode");
	    //reset code
	    $this->setSession("kajonaCaptchaCode", "");
	    if($strCode == "")
	       $strCode = generateSystemid();
	       
	    return $strCode;
	}

	/**
	 * Returns a value from the session
	 *
	 * @param string $strKey
	 * @param int $intScope one of class_session::$intScopeRequest or class_session::$intScopeSession
	 * @return string
	 */
	public function getSession($strKey, $intScope = 1) {
		if($intScope == class_session::$intScopeRequest) {
			if(!isset($this->arrRequestArray[$strKey]))
			    return false;
			else
    			return $this->arrRequestArray[$strKey];
		}
		else {
			if(!isset($_SESSION[$this->strKey][$strKey]))
				return false;
			else
				return $_SESSION[$this->strKey][$strKey];
		}
	}

	/**
	 * Checks if a key exists in the current session
	 *
	 * @param string $strKey
	 * @return bool
	 */
	public function sessionIsset($strKey) {
		if(isset($_SESSION[$this->strKey][$strKey]))
			return true;
		else
			return false;
	}

	/**
	 * Deletes a value from the session
	 *
	 * @param string $strKey
	 * 
	 */
	public function sessionUnset($strKey) {
		if($this->sessionIsset($strKey))
			unset($_SESSION[$this->strKey][$strKey]);
	}

	/**
	 * Checks if the current user is logged in
	 *
	 * @return bool
	 */
	public function isLoggedin() {
		if($this->sessionIsset("status") && $this->getSession("status") == $this->getLoggedinKey())
{'fraction_non_alphanumeric': 0.20898925198132667, 'fraction_numerical': 0.0045597654977744, 'mean_word_length': 2.386764705882353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6872038', 'n_tokens_mistral': 2924, 'n_tokens_neox': 2556, 'n_words': 668}