dolibarr 19.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 * Copyright (C) 2023 anthony Berton <anthony.berton@bb2a.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28if (!defined('NOLOGIN')) {
29 define("NOLOGIN", 1); // This means this output page does not require to be logged.
30}
31if (!defined('NOCSRFCHECK')) {
32 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
33}
34if (!defined('NOIPCHECK')) {
35 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
36}
37if (!defined('NOBROWSERNOTIF')) {
38 define('NOBROWSERNOTIF', '1');
39}
40
41// For MultiCompany module.
42// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
43// Because 2 entities can have the same ref.
44$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
45if (is_numeric($entity)) {
46 define("DOLENTITY", $entity);
47}
48
49// Load Dolibarr environment
50require '../../main.inc.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
56
57// Load translation files
58$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "propal", "commercial"));
59
60// Security check
61// No check on module enabled. Done later according to $validpaymentmethod
62
63// Get parameters
64$action = GETPOST('action', 'aZ09');
65$cancel = GETPOST('cancel', 'alpha');
66$confirm = GETPOST('confirm', 'alpha');
67
68
69$refusepropal = GETPOST('refusepropal', 'alpha');
70$message = GETPOST('message', 'aZ09');
71
72// Input are:
73// type ('invoice','order','contractline'),
74// id (object id),
75// amount (required if id is empty),
76// tag (a free text, required if type is empty)
77// currency (iso code)
78
79$suffix = GETPOST("suffix", 'aZ09');
80$source = GETPOST("source", 'alpha');
81$ref = $REF = GETPOST("ref", 'alpha');
82$urlok = '';
83$urlko = '';
84
85
86if (empty($source)) {
87 $source = 'proposal';
88}
89if (!empty($refusepropal)) {
90 $action = "refusepropal";
91}
92
93// Define $urlwithroot
94//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
95//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
96$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
97
98
99// Complete urls for post treatment
100$SECUREKEY = GETPOST("securekey"); // Secure key
101
102if (!empty($source)) {
103 $urlok .= 'source='.urlencode($source).'&';
104 $urlko .= 'source='.urlencode($source).'&';
105}
106if (!empty($REF)) {
107 $urlok .= 'ref='.urlencode($REF).'&';
108 $urlko .= 'ref='.urlencode($REF).'&';
109}
110if (!empty($SECUREKEY)) {
111 $urlok .= 'securekey='.urlencode($SECUREKEY).'&';
112 $urlko .= 'securekey='.urlencode($SECUREKEY).'&';
113}
114if (!empty($entity)) {
115 $urlok .= 'entity='.urlencode($entity).'&';
116 $urlko .= 'entity='.urlencode($entity).'&';
117}
118$urlok = preg_replace('/&$/', '', $urlok); // Remove last &
119$urlko = preg_replace('/&$/', '', $urlko); // Remove last &
120
121$creditor = $mysoc->name;
122
123$type = $source;
124
125if (!$action) {
126 if ($source && !$ref) {
127 httponly_accessforbidden($langs->trans('ErrorBadParameters')." - ref missing", 400, 1);
128 }
129}
130
131// Check securitykey
132$securekeyseed = '';
133if ($source == 'proposal') {
134 $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
135} elseif ($source == 'contract') {
136 $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN');
137} elseif ($source == 'fichinter') {
138 $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN');
139} elseif ($source == 'societe_rib') {
140 $securekeyseed = getDolGlobalString('SOCIETE_RIB_ONLINE_SIGNATURE_SECURITY_TOKEN');
141}
142if (!dol_verifyHash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? $entity : ''), $SECUREKEY, '0')) {
143 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);
144}
145
146if ($source == 'proposal') {
147 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
148 $object = new Propal($db);
149 $result= $object->fetch(0, $ref, '', $entity);
150} elseif ($source == 'contract') {
151 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
152 $object = new Contrat($db);
153 $result= $object->fetch(0, $ref);
154} elseif ($source == 'fichinter') {
155 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
156 $object = new Fichinter($db);
157 $result= $object->fetch(0, $ref);
158} elseif ($source == 'societe_rib') {
159 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
160 $object = new CompanyBankAccount($db);
161 $result= $object->fetch($ref);
162} else {
163 httponly_accessforbidden($langs->trans('ErrorBadParameters')." - Bad value for source. Value not supported.", 400, 1);
164}
165
166// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
167$hookmanager->initHooks(array('onlinesign'));
168
169$error = 0;
170
171
172/*
173 * Actions
174 */
175
176if ($action == 'confirm_refusepropal' && $confirm == 'yes') {
177 $db->begin();
178
179 $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
180 $sql .= " SET fk_statut = ".((int) $object::STATUS_NOTSIGNED).", note_private = '".$db->escape($object->note_private)."', date_signature='".$db->idate(dol_now())."'";
181 $sql .= " WHERE rowid = ".((int) $object->id);
182
183 dol_syslog(__FILE__, LOG_DEBUG);
184 $resql = $db->query($sql);
185 if (!$resql) {
186 $error++;
187 }
188
189 if (!$error) {
190 $db->commit();
191
192 $message = 'refused';
193 setEventMessages("PropalRefused", null, 'warnings');
194 if (method_exists($object, 'call_trigger')) {
195 // Online customer is not a user, so we use the use that validates the documents
196 $user = new User($db);
197 $user->fetch($object->user_validation_id);
198 $object->context = array('closedfromonlinesignature' => 'closedfromonlinesignature');
199 $result = $object->call_trigger('PROPAL_CLOSE_REFUSED', $user);
200 if ($result < 0) {
201 $error++;
202 }
203 }
204 } else {
205 $db->rollback();
206 }
207
208 $object->fetch(0, $ref);
209}
210
211
212/*
213 * View
214 */
215
216$form = new Form($db);
217$head = '';
218if (getDolGlobalString('MAIN_SIGN_CSS_URL')) {
219 $head = '<link rel="stylesheet" type="text/css" href="' . getDolGlobalString('MAIN_SIGN_CSS_URL').'?lang='.$langs->defaultlang.'">'."\n";
220}
221
222$conf->dol_hide_topmenu = 1;
223$conf->dol_hide_leftmenu = 1;
224
225$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
226llxHeader($head, $langs->trans("OnlineSignature"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea, 1);
227
228if ($action == 'refusepropal') {
229 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);
230}
231
232// Check link validity for param 'source' to avoid use of the examples as value
233if (!empty($source) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', 'proposal_ref', ''))) {
234 $langs->load("errors");
235 dol_print_error_email('BADREFINONLINESIGNFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref));
236 // End of page
237 llxFooter();
238 $db->close();
239 exit;
240}
241
242print '<span id="dolpaymentspan"></span>'."\n";
243print '<div class="center">'."\n";
244print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
245print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
246print '<input type="hidden" name="action" value="dosign">'."\n";
247print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
248print '<input type="hidden" name="suffix" value="'.GETPOST("suffix", 'alpha').'">'."\n";
249print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
250print '<input type="hidden" name="entity" value="'.$entity.'" />';
251print '<input type="hidden" name="page_y" value="" />';
252print '<input type="hidden" name="source" value="'.$source.'" />';
253print '<input type="hidden" name="ref" value="'.$ref.'" />';
254print "\n";
255print '<!-- Form to sign -->'."\n";
256
257print '<table id="dolpublictable" summary="Payment form" class="center">'."\n";
258
259// 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)
260// Define logo and logosmall
261$logosmall = $mysoc->logo_small;
262$logo = $mysoc->logo;
263$paramlogo = 'ONLINE_SIGN_LOGO_'.$suffix;
264if (!empty($conf->global->$paramlogo)) {
265 $logosmall = $conf->global->$paramlogo;
266} elseif (getDolGlobalString('ONLINE_SIGN_LOGO')) {
267 $logosmall = $conf->global->ONLINE_SIGN_LOGO;
268}
269//print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
270// Define urllogo
271$urllogo = '';
272$urllogofull = '';
273if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
274 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
275 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
276} elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
277 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
278 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
279}
280// Output html code for logo
281if ($urllogo) {
282 print '<div class="backgreypublicpayment">';
283 print '<div class="logopublicpayment">';
284 print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
285 print '>';
286 print '</div>';
287 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
288 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>';
289 }
290 print '</div>';
291}
292if ($source == 'proposal' && getDolGlobalString('PROPOSAL_IMAGE_PUBLIC_SIGN')) {
293 print '<div class="backimagepublicproposalsign">';
294 print '<img id="idPROPOSAL_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('PROPOSAL_IMAGE_PUBLIC_SIGN').'">';
295 print '</div>';
296}
297
298// Output introduction text
299$text = '';
300if (getDolGlobalString('ONLINE_SIGN_NEWFORM_TEXT')) {
301 $reg = array();
302 if (preg_match('/^\‍((.*)\‍)$/', $conf->global->ONLINE_SIGN_NEWFORM_TEXT, $reg)) {
303 $text .= $langs->trans($reg[1])."<br>\n";
304 } else {
305 $text .= getDolGlobalString('ONLINE_SIGN_NEWFORM_TEXT') . "<br>\n";
306 }
307 $text = '<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
308}
309if (empty($text)) {
310 if ($source == 'proposal') {
311 $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageProposal", $mysoc->name).'</strong></td></tr>'."\n";
312 $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromProposal", $creditor).'<br><br></td></tr>'."\n";
313 } elseif ($source == 'contract') {
314 $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageContract", $mysoc->name).'</strong></td></tr>'."\n";
315 $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromContract", $creditor).'<br><br></td></tr>'."\n";
316 } elseif ($source == 'fichinter') {
317 $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageFichinter", $mysoc->name).'</strong></td></tr>'."\n";
318 $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromFichinter", $creditor).'<br><br></td></tr>'."\n";
319 } else {
320 $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePage".dol_ucfirst($source), $mysoc->name).'</strong></td></tr>'."\n";
321 $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFrom".dol_ucfirst($source), $creditor).'<br><br></td></tr>'."\n";
322 }
323}
324print $text;
325
326// Output payment summary form
327print '<tr><td align="center">';
328print '<table with="100%" id="tablepublicpayment">';
329if ($source == 'proposal') {
330 print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignProposal").' :</td></tr>'."\n";
331} elseif ($source == 'contract') {
332 print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignContract").' :</td></tr>'."\n";
333} elseif ($source == 'fichinter') {
334 print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignFichinter").' :</td></tr>'."\n";
335} else {
336 print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSign".dol_ucfirst($source)).' :</td></tr>'."\n";
337}
338$found = false;
339$error = 0;
340
341// Signature on commercial proposal
342if ($source == 'proposal') {
343 $found = true;
344 $langs->load("proposal");
345
346 $result = $object->fetch_thirdparty($object->socid);
347
348 // Creditor
349 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
350 print '</td><td class="CTableRow2">';
351 print img_picto('', 'company', 'class="pictofixedwidth"');
352 print '<b>'.$creditor.'</b>';
353 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
354 print '</td></tr>'."\n";
355
356 // Debitor
357 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
358 print '</td><td class="CTableRow2">';
359 print img_picto('', 'company', 'class="pictofixedwidth"');
360 print '<b>'.$object->thirdparty->name.'</b>';
361 print '</td></tr>'."\n";
362
363 // Amount
364
365 $amount = '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
366 $amount .= '</td><td class="CTableRow2">';
367 $amount .= '<b>'.price($object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).'</b>';
368 if ($object->multicurrency_code != $conf->currency) {
369 $amount .= ' ('.price($object->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $object->multicurrency_code).')';
370 }
371 $amount .= '</td></tr>'."\n";
372
373 // Call Hook amountPropalSign
374 $parameters = array('source' => $source);
375 $reshook = $hookmanager->executeHooks('amountPropalSign', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
376 if (empty($reshook)) {
377 $amount .= $hookmanager->resPrint;
378 } elseif ($reshook > 0) {
379 $amount = $hookmanager->resPrint;
380 }
381
382 print $amount;
383
384 // Object
385 $text = '<b>'.$langs->trans("SignatureProposalRef", $object->ref).'</b>';
386 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
387 print '</td><td class="CTableRow2">'.$text;
388
389 $last_main_doc_file = $object->last_main_doc;
390
391 if ($object->status == $object::STATUS_VALIDATED) {
392 if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
393 // It seems document has never been generated, or was generated and then deleted.
394 // So we try to regenerate it with its default template.
395 $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.
396 $object->generateDocument($defaulttemplate, $langs);
397 }
398
399 $directdownloadlink = $object->getLastMainDocLink('proposal');
400 if ($directdownloadlink) {
401 print '<br><a href="'.$directdownloadlink.'">';
402 print img_mime($object->last_main_doc, '');
403 print $langs->trans("DownloadDocument").'</a>';
404 }
405 } else {
406 if ($object->status == $object::STATUS_NOTSIGNED) {
407 $directdownloadlink = $object->getLastMainDocLink('proposal');
408 if ($directdownloadlink) {
409 print '<br><a href="'.$directdownloadlink.'">';
410 print img_mime($last_main_doc_file, '');
411 print $langs->trans("DownloadDocument").'</a>';
412 }
413 } elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) {
414 if (preg_match('/_signed-(\d+)/', $last_main_doc_file)) { // If the last main doc has been signed
415 $last_main_doc_file_not_signed = preg_replace('/_signed-(\d+)/', '', $last_main_doc_file);
416
417 $datefilesigned = dol_filemtime($last_main_doc_file);
418 $datefilenotsigned = dol_filemtime($last_main_doc_file_not_signed);
419
420 if (empty($datefilenotsigned) || $datefilesigned > $datefilenotsigned) {
421 $directdownloadlink = $object->getLastMainDocLink('proposal');
422 if ($directdownloadlink) {
423 print '<br><a href="'.$directdownloadlink.'">';
424 print img_mime($object->last_main_doc, '');
425 print $langs->trans("DownloadDocument").'</a>';
426 }
427 }
428 }
429 }
430 }
431
432 print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
433 print '<input type="hidden" name="ref" value="'.$object->ref.'">';
434 print '</td></tr>'."\n";
435} elseif ($source == 'contract') { // Signature on contract
436 $found = true;
437 $langs->load("contract");
438
439 $result = $object->fetch_thirdparty($object->socid);
440
441 // Proposer
442 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
443 print '</td><td class="CTableRow2">';
444 print img_picto('', 'company', 'class="pictofixedwidth"');
445 print '<b>'.$creditor.'</b>';
446 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
447 print '</td></tr>'."\n";
448
449 // Target
450 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
451 print '</td><td class="CTableRow2">';
452 print img_picto('', 'company', 'class="pictofixedwidth"');
453 print '<b>'.$object->thirdparty->name.'</b>';
454 print '</td></tr>'."\n";
455
456 // Object
457 $text = '<b>'.$langs->trans("SignatureContractRef", $object->ref).'</b>';
458 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
459 print '</td><td class="CTableRow2">'.$text;
460
461 $last_main_doc_file = $object->last_main_doc;
462
463 if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
464 // It seems document has never been generated, or was generated and then deleted.
465 // So we try to regenerate it with its default template.
466 $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.
467 $object->generateDocument($defaulttemplate, $langs);
468 }
469
470 $directdownloadlink = $object->getLastMainDocLink('contract');
471 if ($directdownloadlink) {
472 print '<br><a href="'.$directdownloadlink.'">';
473 print img_mime($object->last_main_doc, '');
474 if ($message == "signed") {
475 print $langs->trans("DownloadSignedDocument").'</a>';
476 } else {
477 print $langs->trans("DownloadDocument").'</a>';
478 }
479 }
480
481
482 print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
483 print '<input type="hidden" name="ref" value="'.$object->ref.'">';
484 print '</td></tr>'."\n";
485} elseif ($source == 'fichinter') {
486 // Signature on fichinter
487 $found = true;
488 $langs->load("fichinter");
489
490 $result = $object->fetch_thirdparty($object->socid);
491
492 // Proposer
493 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
494 print '</td><td class="CTableRow2">';
495 print img_picto('', 'company', 'class="pictofixedwidth"');
496 print '<b>'.$creditor.'</b>';
497 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
498 print '</td></tr>'."\n";
499
500 // Target
501 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
502 print '</td><td class="CTableRow2">';
503 print img_picto('', 'company', 'class="pictofixedwidth"');
504 print '<b>'.$object->thirdparty->name.'</b>';
505 print '</td></tr>'."\n";
506
507 // Object
508 $text = '<b>'.$langs->trans("SignatureFichinterRef", $object->ref).'</b>';
509 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
510 print '</td><td class="CTableRow2">'.$text;
511
512 $last_main_doc_file = $object->last_main_doc;
513
514 if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
515 // It seems document has never been generated, or was generated and then deleted.
516 // So we try to regenerate it with its default template.
517 $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.
518 $object->generateDocument($defaulttemplate, $langs);
519 }
520
521 $directdownloadlink = $object->getLastMainDocLink('fichinter');
522 if ($directdownloadlink) {
523 print '<br><a href="'.$directdownloadlink.'">';
524 print img_mime($object->last_main_doc, '');
525 if ($message == "signed") {
526 print $langs->trans("DownloadSignedDocument").'</a>';
527 } else {
528 print $langs->trans("DownloadDocument").'</a>';
529 }
530 }
531 print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
532 print '<input type="hidden" name="ref" value="'.$object->ref.'">';
533 print '</td></tr>'."\n";
534} elseif ($source == 'societe_rib') {
535 $found = true;
536 $langs->loadLangs(array("companies", "commercial", "withdrawals"));
537
538 $result = $object->fetch_thirdparty();
539
540 // Proposer
541 print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs->trans("Proposer");
542 print '</td><td class="CTableRow2">';
543 print img_picto('', 'company', 'class="pictofixedwidth"');
544 print '<b>' . $creditor . '</b>';
545 print '<input type="hidden" name="creditor" value="' . $creditor . '">';
546 print '</td></tr>' . "\n";
547
548 // Target
549 print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs->trans("ThirdParty");
550 print '</td><td class="CTableRow2">';
551 print img_picto('', 'company', 'class="pictofixedwidth"');
552 print '<b>' . $object->thirdparty->name . '</b>';
553 print '</td></tr>' . "\n";
554
555 // Object
556 $text = '<b>' . $langs->trans("Signature" . dol_ucfirst($source) . "Ref", $object->ref) . '</b>';
557 print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs->trans("Designation");
558 print '</td><td class="CTableRow2">' . $text;
559
560 $last_main_doc_file = $object->last_main_doc;
561 $diroutput = $conf->societe->multidir_output[$object->thirdparty->entity].'/'
562 .dol_sanitizeFileName($object->thirdparty->id).'/';
563 if ((empty($last_main_doc_file) ||
564 !dol_is_file($diroutput
565 .$langs->transnoentitiesnoconv("SepaMandateShort").' '.$object->id."-".dol_sanitizeFileName($object->rum).".pdf"))
566 && $message != "signed") {
567 // It seems document has never been generated, or was generated and then deleted.
568 // So we try to regenerate it with its default template.
569 //$defaulttemplate = 'sepamandate';
570 $defaulttemplate = getDolGlobalString("BANKADDON_PDF");
571
572 $object->setDocModel($user, $defaulttemplate);
573 $moreparams = array(
574 'use_companybankid'=>$object->id,
575 'force_dir_output'=>$diroutput
576 );
577 $result = $object->thirdparty->generateDocument($defaulttemplate, $langs, 0, 0, 0, $moreparams);
578 $object->last_main_doc=$object->thirdparty->last_main_doc;
579 }
580 $directdownloadlink = $object->getLastMainDocLink('company');
581 if ($directdownloadlink) {
582 print '<br><a href="'.$directdownloadlink.'">';
583 print img_mime($object->last_main_doc, '');
584 if ($message == "signed") {
585 print $langs->trans("DownloadSignedDocument").'</a>';
586 } else {
587 print $langs->trans("DownloadDocument").'</a>';
588 }
589 }
590} else {
591 $found = true;
592 $langs->load('companies');
593
594 if (!empty($object->socid) || !empty($object->fk_soc)) {
595 $result = $object->fetch_thirdparty();
596 }
597
598 // Proposer
599 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
600 print '</td><td class="CTableRow2">';
601 print img_picto('', 'company', 'class="pictofixedwidth"');
602 print '<b>'.$creditor.'</b>';
603 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
604 print '</td></tr>'."\n";
605
606 // Target
607 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
608 print '</td><td class="CTableRow2">';
609 print img_picto('', 'company', 'class="pictofixedwidth"');
610 print '<b>'.$object->thirdparty->name.'</b>';
611 print '</td></tr>'."\n";
612
613 // Object
614 $text = '<b>'.$langs->trans("Signature".dol_ucfirst($source)."Ref", $object->ref).'</b>';
615 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
616 print '</td><td class="CTableRow2">'.$text;
617
618 $last_main_doc_file = $object->last_main_doc;
619
620 if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
621 // It seems document has never been generated, or was generated and then deleted.
622 // So we try to regenerate it with its default template.
623 $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.
624 $object->generateDocument($defaulttemplate, $langs);
625 }
626
627 $directdownloadlink = $object->getLastMainDocLink($source);
628 if ($directdownloadlink) {
629 print '<br><a href="'.$directdownloadlink.'">';
630 print img_mime($object->last_main_doc, '');
631 if ($message == "signed") {
632 print $langs->trans("DownloadSignedDocument").'</a>';
633 } else {
634 print $langs->trans("DownloadDocument").'</a>';
635 }
636 }
637}
638
639// Call Hook addFormSign
640$parameters = array('source' => $source);
641$reshook = $hookmanager->executeHooks('addFormSign', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
642
643if (!$found && !$mesg) {
644 $mesg = $langs->transnoentitiesnoconv("ErrorBadParameters");
645}
646
647if ($mesg) {
648 print '<tr><td class="center" colspan="2"><br><div class="warning">'.dol_escape_htmltag($mesg).'</div></td></tr>'."\n";
649}
650
651print '</table>'."\n";
652print "\n";
653
654if ($action != 'dosign') {
655 if ($found && !$error) {
656 // We are in a management option and no error
657 } else {
658 dol_print_error_email('ERRORNEWONLINESIGN');
659 }
660} else {
661 // Print
662}
663
664print '</td></tr>'."\n";
665print '<tr><td class="center">';
666
667
668if ($action == "dosign" && empty($cancel)) {
669 print '<div class="tablepublicpayment">';
670 print '<input type="text" class="paddingleftonly marginleftonly paddingrightonly marginrightonly marginbottomonly" id="name" placeholder="'.$langs->trans("Lastname").'" autofocus>';
671 print '<div id="signature" style="border:solid;"></div>';
672 print '</div>';
673 print '<input type="button" class="small noborderbottom cursorpointer buttonreset" id="clearsignature" value="'.$langs->trans("ClearSignature").'">';
674
675 // 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.
676 print '<div>';
677 print '<input type="button" class="button marginleftonly marginrightonly" id="signbutton" value="'.$langs->trans("Sign").'">';
678 print '<input type="submit" class="button butActionDelete marginleftonly marginrightonly" name="cancel" value="'.$langs->trans("Cancel").'">';
679 print '</div>';
680
681 // Add js code managed into the div #signature
682 print '<script language="JavaScript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jSignature/jSignature.js"></script>
683 <script type="text/javascript">
684 $(document).ready(function() {
685 $("#signature").jSignature({ color:"#000", lineWidth:0, '.(empty($conf->dol_optimize_smallscreen) ? '' : 'width: 280, ').'height: 180});
686
687 $("#signature").on("change",function(){
688 $("#clearsignature").css("display","");
689 $("#signbutton").attr("disabled",false);
690 if(!$._data($("#signbutton")[0], "events")){
691 $("#signbutton").on("click",function(){
692 console.log("We click on button sign");
693 document.body.style.cursor = \'wait\';
694 /* $("#signbutton").val(\''.dol_escape_js($langs->transnoentities('PleaseBePatient')).'\'); */
695 var signature = $("#signature").jSignature("getData", "image");
696 var name = document.getElementById("name").value;
697 $.ajax({
698 type: "POST",
699 url: "'.DOL_URL_ROOT.'/core/ajax/onlineSign.php",
700 dataType: "text",
701 data: {
702 "action" : "importSignature",
703 "token" : \''.newToken().'\',
704 "signaturebase64" : signature,
705 "onlinesignname" : name,
706 "ref" : \''.dol_escape_js($REF).'\',
707 "securekey" : \''.dol_escape_js($SECUREKEY).'\',
708 "mode" : \''.dol_escape_htmltag($source).'\',
709 "entity" : \''.dol_escape_htmltag($entity).'\',
710 },
711 success: function(response) {
712 if(response == "success"){
713 console.log("Success on saving signature");
714 window.location.replace("'.$_SERVER["PHP_SELF"].'?ref='.urlencode($ref).'&source='.urlencode($source).'&message=signed&securekey='.urlencode($SECUREKEY).(isModEnabled('multicompany') ? '&entity='.$entity : '').'");
715 }else{
716 console.error(response);
717 }
718 },
719 });
720 });
721 }
722 });
723
724 $("#clearsignature").on("click",function(){
725 $("#signature").jSignature("clear");
726 $("#signbutton").attr("disabled",true);
727 // document.getElementById("onlinesignname").value = "";
728 });
729
730 $("#signbutton").attr("disabled",true);
731 });
732 </script>';
733} else {
734 if ($source == 'proposal') {
735 if ($object->status == $object::STATUS_SIGNED) {
736 print '<br>';
737 if ($message == 'signed') {
738 print img_picto('', 'check', '', false, 0, 0, '', 'size2x').'<br>';
739 print '<span class="ok">'.$langs->trans("PropalSigned").'</span>';
740 } else {
741 print img_picto('', 'check', '', false, 0, 0, '', 'size2x').'<br>';
742 print '<span class="ok">'.$langs->trans("PropalAlreadySigned").'</span>';
743 }
744 } elseif ($object->status == $object::STATUS_NOTSIGNED) {
745 print '<br>';
746 if ($message == 'refused') {
747 print img_picto('', 'cross', '', false, 0, 0, '', 'size2x').'<br>';
748 print '<span class="ok">'.$langs->trans("PropalRefused").'</span>';
749 } else {
750 print img_picto('', 'cross', '', false, 0, 0, '', 'size2x').'<br>';
751 print '<span class="warning">'.$langs->trans("PropalAlreadyRefused").'</span>';
752 }
753 } else {
754 print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignPropal").'">';
755 print '<input name="refusepropal" type="submit" class="butActionDelete small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("RefusePropal").'">';
756 }
757 } elseif ($source == 'contract') {
758 if ($message == 'signed') {
759 print '<span class="ok">'.$langs->trans("ContractSigned").'</span>';
760 } else {
761 print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignContract").'">';
762 }
763 } elseif ($source == 'fichinter') {
764 if ($message == 'signed') {
765 print '<span class="ok">'.$langs->trans("FichinterSigned").'</span>';
766 } else {
767 print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignFichinter").'">';
768 }
769 } else {
770 if ($message == 'signed') {
771 print '<span class="ok">'.$langs->trans(dol_ucfirst($source)."Signed").'</span>';
772 } else {
773 print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("Sign".dol_ucfirst($source)).'">';
774 }
775 }
776}
777print '</td></tr>'."\n";
778print '</table>'."\n";
779print '</form>'."\n";
780print '</div>'."\n";
781print '<br>';
782
783
784htmlPrintOnlineFooter($mysoc, $langs);
785
786llxFooter('', 'public');
787
788$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
$object ref
Definition info.php:79
Class to manage bank accounts description of third parties.
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.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML pages.
dol_filemtime($pathoffile)
Return time of a file.
dol_is_file($pathoffile)
Return if path is a file.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error_email($prefixcode, $errormessage='', $errormessages=array(), $morecss='error', $email='')
Show a public email and error code to contact if technical error.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124
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.