modules_fichinter.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. /**
  22. * \file htdocs/core/modules/fichinter/modules_fichinter.php
  23. * \ingroup ficheinter
  24. * \brief File that contains parent class for PDF interventions models
  25. * and parent class for interventions numbering models
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
  28. /**
  29. * Parent class to manage intervention document templates
  30. */
  31. abstract class ModelePDFFicheinter extends CommonDocGenerator
  32. {
  33. /**
  34. * @var string Error code (or message)
  35. */
  36. public $error = '';
  37. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  38. /**
  39. * Return list of active generation modules
  40. *
  41. * @param DoliDB $db Database handler
  42. * @param integer $maxfilenamelength Max length of value to show
  43. * @return array List of templates
  44. */
  45. public static function liste_modeles($db, $maxfilenamelength = 0)
  46. {
  47. // phpcs:enable
  48. global $conf;
  49. $type = 'ficheinter';
  50. $list = array();
  51. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  52. $list = getListOfModels($db, $type, $maxfilenamelength);
  53. return $list;
  54. }
  55. }
  56. /**
  57. * Parent class numbering models of intervention sheet references
  58. */
  59. abstract class ModeleNumRefFicheinter
  60. {
  61. /**
  62. * @var string Error code (or message)
  63. */
  64. public $error = '';
  65. /**
  66. * Return if a module can be used or not
  67. *
  68. * @return boolean true if module can be used
  69. */
  70. public function isEnabled()
  71. {
  72. return true;
  73. }
  74. /**
  75. * Returns the default description of the numbering template
  76. *
  77. * @return string Descriptive text
  78. */
  79. public function info()
  80. {
  81. global $langs;
  82. $langs->load("ficheinter");
  83. return $langs->trans("NoDescription");
  84. }
  85. /**
  86. * Return a numbering example
  87. *
  88. * @return string Example
  89. */
  90. public function getExample()
  91. {
  92. global $langs;
  93. $langs->load("ficheinter");
  94. return $langs->trans("NoExample");
  95. }
  96. /**
  97. * Checks if the numbers already in the database do not
  98. * cause conflicts that would prevent this numbering working.
  99. *
  100. * @return boolean false if conflict, true if ok
  101. */
  102. public function canBeActivated()
  103. {
  104. return true;
  105. }
  106. /**
  107. * Return the next assigned value
  108. *
  109. * @param Societe $objsoc Object thirdparty
  110. * @param Object $object Object we need next value for
  111. * @return string Value if KO, <0 if KO
  112. */
  113. public function getNextValue($objsoc = 0, $object = '')
  114. {
  115. global $langs;
  116. return $langs->trans("NotAvailable");
  117. }
  118. /**
  119. * Return the version of the numbering module
  120. *
  121. * @return string Value
  122. */
  123. public function getVersion()
  124. {
  125. global $langs;
  126. $langs->load("admin");
  127. if ($this->version == 'development') {
  128. return $langs->trans("VersionDevelopment");
  129. } elseif ($this->version == 'experimental') {
  130. return $langs->trans("VersionExperimental");
  131. } elseif ($this->version == 'dolibarr') {
  132. return DOL_VERSION;
  133. } elseif ($this->version) {
  134. return $this->version;
  135. } else {
  136. return $langs->trans("NotAvailable");
  137. }
  138. }
  139. }
  140. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  141. /**
  142. * Create an intervention document on disk using template defined into FICHEINTER_ADDON_PDF
  143. *
  144. * @param DoliDB $db objet base de donnee
  145. * @param Object $object Object fichinter
  146. * @param string $modele force le modele a utiliser ('' par defaut)
  147. * @param Translate $outputlangs objet lang a utiliser pour traduction
  148. * @param int $hidedetails Hide details of lines
  149. * @param int $hidedesc Hide description
  150. * @param int $hideref Hide ref
  151. * @return int 0 if KO, 1 if OK
  152. */
  153. function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  154. {
  155. // phpcs:enable
  156. global $conf, $langs, $user;
  157. $langs->load("ficheinter");
  158. $error = 0;
  159. $srctemplatepath = '';
  160. // Positionne modele sur le nom du modele de fichinter a utiliser
  161. if (!dol_strlen($modele)) {
  162. if (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
  163. $modele = $conf->global->FICHEINTER_ADDON_PDF;
  164. } else {
  165. $modele = 'soleil';
  166. }
  167. }
  168. // If selected modele is a filename template (then $modele="modelname:filename")
  169. $tmp = explode(':', $modele, 2);
  170. if (!empty($tmp[1])) {
  171. $modele = $tmp[0];
  172. $srctemplatepath = $tmp[1];
  173. }
  174. // Search template files
  175. $file = '';
  176. $classname = '';
  177. $filefound = 0;
  178. $dirmodels = array('/');
  179. if (is_array($conf->modules_parts['models'])) {
  180. $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
  181. }
  182. foreach ($dirmodels as $reldir) {
  183. foreach (array('doc', 'pdf') as $prefix) {
  184. $file = $prefix."_".$modele.".modules.php";
  185. // On verifie l'emplacement du modele
  186. $file = dol_buildpath($reldir."core/modules/fichinter/doc/".$file, 0);
  187. if (file_exists($file)) {
  188. $filefound = 1;
  189. $classname = $prefix.'_'.$modele;
  190. break;
  191. }
  192. }
  193. if ($filefound) {
  194. break;
  195. }
  196. }
  197. // Charge le modele
  198. if ($filefound) {
  199. require_once $file;
  200. $obj = new $classname($db);
  201. // We save charset_output to restore it because write_file can change it if needed for
  202. // output format that does not support UTF8.
  203. $sav_charset_output = $outputlangs->charset_output;
  204. if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
  205. $outputlangs->charset_output = $sav_charset_output;
  206. // We delete old preview
  207. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  208. dol_delete_preview($object);
  209. return 1;
  210. } else {
  211. $outputlangs->charset_output = $sav_charset_output;
  212. dol_print_error($db, "fichinter_pdf_create Error: ".$obj->error);
  213. return 0;
  214. }
  215. } else {
  216. print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
  217. return 0;
  218. }
  219. }