newonlinesign.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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. /**
  20. * \file htdocs/public/onlinesign/newonlinesign.php
  21. * \ingroup core
  22. * \brief File to offer a way to make an online signature for a particular Dolibarr entity
  23. * Example of URL: https://localhost/public/onlinesign/newonlinesign.php?ref=PR...
  24. */
  25. if (!defined('NOLOGIN')) {
  26. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  27. }
  28. if (!defined('NOCSRFCHECK')) {
  29. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  30. }
  31. if (!defined('NOIPCHECK')) {
  32. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  33. }
  34. if (!defined('NOBROWSERNOTIF')) {
  35. define('NOBROWSERNOTIF', '1');
  36. }
  37. // For MultiCompany module.
  38. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  39. // Because 2 entities can have the same ref.
  40. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  41. if (is_numeric($entity)) {
  42. define("DOLENTITY", $entity);
  43. }
  44. // Load Dolibarr environment
  45. require '../../main.inc.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  48. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  51. // Load translation files
  52. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "propal", "commercial"));
  53. // Security check
  54. // No check on module enabled. Done later according to $validpaymentmethod
  55. // Get parameters
  56. $action = GETPOST('action', 'aZ09');
  57. $cancel = GETPOST('cancel', 'alpha');
  58. $confirm = GETPOST('confirm', 'alpha');
  59. $refusepropal = GETPOST('refusepropal', 'alpha');
  60. $message = GETPOST('message', 'aZ09');
  61. // Input are:
  62. // type ('invoice','order','contractline'),
  63. // id (object id),
  64. // amount (required if id is empty),
  65. // tag (a free text, required if type is empty)
  66. // currency (iso code)
  67. $suffix = GETPOST("suffix", 'aZ09');
  68. $source = GETPOST("source", 'alpha');
  69. $ref = $REF = GETPOST("ref", 'alpha');
  70. $urlok = '';
  71. $urlko = '';
  72. if (empty($source)) {
  73. $source = 'proposal';
  74. }
  75. if (!empty($refusepropal)) {
  76. $action = "refusepropal";
  77. }
  78. // Define $urlwithroot
  79. //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  80. //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  81. $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
  82. // Complete urls for post treatment
  83. $SECUREKEY = GETPOST("securekey"); // Secure key
  84. if (!empty($source)) {
  85. $urlok .= 'source='.urlencode($source).'&';
  86. $urlko .= 'source='.urlencode($source).'&';
  87. }
  88. if (!empty($REF)) {
  89. $urlok .= 'ref='.urlencode($REF).'&';
  90. $urlko .= 'ref='.urlencode($REF).'&';
  91. }
  92. if (!empty($SECUREKEY)) {
  93. $urlok .= 'securekey='.urlencode($SECUREKEY).'&';
  94. $urlko .= 'securekey='.urlencode($SECUREKEY).'&';
  95. }
  96. if (!empty($entity)) {
  97. $urlok .= 'entity='.urlencode($entity).'&';
  98. $urlko .= 'entity='.urlencode($entity).'&';
  99. }
  100. $urlok = preg_replace('/&$/', '', $urlok); // Remove last &
  101. $urlko = preg_replace('/&$/', '', $urlko); // Remove last &
  102. $creditor = $mysoc->name;
  103. $type = $source;
  104. if (!$action) {
  105. if ($source && !$ref) {
  106. httponly_accessforbidden($langs->trans('ErrorBadParameters')." - ref missing", 400, 1);
  107. }
  108. }
  109. // Check securitykey
  110. $securekeyseed = '';
  111. if ($source == 'proposal') {
  112. $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
  113. } elseif ($source == 'contract') {
  114. $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN');
  115. } elseif ($source == 'fichinter') {
  116. $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN');
  117. }
  118. if (!dol_verifyHash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? $entity : ''), $SECUREKEY, '0')) {
  119. 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);
  120. }
  121. if ($source == 'proposal') {
  122. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  123. $object = new Propal($db);
  124. $result= $object->fetch(0, $ref, '', $entity);
  125. } elseif ($source == 'contract') {
  126. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  127. $object = new Contrat($db);
  128. $result= $object->fetch(0, $ref);
  129. } elseif ($source == 'fichinter') {
  130. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  131. $object = new Fichinter($db);
  132. $result= $object->fetch(0, $ref);
  133. } else {
  134. httponly_accessforbidden($langs->trans('ErrorBadParameters')." - Bad value for source", 400, 1);
  135. }
  136. /*
  137. * Actions
  138. */
  139. if ($action == 'confirm_refusepropal' && $confirm == 'yes') {
  140. $db->begin();
  141. $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
  142. $sql .= " SET fk_statut = ".((int) $object::STATUS_NOTSIGNED).", note_private = '".$db->escape($object->note_private)."', date_signature='".$db->idate(dol_now())."'";
  143. $sql .= " WHERE rowid = ".((int) $object->id);
  144. dol_syslog(__METHOD__, LOG_DEBUG);
  145. $resql = $db->query($sql);
  146. if (!$resql) {
  147. $error++;
  148. }
  149. if (!$error) {
  150. $db->commit();
  151. $message = 'refused';
  152. setEventMessages("PropalRefused", null, 'warnings');
  153. if (method_exists($object, 'call_trigger')) {
  154. // Online customer is not a user, so we use the use that validates the documents
  155. $user = new User($db);
  156. $user->fetch($object->user_valid_id);
  157. $object->context = array('closedfromonlinesignature' => 'closedfromonlinesignature');
  158. $result = $object->call_trigger('PROPAL_CLOSE_REFUSED', $user);
  159. if ($result < 0) {
  160. $error++;
  161. }
  162. }
  163. } else {
  164. $db->rollback();
  165. }
  166. $object->fetch(0, $ref);
  167. }
  168. /*
  169. * View
  170. */
  171. $form = new Form($db);
  172. $head = '';
  173. if (!empty($conf->global->MAIN_SIGN_CSS_URL)) {
  174. $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->MAIN_SIGN_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  175. }
  176. $conf->dol_hide_topmenu = 1;
  177. $conf->dol_hide_leftmenu = 1;
  178. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  179. llxHeader($head, $langs->trans("OnlineSignature"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea, 1);
  180. if ($action == 'refusepropal') {
  181. 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);
  182. }
  183. // Check link validity for param 'source' to avoid use of the examples as value
  184. if (!empty($source) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', 'proposal_ref', ''))) {
  185. $langs->load("errors");
  186. dol_print_error_email('BADREFINONLINESIGNFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref));
  187. // End of page
  188. llxFooter();
  189. $db->close();
  190. exit;
  191. }
  192. print '<span id="dolpaymentspan"></span>'."\n";
  193. print '<div class="center">'."\n";
  194. print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  195. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  196. print '<input type="hidden" name="action" value="dosign">'."\n";
  197. print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
  198. print '<input type="hidden" name="suffix" value="'.GETPOST("suffix", 'alpha').'">'."\n";
  199. print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
  200. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  201. print '<input type="hidden" name="page_y" value="" />';
  202. print "\n";
  203. print '<!-- Form to sign -->'."\n";
  204. print '<table id="dolpublictable" summary="Payment form" class="center">'."\n";
  205. // 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)
  206. // Define logo and logosmall
  207. $logosmall = $mysoc->logo_small;
  208. $logo = $mysoc->logo;
  209. $paramlogo = 'ONLINE_SIGN_LOGO_'.$suffix;
  210. if (!empty($conf->global->$paramlogo)) {
  211. $logosmall = $conf->global->$paramlogo;
  212. } elseif (!empty($conf->global->ONLINE_SIGN_LOGO)) {
  213. $logosmall = $conf->global->ONLINE_SIGN_LOGO;
  214. }
  215. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  216. // Define urllogo
  217. $urllogo = '';
  218. $urllogofull = '';
  219. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  220. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  221. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  222. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  223. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  224. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  225. }
  226. // Output html code for logo
  227. if ($urllogo) {
  228. print '<div class="backgreypublicpayment">';
  229. print '<div class="logopublicpayment">';
  230. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  231. print '>';
  232. print '</div>';
  233. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  234. 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>';
  235. }
  236. print '</div>';
  237. }
  238. if ($source == 'proposal' && !empty($conf->global->PROPOSAL_IMAGE_PUBLIC_SIGN)) {
  239. print '<div class="backimagepublicproposalsign">';
  240. print '<img id="idPROPOSAL_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->PROPOSAL_IMAGE_PUBLIC_SIGN.'">';
  241. print '</div>';
  242. }
  243. // Output introduction text
  244. $text = '';
  245. if (!empty($conf->global->ONLINE_SIGN_NEWFORM_TEXT)) {
  246. $reg = array();
  247. if (preg_match('/^\((.*)\)$/', $conf->global->ONLINE_SIGN_NEWFORM_TEXT, $reg)) {
  248. $text .= $langs->trans($reg[1])."<br>\n";
  249. } else {
  250. $text .= $conf->global->ONLINE_SIGN_NEWFORM_TEXT."<br>\n";
  251. }
  252. $text = '<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
  253. }
  254. if (empty($text)) {
  255. if ($source == 'proposal') {
  256. $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageProposal", $mysoc->name).'</strong></td></tr>'."\n";
  257. $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromProposal", $creditor).'<br><br></td></tr>'."\n";
  258. } elseif ($source == 'contract') {
  259. $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageContract", $mysoc->name).'</strong></td></tr>'."\n";
  260. $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromContract", $creditor).'<br><br></td></tr>'."\n";
  261. } elseif ($source == 'fichinter') {
  262. $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePageFichinter", $mysoc->name).'</strong></td></tr>'."\n";
  263. $text .= '<tr><td class="textpublicpayment opacitymedium">'.$langs->trans("ThisScreenAllowsYouToSignDocFromFichinter", $creditor).'<br><br></td></tr>'."\n";
  264. }
  265. }
  266. print $text;
  267. // Output payment summary form
  268. print '<tr><td align="center">';
  269. print '<table with="100%" id="tablepublicpayment">';
  270. if ($source == 'proposal') {
  271. print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignProposal").' :</td></tr>'."\n";
  272. } elseif ($source == 'contract') {
  273. print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignContract").' :</td></tr>'."\n";
  274. } elseif ($source == 'fichinter') {
  275. print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSignFichinter").' :</td></tr>'."\n";
  276. }
  277. $found = false;
  278. $error = 0;
  279. // Signature on commercial proposal
  280. if ($source == 'proposal') {
  281. $found = true;
  282. $langs->load("proposal");
  283. $result = $object->fetch_thirdparty($object->socid);
  284. // Creditor
  285. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  286. print '</td><td class="CTableRow2">';
  287. print img_picto('', 'company', 'class="pictofixedwidth"');
  288. print '<b>'.$creditor.'</b>';
  289. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  290. print '</td></tr>'."\n";
  291. // Debitor
  292. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  293. print '</td><td class="CTableRow2">';
  294. print img_picto('', 'company', 'class="pictofixedwidth"');
  295. print '<b>'.$object->thirdparty->name.'</b>';
  296. print '</td></tr>'."\n";
  297. // Amount
  298. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
  299. print '</td><td class="CTableRow2">';
  300. print '<b>'.price($object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).'</b>';
  301. print '</td></tr>'."\n";
  302. // Object
  303. $text = '<b>'.$langs->trans("SignatureProposalRef", $object->ref).'</b>';
  304. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  305. print '</td><td class="CTableRow2">'.$text;
  306. $last_main_doc_file = $object->last_main_doc;
  307. if ($object->status == $object::STATUS_VALIDATED) {
  308. if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
  309. // It seems document has never been generated, or was generated and then deleted.
  310. // So we try to regenerate it with its default template.
  311. $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.
  312. $object->generateDocument($defaulttemplate, $langs);
  313. }
  314. $directdownloadlink = $object->getLastMainDocLink('proposal');
  315. if ($directdownloadlink) {
  316. print '<br><a href="'.$directdownloadlink.'">';
  317. print img_mime($object->last_main_doc, '');
  318. print $langs->trans("DownloadDocument").'</a>';
  319. }
  320. } else {
  321. if ($object->status == $object::STATUS_NOTSIGNED) {
  322. $directdownloadlink = $object->getLastMainDocLink('proposal');
  323. if ($directdownloadlink) {
  324. print '<br><a href="'.$directdownloadlink.'">';
  325. print img_mime($last_main_doc_file, '');
  326. print $langs->trans("DownloadDocument").'</a>';
  327. }
  328. } elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) {
  329. if (preg_match('/_signed-(\d+)/', $last_main_doc_file)) { // If the last main doc has been signed
  330. $last_main_doc_file_not_signed = preg_replace('/_signed-(\d+)/', '', $last_main_doc_file);
  331. $datefilesigned = dol_filemtime($last_main_doc_file);
  332. $datefilenotsigned = dol_filemtime($last_main_doc_file_not_signed);
  333. if (empty($datefilenotsigned) || $datefilesigned > $datefilenotsigned) {
  334. $directdownloadlink = $object->getLastMainDocLink('proposal');
  335. if ($directdownloadlink) {
  336. print '<br><a href="'.$directdownloadlink.'">';
  337. print img_mime($object->last_main_doc, '');
  338. print $langs->trans("DownloadDocument").'</a>';
  339. }
  340. }
  341. }
  342. }
  343. }
  344. print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
  345. print '<input type="hidden" name="ref" value="'.$object->ref.'">';
  346. print '</td></tr>'."\n";
  347. } elseif ($source == 'contract') { // Signature on contract
  348. $found = true;
  349. $langs->load("contract");
  350. $result = $object->fetch_thirdparty($object->socid);
  351. // Proposer
  352. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
  353. print '</td><td class="CTableRow2">';
  354. print img_picto('', 'company', 'class="pictofixedwidth"');
  355. print '<b>'.$creditor.'</b>';
  356. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  357. print '</td></tr>'."\n";
  358. // Target
  359. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  360. print '</td><td class="CTableRow2">';
  361. print img_picto('', 'company', 'class="pictofixedwidth"');
  362. print '<b>'.$object->thirdparty->name.'</b>';
  363. print '</td></tr>'."\n";
  364. // Object
  365. $text = '<b>'.$langs->trans("SignatureContractRef", $object->ref).'</b>';
  366. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  367. print '</td><td class="CTableRow2">'.$text;
  368. $last_main_doc_file = $object->last_main_doc;
  369. if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
  370. // It seems document has never been generated, or was generated and then deleted.
  371. // So we try to regenerate it with its default template.
  372. $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.
  373. $object->generateDocument($defaulttemplate, $langs);
  374. }
  375. $directdownloadlink = $object->getLastMainDocLink('contract');
  376. if ($directdownloadlink) {
  377. print '<br><a href="'.$directdownloadlink.'">';
  378. print img_mime($object->last_main_doc, '');
  379. if ($message == "signed") {
  380. print $langs->trans("DownloadSignedDocument").'</a>';
  381. } else {
  382. print $langs->trans("DownloadDocument").'</a>';
  383. }
  384. }
  385. print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
  386. print '<input type="hidden" name="ref" value="'.$object->ref.'">';
  387. print '</td></tr>'."\n";
  388. } elseif ($source == 'fichinter') { // Signature on fichinter
  389. $found = true;
  390. $langs->load("fichinter");
  391. $result = $object->fetch_thirdparty($object->socid);
  392. // Proposer
  393. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Proposer");
  394. print '</td><td class="CTableRow2">';
  395. print img_picto('', 'company', 'class="pictofixedwidth"');
  396. print '<b>'.$creditor.'</b>';
  397. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  398. print '</td></tr>'."\n";
  399. // Target
  400. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  401. print '</td><td class="CTableRow2">';
  402. print img_picto('', 'company', 'class="pictofixedwidth"');
  403. print '<b>'.$object->thirdparty->name.'</b>';
  404. print '</td></tr>'."\n";
  405. // Object
  406. $text = '<b>'.$langs->trans("SignatureFichinterRef", $object->ref).'</b>';
  407. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  408. print '</td><td class="CTableRow2">'.$text;
  409. $last_main_doc_file = $object->last_main_doc;
  410. if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
  411. // It seems document has never been generated, or was generated and then deleted.
  412. // So we try to regenerate it with its default template.
  413. $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.
  414. $object->generateDocument($defaulttemplate, $langs);
  415. }
  416. $directdownloadlink = $object->getLastMainDocLink('fichinter');
  417. if ($directdownloadlink) {
  418. print '<br><a href="'.$directdownloadlink.'">';
  419. print img_mime($object->last_main_doc, '');
  420. if ($message == "signed") {
  421. print $langs->trans("DownloadSignedDocument").'</a>';
  422. } else {
  423. print $langs->trans("DownloadDocument").'</a>';
  424. }
  425. }
  426. print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
  427. print '<input type="hidden" name="ref" value="'.$object->ref.'">';
  428. print '</td></tr>'."\n";
  429. }
  430. if (!$found && !$mesg) {
  431. $mesg = $langs->transnoentitiesnoconv("ErrorBadParameters");
  432. }
  433. if ($mesg) {
  434. print '<tr><td class="center" colspan="2"><br><div class="warning">'.dol_escape_htmltag($mesg).'</div></td></tr>'."\n";
  435. }
  436. print '</table>'."\n";
  437. print "\n";
  438. if ($action != 'dosign') {
  439. if ($found && !$error) {
  440. // We are in a management option and no error
  441. } else {
  442. dol_print_error_email('ERRORNEWONLINESIGN');
  443. }
  444. } else {
  445. // Print
  446. }
  447. print '</td></tr>'."\n";
  448. print '<tr><td class="center">';
  449. if ($action == "dosign" && empty($cancel)) {
  450. print '<div class="tablepublicpayment">';
  451. print '<input type="button" class="buttonDelete small" id="clearsignature" value="'.$langs->trans("ClearSignature").'">';
  452. print '<div id="signature" style="border:solid;"></div>';
  453. print '</div>';
  454. // 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.
  455. print '<input type="button" class="button" id="signbutton" value="'.$langs->trans("Sign").'">';
  456. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  457. // Add js code managed into the div #signature
  458. print '<script language="JavaScript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jSignature/jSignature.js"></script>
  459. <script type="text/javascript">
  460. $(document).ready(function() {
  461. $("#signature").jSignature({ color:"#000", lineWidth:4, '.(empty($conf->dol_optimize_smallscreen) ? '' : 'width: 280, ' ).'height: 180});
  462. $("#signature").on("change",function(){
  463. $("#clearsignature").css("display","");
  464. $("#signbutton").attr("disabled",false);
  465. if(!$._data($("#signbutton")[0], "events")){
  466. $("#signbutton").on("click",function(){
  467. console.log("We click on button sign");
  468. $("#signbutton").val(\''.dol_escape_js($langs->transnoentities('PleaseBePatient')).'\');
  469. var signature = $("#signature").jSignature("getData", "image");
  470. $.ajax({
  471. type: "POST",
  472. url: "'.DOL_URL_ROOT.'/core/ajax/onlineSign.php",
  473. dataType: "text",
  474. data: {
  475. "action" : "importSignature",
  476. "token" : \''.newToken().'\',
  477. "signaturebase64" : signature,
  478. "ref" : \''.dol_escape_js($REF).'\',
  479. "securekey" : \''.dol_escape_js($SECUREKEY).'\',
  480. "mode" : \''.dol_escape_htmltag($source).'\',
  481. "entity" : \''.dol_escape_htmltag($entity).'\',
  482. },
  483. success: function(response) {
  484. if(response == "success"){
  485. console.log("Success on saving signature");
  486. window.location.replace("'.$_SERVER["PHP_SELF"].'?ref='.urlencode($ref).'&source='.urlencode($source).'&message=signed&securekey='.urlencode($SECUREKEY).(isModEnabled('multicompany')?'&entity='.$entity:'').'");
  487. }else{
  488. console.error(response);
  489. }
  490. },
  491. });
  492. });
  493. }
  494. });
  495. $("#clearsignature").on("click",function(){
  496. $("#signature").jSignature("clear");
  497. $("#signbutton").attr("disabled",true);
  498. });
  499. $("#signbutton").attr("disabled",true);
  500. });
  501. </script>';
  502. } else {
  503. if ($source == 'proposal') {
  504. if ($object->status == $object::STATUS_SIGNED) {
  505. print '<br>';
  506. if ($message == 'signed') {
  507. print '<span class="ok">'.$langs->trans("PropalSigned").'</span>';
  508. } else {
  509. print '<span class="ok">'.$langs->trans("PropalAlreadySigned").'</span>';
  510. }
  511. } elseif ($object->status == $object::STATUS_NOTSIGNED) {
  512. print '<br>';
  513. if ($message == 'refused') {
  514. print '<span class="ok">'.$langs->trans("PropalRefused").'</span>';
  515. } else {
  516. print '<span class="warning">'.$langs->trans("PropalAlreadyRefused").'</span>';
  517. }
  518. } else {
  519. print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignPropal").'">';
  520. print '<input name="refusepropal" type="submit" class="butActionDelete small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("RefusePropal").'">';
  521. }
  522. } elseif ($source == 'contract') {
  523. if ($message == 'signed') {
  524. print '<span class="ok">'.$langs->trans("ContractSigned").'</span>';
  525. } else {
  526. print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignContract").'">';
  527. }
  528. } elseif ($source == 'fichinter') {
  529. if ($message == 'signed') {
  530. print '<span class="ok">'.$langs->trans("FichinterSigned").'</span>';
  531. } else {
  532. print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="'.$langs->trans("SignFichinter").'">';
  533. }
  534. }
  535. }
  536. print '</td></tr>'."\n";
  537. print '</table>'."\n";
  538. print '</form>'."\n";
  539. print '</div>'."\n";
  540. print '<br>';
  541. htmlPrintOnlinePaymentFooter($mysoc, $langs);
  542. llxFooter('', 'public');
  543. $db->close();