diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php index 994ba5c42f3..5f3cc281f90 100644 --- a/htdocs/core/ajax/onlineSign.php +++ b/htdocs/core/ajax/onlineSign.php @@ -69,10 +69,10 @@ $type = $mode; // Check securitykey $securekeyseed = ''; if ($type == 'proposal') { - $securekeyseed = $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN; + $securekeyseed = isset($conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN : ''; } -if (!dol_verifyHash($securekeyseed.$type.$ref, $SECUREKEY, '0')) { +if (empty($SECUREKEY) || !dol_verifyHash($securekeyseed.$type.$ref, $SECUREKEY, '0')) { http_response_code(403); print 'Bad value for securitykey. Value provided '.dol_escape_htmltag($SECUREKEY).' does not match expected value for ref='.dol_escape_htmltag($ref); exit(-1); @@ -122,28 +122,40 @@ if ($action == "importSignature") { } if (!$error) { - $newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf"; + // Defined modele of doc + $directdownloadlink = $object->getLastMainDocLink('proposal'); - $pdf = pdf_getInstance(); - $pdf->Open(); - $pdf->AddPage(); - $pagecount = $pdf->setSourceFile($upload_dir.$ref.".pdf"); // original PDF + if (preg_match('/\.pdf/i', $directdownloadlink)) { + $newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf"; + $sourcefile = $upload_dir.$ref.".pdf"; - for ($i=1;$i<($pagecount+1);$i++) { - if ($i>1) $pdf->AddPage(); - $tppl=$pdf->importPage($i); - $pdf->useTemplate($tppl); + if (dol_is_file($sourcefile)) { + $pdf = pdf_getInstance(); + $pdf->Open(); + $pdf->AddPage(); + $pagecount = $pdf->setSourceFile($sourcefile); // original PDF + + for ($i=1; $i<($pagecount+1); $i++) { + if ($i>1) $pdf->AddPage(); + $tppl=$pdf->importPage($i); + $pdf->useTemplate($tppl); + } + + $pdf->Image($upload_dir.$filename, 129, 239.6, 60, 15); // FIXME Position will be wrong with non A4 format. Use a value from width and height of page minus relative offset. + $pdf->Close(); + $pdf->Output($newpdffilename, "F"); + + // Index the new file and update the last_main_doc property of object. + $object->indexFile($newpdffilename, 1); + } + } else { + // Adding signature on doc not yet supported } + } - $pdf->Image($upload_dir.$filename, 129, 239.6, 60, 15); // FIXME Position will be wrong with non A4 format. Use a value from width and height of page minus relative offset. - $pdf->Close(); - $pdf->Output($newpdffilename, "F"); - + if (!$error) { $db->begin(); - // Index the new file and update the last_main_doc property of object. - $object->indexFile($newpdffilename, 1); - $online_sign_ip = getUserRemoteIP(); $online_sign_name = ''; // TODO Ask name on form to sign diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 9cfe5b47de5..62782d28a96 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -602,6 +602,8 @@ abstract class CommonObject // No constructor as it is an abstract class + + /** * Check an object id/ref exists * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch @@ -648,6 +650,7 @@ abstract class CommonObject return -1; } + /** * Method to output saved errors * @@ -5530,7 +5533,9 @@ abstract class CommonObject * Index a file into the ECM database * * @param string $destfull Full path of file to index - * @param int $update_main_doc_field Update field main_doc file into table of object + * @param int $update_main_doc_field Update field main_doc fied into the table of object. + * This param is set when called for a document generation if document generator hase + * ->update_main_doc_field set and returns ->result['fullpath']. * @return int <0 if KO, >0 if OK */ public function indexFile($destfull, $update_main_doc_field) diff --git a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php index 6f91d676949..7f2e0733e9d 100644 --- a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php +++ b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php @@ -71,6 +71,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales $this->db = $db; $this->name = "ODT templates"; $this->description = $langs->trans("DocumentModelOdt"); + $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template $this->scandir = 'PROPALE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan // Page size for A4 format diff --git a/htdocs/core/modules/propale/modules_propale.php b/htdocs/core/modules/propale/modules_propale.php index ee7df804c59..dcb386947a3 100644 --- a/htdocs/core/modules/propale/modules_propale.php +++ b/htdocs/core/modules/propale/modules_propale.php @@ -67,7 +67,7 @@ abstract class ModelePDFPropales extends CommonDocGenerator /** - * Classe mere des modeles de numerotation des references de propales + * Parent class for numbering rules of proposals */ abstract class ModeleNumRefPropales { diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index d1020dc2c1d..5e920444c35 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -328,7 +328,7 @@ if ($source == 'proposal') { // Object $text = ''.$langs->trans("SignatureProposalRef", $proposal->ref).''; - print '