dolibarr 21.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-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 * 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
39// Print file
40if ($action == 'print_file' && $user->hasRight('printing', 'read')) {
41 $langs->load("printing");
42 require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
43 $objectprint = new PrintingDriver($db);
44 $list = $objectprint->listDrivers($db, 10);
45 $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
46 if (!empty($list)) {
47 $errorprint = 0;
48 $printerfound = 0;
49 foreach ($list as $driver) {
50 foreach ($dirmodels as $dir) {
51 if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
52 $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
53 break;
54 }
55 }
56 require_once $classfile;
57 $classname = 'printing_'.$driver;
58 $printer = new $classname($db);
59 '@phan-var-force PrintingDriver $printer';
61 $langs->load('printing');
62 // print '<pre>'.print_r($printer, true).'</pre>';
63
64 if (getDolGlobalString($printer->active)) {
65 $printerfound++;
66
67 $subdir = '';
68 $module = GETPOST('printer', 'alpha');
69 switch ($module) {
70 case 'livraison':
71 $subdir = 'receipt';
72 $module = 'expedition';
73 break;
74 case 'expedition':
75 $subdir = 'sending';
76 break;
77 case 'commande_fournisseur':
78 $module = 'fournisseur';
79 $subdir = 'commande';
80 break;
81 }
82 try {
83 $ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
84 if ($ret > 0) {
85 //print '<pre>'.print_r($printer->errors, true).'</pre>';
86 setEventMessages($printer->error, $printer->errors, 'errors');
87 }
88 if ($ret == 0) {
89 //print '<pre>'.print_r($printer->errors, true).'</pre>';
90 setEventMessages($printer->error, $printer->errors);
91 setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
92 }
93 } catch (Exception $e) {
94 $ret = 1;
95 setEventMessages($e->getMessage(), null, 'errors');
96 }
97 }
98 }
99 if ($printerfound == 0) {
100 setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
101 }
102 } else {
103 setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
104 }
105 $action = '';
106}
Parent class of emailing target selectors modules.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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