dolibarr  7.0.0-beta
modules_action.php
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.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 <http://www.gnu.org/licenses/>.
20  * or see http://www.gnu.org/
21  */
22 
23 require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
24 
29 abstract class ModeleAction extends CommonDocGenerator
30 {
31  var $error='';
32 
40  static function liste_modeles($db,$maxfilenamelength=0)
41  {
42  global $conf;
43 
44  $type='action';
45  $liste=array();
46 
47  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
48  $liste=getListOfModels($db,$type,$maxfilenamelength);
49 
50  return $liste;
51  }
52 }
65 function action_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
66 {
67  global $conf,$langs,$user;
68  $langs->load("action");
69 
70  $error=0;
71 
72  $srctemplatepath='';
73 
74  // Positionne modele sur le nom du modele de fichinter a utiliser
75  if (! dol_strlen($modele))
76  {
77  if (! empty($conf->global->ACTION_EVENT_ADDON_PDF))
78  {
79  $modele = $conf->global->ACTION_EVENT_ADDON_PDF;
80  }
81  else
82  {
83  $modele = 'soleil';
84  }
85  }
86 
87  // If selected modele is a filename template (then $modele="modelname:filename")
88  $tmp=explode(':',$modele,2);
89  if (! empty($tmp[1]))
90  {
91  $modele=$tmp[0];
92  $srctemplatepath=$tmp[1];
93  }
94 
95  // Search template files
96  $file=''; $classname=''; $filefound=0;
97  $dirmodels=array('/');
98  if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
99  foreach($dirmodels as $reldir)
100  {
101  foreach(array('doc','pdf') as $prefix)
102  {
103  $file = $prefix."_".$modele.".modules.php";
104 
105  // On verifie l'emplacement du modele
106  $file=dol_buildpath($reldir."core/modules/action/doc/".$file,0);
107  if (file_exists($file))
108  {
109  $filefound=1;
110  $classname=$prefix.'_'.$modele;
111  break;
112  }
113  }
114  if ($filefound) break;
115  }
116 
117  // Charge le modele
118  if ($filefound)
119  {
120  require_once $file;
121 
122  $obj = new $classname($db);
123 
124  // We save charset_output to restore it because write_file can change it if needed for
125  // output format that does not support UTF8.
126  $sav_charset_output=$outputlangs->charset_output;
127  if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
128  {
129  $outputlangs->charset_output=$sav_charset_output;
130 
131  // We delete old preview
132  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
133  dol_delete_preview($object);
134 
135  return 1;
136  }
137  else
138  {
139  $outputlangs->charset_output=$sav_charset_output;
140  dol_print_error($db,"action_pdf_create Error: ".$obj->error);
141  return 0;
142  }
143  }
144  else
145  {
146  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
147  return 0;
148  }
149 }
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1283
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
print
Draft customers invoices.
Definition: index.php:91
Parent class for documents generators.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
Parent class for product models of doc generators.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.