Fix: big problem with files upload and more compatible with external
modules
This commit is contained in:
parent
763e2a96a4
commit
b5246add8d
@ -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)
|
||||
{
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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 '<br>';
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 '<form action="'.DOL_URL_ROOT.'/core/ajax/fileupload.php" method="POST" enctype="multipart/form-data">';
|
||||
print '<input type="hidden" name="fk_element" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="element" value="'.$object->element.'">';
|
||||
print '<input type="hidden" name="element_ref" value="'.$object->ref.'">';
|
||||
print '<div class="fileupload-buttonbar">';
|
||||
print '<input type="hidden" name="protocol" value="http">';
|
||||
print '<label class="fileinput-button">';
|
||||
|
||||
@ -598,16 +598,25 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
|
||||
if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
|
||||
dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
|
||||
|
||||
if (! $notrigger && is_object($object))
|
||||
if (! $notrigger)
|
||||
{
|
||||
$object->src_file=$dest_file;
|
||||
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||
$interface=new Interfaces($db);
|
||||
$result=$interface->run_triggers('FILE_UPLOAD',$object,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
if (is_object($object))
|
||||
{
|
||||
$object->src_file=$dest_file;
|
||||
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||
$interface=new Interfaces($db);
|
||||
$result=$interface->run_triggers('FILE_UPLOAD',$object,$user,$langs,$conf);
|
||||
if ($result < 0) {
|
||||
$error++; $errors=$interface->errors;
|
||||
}
|
||||
// Fin appel triggers
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Files.lib::dol_move_uploaded_file Object not find", LOG_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
return 1; // Success
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
|
||||
if ($conf->ldap->enabled) require_once (DOL_DOCUMENT_ROOT."/core/class/ldap.class.php");
|
||||
if (! empty($conf->ldap->enabled)) require_once (DOL_DOCUMENT_ROOT."/core/class/ldap.class.php");
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user