dolibarr  20.0.0-alpha
actions_printing.inc.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2014-2018 Frederic France <frederic.france@netlogic.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  * or see https://www.gnu.org/
19  */
20 
27 // $action must be defined
28 // $db, $user, $conf, $langs must be defined
29 // Filename to print must be provided into 'file' parameter
30 
31 // Print file
32 if ($action == 'print_file' && $user->hasRight('printing', 'read')) {
33  $langs->load("printing");
34  require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
35  $objectprint = new PrintingDriver($db);
36  $list = $objectprint->listDrivers($db, 10);
37  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
38  if (!empty($list)) {
39  $errorprint = 0;
40  $printerfound = 0;
41  foreach ($list as $driver) {
42  foreach ($dirmodels as $dir) {
43  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
44  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
45  break;
46  }
47  }
48  require_once $classfile;
49  $classname = 'printing_'.$driver;
50  $printer = new $classname($db);
51  '@phan-var-force PrintingDriver $printer';
52  $langs->load('printing');
53  //print '<pre>'.print_r($printer, true).'</pre>';
54 
55  if (getDolGlobalString($printer->active)) {
56  $printerfound++;
57 
58  $subdir = '';
59  $module = GETPOST('printer', 'alpha');
60  switch ($module) {
61  case 'livraison':
62  $subdir = 'receipt';
63  $module = 'expedition';
64  break;
65  case 'expedition':
66  $subdir = 'sending';
67  break;
68  case 'commande_fournisseur':
69  $module = 'fournisseur';
70  $subdir = 'commande';
71  break;
72  }
73  try {
74  $ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
75  if ($ret > 0) {
76  //print '<pre>'.print_r($printer->errors, true).'</pre>';
77  setEventMessages($printer->error, $printer->errors, 'errors');
78  }
79  if ($ret == 0) {
80  //print '<pre>'.print_r($printer->errors, true).'</pre>';
81  setEventMessages($printer->error, $printer->errors);
82  setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
83  }
84  } catch (Exception $e) {
85  $ret = 1;
86  setEventMessages($e->getMessage(), null, 'errors');
87  }
88  }
89  }
90  if ($printerfound == 0) {
91  setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
92  }
93  } else {
94  setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
95  }
96  $action = '';
97 }
Parent class of emailing target selectors modules.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.