dolibarr  17.0.4
newonlinesign.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
27 if (!defined('NOLOGIN')) {
28  define("NOLOGIN", 1); // This means this output page does not require to be logged.
29 }
30 if (!defined('NOCSRFCHECK')) {
31  define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
32 }
33 if (!defined('NOIPCHECK')) {
34  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
35 }
36 if (!defined('NOBROWSERNOTIF')) {
37  define('NOBROWSERNOTIF', '1');
38 }
39 
40 // For MultiCompany module.
41 // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
42 // Because 2 entities can have the same ref.
43 $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
44 if (is_numeric($entity)) {
45  define("DOLENTITY", $entity);
46 }
47 
48 // Load Dolibarr environment
49 require '../../main.inc.php';
50 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
53 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
54 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
55 
56 // Load translation files
57 $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "propal", "commercial"));
58 
59 // Security check
60 // No check on module enabled. Done later according to $validpaymentmethod
61 
62 // Get parameters
63 $action = GETPOST('action', 'aZ09');
64 $cancel = GETPOST('cancel', 'alpha');
65 $confirm = GETPOST('confirm', 'alpha');
66 
67 
68 $refusepropal = GETPOST('refusepropal', 'alpha');
69 $message = GETPOST('message', 'aZ09');
70 
71 // Input are:
72 // type ('invoice','order','contractline'),
73 // id (object id),
74 // amount (required if id is empty),
75 // tag (a free text, required if type is empty)
76 // currency (iso code)
77 
78 $suffix = GETPOST("suffix", 'aZ09');
79 $source = GETPOST("source", 'alpha');
80 $ref = $REF = GETPOST("ref", 'alpha');
81 $urlok = '';
82 $urlko = '';
83 
84 
85 if (empty($source)) {
86  $source = 'proposal';
87 }
88 if (!empty($refusepropal)) {
89  $action = "refusepropal";
90 }
91 
92 // Define $urlwithroot
93 //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
94 //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
95 $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
96 
97 
98 // Complete urls for post treatment
99 $SECUREKEY = GETPOST("securekey"); // Secure key
100 
101 if (!empty($source)) {
102  $urlok .= 'source='.urlencode($source).'&';
103  $urlko .= 'source='.urlencode($source).'&';
104 }
105 if (!empty($REF)) {
106  $urlok .= 'ref='.urlencode($REF).'&';
107  $urlko .= 'ref='.urlencode($REF).'&';
108 }
109 if (!empty($SECUREKEY)) {
110  $urlok .= 'securekey='.urlencode($SECUREKEY).'&';
111  $urlko .= 'securekey='.urlencode($SECUREKEY).'&';
112 }
113 if (!empty($entity)) {
114  $urlok .= 'entity='.urlencode($entity).'&';
115  $urlko .= 'entity='.urlencode($entity).'&';
116 }
117 $urlok = preg_replace('/&$/', '', $urlok); // Remove last &
118 $urlko = preg_replace('/&$/', '', $urlko); // Remove last &
119 
120 $creditor = $mysoc->name;
121 
122 $type = $source;
123 
124 if (!$action) {
125  if ($source && !$ref) {
126  httponly_accessforbidden($langs->trans('ErrorBadParameters')." - ref missing", 400, 1);
127  }
128 }
129 
130 // Check securitykey
131 $securekeyseed = '';
132 if ($source == 'proposal') {
133  $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
134 } elseif ($source == 'contract') {
135  $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN');
136 } elseif ($source == 'fichinter') {
137  $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN');
138 }
139 if (!dol_verifyHash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? $entity : ''), $SECUREKEY, '0')) {
140  httponly_accessforbidden('Bad value for securitykey. Value provided '.dol_escape_htmltag($SECUREKEY).' does not match expected value for ref='.dol_escape_htmltag($ref), 403, 1);
141 }
142 
143 if ($source == 'proposal') {
144  require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
145  $object = new Propal($db);
146  $result= $object->fetch(0, $ref, '', $entity);
147 } elseif ($source == 'contract') {
148  require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
149  $object = new Contrat($db);
150  $result= $object->fetch(0, $ref);
151 } elseif ($source == 'fichinter') {
152  require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
153  $object = new Fichinter($db);
154  $result= $object->fetch(0, $ref);
155 } else {
156  httponly_accessforbidden($langs->trans('ErrorBadParameters')." - Bad value for source", 400, 1);
157 }
158 
159 
160 /*
161  * Actions
162  */
163 
164 if ($action == 'confirm_refusepropal' && $confirm == 'yes') {
165  $db->begin();
166 
167  $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
168  $sql .= " SET fk_statut = ".((int) $object::STATUS_NOTSIGNED).", note_private = '".$db->escape($object->note_private)."', date_signature='".$db->idate(dol_now())."'";
169  $sql .= " WHERE rowid = ".((int) $object->id);
170 
171  dol_syslog(__METHOD__, LOG_DEBUG);
172  $resql = $db->query($sql);
173  if (!$resql) {
174  $error++;
175  }
176 
177  if (!$error) {
178  $db->commit();
179 
180  $message = 'refused';
181  setEventMessages("PropalRefused", null, 'warnings');
182  if (method_exists($object, 'call_trigger')) {
183  // Online customer is not a user, so we use the use that validates the documents
184  $user = new User($db);
185  $user->fetch($object->user_valid_id);
186  $object->context = array('closedfromonlinesignature' => 'closedfromonlinesignature');
187  $result = $object->call_trigger('PROPAL_CLOSE_REFUSED', $user);
188  if ($result < 0) {
189  $error++;
190  }
191  }
192  } else {
193  $db->rollback();
194  }
195 
196  $object->fetch(0, $ref);
197 }
198 
199 
200 /*
201  * View
202  */
203 
204 $form = new Form($db);
205 $head = '';
206 if (!empty($conf->global->MAIN_SIGN_CSS_URL)) {
207  $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->MAIN_SIGN_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
208 }
209 
210 $conf->dol_hide_topmenu = 1;
211 $conf->dol_hide_leftmenu = 1;
212 
213 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
214 llxHeader($head, $langs->trans("OnlineSignature"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea, 1);
215 
216 if ($action == 'refusepropal') {
217  print $form->formconfirm($_SERVER["PHP_SELF"].'?ref='.urlencode($ref).'&securekey='.urlencode($SECUREKEY).(isModEnabled('multicompany')?'&entity='.$entity:''), $langs->trans('RefusePropal'), $langs->trans('ConfirmRefusePropal', $object->ref), 'confirm_refusepropal', '', '', 1);
218 }
219 
220 // Check link validity for param 'source' to avoid use of the examples as value
221 if (!empty($source) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', 'proposal_ref', ''))) {
222  $langs->load("errors");
223  dol_print_error_email('BADREFINONLINESIGNFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref));
224  // End of page
225  llxFooter();
226  $db->close();
227  exit;
228 }
229 
230 print '<span id="dolpaymentspan"></span>'."\n";
231 print '<div class="center">'."\n";
232 print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
233 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
234 print '<input type="hidden" name="action" value="dosign">'."\n";
235 print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
236 print '<input type="hidden" name="suffix" value="'.GETPOST("suffix", 'alpha').'">'."\n";
237 print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
238 print '<input type="hidden" name="entity" value="'.$entity.'" />';
239 print '<input type="hidden" name="page_y" value="" />';
240 print "\n";
241 print '<!-- Form to sign -->'."\n";
242 
243 print '<table id="dolpublictable" summary="Payment form" class="center">'."\n";
244 
245 // Show logo (search order: logo defined by ONLINE_SIGN_LOGO_suffix, then ONLINE_SIGN_LOGO_, then small company logo, large company logo, theme logo, common logo)
246 // Define logo and logosmall
247 $logosmall = $mysoc->logo_small;
248 $logo = $mysoc->logo;
249 $paramlogo = 'ONLINE_SIGN_LOGO_'.$suffix;
250 if (!empty($conf->global->$paramlogo)) {
251  $logosmall = $conf->global->$paramlogo;
252 } elseif (!empty($conf->global->ONLINE_SIGN_LOGO)) {
253  $logosmall = $conf->global->ONLINE_SIGN_LOGO;
254 }
255 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
256 // Define urllogo
257 $urllogo = '';
258 $urllogofull = '';
259 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
260  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
261  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
262 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
263  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
264  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
265 }
266 // Output html code for logo
267 if ($urllogo) {
268  print '<div class="backgreypublicpayment">';
269  print '<div class="logopublicpayment">';
270  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
271  print '>';
272  print '</div>';
273  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
274  print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img class="poweredbyimg" src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
275  }
276  print '</div>';
277 }
278 if ($source == 'proposal' && !empty($conf->global->PROPOSAL_IMAGE_PUBLIC_SIGN)) {
279  print '<div class="backimagepublicproposalsign">';
280  print '<img id="idPROPOSAL_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->PROPOSAL_IMAGE_PUBLIC_SIGN.'">';
281  print '</div>';
282 }
283 
284 // Output introduction text
285 $text = '';
286 if (!empty($conf->global->ONLINE_SIGN_NEWFORM_TEXT)) {
287  $reg = array();
288  if (preg_match('/^\‍((.*)\‍)$/', $conf->global->ONLINE_SIGN_NEWFORM_TEXT, $reg)) {
289  $text .= $langs->trans($reg[1])."<br>\n";
290  } else {
291  $text .= $conf->global->ONLINE_SIGN_NEWFORM_TEXT."<br>\n";
292  }
293  $text = '<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
294 }
295 if (empty($text)) {
296  if ($source == 'proposal') {
297  $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageProposal", $mysoc->name).'</strong></td></tr>'."\n";
298  $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromProposal", $creditor).'<br><br></td></tr>'."\n";
299  } elseif ($source == 'contract') {
300  $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageContract", $mysoc->name).'</strong></td></tr>'."\n";
301  $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromContract", $creditor).'<br><br></td></tr>'."\n";
302  } elseif ($source == 'fichinter') {
303  $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageFichinter", $mysoc->name).'</strong></td></tr>'."\n";
304  $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromFichinter", $creditor).'<br><br></td></tr>'."\n";
305  }
306 }
307 print $text;
308 
309 // Output payment summary form
310 print '<tr><td align="center">';
311 print '<table with="100%" id="tablepublicpayment">';
312 if ($source == 'proposal') {
313  print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignProposal").' :</td></tr>'."\n";
314 } elseif ($source == 'contract') {
315  print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignContract").' :</td></tr>'."\n";
316 } elseif ($source == 'fichinter') {
317  print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignFichinter").' :</td></tr>'."\n";
318 }
319 $found = false;
320 $error = 0;
321 
322 // Signature on commercial proposal
323 if ($source == 'proposal') {
324  $found = true;
325  $langs->load("proposal");
326 
327  $result = $object->fetch_thirdparty($object->socid);
328 
329  // Creditor
330  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
331  print '</td><td class="CTableRow2">';
332  print img_picto('', 'company', 'class="pictofixedwidth"');
333  print '<b>'.$creditor.'</b>';
334  print '<input type="hidden" name="creditor" value="'.$creditor.'">';
335  print '</td></tr>'."\n";
336 
337  // Debitor
338  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
339  print '</td><td class="CTableRow2">';
340  print img_picto('', 'company', 'class="pictofixedwidth"');
341  print '<b>'.$object->thirdparty->name.'</b>';
342  print '</td></tr>'."\n";
343 
344  // Amount
345  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
346  print '</td><td class="CTableRow2">';
347  print '<b>'.price($object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).'</b>';
348  print '</td></tr>'."\n";
349 
350  // Object
351  $text = '<b>'.$langs->trans("SignatureProposalRef", $object->ref).'</b>';
352  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
353  print '</td><td class="CTableRow2">'.$text;
354 
355  $last_main_doc_file = $object->last_main_doc;
356 
357  if ($object->status == $object::STATUS_VALIDATED) {
358  if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
359  // It seems document has never been generated, or was generated and then deleted.
360  // So we try to regenerate it with its default template.
361  $defaulttemplate = ''; // We force the use an empty string instead of $object->model_pdf to be sure to use a "main" default template and not the last one used.
362  $object->generateDocument($defaulttemplate, $langs);
363  }
364 
365  $directdownloadlink = $object->getLastMainDocLink('proposal');
366  if ($directdownloadlink) {
367  print '<br><a href="'.$directdownloadlink.'">';
368  print img_mime($object->last_main_doc, '');
369  print $langs->trans("DownloadDocument").'</a>';
370  }
371  } else {
372  if ($object->status == $object::STATUS_NOTSIGNED) {
373  $directdownloadlink = $object->getLastMainDocLink('proposal');
374  if ($directdownloadlink) {
375  print '<br><a href="'.$directdownloadlink.'">';
376  print img_mime($last_main_doc_file, '');
377  print $langs->trans("DownloadDocument").'</a>';
378  }
379  } elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) {
380  if (preg_match('/_signed-(\d+)/', $last_main_doc_file)) { // If the last main doc has been signed
381  $last_main_doc_file_not_signed = preg_replace('/_signed-(\d+)/', '', $last_main_doc_file);
382 
383  $datefilesigned = dol_filemtime($last_main_doc_file);
384  $datefilenotsigned = dol_filemtime($last_main_doc_file_not_signed);
385 
386  if (empty($datefilenotsigned) || $datefilesigned > $datefilenotsigned) {
387  $directdownloadlink = $object->getLastMainDocLink('proposal');
388  if ($directdownloadlink) {
389  print '<br><a href="'.$directdownloadlink.'">';
390  print img_mime($object->last_main_doc, '');
391  print $langs->trans("DownloadDocument").'</a>';
392  }
393  }
394  }
395  }
396  }
397 
398  print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
399  print '<input type="hidden" name="ref" value="'.$object->ref.'">';
400  print '</td></tr>'."\n";
401 } elseif ($source == 'contract') { // Signature on contract
402  $found = true;
403  $langs->load("contract");
404 
405  $result = $object->fetch_thirdparty($object->socid);
406 
407  // Proposer
408  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
409  print '</td><td class="CTableRow2">';
410  print img_picto('', 'company', 'class="pictofixedwidth"');
411  print '<b>'.$creditor.'</b>';
412  print '<input type="hidden" name="creditor" value="'.$creditor.'">';
413  print '</td></tr>'."\n";
414 
415  // Target
416  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
417  print '</td><td class="CTableRow2">';
418  print img_picto('', 'company', 'class="pictofixedwidth"');
419  print '<b>'.$object->thirdparty->name.'</b>';
420  print '</td></tr>'."\n";
421 
422  // Object
423  $text = '<b>'.$langs->trans("SignatureContractRef", $object->ref).'</b>';
424  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
425  print '</td><td class="CTableRow2">'.$text;
426 
427  $last_main_doc_file = $object->last_main_doc;
428 
429  if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
430  // It seems document has never been generated, or was generated and then deleted.
431  // So we try to regenerate it with its default template.
432  $defaulttemplate = ''; // We force the use an empty string instead of $object->model_pdf to be sure to use a "main" default template and not the last one used.
433  $object->generateDocument($defaulttemplate, $langs);
434  }
435 
436  $directdownloadlink = $object->getLastMainDocLink('contract');
437  if ($directdownloadlink) {
438  print '<br><a href="'.$directdownloadlink.'">';
439  print img_mime($object->last_main_doc, '');
440  if ($message == "signed") {
441  print $langs->trans("DownloadSignedDocument").'</a>';
442  } else {
443  print $langs->trans("DownloadDocument").'</a>';
444  }
445  }
446 
447 
448  print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
449  print '<input type="hidden" name="ref" value="'.$object->ref.'">';
450  print '</td></tr>'."\n";
451 } elseif ($source == 'fichinter') { // Signature on fichinter
452  $found = true;
453  $langs->load("fichinter");
454 
455  $result = $object->fetch_thirdparty($object->socid);
456  // Proposer
457  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
458  print '</td><td class="CTableRow2">';
459  print img_picto('', 'company', 'class="pictofixedwidth"');
460  print '<b>'.$creditor.'</b>';
461  print '<input type="hidden" name="creditor" value="'.$creditor.'">';
462  print '</td></tr>'."\n";
463 
464  // Target
465  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
466  print '</td><td class="CTableRow2">';
467  print img_picto('', 'company', 'class="pictofixedwidth"');
468  print '<b>'.$object->thirdparty->name.'</b>';
469  print '</td></tr>'."\n";
470 
471  // Object
472  $text = '<b>'.$langs->trans("SignatureFichinterRef", $object->ref).'</b>';
473  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
474  print '</td><td class="CTableRow2">'.$text;
475 
476  $last_main_doc_file = $object->last_main_doc;
477 
478  if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
479  // It seems document has never been generated, or was generated and then deleted.
480  // So we try to regenerate it with its default template.
481  $defaulttemplate = ''; // We force the use an empty string instead of $object->model_pdf to be sure to use a "main" default template and not the last one used.
482  $object->generateDocument($defaulttemplate, $langs);
483  }
484 
485  $directdownloadlink = $object->getLastMainDocLink('fichinter');
486  if ($directdownloadlink) {
487  print '<br><a href="'.$directdownloadlink.'">';
488  print img_mime($object->last_main_doc, '');
489  if ($message == "signed") {
490  print $langs->trans("DownloadSignedDocument").'</a>';
491  } else {
492  print $langs->trans("DownloadDocument").'</a>';
493  }
494  }
495 
496 
497  print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
498  print '<input type="hidden" name="ref" value="'.$object->ref.'">';
499  print '</td></tr>'."\n";
500 }
501 
502 
503 if (!$found && !$mesg) {
504  $mesg = $langs->transnoentitiesnoconv("ErrorBadParameters");
505 }
506 
507 if ($mesg) {
508  print '<tr><td class="center" colspan="2"><br><div class="warning">'.dol_escape_htmltag($mesg).'</div></td></tr>'."\n";
509 }
510 
511 print '</table>'."\n";
512 print "\n";
513 
514 if ($action != 'dosign') {
515  if ($found && !$error) {
516  // We are in a management option and no error
517  } else {
518  dol_print_error_email('ERRORNEWONLINESIGN');
519  }
520 } else {
521  // Print
522 }
523 
524 print '</td></tr>'."\n";
525 print '<tr><td class="center">';
526 
527 
528 if ($action == "dosign" && empty($cancel)) {
529  print '<div class="tablepublicpayment">';
530  print '<input type="button" class="buttonDelete small" id="clearsignature" value="'.$langs->trans("ClearSignature").'">';
531  print '<div id="signature" style="border:solid;"></div>';
532  print '</div>';
533  // Do not use class="reposition" here: It breaks the submit and there is a message on top to say it's ok, so going back top is better.
534  print '<input type="button" class="button" id="signbutton" value="'.$langs->trans("Sign").'">';
535  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
536 
537  // Add js code managed into the div #signature
538  print '<script language="JavaScript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jSignature/jSignature.js"></script>
539  <script type="text/javascript">
540  $(document).ready(function() {
541  $("#signature").jSignature({ color:"#000", lineWidth:4, '.(empty($conf->dol_optimize_smallscreen) ? '' : 'width: 280, ' ).'height: 180});
542 
543  $("#signature").on("change",function(){
544  $("#clearsignature").css("display","");
545  $("#signbutton").attr("disabled",false);
546  if(!$._data($("#signbutton")[0], "events")){
547  $("#signbutton").on("click",function(){
548  console.log("We click on button sign");
549  $("#signbutton").val(\''.dol_escape_js($langs->transnoentities('PleaseBePatient')).'\');
550  var signature = $("#signature").jSignature("getData", "image");
551  $.ajax({
552  type: "POST",
553  url: "'.DOL_URL_ROOT.'/core/ajax/onlineSign.php",
554  dataType: "text",
555  data: {
556  "action" : "importSignature",
557  "token" : \''.newToken().'\',
558  "signaturebase64" : signature,
559  "ref" : \''.dol_escape_js($REF).'\',
560  "securekey" : \''.dol_escape_js($SECUREKEY).'\',
561  "mode" : \''.dol_escape_htmltag($source).'\',
562  "entity" : \''.dol_escape_htmltag($entity).'\',
563  },
564  success: function(response) {
565  if(response == "success"){
566  console.log("Success on saving signature");
567  window.location.replace("'.$_SERVER["PHP_SELF"].'?ref='.urlencode($ref).'&source='.urlencode($source).'&message=signed&securekey='.urlencode($SECUREKEY).(isModEnabled('multicompany')?'&entity='.$entity:'').'");
568  }else{
569  console.error(response);
570  }
571  },
572  });
573  });
574  }
575  });
576 
577  $("#clearsignature").on("click",function(){
578  $("#signature").jSignature("clear");
579  $("#signbutton").attr("disabled",true);
580  });
581 
582  $("#signbutton").attr("disabled",true);
583  });
584  </script>';
585 } else {
586  if ($source == 'proposal') {
587  if ($object->status == $object::STATUS_SIGNED) {
588  print '<br>';
589  if ($message == 'signed') {
590  print '<span class="ok">'.$langs->trans("PropalSigned").'</span>';
591  } else {
592  print '<span class="ok">'.$langs->trans("PropalAlreadySigned").'</span>';
593  }
594  } elseif ($object->status == $object::STATUS_NOTSIGNED) {
595  print '<br>';
596  if ($message == 'refused') {
597  print '<span class="ok">'.$langs->trans("PropalRefused").'</span>';
598  } else {
599  print '<span class="warning">'.$langs->trans("PropalAlreadyRefused").'</span>';
600  }
601  } else {
602  print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignPropal").'">';
603  print '<input name="refusepropal" type="submit" class="butActionDelete small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("RefusePropal").'">';
604  }
605  } elseif ($source == 'contract') {
606  if ($message == 'signed') {
607  print '<span class="ok">'.$langs->trans("ContractSigned").'</span>';
608  } else {
609  print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignContract").'">';
610  }
611  } elseif ($source == 'fichinter') {
612  if ($message == 'signed') {
613  print '<span class="ok">'.$langs->trans("FichinterSigned").'</span>';
614  } else {
615  print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignFichinter").'">';
616  }
617  }
618 }
619 print '</td></tr>'."\n";
620 print '</table>'."\n";
621 print '</form>'."\n";
622 print '</div>'."\n";
623 print '<br>';
624 
625 
626 htmlPrintOnlinePaymentFooter($mysoc, $langs);
627 
628 llxFooter('', 'public');
629 
630 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage contracts.
Class to manage interventions.
Class to manage generation of HTML components Only common components must be here.
Class to manage proposals.
Class to manage Dolibarr users.
Definition: user.class.php:47
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.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:597
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:481
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_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error_email($prefixcode, $errormessage='', $errormessages=array(), $morecss='error', $email='')
Show a public email and error code to contact if technical error.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
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.