PageRenderTime 85ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/project/modules_project.php

https://github.com/asterix14/dolibarr
PHP | 199 lines | 98 code | 27 blank | 74 comment | 10 complexity | ef3e5ff9295ceacf4a1b8e1f6378f197 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/project/modules_project.php
  20. * \ingroup project
  21. * \brief File that contain parent class for projects models
  22. * and parent class for projects numbering models
  23. */
  24. require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php");
  25. /**
  26. * \class ModelePDFProjects
  27. * \brief Parent class for projects models
  28. */
  29. abstract class ModelePDFProjects extends CommonDocGenerator
  30. {
  31. var $error='';
  32. /**
  33. * \brief Return list of active generation modules
  34. * \param $db Database handler
  35. */
  36. function liste_modeles($db)
  37. {
  38. global $conf;
  39. $type='project';
  40. $liste=array();
  41. include_once(DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php');
  42. $liste=getListOfModels($db,$type,'');
  43. return $liste;
  44. }
  45. }
  46. /**
  47. * \class ModeleNumRefProjects
  48. * \brief Classe mere des modeles de numerotation des references de projets
  49. */
  50. abstract class ModeleNumRefProjects
  51. {
  52. var $error='';
  53. /**
  54. * \brief Return if a module can be used or not
  55. * \return boolean true if module can be used
  56. */
  57. function isEnabled()
  58. {
  59. return true;
  60. }
  61. /**
  62. * \brief Renvoi la description par defaut du modele de numerotation
  63. * \return string Texte descripif
  64. */
  65. function info()
  66. {
  67. global $langs;
  68. $langs->load("projects");
  69. return $langs->trans("NoDescription");
  70. }
  71. /**
  72. * \brief Renvoi un exemple de numerotation
  73. * \return string Example
  74. */
  75. function getExample()
  76. {
  77. global $langs;
  78. $langs->load("projects");
  79. return $langs->trans("NoExample");
  80. }
  81. /**
  82. * \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de
  83. * de conflits qui empechera cette numerotation de fonctionner.
  84. * \return boolean false si conflit, true si ok
  85. */
  86. function canBeActivated()
  87. {
  88. return true;
  89. }
  90. /**
  91. * \brief Renvoi prochaine valeur attribuee
  92. * \return string Valeur
  93. */
  94. function getNextValue()
  95. {
  96. global $langs;
  97. return $langs->trans("NotAvailable");
  98. }
  99. /**
  100. * \brief Renvoi version du module numerotation
  101. * \return string Valeur
  102. */
  103. function getVersion()
  104. {
  105. global $langs;
  106. $langs->load("admin");
  107. if ($this->version == 'development') return $langs->trans("VersionDevelopment");
  108. if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
  109. if ($this->version == 'dolibarr') return DOL_VERSION;
  110. return $langs->trans("NotAvailable");
  111. }
  112. }
  113. /**
  114. * Create object on disk
  115. * @param db objet base de donnee
  116. * @param object object project
  117. * @param model force le modele a utiliser ('' to not force)
  118. * @param outputlangs objet lang a utiliser pour traduction
  119. * @return int 0 si KO, 1 si OK
  120. */
  121. function project_pdf_create($db, $object, $model,$outputlangs)
  122. {
  123. global $conf,$langs;
  124. $langs->load("projects");
  125. $dir = DOL_DOCUMENT_ROOT."/core/modules/project/pdf/";
  126. // Positionne modele sur le nom du modele de projet a utiliser
  127. if (! dol_strlen($model))
  128. {
  129. if (! empty($conf->global->PROJECT_ADDON_PDF))
  130. {
  131. $model = $conf->global->PROJECT_ADDON_PDF;
  132. }
  133. else
  134. {
  135. $model='baleine';
  136. //print $langs->trans("Error")." ".$langs->trans("Error_PROJECT_ADDON_PDF_NotDefined");
  137. //return 0;
  138. }
  139. }
  140. // Charge le modele
  141. $file = "pdf_".$model.".modules.php";
  142. if (file_exists($dir.$file))
  143. {
  144. $classname = "pdf_".$model;
  145. require_once($dir.$file);
  146. $obj = new $classname($db);
  147. // We save charset_output to restore it because write_file can change it if needed for
  148. // output format that does not support UTF8.
  149. $sav_charset_output=$outputlangs->charset_output;
  150. if ($obj->write_file($object,$outputlangs) > 0)
  151. {
  152. $outputlangs->charset_output=$sav_charset_output;
  153. // we delete preview files
  154. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  155. dol_delete_preview($object);
  156. return 1;
  157. }
  158. else
  159. {
  160. $outputlangs->charset_output=$sav_charset_output;
  161. dol_syslog("Erreur dans project_pdf_create");
  162. dol_print_error($db,$obj->error);
  163. return 0;
  164. }
  165. }
  166. else
  167. {
  168. print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file);
  169. return 0;
  170. }
  171. }
  172. ?>