dolibarr  13.0.2
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 if (!$user->admin) accessforbidden();
37 
38 $action = GETPOST('action', 'aZ09');
39 $mode = GETPOST('mode', 'alpha');
40 $value = GETPOST('value', 'alpha', 0, null, null, 1); // The value may be __google__docs so we force disable of replace
41 $varname = GETPOST('varname', 'alpha');
42 $driver = GETPOST('driver', 'alpha');
43 
44 if (!empty($driver)) $langs->load($driver);
45 
46 if (!$mode) $mode = 'config';
47 
48 $OAUTH_SERVICENAME_GOOGLE = 'Google';
49 
50 
51 /*
52  * Action
53  */
54 
55 if (($mode == 'test' || $mode == 'setup') && empty($driver))
56 {
57  setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
58  header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
59  exit;
60 }
61 
62 if ($action == 'setconst' && $user->admin)
63 {
64  $error = 0;
65  $db->begin();
66  foreach ($_POST['setupdriver'] as $setupconst) {
67  //print '<pre>'.print_r($setupconst, true).'</pre>';
68  $result = dolibarr_set_const($db, $setupconst['varname'], $setupconst['value'], 'chaine', 0, '', $conf->entity);
69  if (!$result > 0) $error++;
70  }
71 
72  if (!$error) {
73  $db->commit();
74  setEventMessages($langs->trans("SetupSaved"), null);
75  } else {
76  $db->rollback();
77  dol_print_error($db);
78  }
79  $action = '';
80 }
81 
82 if ($action == 'setvalue' && $user->admin)
83 {
84  $db->begin();
85 
86  $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
87  if (!$result > 0) $error++;
88 
89  if (!$error) {
90  $db->commit();
91  setEventMessages($langs->trans("SetupSaved"), null);
92  } else {
93  $db->rollback();
94  dol_print_error($db);
95  }
96  $action = '';
97 }
98 
99 
100 /*
101  * View
102  */
103 
104 $form = new Form($db);
105 
106 llxHeader('', $langs->trans("PrintingSetup"));
107 
108 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
109 print load_fiche_titre($langs->trans("PrintingSetup"), $linkback, 'title_setup');
110 
111 $head = printingAdminPrepareHead($mode);
112 
113 if ($mode == 'setup' && $user->admin)
114 {
115  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off">';
116  print '<input type="hidden" name="token" value="'.newToken().'">';
117  print '<input type="hidden" name="action" value="setconst">';
118 
119  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
120 
121  print $langs->trans("PrintingDriverDesc".$driver)."<br><br>\n";
122 
123  print '<table class="noborder centpercent">'."\n";
124  print '<tr class="liste_titre">';
125  print '<th>'.$langs->trans("Parameters").'</th>';
126  print '<th>'.$langs->trans("Value").'</th>';
127  print '<th>&nbsp;</th>';
128  print "</tr>\n";
129  $submit_enabled = 0;
130 
131  if (!empty($driver)) {
132  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
133  foreach ($dirmodels as $dir) {
134  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
135  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
136  break;
137  }
138  }
139  require_once $classfile;
140  $classname = 'printing_'.$driver;
141  $printer = new $classname($db);
142  $langs->load($printer::LANGFILE);
143 
144  $i = 0;
145  $submit_enabled = 0;
146  foreach ($printer->conf as $key)
147  {
148  switch ($key['type']) {
149  case "text":
150  case "password":
151  print '<tr class="oddeven">';
152  print '<td'.($key['required'] ? ' class=required' : '').'>'.$langs->trans($key['varname']).'</td>';
153  print '<td><input size="32" type="'.(empty($key['type']) ? 'text' : $key['type']).'" name="setupdriver['.$i.'][value]" value="'.$conf->global->{$key['varname']}.'"';
154  print isset($key['moreattributes']) ? ' '.$key['moreattributes'] : '';
155  print '><input type="hidden" name="setupdriver['.$i.'][varname]" value="'.$key['varname'].'"></td>';
156  print '<td>&nbsp;'.($key['example'] != '' ? $langs->trans("Example").' : '.$key['example'] : '').'</td>';
157  print '</tr>'."\n";
158  break;
159  case "info": // Google Api setup or Google OAuth Token
160  print '<tr class="oddeven">';
161  print '<td'.($key['required'] ? ' class=required' : '').'>';
162  if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
163  {
164  print $langs->trans("IsTokenGenerated");
165  } else {
166  print $langs->trans($key['varname']);
167  }
168  print '</td>';
169  print '<td>'.$langs->trans($key['info']).'</td>';
170  print '<td>';
171  //var_dump($key);
172  if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
173  {
174  // Delete remote tokens
175  if (!empty($key['delete'])) print '<a class="button" href="'.$key['delete'].'">'.$langs->trans('DeleteAccess').'</a><br><br>';
176  // Request remote token
177  print '<a class="button" href="'.$key['renew'].'">'.$langs->trans('RequestAccess').'</a><br><br>';
178  // Check remote access
179  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>';
180  }
181  print '</td>';
182  print '</tr>'."\n";
183  break;
184  case "submit":
185  if ($key['enabled']) $submit_enabled = 1;
186  break;
187  }
188  $i++;
189 
190  if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS')
191  {
192  // Token
193  print '<tr class="oddeven">';
194  print '<td>'.$langs->trans("Token").'</td>';
195  print '<td colspan="2">';
196  $tokenobj = null;
197  // Dolibarr storage
198  $storage = new DoliStorage($db, $conf);
199  try {
200  $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE);
201  } catch (Exception $e)
202  {
203  // Return an error if token not found
204  }
205  if (is_object($tokenobj))
206  {
207  //var_dump($tokenobj);
208  print $tokenobj->getAccessToken().'<br>';
209  //print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
210  //print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
211  //var_dump($tokenobj->getExtraParams());
212  /*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
213  print ''.join(',',$tokenobj->getExtraParams());
214  print '</textarea>';*/
215  }
216  print '</td>';
217  print '</tr>'."\n";
218  }
219  }
220  } else {
221  print $langs->trans('PleaseSelectaDriverfromList');
222  }
223 
224  print '</table>';
225 
227 
228  if (!empty($driver))
229  {
230  if ($submit_enabled) {
231  print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></div>';
232  }
233  }
234 
235  print '</form>';
236 }
237 if ($mode == 'config' && $user->admin)
238 {
239  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
240 
241  print $langs->trans("PrintingDesc")."<br><br>\n";
242 
243  print '<table class="noborder centpercent">'."\n";
244 
245  print '<tr class="liste_titre">';
246  print '<th>'.$langs->trans("Description").'</th>';
247  print '<th class="center">'.$langs->trans("Active").'</th>';
248  print '<th class="center">'.$langs->trans("Setup").'</th>';
249  print '<th class="center">'.$langs->trans("TargetedPrinter").'</th>';
250  print "</tr>\n";
251 
252  $object = new PrintingDriver($db);
253  $result = $object->listDrivers($db, 10);
254  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
255  foreach ($result as $driver) {
256  foreach ($dirmodels as $dir) {
257  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
258  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
259  break;
260  }
261  }
262  require_once $classfile;
263  $classname = 'printing_'.$driver;
264  $printer = new $classname($db);
265  $langs->load($printer::LANGFILE);
266  //print '<pre>'.print_r($printer, true).'</pre>';
267 
268  print '<tr class="oddeven">';
269  print '<td>'.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).'</td>';
270  print '<td class="center">';
271  if (!empty($conf->use_javascript_ajax)) {
272  print ajax_constantonoff($printer->active);
273  } else {
274  if (empty($conf->global->{$printer->conf})) {
275  print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&amp;token='.newToken().'&amp;varname='.$printer->active.'&amp;value=1">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
276  } else {
277  print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&amp;token='.newToken().'&amp;varname='.$printer->active.'&amp;value=0">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
278  }
279  }
280  print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=setup&amp;driver='.$printer->name.'">'.img_picto('', 'setup').'</a></td>';
281  print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=test&amp;driver='.$printer->name.'">'.img_picto('', 'setup').'</a></td>';
282  print '</tr>'."\n";
283  }
284 
285  print '</table>';
286 
288 }
289 
290 if ($mode == 'test' && $user->admin)
291 {
292  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
293 
294  print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
295 
296  print '<table class="noborder centpercent">';
297  if (!empty($driver)) {
298  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
299  foreach ($dirmodels as $dir) {
300  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
301  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
302  break;
303  }
304  }
305  require_once $classfile;
306  $classname = 'printing_'.$driver;
307  $langs->load($driver);
308  $printer = new $classname($db);
309  $langs->load($printer::LANGFILE);
310  //print '<pre>'.print_r($printer, true).'</pre>';
311  if (count($printer->getlistAvailablePrinters())) {
312  if ($printer->listAvailablePrinters() == 0) {
313  print $printer->resprint;
314  } else {
315  setEventMessages($printer->error, $printer->errors, 'errors');
316  }
317  } else {
318  print $langs->trans('PleaseConfigureDriverfromList');
319  }
320  } else {
321  print $langs->trans('PleaseSelectaDriverfromList');
322  }
323  print '</table>';
324 
326 }
327 
328 if ($mode == 'userconf' && $user->admin)
329 {
330  print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
331 
332  print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
333 
334  print '<table class="noborder centpercent">';
335  print '<tr class="liste_titre">';
336  print '<th>'.$langs->trans("User").'</th>';
337  print '<th>'.$langs->trans("PrintModule").'</th>';
338  print '<th>'.$langs->trans("PrintDriver").'</th>';
339  print '<th>'.$langs->trans("Printer").'</th>';
340  print '<th>'.$langs->trans("PrinterLocation").'</th>';
341  print '<th>'.$langs->trans("PrinterId").'</th>';
342  print '<th>'.$langs->trans("NumberOfCopy").'</th>';
343  print '<th class="center">'.$langs->trans("Delete").'</th>';
344  print "</tr>\n";
345  $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';
346  $resql = $db->query($sql);
347  while ($row = $db->fetch_array($resql)) {
348  print '<tr class="oddeven">';
349  print '<td>'.$row['login'].'</td>';
350  print '<td>'.$row['module'].'</td>';
351  print '<td>'.$row['driver'].'</td>';
352  print '<td>'.$row['printer_name'].'</td>';
353  print '<td>'.$row['printer_location'].'</td>';
354  print '<td>'.$row['printer_id'].'</td>';
355  print '<td>'.$row['copy'].'</td>';
356  print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
357  print "</tr>\n";
358  }
359  print '</table>';
360 
362 }
363 
364 // End of page
365 llxFooter();
366 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
Parent class of emailing target selectors modules.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
llxHeader()
Empty header.
Definition: wrapper.php:45
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)
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0)
On/off button for constant.
Definition: ajax.lib.php:503
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
print
Draft customers invoices.
Definition: index.php:89
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.
Definition: index.php:1232
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59