dolibarr 21.0.3
modBlockedLog.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourcefore.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
25include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
26
31{
37 public function __construct($db)
38 {
39 global $conf, $mysoc;
40
41 $this->db = $db;
42 $this->numero = 3200;
43 // Key text used to identify module (for permissions, menus, etc...)
44 $this->rights_class = 'blockedlog';
45
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 = "base";
49 // Module position in the family on 2 digits ('01', '10', '20', ...)
50 $this->module_position = '76';
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 $this->description = "Enable a log on some business events into a non reversible log. This module may be mandatory for some countries.";
54 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
55 $this->version = 'dolibarr';
56 // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
57 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
58 // Name of image file used for this module.
59 $this->picto = 'technic';
60
61 // Data directories to create when module is enabled
62 $this->dirs = array();
63
64 // Config pages
65 //-------------
66 $this->config_page_url = array('blockedlog.php?withtab=1@blockedlog');
67
68 // Dependencies
69 //-------------
70 $this->hidden = false; // A condition to disable module
71 $this->depends = array('always'=>'modFacture'); // List of modules id that must be enabled if this module is enabled
72 $this->requiredby = array(); // List of modules id to disable if this one is disabled
73 $this->conflictwith = array(); // List of modules id this module is in conflict with
74 $this->langfiles = array('blockedlog');
75
76 $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
77 $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
78 $this->warnings_unactivation = array('FR'=>'BlockedLogAreRequiredByYourCountryLegislation');
79
80 // Currently, activation is not automatic because only companies (in France) making invoices to non business customers must
81 // enable this module.
82 /*if (getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY')) {
83 $tmp=explode(',', getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY'));
84 $this->automatic_activation = array();
85 foreach($tmp as $key)
86 {
87 $this->automatic_activation[$key]='BlockedLogActivatedBecauseRequiredByYourCountryLegislation';
88 }
89 }*/
90 //var_dump($this->automatic_activation);
91
92 $this->always_enabled = (isModEnabled('blockedlog')
93 && getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY')
94 && in_array((empty($mysoc->country_code) ? '' : $mysoc->country_code), explode(',', getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY')))
95 && $this->alreadyUsed());
96
97 // Constants
98 //-----------
99 $this->const = array(
100 1=>array('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY', 'chaine', 'FR', 'This is list of country code where the module may be mandatory', 0, 'current', 0)
101 );
102
103 // New pages on tabs
104 // -----------------
105 $this->tabs = array();
106
107 // Boxes
108 //------
109 $this->boxes = array();
110
111 // Permissions
112 // -----------------
113 $this->rights = array(); // Permission array used by this module
114
115 $r = 1;
116 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
117 $this->rights[$r][1] = 'Read archived events and fingerprints'; // Permission label
118 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
119 $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
120 $this->rights[$r][5] = '';
121
122 // Main menu entries
123 // -----------------
124 $r = 0;
125 $this->menu[$r] = array(
126 '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
127 'mainmenu'=>'tools',
128 'leftmenu'=>'blockedlogbrowser',
129 'type'=>'left', // This is a Left menu entry
130 'titre'=>'BrowseBlockedLog',
131 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
132 'url'=>'/blockedlog/admin/blockedlog_list.php?mainmenu=tools&leftmenu=blockedlogbrowser',
133 'langs'=>'blockedlog', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
134 'position'=>200,
135 'enabled'=>'isModEnabled("blockedlog")', // 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.
136 'perms'=>'$user->hasRight("blockedlog", "read")', // Use 'perms'=>'$user->hasRight("mymodule","level1","level2")' if you want your menu with a permission rules
137 'target'=>'',
138 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
139 );
140 $r++;
141 }
142
143
149 public function alreadyUsed()
150 {
151 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
152 $b = new BlockedLog($this->db);
153 return $b->alreadyUsed(1);
154 }
155
156
165 public function init($options = '')
166 {
167 global $conf, $user;
168
169 $sql = array();
170
171 // If already used, we add an entry to show we enable module
172 require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php';
173
174 $object = new stdClass();
175 $object->id = 0;
176 $object->element = 'module';
177 $object->ref = 'systemevent';
178 $object->entity = $conf->entity;
179 $object->date = dol_now();
180
181 $b = new BlockedLog($this->db);
182
183 $action = 'MODULE_SET';
184 $result = $b->setObjectData($object, $action, 0);
185
186 if ($result < 0) {
187 $this->error = $b->error;
188 $this->errors = $b->errors;
189 return 0;
190 }
191
192 $res = $b->create($user);
193 if ($res <= 0) {
194 $this->error = $b->error;
195 $this->errors = $b->errors;
196 return $res;
197 }
198
199 return $this->_init($sql, $options);
200 }
201
210 public function remove($options = '')
211 {
212 global $conf, $user;
213
214 $sql = array();
215
216 // If already used, we add an entry to show we enable module
217 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
218
219 $object = new stdClass();
220 $object->id = 1;
221 $object->element = 'module';
222 $object->ref = 'systemevent';
223 $object->entity = $conf->entity;
224 $object->date = dol_now();
225
226 $b = new BlockedLog($this->db);
227 $result = $b->setObjectData($object, 'MODULE_RESET', 0);
228 if ($result < 0) {
229 $this->error = $b->error;
230 $this->errors = $b->errors;
231 return 0;
232 }
233
234 if ($b->alreadyUsed(1)) {
235 $res = $b->create($user, '0000000000'); // If already used for something else than SET or UNSET, we log with error
236 } else {
237 $res = $b->create($user);
238 }
239 if ($res <= 0) {
240 $this->error = $b->error;
241 $this->errors = $b->errors;
242 return $res;
243 }
244
245 return $this->_remove($sql, $options);
246 }
247}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to manage Blocked Log.
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
Class to describe a BlockedLog module.
init($options='')
Function called when module is enabled.
alreadyUsed()
Check if module was already used before unactivation linked to warnings_unactivation property.
__construct($db)
Constructor.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:153