dolibarr  x.y.z
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  $result = $object->call_trigger('PROPAL_CLOSE_REFUSED_WEB', $user);
192  if ($result < 0) {
193  $error++;
194  }
195  }
196  } else {
197  $db->rollback();
198  }
199 
200  $object->fetch(0, $ref);
201 }
202 
203 
204 /*
205  * View
206  */
207 
208 $form = new Form($db);
209 $head = '';
210 if (!empty($conf->global->MAIN_SIGN_CSS_URL)) {
211  $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->MAIN_SIGN_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
212 }
213 
214 $conf->dol_hide_topmenu = 1;
215 $conf->dol_hide_leftmenu = 1;
216 
217 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
218 llxHeader($head, $langs->trans("OnlineSignature"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea, 1);
219 
220 if ($action == 'refusepropal') {
221  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);
222 }
223 
224 // Check link validity for param 'source' to avoid use of the examples as value
225 if (!empty($source) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', 'proposal_ref', ''))) {
226  $langs->load("errors");
227  dol_print_error_email('BADREFINONLINESIGNFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref));
228  // End of page
229  llxFooter();
230  $db->close();
231  exit;
232 }
233 
234 print '<span id="dolpaymentspan"></span>'."\n";
235 print '<div class="center">'."\n";
236 print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
237 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
238 print '<input type="hidden" name="action" value="dosign">'."\n";
239 print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
240 print '<input type="hidden" name="suffix" value="'.GETPOST("suffix", 'alpha').'">'."\n";
241 print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
242 print '<input type="hidden" name="entity" value="'.$entity.'" />';
243 print '<input type="hidden" name="page_y" value="" />';
244 print "\n";
245 print '<!-- Form to sign -->'."\n";
246 
247 print '<table id="dolpublictable" summary="Payment form" class="center">'."\n";
248 
249 // 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)
250 // Define logo and logosmall
251 $logosmall = $mysoc->logo_small;
252 $logo = $mysoc->logo;
253 $paramlogo = 'ONLINE_SIGN_LOGO_'.$suffix;
254 if (!empty($conf->global->$paramlogo)) {
255  $logosmall = $conf->global->$paramlogo;
256 } elseif (!empty($conf->global->ONLINE_SIGN_LOGO)) {
257  $logosmall = $conf->global->ONLINE_SIGN_LOGO;
258 }
259 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
260 // Define urllogo
261 $urllogo = '';
262 $urllogofull = '';
263 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
264  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
265  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
266 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
267  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
268  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
269 }
270 // Output html code for logo
271 if ($urllogo) {
272  print '<div class="backgreypublicpayment">';
273  print '<div class="logopublicpayment">';
274  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
275  print '>';
276  print '</div>';
277  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
278  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>';
279  }
280  print '</div>';
281 }
282 if ($source == 'proposal' && !empty($conf->global->PROPOSAL_IMAGE_PUBLIC_SIGN)) {
283  print '<div class="backimagepublicproposalsign">';
284  print '<img id="idPROPOSAL_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->PROPOSAL_IMAGE_PUBLIC_SIGN.'">';
285  print '</div>';
286 }
287 
288 // Output introduction text
289 $text = '';
290 if (!empty($conf->global->ONLINE_SIGN_NEWFORM_TEXT)) {
291  $reg = array();
292  if (preg_match('/^\‍((.*)\‍)$/', $conf->global->ONLINE_SIGN_NEWFORM_TEXT, $reg)) {
293  $text .= $langs->trans($reg[1])."<br>\n";
294  } else {
295  $text .= $conf->global->ONLINE_SIGN_NEWFORM_TEXT."<br>\n";
296  }
297  $text = '<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
298 }
299 if (empty($text)) {
300  if ($source == 'proposal') {
301  $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageProposal", $mysoc->name).'</strong></td></tr>'."\n";
302  $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromProposal", $creditor).'<br><br></td></tr>'."\n";
303  } elseif ($source == 'contract') {
304  $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageContract", $mysoc->name).'</strong></td></tr>'."\n";
305  $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromContract", $creditor).'<br><br></td></tr>'."\n";
306  } elseif ($source == 'fichinter') {
307  $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageFichinter", $mysoc->name).'</strong></td></tr>'."\n";
308  $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromFichinter", $creditor).'<br><br></td></tr>'."\n";
309  }
310 }
311 print $text;
312 
313 // Output payment summary form
314 print '<tr><td align="center">';
315 print '<table with="100%" id="tablepublicpayment">';
316 if ($source == 'proposal') {
317  print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignProposal").' :</td></tr>'."\n";
318 } elseif ($source == 'contract') {
319  print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignContract").' :</td></tr>'."\n";
320 } elseif ($source == 'fichinter') {
321  print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignFichinter").' :</td></tr>'."\n";
322 }
323 $found = false;
324 $error = 0;
325 
326 // Signature on commercial proposal
327 if ($source == 'proposal') {
328  $found = true;
329  $langs->load("proposal");
330 
331  $result = $object->fetch_thirdparty($object->socid);
332 
333  // Creditor
334  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
335  print '</td><td class="CTableRow2">';
336  print img_picto('', 'company', 'class="pictofixedwidth"');
337  print '<b>'.$creditor.'</b>';
338  print '<input type="hidden" name="creditor" value="'.$creditor.'">';
339  print '</td></tr>'."\n";
340 
341  // Debitor
342  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
343  print '</td><td class="CTableRow2">';
344  print img_picto('', 'company', 'class="pictofixedwidth"');
345  print '<b>'.$object->thirdparty->name.'</b>';
346  print '</td></tr>'."\n";
347 
348  // Amount
349  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
350  print '</td><td class="CTableRow2">';
351  print '<b>'.price($object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).'</b>';
352  print '</td></tr>'."\n";
353 
354  // Object
355  $text = '<b>'.$langs->trans("SignatureProposalRef", $object->ref).'</b>';
356  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
357  print '</td><td class="CTableRow2">'.$text;
358 
359  $last_main_doc_file = $object->last_main_doc;
360 
361  if ($object->status == $object::STATUS_VALIDATED) {
362  if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
363  // It seems document has never been generated, or was generated and then deleted.
364  // So we try to regenerate it with its default template.
365  $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.
366  $object->generateDocument($defaulttemplate, $langs);
367  }
368 
369  $directdownloadlink = $object->getLastMainDocLink('proposal');
370  if ($directdownloadlink) {
371  print '<br><a href="'.$directdownloadlink.'">';
372  print img_mime($object->last_main_doc, '');
373  print $langs->trans("DownloadDocument").'</a>';
374  }
375  } else {
376  if ($object->status == $object::STATUS_NOTSIGNED) {
377  $directdownloadlink = $object->getLastMainDocLink('proposal');
378  if ($directdownloadlink) {
379  print '<br><a href="'.$directdownloadlink.'">';
380  print img_mime($last_main_doc_file, '');
381  print $langs->trans("DownloadDocument").'</a>';
382  }
383  } elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) {
384  if (preg_match('/_signed-(\d+)/', $last_main_doc_file)) { // If the last main doc has been signed
385  $last_main_doc_file_not_signed = preg_replace('/_signed-(\d+)/', '', $last_main_doc_file);
386 
387  $datefilesigned = dol_filemtime($last_main_doc_file);
388  $datefilenotsigned = dol_filemtime($last_main_doc_file_not_signed);
389 
390  if (empty($datefilenotsigned) || $datefilesigned > $datefilenotsigned) {
391  $directdownloadlink = $object->getLastMainDocLink('proposal');
392  if ($directdownloadlink) {
393  print '<br><a href="'.$directdownloadlink.'">';
394  print img_mime($object->last_main_doc, '');
395  print $langs->trans("DownloadDocument").'</a>';
396  }
397  }
398  }
399  }
400  }
401 
402  print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
403  print '<input type="hidden" name="ref" value="'.$object->ref.'">';
404  print '</td></tr>'."\n";
405 } elseif ($source == 'contract') { // Signature on contract
406  $found = true;
407  $langs->load("contract");
408 
409  $result = $object->fetch_thirdparty($object->socid);
410 
411  // Proposer
412  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
413  print '</td><td class="CTableRow2">';
414  print img_picto('', 'company', 'class="pictofixedwidth"');
415  print '<b>'.$creditor.'</b>';
416  print '<input type="hidden" name="creditor" value="'.$creditor.'">';
417  print '</td></tr>'."\n";
418 
419  // Target
420  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
421  print '</td><td class="CTableRow2">';
422  print img_picto('', 'company', 'class="pictofixedwidth"');
423  print '<b>'.$object->thirdparty->name.'</b>';
424  print '</td></tr>'."\n";
425 
426  // Object
427  $text = '<b>'.$langs->trans("SignatureContractRef", $object->ref).'</b>';
428  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
429  print '</td><td class="CTableRow2">'.$text;
430 
431  $last_main_doc_file = $object->last_main_doc;
432 
433  if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
434  // It seems document has never been generated, or was generated and then deleted.
435  // So we try to regenerate it with its default template.
436  $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.
437  $object->generateDocument($defaulttemplate, $langs);
438  }
439 
440  $directdownloadlink = $object->getLastMainDocLink('contract');
441  if ($directdownloadlink) {
442  print '<br><a href="'.$directdownloadlink.'">';
443  print img_mime($object->last_main_doc, '');
444  if ($message == "signed") {
445  print $langs->trans("DownloadSignedDocument").'</a>';
446  } else {
447  print $langs->trans("DownloadDocument").'</a>';
448  }
449  }
450 
451 
452  print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
453  print '<input type="hidden" name="ref" value="'.$object->ref.'">';
454  print '</td></tr>'."\n";
455 } elseif ($source == 'fichinter') { // Signature on fichinter
456  $found = true;
457  $langs->load("fichinter");
458 
459  $result = $object->fetch_thirdparty($object->socid);
460  // Proposer
461  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
462  print '</td><td class="CTableRow2">';
463  print img_picto('', 'company', 'class="pictofixedwidth"');
464  print '<b>'.$creditor.'</b>';
465  print '<input type="hidden" name="creditor" value="'.$creditor.'">';
466  print '</td></tr>'."\n";
467 
468  // Target
469  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
470  print '</td><td class="CTableRow2">';
471  print img_picto('', 'company', 'class="pictofixedwidth"');
472  print '<b>'.$object->thirdparty->name.'</b>';
473  print '</td></tr>'."\n";
474 
475  // Object
476  $text = '<b>'.$langs->trans("SignatureFichinterRef", $object->ref).'</b>';
477  print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
478  print '</td><td class="CTableRow2">'.$text;
479 
480  $last_main_doc_file = $object->last_main_doc;
481 
482  if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
483  // It seems document has never been generated, or was generated and then deleted.
484  // So we try to regenerate it with its default template.
485  $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.
486  $object->generateDocument($defaulttemplate, $langs);
487  }
488 
489  $directdownloadlink = $object->getLastMainDocLink('fichinter');
490  if ($directdownloadlink) {
491  print '<br><a href="'.$directdownloadlink.'">';
492  print img_mime($object->last_main_doc, '');
493  if ($message == "signed") {
494  print $langs->trans("DownloadSignedDocument").'</a>';
495  } else {
496  print $langs->trans("DownloadDocument").'</a>';
497  }
498  }
499 
500 
501  print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
502  print '<input type="hidden" name="ref" value="'.$object->ref.'">';
503  print '</td></tr>'."\n";
504 }
505 
506 
507 if (!$found && !$mesg) {
508  $mesg = $langs->transnoentitiesnoconv("ErrorBadParameters");
509 }
510 
511 if ($mesg) {
512  print '<tr><td class="center" colspan="2"><br><div class="warning">'.dol_escape_htmltag($mesg).'</div></td></tr>'."\n";
513 }
514 
515 print '</table>'."\n";
516 print "\n";
517 
518 if ($action != 'dosign') {
519  if ($found && !$error) {
520  // We are in a management option and no error
521  } else {
522  dol_print_error_email('ERRORNEWONLINESIGN');
523  }
524 } else {
525  // Print
526 }
527 
528 print '</td></tr>'."\n";
529 print '<tr><td class="center">';
530 
531 
532 if ($action == "dosign" && empty($cancel)) {
533  print '<div class="tablepublicpayment">';
534  print '<input type="button" class="buttonDelete small" id="clearsignature" value="'.$langs->trans("ClearSignature").'">';
535  print '<div id="signature" style="border:solid;"></div>';
536  print '</div>';
537  // 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.
538  print '<input type="button" class="button" id="signbutton" value="'.$langs->trans("Sign").'">';
539  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
540 
541  // Add js code managed into the div #signature
542  print '<script language="JavaScript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jSignature/jSignature.js"></script>
543  <script type="text/javascript">
544  $(document).ready(function() {
545  $("#signature").jSignature({ color:"#000", lineWidth:4, '.(empty($conf->dol_optimize_smallscreen) ? '' : 'width: 280, ' ).'height: 180});
546 
547  $("#signature").on("change",function(){
548  $("#clearsignature").css("display","");
549  $("#signbutton").attr("disabled",false);
550  if(!$._data($("#signbutton")[0], "events")){
551  $("#signbutton").on("click",function(){
552  var signature = $("#signature").jSignature("getData", "image");
553  $.ajax({
554  type: "POST",
555  url: "'.DOL_URL_ROOT.'/core/ajax/onlineSign.php",
556  dataType: "text",
557  data: {
558  "action" : "importSignature",
559  "token" : \''.newToken().'\',
560  "signaturebase64" : signature,
561  "ref" : \''.dol_escape_js($REF).'\',
562  "securekey" : \''.dol_escape_js($SECUREKEY).'\',
563  "mode" : \''.dol_escape_htmltag($source).'\',
564  "entity" : \''.dol_escape_htmltag($entity).'\',
565  },
566  success: function(response) {
567  if(response == "success"){
568  console.log("Success on saving signature");
569  window.location.replace("'.$_SERVER["PHP_SELF"].'?ref='.urlencode($ref).'&source='.urlencode($source).'&message=signed&securekey='.urlencode($SECUREKEY).(isModEnabled('multicompany')?'&entity='.$entity:'').'");
570  }else{
571  console.error(response);
572  }
573  },
574  });
575  });
576  }
577  });
578 
579  $("#clearsignature").on("click",function(){
580  $("#signature").jSignature("clear");
581  $("#signbutton").attr("disabled",true);
582  });
583 
584  $("#signbutton").attr("disabled",true);
585  });
586  </script>';
587 } else {
588  if ($source == 'proposal') {
589  if ($object->status == $object::STATUS_SIGNED) {
590  print '<br>';
591  if ($message == 'signed') {
592  print '<span class="ok">'.$langs->trans("PropalSigned").'</span>';
593  } else {
594  print '<span class="ok">'.$langs->trans("PropalAlreadySigned").'</span>';
595  }
596  } elseif ($object->status == $object::STATUS_NOTSIGNED) {
597  print '<br>';
598  if ($message == 'refused') {
599  print '<span class="ok">'.$langs->trans("PropalRefused").'</span>';
600  } else {
601  print '<span class="warning">'.$langs->trans("PropalAlreadyRefused").'</span>';
602  }
603  } else {
604  print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignPropal").'">';
605  print '<input name="refusepropal" type="submit" class="butActionDelete small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("RefusePropal").'">';
606  }
607  } elseif ($source == 'contract') {
608  if ($message == 'signed') {
609  print '<span class="ok">'.$langs->trans("ContractSigned").'</span>';
610  } else {
611  print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignContract").'">';
612  }
613  } elseif ($source == 'fichinter') {
614  if ($message == 'signed') {
615  print '<span class="ok">'.$langs->trans("FichinterSigned").'</span>';
616  } else {
617  print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignFichinter").'">';
618  }
619  }
620 }
621 print '</td></tr>'."\n";
622 print '</table>'."\n";
623 print '</form>'."\n";
624 print '</div>'."\n";
625 print '<br>';
626 
627 
628 htmlPrintOnlinePaymentFooter($mysoc, $langs);
629 
630 llxFooter('', 'public');
631 
632 $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:45
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:596
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:480
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)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.