| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 |
- <?php
- /*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file /htdocs/core/ajax/onlineSign.php
- * \brief File to make Ajax action on Knowledge Management
- */
- if (!defined('NOTOKENRENEWAL')) {
- define('NOTOKENRENEWAL', '1'); // Disables token renewal
- }
- if (!defined('NOREQUIREHTML')) {
- define('NOREQUIREHTML', '1');
- }
- if (!defined('NOREQUIREAJAX')) {
- define('NOREQUIREAJAX', '1');
- }
- // Needed to create other objects with workflow
- /*if (!defined('NOREQUIRESOC')) {
- define('NOREQUIRESOC', '1');
- }*/
- // Do not check anti CSRF attack test
- if (!defined('NOREQUIREMENU')) {
- define('NOREQUIREMENU', '1');
- }
- // If there is no need to load and show top and left menu
- if (!defined("NOLOGIN")) {
- define("NOLOGIN", '1');
- }
- if (!defined('NOIPCHECK')) {
- define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
- }
- if (!defined('NOBROWSERNOTIF')) {
- define('NOBROWSERNOTIF', '1');
- }
- $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
- if (is_numeric($entity)) {
- define("DOLENTITY", $entity);
- }
- include '../../main.inc.php';
- require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
- $action = GETPOST('action', 'aZ09');
- $signature = GETPOST('signaturebase64');
- $ref = GETPOST('ref', 'aZ09');
- $mode = GETPOST('mode', 'aZ09'); // 'proposal', ...
- $SECUREKEY = GETPOST("securekey"); // Secure key
- $online_sign_name = GETPOST("onlinesignname") ? GETPOST("onlinesignname") : '';
- $error = 0;
- $response = "";
- $type = $mode;
- // Security check
- $securekeyseed = '';
- if ($type == 'proposal') {
- $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
- } elseif ($type == 'contract') {
- $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN');
- } elseif ($type == 'fichinter') {
- $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN');
- } else {
- $securekeyseed = getDolGlobalString(strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN');
- }
- if (empty($SECUREKEY) || !dol_verifyHash($securekeyseed . $type . $ref . (!isModEnabled('multicompany') ? '' : $entity), $SECUREKEY, '0')) {
- httponly_accessforbidden('Bad value for securitykey. Value provided ' . dol_escape_htmltag($SECUREKEY) . ' does not match expected value for ref=' . dol_escape_htmltag($ref), 403);
- }
- /*
- * Actions
- */
- // None
- /*
- * View
- */
- top_httphead();
- if ($action == "importSignature") {
- $issignatureok = (!empty($signature) && $signature[0] == "image/png;base64");
- if ($issignatureok) {
- $signature = $signature[1];
- $data = base64_decode($signature);
- if ($mode == "propale" || $mode == 'proposal') {
- require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
- $object = new Propal($db);
- $object->fetch(0, $ref);
- $upload_dir = !empty($conf->propal->multidir_output[$object->entity]) ? $conf->propal->multidir_output[$object->entity] : $conf->propal->dir_output;
- $upload_dir .= '/' . dol_sanitizeFileName($object->ref) . '/';
- $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
- $default_font = pdf_getPDFFont($langs); // Must be after pdf_getInstance
- $langs->loadLangs(array("main", "companies"));
- $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
- $filename = "signatures/" . $date . "_signature.png";
- if (!is_dir($upload_dir . "signatures/")) {
- if (!dol_mkdir($upload_dir . "signatures/")) {
- $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
- $error++;
- }
- }
- if (!$error) {
- $return = file_put_contents($upload_dir . $filename, $data);
- if ($return == false) {
- $error++;
- $response = 'Error file_put_content: failed to create signature file.';
- }
- }
- if (!$error) {
- // Defined modele of doc
- $last_main_doc_file = $object->last_main_doc;
- $directdownloadlink = $object->getLastMainDocLink('proposal'); // url to download the $object->last_main_doc
- if (preg_match('/\.pdf/i', $last_main_doc_file)) {
- // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
- $newpdffilename = $upload_dir . $ref . "_signed-" . $date . ".pdf";
- $sourcefile = $upload_dir . $ref . ".pdf";
- if (dol_is_file($sourcefile)) {
- // We build the new PDF
- $pdf = pdf_getInstance();
- if (class_exists('TCPDF')) {
- $pdf->setPrintHeader(false);
- $pdf->setPrintFooter(false);
- }
- $pdf->SetFont(pdf_getPDFFont($langs));
- if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
- $pdf->SetCompression(false);
- }
- //$pdf->Open();
- $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
- $param = array();
- $param['online_sign_name'] = $online_sign_name;
- $param['pathtoimage'] = $upload_dir . $filename;
- $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
- for ($i = 1; $i < ($pagecount + 1); $i++) {
- try {
- $tppl = $pdf->importPage($i);
- $s = $pdf->getTemplatesize($tppl);
- $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
- $pdf->useTemplate($tppl);
- if (getDolGlobalString("PROPAL_SIGNATURE_ON_ALL_PAGES")) {
- // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
- // TODO Get position of box from PDF template
- $param['xforimgstart'] = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
- $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 60);
- $param['wforimg'] = $s['w'] - 20 - $param['xforimgstart'];
- dolPrintSignatureImage($pdf, $langs, $param);
- }
- } catch (Exception $e) {
- dol_syslog("Error when manipulating the PDF " . $sourcefile . " by onlineSign: " . $e->getMessage(), LOG_ERR);
- $response = $e->getMessage();
- $error++;
- }
- }
- if (!getDolGlobalString("PROPAL_SIGNATURE_ON_ALL_PAGES")) {
- // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
- // TODO Get position of box from PDF template
- $param['xforimgstart'] = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
- $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 60);
- $param['wforimg'] = $s['w'] - 20 - $param['xforimgstart'];
- dolPrintSignatureImage($pdf, $langs, $param);
- }
- //$pdf->Close();
- $pdf->Output($newpdffilename, "F");
- // Index the new file and update the last_main_doc property of object.
- $object->indexFile($newpdffilename, 1);
- }
- } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
- // Adding signature on .ODT not yet supported
- // TODO
- } else {
- // Document format not supported to insert online signature.
- // We should just create an image file with the signature.
- }
- }
- if (!$error) {
- $db->begin();
- $online_sign_ip = getUserRemoteIP();
- $sql = "UPDATE " . MAIN_DB_PREFIX . "propal";
- $sql .= " SET fk_statut = " . ((int) $object::STATUS_SIGNED) . ", note_private = '" . $db->escape($object->note_private) . "',";
- $sql .= " date_signature = '" . $db->idate(dol_now()) . "',";
- $sql .= " online_sign_ip = '" . $db->escape($online_sign_ip) . "'";
- if ($online_sign_name) {
- $sql .= ", online_sign_name = '" . $db->escape($online_sign_name) . "'";
- }
- $sql .= " WHERE rowid = " . ((int) $object->id);
- dol_syslog(__FILE__, LOG_DEBUG);
- $resql = $db->query($sql);
- if (!$resql) {
- $error++;
- } else {
- $num = $db->affected_rows($resql);
- }
- if (!$error) {
- if (method_exists($object, 'call_trigger')) {
- //customer is not a user !?! so could we use same user as validation ?
- $user = new User($db);
- $user->fetch($object->user_validation_id);
- $object->context = array('closedfromonlinesignature' => 'closedfromonlinesignature');
- $result = $object->call_trigger('PROPAL_CLOSE_SIGNED', $user);
- if ($result < 0) {
- $error++;
- $response = "error in trigger " . $object->error;
- } else {
- $response = "success";
- }
- } else {
- $response = "success";
- }
- } else {
- $error++;
- $response = "error sql";
- }
- if (!$error) {
- $db->commit();
- $response = "success";
- setEventMessages("PropalSigned", null, 'warnings');
- } else {
- $db->rollback();
- }
- }
- } elseif ($mode == 'contract') {
- require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
- $object = new Contrat($db);
- $object->fetch(0, $ref);
- $upload_dir = !empty($conf->contrat->multidir_output[$object->entity]) ? $conf->contrat->multidir_output[$object->entity] : $conf->contrat->dir_output;
- $upload_dir .= '/' . dol_sanitizeFileName($object->ref) . '/';
- $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
- $filename = "signatures/" . $date . "_signature.png";
- if (!is_dir($upload_dir . "signatures/")) {
- if (!dol_mkdir($upload_dir . "signatures/")) {
- $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
- $error++;
- }
- }
- if (!$error) {
- $return = file_put_contents($upload_dir . $filename, $data);
- if ($return == false) {
- $error++;
- $response = 'Error file_put_content: failed to create signature file.';
- }
- }
- if (!$error) {
- // Defined modele of doc
- $last_main_doc_file = $object->last_main_doc;
- $directdownloadlink = $object->getLastMainDocLink('contrat'); // url to download the $object->last_main_doc
- if (preg_match('/\.pdf/i', $last_main_doc_file)) {
- // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
- $newpdffilename = $upload_dir . $ref . "_signed-" . $date . ".pdf";
- $sourcefile = $upload_dir . $ref . ".pdf";
- if (dol_is_file($sourcefile)) {
- // We build the new PDF
- $pdf = pdf_getInstance();
- if (class_exists('TCPDF')) {
- $pdf->setPrintHeader(false);
- $pdf->setPrintFooter(false);
- }
- $pdf->SetFont(pdf_getPDFFont($langs));
- if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
- $pdf->SetCompression(false);
- }
- //$pdf->Open();
- $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
- $param = array();
- $param['online_sign_name'] = $online_sign_name;
- $param['pathtoimage'] = $upload_dir . $filename;
- $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
- for ($i = 1; $i < ($pagecount + 1); $i++) {
- try {
- $tppl = $pdf->importPage($i);
- $s = $pdf->getTemplatesize($tppl);
- $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
- $pdf->useTemplate($tppl);
- if (getDolGlobalString("CONTRACT_SIGNATURE_ON_ALL_PAGES")) {
- // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
- // TODO Get position of box from PDF template
- $param['xforimgstart'] = 10;
- $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 65);
- $param['wforimg'] = $s['w'] / 2 - $param['xforimgstart'];
- dolPrintSignatureImage($pdf, $langs, $param);
- }
- } catch (Exception $e) {
- dol_syslog("Error when manipulating some PDF by onlineSign: " . $e->getMessage(), LOG_ERR);
- $response = $e->getMessage();
- $error++;
- }
- }
- if (!getDolGlobalString("CONTRACT_SIGNATURE_ON_ALL_PAGES")) {
- // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
- // TODO Get position of box from PDF template
- $param['xforimgstart'] = 10;
- $param['yforimgstart'] = (empty($s['h']) ? 240 : $s['h'] - 65);
- $param['wforimg'] = $s['w'] / 2 - $param['xforimgstart'];
- dolPrintSignatureImage($pdf, $langs, $param);
- }
- //$pdf->Close();
- $pdf->Output($newpdffilename, "F");
- // Index the new file and update the last_main_doc property of object.
- $object->indexFile($newpdffilename, 1);
- }
- if (!$error) {
- $response = "success";
- }
- } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
- // Adding signature on .ODT not yet supported
- // TODO
- } else {
- // Document format not supported to insert online signature.
- // We should just create an image file with the signature.
- }
- }
- } elseif ($mode == 'fichinter') {
- require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
- $object = new Fichinter($db);
- $object->fetch(0, $ref);
- $upload_dir = !empty($conf->ficheinter->multidir_output[$object->entity]) ? $conf->ficheinter->multidir_output[$object->entity] : $conf->ficheinter->dir_output;
- $upload_dir .= '/'.dol_sanitizeFileName($object->ref).'/';
- $langs->loadLangs(array("main", "companies"));
- $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
- $default_font = pdf_getPDFFont($langs); // Must be
- $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
- $filename = "signatures/" . $date . "_signature.png";
- if (!is_dir($upload_dir . "signatures/")) {
- if (!dol_mkdir($upload_dir . "signatures/")) {
- $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
- $error++;
- }
- }
- if (!$error) {
- $return = file_put_contents($upload_dir . $filename, $data);
- if ($return == false) {
- $error++;
- $response = 'Error file_put_content: failed to create signature file.';
- }
- }
- if (!$error) {
- // Defined modele of doc
- $last_main_doc_file = $object->last_main_doc;
- $directdownloadlink = $object->getLastMainDocLink('fichinter'); // url to download the $object->last_main_doc
- if (preg_match('/\.pdf/i', $last_main_doc_file)) {
- // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
- $newpdffilename = $upload_dir . $ref . "_signed-" . $date . ".pdf";
- $sourcefile = $upload_dir . $ref . ".pdf";
- if (dol_is_file($sourcefile)) {
- // We build the new PDF
- $pdf = pdf_getInstance();
- if (class_exists('TCPDF')) {
- $pdf->setPrintHeader(false);
- $pdf->setPrintFooter(false);
- }
- $pdf->SetFont(pdf_getPDFFont($langs));
- if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
- $pdf->SetCompression(false);
- }
- //$pdf->Open();
- $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
- $param = array();
- $param['online_sign_name'] = $online_sign_name;
- $param['pathtoimage'] = $upload_dir . $filename;
- $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
- for ($i = 1; $i < ($pagecount + 1); $i++) {
- try {
- $tppl = $pdf->importPage($i);
- $s = $pdf->getTemplatesize($tppl);
- $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
- $pdf->useTemplate($tppl);
- if (getDolGlobalString("FICHINTER_SIGNATURE_ON_ALL_PAGES")) {
- // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
- // TODO Get position of box from PDF template
- $param['xforimgstart'] = 111;
- $param['yforimgstart'] = (empty($s['h']) ? 250 : $s['h'] - 60);
- $param['wforimg'] = $s['w'] - ($param['xforimgstart'] + 16);
- dolPrintSignatureImage($pdf, $langs, $param);
- }
- } catch (Exception $e) {
- dol_syslog("Error when manipulating some PDF by onlineSign: " . $e->getMessage(), LOG_ERR);
- $response = $e->getMessage();
- $error++;
- }
- }
- if (!getDolGlobalString("FICHINTER_SIGNATURE_ON_ALL_PAGES")) {
- // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
- // TODO Get position of box from PDF template
- $param['xforimgstart'] = 111;
- $param['yforimgstart'] = (empty($s['h']) ? 250 : $s['h'] - 60);
- $param['wforimg'] = $s['w'] - ($param['xforimgstart'] + 16);
- dolPrintSignatureImage($pdf, $langs, $param);
- }
- //$pdf->Close();
- $pdf->Output($newpdffilename, "F");
- // Index the new file and update the last_main_doc property of object.
- $object->indexFile($newpdffilename, 1);
- }
- if (!$error) {
- $response = "success";
- }
- } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
- // Adding signature on .ODT not yet supported
- // TODO
- } else {
- // Document format not supported to insert online signature.
- // We should just create an image file with the signature.
- }
- }
- } elseif ($mode == "societe_rib") {
- $langs->load('withdrawals');
- require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
- $modelpath = "core/modules/bank/doc/";
- $object = new CompanyBankAccount($db);
- $object->fetch($ref);
- if (!empty($object->id)) {
- $object->fetch_thirdparty();
- $upload_dir = $conf->societe->multidir_output[$object->thirdparty->entity] . '/' . dol_sanitizeFileName($object->thirdparty->id) . '/';
- $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
- $default_font = pdf_getPDFFont($langs); // Must be after pdf_getInstance
- $langs->loadLangs(array("main", "companies"));
- $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S");
- $filename = "signatures/" . $date . "_signature.png";
- if (!is_dir($upload_dir . "signatures/")) {
- if (!dol_mkdir($upload_dir . "signatures/")) {
- $response = "Error mkdir. Failed to create dir " . $upload_dir . "signatures/";
- $error++;
- }
- }
- if (!$error) {
- $return = file_put_contents($upload_dir . $filename, $data);
- if ($return == false) {
- $error++;
- $response = 'Error file_put_content: failed to create signature file.';
- }
- }
- if (!$error) {
- // Defined modele of doc
- $last_main_doc_file = $object->last_main_doc;
- $last_modelpdf = $object->model_pdf;
- $directdownloadlink = $object->getLastMainDocLink('company'); // url to download the $object->last_main_doc
- if (preg_match('/\.pdf/i', $last_main_doc_file)) {
- $sourcefile = '';
- $newpdffilename = '';
- if ($last_modelpdf == 'sepamandate') {
- $newpdffilename = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref) . "-" . dol_sanitizeFileName($object->rum) . "_signed-" . $date . ".pdf";
- $sourcefile = $upload_dir . $langs->transnoentitiesnoconv("SepaMandateShort") . ' ' . dol_sanitizeFileName($object->ref) . "-" . dol_sanitizeFileName($object->rum) . ".pdf";
- }
- if (dol_is_file($sourcefile)) {
- // We build the new PDF
- $pdf = pdf_getInstance();
- if (class_exists('TCPDF')) {
- $pdf->setPrintHeader(false);
- $pdf->setPrintFooter(false);
- }
- $pdf->SetFont(pdf_getPDFFont($langs));
- if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
- $pdf->SetCompression(false);
- }
- //$pdf->Open();
- $pagecount = $pdf->setSourceFile($sourcefile); // original PDF
- $s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
- for ($i = 1; $i < ($pagecount + 1); $i++) {
- try {
- $tppl = $pdf->importPage($i);
- $s = $pdf->getTemplatesize($tppl);
- $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
- $pdf->useTemplate($tppl);
- } catch (Exception $e) {
- dol_syslog("Error when manipulating the PDF " . $sourcefile . " by onlineSign: " . $e->getMessage(), LOG_ERR);
- $response = $e->getMessage();
- $error++;
- }
- }
- // Get position of box from PDF template
- $file = '';
- $classname = '';
- $filefound = '';
- $dirmodels = array('/');
- if (is_array($conf->modules_parts['models'])) {
- $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
- }
- foreach ($dirmodels as $reldir) {
- $file = "pdf_" . $last_modelpdf . ".modules.php";
- // On vérifie l'emplacement du modele
- $file = dol_buildpath($reldir . $modelpath . $file, 0);
- if (file_exists($file)) {
- $filefound = $file;
- $classname = 'pdf_' . $last_modelpdf;
- break;
- }
- if ($filefound) {
- break;
- }
- }
- if (!$filefound) {
- $response = $langs->trans("Error") . ' Failed to load doc generator with modelpaths=' . $modelpath . ' - modele=' . $last_modelpdf;
- dol_syslog($response, LOG_ERR);
- $error++;
- }
- if (!$error) {
- // If PDF template class was found
- require_once $file;
- $objPDF = new $classname($db);
- $pdf->SetFont($default_font, '', $default_font_size - 1);
- $xForDate = $objPDF->marge_gauche;
- $yForDate = $objPDF->page_hauteur - $objPDF->heightforinfotot - $objPDF->heightforfreetext - $objPDF->heightforfooter + 10;
- $pdf->SetXY($xForDate, $yForDate);
- $pdf->MultiCell(100, 4, dol_print_date(dol_now(), "daytext", false, $langs, true), 0, 'L');
- $xforimgstart = $objPDF->xPosSignArea;
- $yforimgstart = $yForDate - 5;
- $wforimg = $s['w'] - 20 - $xforimgstart;
- $param = array();
- $param['online_sign_name'] = $online_sign_name;
- $param['pathtoimage'] = $upload_dir . $filename;
- // A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
- // TODO Get position of box from PDF template
- $param['xforimgstart'] = $xforimgstart;
- $param['yforimgstart'] = $yforimgstart;
- $param['wforimg'] = $wforimg;
- dolPrintSignatureImage($pdf, $langs, $param);
- }
- //$pdf->Close();
- $pdf->Output($newpdffilename, "F");
- // Index the new file and update the last_main_doc property of object.
- $object->indexFile($newpdffilename, 1);
- }
- } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
- // Adding signature on .ODT not yet supported
- // TODO
- } else {
- // Document format not supported to insert online signature.
- // We should just create an image file with the signature.
- }
- }
- } else {
- $error++;
- $response = "cannot find Rib";
- }
- if (!$error) {
- $db->begin();
- $online_sign_ip = getUserRemoteIP();
- $sql = "UPDATE " . MAIN_DB_PREFIX . $object->table_element;
- $sql .= " SET ";
- $sql .= " date_signature = '" . $db->idate(dol_now()) . "',";
- $sql .= " online_sign_ip = '" . $db->escape($online_sign_ip) . "'";
- if ($online_sign_name) {
- $sql .= ", online_sign_name = '" . $db->escape($online_sign_name) . "'";
- }
- //$sql .= ", last_main_doc = '" . $db->escape($object->element'..') . "'";
- $sql .= " WHERE rowid = " . ((int) $object->id);
- dol_syslog(__FILE__, LOG_DEBUG);
- $resql = $db->query($sql);
- if (!$resql) {
- $error++;
- } else {
- $num = $db->affected_rows($resql);
- }
- if (!$error) {
- $response = "success";
- } else {
- $error++;
- $response = "error sql";
- }
- if (!$error) {
- $db->commit();
- $response = "success";
- setEventMessages(dol_ucfirst($mode)."Signed", null, 'warnings');
- } else {
- $db->rollback();
- }
- }
- }
- } else {
- $error++;
- $response = 'error signature_not_found';
- }
- }
- if ($error) {
- http_response_code(501);
- }
- echo $response;
- /**
- * Output the signature file
- *
- * @param TCPDF $pdf PDF handler
- * @param Translate $langs Language
- * @param array $params Array of params
- * @return void
- */
- function dolPrintSignatureImage(TCPDF $pdf, $langs, $params)
- {
- $default_font_size = pdf_getPDFFontSize($langs); // Must be after pdf_getInstance
- $default_font = pdf_getPDFFont($langs); // Must be
- $xforimgstart = $params['xforimgstart'];
- $yforimgstart = $params['yforimgstart'];
- $wforimg = $params['wforimg'];
- $pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4) - 4);
- $pdf->SetFont($default_font, '', $default_font_size - 1);
- $pdf->SetTextColor(80, 80, 80);
- $pdf->MultiCell($wforimg, 4, $langs->trans("Signature") . ': ' . dol_print_date(dol_now(), "day", false, $langs, true). ' - '.$params['online_sign_name'], 0, 'L');
- //$pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4));
- //$pdf->MultiCell($wforimg, 4, $langs->trans("Lastname") . ': ' . $online_sign_name, 0, 'L');
- $pdf->Image($params['pathtoimage'], $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
- return;
- }
|