modules_task.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2010 Florian Henry <florian.henry<àopen-concept.pro>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/project/task/modules_task.php
  21. * \ingroup project
  22. * \brief File that contain parent class for task models
  23. * and parent class for task numbering models
  24. */
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
  26. /**
  27. * Parent class for projects models
  28. */
  29. abstract class ModelePDFTask extends CommonDocGenerator
  30. {
  31. var $error='';
  32. /**
  33. * Return list of active generation modules
  34. *
  35. * @param DoliDB $db Database handler
  36. * @param string $maxfilenamelength Max length of value to show
  37. * @return array List of templates
  38. */
  39. static function liste_modeles($db,$maxfilenamelength=0)
  40. {
  41. global $conf;
  42. $type='project_task';
  43. $liste=array();
  44. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  45. $liste=getListOfModels($db,$type,$maxfilenamelength);
  46. return $liste;
  47. }
  48. }
  49. /**
  50. * Classe mere des modeles de numerotation des references de projets
  51. */
  52. abstract class ModeleNumRefTask
  53. {
  54. var $error='';
  55. /**
  56. * Return if a module can be used or not
  57. *
  58. * @return boolean true if module can be used
  59. */
  60. function isEnabled()
  61. {
  62. return true;
  63. }
  64. /**
  65. * Renvoi la description par defaut du modele de numerotation
  66. *
  67. * @return string Texte descripif
  68. */
  69. function info()
  70. {
  71. global $langs;
  72. $langs->load("projects");
  73. return $langs->trans("NoDescription");
  74. }
  75. /**
  76. * Renvoi un exemple de numerotation
  77. *
  78. * @return string Example
  79. */
  80. function getExample()
  81. {
  82. global $langs;
  83. $langs->load("projects");
  84. return $langs->trans("NoExample");
  85. }
  86. /**
  87. * Test si les numeros deja en vigueur dans la base ne provoquent pas de
  88. * de conflits qui empechera cette numerotation de fonctionner.
  89. *
  90. * @return boolean false si conflit, true si ok
  91. */
  92. function canBeActivated()
  93. {
  94. return true;
  95. }
  96. /**
  97. * Renvoi prochaine valeur attribuee
  98. *
  99. * @param Societe $objsoc Object third party
  100. * @param Project $project Object project
  101. * @return string Valeur
  102. */
  103. function getNextValue($objsoc, $project)
  104. {
  105. global $langs;
  106. return $langs->trans("NotAvailable");
  107. }
  108. /**
  109. * Renvoi version du module numerotation
  110. *
  111. * @return string Valeur
  112. */
  113. function getVersion()
  114. {
  115. global $langs;
  116. $langs->load("admin");
  117. if ($this->version == 'development') return $langs->trans("VersionDevelopment");
  118. if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
  119. if ($this->version == 'dolibarr') return DOL_VERSION;
  120. return $langs->trans("NotAvailable");
  121. }
  122. }
  123. /**
  124. * Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF
  125. *
  126. * @param DoliDB $db objet base de donnee
  127. * @param Object $object Object fichinter
  128. * @param string $modele force le modele a utiliser ('' par defaut)
  129. * @param Translate $outputlangs objet lang a utiliser pour traduction
  130. * @param int $hidedetails Hide details of lines
  131. * @param int $hidedesc Hide description
  132. * @param int $hideref Hide ref
  133. * @param HookManager $hookmanager Hook manager instance
  134. * @return int 0 if KO, 1 if OK
  135. */
  136. function task_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
  137. {
  138. global $conf,$langs;
  139. $langs->load("projects");
  140. $error=0;
  141. $srctemplatepath='';
  142. // Positionne modele sur le nom du modele de projet a utiliser
  143. if (! dol_strlen($modele))
  144. {
  145. if (! empty($conf->global->PROJECT_TASK_ADDON_PDF))
  146. {
  147. $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
  148. }
  149. else
  150. {
  151. $modele='nodefault';
  152. }
  153. }
  154. // If selected modele is a filename template (then $modele="modelname:filename")
  155. $tmp=explode(':',$modele,2);
  156. if (! empty($tmp[1]))
  157. {
  158. $modele=$tmp[0];
  159. $srctemplatepath=$tmp[1];
  160. }
  161. // Search template files
  162. $file=''; $classname=''; $filefound=0;
  163. $dirmodels=array('/');
  164. if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
  165. foreach($dirmodels as $reldir)
  166. {
  167. foreach(array('doc','pdf') as $prefix)
  168. {
  169. $file = $prefix."_".$modele.".modules.php";
  170. // On verifie l'emplacement du modele
  171. $file=dol_buildpath($reldir."core/modules/project/task/pdf/".$file,0);
  172. if (file_exists($file))
  173. {
  174. $filefound=1;
  175. $classname=$prefix.'_'.$modele;
  176. break;
  177. }
  178. }
  179. if ($filefound) break;
  180. }
  181. // Charge le modele
  182. if ($filefound)
  183. {
  184. require_once $file;
  185. $obj = new $classname($db);
  186. // We save charset_output to restore it because write_file can change it if needed for
  187. // output format that does not support UTF8.
  188. $sav_charset_output=$outputlangs->charset_output;
  189. if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
  190. {
  191. $outputlangs->charset_output=$sav_charset_output;
  192. // we delete preview files
  193. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  194. dol_delete_preview($object);
  195. // Success in building document. We build meta file.
  196. dol_meta_create($object);
  197. // Appel des triggers
  198. /*include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  199. $interface=new Interfaces($db);
  200. $result=$interface->run_triggers('PROJECT_BUILDDOC',$object,$user,$langs,$conf);
  201. if ($result < 0) { $error++; $this->errors=$interface->errors; }*/
  202. // Fin appel triggers
  203. return 1;
  204. }
  205. else
  206. {
  207. $outputlangs->charset_output=$sav_charset_output;
  208. dol_print_error($db,"task_pdf_create Error: ".$obj->error);
  209. return 0;
  210. }
  211. }
  212. else
  213. {
  214. print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
  215. return 0;
  216. }
  217. }