modBarcode.class.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  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 barcode Module barcode
  22. * \brief Module pour gerer les codes barres
  23. * \file htdocs/core/modules/modBarcode.class.php
  24. * \ingroup barcode, product
  25. * \brief Description and activation file for the module barcode
  26. */
  27. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  28. /**
  29. * Class to describe Barcode
  30. */
  31. class modBarcode 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 = 55;
  42. $this->family = "technic";
  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 codes barres";
  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. $this->picto = 'barcode';
  50. // Data directories to create when module is enabled
  51. $this->dirs = array("/barcode/temp");
  52. // Dependencies
  53. $this->depends = array(); // May be used for product or service or third party module
  54. $this->requiredby = array();
  55. // Config pages
  56. $this->config_page_url = array("barcode.php");
  57. // Constants
  58. // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
  59. // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
  60. $this->const = array();
  61. //$this->const[0] = array('BARCODE_LABEL_LEFT_TEXT','chaine','%BARCODE%','Print barcode on left side of label',1);
  62. //$this->const[1] = array('BARCODE_LABEL_RIGHT_TEXT','chaine','%LOGO%','Print Company logo on right side',1);
  63. //$this->const[2] = array('BARCODE_LABEL_HEADER_TEXT','chaine','My header','Print header text on label',1);
  64. //$this->const[3] = array('BARCODE_LABEL_FOOTER_TEXT','chaine','My footer','Print footer text on label',1);
  65. // Boxes
  66. $this->boxes = array();
  67. // Permissions
  68. $this->rights = array();
  69. $this->rights_class = 'barcode';
  70. $r = 0;
  71. $this->rights[$r][0] = 301; // id de la permission
  72. $this->rights[$r][1] = 'Generate PDF sheets of barcodes'; // libelle de la permission
  73. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  74. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  75. $this->rights[$r][4] = 'read';
  76. $r++;
  77. $this->rights[$r][0] = 304; // id de la permission
  78. $this->rights[$r][1] = 'Read barcodes'; // libelle de la permission
  79. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  80. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  81. $this->rights[$r][4] = 'lire_advance';
  82. $r++;
  83. $this->rights[$r][0] = 305; // id de la permission
  84. $this->rights[$r][1] = 'Create/modify barcodes'; // libelle de la permission
  85. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  86. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  87. $this->rights[$r][4] = 'creer_advance';
  88. $r++;
  89. // Main menu entries
  90. $r = 0;
  91. // A menu entry for the Tools top menu
  92. $this->menu[$r] = array(
  93. 'fk_menu'=>'fk_mainmenu=tools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  94. 'mainmenu'=>'tools',
  95. 'leftmenu'=>'barcodeprint',
  96. 'type'=>'left', // This is a Left menu entry
  97. 'titre'=>'BarCodePrintsheet',
  98. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
  99. 'url'=>'/barcode/printsheet.php?mainmenu=tools&leftmenu=barcodeprint',
  100. 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  101. 'position'=>200,
  102. 'enabled'=>'isModEnabled("barcode")', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
  103. 'perms'=>'$user->hasRight("barcode", "read")',
  104. 'target'=>'',
  105. 'user'=>0, // 0=Menu for internal users, 1=external users, 2=both
  106. );
  107. $r++;
  108. // A menu entry for the left menu
  109. $this->menu[$r] = array(
  110. 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  111. 'type'=>'left', // This is a Left menu entry
  112. 'titre'=>'MassBarcodeInit',
  113. 'url'=>'/barcode/codeinit.php?mainmenu=home&leftmenu=admintools',
  114. 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  115. 'position'=>300,
  116. 'enabled'=>'isModEnabled("barcode") && preg_match(\'/^(admintools|all)/\',$leftmenu)', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
  117. 'perms'=>'$user->admin',
  118. 'target'=>'',
  119. 'user'=>0, // 0=Menu for internal users, 1=external users, 2=both
  120. );
  121. $r++;
  122. }
  123. /**
  124. * Function called when module is enabled.
  125. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  126. * It also creates data directories.
  127. *
  128. * @param string $options Options when enabling module ('', 'noboxes')
  129. * @return int 1 if OK, 0 if KO
  130. */
  131. public function init($options = '')
  132. {
  133. // Permissions
  134. $this->remove($options);
  135. $sql = array(
  136. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('EAN8', 'EAN8', 0, '1234567', __ENTITY__)", 'ignoreerror'=>1),
  137. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('EAN13', 'EAN13', 0, '123456789012', __ENTITY__)", 'ignoreerror'=>1),
  138. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('UPC', 'UPC', 0, '123456789012', __ENTITY__)", 'ignoreerror'=>1),
  139. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('ISBN', 'ISBN', 0, '123456789', __ENTITY__)", 'ignoreerror'=>1),
  140. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C39', 'Code 39', 0, '1234567890', __ENTITY__)", 'ignoreerror'=>1),
  141. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C128', 'Code 128', 0, 'ABCD1234567890', __ENTITY__)", 'ignoreerror'=>1),
  142. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('DATAMATRIX', 'Datamatrix', 0, '1234567xyz', __ENTITY__)", 'ignoreerror'=>1),
  143. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('QRCODE', 'Qr Code', 0, 'www.dolibarr.org', __ENTITY__)", 'ignoreerror'=>1)
  144. );
  145. return $this->_init($sql, $options);
  146. }
  147. }