FIX online signature works partially on ODT templates.

This commit is contained in:
Laurent Destailleur 2022-07-10 18:06:41 +02:00
parent 3846520862
commit 09932000dd
5 changed files with 39 additions and 21 deletions

View File

@ -69,10 +69,10 @@ $type = $mode;
// Check securitykey // Check securitykey
$securekeyseed = ''; $securekeyseed = '';
if ($type == 'proposal') { 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); 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); print 'Bad value for securitykey. Value provided '.dol_escape_htmltag($SECUREKEY).' does not match expected value for ref='.dol_escape_htmltag($ref);
exit(-1); exit(-1);
@ -122,12 +122,18 @@ if ($action == "importSignature") {
} }
if (!$error) { if (!$error) {
$newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf"; // Defined modele of doc
$directdownloadlink = $object->getLastMainDocLink('proposal');
if (preg_match('/\.pdf/i', $directdownloadlink)) {
$newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf";
$sourcefile = $upload_dir.$ref.".pdf";
if (dol_is_file($sourcefile)) {
$pdf = pdf_getInstance(); $pdf = pdf_getInstance();
$pdf->Open(); $pdf->Open();
$pdf->AddPage(); $pdf->AddPage();
$pagecount = $pdf->setSourceFile($upload_dir.$ref.".pdf"); // original PDF $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
for ($i=1; $i<($pagecount+1); $i++) { for ($i=1; $i<($pagecount+1); $i++) {
if ($i>1) $pdf->AddPage(); if ($i>1) $pdf->AddPage();
@ -139,10 +145,16 @@ if ($action == "importSignature") {
$pdf->Close(); $pdf->Close();
$pdf->Output($newpdffilename, "F"); $pdf->Output($newpdffilename, "F");
$db->begin();
// Index the new file and update the last_main_doc property of object. // Index the new file and update the last_main_doc property of object.
$object->indexFile($newpdffilename, 1); $object->indexFile($newpdffilename, 1);
}
} else {
// Adding signature on doc not yet supported
}
}
if (!$error) {
$db->begin();
$online_sign_ip = getUserRemoteIP(); $online_sign_ip = getUserRemoteIP();
$online_sign_name = ''; // TODO Ask name on form to sign $online_sign_name = ''; // TODO Ask name on form to sign

View File

@ -602,6 +602,8 @@ abstract class CommonObject
// No constructor as it is an abstract class // No constructor as it is an abstract class
/** /**
* Check an object id/ref exists * 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 * 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; return -1;
} }
/** /**
* Method to output saved errors * Method to output saved errors
* *
@ -5530,7 +5533,9 @@ abstract class CommonObject
* Index a file into the ECM database * Index a file into the ECM database
* *
* @param string $destfull Full path of file to index * @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 * @return int <0 if KO, >0 if OK
*/ */
public function indexFile($destfull, $update_main_doc_field) public function indexFile($destfull, $update_main_doc_field)

View File

@ -71,6 +71,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
$this->db = $db; $this->db = $db;
$this->name = "ODT templates"; $this->name = "ODT templates";
$this->description = $langs->trans("DocumentModelOdt"); $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 $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 // Page size for A4 format

View File

@ -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 abstract class ModeleNumRefPropales
{ {

View File

@ -328,7 +328,7 @@ if ($source == 'proposal') {
// Object // Object
$text = '<b>'.$langs->trans("SignatureProposalRef", $proposal->ref).'</b>'; $text = '<b>'.$langs->trans("SignatureProposalRef", $proposal->ref).'</b>';
print '<tr class="CTableRow2"><td class="CTableRow2 tdtop">'.$langs->trans("Designation"); print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
print '</td><td class="CTableRow2">'.$text; print '</td><td class="CTableRow2">'.$text;
if ($proposal->status == $proposal::STATUS_VALIDATED) { if ($proposal->status == $proposal::STATUS_VALIDATED) {
$directdownloadlink = $proposal->getLastMainDocLink('proposal'); $directdownloadlink = $proposal->getLastMainDocLink('proposal');