26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/oauth.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
30 use OAuth\Common\Storage\DoliStorage;
33 $langs->loadLangs(array(
'admin',
'printing',
'oauth'));
37 $action =
GETPOST(
'action',
'aZ09');
38 $mode =
GETPOST(
'mode',
'alpha');
39 $value =
GETPOST(
'value',
'alpha');
40 $varname =
GETPOST(
'varname',
'alpha');
41 $driver =
GETPOST(
'driver',
'alpha');
43 if (!empty($driver)) $langs->load($driver);
45 if (!$mode) $mode =
'setup';
59 if ($action ==
'setconst' && $user->admin)
64 $setupconstarray =
GETPOST(
'setupdriver',
'array');
66 foreach ($setupconstarray as $setupconst) {
74 $result =
dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
75 if (!$result > 0) $error++;
89 if ($action ==
'setvalue' && $user->admin)
94 if (!$result > 0) $error++;
113 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
114 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
117 $form =
new Form($db);
119 llxHeader(
'', $langs->trans(
"PrintingSetup"));
121 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
132 if ($mode ==
'setup' && $user->admin)
134 print '<span class="opacitymedium">'.$langs->trans(
"OAuthSetupForLogin").
"</span><br><br>\n";
136 foreach ($list as $key)
139 if (in_array($key[0], array_keys($supportedoauth2array))) $supported = 1;
140 if (!$supported)
continue;
143 $OAUTH_SERVICENAME =
'Unknown';
144 if ($key[0] ==
'OAUTH_GITHUB_NAME')
146 $OAUTH_SERVICENAME =
'GitHub';
149 $shortscope =
'user,public_repo';
150 $urltorenew = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?shortscope='.$shortscope.
'&state='.$shortscope.
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
151 $urltodelete = $urlwithroot.
'/core/modules/oauth/github_oauthcallback.php?action=delete&token='.
newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
152 $urltocheckperms =
'https://github.com/settings/applications/';
153 } elseif ($key[0] ==
'OAUTH_GOOGLE_NAME')
155 $OAUTH_SERVICENAME =
'Google';
158 $shortscope =
'userinfo_email,userinfo_profile,cloud_print';
159 if (!empty($conf->global->OAUTH_GSUITE)) {
160 $shortscope .=
',admin_directory_user';
163 $urltorenew = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?shortscope='.$shortscope.
'&state='.$shortscope.
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
164 $urltodelete = $urlwithroot.
'/core/modules/oauth/google_oauthcallback.php?action=delete&token='.
newToken().
'&backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
165 $urltocheckperms =
'https://security.google.com/settings/security/permissions';
166 } elseif ($key[0] ==
'OAUTH_STRIPE_TEST_NAME')
168 $OAUTH_SERVICENAME =
'StripeTest';
169 $urltorenew = $urlwithroot.
'/core/modules/oauth/stripetest_oauthcallback.php?backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
171 $urltocheckperms =
'';
172 } elseif ($key[0] ==
'OAUTH_STRIPE_LIVE_NAME')
174 $OAUTH_SERVICENAME =
'StripeLive';
175 $urltorenew = $urlwithroot.
'/core/modules/oauth/stripelive_oauthcallback.php?backtourl='.urlencode(DOL_URL_ROOT.
'/admin/oauthlogintokens.php');
177 $urltocheckperms =
'';
181 $urltocheckperms =
'';
188 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
189 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
191 $storage =
new DoliStorage($db, $conf);
193 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
200 $refreshtoken =
false;
205 if (is_object($tokenobj)) {
206 $expire = ($tokenobj->getEndOfLife() !== $tokenobj::EOL_NEVER_EXPIRES && $tokenobj->getEndOfLife() !== $tokenobj::EOL_UNKNOWN && time() > ($tokenobj->getEndOfLife() - 30));
209 if ($key[1] !=
'' && $key[2] !=
'') {
210 if (is_object($tokenobj)) {
211 $refreshtoken = $tokenobj->getRefreshToken();
213 $endoflife = $tokenobj->getEndOfLife();
214 if ($endoflife == $tokenobj::EOL_NEVER_EXPIRES)
216 $expiredat = $langs->trans(
"Never");
217 } elseif ($endoflife == $tokenobj::EOL_UNKNOWN)
219 $expiredat = $langs->trans(
"Unknown");
228 print '<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?mode=setup&driver='.$driver.
'" autocomplete="off">';
229 print '<input type="hidden" name="token" value="'.newToken().
'">';
230 print '<input type="hidden" name="action" value="setconst">';
233 print '<table class="noborder centpercent">'.
"\n";
235 print '<tr class="liste_titre">';
236 print '<th class="titlefieldcreate">'.$langs->trans($key[0]).
'</th>';
241 print '<tr class="oddeven">';
242 print '<td'.($key[
'required'] ?
' class="required"' :
'').
'>';
244 print $langs->trans(
"OAuthIDSecret").
'</td>';
246 print $langs->trans(
"SeePreviousTab");
252 print '<tr class="oddeven">';
253 print '<td'.($key[
'required'] ?
' class="required"' :
'').
'>';
255 print $langs->trans(
"IsTokenGenerated");
258 if (is_object($tokenobj))
print $langs->trans(
"HasAccessToken");
259 else print $langs->trans(
"NoAccessToken");
263 if (is_object($tokenobj))
266 print '<a class="button" href="'.$urltodelete.
'">'.$langs->trans(
'DeleteAccess').
'</a><br>';
271 print '<a class="button" href="'.$urltorenew.
'">'.$langs->trans(
'RequestAccess').
'</a><br>';
274 if ($urltocheckperms)
276 print '<br>'.$langs->trans(
"ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).
': <a href="'.$urltocheckperms.
'" target="_'.strtolower($OAUTH_SERVICENAME).
'">'.$urltocheckperms.
'</a>';
281 print '<tr class="oddeven">';
282 print '<td'.($key[
'required'] ?
' class="required"' :
'').
'>';
284 print $langs->trans(
"Token").
'</td>';
285 print '<td colspan="2">';
286 if (is_object($tokenobj))
289 print $tokenobj->getAccessToken().
'<br>';
300 if (is_object($tokenobj))
303 print '<tr class="oddeven">';
304 print '<td'.($key[
'required'] ?
' class="required"' :
'').
'>';
306 print $langs->trans(
"TOKEN_REFRESH").
'</td>';
307 print '<td colspan="2">';
313 print '<tr class="oddeven">';
314 print '<td'.($key[
'required'] ?
' class="required"' :
'').
'>';
316 print $langs->trans(
"TOKEN_EXPIRED").
'</td>';
317 print '<td colspan="2">';
323 print '<tr class="oddeven">';
324 print '<td'.($key[
'required'] ?
' class="required"' :
'').
'>';
326 print $langs->trans(
"TOKEN_EXPIRE_AT").
'</td>';
327 print '<td colspan="2">';
337 if ($submit_enabled) {
338 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans(
"Modify")).
'"></div>';
347 if ($mode ==
'test' && $user->admin)
349 print $langs->trans(
'PrintTestDesc'.$driver).
"<br><br>\n";
351 print '<table class="noborder centpercent">';
354 require_once DOL_DOCUMENT_ROOT.
'/core/modules/printing/'.$driver.
'.modules.php';
355 $classname =
'printing_'.$driver;
356 $langs->load($driver);
357 $printer =
new $classname($db);
359 if (count($printer->getlistAvailablePrinters())) {
360 if ($printer->listAvailablePrinters() == 0) {
361 print $printer->resprint;
366 print $langs->trans(
'PleaseConfigureDriverfromList');
373 if ($mode ==
'userconf' && $user->admin)
375 print $langs->trans(
'PrintUserConfDesc'.$driver).
"<br><br>\n";
377 print '<table class="noborder centpercent">';
378 print '<tr class="liste_titre">';
379 print '<th>'.$langs->trans(
"User").
'</th>';
380 print '<th>'.$langs->trans(
"PrintModule").
'</th>';
381 print '<th>'.$langs->trans(
"PrintDriver").
'</th>';
382 print '<th>'.$langs->trans(
"Printer").
'</th>';
383 print '<th>'.$langs->trans(
"PrinterLocation").
'</th>';
384 print '<th>'.$langs->trans(
"PrinterId").
'</th>';
385 print '<th>'.$langs->trans(
"NumberOfCopy").
'</th>';
386 print '<th class="center">'.$langs->trans(
"Delete").
'</th>';
388 $sql =
'SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login FROM '.MAIN_DB_PREFIX.
'printing as p, '.MAIN_DB_PREFIX.
'user as u WHERE p.userid=u.rowid';
389 $resql = $db->query($sql);
390 while ($row = $db->fetch_array(
$resql)) {
391 print '<tr class="oddeven">';
392 print '<td>'.$row[
'login'].
'</td>';
393 print '<td>'.$row[
'module'].
'</td>';
394 print '<td>'.$row[
'driver'].
'</td>';
395 print '<td>'.$row[
'printer_name'].
'</td>';
396 print '<td>'.$row[
'printer_location'].
'</td>';
397 print '<td>'.$row[
'printer_id'].
'</td>';
398 print '<td>'.$row[
'copy'].
'</td>';
399 print '<td class="center">'.img_picto($langs->trans(
"Delete"),
'delete').
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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).
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...