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

class BSRenameDir
{
	function BSRenameDir()
	{
	}

	function renamedir($_request, $_response)
	{
		// Get Filedirdb

		$filedirdb = null;


		if (isset($_request['dirid']) && (is_numeric($_request['dirid'])))
		{

			$daogf = new DAOGetFileDirAttr();
			$filedirdb = $daogf->getDirById($_request['dirid']);
			//unset($daogf);
		}


		if ($filedirdb == null)
		{
			$_response['result'] = false;
			return $_response;
		}

		// Get Auth Right

		$bsar = new BSGAuthRight();
		$rauth = $bsar->getBasicAuthWFileDirDb($filedirdb, $_request['user_id'], $_request['ownerid']);
		unset($bsar);


		if ($rauth->getupdatedir()=="Y")
		{
			$tobj = $filedirdb->getobj();
			$fullpath = $tobj->getfullpath();
			$dirarray = explode("/", $fullpath);
			$nfullpath = "";
			for ($i=0; $i<(count($dirarray)-1); $i++)
			{
				$nfullpath .= $dirarray[$i]."/";
			}
			$nfullpath .= $_request['rename'];

			// Get Dir Index
			$daogi = new DAOGetIndex();
			$index = $daogi->getdirindex($_request['dirid'], $_request['ownerid'], $dirarray);
			if (($index!=null) && (count($index)>0))
			{
				$indexlist = array();
				$affectedid = array();
				$ssstart = false;
				$scounter = 0;

				for ($i=0; $i<count($index); $i++)
				{
					//echo("Checking ".$index[$i]['id']."<br />");
					if (($ssstart==false) && ($index[$i]['dirname']=="~"))
					{
						$ssstart = true;
						$scounter=1;
					}
					elseif (($ssstart == true) && ($index[$i]['dirname']=="~"))
					{
						$scounter = 1;
					}
					elseif ($ssstart == true)
					{
						if ($index[$i]['dirname']==$dirarray[$scounter])
						{
							if ($index[$i]['dirname']==$dirarray[count($dirarray)-1])
							{
								$indexlist[] = $index[$i]['id'];
								$affectedid[] = $index[$i]['fileid'];
								$ssstart = false;
							}
						}
						else
							$ssstart = false;
					}
				}


			}
			else
			{
				$_response['result'] = false;
				return $_response;
			}


			$otherdata = array();

			for ($i=0; $i<count($affectedid); $i++)
			{
				$nfiledirdb = $daogf->getDirById($affectedid[$i]);
				if ($nfiledirdb==null)
					$nfiledirdb = $daogf->getFileById($affectedid[$i]);
				if ($nfiledirdb!=null)
				{
					$otherdata[] = array();
					$otherdata[count($otherdata)-1]['id'] = $nfiledirdb->getlinkid();
					$nobj = $nfiledirdb->getobj();
					$ndirarray = explode("/", $nobj->getfullpath());
					$ndirarray[count($dirarray)-1]=$_request['rename'];
					//for ($j=0; $j<count($dirarray); $j++)
					//{
					//	if ($ndirarray[$j]==$dirarray[$j])
					//		$ndirarray[$j] = $_request['rename'];
					//}
					$otherdata[count($otherdata)-1]['fullpath'] = implode("/", $ndirarray);
					$otherdata[count($otherdata)-1]['type'] = $nfiledirdb->gettype();
				}
			}


			// If Accept, open rename DAO to update the db
			$daorf = new DAORenameDir();
			if ($daorf->renamedir($filedirdb->getlinkid(), $_request['rename'], $nfullpath, $indexlist, $otherdata))
			{
				$_response['result'] = true;
			}
			else
				$_response['result'] = false;

			// Set $_response['result'] = true;
		}
		else
		{
			$_response['result'] = false;
		}
		

		return $_response;
	}
}

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