Location: PHPKode > projects > RabbitBB - Online Web Storage Project > mywebdrive/PHP_CON/general/BSGAuthRight.php
<?PHP

class BSGAuthRight
{
	var $daoc = null;
	var $tfiledirdb = null;
	var $p_dirname;
	var $p_user_id;
	var $p_ownerid;
	var $p_keypass;
	var $p_vartype;

	var $p_authright;
	
	function BSGAuthRight()
	{
		$this->daoc = new DAOGetFileDirAttr();
	}

	function savevar($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$this->p_dirname = $_dirname;
		$this->p_user_id = $_user_id;
		$this->p_ownerid = $_ownerid;
		$this->p_keypass = $_keypass;
		$this->p_vartype = $_vartype;
	}
	function samevar($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		if ($this->p_dirname!=$_dirname)
			return false;
		if ($this->p_user_id!=$_user_id)
			return false;
		if ($this->p_ownerid!=$_ownerid)
			return false;
		if ($this->p_keypass!=$_keypass)
			return false;
		if ($this->p_vartype!=$_vartype)
			return false;
		return true;
	}

	function checkDirRead($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_dirname, DIRECTORY,
			$_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright!=null)
		{
			if ($authright->getread()=="Y")
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}

	/*function checkDirWrite($_dirname, $_user_id, $_ownerid, $_keypass)
	{
		$authright = $this->checkBasicAuth($_dirname, DIRECTORY, $_user_id, $_ownerid, true, true, $_keypass);
		if ($authright!=null)
		{
			if ($authright->gerwrite()==true)
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}*/

	function checkDirCreateDir($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_dirname, DIRECTORY, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright != null)
		{
			if ($authright->getcreatedir()=="Y")
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}

	function checkDirUpdateDir($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_dirname, DIRECTORY, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright != null)
		{
			if ($authright->getupdatedir()=="Y")
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}

	function checkDirDelDir($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_dirname, DIRECTORY, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright != null)
		{
			if ($authright->getdeldir()=="Y")
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}

	function checkDirCreateFile($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_dirname, DIRECTORY, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright != null)
		{
			if ($authright->getcreatefile()=="Y")
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}

	function checkDirUpdateFile($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_dirname, DIRECTORY, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright != null)
		{
			if ($authright->getupdatefile()=="Y")
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}

	function checkDirDelFile($_dirname, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_dirname, DIRECTORY, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright != null)
		{
			if ($authright->getdelfile()=="Y")
			{
				return true;;
			}
			else
				return false;
		}
		else
			return false;
	}

	function checkFileWrite($_filename, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_filename, SFILE, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright != null)
		{
			if ($authright->getwrite())
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;

	}

	function checkFileRead($_filename, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		$authright = $this->getBasicAuth($_filename, SFILE, $_user_id, $_ownerid, $_keypass, $_vartype);
		if ($authright!=null)
		{
			if ($authright->getread())
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;

	}

	function getBasicAuth($_filename, $_type, $_user_id, $_ownerid, $_keypass, $_vartype=FILENAME)
	{
		if ($this->samevar($_filename, $_user_id, $_ownerid, $_keypass, $_vartype))
			return $this->rauth;
		else
			$this->savevar($_filename, $_user_id, $_ownerid, $_keypass, $_vartype);
		$rauth = null;
		if ($_vartype == FILENAME)
			$filedirdb = $this->daoc->getFileDirAttr($_ownerid, $_filename, $_type);
		elseif ($_vartype == ID)
		{
			if ($_type==SFILE)
				$filedirdb = $this->daoc->getFileById($_filename);
			else
				$filedirdb = $this->daoc->getDirById($_filename);
		}
		if ($filedirdb==null)
			return null;
		return $this->getBasicAuthWFileDirDb($filedirdb, $_user_id, $_ownerid);
	}
			
	function getBasicAuthWFileDirDb($filedirdb, $_user_id, $_ownerid)
	{

		$rauth = $this->returnAuth($filedirdb, $_user_id);
		if ($rauth==null)
		{
			$rauth = $this->getPreAuth($filedirdb, $_user_id);
			if ($rauth==null)
			{
				if ($_user_id==$_ownerid)
				{
					if ($filedirdb->gettype()==SFILE)
					{
						$rauth = new UserFileParamAttr(0, 0, 0, 0, "Y", "Y");
					}
					else
					{
						$rauth = new UserDirParamAttr(0, 0, 0, 0,
								"Y", "Y", "Y", "Y", "Y", "Y", "Y");
					}
				}
			}
		}
		
		$this->tfiledirdb = $filedirdb;

		$this->rauth = $rauth;

		return $rauth;
	}

	function getfiledirdb() { return $this->tfiledirdb; }

	function getPreAuth($_filedirdb, $_user_id)
	{
		if ($_filedirdb->getpid()!=0)
		{
			$filedirdb = $this->daoc->getFileDirAttrById($_filedirdb->getpid(), $_filedirdb->getownerid());
			if ($filedirdb!=null)
			{
				$rauth = $this->returnAuth($filedirdb, $_user_id);
				if ($rauth == null)
				{
					return $this->getPreAuth($filedirdb, $_user_id);
				}
				else
					return $rauth;
			}
		}
		else
		{
			return null;
		}
	}

	function returnAuth($_filedirdb, $_user_id)
	{
		if ($_filedirdb==null)
			return null;
		$rauth = null;
		
		if (!NSession::check_login())
		{
			// Check the file is allowed to access from public or no			
			$bsga = new BSGPublicAuth();
			$rauth = $bsga->publicAuth($_filedirdb);
			unset($bsga);

		}
		else
		{
			$bsua = new BSGUserAuthAttr();
			$rauth = $bsua->getAuth($_filedirdb, $_user_id);
			unset($bsua);

			if ($rauth==null)
			{
				$bsga = new BSGGroupAuthAttr();
				$rauth = $bsga->getAuth($_filedirdb, $_user_id);
				unset($bsga);
			}
			
		}
		return $rauth;
	}
}

?>
Return current item: RabbitBB - Online Web Storage Project