PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/propale/modules_propale.php

https://github.com/asterix14/dolibarr
PHP | 244 lines | 129 code | 35 blank | 80 comment | 20 complexity | ad735cf2a729186eecd21a2c0baf0d2f MD5 | raw file
Possible License(s): LGPL-2.0
  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-2011 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/modules/propale/modules_propale.php
  22. * \ingroup propale
  23. * \brief Fichier contenant la classe mere de generation des propales en PDF
  24. * et la classe mere de numerotation des propales
  25. */
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); // Requis car utilise dans les classes qui heritent
  28. /**
  29. * \class ModelePDFPropales
  30. * \brief Classe mere des modeles de propale
  31. */
  32. abstract class ModelePDFPropales extends CommonDocGenerator
  33. {
  34. var $error='';
  35. /**
  36. * Return list of active generation modules
  37. * @param $db Database handler
  38. */
  39. function liste_modeles($db)
  40. {
  41. global $conf;
  42. $type='propal';
  43. $liste=array();
  44. include_once(DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php');
  45. $liste=getListOfModels($db,$type,'');
  46. return $liste;
  47. }
  48. }
  49. /**
  50. * \class ModeleNumRefPropales
  51. * \brief Classe mere des modeles de numerotation des references de propales
  52. */
  53. abstract class ModeleNumRefPropales
  54. {
  55. var $error='';
  56. /** \brief Return if a module can be used or not
  57. * \return boolean true if module can be used
  58. */
  59. function isEnabled()
  60. {
  61. return true;
  62. }
  63. /** \brief Renvoi la description par defaut du modele de numerotation
  64. * \return string Texte descripif
  65. */
  66. function info()
  67. {
  68. global $langs;
  69. $langs->load("propale");
  70. return $langs->trans("NoDescription");
  71. }
  72. /** \brief Renvoi un exemple de numerotation
  73. * \return string Example
  74. */
  75. function getExample()
  76. {
  77. global $langs;
  78. $langs->load("propale");
  79. return $langs->trans("NoExample");
  80. }
  81. /** \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de
  82. * de conflits qui empechera cette numerotation de fonctionner.
  83. * \return boolean false si conflit, true si ok
  84. */
  85. function canBeActivated()
  86. {
  87. return true;
  88. }
  89. /** \brief Renvoi prochaine valeur attribuee
  90. * \return string Valeur
  91. */
  92. function getNextValue()
  93. {
  94. global $langs;
  95. return $langs->trans("NotAvailable");
  96. }
  97. /** \brief Renvoi version du module numerotation
  98. * \return string Valeur
  99. */
  100. function getVersion()
  101. {
  102. global $langs;
  103. $langs->load("admin");
  104. if ($this->version == 'development') return $langs->trans("VersionDevelopment");
  105. if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
  106. if ($this->version == 'dolibarr') return DOL_VERSION;
  107. return $langs->trans("NotAvailable");
  108. }
  109. }
  110. /**
  111. * Create a document onto disk accordign to template module.
  112. *
  113. * @param DoliDB $db Database handler
  114. * @param Object $object Object proposal
  115. * @param string $modele Force model to use ('' to not force)
  116. * @param Translate $outputlangs Object langs to use for output
  117. * @param int $hidedetails Hide details of lines
  118. * @param int $hidedesc Hide description
  119. * @param int $hideref Hide ref
  120. * @param HookManager $hookmanager Hook manager instance
  121. * @return int 0 if KO, 1 if OK
  122. */
  123. function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
  124. {
  125. global $conf,$user,$langs;
  126. $langs->load("propale");
  127. $dir = "/core/modules/propale/";
  128. $srctemplatepath='';
  129. $modelisok=0;
  130. // Positionne le modele sur le nom du modele a utiliser
  131. if (! dol_strlen($modele))
  132. {
  133. if (! empty($conf->global->PROPALE_ADDON_PDF))
  134. {
  135. $modele = $conf->global->PROPALE_ADDON_PDF;
  136. }
  137. else
  138. {
  139. $modele = 'azur';
  140. }
  141. }
  142. // Positionne modele sur le nom du modele de propale a utiliser
  143. $file = "pdf_propale_".$modele.".modules.php";
  144. // On verifie l'emplacement du modele
  145. $file = dol_buildpath($dir.$file);
  146. if ($modele && file_exists($file)) $modelisok=1;
  147. // Si model pas encore bon
  148. if (! $modelisok)
  149. {
  150. if ($conf->global->PROPALE_ADDON_PDF) $modele = $conf->global->PROPALE_ADDON_PDF;
  151. $file = "pdf_propale_".$modele.".modules.php";
  152. // On verifie l'emplacement du modele
  153. $file = dol_buildpath($dir.$file);
  154. if (file_exists($file)) $modelisok=1;
  155. }
  156. // Si model pas encore bon
  157. if (! $modelisok && is_array($liste))
  158. {
  159. $liste=ModelePDFPropales::liste_modeles($db);
  160. $modele=key($liste); // Renvoie premiere valeur de cle trouve dans le tableau
  161. $file = "pdf_propale_".$modele.".modules.php";
  162. $file = dol_buildpath($dir.$file);
  163. if (file_exists($file)) $modelisok=1;
  164. }
  165. // Charge le modele
  166. if ($modelisok)
  167. {
  168. $classname = "pdf_propale_".$modele;
  169. require_once($file);
  170. $obj = new $classname($db);
  171. // We save charset_output to restore it because write_file can change it if needed for
  172. // output format that does not support UTF8.
  173. $sav_charset_output=$outputlangs->charset_output;
  174. if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
  175. {
  176. $outputlangs->charset_output=$sav_charset_output;
  177. // we delete preview files
  178. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  179. dol_delete_preview($object);
  180. // Appel des triggers
  181. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  182. $interface=new Interfaces($db);
  183. $result=$interface->run_triggers('PROPAL_BUILDDOC',$object,$user,$langs,$conf);
  184. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  185. // Fin appel triggers
  186. return 1;
  187. }
  188. else
  189. {
  190. $outputlangs->charset_output=$sav_charset_output;
  191. dol_syslog("modules_propale::propale_pdf_create error");
  192. dol_print_error($db,$obj->error);
  193. return 0;
  194. }
  195. }
  196. else
  197. {
  198. if (! $conf->global->PROPALE_ADDON_PDF)
  199. {
  200. print $langs->trans("Error")." ".$langs->trans("Error_PROPALE_ADDON_PDF_NotDefined");
  201. }
  202. else
  203. {
  204. print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
  205. }
  206. return 0;
  207. }
  208. }
  209. ?>