FIX delete of a file in file_manager return to same dir
This commit is contained in:
parent
d4bc53660b
commit
985ab1efda
@ -77,20 +77,23 @@ elseif (GETPOST('linkit','none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
|||||||
// Delete file/link
|
// Delete file/link
|
||||||
if ($action == 'confirm_deletefile' && $confirm == 'yes')
|
if ($action == 'confirm_deletefile' && $confirm == 'yes')
|
||||||
{
|
{
|
||||||
$urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
|
$urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
|
||||||
if (GETPOST('section', 'alpha')) $file = $upload_dir . "/" . $urlfile; // For a delete of GED module urlfile contains full path from upload_dir
|
if (GETPOST('section', 'alpha')) // For a delete from the ECM module, upload_dir is ECM root dir and urlfile contains relative path from upload_dir
|
||||||
else // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
|
{
|
||||||
|
$file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile;
|
||||||
|
}
|
||||||
|
else // For a delete from the file manager into another module, or from documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
|
||||||
{
|
{
|
||||||
$urlfile=basename($urlfile);
|
$urlfile=basename($urlfile);
|
||||||
$file = $upload_dir . "/" . $urlfile;
|
$file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile;
|
||||||
if (! empty($upload_dirold)) $fileold = $upload_dirold . "/" . $urlfile;
|
if (! empty($upload_dirold)) $fileold = $upload_dirold . "/" . $urlfile;
|
||||||
}
|
}
|
||||||
$linkid = GETPOST('linkid', 'int'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
|
$linkid = GETPOST('linkid', 'int');
|
||||||
|
|
||||||
if ($urlfile)
|
if ($urlfile) // delete of a file
|
||||||
{
|
{
|
||||||
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
|
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
|
||||||
$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
|
$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette (if file is an image)
|
||||||
|
|
||||||
$ret = dol_delete_file($file, 0, 0, 0, (is_object($object)?$object:null));
|
$ret = dol_delete_file($file, 0, 0, 0, (is_object($object)?$object:null));
|
||||||
if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, (is_object($object)?$object:null)); // Delete file using old path
|
if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, (is_object($object)?$object:null)); // Delete file using old path
|
||||||
@ -114,7 +117,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
|
|||||||
if ($ret) setEventMessages($langs->trans("FileWasRemoved", $urlfile), null, 'mesgs');
|
if ($ret) setEventMessages($langs->trans("FileWasRemoved", $urlfile), null, 'mesgs');
|
||||||
else setEventMessages($langs->trans("ErrorFailToDeleteFile", $urlfile), null, 'errors');
|
else setEventMessages($langs->trans("ErrorFailToDeleteFile", $urlfile), null, 'errors');
|
||||||
}
|
}
|
||||||
elseif ($linkid)
|
elseif ($linkid) // delete of external link
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
|
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
|
||||||
$link = new Link($db);
|
$link = new Link($db);
|
||||||
@ -143,7 +146,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id.(!empty($withproject)?'&withproject=1':''));
|
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(GETPOST('section_dir','alpha')?'§ion_dir='.urlencode(GETPOST('section_dir','alpha')):'').(!empty($withproject)?'&withproject=1':''));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,6 +77,10 @@ $error=0;
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO Replace sendit and confirm_deletefile with
|
||||||
|
//$backtopage=$_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid; // used after a confirm_deletefile into actions_linkedfiles.inc.php
|
||||||
|
//include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
|
||||||
|
|
||||||
// Upload file (code similar but different than actions_linkedfiles.inc.php)
|
// Upload file (code similar but different than actions_linkedfiles.inc.php)
|
||||||
if (GETPOST("sendit",'none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
if (GETPOST("sendit",'none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||||
{
|
{
|
||||||
@ -113,6 +117,33 @@ if (GETPOST("sendit",'none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove file (code similar but different than actions_linkedfiles.inc.php)
|
||||||
|
if ($action == 'confirm_deletefile')
|
||||||
|
{
|
||||||
|
if (GETPOST('confirm') == 'yes')
|
||||||
|
{
|
||||||
|
// GETPOST('urlfile','alpha') is full relative URL from ecm root dir. Contains path of all sections.
|
||||||
|
//var_dump(GETPOST('urlfile'));exit;
|
||||||
|
|
||||||
|
$upload_dir = $conf->ecm->dir_output.($relativepath?'/'.$relativepath:'');
|
||||||
|
$file = $upload_dir . "/" . GETPOST('urlfile','alpha');
|
||||||
|
|
||||||
|
$ret=dol_delete_file($file); // This include also the delete from file index in database.
|
||||||
|
if ($ret)
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile','alpha')), null, 'mesgs');
|
||||||
|
$result=$ecmdir->changeNbOfFiles('-');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile','alpha')), null, 'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
clearstatcache();
|
||||||
|
}
|
||||||
|
$action='file_manager';
|
||||||
|
}
|
||||||
|
|
||||||
// Add directory
|
// Add directory
|
||||||
if ($action == 'add' && $user->rights->ecm->setup)
|
if ($action == 'add' && $user->rights->ecm->setup)
|
||||||
{
|
{
|
||||||
@ -135,33 +166,6 @@ if ($action == 'add' && $user->rights->ecm->setup)
|
|||||||
clearstatcache();
|
clearstatcache();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove file (code similar but different than actions_linkedfiles.inc.php)
|
|
||||||
if ($action == 'confirm_deletefile')
|
|
||||||
{
|
|
||||||
if (GETPOST('confirm') == 'yes')
|
|
||||||
{
|
|
||||||
// GETPOST('urlfile','alpha') is full relative URL from ecm root dir. Contains path of all sections.
|
|
||||||
//var_dump(GETPOST('urlfile'));exit;
|
|
||||||
|
|
||||||
$upload_dir = $conf->ecm->dir_output.($relativepath?'/'.$relativepath:'');
|
|
||||||
$file = $upload_dir . "/" . GETPOST('urlfile','alpha'); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP).
|
|
||||||
|
|
||||||
$ret=dol_delete_file($file); // This include also the delete from file index in database.
|
|
||||||
if ($ret)
|
|
||||||
{
|
|
||||||
setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile','alpha')), null, 'mesgs');
|
|
||||||
$result=$ecmdir->changeNbOfFiles('-');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile','alpha')), null, 'errors');
|
|
||||||
}
|
|
||||||
|
|
||||||
clearstatcache();
|
|
||||||
}
|
|
||||||
$action='file_manager';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove directory
|
// Remove directory
|
||||||
if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
|
if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
|
||||||
{
|
{
|
||||||
|
|||||||
@ -207,7 +207,7 @@ $htmlheadercontentdefault.='-->'."\n";
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$backtopage=$_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid; // used after a confirm_deletefile into actions_linkedfiles.inc.php
|
$backtopage=$_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid.(GETPOST('section_dir','alpha')?'§ion_dir='.urlencode(GETPOST('section_dir','alpha')):''); // used after a confirm_deletefile into actions_linkedfiles.inc.php
|
||||||
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
|
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
|
||||||
|
|
||||||
if ($action == 'renamefile') $action='file_manager'; // After actions_linkedfiles, if action were renamefile, we set it to 'file_manager'
|
if ($action == 'renamefile') $action='file_manager'; // After actions_linkedfiles, if action were renamefile, we set it to 'file_manager'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user