dolibarr  18.0.0-alpha
modules_fichinter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2019 Philippe Grand <philippe.grand@atoo-net.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 
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
30 
31 
36 {
40  public $error = '';
41 
42 
43  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
51  public static function liste_modeles($db, $maxfilenamelength = 0)
52  {
53  // phpcs:enable
54  $type = 'ficheinter';
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 
68 abstract class ModeleNumRefFicheinter
69 {
73  public $error = '';
74 
80  public function isEnabled()
81  {
82  return true;
83  }
84 
90  public function info()
91  {
92  global $langs;
93  $langs->load("ficheinter");
94  return $langs->trans("NoDescription");
95  }
96 
102  public function getExample()
103  {
104  global $langs;
105  $langs->load("ficheinter");
106  return $langs->trans("NoExample");
107  }
108 
115  public function canBeActivated()
116  {
117  return true;
118  }
119 
127  public function getNextValue($objsoc = 0, $object = '')
128  {
129  global $langs;
130  return $langs->trans("NotAvailable");
131  }
132 
138  public function getVersion()
139  {
140  global $langs;
141  $langs->load("admin");
142 
143  if ($this->version == 'development') {
144  return $langs->trans("VersionDevelopment");
145  } elseif ($this->version == 'experimental') {
146  return $langs->trans("VersionExperimental");
147  } elseif ($this->version == 'dolibarr') {
148  return DOL_VERSION;
149  } elseif ($this->version) {
150  return $this->version;
151  } else {
152  return $langs->trans("NotAvailable");
153  }
154  }
155 }
156 
157 
158 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
171 function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
172 {
173  // phpcs:enable
174  global $conf, $langs, $user;
175  $langs->load("ficheinter");
176 
177  $error = 0;
178 
179  $srctemplatepath = '';
180 
181  // Positionne modele sur le nom du modele de fichinter a utiliser
182  if (!dol_strlen($modele)) {
183  if (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
184  $modele = $conf->global->FICHEINTER_ADDON_PDF;
185  } else {
186  $modele = 'soleil';
187  }
188  }
189 
190  // If selected modele is a filename template (then $modele="modelname:filename")
191  $tmp = explode(':', $modele, 2);
192  if (!empty($tmp[1])) {
193  $modele = $tmp[0];
194  $srctemplatepath = $tmp[1];
195  }
196 
197  // Search template files
198  $file = '';
199  $classname = '';
200  $filefound = 0;
201  $dirmodels = array('/');
202  if (is_array($conf->modules_parts['models'])) {
203  $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
204  }
205  foreach ($dirmodels as $reldir) {
206  foreach (array('doc', 'pdf') as $prefix) {
207  $file = $prefix."_".$modele.".modules.php";
208 
209  // On verifie l'emplacement du modele
210  $file = dol_buildpath($reldir."core/modules/fichinter/doc/".$file, 0);
211  if (file_exists($file)) {
212  $filefound = 1;
213  $classname = $prefix.'_'.$modele;
214  break;
215  }
216  }
217  if ($filefound) {
218  break;
219  }
220  }
221 
222  // Charge le modele
223  if ($filefound) {
224  require_once $file;
225 
226  $obj = new $classname($db);
227 
228  // We save charset_output to restore it because write_file can change it if needed for
229  // output format that does not support UTF8.
230  $sav_charset_output = $outputlangs->charset_output;
231  if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
232  $outputlangs->charset_output = $sav_charset_output;
233 
234  // We delete old preview
235  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
236  dol_delete_preview($object);
237 
238  return 1;
239  } else {
240  $outputlangs->charset_output = $sav_charset_output;
241  dol_print_error($db, "fichinter_pdf_create Error: ".$obj->error);
242  return 0;
243  }
244  } else {
245  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
246  return 0;
247  }
248 }
ModeleNumRefFicheinter\getNextValue
getNextValue($objsoc=0, $object='')
Return the next assigned value.
Definition: modules_fichinter.php:127
ModeleNumRefFicheinter\canBeActivated
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
Definition: modules_fichinter.php:115
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:4994
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1072
fichinter_create
fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into FICHEINTER_ADDON_PDF.
Definition: modules_fichinter.php:171
ModelePDFFicheinter
Parent class to manage intervention document templates.
Definition: modules_fichinter.php:35
ModeleNumRefFicheinter\isEnabled
isEnabled()
Return if a module can be used or not.
Definition: modules_fichinter.php:80
ModeleNumRefFicheinter
Parent class numbering models of intervention sheet references.
Definition: modules_fichinter.php:68
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3888
getListOfModels
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
Definition: functions2.lib.php:1925
ModeleNumRefFicheinter\getExample
getExample()
Return a numbering example.
Definition: modules_fichinter.php:102
ModelePDFFicheinter\liste_modeles
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_fichinter.php:51
dol_delete_preview
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1464
ModeleNumRefFicheinter\info
info()
Returns the default description of the numbering template.
Definition: modules_fichinter.php:90
ModeleNumRefFicheinter\getVersion
getVersion()
Return the version of the numbering module.
Definition: modules_fichinter.php:138
CommonDocGenerator
Parent class for documents generators.
Definition: commondocgenerator.class.php:36