From 57fea5151d3d25c21111da838ca9a9ef0d437083 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Aug 2022 20:45:04 +0200 Subject: [PATCH] Fix regression in online signature Conflicts: htdocs/core/ajax/onlineSign.php htdocs/public/onlinesign/newonlinesign.php --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/core/ajax/onlineSign.php | 9 ++++++--- htdocs/public/onlinesign/newonlinesign.php | 19 +++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 5b91caa2673..1002a14aef3 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -3721,7 +3721,7 @@ class Propal extends CommonObject * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php index a67f89cc6ef..3fb8671cd39 100644 --- a/htdocs/core/ajax/onlineSign.php +++ b/htdocs/core/ajax/onlineSign.php @@ -53,6 +53,7 @@ if (is_numeric($entity)) { define("DOLENTITY", $entity); } include '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $action = GETPOST('action', 'aZ09'); @@ -123,9 +124,11 @@ if ($action == "importSignature") { if (!$error) { // Defined modele of doc - $directdownloadlink = $object->getLastMainDocLink('proposal'); + $last_main_doc_file = $object->last_main_doc; + $directdownloadlink = $object->getLastMainDocLink('proposal'); // url to download the $object->last_main_doc - if (preg_match('/\.pdf/i', $directdownloadlink)) { + if (preg_match('/\.pdf/i', $last_main_doc_file)) { + // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile $newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf"; $sourcefile = $upload_dir.$ref.".pdf"; @@ -148,7 +151,7 @@ if ($action == "importSignature") { // Index the new file and update the last_main_doc property of object. $object->indexFile($newpdffilename, 1); } - } elseif (preg_match('/\.odt/i', $directdownloadlink)) { + } elseif (preg_match('/\.odt/i', $last_main_doc_file)) { // Adding signature on .ODT not yet supported // TODO } else { diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index b09006787c4..5dca1604f58 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -39,7 +39,7 @@ if (!defined('NOBROWSERNOTIF')) { // For MultiCompany module. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php -// TODO This should be useless. Because entity must be retrieve from object ref and not from url. +// Because 2 entities can have the same ref. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); if (is_numeric($entity)) { define("DOLENTITY", $entity); @@ -51,7 +51,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; // Load translation files $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "propal")); @@ -125,6 +124,7 @@ $creditor = $mysoc->name; $type = $source; if ($source == 'proposal') { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; $object = new Propal($db); $object->fetch(0, $ref, '', $entity); } else { @@ -318,11 +318,14 @@ if ($source == 'proposal') { // Object $text = ''.$langs->trans("SignatureProposalRef", $object->ref).''; - print ''.$langs->trans("Designation"); + print ''.$langs->trans("Designation"); print ''.$text; + + $last_main_doc_file = $object->last_main_doc; + if ($object->status == $object::STATUS_VALIDATED) { - if (empty($object->last_main_doc) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) { - // It seems document has never been generated, or was generated and the deleted. + if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) { + // It seems document has never been generated, or was generated and then deleted. // So we try to regenerate it with its default template. $defaulttemplate = ''; // We force the use an empty string instead of $object->model_pdf to be sure to use a "main" default template and not the last one used. $object->generateDocument($defaulttemplate, $langs); @@ -335,13 +338,11 @@ if ($source == 'proposal') { print $langs->trans("DownloadDocument").''; } } else { - $last_main_doc_file = $object->last_main_doc; - if ($object->status == $object::STATUS_NOTSIGNED) { $directdownloadlink = $object->getLastMainDocLink('proposal'); if ($directdownloadlink) { print '
'; - print img_mime($object->last_main_doc, ''); + print img_mime($last_main_doc_file, ''); print $langs->trans("DownloadDocument").''; } } elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) { @@ -366,8 +367,6 @@ if ($source == 'proposal') { print ''; print ''; print ''."\n"; - - // TODO Add link to download PDF (similar code than for invoice) }