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') {
75if (empty($SECUREKEY) || !
dol_verifyHash($securekeyseed.$type.$ref.(!isModEnabled(
'multicompany') ?
'' : $entity), $SECUREKEY,
'0')) {
93if ($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 $langs->loadLangs(array(
"main",
"companies"));
349 $upload_dir = !empty($conf->ficheinter->multidir_output[$object->entity])?$conf->ficheinter->multidir_output[$object->entity]:$conf->ficheinter->dir_output;
350 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
352 $filename =
"signatures/".$date.
"_signature.png";
353 if (!is_dir($upload_dir.
"signatures/")) {
354 if (!
dol_mkdir($upload_dir.
"signatures/")) {
355 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
361 $return = file_put_contents($upload_dir.$filename, $data);
362 if ($return ==
false) {
364 $response =
'Error file_put_content: failed to create signature file.';
370 $last_main_doc_file = $object->last_main_doc;
371 $directdownloadlink = $object->getLastMainDocLink(
'fichinter');
372 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
374 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
375 $sourcefile = $upload_dir.$ref.
".pdf";
380 if (class_exists(
'TCPDF')) {
381 $pdf->setPrintHeader(
false);
382 $pdf->setPrintFooter(
false);
387 $pdf->SetCompression(
false);
392 $pagecount = $pdf->setSourceFile($sourcefile);
394 for ($i=1; $i<($pagecount+1); $i++) {
396 $tppl = $pdf->importPage($i);
397 $s = $pdf->getTemplatesize($tppl);
398 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
399 $pdf->useTemplate($tppl);
401 dol_syslog(
"Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
402 $response = $e->getMessage();
413 $yforimgstart = (empty($s[
'h']) ? 250 : $s[
'h'] - 57);
414 $wforimg = $s[
'w']/1 - ($xforimgstart + 16);
416 $pdf->SetXY(111, 235 +25);
417 $pdf->SetFont($default_font,
'', $default_font_size - 1);
418 $pdf->MultiCell($wforimg, 4, $langs->trans(
"DateSigning").
': '.
dol_print_date(
dol_now(),
"daytext",
false, $langs,
true), 0,
'L');
419 $pdf->SetXY(111, $pdf->GetY());
420 $pdf->MultiCell($wforimg, 4, $langs->trans(
"Lastname").
': '.$online_sign_name, 0,
'L');
423 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
425 $pdf->Output($newpdffilename,
"F");
428 $object->indexFile($newpdffilename, 1);
431 $response =
"success";
433 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
444 $response =
'error signature_not_found';
449 http_response_code(501);
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_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.
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.
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.