dolibarr 19.0.4
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
28require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
30
31
36{
40 public $error = '';
41
42
43 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
51 public function liste_modeles($db, $maxfilenamelength = 0)
52 {
53 // phpcs:enable
54 $type = 'members_labels';
55 $list = array();
56
57 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
58 $list = getListOfModels($db, $type, $maxfilenamelength);
59
60 return $list;
61 }
62}
63
64
65// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
78function doc_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir = '', $template = 'standardlabel', $filename = 'tmp_address_sheet.pdf')
79{
80 // phpcs:enable
81 global $conf, $langs;
82 $langs->load("members");
83
84 $error = 0;
85
86 // Increase limit for PDF build
87 $err = error_reporting();
88 error_reporting(0);
89 @set_time_limit(120);
90 error_reporting($err);
91
92 $code = '';
93 $srctemplatepath = '';
94
95 // Positionne le modele sur le nom du modele a utiliser
96 if (!dol_strlen($modele)) {
97 if (getDolGlobalString('ADHERENT_ETIQUETTE_TYPE')) {
98 $code = $conf->global->ADHERENT_ETIQUETTE_TYPE;
99 } else {
100 $code = $modele;
101 }
102 } else {
103 $code = $modele;
104 }
105
106 // If selected modele is a filename template (then $modele="modelname:filename")
107 $tmp = explode(':', $template, 2);
108 if (!empty($tmp[1])) {
109 $template = $tmp[0];
110 $srctemplatepath = $tmp[1];
111 } else {
112 $srctemplatepath = $code;
113 }
114
115 dol_syslog("modele=".$modele." outputdir=".$outputdir." template=".$template." code=".$code." srctemplatepath=".$srctemplatepath." filename=".$filename, LOG_DEBUG);
116
117 // Search template files
118 $file = '';
119 $classname = '';
120 $filefound = 0;
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 // On verifie l'emplacement du modele
130 $file = dol_buildpath($reldir."core/modules/printsheet/doc/".$file, 0);
131 if (file_exists($file)) {
132 $filefound = 1;
133 $classname = $prefix.'_'.$template;
134 break;
135 }
136 }
137 if ($filefound) {
138 break;
139 }
140 }
141
142 // Charge le modele
143 if ($filefound) {
144 require_once $file;
145
146 $obj = new $classname($db);
147
148 // We save charset_output to restore it because write_file can change it if needed for
149 // output format that does not support UTF8.
150 $sav_charset_output = $outputlangs->charset_output;
151 if ($obj->write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir, $filename) > 0) {
152 $outputlangs->charset_output = $sav_charset_output;
153
154 $fullpath = $obj->result['fullpath'];
155
156 // Output to http stream
157 clearstatcache();
158
159 $attachment = true;
160 if (getDolGlobalString('MAIN_DISABLE_FORCE_SAVEAS')) {
161 $attachment = false;
162 }
163 $type = dol_mimetype($filename);
164
165 //if ($encoding) header('Content-Encoding: '.$encoding);
166 if ($type) {
167 header('Content-Type: '.$type);
168 }
169 if ($attachment) {
170 header('Content-Disposition: attachment; filename="'.$filename.'"');
171 } else {
172 header('Content-Disposition: inline; filename="'.$filename.'"');
173 }
174
175 // Ajout directives pour resoudre bug IE
176 header('Cache-Control: Public, must-revalidate');
177 header('Pragma: public');
178
179 readfile($fullpath);
180
181 return 1;
182 } else {
183 $outputlangs->charset_output = $sav_charset_output;
184 dol_print_error($db, "doc_label_pdf_create Error: ".$obj->error);
185 return -1;
186 }
187 } else {
188 dol_print_error('', $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file));
189 return -1;
190 }
191}
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.