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

class BSSaveDirProp
{
	function BSSaveDirProp()
	{
	}

	function savedirprop($_request, $_response)
	{
		$_response = $this->_savedirprop($_request, $_response);
		if ($_response['result']==false)
			return $_response;

		if (isset($_request['recursiveupdate']) && ($_request['recursiveupdate']=="Y"))
		{
			$_response = $this->recursiveupdate($_request, $_response);
		}
		return $_response;
	}

	function recursiveupdate($_request, $_response)
	{
		$daoru = new DAORecursiveUpdate();
		$tdirlist = $daoru->getChildDir($_request['dir_id']);
		$tfilelist = $daoru->getChildFile($_request['dir_id']);

		//print_r($tdirlist);
		//print_r($tfilelist);

		for ($i=0; $i<count($tdirlist); $i++)
		{
			$_request['dir_id'] = $tdirlist[$i]->getid();
			$_request['tfiledirdb'] = $tdirlist[$i];
			$_response = $this->savedirprop($_request, $_response);
			$_request['tfiledirdb'] = null;
		}
		$bssfp = new BSSaveFileProp();
		
		for ($i=0; $i<count($tfilelist); $i++)
		{
			$_response['result'] = $bssfp->savefileprop($tfilelist[$i]->getid(), $_request['ownerid'],
							$_request['ownerwriteaccess'], $_request['publicreadaccess'],
							$_request['diruseraccess'], $_request['diruseraccessdel']);
		}

		return $_response;
	}

	function _savedirprop($_request, $_response)
	{
		$daogf = new DAOGetFileDirAttr();
		if (isset($_request['tfiledirdb']) && ($_request['tfiledirdb']!=null))
			$filedirdb = $_request['tfiledirdb'];
		else
			$filedirdb = $daogf->getDirById($_request['dir_id']);

		if ($filedirdb != null)
		{
			if ($filedirdb->getownerid()!=$_request['ownerid'])
			{
				$_response['result'] = false;
				return $_response;
			}
			$daosdp = new DAOSaveDirProp();

			if ($_request['ownerwriteaccess']=="Y")
				$accessright = array('createdir'=>'Y', 'updatedir'=>'Y', 'deldir'=>'Y',
					'createfile'=>'Y', 'updatefile'=>'Y', 'delfile'=>'Y',
					'allowread'=>'Y');
			else
				$accessright = array('createdir'=>'N', 'updatedir'=>'N', 'deldir'=>'N',
					'createfile'=>'N', 'updatefile'=>'N', 'delfile'=>'N',
					'allowread'=>'Y');
			if ($daosdp->getownerdiraccess($_request['dir_id'], $_request['ownerid']) == true)
			{
				if ($daosdp->updateownerdiraccess($_request['dir_id'], $_request['ownerid'],
					$accessright)==false)
				{
					$daosdp->rollback();
					$_response['result'] = false;
					return $_response;
				}
			}
			else
			{
				if ($daosdp->insertownerdiraccess($_request['dir_id'], $_request['ownerid'],
					$accessright)==false)
				{
					$daosdp->rollback();
					$_response['result'] = false;
					return $_response;
				}
			}

			if ($_request['publicreadaccess']=="Y")
				$accessright = array('createdir'=>'N', 'updatedir'=>'N', 'deldir'=>'N',
					'createfile'=>'N', 'updatefile'=>'N', 'delfile'=>'N',
					'allowread'=>'Y');
			else
				$accessright = array('createdir'=>'N', 'updatedir'=>'N', 'deldir'=>'N',
					'createfile'=>'N', 'updatefile'=>'N', 'delfile'=>'N',
					'allowread'=>'N');
			
			if ($daosdp->getpublicdiraccess($_request['dir_id'], $_request['ownerid']) == true)
			{
				if ($daosdp->updatepublicdiraccess($_request['dir_id'], $_request['ownerid'],
					$accessright)==false)
				{
					$daosdp->rollback();
					$_response['result'] = false;
					return $_response;
				}
			}
			else
			{
				if ($daosdp->insertpublicdiraccess($_request['dir_id'], $_request['ownerid'],
					$accessright) == false)
				{
					$daosdp->rollback();
					$_response['result'] = false;
					return $_response;
				}
			}

			if ($daosdp->deluseraccess($_request['dir_id'], explode(":", $_request['diruseraccessdel']),
				$_request['ownerid'])==false)
			{
				$daosdp->rollback();
				$_response['result'] = false;
				return $_response;
			}

			$useraccesslist = explode(":", $_request['diruseraccess']);
			for ($i=0; $i<count($useraccesslist); $i++)
			{
				if (!is_numeric($useraccesslist[$i]))
					continue;

				$accessright = array('createdir'=>'N', 'updatedir'=>'N', 'deldir'=>'N',
					'createfile'=>'N', 'updatefile'=>'N', 'delfile'=>'N',
					'allowread'=>'Y');
					
				if ($daosdp->getuserdiraccess($_request['dir_id'], $useraccesslist[$i], $_request['ownerid'])==true)
				{
					if ($daosdp->updateuserdiraccess($_request['dir_id'], $useraccesslist[$i], $_request['ownerid'], $accessright)==false)
					{
						$daosdp->rollback();
						$_response['result'] = false;
						return $_response;
					}
				}
				else
				{
					if ($daosdp->insertuserdiraccess($_request['dir_id'], $useraccesslist[$i], $_request['ownerid'], $accessright)==false)
					{
						$daosdp->rollback();
						$_response['result'] = false;
						return $_response;
					}
				}
			}

			$daosdp->commit();
			$_response['result'] = true;
		}
		else
		{
			$_response['result'] = false;
		}

		return $_response;
	}

}
Return current item: RabbitBB - Online Web Storage Project