Example #1
0
 /**
  * Delete this folder, all subsections and files
  * @return boolean to determine if delete was succesfull
  */
 function deleteFolder()
 {
     if (!empty($this->id)) {
         global $dbi;
         /* Delete files in folder */
         $result = $dbi->query("SELECT id FROM " . fileTableName . " WHERE folderId=" . $this->id);
         for ($i = 0; list($id) = $result->fetchrow_array(); $i++) {
             $file = new File($id);
             $file->deleteFile();
         }
         /* Delete subfolders */
         $result = $dbi->query("SELECT id FROM " . folderTableName . " WHERE parentId=" . $this->id);
         for ($i = 0; list($id) = $result->fetchrow_array(); $i++) {
             $folder = new Folder($id);
             $folder->deleteFolder();
         }
         /* Delete logged information in database */
         $dbi->query("DELETE FROM " . logTableName . " WHERE type='folder' AND typeId=" . $this->id);
         /* Delete this folder */
         $dbi->query("DELETE FROM " . folderTableName . " WHERE id=" . $this->id);
         /* Folder was deleted */
         return true;
     }
     /* Folder was not deleted */
     return false;
 }
Example #2
0
if (!$login->isAdmin()) {
    $login->printLoginForm();
    exit;
}
// Delete files
$delete = getPostValue("delete");
if ($delete) {
    // Check if data is submitted from the form
    checkSubmitter();
    // Delete folders
    $folders = getPostValue("folders");
    if (!empty($folders)) {
        for ($i = 0; $i < sizeof($folders); $i++) {
            if (!empty($folders[$i])) {
                $tmpFolder = new Folder($folders[$i]);
                $tmpFolder->deleteFolder();
            }
        }
    }
    // Delete files
    $files = getPostValue("files");
    if (!empty($files)) {
        for ($i = 0; $i < sizeof($files); $i++) {
            if (!empty($files[$i])) {
                $tmpFile = new File($files[$i]);
                $tmpFile->deleteFile();
            }
        }
    }
    // Redirect
    redirect(scriptUrl . "/" . folderFilesAdmin . "/" . fileFilesIndex . (!empty($folder->id) ? "?folderId=" . $folder->id : ""));
Example #3
0
 public static function syncFolders($folderToSync)
 {
     $debug = self::$debug;
     $mode = self::$mode;
     import('dao.Folder');
     $folder = new Folder();
     import('dao.File');
     $file = new File();
     $folderFullName = $folderToSync['path'];
     $folderId = $folderToSync['fd_id'];
     // If folder is locked, ignore. Unless set mode greater than 0.
     if ($folderToSync['locked'] && $mode == 0) {
         if ($debug) {
             ZDebug::my_echo('Ignore locked folder: ' . $folderFullName . '(' . $folderId . ')');
         }
         return TRUE;
     }
     // Step 1: If folder is not physically exist, set to deleted in DB.
     if (!is_dir($folderFullName)) {
         $folder->deleteFolder($folderId);
         if ($debug) {
             ZDebug::my_echo('Delete folder in DB: ' . $folderFullName . '(' . $folderId . ')');
         }
         return TRUE;
     }
     // Step 2: Get the result set of files under this folder
     $filesInFolder = $folder->getFilesInFolder($folderId);
     $fileNameArr = array();
     foreach ($filesInFolder as $theFile) {
         // Step 3: If a file is not physically exist, delete it in table files.
         if (!file_exists($theFile['path'])) {
             $file->deleteFile($theFile['fid']);
             if ($debug) {
                 ZDebug::my_echo('Delete file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')');
             }
         } elseif ($theFile['last_modified'] != my_filemtime($theFile['path'])) {
             $theFile['last_modified'] = my_filemtime($theFile['path']);
             $file->saveFile($theFile);
             if ($debug) {
                 ZDebug::my_echo('Update file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')');
             }
         } elseif ($mode > 1) {
             $file->saveFile($theFile);
             if ($debug) {
                 ZDebug::my_echo('Update file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')');
             }
         } else {
         }
         $fileNameArr[] = $theFile['name'];
     }
     // Step 5: Get result set of sub-folders under this folder
     $subFoldera = $folder->getSubFolder($folderId);
     $folderNameArr = array();
     foreach ($subFoldera as $theFolder) {
         // Step 6: If a folder is not physically exist, set deleted flag in table folders.
         if (!file_exists($theFolder['path'])) {
             $folder->deleteFolder($theFolder['fd_id']);
             if ($debug) {
                 ZDebug::my_echo('Delete folder in DB: ' . $theFolder['path'] . '(' . $theFolder['fd_id'] . ')');
             }
         } elseif ($theFolder['last_modified'] != my_filemtime($theFolder['path'])) {
             $theFolder['last_modified'] = my_filemtime($theFolder['path']);
             $folder->saveFolder($theFolder);
             if ($debug) {
                 ZDebug::my_echo('Update folder in DB: ' . $theFolder['path'] . '(' . $theFolder['fd_id'] . ')');
             }
             self::syncFolders($theFolder);
         } else {
             self::syncFolders($theFolder);
         }
         $folderNameArr[] = $theFolder['name'];
     }
     $hdl = opendir($folderFullName);
     while ($item = readdir($hdl)) {
         $itemFullName = $folderFullName . DIRECTORY_SEPARATOR . $item;
         // Step 8: If physical file is not in DB file result set, then add a file
         if ($item != "." && $item != ".." && is_file($itemFullName) && !in_array($item, $fileNameArr)) {
             $file->saveFile(array('path' => $itemFullName, 'fd_id' => $folderId));
             if ($debug > 1) {
                 ZDebug::my_echo('Adding new file in DB: ' . $itemFullName);
             }
         }
         // Step 9: if physical folder is not in DB folder result set, then add a folder
         if ($item != "." && $item != ".." && is_dir($itemFullName) && !in_array($item, $folderNameArr)) {
             self::addFolder($itemFullName, $folderId);
         }
     }
     closedir($hdl);
 }