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