dolibarr 24.0.0-beta
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 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26include_once DOL_DOCUMENT_ROOT.'/blockedlog/versionmod.inc.php';
27
28
35{
36 $versionbadge = constant('DOLCERT_VERSION');
37
38 // Protection if we used a past old version not yet certified, we change version shown.
39 if (!constant('CERTIF_LNE')) { // Hard coded in version
40 $versionbadge = preg_replace('/^(\d)\./', '\1b.', $versionbadge);
41 };
42
43 return $versionbadge;
44}
45
46
53function blockedlogadmin_prepare_head($withtabsetup)
54{
55 global $db, $langs, $conf, $mysoc;
56
57 $langs->load("blockedlog");
58
59 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
60
61 $param = '';
62 $param .= ($withtabsetup? "?withtab=".$withtabsetup : "");
63 $param .= (GETPOST('origin') ? ($param ? '&' : '?').'origin='.GETPOST('origin') : '');
64
65 $h = 0;
66 $head = array();
67
68 if (!userIsTaxAuditor()) {
69 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/registration.php".$param;
70 $head[$h][1] = $langs->trans("UserRegistration");
71 $head[$h][2] = 'registration';
72 $h++;
73 }
74
75 if (!userIsTaxAuditor()) {
76 $b = new BlockedLog($db);
77 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_list.php".$param;
78 $head[$h][1] = $langs->trans("BrowseBlockedLog");
79 if ($b->alreadyUsed()) {
80 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">...</span>' : '');
81 }
82 $head[$h][2] = 'fingerprints';
83 $h++;
84 }
85
86 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_archives.php".$param;
87 $head[$h][1] = $langs->trans("Archives");
88 // Add badge on nb of files
89 $block_static = new BlockedLog($db);
90 $upload_dir = getMultidirOutput($block_static, 'blockedlog').'/archives';
91 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
92 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
93 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
94 $nbLinks = 0;
95 if (($nbFiles + $nbLinks) > 0) {
96 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
97 }
98 $head[$h][2] = 'archives';
99 $h++;
100
101 if (userIsTaxAuditor()) {
102 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_control.php".$param;
103 $head[$h][1] = $langs->trans("OtherControl");
104 $head[$h][2] = 'control';
105 $h++;
106 }
107
108 if ($mysoc->country_code == 'FR') {
109 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/documentation.php".$param;
110 $head[$h][1] = $langs->trans("Documentation");
111 $head[$h][2] = 'documentation';
112 $h++;
113 }
114
115 if ($withtabsetup && !userIsTaxAuditor()) {
116 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog.php".$param;
117 $head[$h][1] = $langs->trans("TechnicalInformation");
118 $head[$h][2] = 'technicalinfo';
119 $h++;
120 }
121
122
123 $object = new stdClass();
124
125 // Show more tabs from modules
126 // Entries must be declared in modules descriptor with line
127 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
128 // $this->tabs = array('entity:-tabname); to remove a tab
129 complete_head_from_modules($conf, $langs, $object, $head, $h, 'blockedlog');
130
131 complete_head_from_modules($conf, $langs, $object, $head, $h, 'blockedlog', 'remove');
132
133 return $head;
134}
135
136
144{
145 global $mysoc;
146
147 $companyname = getDolGlobalString('BLOCKEDLOG_REGISTRATION_NAME', $mysoc->name);
148 $companyemail = getDolGlobalString('BLOCKEDLOG_REGISTRATION_EMAIL', $mysoc->email);
149 $companycountrycode = $mysoc->country_code;
150 $companyidprof1 = getDolGlobalString('MAIN_INFO_SIREN', $mysoc->idprof1);
151 $companyidprof2 = getDolGlobalString('MAIN_INFO_SIRET', $mysoc->idprof2);
152 //$companytel = getDolGlobalString('BLOCKEDLOG_REGISTRATION_TEL', $mysoc->phone);
153
154 if (empty($companyname) || empty($companycountrycode) || empty($companyidprof1) || empty($companyidprof2) || empty($companyemail)) {
155 return false;
156 }
157 /*
158 $providerset = getDolGlobalString('MAIN_INFO_ITPROVIDER_NAME'); // Can be 'myself'
159
160 if (empty($providerset)) {
161 return false;
162 }
163 */
164
165 return true;
166}
167
168
175{
176 return isRegistrationDataSaved() && (bool) getDolGlobalString('MAIN_FIRST_REGISTRATION_OK_DATE');
177}
178
179
186function getHashUniqueIdOfRegistration($algo = 'sha256')
187{
188 global $conf;
189
190 return dol_hash('dolibarr'.$conf->file->instance_unique_id.($conf->entity > 1 ? $conf->entity : ''), $algo, 1);
191}
192
193
204function isALNEQualifiedVersion($ignoredev = 0, $ignoremodule = 0)
205{
206 global $mysoc;
207
208 // For Dev/Debug purpose: Constant set by developer to force all LNE restrictions even if country is not France so we can test them on any dev instance.
209 // 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.
210 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 2) {
211 return 'CERTIF_LNE_IS_2';
212 }
213
214 if (!$ignoredev && preg_match('/\-/', DOL_VERSION)) { // This is not a stable version (dev version), it can't be the certified versions.
215 return '';
216 }
217 if ($mysoc->country_code != 'FR') {
218 return '';
219 }
220 if (!defined('CERTIF_LNE') || (int) constant('CERTIF_LNE') === 0) {
221 return '';
222 }
223 if (!$ignoremodule && !isModEnabled('blockedlog')) {
224 return '';
225 }
226
227 // All conditions are ok to become a LNE certified version
228 return ($ignoredev ? '' : 'NOT_BETA+').'FR+CERTIF_LNE_IS_1'.($ignoremodule ? '' : '+MODENABLED');
229}
230
231
240function isALNERunningVersion($blockedlogtestalreadydone = 0, $blockedlogmodulealreadydone = 0)
241{
242 // For Debug help: Constant CERTIF_LNE can be set 2 by developers get mode 1 compliant with dev env.
243 // Note that you can force, with this constant, the enabling of the restrictions,
244 // but there is no way to force the disabling of a restriction.
245 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 2 // Value is 2 for debug purpose to enable restriction except https for dev env.
246 && ($blockedlogmodulealreadydone || isModEnabled('blockedlog'))
247 && ($blockedlogtestalreadydone || isBlockedLogUsed())) {
248 return true;
249 }
250 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 1 // Value is 1 when version is certified
251 && ($blockedlogmodulealreadydone || isModEnabled('blockedlog'))
252 && ($blockedlogtestalreadydone || isBlockedLogUsed())) {
253 return true;
254 }
255
256 return false;
257}
258
265function isBlockedLogUsed($ignoresystem = 0)
266{
267 global $conf, $db;
268
269 $result = true; // by default restrictions are on, so we can't disable them
270
271 // Note: if module on, we suppose it is used, if not, we check in case of it was disabled.
272 if (!isModEnabled('blockedlog')) {
273 // Test the cache key
274 if (array_key_exists('isblockedlogused', $conf->cache)) {
275 return $conf->cache['isblockedlogused'.$ignoresystem];
276 }
277
278 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog";
279 $sql .= " WHERE entity = ".((int) $conf->entity); // Sharing entity in blocked log will never be allowed
280 if ($ignoresystem) {
281 $sql .= " AND action NOT IN ('MODULE_SET', 'MODULE_RESET')";
282 }
283 $sql .= $db->plimit(1);
284
285 $resql = $db->query($sql);
286 if ($resql !== false) {
287 $obj = $db->fetch_object($resql);
288 if (!$obj) {
289 $result = false;
290 }
291 } else {
293 }
294
295 $conf->cache['isblockedlogused'.$ignoresystem] = $result;
296 }
297
298 dol_syslog("isBlockedLogUsed: ignoresystem=".$ignoresystem." returns ".(string) $result);
299
300 return $result;
301}
302
303
315function pdfCertifMentionblockedLog(&$pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
316{
317 $result = 0;
318
319 if (in_array($seller->country_code, array('FR'))) {
320 $outputlangs->load("blockedlog");
321 $blockedlog_mention = '';
322
323 $isalne = isALNEQualifiedVersion(); // If necessary, we could replace with "if isALNERunningVersion()"
324 if ($isalne == 'CERTIF_LNE_IS_2') {
325 $blockedlog_mention = $outputlangs->transnoentitiesnoconv("InvoiceGeneratedWithLNECandidatePOSSystem");
326 } elseif ($isalne) {
327 $blockedlog_mention = $outputlangs->transnoentitiesnoconv("InvoiceGeneratedWithLNECertifiedPOSSystem");
328 }
329
330 if ($blockedlog_mention) {
331 $pdf->SetFont('', '', $default_font_size - 2);
332 $pdf->SetXY($pdftemplate->marge_gauche, $posy);
333 $pdf->MultiCell(100, 3, $blockedlog_mention, 0, 'L', false);
334 $posy = $pdf->GetY();
335 $result = 1;
336 }
337 }
338
339 return $result;
340}
341
355function sumAmountsForUnalterableEvent($block, &$refinvoicefound, &$totalhtamount, &$totalvatamount, &$totalamount, &$total_ht, &$total_vat, &$total_ttc)
356{
357 if ($block->action == 'BILL_VALIDATE') {
358 $total_ht = $block->object_data->total_ht;
359 $total_vat = $block->object_data->total_tva;
360 $total_ttc = $block->object_data->total_ttc;
361
362 // Init to avoid warnings if not initialized yet
363 if (!isset($totalamount[$block->action][$block->module_source])) {
364 $totalhtamount[$block->action][$block->module_source] = 0;
365 $totalvatamount[$block->action][$block->module_source] = 0;
366 $totalamount[$block->action][$block->module_source] = 0;
367 }
368
369 // We add total for the invoice if "invoice validate event" not yet met.
370 // 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.
371 if (empty($refinvoicefound[$block->ref_object])) {
372 $totalhtamount[$block->action][$block->module_source] += $total_ht;
373 $totalvatamount[$block->action][$block->module_source] += $total_vat;
374 $totalamount[$block->action][$block->module_source] += $total_ttc;
375 }
376 $refinvoicefound[$block->ref_object] = 1;
377 } elseif ($block->action == 'PAYMENT_CUSTOMER_CREATE' || $block->action == 'PAYMENT_CUSTOMER_DELETE') {
378 $total_ht = $block->object_data->amount;
379 $total_vat = 0;
380 $total_ttc = $block->object_data->amount;
381
382 //$actionkey = $block->action;
383 $actionkey = 'PAYMENT_CUSTOMER';
384
385 // Init to avoid warnings if not initialized yet
386 if (!isset($totalamount[$actionkey][$block->module_source])) {
387 $totalhtamount[$actionkey][$block->module_source] = 0;
388 $totalvatamount[$actionkey][$block->module_source] = 0;
389 $totalamount[$actionkey][$block->module_source] = 0;
390 }
391
392 $totalhtamount[$actionkey][$block->module_source] += $total_ht;
393 $totalvatamount[$actionkey][$block->module_source] += $total_vat;
394 $totalamount[$actionkey][$block->module_source] += $total_ttc;
395 } else {
396 $total_ttc = $block->amounts;
397 }
398
399 return 1;
400}
401
402
412function callApiToGetObfuscationKey($idprof1, $registrationnumber, $force = false)
413{
414 global $mysoc, $conf;
415
416 $obfuscationkey = 'ERROR';
417
418 if (empty($idprof1)) {
419 dol_syslog("callApiToGetObfuscationKey was called with empty idprof1", LOG_DEBUG);
420 return 'ERROR callApiToGetObfuscationKey was called with empty idprof1';
421 }
422
423 //if ((isALNERunningVersion(1) || $force) && $mysoc->country_code == 'FR') {
424 $url_for_ping = getDolGlobalString('MAIN_URL_FOR_PING', "https://ping.dolibarr.org/");
425
426 $algo = 'sha256';
427 $hash_unique_id = getHashUniqueIdOfRegistration($algo); // The hash of the unique IDof instance
428
429 $t = microtime(true);
430 $micro = sprintf("%06d", (int) (($t - floor($t)) * 1000000));
431
432 $data = '';
433 $data .= 'hash_algo=dol_hash-'.urlencode($algo);
434 $data .= '&hash_unique_id='.urlencode($hash_unique_id);
435 $data .= '&action=dolibarrgetkeyobfuscation';
436 $data .= '&datesys='.urlencode(dol_print_date(dol_now('gmt'), 'standard', 'gmt').'.'.$micro);
437 $data .= '&version='.(float) DOL_VERSION;
438 $data .= '&version_full='.urlencode(DOL_VERSION);
439 $data .= '&versionblockedlog='.(float) getBlockedLogVersionToShow();
440 $data .= '&versionblockedlog_full='.urlencode(getBlockedLogVersionToShow());
441
442 $data .= '&entity='.(int) $conf->entity;
443
444 $data .= '&company_idprof1='.urlencode(dol_sanitizeKeyCode($idprof1));
445 $data .= '&registrationnumber='.urlencode(dol_sanitizeKeyCode($registrationnumber));
446
447 $addheaders = array();
448 $timeoutconnect = 3;
449 $timeoutresponse = 3;
450
451 dol_syslog("callApiToGetObfuscationKey call remote URL idprod1=".dol_sanitizeKeyCode($idprof1), LOG_DEBUG);
452 dol_syslog("callApiToGetObfuscationKey call remote URL idprod1=".dol_sanitizeKeyCode($idprof1), LOG_DEBUG, 0, '_dolibarrgetkeyobfuscation');
453
454 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
455 try {
456 $tmpresult = getURLContent($url_for_ping, 'POST', $data, 1, $addheaders, array('https'), 0, -1, $timeoutconnect, $timeoutresponse, array());
457 usleep(10000);
458
459 // Add a warning in log in case of error
460 if ($tmpresult['http_code'] == 0 && !empty($tmpresult['curl_error_msg'])) {
461 $logerrormessage = 'Error: '.$tmpresult['curl_error_msg'];
462 $obfuscationkey .= ' '.$tmpresult['curl_error_msg'];
463 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING);
464 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
465 } elseif ($tmpresult['http_code'] != 200) {
466 $logerrormessage = 'Error: '.$tmpresult['http_code'].' '.$tmpresult['content'];
467 $obfuscationkey .= ' '.$tmpresult['http_code'].' '.$tmpresult['content'];
468 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING);
469 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
470 } else {
471 $reg = array();
472 if (preg_match('/(DOLOBFUSCKEY.*)/', $tmpresult['content'], $reg)) { // gitleaks:allow $tmpresult['content'] may contains text comments before the line 'DOLOBFUSCKEY1...,DOLOBFUSCKEY2...'
473 $obfuscationkey = $reg[1];
474 dol_syslog("callApiToGetObfuscationKey we got the remote obfuscation key", LOG_DEBUG);
475 dol_syslog("callApiToGetObfuscationKey we got the remote obfuscation key", LOG_DEBUG, 0, '_dolibarrgetkeyobfuscation');
476 } else {
477 $obfuscationkey .= ' '.$tmpresult['content'];
478 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$tmpresult['content'], LOG_WARNING);
479 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$tmpresult['content'], LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
480 }
481 }
482 } catch (Exception $e) {
483 $obfuscationkey .= ' '.$e->getMessage();
484 dol_syslog("callApiToGetObfuscationKey result error ".$e->getMessage(), LOG_ERR);
485 dol_syslog("callApiToGetObfuscationKey result error ".$e->getMessage(), LOG_ERR, 0, '_dolibarrgetkeyobfuscation');
486 }
487
488 return $obfuscationkey;
489}
490
491
504/*
505function callApiToPushCounter($id, $signature, $datecreation, $test, $previousid, $previoussignature, $previousdatecreation)
506{
507 global $mysoc, $conf;
508
509 if (isALNERunningVersion(1) && $mysoc->country_code == 'FR') {
510 // Push last rowid + signature to remote dolibarr server
511 // TODO Do it only for selected events: BILL_VALIDATE ?
512
513 // Code here is similar to the one into printCodeForPing(), except that message code/properties/fields may differ.
514 $url_for_ping = getDolGlobalString('MAIN_URL_FOR_PING', "https://ping.dolibarr.org/");
515
516 $algo = 'sha256';
517 $hash_unique_id = getHashUniqueIdOfRegistration($algo); // The hash of the unique IDof instance
518
519 $t = microtime(true);
520 $micro = sprintf("%06d", (int) (($t - floor($t)) * 1000000));
521
522 $data = '';
523 $data .= 'hash_algo=dol_hash-'.urlencode($algo);
524 $data .= '&hash_unique_id='.urlencode($hash_unique_id);
525 $data .= '&action=dolibarrpushcounter';
526 $data .= '&datesys='.urlencode(dol_print_date(dol_now('gmt'), 'standard', 'gmt').'.'.$micro);
527 $data .= '&version='.(float) DOL_VERSION;
528 $data .= '&version_full='.urlencode(DOL_VERSION);
529 $data .= '&versionblockedlog='.(float) getBlockedLogVersionToShow();
530 $data .= '&versionblockedlog_full='.urlencode(getBlockedLogVersionToShow());
531
532 $data .= '&entity='.(int) $conf->entity;
533
534 $data .= '&lastrowid='.(int) $id;
535 $data .= '&lastsignature='.urlencode($signature);
536 $data .= '&lastdatecreation='.urlencode(dol_print_date($datecreation, 'standard', 'gmt'));
537 $data .= '&previousrowid='.(int) $previousid;
538 $data .= '&previoussignature='.urlencode($previoussignature);
539 $data .= '&previousdatecreation='.urlencode(dol_print_date($previousdatecreation, 'standard', 'gmt'));
540 if ($test) {
541 $data .= '&test=1';
542 }
543
544 $addheaders = array();
545 $timeoutconnect = 1;
546 $timeoutresponse = 1;
547
548 $conf->global->BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING = 1; // Force probability to 1
549
550 // Probability will be between 1/10 by default and 1/1 if const BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING is set to 1. Can't be lower than 1/10.
551 $BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING = min(10, getDolGlobalInt('BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING', 10));
552 $random = 1;
553 //$BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING = 1; // To force track at every call
554 if ($BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING > 1) {
555 $random = random_int(1, (int) $BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING);
556 }
557
558 if ($random == 1) { // 1 chance on BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING
559 dol_syslog("callApiToPushCounter create Record is selected to be remotely pushed for tracking", LOG_DEBUG);
560
561 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
562 try {
563 $tmpresult = getURLContent($url_for_ping, 'POST', $data, 1, $addheaders, array('https'), 0, -1, $timeoutconnect, $timeoutresponse, array(), '_dolibarrpushcounter');
564 usleep(1000);
565
566 // Add a warning in log in case of error
567 if ($tmpresult['http_code'] != 200) {
568 $logerrormessage = 'Error: '.$tmpresult['http_code'].' '.$tmpresult['content'];
569 dol_syslog("callApiToPushCounter create Error when pushing track info: ".$logerrormessage, LOG_WARNING);
570 }
571 } catch (Exception $e) {
572 dol_syslog("callApiToPushCounter create Error ".$e->getMessage(), LOG_ERR);
573 }
574 } else {
575 dol_syslog("callApiToPushCounter create Record is NOT selected to be remotely pushed for tracking", LOG_DEBUG);
576 }
577
578 return 1;
579 }
580
581 return 0;
582}
583*/
584
585
594{
595 global $user;
596
597 return (((getDolGlobalString('BLOCKEDLOG_FOR_TAX_AUDITOR') && $user->socid) || getDolGlobalString('BLOCKEDLOG_FOR_TAX_AUDITOR') == '2') ? 1 : 0);
598}
599
600
601
614function pdfWriteBlockedLogSignature(&$pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
615{
616 global $db;
617
618 // Transaction ID
619 if (isALNERunningVersion() && isModEnabled('blockedlog')) {
620 if ($object->status > $object::STATUS_DRAFT) {
621 $unalterablelogid = 'UNDEFINED'; // By default
622
623 $sql = "SELECT signature FROM ".MAIN_DB_PREFIX."blockedlog";
624 $sql .= " WHERE action = 'BILL_VALIDATE' AND element = 'facture' AND ref_object = '".$db->escape($object->ref)."'";
625 $sql .= $db->order('rowid', 'DESC');
626 $sql .= $db->plimit(1);
627
628 $resql = $db->query($sql);
629 if ($resql) {
630 $obj = $db->fetch_object($resql);
631 if ($obj) {
632 $unalterablelogid = $obj->signature;
633 }
634 }
635
636 if ($unalterablelogid != 'UNDEFINED') {
637 $pdf->SetXY($posx, $posy);
638 $pdf->SetTextColor(0, 0, 60);
639 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SignatureID")." : ".dol_trunc(strtoupper($unalterablelogid), 10), '', 'R');
640 $posy += 3;
641 }
642
643 $isADuplicata = ($object->pos_print_counter >= 2);
644 if ($isADuplicata) {
645 $pdf->SetXY($posx, $posy);
646 $pdf->SetTextColor(0, 0, 60);
647 $pdf->MultiCell($w, 3, '*** '.$outputlangs->trans("DUPLICATA").(getDolGlobalString('TAKEPOS_SHOW_PRINT_COUNTER_ON_RECEIPT') ? ' (no '.($object->pos_print_counter - 1).')' : '').' ***', '', 'R');
648 $posy += 3;
649 }
650 }
651
652 if ($object->status == $object::STATUS_DRAFT) {
653 $pdf->SetXY($posx, $posy);
654 $pdf->SetTextColor(0, 0, 60);
655 $pdf->MultiCell($w, 3, '*** '.strtoupper($outputlangs->trans("TemporaryReceipt")).' ***', '', 'R');
656 $posy += 3;
657 }
658 }
659}
660
661
662
669{
670 global $conf, $db, $langs, $mysoc;
671
672 include_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
673
674 $blocklog_static = new BlockedLog($db);
675
676 // Loop on all entities found in llx_blockedlog
677 $listofentities = array();
678 $sql = "SELECT DISTINCT entity FROM ".MAIN_DB_PREFIX."blockedlog";
679 $resql = $db->query($sql);
680 if ($resql) {
681 while ($obj = $db->fetch_object($resql)) {
682 $listofentities[] = $obj->entity;
683 }
684 } else {
685 print '<tr class="trforrunsql"><td colspan="4">';
686 print '<b>'.$langs->trans('InitEndFlagFile')."</b>:\n";
687 print 'Error: Failed to get list of entities in blockedlog table';
688 print '</td></tr>';
689 return -1;
690 }
691
692 foreach ($listofentities as $entity) {
693 print '<tr class="trforrunsql"><td colspan="4">';
694 print '<b>'.$langs->trans('InitEndFlagFile')." (entity = ".$entity.")</b>:\n";
695
696 // Load the data of company (country, ...). Erase current one so this function can be used by migration script only.
697 $conf->setEntityValues($db, $entity);
698 $mysoc = new Societe($db);
699 $mysoc->setMysoc($conf);
700
701 $maxid = 0;
702 $sql = "SELECT MAX(rowid) as maxid FROM ".MAIN_DB_PREFIX."blockedlog WHERE entity = ".((int) $entity);
703 $resql = $db->query($sql);
704 if ($resql) {
705 $obj = $db->fetch_object($resql);
706 if ($obj) {
707 $maxid = $obj->maxid;
708 }
709 } else {
710 print 'Error: Failed to get max id of blockedlog table';
711 print '</td></tr>';
712 return -1;
713 }
714
715 $blocklog_static->fetch($maxid);
716
717 $lockfile = $blocklog_static->getEndOfChainFlagFile();
718
719 // Lock acquired, we can now write the new .end file
720 $stringtowrite = 'BLOCKEDLOGHEAD '.$blocklog_static->id." ".dol_print_date($blocklog_static->date_creation, 'dayhourrfc', 'gmt')." ".(string) $blocklog_static->signature;
721
722 if (isALNERunningVersion(1) && $mysoc->country_code == 'FR') {
723 $remoteobfuscationkey = $blocklog_static->getObfuscationKey();
724 if (empty($remoteobfuscationkey)) {
725 print "Error: Failed to get the remote obfuscation key. We can't record the end of chain flag file so we abort the transaction.";
726 print '</td></tr>';
727 return -1;
728 }
729
730 $stringtowriteencoded = dolEncrypt($stringtowrite, $remoteobfuscationkey, '', '', 'dolobfuscationv1-'.$mysoc->idprof1.'-'.$blocklog_static->id);
731 } else {
732 $stringtowriteencoded = dolEncrypt($stringtowrite, '', '', '', 'dolcrypt-'.$mysoc->idprof1.'-'.$blocklog_static->id);
733 }
734
735 // Update or create the .end flag file.
736 if (defined('BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
737 $lockhandle = fopen($lockfile, 'w+');
738 if ($lockhandle) {
739 if (fwrite($lockhandle, $stringtowriteencoded."\n") === false) {
740 print "Cannot write to the blockedlog .end file ".$lockfile;
741 print '</td></tr>';
742 return -1;
743 }
744
745 fclose($lockhandle); // Remove the lock
746 dolChmod($lockfile);
747 } else {
748 print "Cannot open for writing the blockedlog .end file ".$lockfile;
749 print '</td></tr>';
750 return -1;
751 }
752 } else {
753 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
754 $sql .= " WHERE name = '".$db->escape(basename($lockfile))."' AND entity = ".((int) $conf->entity);
755 $resql = $db->query($sql);
756
757 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity)";
758 $sql .= " VALUES('".$db->escape(basename($lockfile))."', '".$db->escape($stringtowriteencoded)."', 'chaine', 0, 'Blockedlog end of chain flag', ".((int) $conf->entity).")";
759 $resql = $db->query($sql);
760 if (!$resql) {
761 print "Cannot open for writing the blockedlog .end file ".basename($lockfile);
762 print '</td></tr>';
763 return -1;
764 }
765 }
766
767 print $langs->trans("Done");
768 print '</td></tr>';
769 }
770
771 return 1;
772}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
migrate_blockedlog_add_end_file()
Migrate an old database to add the .end flag.
sumAmountsForUnalterableEvent($block, &$refinvoicefound, &$totalhtamount, &$totalvatamount, &$totalamount, &$total_ht, &$total_vat, &$total_ttc)
sumAmountsForUnalterableEvent
getBlockedLogVersionToShow()
Define head array for tabs of blockedlog tools setup pages.
pdfWriteBlockedLogSignature(&$pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Add some information from the blockedlog module.
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 Must be the same fields than the one defined as mandat...
userIsTaxAuditor()
Call remote API service to push the last counter and signature.
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.
isRegistrationDataSavedAndPushed()
Return if the KYC mandatory parameters are set AND pushed/registered centralized server.
getHashUniqueIdOfRegistration($algo='sha256')
Return a hash unique identifier of the registration (used to identify the registration of instance wi...
isALNERunningVersion($blockedlogtestalreadydone=0, $blockedlogmodulealreadydone=0)
Return if the application is executed with the LNE requirements on.
callApiToGetObfuscationKey($idprof1, $registrationnumber, $force=false)
Call remote API service to get the obfuscation key.
Class to manage Blocked Log.
Class to manage third parties objects (customers, suppliers, prospects...)
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_now($mode='gmt')
Return date for now.
dolChmod($filepath, $newmask='')
Change mod of a file.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array(), $morelogsuffix='')
Function to get a content from an URL (use proxy if proxy defined).
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.