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");
70 if ($type ==
'proposal') {
74 if (empty($SECUREKEY) || !
dol_verifyHash($securekeyseed.$type.$ref.(!
isModEnabled(
'multicompany') ?
'' : $entity), $SECUREKEY,
'0')) {
92 if ($action ==
"importSignature") {
93 if (!empty($signature) && $signature[0] ==
"image/png;base64") {
94 $signature = $signature[1];
95 $data = base64_decode($signature);
97 if ($mode ==
"propale" || $mode ==
'proposal') {
98 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
99 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
100 $object =
new Propal($db);
101 $object->fetch(0, $ref);
103 $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
104 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
107 $filename =
"signatures/".$date.
"_signature.png";
108 if (!is_dir($upload_dir.
"signatures/")) {
109 if (!
dol_mkdir($upload_dir.
"signatures/")) {
110 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
116 $return = file_put_contents($upload_dir.$filename, $data);
117 if ($return ==
false) {
119 $response =
'Error file_put_content: failed to create signature file.';
125 $last_main_doc_file = $object->last_main_doc;
126 $directdownloadlink = $object->getLastMainDocLink(
'proposal');
128 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
130 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
131 $sourcefile = $upload_dir.$ref.
".pdf";
136 if (class_exists(
'TCPDF')) {
137 $pdf->setPrintHeader(
false);
138 $pdf->setPrintFooter(
false);
143 $pdf->SetCompression(
false);
148 $pagecount = $pdf->setSourceFile($sourcefile);
151 for ($i=1; $i<($pagecount+1); $i++) {
153 $tppl = $pdf->importPage($i);
154 $s = $pdf->getTemplatesize($tppl);
155 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
156 $pdf->useTemplate($tppl);
158 dol_syslog(
"Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
159 $response = $e->getMessage();
166 $xforimgstart = (empty($s[
'w']) ? 120 : round($s[
'w'] / 2) + 15);
167 $yforimgstart = (empty($s[
'h']) ? 240 : $s[
'h'] - 60);
168 $wforimg = $s[
'w'] - 20 - $xforimgstart;
170 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
172 $pdf->Output($newpdffilename,
"F");
175 $object->indexFile($newpdffilename, 1);
177 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
190 $online_sign_name =
'';
192 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
193 $sql .=
" SET fk_statut = ".((int) $object::STATUS_SIGNED).
", note_private = '".$db->escape($object->note_private).
"',";
194 $sql .=
" date_signature = '".$db->idate(
dol_now()).
"',";
195 $sql .=
" online_sign_ip = '".$db->escape($online_sign_ip).
"'";
196 if ($online_sign_name) {
197 $sql .=
", online_sign_name = '".$db->escape($online_sign_name).
"'";
199 $sql .=
" WHERE rowid = ".((int) $object->id);
202 $resql = $db->query($sql);
206 $num = $db->affected_rows(
$resql);
211 $response =
"success";
213 if (method_exists($object,
'call_trigger')) {
215 $user =
new User($db);
216 $user->fetch($object->user_valid_id);
217 $object->context = array(
'closedfromonlinesignature' =>
'closedfromonlinesignature');
218 $result = $object->call_trigger(
'PROPAL_CLOSE_SIGNED', $user);
222 $result = $object->call_trigger(
'PROPAL_CLOSE_SIGNED_WEB', $user);
230 $response =
"error sql";
233 } elseif ($mode ==
'contract') {
234 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
235 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
237 $object->fetch(0, $ref);
239 $upload_dir = !empty($conf->contrat->multidir_output[$object->entity])?$conf->contrat->multidir_output[$object->entity]:$conf->contrat->dir_output;
240 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
243 $filename =
"signatures/".$date.
"_signature.png";
244 if (!is_dir($upload_dir.
"signatures/")) {
245 if (!
dol_mkdir($upload_dir.
"signatures/")) {
246 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
252 $return = file_put_contents($upload_dir.$filename, $data);
253 if ($return ==
false) {
255 $response =
'Error file_put_content: failed to create signature file.';
261 $last_main_doc_file = $object->last_main_doc;
262 $directdownloadlink = $object->getLastMainDocLink(
'contrat');
263 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
265 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
266 $sourcefile = $upload_dir.$ref.
".pdf";
271 if (class_exists(
'TCPDF')) {
272 $pdf->setPrintHeader(
false);
273 $pdf->setPrintFooter(
false);
278 $pdf->SetCompression(
false);
283 $pagecount = $pdf->setSourceFile($sourcefile);
285 for ($i=1; $i<($pagecount+1); $i++) {
287 $tppl = $pdf->importPage($i);
288 $s = $pdf->getTemplatesize($tppl);
289 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
290 $pdf->useTemplate($tppl);
292 dol_syslog(
"Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
293 $response = $e->getMessage();
301 $yforimgstart = (empty($s[
'h']) ? 240 : $s[
'h'] - 65);
302 $wforimg = $s[
'w']/2 - $xforimgstart;
304 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
306 $pdf->Output($newpdffilename,
"F");
309 $object->indexFile($newpdffilename, 1);
312 $response =
"success";
314 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
322 } elseif ($mode ==
'fichinter') {
323 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
324 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
326 $object->fetch(0, $ref);
328 $upload_dir = !empty($conf->ficheinter->multidir_output[$object->entity])?$conf->ficheinter->multidir_output[$object->entity]:$conf->ficheinter->dir_output;
329 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
331 $filename =
"signatures/".$date.
"_signature.png";
332 if (!is_dir($upload_dir.
"signatures/")) {
333 if (!
dol_mkdir($upload_dir.
"signatures/")) {
334 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
340 $return = file_put_contents($upload_dir.$filename, $data);
341 if ($return ==
false) {
343 $response =
'Error file_put_content: failed to create signature file.';
349 $last_main_doc_file = $object->last_main_doc;
350 $directdownloadlink = $object->getLastMainDocLink(
'fichinter');
351 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
353 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
354 $sourcefile = $upload_dir.$ref.
".pdf";
359 if (class_exists(
'TCPDF')) {
360 $pdf->setPrintHeader(
false);
361 $pdf->setPrintFooter(
false);
366 $pdf->SetCompression(
false);
371 $pagecount = $pdf->setSourceFile($sourcefile);
373 for ($i=1; $i<($pagecount+1); $i++) {
375 $tppl = $pdf->importPage($i);
376 $s = $pdf->getTemplatesize($tppl);
377 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
378 $pdf->useTemplate($tppl);
380 dol_syslog(
"Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
381 $response = $e->getMessage();
389 $yforimgstart = (empty($s[
'h']) ? 250 : $s[
'h'] - 57);
390 $wforimg = $s[
'w']/1 - ($xforimgstart + 16);
391 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
393 $pdf->Output($newpdffilename,
"F");
396 $object->indexFile($newpdffilename, 1);
399 $response =
"success";
401 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
412 $response =
'error signature_not_found';
417 http_response_code(501);
Class to manage contracts.
Class to manage interventions.
Class to manage proposals.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_is_file($pathoffile)
Return if path is a file.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
isModEnabled($module)
Is Dolibarr module enabled.
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)
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
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.