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

class BSSharePublic
{
	function BSSharePublic()
	{
	}

	function sharePublic($_ownerid, $_dirfile_id)
	{
		$daosp = new DAOSharePublic();
		$rset = $daosp->getPublicAuth($_ownerid, $_dirfile_id);
		if (count($rset[SFILE])>0)
		{
			// Checking
			return $daosp->updateShare($_ownerid, $_dirfile_id);
		}
		else
		{
			$nid = $daosp->newShare($_ownerid, $_dirfile_id);
			if ($nid>0)
				return true;
			else
				return false;
		}
	}

	function getPublicAuth($_ownerid, $_dirfile_id)
	{
		$daosp = new DAOSharePublic();
		$rest = $daosp->getPublicAuth($_ownerid, $_dirfile_id);
		if (count($rest[SFILE])>0)
			return $rest[SFILE][0];
		else
			return new UserFileParamAttr(-1, $_dirfile_id, 
				ANONYMOUS,$_ownerid, "N","N");
	}

	function getDirPublicAuth($_request, $_response)
	{
		$daosp = new DAOSharePublic();
		$rest = $daosp->getDirPublicAuth($_request['ownerid'], $_request['dir_id']);
		if (count($rest[DIRECTORY])>0)
			$_response['publicaccess'] = $rest[DIRECTORY][0];
		else
			$_response['publicaccess'] = new UserDirParamAttr(-1, $_request['dir_id'], 
				ANONYMOUS,$_request['ownerid'], "N","N", "N", "N", "N", "N", "N");
		return $_response;
	}

	function banPublic($_ownerid, $_dirfile_id)
	{
		$daosp = new DAOSharePublic();
		$rset = $daosp->getPublicAuth($_ownerid, $_dirfile_id);
		if (count($rset[SFILE])>0)
		{
			return $daosp->banShare($_ownerid, $_dirfile_id);
		}
		else
			return true;
	}
}

class DAOSharePublic extends DAOGAuth
{
	var $db;
	var $db_table;
	var $db_field;
	
	function DAOSharePublic()
	{
		global $db, $db_table, $db_field;
		$this->db = $db;
		$this->db_table = $db_table;
		$this->db_field = $db_field;
	}

	function getPublicAuth($_ownerid, $_dirfile_id)
	{
		$sqlq = new SQLSelect();
		$sqlq->setSelect($this->db_field['userfileparamattr'],
			$this->db_table['userfileparamattr']);
		$sqlq->setWhere($this->db_table['userfileparamattr'].
			".filedb_id=".$_dirfile_id);

		$sqlq->setWhere($this->db_table['userfileparamattr'].
			".owner=".$_ownerid);
		$sqlq->setWhere($this->db_table['userfileparamattr'].
			".user_id=".ANONYMOUS);
		// Return the array
		//echo ($sqlq->SQLReturn());
		return $this->populate($sqlq->getRow($this->db, $sqlq->SQLReturn()));		
	}

	function getDirPublicAuth($_ownerid, $_dir_id)
	{
		$sqlq = new SQLSelect();
		$sqlq->setSelect($this->db_field['userdirparamattr'],
			$this->db_table['userdirparamattr']);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".dirdb_id=".$_dir_id);

		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".owner=".$_ownerid);
		$sqlq->setWhere($this->db_table['userdirparamattr'].
			".user_id=".ANONYMOUS);
		// Return the array
		return $this->populate($sqlq->getRow($this->db, $sqlq->SQLReturn()));
	}

	function updateShare($_ownerid, $_dirfile_id)
	{
		$sqlq = "UPDATE " . $this->db_table['userfileparamattr'].
			" SET allowread='Y' WHERE filedb_id=$_dirfile_id AND ".
			" owner=".$_ownerid." AND user_id=".ANONYMOUS;
		return $this->db->sql_query($sqlq);
		
	}

	function banShare($_ownerid, $_dirfile_id)
	{
		$sqlq = "UPDATE " . $this->db_table['userfileparamattr'].
			" SET allowread='N' WHERE filedb_id=$_dirfile_id AND ".
			" owner=".$_ownerid." AND user_id=".ANONYMOUS;
		return $this->db->sql_query($sqlq);
	}

	function newShare($_ownerid, $_dirfile_id)
	{
		$sqlq = "INSERT INTO ".$this->db_table['userfileparamattr'].
			" (filedb_id, user_id, owner, allowread, allowwrite)".
			" VALUES (".$_dirfile_id.",".ANONYMOUS.",".$_ownerid.
			", 'Y', 'N')";

		if ($this->db->sql_query($sqlq))
		{
			return $this->db->sql_nextid();
		}
	}
}

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