dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
32require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php';
33use OAuth\Common\Storage\DoliStorage;
34
43// Load translation files required by the page
44$langs->loadLangs(array('admin', 'printing', 'oauth'));
45
46$action = GETPOST('action', 'aZ09');
47$mode = GETPOST('mode', 'alpha');
48$value = GETPOST('value', 'alpha', 0, null, null, 1); // The value may be __google__docs so we force disable of replace
49$varname = GETPOST('varname', 'alpha');
50$driver = GETPOST('driver', 'alpha');
51
52if (!empty($driver)) {
53 $langs->load($driver);
54}
55
56if (!$mode) {
57 $mode = 'config';
58}
59
60$OAUTH_SERVICENAME_GOOGLE = 'Google';
61
62if (!$user->admin) {
64}
65
66
67/*
68 * Action
69 */
70$error = 0;
71
72if (($mode == 'test' || $mode == 'setup') && empty($driver)) {
73 setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null);
74 header("Location: ".$_SERVER['PHP_SELF'].'?mode=config');
75 exit;
76}
77
78if ($action == 'setconst' && $user->admin) {
79 $db->begin();
80 foreach ($_POST['setupdriver'] as $setupconst) {
81 '@phan-var-force array<string,string> $setupconst';
82 //print '<pre>'.print_r($setupconst, true).'</pre>';
83 $result = dolibarr_set_const($db, $setupconst['varname'], $setupconst['value'], 'chaine', 0, '', $conf->entity);
84 if (!($result > 0)) {
85 $error++;
86 }
87 }
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
99if ($action == 'setvalue' && $user->admin) {
100 $db->begin();
101
102 $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
103 if (!($result > 0)) {
104 $error++;
105 }
106
107 if (!$error) {
108 $db->commit();
109 setEventMessages($langs->trans("SetupSaved"), null);
110 } else {
111 $db->rollback();
112 dol_print_error($db);
113 }
114 $action = '';
115}
116
117
118/*
119 * View
120 */
121
122$form = new Form($db);
123
124llxHeader('', $langs->trans("PrintingSetup"));
125
126$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
127print load_fiche_titre($langs->trans("PrintingSetup"), $linkback, 'title_setup');
128
129$head = printingAdminPrepareHead($mode);
130
131if ($mode == 'setup' && $user->admin) {
132 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off">';
133 print '<input type="hidden" name="token" value="'.newToken().'">';
134 print '<input type="hidden" name="action" value="setconst">';
135
136 print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
137
138 print $langs->trans("PrintingDriverDesc".$driver)."<br><br>\n";
139
140 print '<table class="noborder centpercent">'."\n";
141 print '<tr class="liste_titre">';
142 print '<th>'.$langs->trans("Parameters").'</th>';
143 print '<th>'.$langs->trans("Value").'</th>';
144 print '<th>&nbsp;</th>';
145 print "</tr>\n";
146 $submit_enabled = 0;
147
148 if (!empty($driver)) {
149 if (!empty($conf->modules_parts['printing'])) {
150 $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
151 } else {
152 $dirmodels = array('/core/modules/printing/');
153 }
154
155 foreach ($dirmodels as $dir) {
156 if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
157 $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
158 break;
159 }
160 }
161 require_once $classfile;
162 $classname = 'printing_'.$driver;
163 $printer = new $classname($db);
164 $langs->load('printing');
165
166 $i = 0;
167 $submit_enabled = 0;
168 foreach ($printer->conf as $key) {
169 switch ($key['type']) {
170 case "text":
171 case "password":
172 print '<tr class="oddeven">';
173 print '<td'.($key['required'] ? ' class=required' : '').'>'.$langs->trans($key['varname']).'</td>';
174 print '<td><input class="width100" type="'.(empty($key['type']) ? 'text' : $key['type']).'" name="setupdriver['.$i.'][value]" value="'.getDolGlobalString($key['varname']).'"';
175 print isset($key['moreattributes']) ? ' '.$key['moreattributes'] : '';
176 print '><input type="hidden" name="setupdriver['.$i.'][varname]" value="'.$key['varname'].'"></td>';
177 print '<td>&nbsp;'.($key['example'] != '' ? $langs->trans("Example").' : '.$key['example'] : '').'</td>';
178 print '</tr>'."\n";
179 break;
180 case "checkbox":
181 print '<tr class="oddeven">';
182 print '<td'.($key['required'] ? ' class=required' : '').'>'.$langs->trans($key['varname']).'</td>';
183 print '<td><input class="width100" type="'.(empty($key['type']) ? 'text' : $key['type']).'" name="setupdriver['.$i.'][value]" value="1" '.((getDolGlobalInt($key['varname'])) ? 'checked' : '');
184 print isset($key['moreattributes']) ? ' '.$key['moreattributes'] : '';
185 print '><input type="hidden" name="setupdriver['.$i.'][varname]" value="'.$key['varname'].'"></td>';
186 print '<td>&nbsp;'.($key['example'] != '' ? $langs->trans("Example").' : '.$key['example'] : '').'</td>';
187 print '</tr>'."\n";
188 break;
189 case "info": // Google Api setup or Google OAuth Token
190 print '<tr class="oddeven">';
191 print '<td'.($key['required'] ? ' class=required' : '').'>';
192 if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
193 print $langs->trans("IsTokenGenerated");
194 } else {
195 print $langs->trans($key['varname']);
196 }
197 print '</td>';
198 print '<td>'.$langs->trans($key['info']).'</td>';
199 print '<td>';
200 //var_dump($key);
201 if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
202 // Delete remote tokens
203 if (!empty($key['delete'])) {
204 print '<a class="button" href="'.$key['delete'].'">'.$langs->trans('DeleteAccess').'</a><br><br>';
205 }
206 // Request remote token
207 print '<a class="button" href="'.$key['renew'].'">'.$langs->trans('RequestAccess').'</a><br><br>';
208 // Check remote access
209 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>';
210 }
211 print '</td>';
212 print '</tr>'."\n";
213 break;
214 case "submit":
215 if ($key['enabled']) {
216 $submit_enabled = 1;
217 }
218 break;
219 }
220 $i++;
221
222 if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') {
223 $keyforprovider = ''; // @BUG This must be set
224
225 // Token
226 print '<tr class="oddeven">';
227 print '<td>'.$langs->trans("Token").'</td>';
228 print '<td colspan="2">';
229 $tokenobj = null;
230 // Dolibarr storage
231 $storage = new DoliStorage($db, $conf, $keyforprovider);
232 try {
233 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE);
234 } catch (Exception $e) {
235 // Return an error if token not found
236 }
237 if (is_object($tokenobj)) {
238 //var_dump($tokenobj);
239 print $tokenobj->getAccessToken().'<br>';
240 //print 'Refresh: '.$tokenobj->getRefreshToken().'<br>';
241 //print 'EndOfLife: '.$tokenobj->getEndOfLife().'<br>';
242 //var_dump($tokenobj->getExtraParams());
243 /*print '<br>Extra: <br><textarea class="quatrevingtpercent">';
244 print ''.join(',',$tokenobj->getExtraParams());
245 print '</textarea>';*/
246 }
247 print '</td>';
248 print '</tr>'."\n";
249 }
250 }
251 } else {
252 print $langs->trans('PleaseSelectaDriverfromList');
253 }
254
255 print '</table>';
256
257 print dol_get_fiche_end();
258
259 if (!empty($driver)) {
260 if ($submit_enabled) {
261 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
262 }
263 }
264
265 print '</form>';
266}
267if ($mode == 'config' && $user->admin) {
268 print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
269
270 print $langs->trans("PrintingDesc")."<br><br>\n";
271
272 print '<table class="noborder centpercent">'."\n";
273
274 print '<tr class="liste_titre">';
275 print '<th>'.$langs->trans("Description").'</th>';
276 print '<th class="center">'.$langs->trans("Active").'</th>';
277 print '<th class="center">'.$langs->trans("Setup").'</th>';
278 print '<th class="center">'.$langs->trans("TargetedPrinter").'</th>';
279 print "</tr>\n";
280
281 $object = new PrintingDriver($db);
282 $result = $object->listDrivers($db, 10);
283
284 if (!empty($conf->modules_parts['printing'])) {
285 $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
286 } else {
287 $dirmodels = array('/core/modules/printing/');
288 }
289
290 foreach ($result as $tmpdriver) {
291 foreach ($dirmodels as $dir) {
292 if (file_exists(dol_buildpath($dir, 0).$tmpdriver.'.modules.php')) {
293 $classfile = dol_buildpath($dir, 0).$tmpdriver.'.modules.php';
294 break;
295 }
296 }
297 require_once $classfile;
298 $classname = 'printing_'.$tmpdriver;
299 $printer = new $classname($db);
300 $langs->load('printing');
301 //print '<pre>'.print_r($printer, true).'</pre>';
302
303 print '<tr class="oddeven">';
304 print '<td>'.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).'</td>';
305 print '<td class="center">';
306 if (!empty($conf->use_javascript_ajax)) {
307 print ajax_constantonoff($printer->active);
308 } else {
309 if (!getDolGlobalString($printer->conf)) {
310 print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.urlencode($printer->active).'&value=1">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
311 } else {
312 print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.urlencode($printer->active).'&value=0">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
313 }
314 }
315 print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=setup&token='.newToken().'&driver='.urlencode($printer->name).'">'.img_picto('', 'setup').'</a></td>';
316 print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=test&token='.newToken().'&driver='.urlencode($printer->name).'">'.img_picto('', 'setup').'</a></td>';
317 print '</tr>'."\n";
318 }
319
320 print '</table>';
321
322 print dol_get_fiche_end();
323}
324
325if ($mode == 'test' && $user->admin) {
326 print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
327
328 print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
329
330 print '<table class="noborder centpercent">';
331 if (!empty($driver)) {
332 if (!empty($conf->modules_parts['printing'])) {
333 $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
334 } else {
335 $dirmodels = array('/core/modules/printing/');
336 }
337
338 foreach ($dirmodels as $dir) {
339 if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
340 $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
341 break;
342 }
343 }
344 require_once $classfile;
345 $classname = 'printing_'.$driver;
346 $printer = new $classname($db);
347 '@phan-var-force PrintingDriver $printer';
348 $langs->load($driver);
349 $langs->load('printing');
350
351 //print '<pre>'.print_r($printer, true).'</pre>';
352 if (count($printer->getlistAvailablePrinters())) {
353 if ($printer->listAvailablePrinters() == 0) {
354 print $printer->resprint;
355 } else {
356 setEventMessages($printer->error, $printer->errors, 'errors');
357 }
358 } else {
359 print $langs->trans('PleaseConfigureDriverfromList');
360 }
361 } else {
362 print $langs->trans('PleaseSelectaDriverfromList');
363 }
364 print '</table>';
365
366 print dol_get_fiche_end();
367}
368
369if ($mode == 'userconf' && $user->admin) {
370 print dol_get_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic');
371
372 print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
373
374 print '<table class="noborder centpercent">';
375 print '<tr class="liste_titre">';
376 print '<th>'.$langs->trans("User").'</th>';
377 print '<th>'.$langs->trans("PrintModule").'</th>';
378 print '<th>'.$langs->trans("PrintDriver").'</th>';
379 print '<th>'.$langs->trans("Printer").'</th>';
380 print '<th>'.$langs->trans("PrinterLocation").'</th>';
381 print '<th>'.$langs->trans("PrinterId").'</th>';
382 print '<th>'.$langs->trans("NumberOfCopy").'</th>';
383 print '<th class="center">'.$langs->trans("Delete").'</th>';
384 print "</tr>\n";
385 $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';
386 $resql = $db->query($sql);
387 while ($row = $db->fetch_array($resql)) {
388 print '<tr class="oddeven">';
389 print '<td>'.$row['login'].'</td>';
390 print '<td>'.$row['module'].'</td>';
391 print '<td>'.$row['driver'].'</td>';
392 print '<td>'.$row['printer_name'].'</td>';
393 print '<td>'.$row['printer_location'].'</td>';
394 print '<td>'.$row['printer_id'].'</td>';
395 print '<td>'.$row['copy'].'</td>';
396 print '<td class="center">'.img_picto($langs->trans("Delete"), 'delete').'</td>';
397 print "</tr>\n";
398 }
399 print '</table>';
400
401 print dol_get_fiche_end();
402}
403
404// End of page
405llxFooter();
406$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
Parent class of emailing target selectors modules.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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 a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.