newonlinesign.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. */
  24. if (!defined('NOLOGIN')) define("NOLOGIN", 1); // This means this output page does not require to be logged.
  25. if (!defined('NOCSRFCHECK')) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  26. if (!defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  27. // For MultiCompany module.
  28. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  29. // TODO This should be useless. Because entity must be retreive from object ref and not from url.
  30. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  31. if (is_numeric($entity)) define("DOLENTITY", $entity);
  32. require '../../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  37. // Load translation files
  38. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox"));
  39. // Security check
  40. // No check on module enabled. Done later according to $validpaymentmethod
  41. $action = GETPOST('action', 'aZ09');
  42. // Input are:
  43. // type ('invoice','order','contractline'),
  44. // id (object id),
  45. // amount (required if id is empty),
  46. // tag (a free text, required if type is empty)
  47. // currency (iso code)
  48. $suffix = GETPOST("suffix", 'aZ09');
  49. $source = GETPOST("source", 'alpha');
  50. $ref = $REF = GETPOST("ref", 'alpha');
  51. if (empty($source)) $source = 'proposal';
  52. if (!$action)
  53. {
  54. if ($source && !$ref)
  55. {
  56. print $langs->trans('ErrorBadParameters')." - ref missing";
  57. exit;
  58. }
  59. }
  60. // Define $urlwithroot
  61. //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  62. //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  63. $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
  64. // Complete urls for post treatment
  65. $SECUREKEY = GETPOST("securekey"); // Secure key
  66. if (!empty($source))
  67. {
  68. $urlok .= 'source='.urlencode($source).'&';
  69. $urlko .= 'source='.urlencode($source).'&';
  70. }
  71. if (!empty($REF))
  72. {
  73. $urlok .= 'ref='.urlencode($REF).'&';
  74. $urlko .= 'ref='.urlencode($REF).'&';
  75. }
  76. if (!empty($SECUREKEY))
  77. {
  78. $urlok .= 'securekey='.urlencode($SECUREKEY).'&';
  79. $urlko .= 'securekey='.urlencode($SECUREKEY).'&';
  80. }
  81. if (!empty($entity))
  82. {
  83. $urlok .= 'entity='.urlencode($entity).'&';
  84. $urlko .= 'entity='.urlencode($entity).'&';
  85. }
  86. $urlok = preg_replace('/&$/', '', $urlok); // Remove last &
  87. $urlko = preg_replace('/&$/', '', $urlko); // Remove last &
  88. $creditor = $mysoc->name;
  89. /*
  90. * Actions
  91. */
  92. if ($action == 'dosign')
  93. {
  94. // TODO
  95. }
  96. /*
  97. * View
  98. */
  99. $head = '';
  100. if (!empty($conf->global->MAIN_SIGN_CSS_URL)) $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->MAIN_SIGN_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  101. $conf->dol_hide_topmenu = 1;
  102. $conf->dol_hide_leftmenu = 1;
  103. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  104. llxHeader($head, $langs->trans("OnlineSignature"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
  105. // Check link validity
  106. if (!empty($source) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', '')))
  107. {
  108. $langs->load("errors");
  109. dol_print_error_email('BADREFINONLINESIGNFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref));
  110. // End of page
  111. llxFooter();
  112. $db->close();
  113. exit;
  114. }
  115. print '<span id="dolpaymentspan"></span>'."\n";
  116. print '<div class="center">'."\n";
  117. print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  118. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  119. print '<input type="hidden" name="action" value="dosign">'."\n";
  120. print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
  121. print '<input type="hidden" name="suffix" value="'.GETPOST("suffix", 'alpha').'">'."\n";
  122. print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
  123. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  124. print "\n";
  125. print '<!-- Form to sign -->'."\n";
  126. print '<table id="dolpaymenttable" summary="Payment form" class="center">'."\n";
  127. // 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)
  128. $width = 0;
  129. // Define logo and logosmall
  130. $logosmall = $mysoc->logo_small;
  131. $logo = $mysoc->logo;
  132. $paramlogo = 'ONLINE_SIGN_LOGO_'.$suffix;
  133. if (!empty($conf->global->$paramlogo)) $logosmall = $conf->global->$paramlogo;
  134. elseif (!empty($conf->global->ONLINE_SIGN_LOGO)) $logosmall = $conf->global->ONLINE_SIGN_LOGO;
  135. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  136. // Define urllogo
  137. $urllogo = '';
  138. $urllogofull = '';
  139. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall))
  140. {
  141. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  142. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  143. $width = 150;
  144. }
  145. elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo))
  146. {
  147. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  148. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  149. $width = 150;
  150. }
  151. // Output html code for logo
  152. if ($urllogo)
  153. {
  154. print '<div class="backgreypublicpayment">';
  155. print '<div class="logopublicpayment">';
  156. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  157. if ($width) print ' width="'.$width.'"';
  158. print '>';
  159. print '</div>';
  160. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  161. print '<div class="poweredbypublicpayment opacitymedium right"><a href="https://www.dolibarr.org" target="dolibarr">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.png" width="80px"></a></div>';
  162. }
  163. print '</div>';
  164. }
  165. // Output introduction text
  166. $text = '';
  167. if (!empty($conf->global->ONLINE_SIGN_NEWFORM_TEXT))
  168. {
  169. $langs->load("members");
  170. if (preg_match('/^\((.*)\)$/', $conf->global->ONLINE_SIGN_NEWFORM_TEXT, $reg)) $text .= $langs->trans($reg[1])."<br>\n";
  171. else $text .= $conf->global->ONLINE_SIGN_NEWFORM_TEXT."<br>\n";
  172. $text = '<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
  173. }
  174. if (empty($text))
  175. {
  176. $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnOnlineSignaturePage", $mysoc->name).'</strong></td></tr>'."\n";
  177. $text .= '<tr><td class="textpublicpayment">'.$langs->trans("ThisScreenAllowsYouToSignDocFrom", $creditor).'<br><br></td></tr>'."\n";
  178. }
  179. print $text;
  180. // Output payment summary form
  181. print '<tr><td align="center">';
  182. print '<table with="100%" id="tablepublicpayment">';
  183. print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnDocumentToSign").' :</td></tr>'."\n";
  184. $found = false;
  185. $error = 0;
  186. $var = false;
  187. // Payment on customer order
  188. if ($source == 'proposal')
  189. {
  190. $found = true;
  191. $langs->load("proposal");
  192. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  193. $proposal = new Propal($db);
  194. $result = $proposal->fetch('', $ref);
  195. if ($result <= 0)
  196. {
  197. $mesg = $proposal->error;
  198. $error++;
  199. }
  200. else
  201. {
  202. $result = $proposal->fetch_thirdparty($proposal->socid);
  203. }
  204. // Creditor
  205. print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("Creditor");
  206. print '</td><td class="CTableRow'.($var ? '1' : '2').'"><b>'.$creditor.'</b>';
  207. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  208. print '</td></tr>'."\n";
  209. // Debitor
  210. print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("ThirdParty");
  211. print '</td><td class="CTableRow'.($var ? '1' : '2').'"><b>'.$proposal->thirdparty->name.'</b>';
  212. // Object
  213. $text = '<b>'.$langs->trans("SignatureProposalRef", $proposal->ref).'</b>';
  214. print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("Designation");
  215. print '</td><td class="CTableRow'.($var ? '1' : '2').'">'.$text;
  216. print '<input type="hidden" name="source" value="'.GETPOST("source", 'alpha').'">';
  217. print '<input type="hidden" name="ref" value="'.$proposal->ref.'">';
  218. print '</td></tr>'."\n";
  219. }
  220. if (!$found && !$mesg) $mesg = $langs->trans("ErrorBadParameters");
  221. if ($mesg) print '<tr><td align="center" colspan="2"><br><div class="warning">'.$mesg.'</div></td></tr>'."\n";
  222. print '</table>'."\n";
  223. print "\n";
  224. if ($action != 'dosign')
  225. {
  226. if ($found && !$error) // We are in a management option and no error
  227. {
  228. }
  229. else
  230. {
  231. dol_print_error_email('ERRORNEWONLINESIGN');
  232. }
  233. }
  234. else
  235. {
  236. // Print
  237. }
  238. print '</td></tr>'."\n";
  239. print '</table>'."\n";
  240. print '</form>'."\n";
  241. print '</div>'."\n";
  242. print '<br>';
  243. htmlPrintOnlinePaymentFooter($mysoc, $langs);
  244. llxFooter('', 'public');
  245. $db->close();