PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/dons/html_cerfafr.modules.php

https://github.com/asterix14/dolibarr
PHP | 164 lines | 99 code | 22 blank | 43 comment | 8 complexity | fbe1d5902f93c06bbc4c703386e818e2 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
  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 2 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. */
  18. /**
  19. * \file htdocs/core/modules/dons/html_cerfafr.modules.php
  20. * \ingroup don
  21. * \brief Formulaire de don
  22. */
  23. require_once(DOL_DOCUMENT_ROOT."/core/modules/dons/modules_don.php");
  24. require_once(DOL_DOCUMENT_ROOT."/compta/dons/class/don.class.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  26. /**
  27. \class html_cerfafr
  28. \brief Classe permettant de generer les propales au modele Azur
  29. */
  30. class html_cerfafr extends ModeleDon
  31. {
  32. /**
  33. \brief Constructeur
  34. \param db Handler acces base de donnees
  35. */
  36. function html_cerfafr($db)
  37. {
  38. global $conf,$langs;
  39. $this->db = $db;
  40. $this->name = "cerfafr";
  41. $this->description = $langs->trans('DonationsReceiptModel');
  42. // Dimension page pour format A4
  43. $this->type = 'html';
  44. }
  45. /** \brief Return if a module can be used or not
  46. * \return boolean true if module can be used
  47. */
  48. function isEnabled()
  49. {
  50. return true;
  51. }
  52. /**
  53. * Write the object to document file to disk
  54. * @param don Donation object
  55. * @param outputlangs Lang object for output language
  56. * @return int >0 if OK, <0 if KO
  57. */
  58. function write_file($don,$outputlangs)
  59. {
  60. global $user,$conf,$langs,$mysoc;
  61. $now=gmmktime();
  62. if (! is_object($outputlangs)) $outputlangs=$langs;
  63. $outputlangs->load("main");
  64. $outputlangs->load("dict");
  65. $outputlangs->load("companies");
  66. $outputlangs->load("bills");
  67. $outputlangs->load("products");
  68. if ($conf->don->dir_output)
  69. {
  70. // Definition de l'objet $don (pour compatibilite ascendante)
  71. if (! is_object($don))
  72. {
  73. $id = $don;
  74. $don = new Don($this->db);
  75. $ret=$don->fetch($id);
  76. }
  77. // Definition de $dir et $file
  78. if ($don->specimen)
  79. {
  80. $dir = $conf->don->dir_output;
  81. $file = $dir . "/SPECIMEN.html";
  82. }
  83. else
  84. {
  85. $donref = dol_sanitizeFileName($don->ref);
  86. $dir = $conf->don->dir_output . "/" . get_exdir($donref,2);
  87. $file = $dir . "/" . $donref . ".html";
  88. }
  89. if (! file_exists($dir))
  90. {
  91. if (create_exdir($dir) < 0)
  92. {
  93. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  94. return -1;
  95. }
  96. }
  97. if (file_exists($dir))
  98. {
  99. // Defini contenu
  100. $donmodel=DOL_DOCUMENT_ROOT ."/core/modules/dons/html_cerfafr.html";
  101. $form = implode('', file($donmodel));
  102. $form = str_replace('__REF__',$id,$form);
  103. $form = str_replace('__DATE__',dol_print_date($don->date,'day',false,$outputlangs),$form);
  104. $form = str_replace('__IP__',$user->ip,$form);
  105. $form = str_replace('__AMOUNT__',$don->amount,$form);
  106. $form = str_replace('__CURRENCY__',$outputlangs->transnoentitiesnoconv("Currency".$conf->monnaie),$form);
  107. $form = str_replace('__CURRENCYCODE__',$conf->monnaie,$form);
  108. $form = str_replace('__MAIN_INFO_SOCIETE_NOM__',$mysoc->name,$form);
  109. $form = str_replace('__MAIN_INFO_SOCIETE_ADRESSE__',$mysoc->address,$form);
  110. $form = str_replace('__MAIN_INFO_SOCIETE_CP__',$mysoc->zip,$form);
  111. $form = str_replace('__MAIN_INFO_SOCIETE_VILLE__',$mysoc->town,$form);
  112. $form = str_replace('__DONATOR_NAME__',$don->nom,$form);
  113. $form = str_replace('__DONATOR_ADDRESS__',$don->adresse,$form);
  114. $form = str_replace('__DONATOR_ZIP__',$don->cp,$form);
  115. $form = str_replace('__DONATOR_TOWN__',$don->ville,$form);
  116. $form = str_replace('__PAYMENTMODE_LIB__ ',$don->modepaiement,$form);
  117. $form = str_replace('__NOW__',dol_print_date($now,'',false,$outputlangs),$form);
  118. // Sauve fichier sur disque
  119. dol_syslog("html_cerfafr::write_file $file");
  120. $handle=fopen($file,"w");
  121. fwrite($handle,$form);
  122. fclose($handle);
  123. if (! empty($conf->global->MAIN_UMASK))
  124. @chmod($file, octdec($conf->global->MAIN_UMASK));
  125. return 1;
  126. }
  127. else
  128. {
  129. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  130. return 0;
  131. }
  132. }
  133. else
  134. {
  135. $this->error=$langs->trans("ErrorConstantNotDefined","DON_OUTPUTDIR");
  136. return 0;
  137. }
  138. $this->error=$langs->trans("ErrorUnknown");
  139. return 0; // Erreur par defaut
  140. }
  141. }
  142. ?>