dolibarr 20.0.2
oauthlogintokens.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014-2018 Frederic France <frederic.france@netlogic.fr>
4 * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.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// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
31
32use OAuth\Common\Storage\DoliStorage;
33use OAuth\Common\Consumer\Credentials;
34
35$supportedoauth2array = getSupportedOauth2Array();
36
37// Load translation files required by the page
38$langs->loadLangs(array('admin', 'printing', 'oauth'));
39
40$action = GETPOST('action', 'aZ09');
41$mode = GETPOST('mode', 'alpha');
42$value = GETPOST('value', 'alpha');
43$varname = GETPOST('varname', 'alpha');
44$driver = GETPOST('driver', 'alpha');
45
46if (!empty($driver)) {
47 $langs->load($driver);
48}
49
50if (!$mode) {
51 $mode = 'setup';
52}
53
54if (!$user->admin) {
56}
57
58
59/*
60 * Action
61 */
62
63/*if (($mode == 'test' || $mode == 'setup') && empty($driver))
64{
65 setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
66 header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
67 exit;
68}*/
69
70if ($action == 'setconst' && $user->admin) {
71 $error = 0;
72 $db->begin();
73
74 $setupconstarray = GETPOST('setupdriver', 'array');
75
76 foreach ($setupconstarray as $setupconst) {
77 //print '<pre>'.print_r($setupconst, true).'</pre>';
78
79 $constname = dol_escape_htmltag($setupconst['varname']);
80 $constvalue = dol_escape_htmltag($setupconst['value']);
81 $consttype = dol_escape_htmltag($setupconst['type']);
82 $constnote = dol_escape_htmltag($setupconst['note']);
83
84 $result = dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
85 if (!($result > 0)) {
86 $error++;
87 }
88 }
89
90 if (!$error) {
91 $db->commit();
92 setEventMessages($langs->trans("SetupSaved"), null);
93 } else {
94 $db->rollback();
95 dol_print_error($db);
96 }
97 $action = '';
98}
99
100if ($action == 'setvalue' && $user->admin) {
101 $db->begin();
102
103 $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
104 if (!($result > 0)) {
105 $error++;
106 }
107
108 if (!$error) {
109 $db->commit();
110 setEventMessages($langs->trans("SetupSaved"), null);
111 } else {
112 $db->rollback();
113 dol_print_error($db);
114 }
115 $action = '';
116}
117
118// Test a refresh of a token using the refresh token
119if ($action == 'refreshtoken' && $user->admin) {
120 $keyforprovider = GETPOST('keyforprovider');
121 $OAUTH_SERVICENAME = GETPOST('service');
122
123 // Show value of token
124 $tokenobj = null;
125 // Load OAUth libraries
126 require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
127
128 $keyforsupportedoauth2array = $OAUTH_SERVICENAME;
129 if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
130 $keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
131 } else {
132 $keyforprovider = '';
133 }
134 $keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
135 $keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
136
137 $keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
138
139 // Dolibarr storage
140 $storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
141 try {
142 // $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
143 print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n";
144
145 dol_syslog("oauthlogintokens.php: Read token for service ".$OAUTH_SERVICENAME);
146 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
147
148 $expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30));
149 // We have to save the refresh token in a memory variable because Google give it only once
150 $refreshtoken = $tokenobj->getRefreshToken();
151 print '<!-- data stored into field token: '.$storage->token.' - expire '.((string) $expire).' -->';
152
153 //print $tokenobj->getExtraParams()['id_token'].'<br>';
154 //print $tokenobj->getAccessToken().'<br>';
155 //print $tokenobj->getRefreshToken().'<br>';
156
157 //var_dump($expire);
158
159 // We do the refresh even if not expired, this is the goal of action.
160 $oauthname = explode('-', $OAUTH_SERVICENAME);
161 $keyforoauthservice = strtoupper($oauthname[0]).(empty($oauthname[1]) ? '' : '-'.$oauthname[1]);
162 $credentials = new Credentials(
163 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_ID'),
164 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_SECRET'),
165 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_URLCALLBACK')
166 );
167
168 $serviceFactory = new \OAuth\ServiceFactory();
169 $httpClient = new \OAuth\Common\Http\Client\CurlClient();
170 // TODO Set options for proxy and timeout
171 // $params=array('CURLXXX'=>value, ...)
172 //$httpClient->setCurlParameters($params);
173 $serviceFactory->setHttpClient($httpClient);
174
175 $scopes = array();
176 if (preg_match('/^Microsoft/', $OAUTH_SERVICENAME)) {
177 //$extraparams = $tokenobj->getExtraParams();
178 $tmp = explode('-', $OAUTH_SERVICENAME);
179 $scopes = explode(',', getDolGlobalString('OAUTH_'.strtoupper($tmp[0]).(empty($tmp[1]) ? '' : '-'.$tmp[1]).'_SCOPE'));
180 }
181
182 // ex service is Google-Emails we need only the first part Google
183 $apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, $scopes);
184
185 if ($apiService instanceof OAuth\OAuth2\Service\AbstractService || $apiService instanceof OAuth\OAuth1\Service\AbstractService) {
186 // ServiceInterface does not provide refreshAccessToekn, AbstractService does
187 dol_syslog("oauthlogintokens.php: call refreshAccessToken to get the new access token");
188 $tokenobj = $apiService->refreshAccessToken($tokenobj); // This call refresh and store the new token (but does not include the refresh token)
189
190 dol_syslog("oauthlogintokens.php: call setRefreshToken");
191 $tokenobj->setRefreshToken($refreshtoken); // Restore the refresh token
192
193 dol_syslog("oauthlogintokens.php: call storeAccessToken to save the new access token + the old refresh token");
194 $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj); // This save the new token including the refresh token
195
196 if ($expire) {
197 setEventMessages($langs->trans("OldTokenWasExpiredItHasBeenRefresh"), null, 'mesgs');
198 } else {
199 setEventMessages($langs->trans("OldTokenWasNotExpiredButItHasBeenRefresh"), null, 'mesgs');
200 }
201 } else {
202 dol_print_error($db, 'apiService is not a correct OAUTH2 Abstract service');
203 }
204
205 dol_syslog("oauthlogintokens.php: Read token again for service ".$OAUTH_SERVICENAME);
206 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
207 } catch (Exception $e) {
208 // Return an error if token not found
209 print $e->getMessage();
210 }
211}
212
213
214/*
215 * View
216 */
217
218// Define $urlwithroot
219$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
220$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
221//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
222
223$form = new Form($db);
224
225$title = $langs->trans("TokenManager");
226$help_url = 'EN:Module_OAuth|FR:Module_OAuth_FR|ES:Módulo_OAuth_ES';
227
228llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-oauthlogintokens');
229
230$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
231print load_fiche_titre($langs->trans('ConfigOAuth'), $linkback, 'title_setup');
232
234
235print dol_get_fiche_head($head, 'tokengeneration', '', -1, '');
236
237if (GETPOST('error')) {
238 setEventMessages(GETPOST('error'), null, 'errors');
239}
240
241if ($mode == 'setup' && $user->admin) {
242 print '<span class="opacitymedium">'.$langs->trans("OAuthSetupForLogin")."</span><br><br>\n";
243
244 // Define $listinsetup
245 $listinsetup = array();
246 foreach ($conf->global as $key => $val) {
247 if (!empty($val) && preg_match('/^OAUTH_.*_ID$/', $key)) {
248 $provider = preg_replace('/_ID$/', '', $key);
249 $listinsetup[] = array(
250 $provider.'_NAME',
251 $provider.'_ID',
252 $provider.'_SECRET',
253 $provider.'_URLAUTHORIZE', // For custom oauth links
254 $provider.'_SCOPE' // For custom oauth links
255 );
256 }
257 }
258
259 $oauthstateanticsrf = bin2hex(random_bytes(128 / 8));
260
261 // $list is defined into oauth.lib.php to the list of supported OAuth providers.
262 if (!empty($listinsetup)) {
263 foreach ($listinsetup as $key) {
264 $supported = 0;
265 $keyforsupportedoauth2array = $key[0]; // May be OAUTH_GOOGLE_NAME or OAUTH_GOOGLE_xxx_NAME
266 $keyforsupportedoauth2array = preg_replace('/^OAUTH_/', '', $keyforsupportedoauth2array);
267 $keyforsupportedoauth2array = preg_replace('/_NAME$/', '', $keyforsupportedoauth2array);
268 if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
269 $keybeforeprovider = preg_replace('/-.*$/', '', $keyforsupportedoauth2array);
270 $keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
271 } else {
272 $keybeforeprovider = $keyforsupportedoauth2array;
273 $keyforprovider = '';
274 }
275 $keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
276 $keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
277
278 $nameofservice = ucfirst(strtolower(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']));
279 $nameofservice .= ($keyforprovider ? '-'.$keyforprovider : '');
280 $OAUTH_SERVICENAME = $nameofservice;
281
282 $keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
283
284 $shortscope = '';
285 if (getDolGlobalString($key[4])) {
286 $shortscope = getDolGlobalString($key[4]);
287 }
288 $state = $shortscope; // TODO USe a better state
289
290 $urltorefresh = $_SERVER["PHP_SELF"].'?action=refreshtoken&token='.newToken();
291
292 // Define $urltorenew, $urltodelete, $urltocheckperms
293 if ($keyforsupportedoauth2array == 'OAUTH_GITHUB_NAME') {
294 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
295 // We pass this param list in to 'state' because we need it before and after the redirect.
296
297 // Note: github does not accept csrf key inside the state parameter (only known values)
298 $urltorenew = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($shortscope).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
299 $urltodelete = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
300 $urltocheckperms = 'https://github.com/settings/applications/';
301 } elseif ($keyforsupportedoauth2array == 'OAUTH_GOOGLE_NAME') {
302 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
303 // List of scopes for Google are here: https://developers.google.com/identity/protocols/oauth2/scopes
304 // We pass this key list into the param 'state' because we need it before and after the redirect.
305 $urltorenew = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'-'.$oauthstateanticsrf.'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
306 $urltodelete = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
307 $urltocheckperms = 'https://security.google.com/settings/security/permissions';
308 } elseif (!empty($supportedoauth2array[$keyforsupportedoauth2array]['returnurl'])) {
309 $urltorenew = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
310 $urltodelete = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
311 $urltocheckperms = '';
312 } else {
313 $urltorenew = '';
314 $urltodelete = '';
315 $urltocheckperms = '';
316 }
317
318 if ($urltorenew) {
319 $urltorenew .= '&keyforprovider='.urlencode($keyforprovider);
320 }
321 if ($urltorefresh) {
322 $urltorefresh .= '&keyforprovider='.urlencode($keyforprovider).'&service='.urlencode($OAUTH_SERVICENAME);
323 }
324 if ($urltodelete) {
325 $urltodelete .= '&keyforprovider='.urlencode($keyforprovider);
326 }
327
328 // Show value of token
329 $tokenobj = null;
330 // Token
331 require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
332 // Dolibarr storage
333 $storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
334 try {
335 // $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
336 print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n";
337 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
338 print '<!-- data stored into field token: '.$storage->token.' -->';
339 //print $storage->token.'<br>';
340 //print $tokenobj->getExtraParams()['id_token'].'<br>';
341 //print $tokenobj->getAccessToken().'<br>';
342 } catch (Exception $e) {
343 // Return an error if token not found
344 //print $e->getMessage();
345 }
346
347 // Set other properties
348 $refreshtoken = false;
349 $expiredat = '';
350
351 $expire = false;
352 // Is token expired or will token expire in the next 30 seconds
353 if (is_object($tokenobj)) {
354 $expire = ($tokenobj->getEndOfLife() !== $tokenobj::EOL_NEVER_EXPIRES && $tokenobj->getEndOfLife() !== $tokenobj::EOL_UNKNOWN && time() > ($tokenobj->getEndOfLife() - 30));
355 }
356 if ($key[1] != '' && $key[2] != '') {
357 if (is_object($tokenobj)) {
358 $refreshtoken = $tokenobj->getRefreshToken();
359
360 $endoflife = $tokenobj->getEndOfLife();
361 if ($endoflife == $tokenobj::EOL_NEVER_EXPIRES) {
362 $expiredat = $langs->trans("Never");
363 } elseif ($endoflife == $tokenobj::EOL_UNKNOWN) {
364 $expiredat = $langs->trans("Unknown");
365 } else {
366 $expiredat = dol_print_date($endoflife, "dayhour", 'tzuserrel');
367 }
368 }
369 }
370
371 $submit_enabled = 0;
372
373 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off">';
374 print '<input type="hidden" name="token" value="'.newToken().'">';
375 print '<input type="hidden" name="action" value="setconst">';
376 print '<input type="hidden" name="page_y" value="">';
377
378 print '<div class="div-table-responsive-no-min">';
379 print '<table class="noborder centpercent">'."\n";
380
381 // Api Name
382 $label = $langs->trans($keyforsupportedoauth2array);
383 print '<tr class="liste_titre">';
384 print '<th class="titlefieldcreate">';
385 print img_picto('', $supportedoauth2array[$keyforsupportedoauth2array]['picto'], 'class="pictofixedwidth"');
386 if ($label == $keyforsupportedoauth2array) {
387 print $supportedoauth2array[$keyforsupportedoauth2array]['name'];
388 } else {
389 print $label;
390 }
391 if ($keyforprovider) {
392 print ' (<b>'.$keyforprovider.'</b>)';
393 } else {
394 print ' (<b>'.$langs->trans("NoName").'</b>)';
395 }
396 print '</th>';
397 print '<th></th>';
398 print '<th></th>';
399 print "</tr>\n";
400
401 print '<tr class="oddeven">';
402 print '<td>';
403 //var_dump($key);
404 print $langs->trans("OAuthIDSecret").'</td>';
405 print '<td>';
406 print '<span class="opacitymedium">'.$langs->trans("SeePreviousTab").'</span>';
407 print '</td>';
408 print '<td>';
409 print '</td>';
410 print '</tr>'."\n";
411
412 // Scopes
413 print '<tr class="oddeven">';
414 print '<td>'.$langs->trans("Scopes").'</td>';
415 print '<td colspan="2">';
416 $currentscopes = getDolGlobalString($key[4]);
417 print $currentscopes;
418 print '</td></tr>';
419
420 print '<tr class="oddeven">';
421 print '<td>';
422 //var_dump($key);
423 print $langs->trans("IsTokenGenerated");
424 print '</td>';
425 print '<td>';
426 if ($keyforprovider != 'Login') {
427 if (is_object($tokenobj)) {
428 print $form->textwithpicto(yn(1), $langs->trans("HasAccessToken").' : '.dol_print_date($storage->date_modification, 'dayhour').' state='.dol_escape_htmltag($storage->state));
429 } else {
430 print '<span class="opacitymedium">'.$langs->trans("NoAccessToken").'</span>';
431 }
432 } else {
433 print '<span class="opacitymedium">'.$langs->trans("TokenNotRequiredForOAuthLogin").'</span>';
434 }
435 print '</td>';
436 print '<td width="50%">';
437 if ($keyforprovider != 'Login') {
438 // Links to delete/checks token
439 if (is_object($tokenobj)) {
440 //test on $storage->hasAccessToken($OAUTH_SERVICENAME) ?
441 if ($urltodelete) {
442 print '<a class="button smallpaddingimp reposition" href="'.$urltodelete.'">'.$langs->trans('DeleteAccess').'</a><br>';
443 } else {
444 print '<span class="opacitymedium">'.$langs->trans('GoOnTokenProviderToDeleteToken').'</span><br>';
445 }
446 }
447 // Request remote token
448 if ($urltorenew) {
449 print '<a class="button smallpaddingimp reposition" href="'.$urltorenew.'">'.$langs->trans('GetAccess').'</a>';
450 print $form->textwithpicto('', $langs->trans('RequestAccess'));
451 print '<br>';
452 }
453 // Request remote token
454 if ($urltorefresh && $refreshtoken) {
455 print '<a class="button smallpaddingimp reposition classfortooltip marginright" href="'.$urltorefresh.'" title="'.dolPrintHTMLForAttribute($langs->trans('RefreshTokenHelp')).'">'.$langs->trans('RefreshToken').'</a>';
456 }
457
458 // Check remote access
459 if ($urltocheckperms) {
460 print '<br>'.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': <a href="'.$urltocheckperms.'" target="_'.strtolower($OAUTH_SERVICENAME).'">'.$urltocheckperms.'</a>';
461 }
462 }
463 print '</td>';
464 print '</tr>';
465
466 print '<tr class="oddeven">';
467 print '<td>';
468 //var_dump($key);
469 print $langs->trans("Token").'</td>';
470 print '<td colspan="2">';
471
472 if (is_object($tokenobj)) {
473 $tokentoshow = $tokenobj->getAccessToken();
474 print '<span class="" title="'.dol_escape_htmltag($tokentoshow).'">'.showValueWithClipboardCPButton($tokentoshow, 1, dol_trunc($tokentoshow, 32)).'</span><br>';
475 //print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
476 //print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
477 //var_dump($tokenobj->getExtraParams());
478 /*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
479 print ''.join(',',$tokenobj->getExtraParams());
480 print '</textarea>';*/
481 }
482 print '</td>';
483 print '</tr>'."\n";
484
485 if (is_object($tokenobj)) {
486 // Token refresh
487 print '<tr class="oddeven">';
488 print '<td>';
489 //var_dump($key);
490 print $langs->trans("TOKEN_REFRESH");
491 print '</td>';
492 print '<td colspan="2">';
493 print '<span class="" title="'.dol_escape_htmltag($refreshtoken).'">'.showValueWithClipboardCPButton($refreshtoken, 1, dol_trunc($refreshtoken, 32)).'</span>';
494 print '</td>';
495 print '</tr>';
496
497 // Token expired
498 print '<tr class="oddeven">';
499 print '<td>';
500 //var_dump($key);
501 print $langs->trans("TOKEN_EXPIRED");
502 print '</td>';
503 print '<td colspan="2">';
504 print yn($expire);
505 print '</td>';
506 print '</tr>';
507
508 // Token expired at
509 print '<tr class="oddeven">';
510 print '<td>';
511 //var_dump($key);
512 print $langs->trans("TOKEN_EXPIRE_AT");
513 print '</td>';
514 print '<td colspan="2">';
515 print $expiredat;
516 print '</td>';
517 print '</tr>';
518 }
519
520 print '</table>';
521 print '</div>';
522
523 if (!empty($driver)) {
524 if ($submit_enabled) {
525 print $form->buttonsSaveCancel("Modify", '');
526 }
527 }
528
529 print '</form>';
530 print '<br>';
531 }
532 }
533}
534
535if ($mode == 'test' && $user->admin) {
536 print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
537
538 print '<div class="div-table-responsive-no-min">';
539 print '<table class="noborder centpercent">';
540 if (!empty($driver)) {
541 require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
542 $classname = 'printing_'.$driver;
543 $langs->load($driver);
544 $printer = new $classname($db);
545 //print '<pre>'.print_r($printer, true).'</pre>';
546 if (count($printer->getlistAvailablePrinters())) {
547 if ($printer->listAvailablePrinters() == 0) {
548 print $printer->resprint;
549 } else {
550 setEventMessages($printer->error, $printer->errors, 'errors');
551 }
552 } else {
553 print $langs->trans('PleaseConfigureDriverfromList');
554 }
555 }
556
557 print '</table>';
558 print '</div>';
559}
560
561if ($mode == 'userconf' && $user->admin) {
562 print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
563
564 print '<div class="div-table-responsive">';
565 print '<table class="noborder centpercent">';
566 print '<tr class="liste_titre">';
567 print '<th>'.$langs->trans("User").'</th>';
568 print '<th>'.$langs->trans("PrintModule").'</th>';
569 print '<th>'.$langs->trans("PrintDriver").'</th>';
570 print '<th>'.$langs->trans("Printer").'</th>';
571 print '<th>'.$langs->trans("PrinterLocation").'</th>';
572 print '<th>'.$langs->trans("PrinterId").'</th>';
573 print '<th>'.$langs->trans("NumberOfCopy").'</th>';
574 print '<th class="center">'.$langs->trans("Delete").'</th>';
575 print "</tr>\n";
576 $sql = "SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login";
577 $sql .= " FROM ".MAIN_DB_PREFIX."printing as p, ".MAIN_DB_PREFIX."user as u WHERE p.userid = u.rowid";
578 $resql = $db->query($sql);
579 while ($obj = $db->fetch_object($resql)) {
580 print '<tr class="oddeven">';
581 print '<td>'.$obj->login.'</td>';
582 print '<td>'.$obj->module.'</td>';
583 print '<td>'.$obj->driver.'</td>';
584 print '<td>'.$obj->printer_name.'</td>';
585 print '<td>'.$obj->printer_location.'</td>';
586 print '<td>'.$obj->printer_id.'</td>';
587 print '<td>'.$obj->copy.'</td>';
588 print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
589 print "</tr>\n";
590 }
591 print '</table>';
592 print '</div>';
593}
594
595print dol_get_fiche_end();
596
597// End of page
598llxFooter();
599$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
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
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolPrintHTMLForAttribute($s)
Return a string ready to be output on an HTML attribute (alt, title, data-html, .....
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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...
getSupportedOauth2Array()
Return array of tabs to used on pages to setup cron module.
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.