22if (!defined(
'NOTOKENRENEWAL')) {
23 define(
'NOTOKENRENEWAL',
'1');
25if (!defined(
'NOREQUIREHTML')) {
26 define(
'NOREQUIREHTML',
'1');
28if (!defined(
'NOREQUIREAJAX')) {
29 define(
'NOREQUIREAJAX',
'1');
36if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU',
'1');
40if (!defined(
"NOLOGIN")) {
41 define(
"NOLOGIN",
'1');
43if (!defined(
'NOIPCHECK')) {
44 define(
'NOIPCHECK',
'1');
46if (!defined(
'NOBROWSERNOTIF')) {
47 define(
'NOBROWSERNOTIF',
'1');
49$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
50if (is_numeric($entity)) {
51 define(
"DOLENTITY", $entity);
53include
'../../main.inc.php';
54require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
56$action =
GETPOST(
'action',
'aZ09');
58$signature =
GETPOST(
'signaturebase64');
61$SECUREKEY =
GETPOST(
"securekey");
62$online_sign_name =
GETPOST(
"onlinesignname") ?
GETPOST(
"onlinesignname") :
'';
71if ($type ==
'proposal') {
73} elseif ($type ==
'contract') {
75} elseif ($type ==
'fichinter') {
78 $securekeyseed =
getDolGlobalString(strtoupper($type).
'_ONLINE_SIGNATURE_SECURITY_TOKEN');
81if (empty($SECUREKEY) || !
dol_verifyHash($securekeyseed . $type . $ref . (!isModEnabled(
'multicompany') ?
'' : $entity), $SECUREKEY,
'0')) {
99if ($action ==
"importSignature") {
100 $issignatureok = (!empty($signature) && $signature[0] ==
"image/png;base64");
101 if ($issignatureok) {
102 $signature = $signature[1];
103 $data = base64_decode($signature);
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);
111 $upload_dir = !empty($conf->propal->multidir_output[$object->entity]) ? $conf->propal->multidir_output[$object->entity] : $conf->propal->dir_output;
116 $langs->loadLangs(array(
"main",
"companies"));
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/";
128 $return = file_put_contents($upload_dir . $filename, $data);
129 if ($return ==
false) {
131 $response =
'Error file_put_content: failed to create signature file.';
137 $last_main_doc_file = $object->last_main_doc;
138 $directdownloadlink = $object->getLastMainDocLink(
'proposal');
140 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
142 $newpdffilename = $upload_dir . $ref .
"_signed-" . $date .
".pdf";
143 $sourcefile = $upload_dir . $ref .
".pdf";
148 if (class_exists(
'TCPDF')) {
149 $pdf->setPrintHeader(
false);
150 $pdf->setPrintFooter(
false);
155 $pdf->SetCompression(
false);
159 $pagecount = $pdf->setSourceFile($sourcefile);
162 $param[
'online_sign_name'] = $online_sign_name;
163 $param[
'pathtoimage'] = $upload_dir . $filename;
166 for ($i = 1; $i < ($pagecount + 1); $i++) {
168 $tppl = $pdf->importPage($i);
169 $s = $pdf->getTemplatesize($tppl);
170 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
171 $pdf->useTemplate($tppl);
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'];
184 dol_syslog(
"Error when manipulating the PDF " . $sourcefile .
" by onlineSign: " . $e->getMessage(), LOG_ERR);
185 $response = $e->getMessage();
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'];
202 $pdf->Output($newpdffilename,
"F");
205 $object->indexFile($newpdffilename, 1);
207 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
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) .
"'";
228 $sql .=
" WHERE rowid = " . ((int) $object->id);
231 $resql = $db->query($sql);
235 $num = $db->affected_rows($resql);
239 if (method_exists($object,
'call_trigger')) {
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);
247 $response =
"error in trigger " . $object->error;
249 $response =
"success";
252 $response =
"success";
256 $response =
"error sql";
261 $response =
"success";
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';
271 $object->fetch(0, $ref);
273 $upload_dir = !empty($conf->contrat->multidir_output[$object->entity]) ? $conf->contrat->multidir_output[$object->entity] : $conf->contrat->dir_output;
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/";
286 $return = file_put_contents($upload_dir . $filename, $data);
287 if ($return ==
false) {
289 $response =
'Error file_put_content: failed to create signature file.';
295 $last_main_doc_file = $object->last_main_doc;
296 $directdownloadlink = $object->getLastMainDocLink(
'contrat');
297 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
299 $newpdffilename = $upload_dir . $ref .
"_signed-" . $date .
".pdf";
300 $sourcefile = $upload_dir . $ref .
".pdf";
305 if (class_exists(
'TCPDF')) {
306 $pdf->setPrintHeader(
false);
307 $pdf->setPrintFooter(
false);
312 $pdf->SetCompression(
false);
316 $pagecount = $pdf->setSourceFile($sourcefile);
319 $param[
'online_sign_name'] = $online_sign_name;
320 $param[
'pathtoimage'] = $upload_dir . $filename;
323 for ($i = 1; $i < ($pagecount + 1); $i++) {
325 $tppl = $pdf->importPage($i);
326 $s = $pdf->getTemplatesize($tppl);
327 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
328 $pdf->useTemplate($tppl);
334 $param[
'xforimgstart'] = 10;
335 $param[
'yforimgstart'] = (empty($s[
'h']) ? 240 : $s[
'h'] - 65);
336 $param[
'wforimg'] = $s[
'w'] / 2 - $param[
'xforimgstart'];
341 dol_syslog(
"Error when manipulating some PDF by onlineSign: " . $e->getMessage(), LOG_ERR);
342 $response = $e->getMessage();
351 $param[
'xforimgstart'] = 10;
352 $param[
'yforimgstart'] = (empty($s[
'h']) ? 240 : $s[
'h'] - 65);
353 $param[
'wforimg'] = $s[
'w'] / 2 - $param[
'xforimgstart'];
359 $pdf->Output($newpdffilename,
"F");
362 $object->indexFile($newpdffilename, 1);
365 $response =
"success";
367 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
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';
379 $object->fetch(0, $ref);
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).
'/';
384 $langs->loadLangs(array(
"main",
"companies"));
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/";
399 $return = file_put_contents($upload_dir . $filename, $data);
400 if ($return ==
false) {
402 $response =
'Error file_put_content: failed to create signature file.';
408 $last_main_doc_file = $object->last_main_doc;
409 $directdownloadlink = $object->getLastMainDocLink(
'fichinter');
410 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
412 $newpdffilename = $upload_dir . $ref .
"_signed-" . $date .
".pdf";
413 $sourcefile = $upload_dir . $ref .
".pdf";
418 if (class_exists(
'TCPDF')) {
419 $pdf->setPrintHeader(
false);
420 $pdf->setPrintFooter(
false);
425 $pdf->SetCompression(
false);
429 $pagecount = $pdf->setSourceFile($sourcefile);
432 $param[
'online_sign_name'] = $online_sign_name;
433 $param[
'pathtoimage'] = $upload_dir . $filename;
436 for ($i = 1; $i < ($pagecount + 1); $i++) {
438 $tppl = $pdf->importPage($i);
439 $s = $pdf->getTemplatesize($tppl);
440 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
441 $pdf->useTemplate($tppl);
447 $param[
'xforimgstart'] = 111;
448 $param[
'yforimgstart'] = (empty($s[
'h']) ? 250 : $s[
'h'] - 60);
449 $param[
'wforimg'] = $s[
'w'] - ($param[
'xforimgstart'] + 16);
454 dol_syslog(
"Error when manipulating some PDF by onlineSign: " . $e->getMessage(), LOG_ERR);
455 $response = $e->getMessage();
464 $param[
'xforimgstart'] = 111;
465 $param[
'yforimgstart'] = (empty($s[
'h']) ? 250 : $s[
'h'] - 60);
466 $param[
'wforimg'] = $s[
'w'] - ($param[
'xforimgstart'] + 16);
472 $pdf->Output($newpdffilename,
"F");
475 $object->indexFile($newpdffilename, 1);
478 $response =
"success";
480 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
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/";
494 $object->fetch($ref);
495 if (!empty($object->id)) {
496 $object->fetch_thirdparty();
499 $upload_dir = $conf->societe->multidir_output[$object->thirdparty->entity] .
'/' .
dol_sanitizeFileName($object->thirdparty->id) .
'/';
503 $langs->loadLangs(array(
"main",
"companies"));
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/";
515 $return = file_put_contents($upload_dir . $filename, $data);
516 if ($return ==
false) {
518 $response =
'Error file_put_content: failed to create signature file.';
524 $last_main_doc_file = $object->last_main_doc;
525 $last_modelpdf = $object->model_pdf;
526 $directdownloadlink = $object->getLastMainDocLink(
'company');
528 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
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";
538 if (class_exists(
'TCPDF')) {
539 $pdf->setPrintHeader(
false);
540 $pdf->setPrintFooter(
false);
545 $pdf->SetCompression(
false);
549 $pagecount = $pdf->setSourceFile($sourcefile);
552 for ($i = 1; $i < ($pagecount + 1); $i++) {
554 $tppl = $pdf->importPage($i);
555 $s = $pdf->getTemplatesize($tppl);
556 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
557 $pdf->useTemplate($tppl);
559 dol_syslog(
"Error when manipulating the PDF " . $sourcefile .
" by onlineSign: " . $e->getMessage(), LOG_ERR);
560 $response = $e->getMessage();
570 $dirmodels = array(
'/');
571 if (is_array($conf->modules_parts[
'models'])) {
572 $dirmodels = array_merge($dirmodels, $conf->modules_parts[
'models']);
574 foreach ($dirmodels as $reldir) {
575 $file =
"pdf_" . $last_modelpdf .
".modules.php";
578 if (file_exists($file)) {
580 $classname =
'pdf_' . $last_modelpdf;
589 $response = $langs->trans(
"Error") .
' Failed to load doc generator with modelpaths=' . $modelpath .
' - modele=' . $last_modelpdf;
598 $objPDF =
new $classname($db);
600 $pdf->SetFont($default_font,
'', $default_font_size - 1);
602 $xForDate = $objPDF->marge_gauche;
603 $yForDate = $objPDF->page_hauteur - $objPDF->heightforinfotot - $objPDF->heightforfreetext - $objPDF->heightforfooter + 10;
604 $pdf->SetXY($xForDate, $yForDate);
607 $xforimgstart = $objPDF->xPosSignArea;
608 $yforimgstart = $yForDate - 5;
609 $wforimg = $s[
'w'] - 20 - $xforimgstart;
612 $param[
'online_sign_name'] = $online_sign_name;
613 $param[
'pathtoimage'] = $upload_dir . $filename;
618 $param[
'xforimgstart'] = $xforimgstart;
619 $param[
'yforimgstart'] = $yforimgstart;
620 $param[
'wforimg'] = $wforimg;
625 $pdf->Output($newpdffilename,
"F");
628 $object->indexFile($newpdffilename, 1);
630 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
640 $response =
"cannot find Rib";
648 $sql =
"UPDATE " . MAIN_DB_PREFIX . $object->table_element;
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) .
"'";
657 $sql .=
" WHERE rowid = " . ((int) $object->id);
660 $resql = $db->query($sql);
664 $num = $db->affected_rows($resql);
668 $response =
"success";
671 $response =
"error sql";
676 $response =
"success";
685 $response =
'error signature_not_found';
690 http_response_code(501);
708 $xforimgstart = $params[
'xforimgstart'];
709 $yforimgstart = $params[
'yforimgstart'];
710 $wforimg = $params[
'wforimg'];
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');
719 $pdf->Image($params[
'pathtoimage'], $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
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.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
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.