modSupplierProposal.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \defgroup supplier_proposal Module supplier_proposal
  24. * \brief Module to request supplier price proposals
  25. *
  26. * \file htdocs/core/modules/modSupplierProposal.class.php
  27. * \ingroup supplier_proposal
  28. * \brief Description and activation file for the module supplier proposal
  29. */
  30. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  31. /**
  32. * Class to describe and enable module SupplierProposal
  33. */
  34. class modSupplierProposal extends DolibarrModules
  35. {
  36. /**
  37. * Constructor. Define names, constants, directories, boxes, permissions
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. public function __construct($db)
  42. {
  43. global $conf;
  44. $this->db = $db;
  45. $this->numero = 1120;
  46. $this->family = "srm";
  47. $this->module_position = '35';
  48. $this->name = preg_replace('/^mod/i', '', get_class($this));
  49. $this->description = "supplier_proposalDESC";
  50. $this->version = 'dolibarr';
  51. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  52. $this->picto = 'supplier_proposal';
  53. // Data directories to create when module is enabled.
  54. $this->dirs = array();
  55. // Config pages. Put here list of php page names stored in admin directory used to setup module.
  56. $this->config_page_url = array("supplier_proposal.php");
  57. // Dependencies
  58. $this->hidden = false; // A condition to hide module
  59. $this->depends = array('modFournisseur'); // List of module class names as string that must be enabled if this module is enabled
  60. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  61. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  62. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  63. $this->langfiles = array("supplier_proposal");
  64. // Constants
  65. $this->const = array();
  66. $r = 0;
  67. $this->const[$r][0] = "SUPPLIER_PROPOSAL_ADDON_PDF";
  68. $this->const[$r][1] = "chaine";
  69. $this->const[$r][2] = "aurore";
  70. $this->const[$r][3] = 'Name of submodule to generate PDF for supplier quotation request';
  71. $this->const[$r][4] = 0;
  72. $r++;
  73. $this->const[$r][0] = "SUPPLIER_PROPOSAL_ADDON";
  74. $this->const[$r][1] = "chaine";
  75. $this->const[$r][2] = "mod_supplier_proposal_marbre";
  76. $this->const[$r][3] = 'Name of submodule to number supplier quotation request';
  77. $this->const[$r][4] = 0;
  78. $r++;
  79. $this->const[$r][0] = "SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH";
  80. $this->const[$r][1] = "chaine";
  81. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/supplier_proposals";
  82. $this->const[$r][3] = "";
  83. $this->const[$r][4] = 0;
  84. // Boxes
  85. $this->boxes = array();
  86. // Permissions
  87. $this->rights = array();
  88. $this->rights_class = 'supplier_proposal';
  89. $r = 0;
  90. $r++;
  91. $this->rights[$r][0] = $this->numero + $r; // id de la permission
  92. $this->rights[$r][1] = 'Read supplier proposals'; // libelle de la permission
  93. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  94. $this->rights[$r][4] = 'lire';
  95. $r++;
  96. $this->rights[$r][0] = $this->numero + $r; // id de la permission
  97. $this->rights[$r][1] = 'Create/modify supplier proposals'; // libelle de la permission
  98. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  99. $this->rights[$r][4] = 'creer';
  100. $r++;
  101. $this->rights[$r][0] = $this->numero + $r; // id de la permission
  102. $this->rights[$r][1] = 'Validate supplier proposals'; // libelle de la permission
  103. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  104. $this->rights[$r][4] = 'validate_advance';
  105. $r++;
  106. $this->rights[$r][0] = $this->numero + $r; // id de la permission
  107. $this->rights[$r][1] = 'Envoyer les demandes fournisseurs'; // libelle de la permission
  108. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  109. $this->rights[$r][4] = 'send_advance';
  110. $r++;
  111. $this->rights[$r][0] = $this->numero + $r; // id de la permission
  112. $this->rights[$r][1] = 'Delete supplier proposals'; // libelle de la permission
  113. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  114. $this->rights[$r][4] = 'supprimer';
  115. $r++;
  116. $this->rights[$r][0] = $this->numero + $r; // id de la permission
  117. $this->rights[$r][1] = 'Close supplier price requests'; // libelle de la permission
  118. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  119. $this->rights[$r][4] = 'cloturer';
  120. // Main menu entries
  121. $this->menu = array(); // List of menus to add
  122. $r = 0;
  123. }
  124. /**
  125. * Function called when module is enabled.
  126. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  127. * It also creates data directories
  128. *
  129. * @param string $options Options when enabling module ('', 'noboxes')
  130. * @return int 1 if OK, 0 if KO
  131. */
  132. public function init($options = '')
  133. {
  134. global $conf, $langs;
  135. // Remove permissions and default values
  136. $this->remove($options);
  137. //ODT template
  138. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_proposals/template_supplier_proposal.odt';
  139. $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_proposals';
  140. $dest = $dirodt.'/template_supplier_proposal.odt';
  141. if (file_exists($src) && !file_exists($dest)) {
  142. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  143. dol_mkdir($dirodt);
  144. $result = dol_copy($src, $dest, 0, 0);
  145. if ($result < 0) {
  146. $langs->load("errors");
  147. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  148. return 0;
  149. }
  150. }
  151. $sql = array(
  152. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'supplier_proposal' AND entity = ".$conf->entity,
  153. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','supplier_proposal',".$conf->entity.")",
  154. );
  155. return $this->_init($sql, $options);
  156. }
  157. /**
  158. * Function called when module is disabled.
  159. * Remove from database constants, boxes and permissions from Dolibarr database.
  160. * Data directories are not deleted
  161. *
  162. * @param string $options Options when enabling module ('', 'noboxes')
  163. * @return int 1 if OK, 0 if KO
  164. */
  165. public function remove($options = '')
  166. {
  167. $sql = array(
  168. "DELETE FROM ".MAIN_DB_PREFIX."rights_def WHERE module = 'askpricesupplier'" // To delete/clean deprecated entries
  169. );
  170. return $this->_remove($sql, $options);
  171. }
  172. }