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