dolibarr  7.0.0-beta
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@capnetworks.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 <http://www.gnu.org/licenses/>.
19  * or see http://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 {
37  var $error='';
38 
39 
47  function liste_modeles($db,$maxfilenamelength=0)
48  {
49  global $conf;
50 
51  $type='members_labels';
52  $liste=array();
53 
54  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55  $liste=getListOfModels($db,$type,$maxfilenamelength);
56 
57  return $liste;
58  }
59 }
60 
61 
74 function doc_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir='', $template='standardlabel', $filename='tmp_address_sheet.pdf')
75 {
76  global $conf,$langs;
77  $langs->load("members");
78 
79  $error=0;
80 
81  // Increase limit for PDF build
82  $err=error_reporting();
83  error_reporting(0);
84  @set_time_limit(120);
85  error_reporting($err);
86 
87  $code='';
88  $srctemplatepath='';
89 
90  // Positionne le modele sur le nom du modele a utiliser
91  if (! dol_strlen($modele))
92  {
93  if (! empty($conf->global->ADHERENT_ETIQUETTE_TYPE))
94  {
95  $code = $conf->global->ADHERENT_ETIQUETTE_TYPE;
96  }
97  else
98  {
99  $code = $modele;
100  }
101  }
102  else $code=$modele;
103 
104  // If selected modele is a filename template (then $modele="modelname:filename")
105  $tmp=explode(':',$template,2);
106  if (! empty($tmp[1]))
107  {
108  $template=$tmp[0];
109  $srctemplatepath=$tmp[1];
110  }
111  else $srctemplatepath=$code;
112 
113  dol_syslog("modele=".$modele." outputdir=".$outputdir." template=".$template." code=".$code." srctemplatepath=".$srctemplatepath." filename=".$filename, LOG_DEBUG);
114 
115  // Search template files
116  $file=''; $classname=''; $filefound=0;
117  $dirmodels=array('/');
118  if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
119  foreach($dirmodels as $reldir)
120  {
121  foreach(array('doc','pdf') as $prefix)
122  {
123  $file = $prefix."_".$template.".class.php";
124 
125  // On verifie l'emplacement du modele
126  $file=dol_buildpath($reldir."core/modules/printsheet/doc/".$file,0);
127  if (file_exists($file))
128  {
129  $filefound=1;
130  $classname=$prefix.'_'.$template;
131  break;
132  }
133  }
134  if ($filefound) break;
135  }
136 
137  // Charge le modele
138  if ($filefound)
139  {
140  require_once $file;
141 
142  $obj = new $classname($db);
143 
144  // We save charset_output to restore it because write_file can change it if needed for
145  // output format that does not support UTF8.
146  $sav_charset_output=$outputlangs->charset_output;
147  if ($obj->write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir, $filename) > 0)
148  {
149  $outputlangs->charset_output=$sav_charset_output;
150  return 1;
151  }
152  else
153  {
154  $outputlangs->charset_output=$sav_charset_output;
155  dol_print_error($db,"doc_label_pdf_create Error: ".$obj->error);
156  return -1;
157  }
158  }
159  else
160  {
161  dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
162  return -1;
163  }
164 
165 
166 }
167 
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Parent class of document generator for address sheet.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.