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

class DAOSaveDirProp
{
	var $db;
	var $db_table;
	var $db_field;

	function DAOSaveDirProp()
	{
		global $db, $db_table, $db_field;
		$this->db = $db;
		$this->db_table = $db_table;
		$this->db_field = $db_field;
	}

	function getownerdiraccess($_dirdb_id, $_ownerid)
	{
		$sqlq= new SQLSelect();
		$sqlq->setSelect($this->db_field['userdirparamattr'],
			$this->db_table['userdirparamattr']);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".user_id=".$this->db_table['userdirparamattr'].
			".owner");
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".dirdb_id=".$_dirdb_id);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".owner=".$_ownerid);
		//echo($sqlq->SQLReturn(). "<br />");
		$result = ($sqlq->getRow($this->db, $sqlq->SQLReturn()));
		if (isset($result['userdirparamattr']) && (count($result['userdirparamattr'])>0))
			return true;
		else
			return false;
	}

	function getpublicdiraccess($_dirdb_id, $_ownerid)
	{
		$sqlq= new SQLSelect();
		$sqlq->setSelect($this->db_field['userdirparamattr'],
			$this->db_table['userdirparamattr']);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".user_id=".ANONYMOUS);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".dirdb_id=".$_dirdb_id);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".owner=".$_ownerid);
		//echo($sqlq->SQLReturn(). "<br />");
		$result = ($sqlq->getRow($this->db, $sqlq->SQLReturn()));
		if (isset($result['userdirparamattr']) && (count($result['userdirparamattr'])>0))
			return true;
		else
			return false;
	}

	function updateownerdiraccess($_dirdb_id, $_ownerid, $_ownerwriteaccess)
	{
		$sqlq = "UPDATE ".$this->db_table['userdirparamattr']." SET ".
		//@reset($_ownerwriteaccess);
		$_testr = "";
		foreach ($_ownerwriteaccess as $_key => $_value)
		{
			if (strlen($_testr)>0)
				$_testr.=",";
			$_testr .= $_key."='".$_value."'";
		}

		$sqlq.=$_testr . " WHERE dirdb_id=".$_dirdb_id." AND user_id=$_ownerid".
			" AND owner=".$_ownerid;
		//echo($sqlq. "<br />");
		//return true;
		if ($this->db->sql_query($sqlq, BEGIN_TRANSACTION))
		{
			return true;
		}
		else
			return false;
	}

	function updatepublicdiraccess($_dirdb_id, $_ownerid, $_publicreadaccess)
	{
		$sqlq = "UPDATE ".$this->db_table['userdirparamattr']." SET ".
		$_testr = "";
		foreach ($_publicreadaccess as $_key => $_value)
		{
			if (strlen($_testr)>0)
				$_testr.=",";
			$_testr .= $_key."='".$_value."'";
		}

		$sqlq.=$_testr." WHERE dirdb_id=".$_dirdb_id." AND user_id=".ANONYMOUS.
			" AND owner=".$_ownerid;
		//echo($sqlq. "\n");
		//return true;
		if ($this->db->sql_query($sqlq))
		{
			return true;
		}
		else
			return false;
	}

	function insertownerdiraccess($_dirdb_id, $_ownerid, $_ownerwriteaccess)
	{
		$sqlq = "INSERT INTO ".$this->db_table['userdirparamattr']." (dirdb_id,".
			" user_id, owner, ";
		$testr = "";
		$teval = "";

		foreach($_ownerwriteaccess as $_key => $_value)
		{
			if (strlen($testr)>0)
				$testr .= ",";
			if (strlen($teval)>0)
				$teval .= ",";
			$testr .= $_key;
			$teval .= "'".$_value."'";
		}
		$sqlq .= $testr . ") VALUES ($_dirdb_id, $_ownerid, $_ownerid, ".$teval.")";
		
		//echo($sqlq. "\n");
		//return true;
		if ($this->db->sql_query($sqlq, BEGIN_TRANSACTION))
		{
			return true;
		}
		else
			return false;
	}

	function insertpublicdiraccess($_dirdb_id, $_ownerid, $_publicreadaccess)
	{
		$sqlq = "INSERT INTO ".$this->db_table['userdirparamattr']." (dirdb_id,".
			" user_id, owner, ";
		$testr = "";
		$teval = "";

		foreach($_publicreadaccess as $_key => $_value)
		{
			if (strlen($testr)>0)
				$testr .= ",";
			if (strlen($teval)>0)
				$teval .= ",";
			$testr .= $_key;
			$teval .= "'".$_value."'";
		}
		$sqlq .= $testr . ") VALUES ($_dirdb_id, ".ANONYMOUS.", $_ownerid, ".$teval.")";
		//echo($sqlq . "\n");
		//return true;
		if ($this->db->sql_query($sqlq))
		{
			return true;
		}
		else
			return false;
	}

	function deluseraccess($_dirdb_id, $_userid, $_owner)
	{
		for ($i=0; $i<count($_userid); $i++)
		{
			if (!is_numeric($_userid[$i]))
				continue;
			$sqlq="DELETE FROM ".$this->db_table['userdirparamattr'].
				" WHERE dirdb_id=".$_dirdb_id. " AND user_id=".
				$_userid[$i]." AND owner=".$_owner;
			//echo($sqlq. "<br />");
			if ($this->db->sql_query($sqlq)==false)
				return false;
		}
		return true;
	}

	function getuserdiraccess($_dirdb_id, $_userid, $_ownerid)
	{
		$sqlq= new SQLSelect();
		$sqlq->setSelect($this->db_field['userdirparamattr'],
			$this->db_table['userdirparamattr']);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".user_id=".$_userid);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".dirdb_id=".$_dirdb_id);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".owner=".$_ownerid);
			//echo($sqlq->SQLReturn(). "<br />");
		$result = ($sqlq->getRow($this->db, $sqlq->SQLReturn()));
		if (isset($result['userdirparamattr']) && (count($result['userdirparamattr'])>0))
			return true;
		else
			return false;
	}

	function updateuserdiraccess($_dirdb_id, $_userid, $_ownerid, $_read)
	{
		$sqlq = "UPDATE ".$this->db_table['userdirparamattr']." SET ".
		$_testr = "";
		foreach ($_read as $_key => $_value)
		{
			if (strlen($_testr)>0)
				$_testr.=",";
			$_testr .= $_key."='".$_value."'";
		}
		$sqlq.=$_testr." WHERE dirdb_id=".$_dirdb_id." AND user_id=$_userid".
			" AND owner=".$_ownerid;
		//echo($sqlq. "<br />");
		//return true;
		if ($this->db->sql_query($sqlq))
		{
			return true;
		}
		else
			return false;
	}

	function insertuserdiraccess($_dirdb_id, $_userid, $_ownerid, $_read)
	{
		$sqlq = "INSERT INTO ".$this->db_table['userdirparamattr']." (dirdb_id,".
			" user_id, owner, ";
		$testr = "";
		$teval = "";

		foreach($_read as $_key => $_value)
		{
			if (strlen($testr)>0)
				$testr .= ",";
			if (strlen($teval)>0)
				$teval .= ",";
			$testr .= $_key;
			$teval .= "'".$_value."'";
		}
		$sqlq.= $testr . ") VALUES ($_dirdb_id, $_userid, $_ownerid, " . $teval.
			")";

		
		//echo($sqlq. "<br />");
		//return true;
		if ($this->db->sql_query($sqlq))
		{
			return true;
		}
		else
			return false;
	}

	function rollback()
	{
		$this->db->sql_query("", ROLLBACK);
	}
	function commit()
	{
		$this->db->sql_query("", END_TRANSACTION);
	}
}

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