* 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 */ 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; $langs->load("admin"); $langs->load("printing"); $langs->load("oauth"); if (! $user->admin) accessforbidden(); $action = GETPOST('action','alpha'); $mode = GETPOST('mode','alpha'); $value = GETPOST('value','alpha'); $varname = GETPOST('varname', 'alpha'); $driver = GETPOST('driver', 'alpha'); if (! empty($driver)) $langs->load($driver); if (!$mode) $mode='config'; $OAUTH_SERVICENAME_GOOGLE = 'Google'; /* * 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=printingadmin_prepare_head($mode); if ($mode == 'setup' && $user->admin) { print '
'; print ''; print ''; dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); print $langs->trans("PrintingDriverDesc".$driver)."

\n"; print ''."\n"; $var=true; print ''; print ''; print ''; print ''; print "\n"; $submit_enabled=0; if (! empty($driver)) { require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; $classname = 'printing_'.$driver; $langs->load($driver); $printer = new $classname($db); $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 "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') { // 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']:'').'
'.$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); 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 '
'; dol_fiche_end(); if (! empty($driver)) { if ($submit_enabled) { print '
'; } } print '
'; } if ($mode == 'config' && $user->admin) { dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); print $langs->trans("PrintingDesc")."

\n"; print ''."\n"; $var=true; print ''; print ''; print ''; print ''; print ''; print "\n"; $object = new PrintingDriver($db); $result = $object->listDrivers($db, 10); foreach ($result as $driver) { require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; $classname = 'printing_'.$driver; $langs->load($driver); $printer = new $classname($db); //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 (empty($conf->global->{$printer->conf})) { print ''.img_picto($langs->trans("Disabled"),'off').''; } else { print ''.img_picto($langs->trans("Enabled"),'on').''; } } print ''.img_picto('', 'setup').''.img_picto('', 'setup').'
'; dol_fiche_end(); } if ($mode == 'test' && $user->admin) { dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); print $langs->trans('PrintTestDesc'.$driver)."

\n"; print ''; if (! empty($driver)) { require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; $classname = 'printing_'.$driver; $langs->load($driver); $printer = new $classname($db); //print '
'.print_r($printer, true).'
'; if (count($printer->getlist_available_printers())) { 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 '
'; dol_fiche_end(); } if ($mode == 'userconf' && $user->admin) { dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); print $langs->trans('PrintUserConfDesc'.$driver)."

\n"; print ''; $var=true; 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').'
'; dol_fiche_end(); } llxFooter(); $db->close();