dolibarr 21.0.0-alpha
modules_labels.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * or see https://www.gnu.org/
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31
32
37{
41 public $error = '';
42
43
44 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
52 public function liste_modeles($db, $maxfilenamelength = 0)
53 {
54 // phpcs:enable
55 $type = 'members_labels';
56 $list = array();
57
58 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
59 $list = getListOfModels($db, $type, $maxfilenamelength);
60
61 return $list;
62 }
63}
64
65
66// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
79function doc_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir = '', $template = 'standardlabel', $filename = 'tmp_address_sheet.pdf')
80{
81 // phpcs:enable
82 global $conf, $langs;
83 $langs->load("members");
84
85 $error = 0;
86
87 // Increase limit for PDF build
88 $err = error_reporting();
89 error_reporting(0);
90 @set_time_limit(120);
91 error_reporting($err);
92
93 $code = '';
94 $srctemplatepath = '';
95
96 // Positionne le modele sur le nom du modele a utiliser
97 if (!dol_strlen($modele)) {
98 if (getDolGlobalString('ADHERENT_ETIQUETTE_TYPE')) {
99 $code = getDolGlobalString('ADHERENT_ETIQUETTE_TYPE');
100 } else {
101 $code = $modele;
102 }
103 } else {
104 $code = $modele;
105 }
106
107 // If selected modele is a filename template (then $modele="modelname:filename")
108 $tmp = explode(':', $template, 2);
109 if (!empty($tmp[1])) {
110 $template = $tmp[0];
111 $srctemplatepath = $tmp[1];
112 } else {
113 $srctemplatepath = $code;
114 }
115
116 dol_syslog("modele=".$modele." outputdir=".$outputdir." template=".$template." code=".$code." srctemplatepath=".$srctemplatepath." filename=".$filename, LOG_DEBUG);
117
118 // Search template files
119 $file = '';
120 $classname = '';
121 $dirmodels = array('/');
122 if (is_array($conf->modules_parts['models'])) {
123 $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
124 }
125 foreach ($dirmodels as $reldir) {
126 foreach (array('doc', 'pdf') as $prefix) {
127 $file = $prefix."_".$template.".class.php";
128
129 // Determine the model path and validate that it exists
130 $file = dol_buildpath($reldir."core/modules/printsheet/doc/".$file, 0);
131 if (file_exists($file)) {
132 $classname = $prefix.'_'.$template;
133 break;
134 }
135 }
136 if ($classname !== '') {
137 break;
138 }
139 }
140
141 // Load the model
142 if ($classname !== '') {
143 require_once $file;
144
145 $obj = new $classname($db);
146
147 // We save charset_output to restore it because write_file can change it if needed for
148 // output format that does not support UTF8.
149 $sav_charset_output = $outputlangs->charset_output;
150 if ($obj->write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir, $filename) > 0) {
151 $outputlangs->charset_output = $sav_charset_output;
152
153 $fullpath = $obj->result['fullpath'];
154
155 // Output to http stream
156 clearstatcache();
157
158 $attachment = true;
159 if (getDolGlobalString('MAIN_DISABLE_FORCE_SAVEAS')) {
160 $attachment = false;
161 }
162 $type = dol_mimetype($filename);
163
164 //if ($encoding) header('Content-Encoding: '.$encoding);
165 if ($type) {
166 header('Content-Type: '.$type);
167 }
168 if ($attachment) {
169 header('Content-Disposition: attachment; filename="'.$filename.'"');
170 } else {
171 header('Content-Disposition: inline; filename="'.$filename.'"');
172 }
173
174 // Ajout directives pour resoudre bug IE
175 header('Cache-Control: Public, must-revalidate');
176 header('Pragma: public');
177
178 readfile($fullpath);
179
180 return 1;
181 } else {
182 $outputlangs->charset_output = $sav_charset_output;
183 dol_print_error($db, "doc_label_pdf_create Error: ".$obj->error);
184 return -1;
185 }
186 } else {
187 dol_print_error(null, $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file));
188 return -1;
189 }
190}
Parent class of document generator for address sheet.
liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
doc_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir='', $template='standardlabel', $filename='tmp_address_sheet.pdf')
Create a document onto disk according to template module.