dolibarr 23.0.3
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-2025 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
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 $printerfound = 0;
48 foreach ($list as $driver) {
49 foreach ($dirmodels as $dir) {
50 if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
51 $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
52 break;
53 }
54 }
55 require_once $classfile;
56 $classname = 'printing_'.$driver;
57 $printer = new $classname($db);
58 '@phan-var-force PrintingDriver $printer';
60 $langs->load('printing');
61 // print '<pre>'.print_r($printer, true).'</pre>';
62
63 if (getDolGlobalString($printer->active)) {
64 $printerfound++;
65
66 $subdir = '';
67 $module = GETPOST('printer', 'alpha');
68 // TODO make conversion in printing module
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 = 'commande_fournisseur';
79 $subdir = 'commande';
80 break;
81 }
82 try {
83 // Case of printing an invoice
84 $filetoprint = GETPOST('file', 'alpha'); //Example FAYYMM-123/FAYYMM-123-xxx.pdf
85 if ($module == 'facture') {
86 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
87 $refinvoice = preg_replace('/[\/\\\\].*$/', '', $filetoprint);
88 $tmpinvoice = new Facture($db);
89 $tmpinvoice->fetch(0, $refinvoice);
90 if ($tmpinvoice->id > 0) {
91 // Increase counter by 1
92 $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
93 $sql .= " WHERE rowid = ".((int) $tmpinvoice->id);
94 $db->query($sql);
95
96 //$tmpinvoice->pos_print_counter += 1;
97 //$tmpinvoice->update($user, 1); // We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after
98 }
99 }
100
101
102 $ret = $printer->printFile($filetoprint, $module, $subdir);
103 if ($ret > 0) {
104 //print '<pre>'.print_r($printer->errors, true).'</pre>';
105 setEventMessages($printer->error, $printer->errors, 'errors');
106 }
107 if ($ret == 0) {
108 //print '<pre>'.print_r($printer->errors, true).'</pre>';
109 setEventMessages($printer->error, $printer->errors);
110 setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
111 }
112 } catch (Exception $e) {
113 $ret = 1;
114 setEventMessages($e->getMessage(), null, 'errors');
115 }
116 }
117 }
118 if ($printerfound == 0) {
119 setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
120 }
121 } else {
122 setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
123 }
124 $action = '';
125}
Class to manage invoices.
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.