dolibarr 19.0.4
onlineSign.php
Go to the documentation of this file.
1<?php
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
22if (!defined('NOTOKENRENEWAL')) {
23 define('NOTOKENRENEWAL', '1'); // Disables token renewal
24}
25if (!defined('NOREQUIREHTML')) {
26 define('NOREQUIREHTML', '1');
27}
28if (!defined('NOREQUIREAJAX')) {
29 define('NOREQUIREAJAX', '1');
30}
31// Needed to create other objects with workflow
32/*if (!defined('NOREQUIRESOC')) {
33 define('NOREQUIRESOC', '1');
34}*/
35// Do not check anti CSRF attack test
36if (!defined('NOREQUIREMENU')) {
37 define('NOREQUIREMENU', '1');
38}
39// If there is no need to load and show top and left menu
40if (!defined("NOLOGIN")) {
41 define("NOLOGIN", '1');
42}
43if (!defined('NOIPCHECK')) {
44 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
45}
46if (!defined('NOBROWSERNOTIF')) {
47 define('NOBROWSERNOTIF', '1');
48}
49$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
50if (is_numeric($entity)) {
51 define("DOLENTITY", $entity);
52}
53include '../../main.inc.php';
54require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
55
56$action = GETPOST('action', 'aZ09');
57
58$signature = GETPOST('signaturebase64');
59$ref = GETPOST('ref', 'aZ09');
60$mode = GETPOST('mode', 'aZ09'); // 'proposal', ...
61$SECUREKEY = GETPOST("securekey"); // Secure key
62$online_sign_name = GETPOST("onlinesignname") ? GETPOST("onlinesignname") : '';
63
64$error = 0;
65$response = "";
66
67$type = $mode;
68
69// Security check
70$securekeyseed = '';
71if ($type == 'proposal') {
72 $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
73} elseif ($type == 'contract') {
74 $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN');
75} elseif ($type == 'fichinter') {
76 $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN');
77} else {
78 $securekeyseed = getDolGlobalString(strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN');
79}
80
81if (empty($SECUREKEY) || !dol_verifyHash($securekeyseed . $type . $ref . (!isModEnabled('multicompany') ? '' : $entity), $SECUREKEY, '0')) {
82 httponly_accessforbidden('Bad value for securitykey. Value provided ' . dol_escape_htmltag($SECUREKEY) . ' does not match expected value for ref=' . dol_escape_htmltag($ref), 403);
83}
84
85
86/*
87 * Actions
88 */
89
90// None
91
92
93/*
94 * View
95 */
96
98
99if ($action == "importSignature") {
100 $issignatureok = (!empty($signature) && $signature[0] == "image/png;base64");
101 if ($issignatureok) {
102 $signature = $signature[1];
103 $data = base64_decode($signature);
104
105 if ($mode == "propale" || $mode == 'proposal') {
106 require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
107 require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
108 $object = new Propal($db);
109 $object->fetch(0, $ref);
110
111 $upload_dir = !empty($conf->propal->multidir_output[$object->entity]) ? $conf->propal->multidir_output[$object->entity] : $conf->propal->dir_output;
112 $upload_dir .= '/' . dol_sanitizeFileName($object->ref) . '/';
113
114 $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
115 $default_font = pdf_getPDFFont($langs); // Must be after pdf_getInstance
116 $langs->loadLangs(array("main", "companies"));
117
118 $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
119 $filename = "signatures/" . $date . "_signature.png";
120 if (!is_dir($upload_dir . "signatures/")) {
121 if (!dol_mkdir($upload_dir . "signatures/")) {
122 $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
123 $error++;
124 }
125 }
126
127 if (!$error) {
128 $return = file_put_contents($upload_dir . $filename, $data);
129 if ($return == false) {
130 $error++;
131 $response = 'Error file_put_content: failed to create signature file.';
132 }
133 }
134
135 if (!$error) {
136 // Defined modele of doc
137 $last_main_doc_file = $object->last_main_doc;
138 $directdownloadlink = $object->getLastMainDocLink('proposal'); // url to download the $object->last_main_doc
139
140 if (preg_match('/\.pdf/i', $last_main_doc_file)) {
141 // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
142 $newpdffilename = $upload_dir . $ref . "_signed-" . $date . ".pdf";
143 $sourcefile = $upload_dir . $ref . ".pdf";
144
145 if (dol_is_file($sourcefile)) {
146 // We build the new PDF
147 $pdf = pdf_getInstance();
148 if (class_exists('TCPDF')) {
149 $pdf->setPrintHeader(false);
150 $pdf->setPrintFooter(false);
151 }
152 $pdf->SetFont(pdf_getPDFFont($langs));
153
154 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
155 $pdf->SetCompression(false);
156 }
157
158 //$pdf->Open();
159 $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
160
161 $param = array();
162 $param['online_sign_name'] = $online_sign_name;
163 $param['pathtoimage'] = $upload_dir . $filename;
164
165 $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
166 for ($i = 1; $i < ($pagecount + 1); $i++) {
167 try {
168 $tppl = $pdf->importPage($i);
169 $s = $pdf->getTemplatesize($tppl);
170 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
171 $pdf->useTemplate($tppl);
172
173 if (getDolGlobalString("PROPAL_SIGNATURE_ON_ALL_PAGES")) {
174 // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
175 // TODO Get position of box from PDF template
176
177 $param['xforimgstart'] = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
178 $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 60);
179 $param['wforimg'] = $s['w'] - 20 - $param['xforimgstart'];
180
181 dolPrintSignatureImage($pdf, $langs, $param);
182 }
183 } catch (Exception $e) {
184 dol_syslog("Error when manipulating the PDF " . $sourcefile . " by onlineSign: " . $e->getMessage(), LOG_ERR);
185 $response = $e->getMessage();
186 $error++;
187 }
188 }
189
190 if (!getDolGlobalString("PROPAL_SIGNATURE_ON_ALL_PAGES")) {
191 // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
192 // TODO Get position of box from PDF template
193
194 $param['xforimgstart'] = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
195 $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 60);
196 $param['wforimg'] = $s['w'] - 20 - $param['xforimgstart'];
197
198 dolPrintSignatureImage($pdf, $langs, $param);
199 }
200
201 //$pdf->Close();
202 $pdf->Output($newpdffilename, "F");
203
204 // Index the new file and update the last_main_doc property of object.
205 $object->indexFile($newpdffilename, 1);
206 }
207 } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
208 // Adding signature on .ODT not yet supported
209 // TODO
210 } else {
211 // Document format not supported to insert online signature.
212 // We should just create an image file with the signature.
213 }
214 }
215
216 if (!$error) {
217 $db->begin();
218
219 $online_sign_ip = getUserRemoteIP();
220
221 $sql = "UPDATE " . MAIN_DB_PREFIX . "propal";
222 $sql .= " SET fk_statut = " . ((int) $object::STATUS_SIGNED) . ", note_private = '" . $db->escape($object->note_private) . "',";
223 $sql .= " date_signature = '" . $db->idate(dol_now()) . "',";
224 $sql .= " online_sign_ip = '" . $db->escape($online_sign_ip) . "'";
225 if ($online_sign_name) {
226 $sql .= ", online_sign_name = '" . $db->escape($online_sign_name) . "'";
227 }
228 $sql .= " WHERE rowid = " . ((int) $object->id);
229
230 dol_syslog(__FILE__, LOG_DEBUG);
231 $resql = $db->query($sql);
232 if (!$resql) {
233 $error++;
234 } else {
235 $num = $db->affected_rows($resql);
236 }
237
238 if (!$error) {
239 if (method_exists($object, 'call_trigger')) {
240 //customer is not a user !?! so could we use same user as validation ?
241 $user = new User($db);
242 $user->fetch($object->user_validation_id);
243 $object->context = array('closedfromonlinesignature' => 'closedfromonlinesignature');
244 $result = $object->call_trigger('PROPAL_CLOSE_SIGNED', $user);
245 if ($result < 0) {
246 $error++;
247 $response = "error in trigger " . $object->error;
248 } else {
249 $response = "success";
250 }
251 } else {
252 $response = "success";
253 }
254 } else {
255 $error++;
256 $response = "error sql";
257 }
258
259 if (!$error) {
260 $db->commit();
261 $response = "success";
262 setEventMessages("PropalSigned", null, 'warnings');
263 } else {
264 $db->rollback();
265 }
266 }
267 } elseif ($mode == 'contract') {
268 require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';
269 require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
270 $object = new Contrat($db);
271 $object->fetch(0, $ref);
272
273 $upload_dir = !empty($conf->contrat->multidir_output[$object->entity]) ? $conf->contrat->multidir_output[$object->entity] : $conf->contrat->dir_output;
274 $upload_dir .= '/' . dol_sanitizeFileName($object->ref) . '/';
275
276 $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
277 $filename = "signatures/" . $date . "_signature.png";
278 if (!is_dir($upload_dir . "signatures/")) {
279 if (!dol_mkdir($upload_dir . "signatures/")) {
280 $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
281 $error++;
282 }
283 }
284
285 if (!$error) {
286 $return = file_put_contents($upload_dir . $filename, $data);
287 if ($return == false) {
288 $error++;
289 $response = 'Error file_put_content: failed to create signature file.';
290 }
291 }
292
293 if (!$error) {
294 // Defined modele of doc
295 $last_main_doc_file = $object->last_main_doc;
296 $directdownloadlink = $object->getLastMainDocLink('contrat'); // url to download the $object->last_main_doc
297 if (preg_match('/\.pdf/i', $last_main_doc_file)) {
298 // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
299 $newpdffilename = $upload_dir . $ref . "_signed-" . $date . ".pdf";
300 $sourcefile = $upload_dir . $ref . ".pdf";
301
302 if (dol_is_file($sourcefile)) {
303 // We build the new PDF
304 $pdf = pdf_getInstance();
305 if (class_exists('TCPDF')) {
306 $pdf->setPrintHeader(false);
307 $pdf->setPrintFooter(false);
308 }
309 $pdf->SetFont(pdf_getPDFFont($langs));
310
311 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
312 $pdf->SetCompression(false);
313 }
314
315 //$pdf->Open();
316 $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
317
318 $param = array();
319 $param['online_sign_name'] = $online_sign_name;
320 $param['pathtoimage'] = $upload_dir . $filename;
321
322 $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
323 for ($i = 1; $i < ($pagecount + 1); $i++) {
324 try {
325 $tppl = $pdf->importPage($i);
326 $s = $pdf->getTemplatesize($tppl);
327 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
328 $pdf->useTemplate($tppl);
329
330 if (getDolGlobalString("CONTRACT_SIGNATURE_ON_ALL_PAGES")) {
331 // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
332 // TODO Get position of box from PDF template
333
334 $param['xforimgstart'] = 10;
335 $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 65);
336 $param['wforimg'] = $s['w'] / 2 - $param['xforimgstart'];
337
338 dolPrintSignatureImage($pdf, $langs, $param);
339 }
340 } catch (Exception $e) {
341 dol_syslog("Error when manipulating some PDF by onlineSign: " . $e->getMessage(), LOG_ERR);
342 $response = $e->getMessage();
343 $error++;
344 }
345 }
346
347 if (!getDolGlobalString("CONTRACT_SIGNATURE_ON_ALL_PAGES")) {
348 // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
349 // TODO Get position of box from PDF template
350
351 $param['xforimgstart'] = 10;
352 $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 65);
353 $param['wforimg'] = $s['w'] / 2 - $param['xforimgstart'];
354
355 dolPrintSignatureImage($pdf, $langs, $param);
356 }
357
358 //$pdf->Close();
359 $pdf->Output($newpdffilename, "F");
360
361 // Index the new file and update the last_main_doc property of object.
362 $object->indexFile($newpdffilename, 1);
363 }
364 if (!$error) {
365 $response = "success";
366 }
367 } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
368 // Adding signature on .ODT not yet supported
369 // TODO
370 } else {
371 // Document format not supported to insert online signature.
372 // We should just create an image file with the signature.
373 }
374 }
375 } elseif ($mode == 'fichinter') {
376 require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php';
377 require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
378 $object = new Fichinter($db);
379 $object->fetch(0, $ref);
380
381 $upload_dir = !empty($conf->ficheinter->multidir_output[$object->entity]) ? $conf->ficheinter->multidir_output[$object->entity] : $conf->ficheinter->dir_output;
382 $upload_dir .= '/'.dol_sanitizeFileName($object->ref).'/';
383
384 $langs->loadLangs(array("main", "companies"));
385
386 $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
387 $default_font = pdf_getPDFFont($langs); // Must be
388
389 $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
390 $filename = "signatures/" . $date . "_signature.png";
391 if (!is_dir($upload_dir . "signatures/")) {
392 if (!dol_mkdir($upload_dir . "signatures/")) {
393 $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
394 $error++;
395 }
396 }
397
398 if (!$error) {
399 $return = file_put_contents($upload_dir . $filename, $data);
400 if ($return == false) {
401 $error++;
402 $response = 'Error file_put_content: failed to create signature file.';
403 }
404 }
405
406 if (!$error) {
407 // Defined modele of doc
408 $last_main_doc_file = $object->last_main_doc;
409 $directdownloadlink = $object->getLastMainDocLink('fichinter'); // url to download the $object->last_main_doc
410 if (preg_match('/\.pdf/i', $last_main_doc_file)) {
411 // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
412 $newpdffilename = $upload_dir . $ref . "_signed-" . $date . ".pdf";
413 $sourcefile = $upload_dir . $ref . ".pdf";
414
415 if (dol_is_file($sourcefile)) {
416 // We build the new PDF
417 $pdf = pdf_getInstance();
418 if (class_exists('TCPDF')) {
419 $pdf->setPrintHeader(false);
420 $pdf->setPrintFooter(false);
421 }
422 $pdf->SetFont(pdf_getPDFFont($langs));
423
424 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
425 $pdf->SetCompression(false);
426 }
427
428 //$pdf->Open();
429 $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
430
431 $param = array();
432 $param['online_sign_name'] = $online_sign_name;
433 $param['pathtoimage'] = $upload_dir . $filename;
434
435 $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
436 for ($i = 1; $i < ($pagecount + 1); $i++) {
437 try {
438 $tppl = $pdf->importPage($i);
439 $s = $pdf->getTemplatesize($tppl);
440 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
441 $pdf->useTemplate($tppl);
442
443 if (getDolGlobalString("FICHINTER_SIGNATURE_ON_ALL_PAGES")) {
444 // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
445 // TODO Get position of box from PDF template
446
447 $param['xforimgstart'] = 111;
448 $param['yforimgstart'] = (empty($s['h']) ? 250 : $s['h'] - 60);
449 $param['wforimg'] = $s['w'] - ($param['xforimgstart'] + 16);
450
451 dolPrintSignatureImage($pdf, $langs, $param);
452 }
453 } catch (Exception $e) {
454 dol_syslog("Error when manipulating some PDF by onlineSign: " . $e->getMessage(), LOG_ERR);
455 $response = $e->getMessage();
456 $error++;
457 }
458 }
459
460 if (!getDolGlobalString("FICHINTER_SIGNATURE_ON_ALL_PAGES")) {
461 // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
462 // TODO Get position of box from PDF template
463
464 $param['xforimgstart'] = 111;
465 $param['yforimgstart'] = (empty($s['h']) ? 250 : $s['h'] - 60);
466 $param['wforimg'] = $s['w'] - ($param['xforimgstart'] + 16);
467
468 dolPrintSignatureImage($pdf, $langs, $param);
469 }
470
471 //$pdf->Close();
472 $pdf->Output($newpdffilename, "F");
473
474 // Index the new file and update the last_main_doc property of object.
475 $object->indexFile($newpdffilename, 1);
476 }
477 if (!$error) {
478 $response = "success";
479 }
480 } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
481 // Adding signature on .ODT not yet supported
482 // TODO
483 } else {
484 // Document format not supported to insert online signature.
485 // We should just create an image file with the signature.
486 }
487 }
488 } elseif ($mode == "societe_rib") {
489 $langs->load('withdrawals');
490 require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
491 require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
492 $modelpath = "core/modules/bank/doc/";
493 $object = new CompanyBankAccount($db);
494 $object->fetch($ref);
495 if (!empty($object->id)) {
496 $object->fetch_thirdparty();
497
498
499 $upload_dir = $conf->societe->multidir_output[$object->thirdparty->entity] . '/' . dol_sanitizeFileName($object->thirdparty->id) . '/';
500
501 $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
502 $default_font = pdf_getPDFFont($langs); // Must be after pdf_getInstance
503 $langs->loadLangs(array("main", "companies"));
504
505 $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
506 $filename = "signatures/" . $date . "_signature.png";
507 if (!is_dir($upload_dir . "signatures/")) {
508 if (!dol_mkdir($upload_dir . "signatures/")) {
509 $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
510 $error++;
511 }
512 }
513
514 if (!$error) {
515 $return = file_put_contents($upload_dir . $filename, $data);
516 if ($return == false) {
517 $error++;
518 $response = 'Error file_put_content: failed to create signature file.';
519 }
520 }
521
522 if (!$error) {
523 // Defined modele of doc
524 $last_main_doc_file = $object->last_main_doc;
525 $last_modelpdf = $object->model_pdf;
526 $directdownloadlink = $object->getLastMainDocLink('company'); // url to download the $object->last_main_doc
527
528 if (preg_match('/\.pdf/i', $last_main_doc_file)) {
529 $sourcefile = '';
530 $newpdffilename = '';
531 if ($last_modelpdf == 'sepamandate') {
532 $newpdffilename = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref) . "-" . dol_sanitizeFileName($object->rum) . "_signed-" . $date . ".pdf";
533 $sourcefile = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref) . "-" . dol_sanitizeFileName($object->rum) . ".pdf";
534 }
535 if (dol_is_file($sourcefile)) {
536 // We build the new PDF
537 $pdf = pdf_getInstance();
538 if (class_exists('TCPDF')) {
539 $pdf->setPrintHeader(false);
540 $pdf->setPrintFooter(false);
541 }
542 $pdf->SetFont(pdf_getPDFFont($langs));
543
544 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
545 $pdf->SetCompression(false);
546 }
547
548 //$pdf->Open();
549 $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
550
551 $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
552 for ($i = 1; $i < ($pagecount + 1); $i++) {
553 try {
554 $tppl = $pdf->importPage($i);
555 $s = $pdf->getTemplatesize($tppl);
556 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
557 $pdf->useTemplate($tppl);
558 } catch (Exception $e) {
559 dol_syslog("Error when manipulating the PDF " . $sourcefile . " by onlineSign: " . $e->getMessage(), LOG_ERR);
560 $response = $e->getMessage();
561 $error++;
562 }
563 }
564
565
566 // Get position of box from PDF template
567 $file = '';
568 $classname = '';
569 $filefound = '';
570 $dirmodels = array('/');
571 if (is_array($conf->modules_parts['models'])) {
572 $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
573 }
574 foreach ($dirmodels as $reldir) {
575 $file = "pdf_" . $last_modelpdf . ".modules.php";
576 // On vérifie l'emplacement du modele
577 $file = dol_buildpath($reldir . $modelpath . $file, 0);
578 if (file_exists($file)) {
579 $filefound = $file;
580 $classname = 'pdf_' . $last_modelpdf;
581 break;
582 }
583 if ($filefound) {
584 break;
585 }
586 }
587
588 if (!$filefound) {
589 $response = $langs->trans("Error") . ' Failed to load doc generator with modelpaths=' . $modelpath . ' - modele=' . $last_modelpdf;
590 dol_syslog($response, LOG_ERR);
591 $error++;
592 }
593
594 if (!$error) {
595 // If PDF template class was found
596 require_once $file;
597
598 $objPDF = new $classname($db);
599
600 $pdf->SetFont($default_font, '', $default_font_size - 1);
601
602 $xForDate = $objPDF->marge_gauche;
603 $yForDate = $objPDF->page_hauteur - $objPDF->heightforinfotot - $objPDF->heightforfreetext - $objPDF->heightforfooter + 10;
604 $pdf->SetXY($xForDate, $yForDate);
605 $pdf->MultiCell(100, 4, dol_print_date(dol_now(), "daytext", false, $langs, true), 0, 'L');
606
607 $xforimgstart = $objPDF->xPosSignArea;
608 $yforimgstart = $yForDate - 5;
609 $wforimg = $s['w'] - 20 - $xforimgstart;
610
611 $param = array();
612 $param['online_sign_name'] = $online_sign_name;
613 $param['pathtoimage'] = $upload_dir . $filename;
614
615 // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
616 // TODO Get position of box from PDF template
617
618 $param['xforimgstart'] = $xforimgstart;
619 $param['yforimgstart'] = $yforimgstart;
620 $param['wforimg'] = $wforimg;
621
622 dolPrintSignatureImage($pdf, $langs, $param);
623 }
624 //$pdf->Close();
625 $pdf->Output($newpdffilename, "F");
626
627 // Index the new file and update the last_main_doc property of object.
628 $object->indexFile($newpdffilename, 1);
629 }
630 } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
631 // Adding signature on .ODT not yet supported
632 // TODO
633 } else {
634 // Document format not supported to insert online signature.
635 // We should just create an image file with the signature.
636 }
637 }
638 } else {
639 $error++;
640 $response = "cannot find Rib";
641 }
642
643 if (!$error) {
644 $db->begin();
645
646 $online_sign_ip = getUserRemoteIP();
647
648 $sql = "UPDATE " . MAIN_DB_PREFIX . $object->table_element;
649 $sql .= " SET ";
650 $sql .= " date_signature = '" . $db->idate(dol_now()) . "',";
651 $sql .= " online_sign_ip = '" . $db->escape($online_sign_ip) . "'";
652 if ($online_sign_name) {
653 $sql .= ", online_sign_name = '" . $db->escape($online_sign_name) . "'";
654 }
655 //$sql .= ", last_main_doc = '" . $db->escape($object->element'..') . "'";
656
657 $sql .= " WHERE rowid = " . ((int) $object->id);
658
659 dol_syslog(__FILE__, LOG_DEBUG);
660 $resql = $db->query($sql);
661 if (!$resql) {
662 $error++;
663 } else {
664 $num = $db->affected_rows($resql);
665 }
666
667 if (!$error) {
668 $response = "success";
669 } else {
670 $error++;
671 $response = "error sql";
672 }
673
674 if (!$error) {
675 $db->commit();
676 $response = "success";
677 setEventMessages(dol_ucfirst($mode)."Signed", null, 'warnings');
678 } else {
679 $db->rollback();
680 }
681 }
682 }
683 } else {
684 $error++;
685 $response = 'error signature_not_found';
686 }
687}
688
689if ($error) {
690 http_response_code(501);
691}
692
693echo $response;
694
695
704function dolPrintSignatureImage(TCPDF $pdf, $langs, $params)
705{
706 $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
707 $default_font = pdf_getPDFFont($langs); // Must be
708 $xforimgstart = $params['xforimgstart'];
709 $yforimgstart = $params['yforimgstart'];
710 $wforimg = $params['wforimg'];
711
712 $pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4) - 4);
713 $pdf->SetFont($default_font, '', $default_font_size - 1);
714 $pdf->SetTextColor(80, 80, 80);
715 $pdf->MultiCell($wforimg, 4, $langs->trans("Signature") . ': ' . dol_print_date(dol_now(), "day", false, $langs, true). ' - '.$params['online_sign_name'], 0, 'L');
716 //$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4));
717 //$pdf->MultiCell($wforimg, 4, $langs->trans("Lastname") . ': ' . $online_sign_name, 0, 'L');
718
719 $pdf->Image($params['pathtoimage'], $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
720
721 return;
722}
Class to manage bank accounts description of third parties.
Class to manage contracts.
Class to manage interventions.
Class to manage proposals.
Class to manage Dolibarr users.
dol_is_file($pathoffile)
Return if path is a file.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
dolPrintSignatureImage(TCPDF $pdf, $langs, $params)
Output the signature file.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:127
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.