diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index c6b4a607520..0536ad051f6 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -141,6 +141,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes') else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propale->supprimer) { $object->fetch($id); + $object->fetch_thirdparty(); $result=$object->delete($user); if ($result > 0) { diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 473ddb46f64..b67e7462508 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1812,7 +1812,7 @@ class Propal extends CommonObject { dol_delete_preview($this); - if (!dol_delete_file($file)) + if (! dol_delete_file($file,0,0,0,$this)) // For triggers { $this->error='ErrorFailToDeleteFile'; $this->db->rollback(); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 5b70f45a2c1..c14d0c2ef50 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2302,7 +2302,7 @@ class Commande extends CommonObject { dol_delete_preview($this); - if (!dol_delete_file($file)) + if (! dol_delete_file($file,0,0,0,$this)) // For triggers { $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); $this->db->rollback(); @@ -2311,7 +2311,7 @@ class Commande extends CommonObject } if (file_exists($dir)) { - if (!dol_delete_dir($dir)) + if (! dol_delete_dir($dir)) { $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); $this->db->rollback(); diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index f5d9ba94e7e..f45e0b407d8 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -177,7 +177,7 @@ if ($id > 0 || ! empty($ref)) */ if ($action == 'delete') { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); if ($ret == 'html') print '
'; } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 7b7605a63dc..ccb82847104 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -139,6 +139,7 @@ else if ($action == 'confirm_delete' && $confirm == 'yes') if ($user->rights->commande->supprimer) { $object->fetch($id); + $object->fetch_thirdparty(); $result=$object->delete($user); if ($result > 0) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 6d30f8c34d4..4dbd6b970f7 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -156,6 +156,7 @@ else if ($action == 'reopen' && $user->rights->facture->creer) else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->supprimer) { $result = $object->fetch($id); + $object->fetch_thirdparty(); $result = $object->delete(); if ($result > 0) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 63e88ebcedd..ebb9b7db8b0 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1166,6 +1166,7 @@ class Facture extends CommonObject function delete($rowid=0, $notrigger=0) { global $user,$langs,$conf; + require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); if (! $rowid) $rowid=$this->id; @@ -1236,6 +1237,34 @@ class Facture extends CommonObject $resql=$this->db->query($sql); if ($resql) { + // On efface le repertoire de pdf provisoire + $ref = dol_sanitizeFileName($this->ref); + if ($conf->facture->dir_output) + { + $dir = $conf->facture->dir_output . "/" . $ref; + $file = $conf->facture->dir_output . "/" . $ref . "/" . $ref . ".pdf"; + if (file_exists($file)) // We must delete all files before deleting directory + { + $ret=dol_delete_preview($this); + + if (! dol_delete_file($file,0,0,0,$this)) // For triggers + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + $this->db->rollback(); + return 0; + } + } + if (file_exists($dir)) + { + if (! dol_delete_dir_recursive($dir)) // For remove dir and meta + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + $this->db->rollback(); + return 0; + } + } + } + $this->db->commit(); return 1; } diff --git a/htdocs/core/ajax/fileupload.php b/htdocs/core/ajax/fileupload.php index ca06febbf13..fef19981fdf 100644 --- a/htdocs/core/ajax/fileupload.php +++ b/htdocs/core/ajax/fileupload.php @@ -23,7 +23,7 @@ //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); +//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); @@ -45,7 +45,6 @@ error_reporting(E_ALL | E_STRICT); $fk_element = GETPOST('fk_element','int'); $element = GETPOST('element','alpha'); -$element_ref=GETPOST('element_ref','alpha'); /** @@ -68,19 +67,45 @@ class UploadHandler * @param string $element element * @param string $element_ref element ref */ - function __construct($options=null,$fk_element=null,$element=null,$element_ref=null) + function __construct($options=null,$fk_element=null,$element=null) { - global $conf; + global $db, $conf; + global $object; $this->_fk_element=$fk_element; $this->_element=$element; - $this->_element_ref=$element_ref; + + $pathname=$filename=$element; + if (preg_match('/^([^_]+)_([^_]+)/i',$element,$regs)) + { + $pathname = $regs[1]; + $filename = $regs[2]; + } + + // For compatibility + if ($element == 'propal') { + $pathname = 'comm/propal'; $filename = 'propal'; + } + if ($element == 'commande') { + $pathname = $filename = 'commande'; + } + if ($element == 'facture') { + $pathname = 'compta/facture'; $filename = 'facture'; + } + + dol_include_once('/'.$pathname.'/class/'.$filename.'.class.php'); + + $classname = ucfirst($filename); + $object = new $classname($db); + + $object->fetch($fk_element); + $object->fetch_thirdparty(); $this->_options = array( 'script_url' => $_SERVER['PHP_SELF'], - 'upload_dir' => $conf->$element->dir_output . '/' . $element_ref . '/', - 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$element_ref.'/', + 'upload_dir' => $conf->$element->dir_output . '/' . $object->ref . '/', + 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/', 'param_name' => 'files', // The php.ini settings upload_max_filesize and post_max_size // take precedence over the following max_file_size setting: @@ -100,8 +125,8 @@ class UploadHandler ), */ 'thumbs' => array( - 'upload_dir' => $conf->$element->dir_output . '/' . $element_ref . '/thumbs/', - 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$element_ref.'/thumbs/' + 'upload_dir' => $conf->$element->dir_output . '/' . $object->ref . '/thumbs/', + 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/thumbs/' ) ) ); @@ -255,8 +280,7 @@ class UploadHandler FILE_APPEND ); } else { - // FIXME problem with trigger - dol_move_uploaded_file($uploaded_file, $file_path, 1, 0, 0, 1); + dol_move_uploaded_file($uploaded_file, $file_path, 1); } } else { // Non-multipart uploads (PUT method support) @@ -384,7 +408,7 @@ class UploadHandler * View */ -$upload_handler = new UploadHandler(null,$fk_element,$element,$element_ref); +$upload_handler = new UploadHandler(null,$fk_element,$element); header('Pragma: no-cache'); header('Cache-Control: private, no-cache'); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 316e6f4ec33..551b3612232 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -545,7 +545,7 @@ abstract class CommonObject $this->thirdparty = $thirdparty; // Use first price level if level not defined for third party - if ($conf->global->PRODUIT_MULTIPRICES && empty($this->thirdparty->price_level)) + if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) { $this->client->price_level=1; // deprecated $this->thirdparty->price_level=1; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 1723b443e4b..156b076f2d5 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -841,7 +841,7 @@ class FormFile // Load existing files: // TODO do not delete if (1 == 2) { - $.getJSON($("#fileupload form").prop("action"), { fk_element: "'.$object->id.'", element: "'.$object->element.'", element_ref: "'.$object->ref.'"}, function (files) { + $.getJSON($("#fileupload form").prop("action"), { fk_element: "'.$object->id.'", element: "'.$object->element.'"}, function (files) { var fu = $("#fileupload").data("fileupload"); fu._adjustMaxNumberOfFiles(-files.length); fu._renderDownload(files) @@ -869,7 +869,6 @@ class FormFile print '
'; print ''; print ''; - print ''; print '
'; print ''; print '