Ejemplo n.º 1
0
/**
 * Crée un nouveau dossier vierge à l'emplacement voulu.
 * @author Alban Truc
 * @param string|MongoId $idUser
 * @param string $path
 * @param string $folderName
 * @param bool $inheritRightsFromParent
 * @since 09/06/2014
 * @return array|TRUE
 */
function createNewFolder($idUser, $path, $folderName, $inheritRightsFromParent)
{
    $idUser = new MongoId($idUser);
    $operationSuccess = FALSE;
    $elementPdoManager = new ElementPdoManager();
    if ($path != '/') {
        //récupération du dossier parent
        $explode = explode('/', $path);
        $parentDirectoryName = $explode[sizeof($explode) - 2];
        $parentDirectoryPath = implode('/', array_slice($explode, 0, sizeof($explode) - 2)) . '/';
        $parentElementCriteria = array('state' => (int) 1, 'name' => $parentDirectoryName, 'serverPath' => $parentDirectoryPath, 'idOwner' => $idUser);
        $parentElement = $elementPdoManager->findOne($parentElementCriteria);
        if ($parentElement instanceof Element) {
            /*
             * 11 correspond au droit de lecture et écriture.
             * Si on souhaite accepter la copie avec des droits de plus bas niveau, il suffit d'ajouter les codes correspondant
             * au tableau en 3e paramètre ci-dessous.
             */
            $hasRight = actionAllowed($parentElement->getId(), $idUser, array('11'));
            if (is_bool($hasRight) && $hasRight == FALSE) {
                return array('error' => 'Creation not allowed.');
            } elseif (is_array($hasRight)) {
                return $hasRight;
            }
        } else {
            return $parentElement;
        }
    }
    //vérification qu'il n'existe pas déjà un dossier avec le même nom
    $elementCriteria = array('state' => (int) 1, 'name' => $folderName, 'serverPath' => $path, 'idOwner' => $idUser);
    $elementsWithSameName = $elementPdoManager->find($elementCriteria);
    if (is_array($elementsWithSameName) && array_key_exists('error', $elementsWithSameName)) {
        if ($elementsWithSameName['error'] != 'No match found.') {
            return $elementsWithSameName;
        }
    } else {
        foreach ($elementsWithSameName as $key => $elementWithSameName) {
            $isFolder = isFolder($elementWithSameName->getRefElement());
            if (is_bool($isFolder)) {
                if ($isFolder == FALSE) {
                    unset($elementsWithSameName[$key]);
                }
            } else {
                return $isFolder;
            }
        }
        if (!empty($elementsWithSameName)) {
            return array('error' => 'Folder name not available.');
        }
    }
    //File Server - 13/06/2014
    $mkdirResult = createFSDirectory($idUser, $path, $folderName);
    if (!is_bool($mkdirResult) || !($mkdirResult == TRUE)) {
        return $mkdirResult;
    }
    //Fin File Server
    //Récupération de l'id de RefElement dossier vide
    $refElementPdoManager = new RefElementPdoManager();
    $emptyFolder = $refElementPdoManager->findOne(array('state' => 1, 'code' => '4002'), array('_id' => TRUE));
    $newFolder = array('state' => 1, 'name' => $folderName, 'idOwner' => $idUser, 'idRefElement' => $emptyFolder['_id'], 'serverPath' => $path);
    $insertResult = $elementPdoManager->create($newFolder);
    if (is_bool($insertResult)) {
        if ($insertResult == TRUE) {
            //Le dossier parent était vide
            if (isset($parentElement)) {
                if ($parentElement->getRefElement() == $emptyFolder['_id']) {
                    $parentElementCriteria = array('_id' => $parentElement->getId());
                    //on change l'id du dossier parent pour dossier non vide
                    $notEmptyFolder = $refElementPdoManager->findOne(array('state' => 1, 'code' => '4003'), array('_id' => TRUE));
                    $update = array('$set' => array('idRefElement' => $notEmptyFolder['_id']));
                    //dans le cas où on voudrait récupérer le dossier parent mis à jour, on peut utiliser $updatedFolder
                    $updatedFolder = $elementPdoManager->findAndModify($parentElementCriteria, $update, array('new' => TRUE));
                    if ($updatedFolder instanceof Element) {
                        $operationSuccess = TRUE;
                    }
                }
                if ($inheritRightsFromParent == TRUE) {
                    //récupération des droits appliqués sur le dossier parent
                    $rightPdoManager = new RightPdoManager();
                    $rightCriteria = array('state' => 1, 'idElement' => $parentElement->getId());
                    $rights = $rightPdoManager->find($rightCriteria);
                    if (!array_key_exists('error', $rights)) {
                        //récupération du dossier précédemment inséré
                        $newElement = $elementPdoManager->findOne($newFolder);
                        if ($newElement instanceof Element) {
                            $insertRightCopy = array();
                            foreach ($rights as $right) {
                                $rightCopy = clone $right;
                                $rightCopy->setId(new MongoId());
                                $rightCopy->setElement($newElement->getId());
                                $insertRightCopy[] = $elementPdoManager->create($rightCopy);
                                //on pourrait se servir de $insertRightCopy pour identifier les erreurs éventuelles
                            }
                            //@todo vérifier que tous les insertRightCopy sont OK et si c'est le cas operationSuccess = TRUE
                            $operationSuccess = TRUE;
                        } else {
                            return $newElement;
                        }
                    }
                }
            }
            $operationSuccess = TRUE;
            return $operationSuccess;
        } else {
            return array('error' => 'Could not create folder in database.');
        }
    } else {
        return $insertResult;
    }
}
Ejemplo n.º 2
0
 * Created by PhpStorm.
 * User: Harry
 * Date: 05/06/14
 * Time: 12:36
 */
header('Content-Type: text/html; charset=utf-8');
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Nestbox';
require_once $projectRoot . '/required.php';
if (isset($_SESSION['userId'])) {
    $userId = $_SESSION['userId'];
}
if (isset($_POST['var']) && !empty($_POST['var'])) {
    $elementManager = new ElementPdoManager();
    $refElementManager = new RefElementPdoManager();
    $userManager = new UserPdoManager();
    $refElementEmptyDirectory = $refElementManager->findOne(array('code' => '4002', 'state' => 1));
    if ($refElementEmptyDirectory instanceof RefElement) {
        $idRefElementEmptyDirectory = $refElementEmptyDirectory->getId();
    } else {
        return $refElementEmptyDirectory;
    }
    $refElementNotEmptyDirectory = $refElementManager->findOne(array('code' => '4003', 'state' => 1));
    if ($refElementNotEmptyDirectory instanceof RefElement) {
        $idRefElementNotEmptyDirectory = $refElementNotEmptyDirectory->getId();
    } else {
        return $refElementNotEmptyDirectory;
    }
    $element = $elementManager->findById($_GET['id']);
    $refElement = $refElementManager->findById($element->getRefElement());
    $user = $userManager->findById($element->getOwner());
    echo '<div id="elementInformations">
Ejemplo n.º 3
0
}
// soumission du formulaire d'upload basique
if (isset($_POST['uploadBasicElem']) && isset($_FILES['fileExplorer'])) {
    $path = 'C:/wamp/www/Nestbox/' . $userId . '/Tmp-' . $userId . '';
    $folder = $path . '/';
    $file = $_FILES['fileExplorer']['name'];
    move_uploaded_file($_FILES['fileExplorer']['tmp_name'], $folder . $file);
    $returnMoveFS = moveFSElement($userId, '/Tmp-' . $userId . '/', $_FILES['fileExplorer']['name'], $_POST['destination'], $_FILES['fileExplorer']['name']);
    if ($returnMoveFS == TRUE) {
        $newPath = $projectRoot . '/' . $userId . $_POST['destination'];
        $elementManager = new ElementPdoManager();
        $refElementManager = new RefElementPdoManager();
        $hash = sha1_file($newPath . $_FILES['fileExplorer']['name']);
        $size = fileSize64($newPath . $_FILES['fileExplorer']['name']);
        $pathInfo = pathinfo($newPath . $_FILES['fileExplorer']['name']);
        $refElement = $refElementManager->findOne(array('extension' => '.' . $pathInfo['extension']));
        if (is_array($refElement) && array_key_exists('error', $refElement)) {
            echo "Extension not found";
        } else {
            $idRefElement = $refElement->getId();
            $criteria = array('downloadLink' => '', 'idOwner' => $userId, 'idRefElement' => $idRefElement, 'name' => $pathInfo['filename'], 'state' => 1, 'hash' => $hash, 'serverPath' => $_POST['destination'], 'size' => $size);
            $createElement = $elementManager->create($criteria);
            updateFolderStatus($_POST['destination'], $userId);
            header('Location : ' . $_SERVER['PHP_SELF'] . '');
        }
    } else {
        echo "Error during upload.";
    }
}
/**
 * @param $owner