modules_project.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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. * Parent class for projects models
  27. */
  28. abstract class ModelePDFProjects extends CommonDocGenerator
  29. {
  30. var $error='';
  31. /**
  32. * Return list of active generation modules
  33. *
  34. * @param DoliDB $db Database handler
  35. * @param string $maxfilenamelength Max length of value to show
  36. * @return array List of templates
  37. */
  38. static function liste_modeles($db,$maxfilenamelength=0)
  39. {
  40. global $conf;
  41. $type='project';
  42. $liste=array();
  43. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  44. $liste=getListOfModels($db,$type,$maxfilenamelength);
  45. return $liste;
  46. }
  47. }
  48. /**
  49. * Classe mere des modeles de numerotation des references de projets
  50. */
  51. abstract class ModeleNumRefProjects
  52. {
  53. var $error='';
  54. /**
  55. * Return if a module can be used or not
  56. *
  57. * @return boolean true if module can be used
  58. */
  59. function isEnabled()
  60. {
  61. return true;
  62. }
  63. /**
  64. * Renvoi la description par defaut du modele de numerotation
  65. *
  66. * @return string Texte descripif
  67. */
  68. function info()
  69. {
  70. global $langs;
  71. $langs->load("projects");
  72. return $langs->trans("NoDescription");
  73. }
  74. /**
  75. * Renvoi un exemple de numerotation
  76. *
  77. * @return string Example
  78. */
  79. function getExample()
  80. {
  81. global $langs;
  82. $langs->load("projects");
  83. return $langs->trans("NoExample");
  84. }
  85. /**
  86. * Test si les numeros deja en vigueur dans la base ne provoquent pas de
  87. * de conflits qui empechera cette numerotation de fonctionner.
  88. *
  89. * @return boolean false si conflit, true si ok
  90. */
  91. function canBeActivated()
  92. {
  93. return true;
  94. }
  95. /**
  96. * Renvoi prochaine valeur attribuee
  97. *
  98. * @param Societe $objsoc Object third party
  99. * @param Project $project Object project
  100. * @return string Valeur
  101. */
  102. function getNextValue($objsoc, $project)
  103. {
  104. global $langs;
  105. return $langs->trans("NotAvailable");
  106. }
  107. /**
  108. * Renvoi version du module numerotation
  109. *
  110. * @return string Valeur
  111. */
  112. function getVersion()
  113. {
  114. global $langs;
  115. $langs->load("admin");
  116. if ($this->version == 'development') return $langs->trans("VersionDevelopment");
  117. if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
  118. if ($this->version == 'dolibarr') return DOL_VERSION;
  119. return $langs->trans("NotAvailable");
  120. }
  121. }
  122. /**
  123. * Create an intervention document on disk using template defined into PROJECT_ADDON_PDF
  124. *
  125. * @param DoliDB $db objet base de donnee
  126. * @param Object $object Object fichinter
  127. * @param string $modele force le modele a utiliser ('' par defaut)
  128. * @param Translate $outputlangs objet lang a utiliser pour traduction
  129. * @param int $hidedetails Hide details of lines
  130. * @param int $hidedesc Hide description
  131. * @param int $hideref Hide ref
  132. * @return int 0 if KO, 1 if OK
  133. */
  134. function project_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
  135. {
  136. global $conf,$langs;
  137. $langs->load("projects");
  138. $error=0;
  139. $srctemplatepath='';
  140. // Positionne modele sur le nom du modele de projet a utiliser
  141. if (! dol_strlen($modele))
  142. {
  143. if (! empty($conf->global->PROJECT_ADDON_PDF))
  144. {
  145. $modele = $conf->global->PROJECT_ADDON_PDF;
  146. }
  147. else
  148. {
  149. $modele='baleine';
  150. }
  151. }
  152. // If selected modele is a filename template (then $modele="modelname:filename")
  153. $tmp=explode(':',$modele,2);
  154. if (! empty($tmp[1]))
  155. {
  156. $modele=$tmp[0];
  157. $srctemplatepath=$tmp[1];
  158. }
  159. // Search template files
  160. $file=''; $classname=''; $filefound=0;
  161. $dirmodels=array('/');
  162. if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
  163. foreach($dirmodels as $reldir)
  164. {
  165. foreach(array('doc','pdf') as $prefix)
  166. {
  167. $file = $prefix."_".$modele.".modules.php";
  168. // On verifie l'emplacement du modele
  169. $file=dol_buildpath($reldir."core/modules/project/pdf/".$file,0);
  170. if (file_exists($file))
  171. {
  172. $filefound=1;
  173. $classname=$prefix.'_'.$modele;
  174. break;
  175. }
  176. }
  177. if ($filefound) break;
  178. }
  179. // Charge le modele
  180. if ($filefound)
  181. {
  182. require_once $file;
  183. $obj = new $classname($db);
  184. // We save charset_output to restore it because write_file can change it if needed for
  185. // output format that does not support UTF8.
  186. $sav_charset_output=$outputlangs->charset_output;
  187. if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
  188. {
  189. $outputlangs->charset_output=$sav_charset_output;
  190. // we delete preview files
  191. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  192. dol_delete_preview($object);
  193. // Success in building document. We build meta file.
  194. dol_meta_create($object);
  195. // Appel des triggers
  196. /*include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  197. $interface=new Interfaces($db);
  198. $result=$interface->run_triggers('PROJECT_BUILDDOC',$object,$user,$langs,$conf);
  199. if ($result < 0) { $error++; $this->errors=$interface->errors; }*/
  200. // Fin appel triggers
  201. return 1;
  202. }
  203. else
  204. {
  205. $outputlangs->charset_output=$sav_charset_output;
  206. dol_print_error($db,"project_pdf_create Error: ".$obj->error);
  207. return 0;
  208. }
  209. }
  210. else
  211. {
  212. print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
  213. return 0;
  214. }
  215. }