<?php

// Using superglobal var $_SESSION and PHP Sessions

class cSessionNamespace extends cSession {
	private $idNs;
	
	function __construct($idNs, $povObj) {
		$this->idNs = $idNs;
		parent::__construct($povObj->oDb, $povObj->oDb2);
		$this->ssid = $povObj->ssid;
		$this->idUser =  $povObj->idUser;
		$this->loginName =  $povObj->loginName;
		$this->nickName =  $povObj->nickName;
		$this->firstName =  $povObj->firstName;
		$this->surName =  $povObj->surName ;
		$this->wholeName =  $povObj->wholeName;
	}
	
	final function generateSql($table, $idMenu, $act) {
		$ret = "SELECT * FROM {$table}
			WHERE id_{$table} IN (SELECT id_{$table} FROM {$table}
				WHERE id_owner = '".$this->idUser."'
				AND owner_type = 'user'
				AND id_menu = '".$idMenu."'
				AND id_namespace = '".$this->idNs."'
				".($table == "perms_init" ? "" : "AND id_element = '".$act."'")."
			) OR id_{$table} IN (SELECT id_{$table} FROM {$table}
				WHERE id_owner IN (SELECT id_group FROM `group_user`
					WHERE id_user = '".$this->idUser."')
				AND owner_type = 'group'
				AND id_menu = '".$idMenu."'
				AND id_namespace = '".$this->idNs."'
				".($table == "perms_init" ? "" : "AND id_element = '".$act."'")."
			) OR id_{$table} IN (SELECT id_{$table} FROM {$table}
				WHERE owner_type = 'public'
				AND id_menu = '".$idMenu."'
				AND id_namespace = '".$this->idNs."'
				".($table == "perms_init" ? "" : "AND id_element = '".$act."'")."
			)";
		return $ret;
	}
	
}

?>
