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

class BSInitAccount
{
	function BSInitAccount()
	{
	}

	function initAccount($_request, $_response)
	{
		global $webappcfg;
		// Get the root directory
		
		$bsgar = new BSGAuthRight();
		$_request['dirname'] = "~";
		if (!isset($_request['ownerid']))
			$_request['ownerid'] = -1;
		if (!isset($_request['keypass']))
			$_request['keypass'] = "";
		
		if ($bsgar->checkDirRead($_request['dirname'], NSession::getuid(),
			$_request['ownerid'], $_request['keypass']))
		{
			$filedirdb = $bsgar->getfiledirdb();

			// Del the folder
			$_request['dirid'] = $filedirdb->getid();
			$_request['user_id'] = NSession::getuid();
			$_request['filestorage'] = $webappcfg['filestorage'];
			$bsdd = new BSDelDir();

			if ($bsdd->deldir($_request, $_response))
			{
				$_response['msg'][] = "Deleted";
				return $this->createRoot($_request, $_response);
			}
			else
			{
				$_response['msg'][] = "Failed to delete directory";
				$_response['result'] = false;
				return $_response;
			}

		}
		else
		{
			if ($_request['ownerid'] == NSession::getuid())
			{
				$filedirdb = $bsgar->getfiledirdb();
				if ($filedirdb=="")
				{
					// No init file structure
					$_response['msg'][] = "File Structure not found";
					return $this->createRoot($_request, $_response);
				}
				else
				{
					$_response['msg'][] = "File Structure exist but failed to delete.";
					$_response['result'] = false;
					return $_response;
				}
			}
			else
			{
				$_response['msg'][] = "Access Denied";
				$_response['result'] = false;
				return $_response;
			}

		}



	}

	function createRoot($_request, $_response)
	{
		$tufdobj = new Ufd(-1, -1, DIRECTORY, 0, 1, $_request['ownerid'], USER);
		$tufdobj->setobj(new WDir(-1, "~", "~", $_request['keypass']));

		$daod = new DAONewDirectory();
		$nufdobj = $daod->newDirectory($tufdobj);

		if ($nufdobj!=null)
		{
			if ($nufdobj->getid()>0)
			{
				$filearrindex =array("~");
				$daoadi = new DAOAddDirIndex();
				if ($daoadi->addindex($filearrindex, $nufdobj->getid()))
				{
					$tauthlist = array();
					if (is_array($tauthlist))
					{
						$daoaauth = new DAOAddAuth();
						if ($daoaauth->addAuth($nufdobj->getid(), $tauthlist, DIRECTORY))
						{
							$daoadi->commit();
							$_response['result'] = true;
						}
					}
					else
					{
						$daoadi->rollback();
						$_response['result'] = false;
						$_response['msg'][] = "tauthlist empty";
					}
				}
				else
				{
					$daoadi->rollback();
					$_response['result'] = false;
					$_response['msg'][] = "add index FAIL";
				}
			}
		}
		return $_response;
	}

}

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