diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php index 848f8cc5..8c691f0d 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php @@ -109,7 +109,7 @@ class FileController extends Controller if($fs->exists($fulldirectory)) { $finder = new Finder(); - $finder->depth('== 0')->sortByName()->in($fulldirectory)->exclude('thumb')->exclude('thumbmini'); + $finder->depth('== 0')->sortByName()->in($fulldirectory)->exclude('thumb')->exclude('thumbmini')->exclude('__trash'); foreach ($finder as $file) { if(is_dir($file)) { @@ -148,6 +148,10 @@ class FileController extends Controller } } + // Flag poubelle + $fgtrash=false; + if(stripos($subdirectory,"_trash")==1) $fgtrash=true; + // Trie du tableu $sort = array_column($files, $preference["widgetsortdirectory"][$directory]); array_multisort($sort, SORT_ASC, $files); @@ -171,6 +175,7 @@ class FileController extends Controller 'canadd' => $canupdate, 'view' => $preference["widgetviewdirectory"][$directory], 'sort' => $preference["widgetsortdirectory"][$directory], + 'fgtrash' => $fgtrash, ]); } @@ -206,7 +211,7 @@ class FileController extends Controller if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); - if($data["subdirectory"]=="thumb"||$data["subdirectory"]=="thumbmini") { + if($data["subdirectory"]=="thumb"||$data["subdirectory"]=="thumbmini"||$data["subdirectory"]=="__trash") { $form->addError(new FormError('Nom de répertoire réservé, merci de choisir un autre nom de répertoire')); $this->get('session')->getFlashBag()->clear(); $request->getSession()->getFlashBag()->add("error", 'Nom de répertoire réservé, merci de choisir un autre nom de répertoire'); @@ -234,6 +239,142 @@ class FileController extends Controller ]); } + public function trashAction(Request $request,$access="config") + { + // S'assurer que c'est un appel ajax + if (!$request->isXmlHttpRequest()) { + return new JsonResponse(array('message' => 'Interdit'), 400); + } + + $output=array(); + $directory=$request->request->get('directory'); + + // Récupération du répertoire source et le nom du fichier + $racine=$this->get('kernel')->getRootDir()."/../uploads/file"; + $directory=$request->request->get('directory'); + $dirsource =$request->request->get('subdirectory'); + $namesource =$request->request->get('filename'); + + $this->getPermission($access,$directory); + $fs = new Filesystem(); + + // Déplacer le fichier + $urlsource=$racine."/".$directory."/".$dirsource."/".$namesource; + $urldestination=$racine."/".$directory."/__trash/".$dirsource."/".$namesource; + $fs->mkdir($racine."/".$directory."/__trash/".$dirsource); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + + } + + // Déplacer le thumb + $fs->mkdir($racine."/".$directory."/__trash/".$dirsource."/thumb"); + $urlsource=$racine."/".$directory."/".$dirsource."/thumb/".$namesource; + $urldestination=$racine."/".$directory."/__trash/".$dirsource."/thumb/".$namesource; + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + // Déplacer le thumbmini + $fs->mkdir($racine."/".$directory."/__trash/".$dirsource."/thumbmini"); + $urlsource=$racine."/".$directory."/".$dirsource."/thumbmini/".$namesource; + $urldestination=$racine."/".$directory."/__trash/".$dirsource."/thumbmini/".$namesource; + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + $response = new Response(json_encode($output)); + $response->headers->set('Content-Type', 'application/json'); + return $response; + } + + public function restaureAction(Request $request,$access="config") + { + // S'assurer que c'est un appel ajax + if (!$request->isXmlHttpRequest()) { + return new JsonResponse(array('message' => 'Interdit'), 400); + } + + $output=array(); + $directory=$request->request->get('directory'); + + // Récupération du répertoire source et le nom du fichier + $racine=$this->get('kernel')->getRootDir()."/../uploads/file"; + $directory=$request->request->get('directory'); + $dirsource =$request->request->get('subdirectory'); + $namesource =$request->request->get('filename'); + + $this->getPermission($access,$directory); + $fs = new Filesystem(); + + // Déplacer le fichier + $dirdestination=str_replace("__trash/","",$dirsource); + $urlsource=$racine."/".$directory."/".$dirsource."/".$namesource; + $urldestination=str_replace("__trash/","/",$urlsource); + $fs->mkdir($racine."/".$directory."/".$dirdestination); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + // Déplacer le thumb + $urlsource=$racine."/".$directory."/".$dirsource."/thumb/".$namesource; + $urldestination=str_replace("__trash/","/",$urlsource); + $fs->mkdir($racine."/".$directory."/".$dirdestination."/thumb"); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + // Déplacer le thumbmini + $urlsource=$racine."/".$directory."/".$dirsource."/thumbmini/".$namesource; + $urldestination=str_replace("__trash/","/",$urlsource); + $fs->mkdir($racine."/".$directory."/".$dirdestination."/thumbmini"); + if($fs->exists($urlsource)) { + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else $fs->rename($urlsource,$urldestination,true); + } + + $response = new Response(json_encode($output)); + $response->headers->set('Content-Type', 'application/json'); + return $response; + } + + public function purgetrashAction($directory,Request $request,$access="config") + { + $output=array(); + + $this->getPermission($access,$directory); + $fs = new Filesystem(); + $url=$this->get('kernel')->getRootDir()."/../uploads/file/".$directory."/__trash"; + if($fs->exists($url)) { + $fs->remove($url); + } + + return $this->redirectToRoute('cadoles_core_'.$access.'_file_list',['directory'=>$directory]); + } + public function deleteAction(Request $request,$access="config") { // S'assurer que c'est un appel ajax @@ -267,7 +408,7 @@ class FileController extends Controller } $output=array(); - $directory=$request->request->get('directory');+ + $directory=$request->request->get('directory'); // Récupération du répertoire source et le nom du fichier $racine=$this->get('kernel')->getRootDir()."/../uploads/file"; @@ -276,7 +417,6 @@ class FileController extends Controller $dirdestination =$request->request->get('dirdestination'); $namedestination =$request->request->get('namedestination'); - $destid=$request->request->get('destid'); $this->getPermission($access,$directory); $fs = new Filesystem(); @@ -285,7 +425,12 @@ class FileController extends Controller $urlsource=$racine."/".$dirsource."/".$namesource; $urldestination=$racine."/".$dirdestination."/".$namedestination; if($fs->exists($urlsource)) { - $fs->rename($urlsource,$urldestination); + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else + $fs->rename($urlsource,$urldestination, true); } // Déplacer le thumb @@ -293,7 +438,12 @@ class FileController extends Controller $urlsource=$racine."/".$dirsource."/thumb/".$namesource; $urldestination=$racine."/".$dirdestination."/thumb/".$namedestination; if($fs->exists($urlsource)) { - $fs->rename($urlsource,$urldestination); + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else + $fs->rename($urlsource,$urldestination, true); } // Déplacer le thumbmini @@ -301,7 +451,12 @@ class FileController extends Controller $urlsource=$racine."/".$dirsource."/thumbmini/".$namesource; $urldestination=$racine."/".$dirdestination."/thumbmini/".$namedestination; if($fs->exists($urlsource)) { - $fs->rename($urlsource,$urldestination); + if(is_dir($urlsource)) { + $fs->mirror($urlsource,$urldestination); + $fs->remove($urlsource); + } + else + $fs->rename($urlsource,$urldestination, true); } $response = new Response(json_encode($output)); @@ -309,6 +464,7 @@ class FileController extends Controller return $response; } + public function viewAction($directory,$filename,Request $request,$access="config") { $this->getPermission($access,$directory); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml index 0511a6ba..5843eabd 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml @@ -74,6 +74,18 @@ cadoles_core_config_file_subdirectory: path: /config/file/subdirectory/{id}/{type} defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: config } +cadoles_core_config_file_trash: + path: /config/file/trash/ + defaults: { _controller: CadolesCoreBundle:File:trash, access: config } + +cadoles_core_config_file_restaure: + path: /config/file/restaure/ + defaults: { _controller: CadolesCoreBundle:File:restaure, access: config } + +cadoles_core_config_file_purgetrash: + path: /config/file/purgetrash/{directory} + defaults: { _controller: CadolesCoreBundle:File:purgetrash, access: config } + cadoles_core_config_file_delete: path: /config/file/delete/ defaults: { _controller: CadolesCoreBundle:File:delete, access: config } @@ -107,6 +119,18 @@ cadoles_core_user_file_subdirectory: path: /user/file/subdirectory/{id}/{type} defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: user } +cadoles_core_user_file_trash: + path: /user/file/trash/ + defaults: { _controller: CadolesCoreBundle:File:trash, access: user } + +cadoles_core_user_file_restaure: + path: /user/file/restaure/ + defaults: { _controller: CadolesCoreBundle:File:restaure, access: user } + +cadoles_core_user_file_purgetrash: + path: /user/file/purgetrash/{directory} + defaults: { _controller: CadolesCoreBundle:File:purgetrash, access: user } + cadoles_core_user_file_delete: path: /user/file/delete defaults: { _controller: CadolesCoreBundle:File:delete, access: user } @@ -128,6 +152,7 @@ cadoles_core_user_file_show: defaults: { _controller: CadolesCoreBundle:File:show, access: user } + #== Ajax ================================================================================================================= cadoles_core_ajax_country_list: path: /ajax/country/list diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css index 29c54e2a..3d446a49 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css @@ -381,6 +381,15 @@ a.item-update { z-index: 1000; } + +a.item-restaure { + display: none; + position: absolute; + right: 25px; + top: 2px; + z-index: 1000; +} + a.item-delete { display: none; position: absolute; diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig index 419bba1e..da291b1e 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig @@ -41,7 +41,7 @@
+ +
+ + {% if fgtrash %} + Purger la poubelle + {% endif %} +
+
@@ -103,12 +110,14 @@ {% set datadir = datadir~'/'~sub %} {% set sub = sub~"/"~parent %} {% endif %} - -
  • {{parent|raw}}
  • + + {% set tmpdirname = parent|replace({'__trash': 'Poubelle'}) %} +
  • {{tmpdirname|raw}}
  • {% endfor %} {% if not subdirectory is empty %} - + {% set tmpdirname = dirname|replace({'__trash': 'Poubelle'}) %} + {% endif %} @@ -124,9 +133,19 @@
    {% if canadd %} + {% if fgtrash %} + + + + - - + + + {% else %} + + + + {% endif %} {% endif %} {% if subdirectory is empty %} @@ -153,9 +172,19 @@
    {% if canadd %} + {% if fgtrash %} + + + + - - + + + {% else %} + + + + {% endif %} {% endif %} {% if file.minefamily=="text" or file.minefamily=="image" or file.minetype == "application/pdf" %} @@ -207,6 +236,8 @@ } $(".item-delete").css("color",color); $(".item-delete > i").css("color",color); + $(".item-restaure").css("color",color); + $(".item-restaure > i").css("color",color); $(".grid-item-title > h2").css("color",color); $('#mymodal').on('shown.bs.modal', function() { @@ -293,9 +324,47 @@ } } + // Trasher un fichier + function trashFile(directory,subdirectory,filename) { + var r = confirm("Confirmez-vous la mise à la poubelle de ce fichier ? Vous pourrez le récupèrer si besoin."); + if (r == true) { + $.ajax({ + method: "POST", + url: "{{ path('cadoles_core_'~access~'_file_trash') }}", + data: { + directory:directory, + subdirectory:subdirectory, + filename:filename + }, + success: function() { + location.reload(); + } + }); + } + } + + // Restaurer un fichier + function restaureFile(directory,subdirectory,filename) { + var r = confirm("Confirmez-vous la restauration de ce fichier ?"); + if (r == true) { + $.ajax({ + method: "POST", + url: "{{ path('cadoles_core_'~access~'_file_restaure') }}", + data: { + directory:directory, + subdirectory:subdirectory, + filename:filename + }, + success: function() { + location.reload(); + } + }); + } + } + // Supprimer un fichier function delFile(directory,subdirectory,filename) { - var r = confirm("Confirmez-vous la suppression de ce fichier ?"); + var r = confirm("Confirmez-vous la suppression définitive de ce fichier ?"); if (r == true) { $.ajax({ method: "POST", diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Include/footer.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Include/footer.html.twig index 92586780..5c13dbcb 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Include/footer.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Include/footer.html.twig @@ -217,6 +217,7 @@ $( ".grid-item-content").hover(function() { $(this).children(".item-heart").show(); $(this).children(".item-delete").show(); + $(this).children(".item-restaure").show(); $(this).children(".item-update").show(); $(this).children(".item-preview").show(); }); @@ -224,6 +225,7 @@ $( ".grid-item-content" ).mouseleave(function() { $(this).children(".item-heart").hide(); $(this).children(".item-delete").hide(); + $(this).children(".item-restaure").hide(); $(this).children(".item-update").hide(); $(this).children(".item-preview").hide(); });