예제 #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;
    }
}
$rightPdoManager = new RightPdoManager();
//Chemin des fichiers de test
$path = 'D:\\Cours SUPINFO\\M1\\Projet Fin d\'annee\\Nestbox\\Fichiers de test/';
/**
 *  /Nestbox/
 *          IMG/
 *              Croquis Nesbtox.jpg
 *          code/
 *              js/
 *                 front/
 *                       js.txt
 *              css/
 *                  test.txt
 *
 *          suivi de projet.gdoc
 *          liens upload.gdoc
 *          Explorateur de fichier.gdoc
 *  /Nestbox - test/
 *	carte.gif
 */
//contient 12 éléments
$insert = array(array('_id' => new MongoId('5392061f09413a1021000041'), 'state' => 1, 'name' => 'Nestbox', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000075'), 'serverPath' => '/'), array('state' => 1, 'name' => 'Nestbox - test', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000074'), 'serverPath' => '/'), array('state' => 1, 'name' => 'IMG', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000075'), 'serverPath' => '/Nestbox/'), array('state' => 1, 'name' => 'Croquis Nestbox', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb502180800006f'), 'serverPath' => '/Nestbox/IMG/', 'size' => fileSize64($path . 'Nestbox/IMG/Croquis Nestbox.jpg'), 'hash' => sha1_file($path . 'Nestbox/IMG/Croquis Nestbox.jpg'), 'downloadLink' => ''), array('state' => 1, 'name' => 'code', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000075'), 'serverPath' => '/Nestbox/'), array('state' => 1, 'name' => 'js', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000075'), 'serverPath' => '/Nestbox/code/'), array('state' => 1, 'name' => 'front', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000075'), 'serverPath' => '/Nestbox/code/js/'), array('state' => 1, 'name' => 'js', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('539b0c4eedb502ac0d000044'), 'serverPath' => '/Nestbox/code/js/front/', 'size' => fileSize64($path . 'Nestbox/code/js/front/js.txt'), 'hash' => sha1_file($path . 'Nestbox/code/js/front/js.txt'), 'downloadLink' => ''), array('state' => 1, 'name' => 'css', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000075'), 'serverPath' => '/Nestbox/code/'), array('state' => 1, 'name' => 'test', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('539b0c4eedb502ac0d000044'), 'serverPath' => '/Nestbox/code/css/', 'size' => fileSize64($path . 'Nestbox/code/css/test.txt'), 'hash' => sha1_file($path . 'Nestbox/code/css/test.txt'), 'downloadLink' => ''), array('state' => 1, 'name' => 'suivi de projet', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000058'), 'serverPath' => '/Nestbox/', 'size' => fileSize64($path . 'Nestbox/suivi de projet.doc'), 'hash' => sha1_file($path . 'Nestbox/suivi de projet.doc'), 'downloadLink' => ''), array('state' => 1, 'name' => 'liens upload', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000058'), 'serverPath' => '/Nestbox/', 'size' => fileSize64($path . 'Nestbox/liens upload.doc'), 'hash' => sha1_file($path . 'Nestbox/liens upload.doc'), 'downloadLink' => ''), array('state' => 1, 'name' => 'Explorateur de fichier', 'idOwner' => new MongoId('536749adedb5025416000029'), 'idRefElement' => new MongoId('53639f93edb5021808000058'), 'serverPath' => '/Nestbox/', 'size' => fileSize64($path . 'Nestbox/Explorateur de fichier.doc'), 'hash' => sha1_file($path . 'Nestbox/Explorateur de fichier.doc'), 'downloadLink' => ''), array('state' => 1, 'name' => 'carte', 'idOwner' => new MongoId('5397628aedb502300d000050'), 'idRefElement' => new MongoId('53639f93edb502180800006b'), 'serverPath' => '/', 'size' => fileSize64($path . 'carte.gif'), 'hash' => sha1_file($path . 'carte.gif'), 'downloadLink' => ''), array('idOwner' => new MongoId("5397628aedb502300d000050"), 'idRefElement' => new MongoId("53639f93edb5021808000074"), 'name' => 'First Share', 'serverPath' => '/', 'state' => new MongoInt32(1)));
foreach ($insert as $element) {
    $elementPdoManager->create($element);
}
$insertRight = array(array('idElement' => new MongoId("53977311edb502b40c000050"), 'idRefRight' => new MongoId("53639f93edb5021808000047"), 'idUser' => new MongoId("536749adedb5025416000029"), 'state' => new MongoInt32(1)), array('idElement' => new MongoId("539761f1edb502300d00004f"), 'idRefRight' => new MongoId("53639f93edb5021808000047"), 'idUser' => new MongoId("536749adedb5025416000029"), 'state' => new MongoInt32(1)));
foreach ($insertRight as $right) {
    $rightPdoManager->create($right);
}
echo 'Insertion OK';
exit;
예제 #3
0
    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
 * @param $isOwner
 * @param $dir
 * todo modifier les paramètres de la fonction
 */
function arborescence($owner, $isOwner, $dir)
{