From 5f51af505f698e4bb5a75d1e3fd4be1c2e9a4af8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Feb 2018 23:52:45 +0100 Subject: [PATCH] NEW Can delete dir content in media and ECM module recursively --- htdocs/core/class/html.form.class.php | 2 +- htdocs/ecm/class/ecmdirectory.class.php | 18 ++++++++++---- htdocs/ecm/dir_card.php | 33 +++++++++++++++++++------ htdocs/langs/en_US/other.lang | 2 ++ 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4e8f67d6552..ba0ea7a37c2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3652,7 +3652,7 @@ class Form $more.=''; $more.=''.$input['label'].' '; $more.='0 if OK + * @param User $user User that delete + * @param string $mode 'all'=delete all, 'databaseonly'=only database entry, 'fileonly' (not implemented) + * @param int $deletedirrecursive 1=Agree to delete content recursiveley (otherwise an error will be returned when trying to delete) + * @return int <0 if KO, >0 if OK */ - function delete($user, $mode='all') + function delete($user, $mode='all', $deletedirrecursive=0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -368,7 +369,14 @@ class EcmDirectory // extends CommonObject if ($mode != 'databaseonly') { $file = $conf->ecm->dir_output . "/" . $relativepath; - $result=@dol_delete_dir($file); + if ($deletedirrecursive) + { + $result=@dol_delete_dir_recursive($file, 0, 0); + } + else + { + $result=@dol_delete_dir($file, 0); + } } if ($result || ! @is_dir(dol_osencode($file))) diff --git a/htdocs/ecm/dir_card.php b/htdocs/ecm/dir_card.php index e2b031305d9..14f0ee18e8c 100644 --- a/htdocs/ecm/dir_card.php +++ b/htdocs/ecm/dir_card.php @@ -156,10 +156,12 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes') $backtourl = DOL_URL_ROOT."/ecm/index.php"; if ($module == 'medias') $backtourl = DOL_URL_ROOT."/website/index.php?file_manager=1"; + $deletedirrecursive = (GETPOST('deletedirrecursive','alpha') == 'on' ? 1 : 0); + if ($module == 'ecm') { // Fetch was already done - $result=$ecmdir->delete($user); + $result=$ecmdir->delete($user, 'all', $deletedirrecursive); if ($result <= 0) { $langs->load('errors'); @@ -168,7 +170,14 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes') } else { - $resbool = dol_delete_dir($upload_dir, 1); + if ($deletedirrecursive) + { + $resbool = dol_delete_dir_recursive($upload_dir, 0, 1); + } + else + { + $resbool = dol_delete_dir($upload_dir, 1); + } if ($resbool) $result = 1; else { @@ -475,8 +484,8 @@ if ($action != 'edit' && $action != 'delete') print ''.$langs->trans('ECMAddSection').''; } - if (count($filearrayall) == 0) - { + //if (count($filearrayall) == 0) + //{ if ($permtoadd) { print ''.$langs->trans('Delete').''; @@ -485,14 +494,14 @@ if ($action != 'edit' && $action != 'delete') { print ''.$langs->trans('Delete').''; } - } + /*} else { if (count($filearray) > 0) print ''.$langs->trans('Delete').''; else print ''.$langs->trans('Delete').''; - } + }*/ print ''; } @@ -506,7 +515,17 @@ if ($action == 'delete') if ($action == 'delete_dir') { $relativepathwithoutslash=preg_replace('/[\/]$/','',$relativepath); - print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.GETPOST('section','alpha').($module?'&module='.$module:''), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$relativepathwithoutslash), 'confirm_deletedir', '', 1, 1); + + //Form to close proposal (signed or not) + if (count($filearrayall) > 0) + { + $langs->load("other"); + $formquestion = array( + array('type' => 'checkbox', 'name' => 'deletedirrecursive', 'label' => $langs->trans("ContentOfDirectoryIsNotEmpty").'
'.$langs->trans("DeleteAlsoContentRecursively"),'value' => '0') // Field to complete private note (not replace) + ); + } + + print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.GETPOST('section','alpha').($module?'&module='.$module:''), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$relativepathwithoutslash), 'confirm_deletedir', $formquestion, 1, 1); } diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 1585504479e..c4cb693716d 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -22,6 +22,8 @@ JumpToLogin=Disconnected. Go to login page... MessageForm=Message on online payment form MessageOK=Message on validated payment return page MessageKO=Message on canceled payment return page +ContentOfDirectoryIsNotEmpty=Content of this directory is not empty. +DeleteAlsoContentRecursively=Check to delete all content recursiveley YearOfInvoice=Year of invoice date PreviousYearOfInvoice=Previous year of invoice date