code syntax printing directory

This commit is contained in:
Frédéric FRANCE 2021-02-26 15:26:09 +01:00
parent fa7cd70052
commit c5ff699b3f
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
2 changed files with 41 additions and 41 deletions

View File

@ -33,7 +33,9 @@ use OAuth\Common\Storage\DoliStorage;
// Load translation files required by the page
$langs->loadLangs(array('admin', 'printing', 'oauth'));
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
$mode = GETPOST('mode', 'alpha');
@ -41,9 +43,13 @@ $value = GETPOST('value', 'alpha', 0, null, null, 1); // The value may be __goog
$varname = GETPOST('varname', 'alpha');
$driver = GETPOST('driver', 'alpha');
if (!empty($driver)) $langs->load($driver);
if (!empty($driver)) {
$langs->load($driver);
}
if (!$mode) $mode = 'config';
if (!$mode) {
$mode = 'config';
}
$OAUTH_SERVICENAME_GOOGLE = 'Google';
@ -52,21 +58,21 @@ $OAUTH_SERVICENAME_GOOGLE = 'Google';
* Action
*/
if (($mode == 'test' || $mode == 'setup') && empty($driver))
{
if (($mode == 'test' || $mode == 'setup') && empty($driver)) {
setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
exit;
}
if ($action == 'setconst' && $user->admin)
{
if ($action == 'setconst' && $user->admin) {
$error = 0;
$db->begin();
foreach ($_POST['setupdriver'] as $setupconst) {
//print '<pre>'.print_r($setupconst, true).'</pre>';
$result = dolibarr_set_const($db, $setupconst['varname'], $setupconst['value'], 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
}
if (!$error) {
@ -79,12 +85,13 @@ if ($action == 'setconst' && $user->admin)
$action = '';
}
if ($action == 'setvalue' && $user->admin)
{
if ($action == 'setvalue' && $user->admin) {
$db->begin();
$result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
if (!$error) {
$db->commit();
@ -110,8 +117,7 @@ print load_fiche_titre($langs->trans("PrintingSetup"), $linkback, 'title_setup')
$head = printingAdminPrepareHead($mode);
if ($mode == 'setup' && $user->admin)
{
if ($mode == 'setup' && $user->admin) {
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setconst">';
@ -143,8 +149,7 @@ if ($mode == 'setup' && $user->admin)
$i = 0;
$submit_enabled = 0;
foreach ($printer->conf as $key)
{
foreach ($printer->conf as $key) {
switch ($key['type']) {
case "text":
case "password":
@ -159,8 +164,7 @@ if ($mode == 'setup' && $user->admin)
case "info": // Google Api setup or Google OAuth Token
print '<tr class="oddeven">';
print '<td'.($key['required'] ? ' class=required' : '').'>';
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
{
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
print $langs->trans("IsTokenGenerated");
} else {
print $langs->trans($key['varname']);
@ -169,10 +173,11 @@ if ($mode == 'setup' && $user->admin)
print '<td>'.$langs->trans($key['info']).'</td>';
print '<td>';
//var_dump($key);
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
{
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
// Delete remote tokens
if (!empty($key['delete'])) print '<a class="button" href="'.$key['delete'].'">'.$langs->trans('DeleteAccess').'</a><br><br>';
if (!empty($key['delete'])) {
print '<a class="button" href="'.$key['delete'].'">'.$langs->trans('DeleteAccess').'</a><br><br>';
}
// Request remote token
print '<a class="button" href="'.$key['renew'].'">'.$langs->trans('RequestAccess').'</a><br><br>';
// Check remote access
@ -182,13 +187,14 @@ if ($mode == 'setup' && $user->admin)
print '</tr>'."\n";
break;
case "submit":
if ($key['enabled']) $submit_enabled = 1;
if ($key['enabled']) {
$submit_enabled = 1;
}
break;
}
$i++;
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
{
if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
// Token
print '<tr class="oddeven">';
print '<td>'.$langs->trans("Token").'</td>';
@ -198,20 +204,18 @@ if ($mode == 'setup' && $user->admin)
$storage = new DoliStorage($db, $conf);
try {
$tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE);
} catch (Exception $e)
{
} catch (Exception $e) {
// Return an error if token not found
}
if (is_object($tokenobj))
{
if (is_object($tokenobj)) {
//var_dump($tokenobj);
print $tokenobj->getAccessToken().'<br>';
//print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
//print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
//var_dump($tokenobj->getExtraParams());
/*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
print ''.join(',',$tokenobj->getExtraParams());
print '</textarea>';*/
print ''.join(',',$tokenobj->getExtraParams());
print '</textarea>';*/
}
print '</td>';
print '</tr>'."\n";
@ -225,8 +229,7 @@ if ($mode == 'setup' && $user->admin)
print dol_get_fiche_end();
if (!empty($driver))
{
if (!empty($driver)) {
if ($submit_enabled) {
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></div>';
}
@ -234,8 +237,7 @@ if ($mode == 'setup' && $user->admin)
print '</form>';
}
if ($mode == 'config' && $user->admin)
{
if ($mode == 'config' && $user->admin) {
print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
print $langs->trans("PrintingDesc")."<br><br>\n";
@ -287,8 +289,7 @@ if ($mode == 'config' && $user->admin)
print dol_get_fiche_end();
}
if ($mode == 'test' && $user->admin)
{
if ($mode == 'test' && $user->admin) {
print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
@ -325,8 +326,7 @@ if ($mode == 'test' && $user->admin)
print dol_get_fiche_end();
}
if ($mode == 'userconf' && $user->admin)
{
if ($mode == 'userconf' && $user->admin) {
print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";

View File

@ -57,10 +57,10 @@ function printingAdminPrepareHead($mode)
}
/** TODO This feature seem to be not ready yet.
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=userconf";
$head[$h][1] = $langs->trans("UserConf");
$head[$h][2] = 'userconf';
$h++;
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=userconf";
$head[$h][1] = $langs->trans("UserConf");
$head[$h][2] = 'userconf';
$h++;
*/
//$object=new stdClass();