diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 3fae4333d37..d8ced81686b 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -952,6 +952,23 @@ else if ($action == 'builddoc' && $user->rights->propale->creer)
}
}
+// Remove file in doc form
+else if ($action == 'remove_file')
+{
+ if ($object->fetch($id))
+ {
+ require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
+
+ $object->fetch_thirdparty();
+
+ $langs->load("other");
+ $upload_dir = $conf->propal->dir_output;
+ $file = $upload_dir . '/' . GETPOST('file');
+ dol_delete_file($file,0,0,0,$object);
+ $mesg = '
'.$langs->trans("FileWasRemoved",GETPOST('file')).'
';
+ }
+}
+
// Set project
else if ($action == 'classin' && $user->rights->propale->creer)
{
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 000daceaae3..7ddd5f25f6c 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -1023,11 +1023,13 @@ else if ($action == 'remove_file')
if ($object->fetch($id))
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
+
+ $object->fetch_thirdparty();
$langs->load("other");
$upload_dir = $conf->commande->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
- dol_delete_file($file);
+ dol_delete_file($file,0,0,0,$object);
$mesg = ''.$langs->trans("FileWasRemoved",GETPOST('file')).'
';
}
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index b8ce3074325..57b1f6fcc27 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1513,6 +1513,23 @@ else if ($action == 'builddoc') // En get ou en post
}
}
+// Remove file in doc form
+else if ($action == 'remove_file')
+{
+ if ($object->fetch($id))
+ {
+ require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
+
+ $object->fetch_thirdparty();
+
+ $langs->load("other");
+ $upload_dir = $conf->facture->dir_output;
+ $file = $upload_dir . '/' . GETPOST('file');
+ dol_delete_file($file,0,0,0,$object);
+ $mesg = ''.$langs->trans("FileWasRemoved",GETPOST('file')).'
';
+ }
+}
+
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
{
if ($action == 'addcontact' && $user->rights->facture->creer)
diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
index ddf4385424a..061eb082818 100644
--- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
+++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
@@ -160,7 +160,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @return int 1 if OK, <=0 if KO
*/
- function write_file($object,$outputlangs,$srctemplatepath)
+ function write_file(&$object,$outputlangs,$srctemplatepath)
{
global $user,$langs,$conf,$mysoc;
@@ -181,19 +181,6 @@ class doc_generic_odt extends ModeleThirdPartyDoc
if ($conf->societe->multidir_output[$object->entity])
{
- // If $object is id instead of object
- if (! is_object($object))
- {
- $id = $object;
- $object = new Societe($this->db);
- $result=$object->fetch($id);
- if ($result < 0)
- {
- dol_print_error($this->db,$object->error);
- return -1;
- }
- }
-
$dir = $conf->societe->multidir_output[$object->entity];
$objectref = dol_sanitizeFileName($object->id);
if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
@@ -214,7 +201,9 @@ class doc_generic_odt extends ModeleThirdPartyDoc
$newfiletmp=preg_replace('/\.odt/i','',$newfile);
$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
- $file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
+ $filename=$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
+ $file=$dir.'/'.$filename;
+ $object->builddoc_filename=$filename; // For triggers
//print "newdir=".$dir;
//print "newfile=".$newfile;
//print "file=".$file;
diff --git a/htdocs/core/modules/societe/modules_societe.class.php b/htdocs/core/modules/societe/modules_societe.class.php
index 582368b6695..269b64faf60 100644
--- a/htdocs/core/modules/societe/modules_societe.class.php
+++ b/htdocs/core/modules/societe/modules_societe.class.php
@@ -364,15 +364,15 @@ abstract class ModeleAccountancyCode
* Create a document for third party
*
* @param DoliDB $db Database handler
- * @param int $id Id of third party to use
+ * @param Societe $object Object of third party to use
* @param string $message Message
* @param string $modele Force model to use ('' to not force). model can be a model name or a template file.
* @param Translate $outputlangs Object lang to use for translation
* @return int <0 if KO, >0 if OK
*/
-function thirdparty_doc_create($db, $id, $message, $modele, $outputlangs)
+function thirdparty_doc_create($db, &$object, $message, $modele, $outputlangs)
{
- global $conf,$langs;
+ global $conf,$langs,$user;
$langs->load("bills");
$dir = DOL_DOCUMENT_ROOT . "/core/modules/societe/doc";
@@ -413,9 +413,19 @@ function thirdparty_doc_create($db, $id, $message, $modele, $outputlangs)
// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output=$outputlangs->charset_output;
- if ($obj->write_file($id, $outputlangs, $srctemplatepath) > 0)
+ if ($obj->write_file($object, $outputlangs, $srctemplatepath) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
+
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('COMPANY_BUILDDOC',$object,$user,$langs,$conf);
+ if ($result < 0) {
+ $error++; $this->errors=$interface->errors;
+ }
+ // Fin appel triggers
+
return 1;
}
else
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 7958c4d49ba..bc36ae956c8 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -426,7 +426,6 @@ if (empty($reshook))
require_once(DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php');
$object->fetch($socid);
- $object->fetch_thirdparty();
// Define output language
$outputlangs = $langs;
@@ -438,7 +437,7 @@ if (empty($reshook))
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
- $result=thirdparty_doc_create($db, $object->id, '', $_REQUEST['model'], $outputlangs);
+ $result=thirdparty_doc_create($db, $object, '', $_REQUEST['model'], $outputlangs);
if ($result <= 0)
{
dol_print_error($db,$result);
@@ -451,6 +450,21 @@ if (empty($reshook))
}
}
}
+
+ // Remove file in doc form
+ else if ($action == 'remove_file')
+ {
+ if ($object->fetch($socid))
+ {
+ require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
+
+ $langs->load("other");
+ $upload_dir = $conf->societe->dir_output;
+ $file = $upload_dir . '/' . GETPOST('file');
+ dol_delete_file($file,0,0,0,$object);
+ $mesg = ''.$langs->trans("FileWasRemoved",GETPOST('file')).'
';
+ }
+ }
}