Clean code

This commit is contained in:
Laurent Destailleur 2026-02-21 22:34:37 +01:00
parent bb8290ef23
commit cdbd56c0ba
4 changed files with 177 additions and 157 deletions

View file

@ -240,26 +240,16 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$nameofdownoadedfile = "unalterable-log-archive-".$dolibarr_main_db_name."-".str_replace('-', '', $yearmonthtoexport).'-'.$yearmonthdateofexportstandard.'UTC-'.$suffixperiod.'.csv';
//$tmpfile = $conf->admin->dir_temp.'/unalterable-log-archive-tmp-'.$user->id.'.csv';
$tmpfileshort = 'blockedlog/archives/'.$nameofdownoadedfile;
$tmpfile = getMultidirOutput($block_static, 'blockedlog').'/archives/'.$nameofdownoadedfile;
$formatexport = 'VE1';
// Init var for totals
/*
$totalhtamountalllines = array('BILL_VALIDATE' => 0, 'PAYMENT_CUSTOMER_CREATE' => 0);
$totalvatamountalllines = array('BILL_VALIDATE' => 0, 'PAYMENT_CUSTOMER_CREATE' => 0);
$totalamountalllines = array('BILL_VALIDATE' => 0, 'PAYMENT_CUSTOMER_CREATE' => 0);
$totalhtamountlifetime = array('BILL_VALIDATE' => array(), 'PAYMENT_CUSTOMER_CREATE' => array());
$totalvatamountlifetime = array('BILL_VALIDATE' => array(), 'PAYMENT_CUSTOMER_CREATE' => array());
$totalamountlifetime = array('BILL_VALIDATE' => array(), 'PAYMENT_CUSTOMER_CREATE' => array());
*/
$formatexport = 'VE2';
if (!$error) {
$fh = fopen($tmpfile, 'w');
if (empty($fh)) {
$error++;
setEventMessages('Failed to open file for writing', null, 'errors');
setEventMessages('Failed to open file '.$tmpfileshort.' for writing.', null, 'errors');
}
}
@ -305,7 +295,6 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$totalhtamount = array();
$totalvatamount = array();
$totalamount = array();
$previoushashexport = '';
while ($obj = $db->fetch_object($resql)) {
// We set here all data used into signature calculation (see checkSignature method) and more
@ -394,14 +383,7 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$statusofrecordnote = $langs->trans("PreviousFingerprint").': '.$previoushash.($statusofrecordnote ? ' - '.$statusofrecordnote : '');
}
$concatenateddata = $block_static->buildKeyForSignature();
// Version line archive VE1=sha256
$signatureexport = '';
if ($formatexport == 'VE1') {
// Note: The signature on export line is not used. It has been replaced with a global signature on all file.
$signatureexport = dol_hash($previoushashexport.$concatenateddata, 'sha256');
}
//$concatenateddata = $block_static->buildKeyForSignature();
// Define $totalhtamount, $totalvatamount, $totalamount for $block->action event / $block->module_source
$total_ht = $total_vat = $total_ttc = 0;
@ -409,14 +391,14 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
fwrite($fh, ";"
.csvClean($block_static->id).';'
.csvClean($block_static->date_creation).';'
.csvClean(dol_print_date($block_static->date_creation, 'standard', 'gmt')).';'
.csvClean($block_static->action).';'
.csvClean($block_static->module_source).';'
.csvClean($block_static->pos_source).';'
.csvClean($block_static->amounts_taxexcl).';' // Can be 1.20000000 with 8 digits. TODO Clean to have 8 digits in V1
.csvClean($block_static->amounts).';' // Can be 1.20000000 with 8 digits. TODO Clean to have 8 digits in V1
.csvClean($block_static->ref_object).';'
.csvClean($block_static->date_object).';'
.csvClean(dol_print_date($block_static->date_object, 'standard', 'gmt')).';'
.csvClean($block_static->user_fullname).';'
.csvClean($block_static->linktoref).';'
.csvClean($block_static->linktype).';'
@ -425,12 +407,10 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
.csvClean($block_static->object_format).';'
.csvClean($block_static->signature).';'
.csvClean($statusofrecord).';'
//.csvClean($signatureexport).';'
."\n");
// Set new previous hash for next fetch
$previoushash = $obj->signature;
$previoushashexport = $signatureexport;
$i++;
}
@ -440,7 +420,6 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
}
// Now calculate cumulative total of all invoices validated
/*
if (array_key_exists('BILL_VALIDATE', $totalhtamount)) {
foreach ($totalhtamount['BILL_VALIDATE'] as $val) { // Loop on each module
$totalhtamountalllines['BILL_VALIDATE'] += $val;
@ -452,28 +431,27 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$totalamountalllines['BILL_VALIDATE'] += $val;
}
}
if (array_key_exists('PAYMENT_CUSTOMER_CREATE', $totalhtamount)) {
foreach ($totalhtamount['PAYMENT_CUSTOMER_CREATE'] as $val) {
$totalhtamountalllines['PAYMENT_CUSTOMER_CREATE'] += $val;
if (array_key_exists('PAYMENT_CUSTOMER', $totalhtamount)) {
foreach ($totalhtamount['PAYMENT_CUSTOMER'] as $val) {
$totalhtamountalllines['PAYMENT_CUSTOMER'] += $val;
}
foreach ($totalvatamount['PAYMENT_CUSTOMER_CREATE'] as $val) {
$totalvatamountalllines['PAYMENT_CUSTOMER_CREATE'] += $val;
foreach ($totalvatamount['PAYMENT_CUSTOMER'] as $val) {
$totalvatamountalllines['PAYMENT_CUSTOMER'] += $val;
}
foreach ($totalamount['PAYMENT_CUSTOMER_CREATE'] as $val) {
$totalamountalllines['PAYMENT_CUSTOMER_CREATE'] += $val;
foreach ($totalamount['PAYMENT_CUSTOMER'] as $val) {
$totalamountalllines['PAYMENT_CUSTOMER'] += $val;
}
}
// Add a final line with cumulative total of invoices validated (BILL_VALIDATE)
$block_static->id = '';
$block_static->date_creation = '';
$block_static->action = 'BILL_VALIDATE';
$block_static->action = '';
$block_static->module_source = '*';
$block_static->pos_source = '*';
$block_static->amounts_taxexcl = $totalhtamountalllines['BILL_VALIDATE'];
$block_static->amounts = $totalamountalllines['BILL_VALIDATE'];
$block_static->ref_object = $langs->transnoentitiesnoconv("VAT").': '.$totalvatamountalllines['BILL_VALIDATE'];
$block_static->amounts_taxexcl = '';
$block_static->amounts = '';
$block_static->ref_object = '';
$block_static->date_object = '';
$block_static->user_fullname = '';
$block_static->linktoref = '';
@ -483,10 +461,8 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$block_static->signature = '';
$statusofrecord = '';
$signatureexport = '';
fwrite($fh, 'Cumulative total - Invoice validations (all invoices);'
fwrite($fh, 'SUMMARY TURNOVER BILLED - '.$langs->transnoentitiesnoconv("Bills").' : '.$totalhtamountalllines['BILL_VALIDATE'].' '.$langs->trans("HT").' - '.$totalvatamountalllines['BILL_VALIDATE'].' '.$langs->trans("VAT").' - '.$totalamountalllines['BILL_VALIDATE'].' '.$langs->trans("HT").';'
.csvClean($block_static->id).';'
.csvClean($block_static->date_creation).';'
.csvClean($block_static->action).';'
@ -503,18 +479,17 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
.csvClean($block_static->object_version).';'
.csvClean($block_static->object_format).';'
.csvClean($block_static->signature).';'
.csvClean($statusofrecord).';'
.csvClean($signatureexport).';'."\n");
.csvClean($statusofrecord).';'."\n");
// Add a final line with cumulative total of invoices validated (PAYMENT_CUSTOMER_CREATE)
$block_static->id = '';
$block_static->date_creation = '';
$block_static->action = 'PAYMENT_CUSTOMER_CREATE';
$block_static->action = '';
$block_static->module_source = '*';
$block_static->pos_source = '*';
$block_static->amounts_taxexcl = '';
$block_static->amounts = $totalamountalllines['PAYMENT_CUSTOMER_CREATE'];
$block_static->amounts = '';
$block_static->ref_object = '';
$block_static->date_object = '';
$block_static->user_fullname = '';
@ -524,9 +499,8 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$block_static->object_format = '';
$block_static->signature = '';
$statusofrecord = '';
$signatureexport = '';
fwrite($fh, 'Cumulative total - Invoice payments (all payments);'
fwrite($fh, 'SUMMARY TURNOVER PAID - '.$langs->transnoentitiesnoconv("Payments").' : '.$totalamountalllines['PAYMENT_CUSTOMER'].';'
.csvClean($block_static->id).';'
.csvClean($block_static->date_creation).';'
.csvClean($block_static->action).';'
@ -543,18 +517,20 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
.csvClean($block_static->object_version).';'
.csvClean($block_static->object_format).';'
.csvClean($block_static->signature).';'
.csvClean($statusofrecord).';'
.csvClean($signatureexport).';'."\n");
.csvClean($statusofrecord).';'."\n");
$totalamountlifetime = array('BILL_VALIDATE' => 0, 'PAYMENT_CUSTOMER_CREATE' => 0, 'PAYMENT_CUSTOMER_DELETE' => 0);
$totalhtamountlifetime = array('BILL_VALIDATE' => 0, 'PAYMENT_CUSTOMER_CREATE' => 0, 'PAYMENT_CUSTOMER_DELETE' => 0);
// Calculate lifetime totals (with date of first record)
$sql = "SELECT action, module_source, pos_source, object_format, MIN(date_creation) as datemin, SUM(amounts_taxexcl) as sumamounts_taxexcl, SUM(amounts) as sumamounts";
$sql = "SELECT action, module_source, object_format, MIN(date_creation) as datemin, SUM(amounts_taxexcl) as sumamounts_taxexcl, SUM(amounts) as sumamounts";
$sql .= " FROM ".MAIN_DB_PREFIX."blockedlog";
$sql .= " WHERE entity = ".((int) $conf->entity);
//$sql .= " AND action IN ('BILL_VALIDATE', 'BILL_SENTBYMAIL', 'PAYMENT_CUSTOMER_CREATE', 'CASHCONTROL_CLOSE', 'PAYMENT_CUSTOMER_DELETE', 'DOC_DOWNLOAD', 'DOC_PREVIEW')";
$sql .= " AND action IN ('BILL_VALIDATE', 'PAYMENT_CUSTOMER_CREATE', 'PAYMENT_CUSTOMER_DELETE')"; // Only event into lifetime total
//$sql .= " AND action IN ('PAYMENT_CUSTOMER_CREATE')";
$sql .= " GROUP BY action, module_source, pos_source, object_format";
$sql .= " AND date_creation < '".$db->idate(dol_get_last_day(GETPOSTINT('yeartoexport'), GETPOSTINT('monthtoexport') > 0 ? GETPOSTINT('monthtoexport') : 12))."'";
$sql .= " GROUP BY action, module_source, object_format";
$foundoldformat = 0;
$firstrecorddatearray = array();
@ -564,10 +540,9 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
while ($obj = $db->fetch_object($resql)) {
// First record date per action code and module
if (!empty($firstrecorddatearray[$obj->action][$obj->module_source])) {
$firstrecorddatearray[$obj->action][$obj->module_source] = min($firstrecorddatearray[$obj->action][$obj->module_source], $db->jdate($obj->datemin, 'gmt'));
$firstrecorddatearray[$obj->action] = min($firstrecorddatearray[$obj->action][$obj->module_source], $db->jdate($obj->datemin, 'gmt'));
} else {
$firstrecorddatearray[$obj->action] = array();
$firstrecorddatearray[$obj->action][$obj->module_source] = $db->jdate($obj->datemin, 'gmt');
$firstrecorddatearray[$obj->action] = $db->jdate($obj->datemin, 'gmt');
}
// First record for all actions code
if (!empty($firstrecorddate)) {
@ -576,20 +551,18 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$firstrecorddate = $obj->datemin;
}
if (!isset($totalamountlifetime[$obj->action][$obj->module_source])) {
$totalamountlifetime[$obj->action][$obj->module_source] = 0;
if (!isset($totalamountlifetime[$obj->action])) {
$totalamountlifetime[$obj->action] = 0;
}
//var_dump($obj->action, $obj->module_source, $obj->sumamounts);
// Total per action code and module
$totalamountlifetime[$obj->action][$obj->module_source] += $obj->sumamounts;
$totalamountlifetime[$obj->action] += $obj->sumamounts;
// If format of line is old, the sumamounts_taxexcl was not recorded. So we flag this case.
if (empty($obj->object_format) || $obj->object_format == 'V1') {
$foundoldformat = 1;
} else {
$totalhtamountlifetime[$obj->action][$obj->module_source] += $obj->sumamounts_taxexcl;
$totalhtamountlifetime[$obj->action] += $obj->sumamounts_taxexcl;
}
}
} else {
@ -597,58 +570,39 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
setEventMessages($db->lasterror, null, 'errors');
}
// Now calculate cumulative total of all invoices validated
if (array_key_exists('BILL_VALIDATE', $totalhtamount)) {
foreach ($totalhtamount['BILL_VALIDATE'] as $val) { // Loop on each module
$totalhtamountalllines['BILL_VALIDATE'] += $val;
}
foreach ($totalvatamount['BILL_VALIDATE'] as $val) {
$totalvatamountalllines['BILL_VALIDATE'] += $val;
}
foreach ($totalamount['BILL_VALIDATE'] as $val) {
$totalamountalllines['BILL_VALIDATE'] += $val;
}
}
if (array_key_exists('PAYMENT_CUSTOMER', $totalhtamount)) {
foreach ($totalhtamount['PAYMENT_CUSTOMER'] as $val) {
$totalhtamountalllines['PAYMENT_CUSTOMER'] += $val;
}
foreach ($totalvatamount['PAYMENT_CUSTOMER'] as $val) {
$totalvatamountalllines['PAYMENT_CUSTOMER'] += $val;
}
foreach ($totalamount['PAYMENT_CUSTOMER'] as $val) {
$totalamountalllines['PAYMENT_CUSTOMER'] += $val;
}
}
// Add a final line with perpetual total for invoice validations
$block_static->id = '';
$block_static->date_creation = '';
$block_static->action = 'BILL_VALIDATE';
$block_static->action = '';
$block_static->module_source = '*';
$block_static->pos_source = '*';
// if an old format was found, we do not have reliable amount excluding tax for lifetime value, we do not show it
$block_static->amounts_taxexcl = ($foundoldformat ? '' : $totalhtamountlifetime['BILL_VALIDATE']);
$block_static->amounts = $totalamountlifetime['BILL_VALIDATE'];
// if an old format was found, we do not have reliable VAT amount for lifetime value, we do not show it
$block_static->ref_object = ($foundoldformat ? '' : $langs->transnoentitiesnoconv("VAT").': '.($block_static->amounts - $block_static->amounts_taxexcl));
$block_static->date_object = '';
$block_static->user_fullname = '';
$block_static->linktoref = '';
$block_static->linktype = '';
$block_static->object_version = '';
$block_static->object_format = '';
$block_static->signature = '';
$statusofrecord = '';
$signatureexport = '';
fwrite($fh, 'Lifetime total (>= '.dol_print_date($firstrecorddate, 'standard').') - Invoice validations (all invoices);'
.csvClean($block_static->id).';'
.csvClean($block_static->date_creation).';'
.csvClean($block_static->action).';'
.csvClean($block_static->module_source).';'
.csvClean($block_static->pos_source).';'
.csvClean($block_static->amounts_taxexcl).';' // Can be 1.20000000 with 8 digits. TODO Clean to have 8 digits in V1
.csvClean($block_static->amounts).';' // Can be 1.20000000 with 8 digits. TODO Clean to have 8 digits in V1
.csvClean($block_static->ref_object).';'
.csvClean($block_static->date_object).';'
.csvClean($block_static->user_fullname).';'
.csvClean($block_static->linktoref).';'
.csvClean($block_static->linktype).';'
.csvClean($obj->object_data).';' // We must use the string (so $obj->object_data) and not the array decoded with dolDecodeBlockedData
.csvClean($block_static->object_version).';'
.csvClean($block_static->object_format).';'
.csvClean($block_static->signature).';'
.csvClean($statusofrecord).';'
.csvClean($signatureexport).';'."\n");
// Add a final line with perpetual total for customer payments
$block_static->id = '';
$block_static->date_creation = '';
$block_static->action = 'PAYMENT_CUSTOMER_CREATE';
$block_static->module_source = '*';
$block_static->pos_source = '*';
$block_static->amounts_taxtecl = '';
$block_static->amounts = array_sum($totalamountlifetime['PAYMENT_CUSTOMER_CREATE']);
$block_static->amounts_taxexcl = '';
$block_static->amounts = '';
$block_static->ref_object = '';
$block_static->date_object = '';
$block_static->user_fullname = '';
@ -659,9 +613,8 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$block_static->signature = '';
$statusofrecord = '';
$signatureexport = '';
fwrite($fh, 'Lifetime total (>= '.dol_print_date($firstrecorddate, 'standard').') - Invoice payments (all payments);'
fwrite($fh, 'SUMMARY LIFETIME BILLED - '.$langs->transnoentitiesnoconv("Invoices").' : '.$totalhtamountalllines['BILL_VALIDATE'].' '.$langs->trans("HT")." - ".($foundoldformat ? '' : ($totalamountalllines['BILL_VALIDATE'] - $totalhtamountalllines['BILL_VALIDATE']).' '.$langs->transnoentitiesnoconv("VAT")).' - '.$totalamountalllines['BILL_VALIDATE'].' '.$langs->trans("TTC").";"
.csvClean($block_static->id).';'
.csvClean($block_static->date_creation).';'
.csvClean($block_static->action).';'
@ -679,8 +632,46 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
.csvClean($block_static->object_format).';'
.csvClean($block_static->signature).';'
.csvClean($statusofrecord).';'
.csvClean($signatureexport).';'."\n");
*/
.csvClean('>= '.dol_print_date($firstrecorddate, 'standard')).";\n");
// Add a final line with perpetual total for customer payments
$block_static->id = '';
$block_static->date_creation = '';
$block_static->action = '';
$block_static->module_source = '*';
$block_static->pos_source = '*';
$block_static->amounts_taxtecl = '';
$block_static->amounts = '';
$block_static->ref_object = '';
$block_static->date_object = '';
$block_static->user_fullname = '';
$block_static->linktoref = '';
$block_static->linktype = '';
$block_static->object_version = '';
$block_static->object_format = '';
$block_static->signature = '';
$statusofrecord = '';
fwrite($fh, 'SUMMARY LIFETIME PAID - '.$langs->transnoentitiesnoconv("Payments").' : '.($totalamountlifetime['PAYMENT_CUSTOMER_CREATE'] + $totalamountlifetime['PAYMENT_CUSTOMER_DELETE']).";"
.csvClean($block_static->id).';'
.csvClean($block_static->date_creation).';'
.csvClean($block_static->action).';'
.csvClean($block_static->module_source).';'
.csvClean($block_static->pos_source).';'
.csvClean($block_static->amounts_taxexcl).';' // Can be 1.20000000 with 8 digits. TODO Clean to have 8 digits in V1
.csvClean($block_static->amounts).';' // Can be 1.20000000 with 8 digits. TODO Clean to have 8 digits in V1
.csvClean($block_static->ref_object).';'
.csvClean($block_static->date_object).';'
.csvClean($block_static->user_fullname).';'
.csvClean($block_static->linktoref).';'
.csvClean($block_static->linktype).';'
.csvClean($obj->object_data).';' // We must use the string (so $obj->object_data) and not the array decoded with dolDecodeBlockedData
.csvClean($block_static->object_version).';'
.csvClean($block_static->object_format).';'
.csvClean($block_static->signature).';'
.csvClean('>= '.dol_print_date($firstrecorddate, 'standard')).";\n");
fclose($fh);
@ -692,10 +683,6 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
// Now add a signature to check integrity at end of file
file_put_contents($tmpfile, 'END - sha256='.$sha256.' - hmac_sha256='.$hmacsha256, FILE_APPEND);
dolChmod($tmpfile);
if (!$error) {
setEventMessages($langs->trans("FileGenerated"), null);
}
}
if (!$error) {
@ -722,19 +709,25 @@ if ($action == 'export' && $user->hasRight('blockedlog', 'read')) { // read is
$result = $b->setObjectData($object, $action, 0, $user, 0);
if ($result < 0) {
setEventMessages('Failed to insert the export int the unalterable log', null, 'errors');
setEventMessages('Failed to insert the export into the unalterable log. Export canceled: '.$b->error, null, 'errors');
dol_delete_file($tmpfile);
$error++;
}
$res = $b->create($user);
if ($res < 0) {
setEventMessages('Failed to insert the export int the unalterable log', null, 'errors');
setEventMessages('Failed to insert the export into the unalterable log. Export canceled: '.$b->error, null, 'errors');
dol_delete_file($tmpfile);
$error++;
}
}
}
if (!$error && $fh) {
setEventMessages($langs->trans("FileGenerated"), null);
}
$action = '';
}
@ -837,33 +830,8 @@ if ($action == 'check' || $action == 'checkconfirmed') {
dol_mkdir($upload_dir.'/temp');
$result = dol_copy($fullpath, $fullpathtmp);
// Generate tmp file content without the last line
// TODO Move this into removeLastLine() function into files.lib.php
$fp = fopen($fullpathtmp, "r");
fseek($fp, -1, SEEK_END);
$pos = -1;
$char = fgetc($fp);
while ($char === "\n" || $char === "\r") { // Go to last real char of last line
fseek($fp, $pos--, SEEK_END);
$char = fgetc($fp);
}
while ($char !== "\n" && $char !== false) {
fseek($fp, $pos--, SEEK_END);
$char = fgetc($fp);
}
/*
while ($char === "\n" || $char === "\r") { // Go to last real char of last-1 line
fseek($fp, $pos--, SEEK_END);
$char = fgetc($fp);
}
*/
$truncatePos = ftell($fp);
fclose($fp);
// Truncate the tmp file to remove the last line
$fp = fopen($fullpathtmp, "c+");
ftruncate($fp, $truncatePos);
fclose($fp);
// Remove the last line of text file
removeLastLine($fullpathtmp);
print $langs->trans("FileHasBeenEncodedWithASecretKeyStartingWith").' : '.$regnumber.'...<br>';
if (preg_match('/^'.$regnumber.'/', $secretkey)) {
@ -882,7 +850,7 @@ if ($action == 'check' || $action == 'checkconfirmed') {
if ($action == 'checkconfirmed') {
$totalhtamountforaction = $totalvatamountforaction = $totalamountforaction = array(
'BILL_VALIDATE' => 0,
'PAYMENT_CUSTOMER_CREATE' => 0
'PAYMENT_CUSTOMER' => 0 // PAYMENT_CUSTOMER_CREATE + PAYMENT_CUSTOMER_DELETE
);
$reg = array();
$refinvoicefound = array();
@ -893,7 +861,6 @@ if ($action == 'check' || $action == 'checkconfirmed') {
$algosign = '';
$algoauth = '';
$previoushash = '';
$previoushashexport = '';
$nbLinesModifiedInExportButKo = 0;
$nbLinesModifiedBeforeExport = 0;
@ -916,6 +883,8 @@ if ($action == 'check' || $action == 'checkconfirmed') {
continue;
}
$block_static->id = 0; // reset tmp record
if ($formatexport == 'VE1' && !empty($line[1])) { // Format V23
$lineanalyzed = 1;
$linetech = $line[0];
@ -968,6 +937,7 @@ if ($action == 'check' || $action == 'checkconfirmed') {
$statusline = (string) $line[17];
}
if ($block_static->id > 0) {
// Status revalidated from calculation using the HMAC secret key (possible only when we are on the same instance than
// the one hosting the initial database of the archive)
@ -985,7 +955,6 @@ if ($action == 'check' || $action == 'checkconfirmed') {
exit;
}*/
$signature = $tmp['calculatedsignature'];
$previoushash = $block_static->signature;
@ -1002,11 +971,17 @@ if ($action == 'check' || $action == 'checkconfirmed') {
//print 'The line '.$numline.' was modified into the Unalterable Log before being exported.';
}
// With format VE1, we can also use a signature export.
// Note: this fieldis not more used, it has been replacedwith a global signature on all the file
$concatenateddata = $block_static->buildKeyForSignature();
$signatureexport = dol_hash($previoushashexport.$concatenateddata, 'sha256');
$previoushashexport = $signatureexport;
// Note: this field is not more used, it has been replacedwith a global signature on all the file
/*
try {
$concatenateddata = $block_static->buildKeyForSignature();
$signatureexport = dol_hash($previoushashexport.$concatenateddata, 'sha256');
$previoushashexport = $signatureexport;
} catch(Exception $e) {
setEventMessages('Bad format for line '.$numline.'. '.$e->getMessage(), null, 'errors');
break;
}
*/
}
if ($lineanalyzed && ($lineactioncode == 'BILL_VALIDATE' || $lineactioncode == 'PAYMENT_CUSTOMER_CREATE' || $lineactioncode == 'PAYMENT_CUSTOMER_DELETE')) {
@ -1026,6 +1001,12 @@ if ($action == 'check' || $action == 'checkconfirmed') {
}
}
if (preg_match('/^SUMMARY /', (string) $line[0])) {
// We are on a line for summary information
$lineanalyzed = 1;
}
if (preg_match('/END - ([a-z0-9_]+)=([a-z0-9]+) - ([a-z0-9_]+)=([a-z0-9]+)$/', (string) $line[0], $reg)) {
$lineanalyzed = 1;
$algosign=$reg[1];
@ -1049,7 +1030,7 @@ if ($action == 'check' || $action == 'checkconfirmed') {
}
fclose($handle);
} else {
print 'Failed to open file '.GETPOST('urlfile');
setEventMessage('Failed to open file '.GETPOST('urlfile'), null, 'errors');
}
print '<br><br>';
@ -1095,12 +1076,14 @@ if ($action == 'check' || $action == 'checkconfirmed') {
print '<br><br>';
}
/*
print img_picto('', 'minus', 'class="valignmiddle pictofixedwidth"');
print '<b>'.$langs->trans("DetectionOfSystemRestoration").'</b>: ';
print '<span class="opacitymedium">';
print $langs->trans("FeatureOnlyWhenArchiveAnalyzedFrom", "https://www.dolibarr.org/onlinecheckarchive.php");
print '</span><br>';
print '<br>';
*/
print '<hr>';

View file

@ -22,7 +22,7 @@
*/
// The version of the POS system
define('DOLCERT_VERSION', '1.0.0');
define('DOLCERT_VERSION', '2.0.0');
// DOL_VERSION is now a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c

View file

@ -4154,3 +4154,40 @@ function dolDocToText($filetoprocess, $useFullTextIndexation = 'pdftotext', $opt
return array('error' => $error, 'keywords' => $keywords, 'content' => $textforfulltextindex, 'cmd' => $cmd);
}
/**
* Remove the last line of a text file
*
* @param string $fullpath Full path of file
* @return int Return <0 if error, >0 if OK
*/
function removeLastLine($fullpath)
{
// Generate tmp file content without the last line
$fp = fopen($fullpath, "r");
fseek($fp, -1, SEEK_END);
$pos = -1;
$char = fgetc($fp);
while ($char === "\n" || $char === "\r") { // Go to last real char of last line
fseek($fp, $pos--, SEEK_END);
$char = fgetc($fp);
}
while ($char !== "\n" && $char !== false) {
fseek($fp, $pos--, SEEK_END);
$char = fgetc($fp);
}
/*
while ($char === "\n" || $char === "\r") { // Go to last real char of last-1 line
fseek($fp, $pos--, SEEK_END);
$char = fgetc($fp);
}
*/
$truncatePos = ftell($fp);
fclose($fp);
// Truncate the tmp file to remove the last line
$fp = fopen($fullpath, "c+");
ftruncate($fp, $truncatePos);
fclose($fp);
return 1;
}

View file

@ -100,7 +100,7 @@ FileHasBeenCorrupted=The file integrity is wrong. It may have been altered (by a
FileHasBeenCorruptedOrNotFromInstance=The file integrity/authenticity is wrong. File may have been altered (by a disk problem or a manual corruption.
FileNotFromInstance=The file integrity seems good but authenticity is wrong. File has not been generated by this instance.
nbLinesModifiedInExportButKo=Some lines are set as valid in export but are detected as modified in Immutable Logs database.
nbLinesModifiedBeforeExport=Some lines were flagged as modified in the Immutable Logs database before the export. They are reported with value KO in the "status" column of the archive file.
nbLinesModifiedBeforeExport=Some lines were flagged as modified in the Immutable Logs database before the export. Such lines are reported with value KO in the "status" column of the archive file.
YouMayFindDocumentOn=You may find documentation related to the responsability and application usage to be compliant with local laws from this link
IfIntegrityAuthenticityIsOkYouCanGetdetailByOpeningTheFile=If integrity and authenticity of file is ok, you can get more details on all events by downloading and opening the file with any speadsheet software (Excel, LibreOffice Calc, Google sheets... using the character <b>;</b> as column separator and the <b>.</b> as decimal separator. Use "international" or "English USA" if you have predefined import presets).
IfIntegrityAuthenticityIsOkYouCanGetdetailByOpeningTheFile2=So you can use any filter of your choice and see detail of references, amounts, cumulative and/or pertetual amounts of each events.