dolibarr  17.0.4
modReceiptPrinter.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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 3 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 <https://www.gnu.org/licenses/>.
17  */
18 
28 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 
30 
31 
36 {
37 
43  public function __construct($db)
44  {
45  $this->db = $db;
46  $this->numero = 67000;
47  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
48  // It is used to group modules in module setup page
49  $this->family = "interface";
50  $this->module_position = '53';
51  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52  $this->name = preg_replace('/^mod/i', '', get_class($this));
53  // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
54  $this->description = "ReceiptPrinterDesc";
55  // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
56  $this->version = 'dolibarr';
57  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
58  // Name of image file used for this module.
59  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
60  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
61  $this->picto = 'printer';
62 
63  // Data directories to create when module is enabled.
64  $this->dirs = array();
65 
66  // Config pages
67  $this->config_page_url = array("receiptprinter.php");
68 
69  // Dependencies
70  $this->hidden = false; // A condition to hide module
71  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
72  $this->requiredby = array(); // List of module ids to disable if this one is disabled
73  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
74  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
75  $this->need_dolibarr_version = array(3, 9, -2); // Minimum version of Dolibarr required by module
76  $this->conflictwith = array();
77  $this->langfiles = array("receiptprinter");
78 
79  // Constants
80  $this->const = array();
81 
82  // Boxes
83  $this->boxes = array();
84 
85  // Permissions
86  $this->rights = array();
87  $this->rights_class = 'receiptprinter';
88 
89  $r = 0;
90  // $this->rights[$r][0] Id permission (unique tous modules confondus)
91  // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
92  // $this->rights[$r][2] Non utilise
93  // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
94  // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
95  // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
96 
97  $r++;
98  $this->rights[$r][0] = 67001;
99  $this->rights[$r][1] = 'ReceiptPrinter';
100  $this->rights[$r][2] = 'r';
101  $this->rights[$r][3] = 0;
102  $this->rights[$r][4] = 'read';
103 
104  // Main menu entries
105  $this->menus = array(); // List of menus to add
106  $r = 0;
107 
108  // This is to declare the Top Menu entry:
109  //$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Put 0 if this is a top menu
110  // 'type'=>'left', // This is a Top menu entry
111  // 'titre'=>'MenuDirectPrinting',
112  // 'mainmenu'=>'printing',
113  // 'url'=>'/printing/index.php',
114  // 'langs'=>'printing', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
115  // 'position'=>300,
116  // 'enabled'=>'$conf->printing->enabled && preg_match(\'/^(admintools|all)/\',$leftmenu)',
117  // 'perms'=>'$user->rights->printing->read', // Use 'perms'=>'1' if you want your menu with no permission rules
118  // 'target'=>'',
119  // 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
120 
121  $r++;
122  }
123 
124 
133  public function init($options = '')
134  {
135  global $conf, $langs;
136 
137  // Clean before activation
138  $this->remove($options);
139 
140  $templateexample = '{dol_align_center}\r\n{dol_print_text}{dol_value_mysoc_name}\r\n{dol_print_text}{dol_value_mysoc_address}\r\n{dol_print_text}{dol_value_mysoc_zip}{dol_value_mysoc_town}\r\n{dol_line_feed}\r\n{dol_print_text}Facture {dol_value_object_ref}\r\n{dol_line_feed}\r\n{dol_align_left}\r\n{dol_print_object_lines}\r\n{dol_line_feed}\r\n{dol_print_object_tax}\r\n{dol_line_feed}\r\n{dol_print_object_total}\r\n{dol_line_feed}\r\n{dol_cut_paper_full}';
141  $sql = array(
142  "CREATE TABLE IF NOT EXISTS ".MAIN_DB_PREFIX."printer_receipt (rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(128), fk_type integer, fk_profile integer, parameter varchar(128), entity integer) ENGINE=innodb;",
143  "CREATE TABLE IF NOT EXISTS ".MAIN_DB_PREFIX."printer_receipt_template (rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(128), template text, entity integer) ENGINE=innodb;",
144  "DELETE FROM ".MAIN_DB_PREFIX."printer_receipt_template WHERE name = '".$this->db->escape($langs->trans('Example'))."';",
145  "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template (name,template,entity) VALUES ('".$this->db->escape($langs->trans('Example'))."', '".$this->db->escape($templateexample)."', 1);",
146  );
147  return $this->_init($sql, $options);
148  }
149 }
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe and activate module Receipt Printer.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41