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