27include_once DOL_DOCUMENT_ROOT.
'/blockedlog/versionmod.inc.php';
37 $versionbadge = constant(
'DOLCERT_VERSION');
39 if (constant(
'DOLCERT_NAME') !=
'BlockedLog') {
40 $versionbadge = constant(
'DOLCERT_NAME').
'-'.$versionbadge;
57 $langs->load(
"blockedlog");
59 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
62 $param .= ($withtabsetup?
"?withtab=".$withtabsetup :
"");
63 $param .= (
GETPOST(
'origin') ? ($param ?
'&' :
'?').
'origin='.
GETPOST(
'origin') :
'');
69 $head[$h][0] = DOL_URL_ROOT.
"/blockedlog/admin/registration.php".$param;
70 $head[$h][1] = $langs->trans(
"UserRegistration");
71 $head[$h][2] =
'registration';
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>' :
'');
82 $head[$h][2] =
'fingerprints';
86 $head[$h][0] = DOL_URL_ROOT.
"/blockedlog/admin/blockedlog_archives.php".$param;
87 $head[$h][1] = $langs->trans(
"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)$'));
95 if (($nbFiles + $nbLinks) > 0) {
96 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).
'</span>';
98 $head[$h][2] =
'archives';
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';
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';
116 $head[$h][0] = DOL_URL_ROOT.
"/blockedlog/admin/blockedlog.php".$param;
117 $head[$h][1] = $langs->trans(
"TechnicalInformation");
118 $head[$h][2] =
'technicalinfo';
149 $companycountrycode =
$mysoc->country_code;
154 if (empty($companyname) || empty($companycountrycode) || empty($companyidprof1) || empty($companyidprof2) || empty($companyemail)) {
190 return dol_hash(
'dolibarr'.
$conf->file->instance_unique_id.($conf->entity > 1 ?
$conf->entity :
''), $algo, 1);
210 if (defined(
'CERTIF_LNE') && (
int) constant(
'CERTIF_LNE') === 2) {
211 return 'CERTIF_LNE_IS_2';
214 if (!$ignoredev && preg_match(
'/\-/', DOL_VERSION)) {
220 if (!defined(
'CERTIF_LNE') || (
int) constant(
'CERTIF_LNE') === 0) {
228 return ($ignoredev ?
'' :
'NOT_BETA+').
'FR+CERTIF_LNE_IS_1'.($ignoremodule ?
'' :
'+MODENABLED');
245 if (defined(
'CERTIF_LNE') && (
int) constant(
'CERTIF_LNE') === 2
246 && ($blockedlogmoduleonalreadychecked ||
isModEnabled(
'blockedlog'))
250 if (defined(
'CERTIF_LNE') && (
int) constant(
'CERTIF_LNE') === 1
251 && ($blockedlogmoduleonalreadychecked ||
isModEnabled(
'blockedlog'))
274 if (array_key_exists(
'isblockedlogused',
$conf->cache)) {
275 return $conf->cache[
'isblockedlogused'.$ignoresystem];
278 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog";
279 $sql .=
" WHERE entity = ".((int)
$conf->entity);
281 $sql .=
" AND action NOT IN ('MODULE_SET', 'MODULE_RESET')";
283 $sql .= $db->plimit(1);
285 $resql = $db->query($sql);
286 if ($resql !==
false) {
287 $obj = $db->fetch_object($resql);
292 dol_print_error($db);
295 $conf->cache[
'isblockedlogused'.$ignoresystem] = $result;
298 dol_syslog(
"isBlockedLogUsed: ignoresystem=".$ignoresystem.
" returns ".(
string) $result);
319 if (in_array($seller->country_code, array(
'FR'))) {
320 $outputlangs->load(
"blockedlog");
321 $blockedlog_mention =
'';
324 if ($isalne ==
'CERTIF_LNE_IS_2') {
325 $blockedlog_mention = $outputlangs->transnoentitiesnoconv(
"InvoiceGeneratedWithLNECandidatePOSSystem");
327 $blockedlog_mention = $outputlangs->transnoentitiesnoconv(
"InvoiceGeneratedWithLNECertifiedPOSSystem");
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();
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;
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;
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;
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;
380 $total_ttc = $block->object_data->amount;
383 $actionkey =
'PAYMENT_CUSTOMER';
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;
392 $totalhtamount[$actionkey][$block->module_source] += $total_ht;
393 $totalvatamount[$actionkey][$block->module_source] += $total_vat;
394 $totalamount[$actionkey][$block->module_source] += $total_ttc;
396 $total_ttc = $block->amounts;
416 $obfuscationkey =
'ERROR';
418 if (empty($idprof1)) {
419 dol_syslog(
"callApiToGetObfuscationKey was called with empty idprof1", LOG_DEBUG);
420 return 'ERROR callApiToGetObfuscationKey was called with empty idprof1';
424 $url_for_ping =
getDolGlobalString(
'MAIN_URL_FOR_PING',
"https://ping.dolibarr.org/");
429 $t = microtime(
true);
430 $micro = sprintf(
"%06d", (
int) (($t - floor($t)) * 1000000));
433 $data .=
'hash_algo=dol_hash-'.urlencode($algo);
434 $data .=
'&hash_unique_id='.urlencode($hash_unique_id);
435 $data .=
'&action=dolibarrgetkeyobfuscation';
437 $data .=
'&version='.(float) DOL_VERSION;
438 $data .=
'&version_full='.urlencode(DOL_VERSION);
442 $data .=
'&entity='.(int)
$conf->entity;
447 $addheaders = array();
449 $timeoutresponse = 3;
454 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
456 $maxretry =
getDolGlobalInt(
'BLOCKEDLOG_MAX_TRY_FOR_REMOTE_OBFUSCATION_KEY', 2);
457 $retrydelay = 300000;
459 for ($tryid = 1; $tryid <= $maxretry; $tryid++) {
463 $tmpresult =
getURLContent($url_for_ping,
'POST', $data, 1, $addheaders, array(
'https'), 0, -1, $timeoutconnect, $timeoutresponse, array());
467 if ($tmpresult[
'http_code'] == 0 && !empty($tmpresult[
'curl_error_msg'])) {
468 $logerrormessage =
'Error: '.$tmpresult[
'curl_error_msg'];
469 $obfuscationkey =
'ERROR '.$tmpresult[
'curl_error_msg'];
470 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid.
"/".$maxretry.
"): ".$logerrormessage, LOG_WARNING);
471 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid.
"/".$maxretry.
"): ".$logerrormessage, LOG_WARNING, 0,
'_dolibarrgetkeyobfuscation');
473 } elseif ($tmpresult[
'http_code'] >= 500) {
474 $logerrormessage =
'Error: '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
475 $obfuscationkey =
'ERROR '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
476 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid.
"/".$maxretry.
"): ".$logerrormessage, LOG_WARNING);
477 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid.
"/".$maxretry.
"): ".$logerrormessage, LOG_WARNING, 0,
'_dolibarrgetkeyobfuscation');
479 } elseif ($tmpresult[
'http_code'] == 403) {
480 $logerrormessage =
'Error: '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
481 $obfuscationkey =
'ERROR '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
482 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid.
"/".$maxretry.
"): ".$logerrormessage, LOG_WARNING);
483 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid.
"/".$maxretry.
"): ".$logerrormessage, LOG_WARNING, 0,
'_dolibarrgetkeyobfuscation');
488 } elseif ($tmpresult[
'http_code'] != 200) {
489 $logerrormessage =
'Error: '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
490 $obfuscationkey =
'ERROR '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
491 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING);
492 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING, 0,
'_dolibarrgetkeyobfuscation');
495 if (preg_match(
'/(DOLOBFUSCKEY.*)/', $tmpresult[
'content'], $reg)) {
496 $obfuscationkey = $reg[1];
497 dol_syslog(
"callApiToGetObfuscationKey we got the remote obfuscation key", LOG_DEBUG);
498 dol_syslog(
"callApiToGetObfuscationKey we got the remote obfuscation key", LOG_DEBUG, 0,
'_dolibarrgetkeyobfuscation');
500 $obfuscationkey =
'ERROR '.$tmpresult[
'content'];
501 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key: ".$tmpresult[
'content'], LOG_WARNING);
502 dol_syslog(
"callApiToGetObfuscationKey result error when getting obfuscation key: ".$tmpresult[
'content'], LOG_WARNING, 0,
'_dolibarrgetkeyobfuscation');
506 $obfuscationkey =
'ERROR '.$e->getMessage();
507 dol_syslog(
"callApiToGetObfuscationKey result error (try ".$tryid.
"/".$maxretry.
"): ".$e->getMessage(), LOG_ERR);
508 dol_syslog(
"callApiToGetObfuscationKey result error (try ".$tryid.
"/".$maxretry.
"): ".$e->getMessage(), LOG_ERR, 0,
'_dolibarrgetkeyobfuscation');
512 if (!$retryable || $tryid == $maxretry) {
519 return $obfuscationkey;
651 if (
$object->status > $object::STATUS_DRAFT) {
652 $unalterablelogid =
'UNDEFINED';
654 $sql =
"SELECT signature FROM ".MAIN_DB_PREFIX.
"blockedlog";
655 $sql .=
" WHERE action = 'BILL_VALIDATE' AND element = 'facture' AND ref_object = '".$db->escape(
$object->ref).
"'";
656 $sql .= $db->order(
'rowid',
'DESC');
657 $sql .= $db->plimit(1);
659 $resql = $db->query($sql);
661 $obj = $db->fetch_object($resql);
663 $unalterablelogid = $obj->signature;
667 if ($unalterablelogid !=
'UNDEFINED') {
668 $pdf->SetXY($posx, $posy);
669 $pdf->SetTextColor(0, 0, 60);
670 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SignatureID").
" : ".
dol_trunc(strtoupper($unalterablelogid), 10),
'',
'R');
674 $isADuplicata = (
$object->pos_print_counter >= 2);
676 $pdf->SetXY($posx, $posy);
677 $pdf->SetTextColor(0, 0, 60);
678 $pdf->MultiCell($w, 3,
'*** '.$outputlangs->trans(
"DUPLICATA").(getDolGlobalString(
'TAKEPOS_SHOW_PRINT_COUNTER_ON_RECEIPT') ?
' (no '.($object->pos_print_counter - 1).
')' :
'').
' ***',
'',
'R');
683 if (
$object->status == $object::STATUS_DRAFT) {
684 $pdf->SetXY($posx, $posy);
685 $pdf->SetTextColor(0, 0, 60);
686 $pdf->MultiCell($w, 3,
'*** '.strtoupper($outputlangs->trans(
"TemporaryReceipt")).
' ***',
'',
'R');
703 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
708 $listofentities = array();
709 $sql =
"SELECT DISTINCT entity FROM ".MAIN_DB_PREFIX.
"blockedlog";
710 $resql = $db->query($sql);
712 while ($obj = $db->fetch_object($resql)) {
713 $listofentities[] = $obj->entity;
716 print
'<tr class="trforrunsql"><td colspan="4">';
717 print
'<b>'.$langs->trans(
'InitEndFlagFile').
"</b>:\n";
718 print
'Error: Failed to get list of entities in blockedlog table';
723 foreach ($listofentities as $entity) {
724 print
'<tr class="trforrunsql"><td colspan="4">';
725 print
'<b>'.$langs->trans(
'InitEndFlagFile').
" (entity = ".$entity.
")</b>:\n";
728 $conf->setEntityValues($db, $entity);
733 $sql =
"SELECT MAX(rowid) as maxid FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE entity = ".((int) $entity);
734 $resql = $db->query($sql);
736 $obj = $db->fetch_object($resql);
738 $maxid = $obj->maxid;
741 print
'Error: Failed to get max id of blockedlog table';
746 $blocklog_static->fetch($maxid);
748 $lockfile = $blocklog_static->getEndOfChainFlagFile();
751 $stringtowrite =
'BLOCKEDLOGHEAD '.$blocklog_static->id.
" ".
dol_print_date($blocklog_static->date_creation,
'dayhourrfc',
'gmt').
" ".(string) $blocklog_static->signature;
754 $remoteobfuscationkey = $blocklog_static->getObfuscationKey();
755 if (empty($remoteobfuscationkey)) {
756 print
"Error: Failed to get the remote obfuscation key. We can't record the end of chain flag file so we abort the transaction.";
761 $stringtowriteencoded =
dolEncrypt($stringtowrite, $remoteobfuscationkey,
'',
'',
'dolobfuscationv1-'.
$mysoc->idprof1.
'-'.$blocklog_static->id);
763 $stringtowriteencoded =
dolEncrypt($stringtowrite,
'',
'',
'',
'dolcrypt-'.
$mysoc->idprof1.
'-'.$blocklog_static->id);
767 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
768 $lockhandle = fopen($lockfile,
'w+');
770 if (fwrite($lockhandle, $stringtowriteencoded.
"\n") ===
false) {
771 print
"Cannot write to the blockedlog .end file ".$lockfile;
779 print
"Cannot open for writing the blockedlog .end file ".$lockfile;
784 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
785 $sql .=
" WHERE name = '".$db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
786 $resql = $db->query($sql);
788 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const(name, value, type, visible, note, entity)";
789 $sql .=
" VALUES('".$db->escape(basename($lockfile)).
"', '".$db->escape($stringtowriteencoded).
"', 'chaine', 0, 'Blockedlog end of chain flag', ".((int)
$conf->entity).
")";
790 $resql = $db->query($sql);
792 print
"Cannot open for writing the blockedlog .end file ".basename($lockfile);
798 print $langs->trans(
"Done");
if(! $sortfield) if(! $sortorder) $object
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($blockedlogusagealreadychecked=0, $blockedlogmoduleonalreadychecked=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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage Blocked Log.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
dol_now($mode='gmt')
Return date for now.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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, $nodefault=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_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).
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.