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