dolibarr 21.0.0-alpha
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
28include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29
30
31
36{
42 public function __construct($db)
43 {
44 $this->db = $db;
45 $this->numero = 67000;
46 // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
47 // It is used to group modules in module setup page
48 $this->family = "interface";
49 $this->module_position = '53';
50 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
51 $this->name = preg_replace('/^mod/i', '', get_class($this));
52 // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
53 $this->description = "ReceiptPrinterDesc";
54 // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
55 $this->version = 'dolibarr';
56 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57 // Name of image file used for this module.
58 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
59 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
60 $this->picto = 'printer';
61
62 // Data directories to create when module is enabled.
63 $this->dirs = array();
64
65 // Config pages
66 $this->config_page_url = array("receiptprinter.php");
67
68 // Dependencies
69 $this->hidden = false; // A condition to hide module
70 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
71 $this->requiredby = array(); // List of module ids to disable if this one is disabled
72 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
73 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
74 $this->need_dolibarr_version = array(3, 9, -2); // Minimum version of Dolibarr required by module
75 $this->conflictwith = array();
76 $this->langfiles = array("receiptprinter");
77
78 // Constants
79 $this->const = array();
80
81 // Boxes
82 $this->boxes = array();
83
84 // Permissions
85 $this->rights = array();
86 $this->rights_class = 'receiptprinter';
87
88 $r = 0;
89 // $this->rights[$r][0] Id permission (unique tous modules confondus)
90 // $this->rights[$r][1] Libelle par default si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
91 // $this->rights[$r][2] Non utilise
92 // $this->rights[$r][3] 1=Permis par default, 0=Non permis par default
93 // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
94 // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
95
96 $r++;
97 $this->rights[$r][0] = 67001;
98 $this->rights[$r][1] = 'ReceiptPrinter';
99 $this->rights[$r][2] = 'r';
100 $this->rights[$r][3] = 0;
101 $this->rights[$r][4] = 'read';
102
103 // Main menu entries
104 $this->menu = array(); // List of menus to add
105 $r = 0;
106
107 // This is to declare the Top Menu entry:
108 //$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Put 0 if this is a top menu
109 // 'type'=>'left', // This is a Top menu entry
110 // 'titre'=>'MenuDirectPrinting',
111 // 'mainmenu'=>'printing',
112 // 'url'=>'/printing/index.php',
113 // 'langs'=>'printing', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
114 // 'position'=>300,
115 // 'enabled'=>'$conf->printing->enabled && preg_match(\'/^(admintools|all)/\',$leftmenu)',
116 // 'perms'=>'$user->rights->printing->read', // Use 'perms'=>'1' if you want your menu with no permission rules
117 // 'target'=>'',
118 // 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
119
120 $r++;
121 }
122
123
132 public function init($options = '')
133 {
134 global $langs;
135
136 $result = $this->_load_tables('/install/mysql/', 'receiptprinter');
137 if ($result < 0) {
138 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')
139 }
140
141 // Clean before activation
142 $this->remove($options);
143
144 // @TODO Move create/delete into sql file and insert into data file
145 $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}';
146 $sql = array(
147 "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;",
148 "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;",
149 "DELETE FROM ".MAIN_DB_PREFIX."printer_receipt_template WHERE name = '".$this->db->escape($langs->trans('Example'))."';",
150 "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template (name,template,entity) VALUES ('".$this->db->escape($langs->trans('Example'))."', '".$this->db->escape($templateexample)."', 1);",
151 );
152
153 return $this->_init($sql, $options);
154 }
155}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Class to describe and activate module Receipt Printer.
init($options='')
Function called when module is enabled.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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:142