dolibarr  16.0.1
printing.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-2015 Frederic France <frederic.france@free.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 require '../../main.inc.php';
26 
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
30 require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php';
31 use OAuth\Common\Storage\DoliStorage;
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('admin', 'printing', 'oauth'));
35 
36 $action = GETPOST('action', 'aZ09');
37 $mode = GETPOST('mode', 'alpha');
38 $value = GETPOST('value', 'alpha', 0, null, null, 1); // The value may be __google__docs so we force disable of replace
39 $varname = GETPOST('varname', 'alpha');
40 $driver = GETPOST('driver', 'alpha');
41 
42 if (!empty($driver)) {
43  $langs->load($driver);
44 }
45 
46 if (!$mode) {
47  $mode = 'config';
48 }
49 
50 $OAUTH_SERVICENAME_GOOGLE = 'Google';
51 
52 if (!$user->admin) {
54 }
55 
56 
57 /*
58  * Action
59  */
60 
61 if (($mode == 'test' || $mode == 'setup') && empty($driver)) {
62  setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
63  header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
64  exit;
65 }
66 
67 if ($action == 'setconst' && $user->admin) {
68  $error = 0;
69  $db->begin();
70  foreach ($_POST['setupdriver'] as $setupconst) {
71  //print '<pre>'.print_r($setupconst, true).'</pre>';
72  $result = dolibarr_set_const($db, $setupconst['varname'], $setupconst['value'], 'chaine', 0, '', $conf->entity);
73  if (!($result > 0)) {
74  $error++;
75  }
76  }
77 
78  if (!$error) {
79  $db->commit();
80  setEventMessages($langs->trans("SetupSaved"), null);
81  } else {
82  $db->rollback();
83  dol_print_error($db);
84  }
85  $action = '';
86 }
87 
88 if ($action == 'setvalue' && $user->admin) {
89  $db->begin();
90 
91  $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
92  if (!($result > 0)) {
93  $error++;
94  }
95 
96  if (!$error) {
97  $db->commit();
98  setEventMessages($langs->trans("SetupSaved"), null);
99  } else {
100  $db->rollback();
101  dol_print_error($db);
102  }
103  $action = '';
104 }
105 
106 
107 /*
108  * View
109  */
110 
111 $form = new Form($db);
112 
113 llxHeader('', $langs->trans("PrintingSetup"));
114 
115 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
116 print load_fiche_titre($langs->trans("PrintingSetup"), $linkback, 'title_setup');
117 
118 $head = printingAdminPrepareHead($mode);
119 
120 if ($mode == 'setup' && $user->admin) {
121  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off">';
122  print '<input type="hidden" name="token" value="'.newToken().'">';
123  print '<input type="hidden" name="action" value="setconst">';
124 
125  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
126 
127  print $langs->trans("PrintingDriverDesc".$driver)."<br><br>\n";
128 
129  print '<table class="noborder centpercent">'."\n";
130  print '<tr class="liste_titre">';
131  print '<th>'.$langs->trans("Parameters").'</th>';
132  print '<th>'.$langs->trans("Value").'</th>';
133  print '<th>&nbsp;</th>';
134  print "</tr>\n";
135  $submit_enabled = 0;
136 
137  if (!empty($driver)) {
138  if (!empty($conf->modules_parts['printing'])) {
139  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
140  } else {
141  $dirmodels = array('/core/modules/printing/');
142  }
143 
144  foreach ($dirmodels as $dir) {
145  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
146  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
147  break;
148  }
149  }
150  require_once $classfile;
151  $classname = 'printing_'.$driver;
152  $printer = new $classname($db);
153  $langs->load($printer::LANGFILE);
154 
155  $i = 0;
156  $submit_enabled = 0;
157  foreach ($printer->conf as $key) {
158  switch ($key['type']) {
159  case "text":
160  case "password":
161  print '<tr class="oddeven">';
162  print '<td'.($key['required'] ? ' class=required' : '').'>'.$langs->trans($key['varname']).'</td>';
163  print '<td><input size="32" type="'.(empty($key['type']) ? 'text' : $key['type']).'" name="setupdriver['.$i.'][value]" value="'.$conf->global->{$key['varname']}.'"';
164  print isset($key['moreattributes']) ? ' '.$key['moreattributes'] : '';
165  print '><input type="hidden" name="setupdriver['.$i.'][varname]" value="'.$key['varname'].'"></td>';
166  print '<td>&nbsp;'.($key['example'] != '' ? $langs->trans("Example").' : '.$key['example'] : '').'</td>';
167  print '</tr>'."\n";
168  break;
169  case "info": // Google Api setup or Google OAuth Token
170  print '<tr class="oddeven">';
171  print '<td'.($key['required'] ? ' class=required' : '').'>';
172  if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
173  print $langs->trans("IsTokenGenerated");
174  } else {
175  print $langs->trans($key['varname']);
176  }
177  print '</td>';
178  print '<td>'.$langs->trans($key['info']).'</td>';
179  print '<td>';
180  //var_dump($key);
181  if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
182  // Delete remote tokens
183  if (!empty($key['delete'])) {
184  print '<a class="button" href="'.$key['delete'].'">'.$langs->trans('DeleteAccess').'</a><br><br>';
185  }
186  // Request remote token
187  print '<a class="button" href="'.$key['renew'].'">'.$langs->trans('RequestAccess').'</a><br><br>';
188  // Check remote access
189  print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME_GOOGLE).': <a href="https://security.google.com/settings/security/permissions" target="_google">https://security.google.com/settings/security/permissions</a>';
190  }
191  print '</td>';
192  print '</tr>'."\n";
193  break;
194  case "submit":
195  if ($key['enabled']) {
196  $submit_enabled = 1;
197  }
198  break;
199  }
200  $i++;
201 
202  if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
203  // Token
204  print '<tr class="oddeven">';
205  print '<td>'.$langs->trans("Token").'</td>';
206  print '<td colspan="2">';
207  $tokenobj = null;
208  // Dolibarr storage
209  $storage = new DoliStorage($db, $conf);
210  try {
211  $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE);
212  } catch (Exception $e) {
213  // Return an error if token not found
214  }
215  if (is_object($tokenobj)) {
216  //var_dump($tokenobj);
217  print $tokenobj->getAccessToken().'<br>';
218  //print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
219  //print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
220  //var_dump($tokenobj->getExtraParams());
221  /*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
222  print ''.join(',',$tokenobj->getExtraParams());
223  print '</textarea>';*/
224  }
225  print '</td>';
226  print '</tr>'."\n";
227  }
228  }
229  } else {
230  print $langs->trans('PleaseSelectaDriverfromList');
231  }
232 
233  print '</table>';
234 
235  print dol_get_fiche_end();
236 
237  if (!empty($driver)) {
238  if ($submit_enabled) {
239  print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></div>';
240  }
241  }
242 
243  print '</form>';
244 }
245 if ($mode == 'config' && $user->admin) {
246  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
247 
248  print $langs->trans("PrintingDesc")."<br><br>\n";
249 
250  print '<table class="noborder centpercent">'."\n";
251 
252  print '<tr class="liste_titre">';
253  print '<th>'.$langs->trans("Description").'</th>';
254  print '<th class="center">'.$langs->trans("Active").'</th>';
255  print '<th class="center">'.$langs->trans("Setup").'</th>';
256  print '<th class="center">'.$langs->trans("TargetedPrinter").'</th>';
257  print "</tr>\n";
258 
259  $object = new PrintingDriver($db);
260  $result = $object->listDrivers($db, 10);
261 
262  if (!empty($conf->modules_parts['printing'])) {
263  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
264  } else {
265  $dirmodels = array('/core/modules/printing/');
266  }
267 
268  foreach ($result as $driver) {
269  foreach ($dirmodels as $dir) {
270  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
271  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
272  break;
273  }
274  }
275  require_once $classfile;
276  $classname = 'printing_'.$driver;
277  $printer = new $classname($db);
278  $langs->load($printer::LANGFILE);
279  //print '<pre>'.print_r($printer, true).'</pre>';
280 
281  print '<tr class="oddeven">';
282  print '<td>'.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).'</td>';
283  print '<td class="center">';
284  if (!empty($conf->use_javascript_ajax)) {
285  print ajax_constantonoff($printer->active);
286  } else {
287  if (empty($conf->global->{$printer->conf})) {
288  print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.urlencode($printer->active).'&value=1">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
289  } else {
290  print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.urlencode($printer->active).'&value=0">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
291  }
292  }
293  print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=setup&token='.newToken().'&driver='.urlencode($printer->name).'">'.img_picto('', 'setup').'</a></td>';
294  print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=test&token='.newToken().'&driver='.urlencode($printer->name).'">'.img_picto('', 'setup').'</a></td>';
295  print '</tr>'."\n";
296  }
297 
298  print '</table>';
299 
300  print dol_get_fiche_end();
301 }
302 
303 if ($mode == 'test' && $user->admin) {
304  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
305 
306  print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
307 
308  print '<table class="noborder centpercent">';
309  if (!empty($driver)) {
310  if (!empty($conf->modules_parts['printing'])) {
311  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
312  } else {
313  $dirmodels = array('/core/modules/printing/');
314  }
315 
316  foreach ($dirmodels as $dir) {
317  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
318  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
319  break;
320  }
321  }
322  require_once $classfile;
323  $classname = 'printing_'.$driver;
324  $langs->load($driver);
325  $printer = new $classname($db);
326  $langs->load($printer::LANGFILE);
327  //print '<pre>'.print_r($printer, true).'</pre>';
328  if (count($printer->getlistAvailablePrinters())) {
329  if ($printer->listAvailablePrinters() == 0) {
330  print $printer->resprint;
331  } else {
332  setEventMessages($printer->error, $printer->errors, 'errors');
333  }
334  } else {
335  print $langs->trans('PleaseConfigureDriverfromList');
336  }
337  } else {
338  print $langs->trans('PleaseSelectaDriverfromList');
339  }
340  print '</table>';
341 
342  print dol_get_fiche_end();
343 }
344 
345 if ($mode == 'userconf' && $user->admin) {
346  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
347 
348  print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
349 
350  print '<table class="noborder centpercent">';
351  print '<tr class="liste_titre">';
352  print '<th>'.$langs->trans("User").'</th>';
353  print '<th>'.$langs->trans("PrintModule").'</th>';
354  print '<th>'.$langs->trans("PrintDriver").'</th>';
355  print '<th>'.$langs->trans("Printer").'</th>';
356  print '<th>'.$langs->trans("PrinterLocation").'</th>';
357  print '<th>'.$langs->trans("PrinterId").'</th>';
358  print '<th>'.$langs->trans("NumberOfCopy").'</th>';
359  print '<th class="center">'.$langs->trans("Delete").'</th>';
360  print "</tr>\n";
361  $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';
362  $resql = $db->query($sql);
363  while ($row = $db->fetch_array($resql)) {
364  print '<tr class="oddeven">';
365  print '<td>'.$row['login'].'</td>';
366  print '<td>'.$row['module'].'</td>';
367  print '<td>'.$row['driver'].'</td>';
368  print '<td>'.$row['printer_name'].'</td>';
369  print '<td>'.$row['printer_location'].'</td>';
370  print '<td>'.$row['printer_id'].'</td>';
371  print '<td>'.$row['copy'].'</td>';
372  print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
373  print "</tr>\n";
374  }
375  print '</table>';
376 
377  print dol_get_fiche_end();
378 }
379 
380 // End of page
381 llxFooter();
382 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
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).
Definition: admin.lib.php:627
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Parent class of emailing target selectors modules.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
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 ...
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
printingAdminPrepareHead($mode)
Define head array for tabs of printing tools setup pages.
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 &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix= '', $mode= '')
On/off button for constant.
Definition: ajax.lib.php:564
llxFooter()
Empty footer.
Definition: wrapper.php:73