dolibarr 23.0.3
blockedlog.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
31function blockedlogadmin_prepare_head($withtabsetup)
32{
33 global $db, $langs, $conf;
34
35 $langs->load("blockedlog");
36
37 $h = 0;
38 $head = array();
39
40 if ($withtabsetup) {
41 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog.php?withtab=".$withtabsetup;
42 $head[$h][1] = $langs->trans("Setup");
43 $head[$h][2] = 'blockedlog';
44 $h++;
45 }
46
47 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_list.php?withtab=".$withtabsetup;
48 $head[$h][1] = $langs->trans("BrowseBlockedLog");
49
50 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
51 $b = new BlockedLog($db);
52 if ($b->alreadyUsed()) {
53 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">...</span>' : '');
54 }
55 $head[$h][2] = 'fingerprints';
56 $h++;
57
58
59 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_archives.php?withtab=".$withtabsetup;
60 $head[$h][1] = $langs->trans("Archives");
61 // TODO Add number of archive files in badge
62 $head[$h][2] = 'archives';
63 $h++;
64
65
66 $object = new stdClass();
67
68 // Show more tabs from modules
69 // Entries must be declared in modules descriptor with line
70 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
71 // $this->tabs = array('entity:-tabname); to remove a tab
72 complete_head_from_modules($conf, $langs, $object, $head, $h, 'blockedlog');
73
74 complete_head_from_modules($conf, $langs, $object, $head, $h, 'blockedlog', 'remove');
75
76 return $head;
77}
78
79
86{
87 global $mysoc;
88
89 $companyname = getDolGlobalString('BLOCKEDLOG_REGISTRATION_NAME', $mysoc->name);
90 $companyemail = getDolGlobalString('BLOCKEDLOG_REGISTRATION_EMAIL', $mysoc->email);
91 $companycountrycode = getDolGlobalString('BLOCKEDLOG_REGISTRATION_COUNTRY_CODE', $mysoc->country_code);
92 $companyidprof1 = getDolGlobalString('BLOCKEDLOG_REGISTRATION_IDPROF1', $mysoc->idprof1);
93 //$companytel = getDolGlobalString('BLOCKEDLOG_REGISTRATION_TEL', $mysoc->phone);
94
95 if (empty($companyname) || empty($companycountrycode) || empty($companyidprof1) || empty($companyemail)) {
96 return false;
97 }
98
99 $providerset = getDolGlobalString('MAIN_INFO_ITPROVIDER_NAME'); // Can be 'myself'
100
101 if (empty($providerset)) {
102 return false;
103 }
104
105 return true;
106}
107
108
115{
116 global $conf;
117
118 return dol_hash('dolibarr'.$conf->file->instance_unique_id, 'sha256', 1);
119}
120
121
132function isALNEQualifiedVersion($ignoredev = 0, $ignoremodule = 0)
133{
134 global $mysoc;
135
136 // For Debug help: Constant set by developer to force all LNE restrictions even if country is not France so we can test them on any dev instance.
137 // Note that you can force, with this option, the enabling of the LNE restrictions, but there is no way to force the disabling of the LNE restriction.
138 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 2) {
139 return true;
140 }
141
142 if (!$ignoredev && preg_match('/\-/', DOL_VERSION)) { // This is not a stable version
143 return false;
144 }
145 if ($mysoc->country_code != 'FR') {
146 return false;
147 }
148 if (!defined('CERTIF_LNE') || (int) constant('CERTIF_LNE') === 0) {
149 return false;
150 }
151 if (!$ignoremodule && !isModEnabled('blockedlog')) {
152 return false;
153 }
154
155 return true; // all conditions are ok to become a LNE certified version
156}
157
158
166function isALNERunningVersion($blockedlogtestalreadydone = 0)
167{
168 // For Debug help: Constant set by developer to force all LNE restrictions
169 // even if country is not France so we can test them on any dev instance.
170 // Note that you can force, with this option, the enabling of the LNE restrictions,
171 // but there is no way to force the disabling of the LNE restriction.
172 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 2
173 && isModEnabled('blockedlog') && ($blockedlogtestalreadydone || isBlockedLogUsed())) {
174 return true;
175 }
176 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 1
177 && isModEnabled('blockedlog') && ($blockedlogtestalreadydone || isBlockedLogUsed())) {
178 return true;
179 }
180
181 return false;
182}
183
190function isBlockedLogUsed($ignoresystem = 0)
191{
192 global $conf, $db;
193
194 $result = true; // by default restrictions are on, so we can't disable them
195
196 // Note: if module on, we suppose it is used, if not, we check in case of it was disabled.
197 if (!isModEnabled('blockedlog')) {
198 // Test the cache key
199 if (array_key_exists('isblockedlogused', $conf->cache)) {
200 return $conf->cache['isblockedlogused'.$ignoresystem];
201 }
202
203 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog";
204 $sql .= " WHERE entity = ".((int) $conf->entity); // Sharing entity in blocked log is disallowed
205 if ($ignoresystem) {
206 $sql .= " AND action NOT IN ('MODULE_SET', 'MODULE_RESET')";
207 }
208 $sql .= $db->plimit(1);
209
210 $resql = $db->query($sql);
211 if ($resql !== false) {
212 $obj = $db->fetch_object($resql);
213 if (!$obj) {
214 $result = false;
215 }
216 } else {
217 dol_print_error($db);
218 }
219
220 $conf->cache['isblockedlogused'.$ignoresystem] = $result;
221 }
222
223 dol_syslog("isBlockedLogUsed: ignoresystem=".$ignoresystem." returns ".(string) $result);
224
225 return $result;
226}
227
228
240function pdfCertifMentionblockedLog(&$pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
241{
242 $result = 0;
243
244 if (in_array($seller->country_code, array('FR')) && isALNEQualifiedVersion()) { // If necessary, we could replace with "if isALNERunningVersion()"
245 $outputlangs->load("blockedlog");
246 $blockedlog_mention = $outputlangs->transnoentitiesnoconv("InvoiceGeneratedWithLNECertifiedPOSSystem");
247 if ($blockedlog_mention) {
248 $pdf->SetFont('', '', $default_font_size - 2);
249 $pdf->SetXY($pdftemplate->marge_gauche, $posy);
250 $pdf->MultiCell(100, 3, $blockedlog_mention, 0, 'L', false);
251 $posy = $pdf->GetY();
252 $result = 1;
253 }
254 }
255
256 return $result;
257}
258
272function sumAmountsForUnalterableEvent($block, &$refinvoicefound, &$totalhtamount, &$totalvatamount, &$totalamount, &$total_ht, &$total_vat, &$total_ttc)
273{
274 // Init to avoid warnings if not initialized yet
275 if (!isset($totalamount[$block->action][$block->module_source])) {
276 $totalhtamount[$block->action][$block->module_source] = 0;
277 $totalvatamount[$block->action][$block->module_source] = 0;
278 $totalamount[$block->action][$block->module_source] = 0;
279 }
280
281 if ($block->action == 'BILL_VALIDATE') {
282 $total_ht = $block->object_data->total_ht;
283 $total_vat = $block->object_data->total_tva;
284 $total_ttc = $block->object_data->total_ttc;
285
286 // We add total for the invoice if "invoice validate event" not yet met.
287 // If we already met the event for this object, we keep only first one but this should not happen because edition of validated invoice is not allowed on secured versions.
288 if (empty($refinvoicefound[$block->ref_object])) {
289 $totalhtamount[$block->action][$block->module_source] += $total_ht;
290 $totalvatamount[$block->action][$block->module_source] += $total_vat;
291 $totalamount[$block->action][$block->module_source] += $total_ttc;
292 }
293 $refinvoicefound[$block->ref_object] = 1;
294 } elseif ($block->action == 'PAYMENT_CUSTOMER_CREATE') {
295 $total_ht = $block->object_data->amount;
296 $total_vat = 0;
297 $total_ttc = $block->object_data->amount;
298
299 $totalhtamount[$block->action][$block->module_source] += $total_ht;
300 $totalvatamount[$block->action][$block->module_source] += $total_vat;
301 $totalamount[$block->action][$block->module_source] += $total_ttc;
302 } else {
303 $total_ttc = $block->amounts;
304 }
305
306 return 1;
307}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
sumAmountsForUnalterableEvent($block, &$refinvoicefound, &$totalhtamount, &$totalvatamount, &$totalamount, &$total_ht, &$total_vat, &$total_ttc)
sumAmountsForUnalterableEvent
isALNEQualifiedVersion($ignoredev=0, $ignoremodule=0)
Return if the version is a candidate version to get the LNE certification and if the prerequisites ar...
isRegistrationDataSaved()
Return if the KYC mandatory parameters are set.
getHashUniqueIdOfRegistration()
Return a hash unique identifier of the registration.
pdfCertifMentionblockedLog(&$pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal mention.
isBlockedLogUsed($ignoresystem=0)
Return if the blocked log was already used to block some events.
blockedlogadmin_prepare_head($withtabsetup)
Define head array for tabs of blockedlog tools setup pages.
isALNERunningVersion($blockedlogtestalreadydone=0)
Return if the application is executed with the LNE requirements on.
Class to manage Blocked Log.
global $mysoc
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.