dolibarr  16.0.5
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 
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
29 require_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  global $conf;
55 
56  $type = 'members_labels';
57  $list = array();
58 
59  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
60  $list = getListOfModels($db, $type, $maxfilenamelength);
61 
62  return $list;
63  }
64 }
65 
66 
67 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
80 function doc_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir = '', $template = 'standardlabel', $filename = 'tmp_address_sheet.pdf')
81 {
82  // phpcs:enable
83  global $conf, $langs;
84  $langs->load("members");
85 
86  $error = 0;
87 
88  // Increase limit for PDF build
89  $err = error_reporting();
90  error_reporting(0);
91  @set_time_limit(120);
92  error_reporting($err);
93 
94  $code = '';
95  $srctemplatepath = '';
96 
97  // Positionne le modele sur le nom du modele a utiliser
98  if (!dol_strlen($modele)) {
99  if (!empty($conf->global->ADHERENT_ETIQUETTE_TYPE)) {
100  $code = $conf->global->ADHERENT_ETIQUETTE_TYPE;
101  } else {
102  $code = $modele;
103  }
104  } else {
105  $code = $modele;
106  }
107 
108  // If selected modele is a filename template (then $modele="modelname:filename")
109  $tmp = explode(':', $template, 2);
110  if (!empty($tmp[1])) {
111  $template = $tmp[0];
112  $srctemplatepath = $tmp[1];
113  } else {
114  $srctemplatepath = $code;
115  }
116 
117  dol_syslog("modele=".$modele." outputdir=".$outputdir." template=".$template." code=".$code." srctemplatepath=".$srctemplatepath." filename=".$filename, LOG_DEBUG);
118 
119  // Search template files
120  $file = '';
121  $classname = '';
122  $filefound = 0;
123  $dirmodels = array('/');
124  if (is_array($conf->modules_parts['models'])) {
125  $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
126  }
127  foreach ($dirmodels as $reldir) {
128  foreach (array('doc', 'pdf') as $prefix) {
129  $file = $prefix."_".$template.".class.php";
130 
131  // On verifie l'emplacement du modele
132  $file = dol_buildpath($reldir."core/modules/printsheet/doc/".$file, 0);
133  if (file_exists($file)) {
134  $filefound = 1;
135  $classname = $prefix.'_'.$template;
136  break;
137  }
138  }
139  if ($filefound) {
140  break;
141  }
142  }
143 
144  // Charge le modele
145  if ($filefound) {
146  require_once $file;
147 
148  $obj = new $classname($db);
149 
150  // We save charset_output to restore it because write_file can change it if needed for
151  // output format that does not support UTF8.
152  $sav_charset_output = $outputlangs->charset_output;
153  if ($obj->write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir, $filename) > 0) {
154  $outputlangs->charset_output = $sav_charset_output;
155 
156  $fullpath = $obj->result['fullpath'];
157 
158  // Output to http stream
159  clearstatcache();
160 
161  $attachment = true;
162  if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) {
163  $attachment = false;
164  }
165  $type = dol_mimetype($filename);
166 
167  //if ($encoding) header('Content-Encoding: '.$encoding);
168  if ($type) {
169  header('Content-Type: '.$type);
170  }
171  if ($attachment) {
172  header('Content-Disposition: attachment; filename="'.$filename.'"');
173  } else {
174  header('Content-Disposition: inline; filename="'.$filename.'"');
175  }
176 
177  // Ajout directives pour resoudre bug IE
178  header('Cache-Control: Public, must-revalidate');
179  header('Pragma: public');
180 
181  readfile($fullpath);
182 
183  return 1;
184  } else {
185  $outputlangs->charset_output = $sav_charset_output;
186  dol_print_error($db, "doc_label_pdf_create Error: ".$obj->error);
187  return -1;
188  }
189  } else {
190  dol_print_error('', $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file));
191  return -1;
192  }
193 }
doc_label_pdf_create
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.
Definition: modules_labels.php:80
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
dol_mimetype
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
Definition: functions.lib.php:9741
ModelePDFLabels\liste_modeles
liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_labels.php:51
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
ModelePDFLabels
Parent class of document generator for address sheet.
Definition: modules_labels.php:35
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
getListOfModels
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
Definition: functions2.lib.php:1919