22 if (!defined(
'NOTOKENRENEWAL')) {
23 define(
'NOTOKENRENEWAL',
'1');
25 if (!defined(
'NOREQUIREHTML')) {
26 define(
'NOREQUIREHTML',
'1');
28 if (!defined(
'NOREQUIREAJAX')) {
29 define(
'NOREQUIREAJAX',
'1');
36 if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU',
'1');
40 if (!defined(
"NOLOGIN")) {
41 define(
"NOLOGIN",
'1');
43 if (!defined(
'NOIPCHECK')) {
44 define(
'NOIPCHECK',
'1');
46 if (!defined(
'NOBROWSERNOTIF')) {
47 define(
'NOBROWSERNOTIF',
'1');
49 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
50 if (is_numeric($entity)) {
51 define(
"DOLENTITY", $entity);
53 include
'../../main.inc.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
56 $action =
GETPOST(
'action',
'aZ09');
58 $signature =
GETPOST(
'signaturebase64');
60 $mode =
GETPOST(
'mode',
'aZ09');
61 $SECUREKEY =
GETPOST(
"securekey");
62 $online_sign_name =
GETPOST(
"onlinesignname") ?
GETPOST(
"onlinesignname") :
'';
71 if ($type ==
'proposal') {
75 if (empty($SECUREKEY) || !
dol_verifyHash($securekeyseed.$type.$ref.(!
isModEnabled(
'multicompany') ?
'' : $entity), $SECUREKEY,
'0')) {
93 if ($action ==
"importSignature") {
94 $issignatureok = (!empty($signature) && $signature[0] ==
"image/png;base64");
96 $signature = $signature[1];
97 $data = base64_decode($signature);
99 if ($mode ==
"propale" || $mode ==
'proposal') {
100 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
101 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
102 $object =
new Propal($db);
103 $object->fetch(0, $ref);
105 $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
106 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
110 $langs->loadLangs(array(
"main",
"companies"));
113 $filename =
"signatures/".$date.
"_signature.png";
114 if (!is_dir($upload_dir.
"signatures/")) {
115 if (!
dol_mkdir($upload_dir.
"signatures/")) {
116 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
122 $return = file_put_contents($upload_dir.$filename, $data);
123 if ($return ==
false) {
125 $response =
'Error file_put_content: failed to create signature file.';
131 $last_main_doc_file = $object->last_main_doc;
132 $directdownloadlink = $object->getLastMainDocLink(
'proposal');
134 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
136 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
137 $sourcefile = $upload_dir.$ref.
".pdf";
142 if (class_exists(
'TCPDF')) {
143 $pdf->setPrintHeader(
false);
144 $pdf->setPrintFooter(
false);
149 $pdf->SetCompression(
false);
153 $pagecount = $pdf->setSourceFile($sourcefile);
156 for ($i=1; $i<($pagecount+1); $i++) {
158 $tppl = $pdf->importPage($i);
159 $s = $pdf->getTemplatesize($tppl);
160 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
161 $pdf->useTemplate($tppl);
163 dol_syslog(
"Error when manipulating the PDF ".$sourcefile.
" by onlineSign: ".$e->getMessage(), LOG_ERR);
164 $response = $e->getMessage();
171 $xforimgstart = (empty($s[
'w']) ? 120 : round($s[
'w'] / 2) + 15);
172 $yforimgstart = (empty($s[
'h']) ? 240 : $s[
'h'] - 60);
173 $wforimg = $s[
'w'] - 20 - $xforimgstart;
175 $pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4) - 4);
176 $pdf->SetFont($default_font,
'', $default_font_size - 1);
177 $pdf->MultiCell($wforimg, 4, $langs->trans(
"DateSigning").
': '.
dol_print_date(
dol_now(),
"daytext",
false, $langs,
true), 0,
'L');
178 $pdf->SetXY($xforimgstart, $yforimgstart + round($wforimg / 4));
179 $pdf->MultiCell($wforimg, 4, $langs->trans(
"Lastname").
': '.$online_sign_name, 0,
'L');
181 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
184 $pdf->Output($newpdffilename,
"F");
187 $object->indexFile($newpdffilename, 1);
189 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
203 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
204 $sql .=
" SET fk_statut = ".((int) $object::STATUS_SIGNED).
", note_private = '".$db->escape($object->note_private).
"',";
205 $sql .=
" date_signature = '".$db->idate(
dol_now()).
"',";
206 $sql .=
" online_sign_ip = '".$db->escape($online_sign_ip).
"'";
207 if ($online_sign_name) {
208 $sql .=
", online_sign_name = '".$db->escape($online_sign_name).
"'";
210 $sql .=
" WHERE rowid = ".((int) $object->id);
213 $resql = $db->query(
$sql);
217 $num = $db->affected_rows($resql);
221 if (method_exists($object,
'call_trigger')) {
223 $user =
new User($db);
224 $user->fetch($object->user_valid_id);
225 $object->context = array(
'closedfromonlinesignature' =>
'closedfromonlinesignature');
226 $result = $object->call_trigger(
'PROPAL_CLOSE_SIGNED', $user);
229 $response =
"error in trigger ".$object->error;
231 $response =
"success";
234 $response =
"success";
238 $response =
"error sql";
243 $response =
"success";
249 } elseif ($mode ==
'contract') {
250 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
251 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
253 $object->fetch(0, $ref);
255 $upload_dir = !empty($conf->contrat->multidir_output[$object->entity])?$conf->contrat->multidir_output[$object->entity]:$conf->contrat->dir_output;
256 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
259 $filename =
"signatures/".$date.
"_signature.png";
260 if (!is_dir($upload_dir.
"signatures/")) {
261 if (!
dol_mkdir($upload_dir.
"signatures/")) {
262 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
268 $return = file_put_contents($upload_dir.$filename, $data);
269 if ($return ==
false) {
271 $response =
'Error file_put_content: failed to create signature file.';
277 $last_main_doc_file = $object->last_main_doc;
278 $directdownloadlink = $object->getLastMainDocLink(
'contrat');
279 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
281 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
282 $sourcefile = $upload_dir.$ref.
".pdf";
287 if (class_exists(
'TCPDF')) {
288 $pdf->setPrintHeader(
false);
289 $pdf->setPrintFooter(
false);
294 $pdf->SetCompression(
false);
299 $pagecount = $pdf->setSourceFile($sourcefile);
301 for ($i=1; $i<($pagecount+1); $i++) {
303 $tppl = $pdf->importPage($i);
304 $s = $pdf->getTemplatesize($tppl);
305 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
306 $pdf->useTemplate($tppl);
308 dol_syslog(
"Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
309 $response = $e->getMessage();
317 $yforimgstart = (empty($s[
'h']) ? 240 : $s[
'h'] - 65);
318 $wforimg = $s[
'w']/2 - $xforimgstart;
320 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
322 $pdf->Output($newpdffilename,
"F");
325 $object->indexFile($newpdffilename, 1);
328 $response =
"success";
330 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
338 } elseif ($mode ==
'fichinter') {
339 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
340 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
342 $object->fetch(0, $ref);
344 $upload_dir = !empty($conf->ficheinter->multidir_output[$object->entity])?$conf->ficheinter->multidir_output[$object->entity]:$conf->ficheinter->dir_output;
345 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
347 $filename =
"signatures/".$date.
"_signature.png";
348 if (!is_dir($upload_dir.
"signatures/")) {
349 if (!
dol_mkdir($upload_dir.
"signatures/")) {
350 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
356 $return = file_put_contents($upload_dir.$filename, $data);
357 if ($return ==
false) {
359 $response =
'Error file_put_content: failed to create signature file.';
365 $last_main_doc_file = $object->last_main_doc;
366 $directdownloadlink = $object->getLastMainDocLink(
'fichinter');
367 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
369 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
370 $sourcefile = $upload_dir.$ref.
".pdf";
375 if (class_exists(
'TCPDF')) {
376 $pdf->setPrintHeader(
false);
377 $pdf->setPrintFooter(
false);
382 $pdf->SetCompression(
false);
387 $pagecount = $pdf->setSourceFile($sourcefile);
389 for ($i=1; $i<($pagecount+1); $i++) {
391 $tppl = $pdf->importPage($i);
392 $s = $pdf->getTemplatesize($tppl);
393 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
394 $pdf->useTemplate($tppl);
396 dol_syslog(
"Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
397 $response = $e->getMessage();
405 $yforimgstart = (empty($s[
'h']) ? 250 : $s[
'h'] - 57);
406 $wforimg = $s[
'w']/1 - ($xforimgstart + 16);
407 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
409 $pdf->Output($newpdffilename,
"F");
412 $object->indexFile($newpdffilename, 1);
415 $response =
"success";
417 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
428 $response =
'error signature_not_found';
433 http_response_code(501);