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
$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

View File

@ -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)

View File

@ -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

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
{

View File

@ -328,7 +328,7 @@ if ($source == 'proposal') {
// Object
$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;
if ($proposal->status == $proposal::STATUS_VALIDATED) {
$directdownloadlink = $proposal->getLastMainDocLink('proposal');