dolibarr  13.0.2
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  *
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  * or see https://www.gnu.org/
18  */
19 
26 // $action must be defined
27 // $db, $user, $conf, $langs must be defined
28 // Filename to print must be provided into 'file' parameter
29 
30 // Print file
31 if ($action == 'print_file' && $user->rights->printing->read) {
32  $langs->load("printing");
33  require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
34  $objectprint = new PrintingDriver($db);
35  $list = $objectprint->listDrivers($db, 10);
36  $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
37  if (!empty($list)) {
38  $errorprint = 0;
39  $printerfound = 0;
40  foreach ($list as $driver) {
41  foreach ($dirmodels as $dir) {
42  if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
43  $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
44  break;
45  }
46  }
47  require_once $classfile;
48  $classname = 'printing_'.$driver;
49  $printer = new $classname($db);
50  $langs->load($printer::LANGFILE);
51  //print '<pre>'.print_r($printer, true).'</pre>';
52 
53  if (!empty($conf->global->{$printer->active})) {
54  $printerfound++;
55 
56  $subdir = '';
57  $module = GETPOST('printer', 'alpha');
58  switch ($module)
59  {
60  case 'livraison' :
61  $subdir = 'receipt';
62  $module = 'expedition';
63  break;
64  case 'expedition' :
65  $subdir = 'sending';
66  break;
67  case 'commande_fournisseur' :
68  $module = 'fournisseur';
69  $subdir = 'commande';
70  break;
71  }
72  try {
73  $ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
74  if ($ret > 0) {
75  //print '<pre>'.print_r($printer->errors, true).'</pre>';
76  setEventMessages($printer->error, $printer->errors, 'errors');
77  }
78  if ($ret == 0)
79  {
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  {
86  $ret = 1;
87  setEventMessages($e->getMessage(), null, 'errors');
88  }
89  }
90  }
91  if ($printerfound == 0) setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
92  } else {
93  setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
94  }
95  $action = '';
96 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.