dolibarr 24.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-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 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
41// Print file
42if ($action == 'print_file' && $user->hasRight('printing', 'read')) {
43 $langs->load("printing");
44 require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
45 $objectprint = new PrintingDriver($db);
46 $list = $objectprint->listDrivers($db, 10);
47 $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
48 if (!empty($list)) {
49 $printerfound = 0;
50 foreach ($list as $driver) {
51 $classfile = null;
52 foreach ($dirmodels as $dir) {
53 $tmpclassfile = dol_buildpath($dir, 0).$driver.'.modules.php';
54 if (file_exists($tmpclassfile)) {
55 $classfile = $tmpclassfile;
56 break;
57 }
58 }
59 if ($classfile === null) {
60 continue;
61 }
62 require_once $classfile;
63 $classname = 'printing_'.$driver;
64 $printer = new $classname($db);
65 '@phan-var-force PrintingDriver $printer';
67 $langs->load('printing');
68
69 if (getDolGlobalString($printer->active)) {
70 $printerfound++;
71
72 $subdir = '';
73 $module = GETPOST('printer', 'alpha');
74
75 try {
76 // Case of printing an invoice
77 $filetoprint = GETPOST('file', 'alpha'); //Example FAYYMM-123/FAYYMM-123-xxx.pdf
78 if ($module == 'facture') {
79 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
80 $refinvoice = preg_replace('/[\/\\\\].*$/', '', $filetoprint);
81 $tmpinvoice = new Facture($db);
82 $tmpinvoice->fetch(0, $refinvoice);
83 if ($tmpinvoice->id > 0) {
84 // Increase counter by 1
85 $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
86 $sql .= " WHERE rowid = ".((int) $tmpinvoice->id);
87 $db->query($sql);
88
89 //$tmpinvoice->pos_print_counter += 1;
90 //$tmpinvoice->update($user, 1); // We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after
91 }
92 }
93
94
95 $ret = $printer->printFile($filetoprint, $module, $subdir);
96 if ($ret > 0) {
97 //print '<pre>'.print_r($printer->errors, true).'</pre>';
98 setEventMessages($printer->error, $printer->errors, 'errors');
99 }
100 if ($ret == 0) {
101 //print '<pre>'.print_r($printer->errors, true).'</pre>';
102 setEventMessages($printer->error, $printer->errors);
103 setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
104 }
105 } catch (Exception $e) {
106 $ret = 1;
107 setEventMessages($e->getMessage(), null, 'errors');
108 }
109 }
110 }
111 if ($printerfound == 0) {
112 setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
113 }
114 } else {
115 setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
116 }
117 $action = '';
118}
Class to manage invoices.
Parent class of emailing target selectors modules.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.