dolibarr  16.0.5
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@inodbox.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 <https://www.gnu.org/licenses/>.
20  * or see https://www.gnu.org/
21  */
22 
23 require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
24 
29 abstract class ModeleAction extends CommonDocGenerator
30 {
34  public $error = '';
35 
36  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
44  public static function liste_modeles($db, $maxfilenamelength = 0)
45  {
46  // phpcs:enable
47  global $conf;
48 
49  $type = 'action';
50  $list = array();
51 
52  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
53  $list = getListOfModels($db, $type, $maxfilenamelength);
54 
55  return $list;
56  }
57 }
58 
59 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
72 function action_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
73 {
74  // phpcs:enable
75  global $conf, $langs, $user;
76  $langs->load("action");
77 
78  $error = 0;
79 
80  $srctemplatepath = '';
81 
82  // Position modele on the name of fichinter model to use
83  if (!dol_strlen($modele)) {
84  if (!empty($conf->global->ACTION_EVENT_ADDON_PDF)) {
85  $modele = $conf->global->ACTION_EVENT_ADDON_PDF;
86  } else {
87  $modele = 'soleil';
88  }
89  }
90 
91  // If selected modele is a filename template (then $modele="modelname:filename")
92  $tmp = explode(':', $modele, 2);
93  if (!empty($tmp[1])) {
94  $modele = $tmp[0];
95  $srctemplatepath = $tmp[1];
96  }
97 
98  // Search template files
99  $file = '';
100  $classname = '';
101  $filefound = 0;
102  $dirmodels = array('/');
103  if (is_array($conf->modules_parts['models'])) {
104  $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
105  }
106  foreach ($dirmodels as $reldir) {
107  foreach (array('doc', 'pdf') as $prefix) {
108  $file = $prefix."_".$modele.".modules.php";
109 
110  // On verifie l'emplacement du modele
111  $file = dol_buildpath($reldir."core/modules/action/doc/".$file, 0);
112  if (file_exists($file)) {
113  $filefound = 1;
114  $classname = $prefix.'_'.$modele;
115  break;
116  }
117  }
118  if ($filefound) {
119  break;
120  }
121  }
122 
123  // Charge le modele
124  if ($filefound) {
125  require_once $file;
126 
127  $obj = new $classname($db);
128 
129  // We save charset_output to restore it because write_file can change it if needed for
130  // output format that does not support UTF8.
131  $sav_charset_output = $outputlangs->charset_output;
132  if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
133  $outputlangs->charset_output = $sav_charset_output;
134 
135  // We delete old preview
136  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
137  dol_delete_preview($object);
138 
139  return 1;
140  } else {
141  $outputlangs->charset_output = $sav_charset_output;
142  dol_print_error($db, "action_pdf_create Error: ".$obj->error);
143  return 0;
144  }
145  } else {
146  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
147  return 0;
148  }
149 }
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_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
ModeleAction\liste_modeles
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_action.php:44
getListOfModels
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
Definition: functions2.lib.php:1919
dol_delete_preview
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1435
CommonDocGenerator
Parent class for documents generators.
Definition: commondocgenerator.class.php:36
ModeleAction
Parent class for product models of doc generators.
Definition: modules_action.php:29