Fix: missing remove_file action
Fix: use object instead id and store odt filename in object for use in triggers
This commit is contained in:
parent
eef50058b1
commit
c9be1cbb8b
@ -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 = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Set project
|
||||
else if ($action == 'classin' && $user->rights->propale->creer)
|
||||
{
|
||||
|
||||
@ -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 = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
|
||||
{
|
||||
if ($action == 'addcontact' && $user->rights->facture->creer)
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user