<?PHP
class BSGNewDirectory
{
var $bsgar;
var $webappcfg;
function BSGNewDirectory()
{
global $webappcfg;
$this->webappcfg = $webappcfg;
$this->bsgar = new BSGAuthRight();
}
function newDirectory($_dirname, $_ownerid, $_createname, $_keypass)
{
if ($this->bsgar->checkDirRead($_dirname, NSession::getuid(),
$_ownerid, $_keypass))
{
$filedirdb = $this->bsgar->getfiledirdb();
if ($filedirdb==null)
return FATALERROR;
$daolsdir = new DAOlsDir();
$listdir = $daolsdir->lsDir($filedirdb);
for ($i=0; $i<count($listdir); $i++)
{
$tdir = $listdir[$i];
$twdir = $tdir->getobj();
if ($twdir->getdirname()==$_createname)
{
return DIREXIST;
}
}
if (!$this->bsgar->checkDirCreateDir($_dirname, NSession::getuid(),
$_ownerid, $_keypass))
return CREATEDIRDENIED;
if ($filedirdb!=null)
{
$bsgetdiraccess = new BSGetDirFileReadAccess();
list($tauthlist) = $bsgetdiraccess->getAuthList($filedirdb->getid(), NSession::getuid(), DIRECTORY);
$tauthlist = $tauthlist[DIRECTORY];
$tufdobj = new Ufd(-1, -1, DIRECTORY, $filedirdb->getid(), 1, $_ownerid, USER);
$tufdobj->setobj(new WDir(-1, $_createname, $_dirname . "/".$_createname, $_keypass));
$daod = new DAONewDirectory();
$nufdobj = $daod->newDirectory($tufdobj);
if ($nufdobj!=null)
{
if ($nufdobj->getid()>0)
{
$filearrindex = explode("/", $_dirname . "/" . $_createname);
$daoadi = new DAOAddDirIndex();
if ($daoadi->addindex($filearrindex, $nufdobj->getid()))
{
if ($tauthlist!=null)
{
$daoaauth = new DAOAddAuth();
if ($daoaauth->addAuth($nufdobj->getid(), $tauthlist, DIRECTORY))
{
$daoadi->commit();
return true;
}
}
$daodi->rollback();
return false;
}
else
{
$daoadi->rollback();
return false;
}
}
}
return false;
}
return false;
}
else
{
// Return Error : Access Denied
return ACCESSDENIED;
}
}
}
?>