dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
17  * or see http://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  if (! empty($list)) {
37  $errorprint=0;
38  $printerfound=0;
39  foreach ($list as $driver) {
40  require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
41  $langs->load($driver);
42  $classname = 'printing_'.$driver;
43  $printer = new $classname($db);
44  //print '<pre>'.print_r($printer, true).'</pre>';
45 
46  if (! empty($conf->global->{$printer->active}))
47  {
48  $printerfound++;
49 
50  $subdir='';
51  $module = GETPOST('printer', 'alpha');
52  switch ($module )
53  {
54  case 'livraison' :
55  $subdir = 'receipt';
56  $module = 'expedition';
57  break;
58  case 'expedition' :
59  $subdir = 'sending';
60  break;
61  case 'commande_fournisseur' :
62  $module = 'fournisseur';
63  $subdir = 'commande';
64  break;
65  }
66  try {
67  $ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
68  if ($ret > 0) {
69  //print '<pre>'.print_r($printer->errors, true).'</pre>';
70  setEventMessages($printer->error, $printer->errors, 'errors');
71  }
72  if ($ret==0)
73  {
74  //print '<pre>'.print_r($printer->errors, true).'</pre>';
75  setEventMessages($printer->error, $printer->errors);
76  setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
77  }
78  }
79  catch(Exception $e)
80  {
81  $ret = 1;
82  setEventMessages($e->getMessage(), null, 'errors');
83  }
84  }
85  }
86  if ($printerfound==0) setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
87  } else {
88  setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
89  }
90  $action = '';
91 }
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Parent class of emailing target selectors modules.