dolibarr 21.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 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
38// Load translation files required by the page
39$langs->loadLangs(array('admin', 'printing', 'oauth'));
40
41$action = GETPOST('action', 'aZ09');
42$mode = GETPOST('mode', 'alpha');
43$value = GETPOST('value', 'alpha');
44$varname = GETPOST('varname', 'alpha');
45$driver = GETPOST('driver', 'alpha');
46
47if (!empty($driver)) {
48 $langs->load($driver);
49}
50
51if (!$mode) {
52 $mode = 'setup';
53}
54
55if (!$user->admin) {
57}
58
59
60/*
61 * Action
62 */
63
64/*if (($mode == 'test' || $mode == 'setup') && empty($driver))
65{
66 setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
67 header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
68 exit;
69}*/
70
71if ($action == 'setconst' && $user->admin) {
72 $error = 0;
73 $db->begin();
74
75 $setupconstarray = GETPOST('setupdriver', 'array');
76
77 foreach ($setupconstarray as $setupconst) {
78 //print '<pre>'.print_r($setupconst, true).'</pre>';
79
80 $constname = dol_escape_htmltag($setupconst['varname']);
81 $constvalue = dol_escape_htmltag($setupconst['value']);
82 $consttype = dol_escape_htmltag($setupconst['type']);
83 $constnote = dol_escape_htmltag($setupconst['note']);
84
85 $result = dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
86 if (!($result > 0)) {
87 $error++;
88 }
89 }
90
91 if (!$error) {
92 $db->commit();
93 setEventMessages($langs->trans("SetupSaved"), null);
94 } else {
95 $db->rollback();
96 dol_print_error($db);
97 }
98 $action = '';
99}
100
101if ($action == 'setvalue' && $user->admin) {
102 $db->begin();
103
104 $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
105 if (!($result > 0)) {
106 $error++;
107 }
108
109 if (!$error) {
110 $db->commit();
111 setEventMessages($langs->trans("SetupSaved"), null);
112 } else {
113 $db->rollback();
114 dol_print_error($db);
115 }
116 $action = '';
117}
118
119// Test a refresh of a token using the refresh token
120if ($action == 'refreshtoken' && $user->admin) {
121 $keyforprovider = GETPOST('keyforprovider');
122 $OAUTH_SERVICENAME = GETPOST('service');
123
124 // Show value of token
125 $tokenobj = null;
126 // Load OAUth libraries
127 require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
128
129 $keyforsupportedoauth2array = $OAUTH_SERVICENAME;
130 if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
131 $keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
132 } else {
133 $keyforprovider = '';
134 }
135 $keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
136 $keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
137
138 $keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
139
140 // Dolibarr storage
141 $storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
142 try {
143 // $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
144 print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n";
145
146 dol_syslog("oauthlogintokens.php: Read token for service ".$OAUTH_SERVICENAME);
147 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
148
149 $expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30));
150 // We have to save the refresh token in a memory variable because Google give it only once
151 $refreshtoken = $tokenobj->getRefreshToken();
152 print '<!-- data stored into field token: '.$storage->token.' - expire '.((string) $expire).' -->';
153
154 //print $tokenobj->getExtraParams()['id_token'].'<br>';
155 //print $tokenobj->getAccessToken().'<br>';
156 //print $tokenobj->getRefreshToken().'<br>';
157
158 //var_dump($expire);
159
160 // We do the refresh even if not expired, this is the goal of action.
161 $oauthname = explode('-', $OAUTH_SERVICENAME);
162 $keyforoauthservice = strtoupper($oauthname[0]).(empty($oauthname[1]) ? '' : '-'.$oauthname[1]);
163 $credentials = new Credentials(
164 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_ID'),
165 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_SECRET'),
166 getDolGlobalString('OAUTH_'.$keyforoauthservice.'_URLCALLBACK')
167 );
168
169 $serviceFactory = new \OAuth\ServiceFactory();
170 $httpClient = new \OAuth\Common\Http\Client\CurlClient();
171 // TODO Set options for proxy and timeout
172 // $params=array('CURLXXX'=>value, ...)
173 //$httpClient->setCurlParameters($params);
174 $serviceFactory->setHttpClient($httpClient);
175
176 $scopes = array();
177 if (preg_match('/^Microsoft/', $OAUTH_SERVICENAME)) {
178 //$extraparams = $tokenobj->getExtraParams();
179 $tmp = explode('-', $OAUTH_SERVICENAME);
180 $scopes = explode(',', getDolGlobalString('OAUTH_'.strtoupper($tmp[0]).(empty($tmp[1]) ? '' : '-'.$tmp[1]).'_SCOPE'));
181 }
182
183 // ex service is Google-Emails we need only the first part Google
184 $apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, $scopes);
185
186 if ($apiService instanceof OAuth\OAuth2\Service\AbstractService || $apiService instanceof OAuth\OAuth1\Service\AbstractService) {
187 // ServiceInterface does not provide refreshAccessToekn, AbstractService does
188 dol_syslog("oauthlogintokens.php: call refreshAccessToken to get the new access token");
189 $tokenobj = $apiService->refreshAccessToken($tokenobj); // This call refresh and store the new token (but does not include the refresh token)
190
191 dol_syslog("oauthlogintokens.php: call setRefreshToken");
192 $tokenobj->setRefreshToken($refreshtoken); // Restore the refresh token
193
194 dol_syslog("oauthlogintokens.php: call storeAccessToken to save the new access token + the old refresh token");
195 $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj); // This save the new token including the refresh token
196
197 if ($expire) {
198 setEventMessages($langs->trans("OldTokenWasExpiredItHasBeenRefresh"), null, 'mesgs');
199 } else {
200 setEventMessages($langs->trans("OldTokenWasNotExpiredButItHasBeenRefresh"), null, 'mesgs');
201 }
202 } else {
203 dol_print_error($db, 'apiService is not a correct OAUTH2 Abstract service');
204 }
205
206 dol_syslog("oauthlogintokens.php: Read token again for service ".$OAUTH_SERVICENAME);
207 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
208 } catch (Exception $e) {
209 // Return an error if token not found
210 print $e->getMessage();
211 }
212}
213
214
215/*
216 * View
217 */
218
219// Define $urlwithroot
220$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
221$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
222//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
223
224$form = new Form($db);
225
226$title = $langs->trans("TokenManager");
227$help_url = 'EN:Module_OAuth|FR:Module_OAuth_FR|ES:Módulo_OAuth_ES';
228
229llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-oauthlogintokens');
230
231$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
232print load_fiche_titre($langs->trans('ConfigOAuth'), $linkback, 'title_setup');
233
235
236print dol_get_fiche_head($head, 'tokengeneration', '', -1, '');
237
238if (GETPOST('error')) {
239 setEventMessages(GETPOST('error'), null, 'errors');
240}
241
242if ($mode == 'setup' && $user->admin) {
243 print '<span class="opacitymedium">'.$langs->trans("OAuthSetupForLogin")."</span><br><br>\n";
244
245 // Define $listinsetup
246 $listinsetup = array();
247 foreach ($conf->global as $key => $val) {
248 if (!empty($val) && preg_match('/^OAUTH_.*_ID$/', $key)) {
249 $provider = preg_replace('/_ID$/', '', $key);
250 $listinsetup[] = array(
251 $provider.'_NAME',
252 $provider.'_ID',
253 $provider.'_SECRET',
254 $provider.'_URL', // For custom oauth links
255 $provider.'_SCOPE' // For custom oauth links
256 );
257 }
258 }
259
260 $oauthstateanticsrf = bin2hex(random_bytes(128 / 8));
261
262 // $list is defined into oauth.lib.php to the list of supported OAuth providers.
263 if (!empty($listinsetup)) {
264 foreach ($listinsetup as $key) {
265 $supported = 0;
266 $keyforsupportedoauth2array = $key[0]; // May be OAUTH_GOOGLE_NAME or OAUTH_GOOGLE_xxx_NAME
267 $keyforsupportedoauth2array = preg_replace('/^OAUTH_/', '', $keyforsupportedoauth2array);
268 $keyforsupportedoauth2array = preg_replace('/_NAME$/', '', $keyforsupportedoauth2array);
269 if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
270 $keybeforeprovider = preg_replace('/-.*$/', '', $keyforsupportedoauth2array);
271 $keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
272 } else {
273 $keybeforeprovider = $keyforsupportedoauth2array;
274 $keyforprovider = '';
275 }
276 $keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
277 $keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
278
279 $nameofservice = ucfirst(strtolower(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']));
280 $nameofservice .= ($keyforprovider ? '-'.$keyforprovider : '');
281 $OAUTH_SERVICENAME = $nameofservice;
282
283 $keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
284
285 $shortscope = '';
286 if (getDolGlobalString($key[4])) {
287 $shortscope = getDolGlobalString($key[4]);
288 }
289 $state = $shortscope; // TODO USe a better state
290
291 $urltorefresh = $_SERVER["PHP_SELF"].'?action=refreshtoken&token='.newToken();
292
293 // Define $urltorenew, $urltodelete, $urltocheckperms
294 if ($keyforsupportedoauth2array == 'OAUTH_GITHUB_NAME') {
295 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
296 // We pass this param list in to 'state' because we need it before and after the redirect.
297
298 // Note: github does not accept csrf key inside the state parameter (only known values)
299 $urltorenew = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($shortscope).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
300 $urltodelete = $urlwithroot.'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
301 $urltocheckperms = 'https://github.com/settings/applications/';
302 } elseif ($keyforsupportedoauth2array == 'OAUTH_GOOGLE_NAME') {
303 // List of keys that will be converted into scopes (from constants 'SCOPE_state_in_uppercase' in file of service).
304 // List of scopes for Google are here: https://developers.google.com/identity/protocols/oauth2/scopes
305 // We pass this key list into the param 'state' because we need it before and after the redirect.
306 $urltorenew = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'-'.$oauthstateanticsrf.'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
307 $urltodelete = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
308 $urltocheckperms = 'https://security.google.com/settings/security/permissions';
309 } elseif (!empty($supportedoauth2array[$keyforsupportedoauth2array]['returnurl'])) {
310 $urltorenew = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?shortscope='.urlencode($shortscope).'&state='.urlencode($state).'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
311 $urltodelete = $urlwithroot.$supportedoauth2array[$keyforsupportedoauth2array]['returnurl'].'?action=delete&token='.newToken().'&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
312 $urltocheckperms = '';
313 } else {
314 $urltorenew = '';
315 $urltodelete = '';
316 $urltocheckperms = '';
317 }
318
319 if ($urltorenew) {
320 $urltorenew .= '&keyforprovider='.urlencode($keyforprovider);
321 }
322 if ($urltorefresh) {
323 $urltorefresh .= '&keyforprovider='.urlencode($keyforprovider).'&service='.urlencode($OAUTH_SERVICENAME);
324 }
325 if ($urltodelete) {
326 $urltodelete .= '&keyforprovider='.urlencode($keyforprovider);
327 }
328
329 // Show value of token
330 $tokenobj = null;
331 // Token
332 require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
333 // Dolibarr storage
334 $storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
335 try {
336 // $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
337 print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n";
338 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
339 print '<!-- data stored into field token: '.$storage->token.' -->';
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 button-delete smallpaddingimp reposition marginright" href="'.$urltodelete.'">'.$langs->trans('DeleteAccess').'</a>';
443 } else {
444 print '<span class="opacitymedium marginright">'.$langs->trans('GoOnTokenProviderToDeleteToken').'</span>';
445 }
446 }
447 // Request remote token
448 if ($urltorenew) {
449 print '<a class="button smallpaddingimp reposition classfortooltip marginright" href="'.$urltorenew.'" title="'.dolPrintHTMLForAttribute($langs->trans('RequestAccess')).'">'.$langs->trans('GetAccess').'</a>';
450 }
451 // Request remote token
452 if ($urltorefresh && $refreshtoken) {
453 print '<a class="button smallpaddingimp reposition classfortooltip marginright" href="'.$urltorefresh.'" title="'.dolPrintHTMLForAttribute($langs->trans('RefreshTokenHelp')).'">'.$langs->trans('RefreshToken').'</a>';
454 }
455
456 // Check remote access
457 if ($urltocheckperms) {
458 print '<br>'.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': <a href="'.$urltocheckperms.'" target="_'.strtolower($OAUTH_SERVICENAME).'">'.$urltocheckperms.'</a>';
459 }
460 }
461 print '</td>';
462 print '</tr>';
463
464 if (is_object($tokenobj)) {
465 print '<tr class="oddeven">';
466 print '<td>';
467 //var_dump($key);
468 print $langs->trans("TokenRawValue").'</td>';
469 print '<td colspan="2">';
470 if (is_object($tokenobj)) {
471 print '<textarea class="quatrevingtpercent small" rows="'.ROWS_4.'">'.var_export($tokenobj, true).'</textarea><br>'."\n";
472 }
473 print '</td>';
474 print '</tr>'."\n";
475
476 print '<tr class="oddeven">';
477 print '<td>';
478 //var_dump($key);
479 print $langs->trans("AccessToken").'</td>';
480 print '<td colspan="2">';
481 $tokentoshow = $tokenobj->getAccessToken();
482 print '<span class="" title="'.dol_escape_htmltag($tokentoshow).'">'.showValueWithClipboardCPButton($tokentoshow, 1, dol_trunc($tokentoshow, 32)).'</span>';
483 //print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
484 //print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
485 //var_dump($tokenobj->getExtraParams());
486 /*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
487 print ''.join(',',$tokenobj->getExtraParams());
488 print '</textarea>';*/
489
490 print '<span class="opacitymedium"> &nbsp; - &nbsp; ';
491 print $langs->trans("ExpirationDate").': ';
492 print '</span>';
493 print $expiredat;
494
495 print $expire ? ' ('.$langs->trans("TokenExpired").')' : ' ('.$langs->trans("TokenNotExpired").')';
496
497 print '</td>';
498 print '</tr>'."\n";
499
500 // Token refresh
501 print '<tr class="oddeven">';
502 print '<td>';
503 //var_dump($key);
504 print $langs->trans("TOKEN_REFRESH");
505 print '</td>';
506 print '<td colspan="2">';
507 print '<span class="" title="'.dol_escape_htmltag($refreshtoken).'">'.showValueWithClipboardCPButton($refreshtoken, 1, dol_trunc($refreshtoken, 32)).'</span>';
508 print '</td>';
509 print '</tr>';
510 }
511
512 print '</table>';
513 print '</div>';
514
515 if (!empty($driver)) {
516 if ($submit_enabled) {
517 print $form->buttonsSaveCancel("Modify", '');
518 }
519 }
520
521 print '</form>';
522 print '<br>';
523 }
524 }
525}
526
527if ($mode == 'test' && $user->admin) {
528 print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
529
530 print '<div class="div-table-responsive-no-min">';
531 print '<table class="noborder centpercent">';
532 if (!empty($driver)) {
533 require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
534 $classname = 'printing_'.$driver;
535 $langs->load($driver);
536 $printer = new $classname($db);
537
538 '@phan-var-force PrintingDriver $printer';
539
540 //print '<pre>'.print_r($printer, true).'</pre>';
541 if (count($printer->getlistAvailablePrinters())) {
542 if ($printer->listAvailablePrinters() == 0) {
543 print $printer->resprint;
544 } else {
545 setEventMessages($printer->error, $printer->errors, 'errors');
546 }
547 } else {
548 print $langs->trans('PleaseConfigureDriverfromList');
549 }
550 }
551
552 print '</table>';
553 print '</div>';
554}
555
556if ($mode == 'userconf' && $user->admin) {
557 print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
558
559 print '<div class="div-table-responsive">';
560 print '<table class="noborder centpercent">';
561 print '<tr class="liste_titre">';
562 print '<th>'.$langs->trans("User").'</th>';
563 print '<th>'.$langs->trans("PrintModule").'</th>';
564 print '<th>'.$langs->trans("PrintDriver").'</th>';
565 print '<th>'.$langs->trans("Printer").'</th>';
566 print '<th>'.$langs->trans("PrinterLocation").'</th>';
567 print '<th>'.$langs->trans("PrinterId").'</th>';
568 print '<th>'.$langs->trans("NumberOfCopy").'</th>';
569 print '<th class="center">'.$langs->trans("Delete").'</th>';
570 print "</tr>\n";
571 $sql = "SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login";
572 $sql .= " FROM ".MAIN_DB_PREFIX."printing as p, ".MAIN_DB_PREFIX."user as u WHERE p.userid = u.rowid";
573 $resql = $db->query($sql);
574 while ($obj = $db->fetch_object($resql)) {
575 print '<tr class="oddeven">';
576 print '<td>'.$obj->login.'</td>';
577 print '<td>'.$obj->module.'</td>';
578 print '<td>'.$obj->driver.'</td>';
579 print '<td>'.$obj->printer_name.'</td>';
580 print '<td>'.$obj->printer_location.'</td>';
581 print '<td>'.$obj->printer_id.'</td>';
582 print '<td>'.$obj->copy.'</td>';
583 print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
584 print "</tr>\n";
585 }
586 print '</table>';
587 print '</div>';
588}
589
590print dol_get_fiche_end();
591
592// End of page
593llxFooter();
594$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
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)
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'.
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_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 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 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.