* Copyright (C) 2014-2015 Frederic France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/printing/admin/printing.php * \ingroup printing * \brief Page to setup printing module */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php'; require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php'; use OAuth\Common\Storage\DoliStorage; // Load translation files required by the page $langs->loadLangs(array('admin', 'printing', 'oauth')); $action = GETPOST('action', 'aZ09'); $mode = GETPOST('mode', 'alpha'); $value = GETPOST('value', 'alpha', 0, null, null, 1); // The value may be __google__docs so we force disable of replace $varname = GETPOST('varname', 'alpha'); $driver = GETPOST('driver', 'alpha'); if (!empty($driver)) { $langs->load($driver); } if (!$mode) { $mode = 'config'; } $OAUTH_SERVICENAME_GOOGLE = 'Google'; if (!$user->admin) { accessforbidden(); } /* * Action */ 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) { $error = 0; $db->begin(); foreach ($_POST['setupdriver'] as $setupconst) { //print '
'.print_r($setupconst, true).'
'; $result = dolibarr_set_const($db, $setupconst['varname'], $setupconst['value'], 'chaine', 0, '', $conf->entity); if (!($result > 0)) { $error++; } } if (!$error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null); } else { $db->rollback(); dol_print_error($db); } $action = ''; } if ($action == 'setvalue' && $user->admin) { $db->begin(); $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity); if (!($result > 0)) { $error++; } if (!$error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null); } else { $db->rollback(); dol_print_error($db); } $action = ''; } /* * View */ $form = new Form($db); llxHeader('', $langs->trans("PrintingSetup")); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("PrintingSetup"), $linkback, 'title_setup'); $head = printingAdminPrepareHead($mode); if ($mode == 'setup' && $user->admin) { print '
'; print ''; print ''; print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic'); print $langs->trans("PrintingDriverDesc".$driver)."

\n"; print ''."\n"; print ''; print ''; print ''; print ''; print "\n"; $submit_enabled = 0; if (!empty($driver)) { if (!empty($conf->modules_parts['printing'])) { $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); } else { $dirmodels = array('/core/modules/printing/'); } foreach ($dirmodels as $dir) { if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) { $classfile = dol_buildpath($dir, 0).$driver.'.modules.php'; break; } } require_once $classfile; $classname = 'printing_'.$driver; $printer = new $classname($db); $langs->load('printing'); $i = 0; $submit_enabled = 0; foreach ($printer->conf as $key) { switch ($key['type']) { case "text": case "password": print ''; print ''.$langs->trans($key['varname']).''; print ''; print ''; print ''."\n"; break; case "checkbox": print ''; print ''.$langs->trans($key['varname']).''; print ''; print ''; print ''."\n"; break; case "info": // Google Api setup or Google OAuth Token print ''; print ''; if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') { print $langs->trans("IsTokenGenerated"); } else { print $langs->trans($key['varname']); } print ''; print ''; print ''; print ''."\n"; break; case "submit": if ($key['enabled']) { $submit_enabled = 1; } break; } $i++; if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') { $keyforprovider = ''; // @BUG This must be set // Token print ''; print ''; print ''; print ''."\n"; } } } else { print $langs->trans('PleaseSelectaDriverfromList'); } print '
'.$langs->trans("Parameters").''.$langs->trans("Value").' 
 '.($key['example'] != '' ? $langs->trans("Example").' : '.$key['example'] : '').'
 '.($key['example'] != '' ? $langs->trans("Example").' : '.$key['example'] : '').'
'.$langs->trans($key['info']).''; //var_dump($key); if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') { // Delete remote tokens if (!empty($key['delete'])) { print ''.$langs->trans('DeleteAccess').'

'; } // Request remote token print ''.$langs->trans('RequestAccess').'

'; // Check remote access print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME_GOOGLE).': https://security.google.com/settings/security/permissions'; } print '
'.$langs->trans("Token").''; $tokenobj = null; // Dolibarr storage $storage = new DoliStorage($db, $conf, $keyforprovider); try { $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE); } catch (Exception $e) { // Return an error if token not found } if (is_object($tokenobj)) { //var_dump($tokenobj); print $tokenobj->getAccessToken().'
'; //print 'Refresh: '.$tokenobj->getRefreshToken().'
'; //print 'EndOfLife: '.$tokenobj->getEndOfLife().'
'; //var_dump($tokenobj->getExtraParams()); /*print '
Extra:
';*/ } print '
'; print dol_get_fiche_end(); if (!empty($driver)) { if ($submit_enabled) { print '
'; } } print '
'; } if ($mode == 'config' && $user->admin) { print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic'); print $langs->trans("PrintingDesc")."

\n"; print ''."\n"; print ''; print ''; print ''; print ''; print ''; print "\n"; $object = new PrintingDriver($db); $result = $object->listDrivers($db, 10); if (!empty($conf->modules_parts['printing'])) { $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); } else { $dirmodels = array('/core/modules/printing/'); } foreach ($result as $tmpdriver) { foreach ($dirmodels as $dir) { if (file_exists(dol_buildpath($dir, 0).$tmpdriver.'.modules.php')) { $classfile = dol_buildpath($dir, 0).$tmpdriver.'.modules.php'; break; } } require_once $classfile; $classname = 'printing_'.$tmpdriver; $printer = new $classname($db); $langs->load('printing'); //print '
'.print_r($printer, true).'
'; print ''; print ''; print ''; print ''; print ''."\n"; } print '
'.$langs->trans("Description").''.$langs->trans("Active").''.$langs->trans("Setup").''.$langs->trans("TargetedPrinter").'
'.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).''; if (!empty($conf->use_javascript_ajax)) { print ajax_constantonoff($printer->active); } else { if (!getDolGlobalString($printer->conf)) { print ''.img_picto($langs->trans("Disabled"), 'off').''; } else { print ''.img_picto($langs->trans("Enabled"), 'on').''; } } print ''.img_picto('', 'setup').''.img_picto('', 'setup').'
'; print dol_get_fiche_end(); } if ($mode == 'test' && $user->admin) { print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic'); print $langs->trans('PrintTestDesc'.$driver)."

\n"; print ''; if (!empty($driver)) { if (!empty($conf->modules_parts['printing'])) { $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); } else { $dirmodels = array('/core/modules/printing/'); } foreach ($dirmodels as $dir) { if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) { $classfile = dol_buildpath($dir, 0).$driver.'.modules.php'; break; } } require_once $classfile; $classname = 'printing_'.$driver; $printer = new $classname($db); $langs->load($driver); $langs->load('printing'); //print '
'.print_r($printer, true).'
'; if (count($printer->getlistAvailablePrinters())) { if ($printer->listAvailablePrinters() == 0) { print $printer->resprint; } else { setEventMessages($printer->error, $printer->errors, 'errors'); } } else { print $langs->trans('PleaseConfigureDriverfromList'); } } else { print $langs->trans('PleaseSelectaDriverfromList'); } print '
'; print dol_get_fiche_end(); } if ($mode == 'userconf' && $user->admin) { print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic'); print $langs->trans('PrintUserConfDesc'.$driver)."

\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $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'; $resql = $db->query($sql); while ($row = $db->fetch_array($resql)) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } print '
'.$langs->trans("User").''.$langs->trans("PrintModule").''.$langs->trans("PrintDriver").''.$langs->trans("Printer").''.$langs->trans("PrinterLocation").''.$langs->trans("PrinterId").''.$langs->trans("NumberOfCopy").''.$langs->trans("Delete").'
'.$row['login'].''.$row['module'].''.$row['driver'].''.$row['printer_name'].''.$row['printer_location'].''.$row['printer_id'].''.$row['copy'].''.img_picto($langs->trans("Delete"), 'delete').'
'; print dol_get_fiche_end(); } // End of page llxFooter(); $db->close();