dolibarr 25.0.0-alpha
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-2026 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 // tokenobj uses time() @phan-suppress-next-line DolibarrForbiddenFunctionPlugin
156 $expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30));
157 // We have to save the refresh token in a memory variable because Google give it only once
158 $refreshtoken = $tokenobj->getRefreshToken();
159 print '<!-- data stored into field token: '.$storage->token.' - expire '.((string) $expire).' -->';
160
161 //print $tokenobj->getExtraParams()['id_token'].'<br>';
162 //print $tokenobj->getAccessToken().'<br>';
163 //print $tokenobj->getRefreshToken().'<br>';
164
165 //var_dump($expire);
166
167 // We do the refresh even if not expired, this is the goal of action.
168 $oauthname = explode('-', $OAUTH_SERVICENAME);
169 $keyforoauthservice = strtoupper($oauthname[0]).(empty($oauthname[1]) ? '' : '-'.$oauthname[1]);
170 $credentials = new Credentials(
171 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_ID'),
172 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_SECRET'),
173 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_URLCALLBACK')
174 );
175
176 $serviceFactory = new \OAuth\ServiceFactory();
177 $httpClient = new \OAuth\Common\Http\Client\CurlClient();
178 // TODO Set options for proxy and timeout
179 // $params=array('CURLXXX'=>value, ...)
180 //$httpClient->setCurlParameters($params);
181 $serviceFactory->setHttpClient($httpClient);
182
183 $scopes = array();
184 if (preg_match('/^Microsoft/', $OAUTH_SERVICENAME)) {
185 //$extraparams = $tokenobj->getExtraParams();
186 $tmp = explode('-', $OAUTH_SERVICENAME);
187 $scopes = explode(',', getDolGlobalString('OAUTH_'.strtoupper($tmp[0]).(empty($tmp[1]) ? '' : '-'.$tmp[1]).'_SCOPE'));
188 }
189
190 // ex service is Google-Emails we need only the first part Google
191 $apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, $scopes);
192
193 if ($apiService instanceof OAuth\OAuth2\Service\AbstractService || $apiService instanceof OAuth\OAuth1\Service\AbstractService) {
194 // ServiceInterface does not provide refreshAccessToekn, AbstractService does
195 dol_syslog("oauthlogintokens.php: call refreshAccessToken to get the new access token");
196 $tokenobj = $apiService->refreshAccessToken($tokenobj); // This call refresh and store the new token (but does not include the refresh token)
197
198 dol_syslog("oauthlogintokens.php: call setRefreshToken");
199 $tokenobj->setRefreshToken($refreshtoken); // Restore the refresh token
200
201 dol_syslog("oauthlogintokens.php: call storeAccessToken to save the new access token + the old refresh token");
202 $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj); // This save the new token including the refresh token
203
204 if ($expire) {
205 setEventMessages($langs->trans("OldTokenWasExpiredItHasBeenRefresh"), null, 'mesgs');
206 } else {
207 setEventMessages($langs->trans("OldTokenWasNotExpiredButItHasBeenRefresh"), null, 'mesgs');
208 }
209 } else {
210 dol_print_error($db, 'apiService is not a correct OAUTH2 Abstract service');
211 }
212
213 dol_syslog("oauthlogintokens.php: Read token again for service ".$OAUTH_SERVICENAME);
214 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
215 } catch (Exception $e) {
216 // Return an error if token not found
217 print $e->getMessage();
218 }
219}
220
221
222/*
223 * View
224 */
225
226// Define $urlwithroot
227$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
228$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
229//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
230
231$form = new Form($db);
232
233$title = $langs->trans("TokenManager");
234$help_url = 'EN:Module_OAuth|FR:Module_OAuth_FR|ES:Módulo_OAuth_ES';
235
236llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-oauthlogintokens');
237
238$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>';
239
240print load_fiche_titre($langs->trans('ConfigOAuth'), $linkback, 'title_setup');
241
243
244print dol_get_fiche_head($head, 'tokengeneration', '', -1, '');
245
246if (GETPOST('error')) {
247 setEventMessages(GETPOST('error'), null, 'errors');
248}
249
250if ($mode == 'setup' && $user->admin) {
251 print '<span class="opacitymedium">'.$langs->trans("OAuthSetupForLogin")."</span><br><br>\n";
252
253 // Define $listinsetup
254 $listinsetup = array();
255 foreach ($conf->global as $key => $val) {
256 if (!empty($val) && preg_match('/^OAUTH_.*_ID$/', $key)) {
257 $provider = preg_replace('/_ID$/', '', $key);
258 $listinsetup[] = array(
259 $provider.'_NAME',
260 $provider.'_ID',
261 $provider.'_SECRET',
262 $provider.'_URL', // For custom oauth links
263 $provider.'_SCOPE' // For custom oauth links
264 );
265 }
266 }
267
268 $oauthstateanticsrf = bin2hex(random_bytes(128 / 8));
269
270 // $list is defined into oauth.lib.php to the list of supported OAuth providers.
271 if (!empty($listinsetup)) {
272 foreach ($listinsetup as $key) {
273 $supported = 0;
274 $keyforsupportedoauth2array = $key[0]; // May be OAUTH_GOOGLE_NAME or OAUTH_GOOGLE_xxx_NAME
275 $keyforsupportedoauth2array = preg_replace('/^OAUTH_/', '', $keyforsupportedoauth2array);
276 $keyforsupportedoauth2array = preg_replace('/_NAME$/', '', $keyforsupportedoauth2array);
277 if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
278 $keybeforeprovider = preg_replace('/-.*$/', '', $keyforsupportedoauth2array);
279 $keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
280 } else {
281 $keybeforeprovider = $keyforsupportedoauth2array;
282 $keyforprovider = '';
283 }
284 $keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
285 $keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
286
287 $nameofservice = ucfirst(strtolower(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']));
288 $nameofservice .= ($keyforprovider ? '-'.$keyforprovider : '');
289 $OAUTH_SERVICENAME = $nameofservice;
290
291 $keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
292
293 $shortscope = '';
294 if (getDolGlobalString($key[4])) {
295 $shortscope = getDolGlobalString($key[4]);
296 }
297 $state = $shortscope; // TODO USe a better state
298
299 $urltorefresh = $_SERVER["PHP_SELF"].'?action=refreshtoken&token='.newToken();
300
301 // Define $urltorenew, $urltodelete, $urltocheckperms
302 if ($keyforsupportedoauth2array == 'OAUTH_GITHUB_NAME') {
303 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
304 // We pass this param list in to 'state' because we need it before and after the redirect.
305
306 // Note: github does not accept csrf key inside the state parameter (only known values)
307 $urltorenew = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($shortscope).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
308 $urltodelete = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
309 $urltocheckperms = 'https://github.com/settings/applications/';
310 } elseif ($keyforsupportedoauth2array == 'OAUTH_GOOGLE_NAME') {
311 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
312 // List of scopes for Google are here: https://developers.google.com/identity/protocols/oauth2/scopes
313 // We pass this key list into the param 'state' because we need it before and after the redirect.
314 $urltorenew = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'-'.$oauthstateanticsrf.'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
315 $urltodelete = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
316 $urltocheckperms = 'https://security.google.com/settings/security/permissions';
317 } elseif (!empty($supportedoauth2array[$keyforsupportedoauth2array]['returnurl'])) {
318 $urltorenew = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
319 $urltodelete = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
320 $urltocheckperms = '';
321 } else {
322 $urltorenew = '';
323 $urltodelete = '';
324 $urltocheckperms = '';
325 }
326
327 if ($urltorenew) {
328 $urltorenew .= '&keyforprovider='.urlencode($keyforprovider);
329 }
330 if ($urltorefresh) {
331 $urltorefresh .= '&keyforprovider='.urlencode($keyforprovider).'&service='.urlencode($OAUTH_SERVICENAME);
332 }
333 if ($urltodelete) {
334 $urltodelete .= '&keyforprovider='.urlencode($keyforprovider);
335 }
336
337 // Show value of token
338 $tokenobj = null;
339 // Token
340 require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
341 // Dolibarr storage
342 $storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
343 try {
344 // $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
345 print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n";
346 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
347 print '<!-- data stored into field token: '.$storage->token.' -->';
348 //print $tokenobj->getExtraParams()['id_token'].'<br>';
349 //print $tokenobj->getAccessToken().'<br>';
350 } catch (Exception $e) {
351 // Return an error if token not found
352 //print $e->getMessage();
353 }
354
355 // Set other properties
356 $refreshtoken = false;
357 $expiredat = '';
358
359 $expire = false;
360 // Is token expired or will token expire in the next 30 seconds
361 if (is_object($tokenobj)) {
362 // tokenobj uses time() @phan-suppress-next-line DolibarrForbiddenFunctionPlugin
363 $expire = ($tokenobj->getEndOfLife() !== $tokenobj::EOL_NEVER_EXPIRES && $tokenobj->getEndOfLife() !== $tokenobj::EOL_UNKNOWN && time() > ($tokenobj->getEndOfLife() - 30));
364 }
365 if ($key[1] != '' && $key[2] != '') {
366 if (is_object($tokenobj)) {
367 $refreshtoken = $tokenobj->getRefreshToken();
368
369 $endoflife = $tokenobj->getEndOfLife();
370 if ($endoflife == $tokenobj::EOL_NEVER_EXPIRES) {
371 $expiredat = $langs->trans("Never");
372 } elseif ($endoflife == $tokenobj::EOL_UNKNOWN) {
373 $expiredat = $langs->trans("Unknown");
374 } else {
375 $expiredat = dol_print_date($endoflife, "dayhour", 'tzuserrel');
376 }
377 }
378 }
379
380 $submit_enabled = 0;
381
382 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off" spellcheck="false">';
383 print '<input type="hidden" name="token" value="'.newToken().'">';
384 print '<input type="hidden" name="action" value="setconst">';
385 print '<input type="hidden" name="page_y" value="">';
386
387 print '<div class="div-table-responsive-no-min">';
388 print '<table class="noborder centpercent">'."\n";
389
390 // Api Name
391 $label = $langs->trans($keyforsupportedoauth2array);
392 print '<tr class="liste_titre">';
393 print '<th class="titlefieldcreate">';
394 print img_picto('', $supportedoauth2array[$keyforsupportedoauth2array]['picto'], 'class="pictofixedwidth"');
395 if ($label == $keyforsupportedoauth2array) {
396 print $supportedoauth2array[$keyforsupportedoauth2array]['name'];
397 } else {
398 print $label;
399 }
400 if ($keyforprovider) {
401 print ' (<b>'.$keyforprovider.'</b>)';
402 } else {
403 print ' (<b>'.$langs->trans("NoName").'</b>)';
404 }
405 print '</th>';
406 print '<th></th>';
407 print '<th></th>';
408 print "</tr>\n";
409
410 print '<tr class="oddeven">';
411 print '<td>';
412 //var_dump($key);
413 print $langs->trans("OAuthIDSecret").'</td>';
414 print '<td>';
415 print '<span class="opacitymedium">'.$langs->trans("SeePreviousTab").'</span>';
416 print '</td>';
417 print '<td>';
418 print '</td>';
419 print '</tr>'."\n";
420
421 // Scopes
422 print '<tr class="oddeven">';
423 print '<td>'.$langs->trans("Scopes").'</td>';
424 print '<td colspan="2">';
425 $currentscopes = getDolGlobalString($key[4]);
426 print $currentscopes;
427 print '</td></tr>';
428
429 print '<tr class="oddeven">';
430 print '<td>';
431 //var_dump($key);
432 print $langs->trans("IsTokenGenerated");
433 print '</td>';
434 print '<td>';
435 if ($keyforprovider != 'Login') {
436 if (is_object($tokenobj)) {
437 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));
438 } else {
439 print '<span class="opacitymedium">'.$langs->trans("NoAccessToken").'</span>';
440 }
441 } else {
442 print '<span class="opacitymedium">'.$langs->trans("TokenNotRequiredForOAuthLogin").'</span>';
443 }
444 print '</td>';
445 print '<td width="50%">';
446 if ($keyforprovider != 'Login') {
447 // Links to delete/checks token
448 if (is_object($tokenobj)) {
449 //test on $storage->hasAccessToken($OAUTH_SERVICENAME) ?
450 if ($urltodelete) {
451 print '<a class="button button-delete smallpaddingimp reposition marginright" href="'.$urltodelete.'">'.$langs->trans('DeleteAccess').'</a>';
452 } else {
453 print '<span class="opacitymedium marginright">'.$langs->trans('GoOnTokenProviderToDeleteToken').'</span>';
454 }
455 }
456 // Request remote token
457 if ($urltorenew) {
458 print '<a class="button smallpaddingimp reposition classfortooltip marginright" href="'.$urltorenew.'" title="'.dolPrintHTMLForAttribute($langs->trans('RequestAccess')).'">'.$langs->trans('GetAccess').'</a>';
459 }
460 // Request remote token
461 if ($urltorefresh && $refreshtoken) {
462 print '<a class="button smallpaddingimp reposition classfortooltip marginright" href="'.$urltorefresh.'" title="'.dolPrintHTMLForAttribute($langs->trans('RefreshTokenHelp')).'">'.$langs->trans('RefreshToken').'</a>';
463 }
464
465 // Check remote access
466 if ($urltocheckperms) {
467 print '<br>'.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': <a href="'.$urltocheckperms.'" target="_'.strtolower($OAUTH_SERVICENAME).'">'.$urltocheckperms.'</a>';
468 }
469 }
470 print '</td>';
471 print '</tr>';
472
473 if (is_object($tokenobj)) {
474 print '<tr class="oddeven">';
475 print '<td>';
476 //var_dump($key);
477 print $langs->trans("TokenRawValue").'</td>';
478 print '<td colspan="2">';
479 if (is_object($tokenobj)) {
480 print '<textarea class="quatrevingtpercent small" rows="'.ROWS_4.'">'.var_export($tokenobj, true).'</textarea><br>'."\n";
481 }
482 print '</td>';
483 print '</tr>'."\n";
484
485 print '<tr class="oddeven">';
486 print '<td>';
487 //var_dump($key);
488 print $langs->trans("AccessToken").'</td>';
489 print '<td colspan="2">';
490 $tokentoshow = $tokenobj->getAccessToken();
491 print '<span class="" title="'.dol_escape_htmltag($tokentoshow).'">'.showValueWithClipboardCPButton($tokentoshow, 1, dol_trunc($tokentoshow, 32)).'</span>';
492 //print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
493 //print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
494 //var_dump($tokenobj->getExtraParams());
495 /*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
496 print ''.join(',',$tokenobj->getExtraParams());
497 print '</textarea>';*/
498
499 print '<span class="opacitymedium"> &nbsp; - &nbsp; ';
500 print $langs->trans("ExpirationDate").': ';
501 print '</span>';
502 print $expiredat;
503
504 print $expire ? ' ('.$langs->trans("TokenExpired").')' : ' ('.$langs->trans("TokenNotExpired").')';
505
506 print '</td>';
507 print '</tr>'."\n";
508
509 // Token refresh
510 print '<tr class="oddeven">';
511 print '<td>';
512 //var_dump($key);
513 print $langs->trans("TOKEN_REFRESH");
514 print '</td>';
515 print '<td colspan="2">';
516 print '<span class="" title="'.dol_escape_htmltag($refreshtoken).'">'.showValueWithClipboardCPButton($refreshtoken, 1, dol_trunc($refreshtoken, 32)).'</span>';
517 print '</td>';
518 print '</tr>';
519 }
520
521 print '</table>';
522 print '</div>';
523
524 if (!empty($driver)) {
525 if ($submit_enabled) {
526 print $form->buttonsSaveCancel("Modify", '');
527 }
528 }
529
530 print '</form>';
531 print '<br>';
532 }
533 }
534}
535
536if ($mode == 'test' && $user->admin) {
537 print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
538
539 print '<div class="div-table-responsive-no-min">';
540 print '<table class="noborder centpercent">';
541 if (!empty($driver)) {
542 require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
543 $classname = 'printing_'.$driver;
544 $langs->load($driver);
545 $printer = new $classname($db);
546
547 '@phan-var-force PrintingDriver $printer';
548
549 //print '<pre>'.print_r($printer, true).'</pre>';
550 if (count($printer->getlistAvailablePrinters())) {
551 if ($printer->listAvailablePrinters() == 0) {
552 print $printer->resprint;
553 } else {
554 setEventMessages($printer->error, $printer->errors, 'errors');
555 }
556 } else {
557 print $langs->trans('PleaseConfigureDriverfromList');
558 }
559 }
560
561 print '</table>';
562 print '</div>';
563}
564
565if ($mode == 'userconf' && $user->admin) {
566 print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
567
568 print '<div class="div-table-responsive">';
569 print '<table class="noborder centpercent">';
570 print '<tr class="liste_titre">';
571 print '<th>'.$langs->trans("User").'</th>';
572 print '<th>'.$langs->trans("PrintModule").'</th>';
573 print '<th>'.$langs->trans("PrintDriver").'</th>';
574 print '<th>'.$langs->trans("Printer").'</th>';
575 print '<th>'.$langs->trans("PrinterLocation").'</th>';
576 print '<th>'.$langs->trans("PrinterId").'</th>';
577 print '<th>'.$langs->trans("NumberOfCopy").'</th>';
578 print '<th class="center">'.$langs->trans("Delete").'</th>';
579 print "</tr>\n";
580 $sql = "SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login";
581 $sql .= " FROM ".MAIN_DB_PREFIX."printing as p, ".MAIN_DB_PREFIX."user as u WHERE p.userid = u.rowid";
582 $resql = $db->query($sql);
583 while ($obj = $db->fetch_object($resql)) {
584 print '<tr class="oddeven">';
585 print '<td>'.$obj->login.'</td>';
586 print '<td>'.$obj->module.'</td>';
587 print '<td>'.$obj->driver.'</td>';
588 print '<td>'.$obj->printer_name.'</td>';
589 print '<td>'.$obj->printer_location.'</td>';
590 print '<td>'.$obj->printer_id.'</td>';
591 print '<td>'.$obj->copy.'</td>';
592 print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
593 print "</tr>\n";
594 }
595 print '</table>';
596 print '</div>';
597}
598
599print dol_get_fiche_end();
600
601// End of page
602llxFooter();
603$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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now 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, $nodefault=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_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.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
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.