modDon.class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \defgroup don Module donations
  22. * \brief Module to manage the follow-up of the donations
  23. * \file htdocs/core/modules/modDon.class.php
  24. * \ingroup donations
  25. * \brief Description and activation file for the module Donation
  26. */
  27. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  28. /**
  29. * Class to describe and enable module Donation
  30. */
  31. class modDon extends DolibarrModules
  32. {
  33. /**
  34. * Constructor. Define names, constants, directories, boxes, permissions
  35. *
  36. * @param DoliDB $db Database handler
  37. */
  38. public function __construct($db)
  39. {
  40. $this->db = $db;
  41. $this->numero = 700;
  42. $this->family = "financial";
  43. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  44. $this->name = preg_replace('/^mod/i', '', get_class($this));
  45. $this->description = "Gestion des dons";
  46. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  47. $this->version = 'dolibarr';
  48. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  49. // Name of png file (without png) used for this module.
  50. // Png file must be in theme/yourtheme/img directory under name object_pictovalue.png.
  51. $this->picto = 'donation';
  52. // Data directories to create when module is enabled
  53. $this->dirs = array("/don/temp");
  54. // Dependancies
  55. $this->depends = array();
  56. $this->requiredby = array();
  57. // Config pages
  58. $this->config_page_url = array("donation.php@don");
  59. // Constants
  60. $this->const = array();
  61. $r = 0;
  62. $this->const[$r][0] = "DON_ADDON_MODEL";
  63. $this->const[$r][1] = "chaine";
  64. $this->const[$r][2] = "html_cerfafr";
  65. $this->const[$r][3] = 'Nom du gestionnaire de generation de recu de dons';
  66. $this->const[$r][4] = 0;
  67. $r++;
  68. $this->const[$r][0] = "DONATION_ART200";
  69. $this->const[$r][1] = "yesno";
  70. $this->const[$r][2] = "0";
  71. $this->const[$r][3] = 'Option Française - Eligibilité Art200 du CGI';
  72. $this->const[$r][4] = 0;
  73. $r++;
  74. $this->const[$r][0] = "DONATION_ART238";
  75. $this->const[$r][1] = "yesno";
  76. $this->const[$r][2] = "0";
  77. $this->const[$r][3] = 'Option Française - Eligibilité Art238 bis du CGI';
  78. $this->const[$r][4] = 0;
  79. $r++;
  80. $this->const[$r][0] = "DONATION_ART978";
  81. $this->const[$r][1] = "yesno";
  82. $this->const[$r][2] = "0";
  83. $this->const[$r][3] = 'Option Française - Eligibilité Art978 du CGI';
  84. $this->const[$r][4] = 0;
  85. $r++;
  86. $this->const[$r][0] = "DONATION_MESSAGE";
  87. $this->const[$r][1] = "chaine";
  88. $this->const[$r][2] = "Thank you";
  89. $this->const[$r][3] = 'Message affiché sur le récépissé de versements ou dons';
  90. $this->const[$r][4] = 0;
  91. $r++;
  92. $this->const[$r][0] = "DONATION_ACCOUNTINGACCOUNT";
  93. $this->const[$r][1] = "chaine";
  94. $this->const[$r][2] = "758";
  95. $this->const[$r][3] = 'Compte comptable de remise des versements ou dons';
  96. $this->const[$r][4] = 0;
  97. // Boxes
  98. $this->boxes = array();
  99. // Permissions
  100. $this->rights = array();
  101. $this->rights_class = 'don';
  102. $this->rights[1][0] = 701;
  103. $this->rights[1][1] = 'Lire les dons';
  104. $this->rights[1][2] = 'r';
  105. $this->rights[1][3] = 1;
  106. $this->rights[1][4] = 'lire';
  107. $this->rights[2][0] = 702;
  108. $this->rights[2][1] = 'Creer/modifier les dons';
  109. $this->rights[2][2] = 'w';
  110. $this->rights[2][3] = 0;
  111. $this->rights[2][4] = 'creer';
  112. $this->rights[3][0] = 703;
  113. $this->rights[3][1] = 'Supprimer les dons';
  114. $this->rights[3][2] = 'd';
  115. $this->rights[3][3] = 0;
  116. $this->rights[3][4] = 'supprimer';
  117. // Menus
  118. //-------
  119. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  120. }
  121. /**
  122. * Function called when module is enabled.
  123. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  124. * It also creates data directories
  125. *
  126. * @param string $options Options when enabling module ('', 'noboxes')
  127. * @return int 1 if OK, 0 if KO
  128. */
  129. public function init($options = '')
  130. {
  131. global $conf;
  132. $result = $this->_load_tables('/install/mysql/', 'don');
  133. if ($result < 0) {
  134. return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
  135. }
  136. $sql = array(
  137. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'donation' AND entity = ".((int) $conf->entity),
  138. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','donation',".((int) $conf->entity).")",
  139. );
  140. return $this->_init($sql, $options);
  141. }
  142. }