modBarcode.class.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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@capnetworks.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 <http://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,produit
  25. * \brief Fichier de description et activation du 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. 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. $this->version = 'dolibarr'; // 'development' or 'experimental' or 'dolibarr' or version
  47. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  48. $this->special = 2;
  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. $this->rights[1][0] = 300; // id de la permission
  71. $this->rights[1][1] = 'Read barcodes'; // libelle de la permission
  72. $this->rights[1][2] = 'r'; // type de la permission (deprecie a ce jour)
  73. $this->rights[1][3] = 1; // La permission est-elle une permission par defaut
  74. $this->rights[1][4] = 'lire_advance';
  75. $this->rights[2][0] = 301; // id de la permission
  76. $this->rights[2][1] = 'Create/modify barcodes'; // libelle de la permission
  77. $this->rights[2][2] = 'w'; // type de la permission (deprecie a ce jour)
  78. $this->rights[2][3] = 0; // La permission est-elle une permission par defaut
  79. $this->rights[2][4] = 'creer_advance';
  80. // Main menu entries
  81. $r=0;
  82. $this->menu[$r]=array( '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
  83. 'mainmenu'=>'tools',
  84. 'leftmenu'=>'barcodeprint',
  85. 'type'=>'left', // This is a Left menu entry
  86. 'titre'=>'BarCodePrintsheet',
  87. 'url'=>'/barcode/printsheet.php?mainmenu=tools&leftmenu=barcodeprint',
  88. 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  89. 'position'=>200,
  90. 'enabled'=>'$conf->barcode->enabled', // 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.
  91. 'perms'=>'($conf->global->MAIN_USE_ADVANCED_PERMS && $user->rights->barcode->lire_advance) || (! $conf->global->MAIN_USE_ADVANCED_PERMS)', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  92. 'target'=>'',
  93. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  94. $r++;
  95. $this->menu[$r]=array( '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
  96. 'type'=>'left', // This is a Left menu entry
  97. 'titre'=>'MassBarcodeInit',
  98. 'url'=>'/barcode/codeinit.php?mainmenu=home&leftmenu=admintools',
  99. 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  100. 'position'=>300,
  101. 'enabled'=>'$conf->barcode->enabled && $leftmenu=="admintools"', // 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.
  102. 'perms'=>'($conf->global->MAIN_USE_ADVANCED_PERMS && $user->rights->barcode->creer_advance) || (! $conf->global->MAIN_USE_ADVANCED_PERMS)', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  103. 'target'=>'',
  104. 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
  105. $r++;
  106. }
  107. /**
  108. * Function called when module is enabled.
  109. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  110. * It also creates data directories.
  111. *
  112. * @param string $options Options when enabling module ('', 'noboxes')
  113. * @return int 1 if OK, 0 if KO
  114. */
  115. function init($options='')
  116. {
  117. // Permissions
  118. $this->remove($options);
  119. $sql = array(
  120. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('EAN8', 'EAN8', 0, '1234567', __ENTITY__)",'ignoreerror'=>1),
  121. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('EAN13', 'EAN13', 0, '123456789012', __ENTITY__)",'ignoreerror'=>1),
  122. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('UPC', 'UPC', 0, '123456789012', __ENTITY__)",'ignoreerror'=>1),
  123. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('ISBN', 'ISBN', 0, '123456789', __ENTITY__)",'ignoreerror'=>1),
  124. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C39', 'Code 39', 0, '1234567890', __ENTITY__)",'ignoreerror'=>1),
  125. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C128', 'Code 128', 0, 'ABCD1234567890', __ENTITY__)",'ignoreerror'=>1),
  126. array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('DATAMATRIX', 'Datamatrix', 0, '1234567xyz', __ENTITY__)",'ignoreerror'=>1),
  127. 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)
  128. );
  129. return $this->_init($sql, $options);
  130. }
  131. }