Skip to content

Commit

Permalink
NEW blocklog other things
Browse files Browse the repository at this point in the history
fix minor
add view only for error
add download log as csv
add record event on bill send by mail event
  • Loading branch information
alexis Algoud committed Jun 13, 2017
1 parent 3f06476 commit f780af3
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 27 deletions.
103 changes: 80 additions & 23 deletions htdocs/blockedlog/admin/fingerprints.php
Expand Up @@ -34,6 +34,9 @@
if (! $user->admin) accessforbidden();

$action = GETPOST('action','alpha');
$showonlyerrors = GETPOST('showonlyerrors','int');

$block_static = new BlockedLog($db);

if($action === 'downloadblockchain') {

Expand All @@ -49,14 +52,57 @@

exit;
}

else if($action === 'downloadcsv') {

$res = $db->query("SELECT rowid,tms,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user
FROM ".MAIN_DB_PREFIX."blockedlog ORDER BY rowid ASC");

if($res) {

$signature = $block_static->getSignature();

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" .$signature. ".csv\"");

print $langs->transnoentities('Id')
.';'.$langs->transnoentities('Timestamp')
.';'.$langs->transnoentities('Action')
.';'.$langs->transnoentities('Amounts')
.';'.$langs->transnoentities('Element')
.';'.$langs->transnoentities('ObjectId')
.';'.$langs->transnoentities('Date')
.';'.$langs->transnoentities('Ref')
.';'.$langs->transnoentities('Fingerprint')
.';'.$langs->transnoentities('User')."\n";

while($obj = $db->fetch_object($res)) {

print $obj->rowid
.';'.$obj->tms
.';'.$obj->action
.';'.$obj->amounts
.';'.$obj->element
.';'.$obj->fk_object
.';'.$obj->date_object
.';'.$obj->ref_object
.';'.$obj->signature
.';'.$obj->fk_user."\n";

}

exit;
}
else{
setEventMessage($db->lasterror, 'errors');
}

}

/*
* View
*/

$block_static = new BlockedLog($db);

$blocks = $block_static->getLog('all', 0, GETPOST('all') ? 0 : 50);

$form=new Form($db);
Expand All @@ -74,8 +120,13 @@

print '<br>';

echo '<div align="right"><a href="?all=1">'.$langs->trans('ShowAllFingerPrintsMightBeTooLong').'</a> | <a href="?action=downloadblockchain">'.$langs->trans('DownloadBlockChain').'</a></div>';

print '<div align="right">';
print ' <a href="?all=1">'.$langs->trans('ShowAllFingerPrintsMightBeTooLong').'</a>';
print ' | <a href="?all=1&showonlyerrors=1">'.$langs->trans('ShowAllFingerPrintsErrorsMightBeTooLong').'</a>';
print ' | <a href="?action=downloadblockchain">'.$langs->trans('DownloadBlockChain').'</a>';
print ' | <a href="?action=downloadcsv">'.$langs->trans('DownloadLogCSV').'</a>';
print ' </div>';


print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
Expand All @@ -92,24 +143,30 @@
print '</tr>';

foreach($blocks as &$block) {

$checksignature = $block->checkSignature();
$object_link = $block->getObjectLink();

print '<tr class="oddeven">';
print '<td>'.dol_print_date($block->tms,'dayhour').'</td>';
print '<td>'.$block->ref_object.'</td>';
print '<td>'.$langs->trans('log'.$block->action).'</td>';
print '<td>'.$block->getObject().'<a href="#" blockid="'.$block->id.'" rel="show-info">'.img_info($langs->trans('ShowDetails')).'</a></td>';
print '<td align="right">'.price($block->amounts).'</td>';
print '<td>'.$block->getUser().'</td>';
print '<td>'.$block->signature.'</td>';
print '<td>';

print $block->checkSignature() ? img_picto($langs->trans('OkCheckFingerprintValidity'), 'on') : img_picto($langs->trans('KoCheckFingerprintValidity'), 'off');
if(!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
print ' '.($block->certified ? img_picto($langs->trans('AddedByAuthority'), 'info') : img_picto($langs->trans('NotAddedByAuthorityYet'), 'info_black') );
}
print '</td>';
print '</tr>';

if(!$showonlyerrors || $block->error>0) {

print '<tr class="oddeven">';
print '<td>'.dol_print_date($block->tms,'dayhour').'</td>';
print '<td>'.$block->ref_object.'</td>';
print '<td>'.$langs->trans('log'.$block->action).'</td>';
print '<td>'.$object_link.'<a href="#" blockid="'.$block->id.'" rel="show-info">'.img_info($langs->trans('ShowDetails')).'</a></td>';
print '<td align="right">'.price($block->amounts).'</td>';
print '<td>'.$block->getUser().'</td>';
print '<td>'.$block->signature.'</td>';
print '<td>';

print $block->error == 0 ? img_picto($langs->trans('OkCheckFingerprintValidity'), 'on') : img_picto($langs->trans('KoCheckFingerprintValidity'), 'off');
if(!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
print ' '.($block->certified ? img_picto($langs->trans('AddedByAuthority'), 'info') : img_picto($langs->trans('NotAddedByAuthorityYet'), 'info_black') );
}
print '</td>';
print '</tr>';

}
}

print '</table>';
Expand All @@ -121,7 +178,7 @@
$pop = $('<div id="pop-info"><table width="100%" class="border"><thead><th width="25%"><?php echo $langs->trans('Field') ?></th><th><?php echo $langs->trans('Value') ?></th></thead><tbody></tbody></table></div>');

$pop.dialog({
title:"<?php echo $langs->trans('BlockedlogInfoDialog'); ?>"
title:"<?php echo $langs->transnoentities('BlockedlogInfoDialog'); ?>"
,modal:true
,width:'80%'
});
Expand Down
18 changes: 15 additions & 3 deletions htdocs/blockedlog/class/blockedlog.class.php
Expand Up @@ -78,6 +78,7 @@ class BlockedLog

public $object_data = null;

public $error = 0;

/**
* Constructor
Expand All @@ -91,9 +92,9 @@ public function __construct(DoliDB $db)
}

/**
* try to retrieve logged object
* try to retrieve logged object link
*/
public function getObject() {
public function getObjectLink() {
global $langs;

if($this->element === 'facture') {
Expand All @@ -103,6 +104,9 @@ public function getObject() {
if($object->fetch($this->fk_object)>0) {
return $object->getNomUrl(1);
}
else{
$this->error++;
}
}
else if($this->element === 'payment') {
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
Expand All @@ -111,6 +115,9 @@ public function getObject() {
if($object->fetch($this->fk_object)>0) {
return $object->getNomUrl(1);
}
else{
$this->error++;
}
}

return $langs->trans('ImpossibleToReloadObject', $this->element, $this->fk_object);
Expand Down Expand Up @@ -388,8 +395,13 @@ public function checkSignature() {

$this->getSignatureRecursive();

return ($signature_to_test=== $this->signature);
$res = ($signature_to_test === $this->signature);

if(!$res) {
$this->error++;
}

return $res;
}

/**
Expand Down
Expand Up @@ -51,7 +51,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
return 0;
}

if($action==='BILL_VALIDATE' || $action === 'BILL_PAYED' || $action==='BILL_UNPAYED') {
if($action==='BILL_VALIDATE' || $action === 'BILL_PAYED' || $action==='BILL_UNPAYED' || $action === 'BILL_SENTBYMAIL') {
$amounts= (double) $object->total_ttc;
}
else if($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_ADD_TO_BANK') {
Expand Down
5 changes: 5 additions & 0 deletions htdocs/langs/en_US/blockedlog.lang
Expand Up @@ -3,6 +3,7 @@ BlockedLogDesc=This module store event for invoice and payments as block chain
FingerprintsDesc=All fingerprints stored
EntityKey=Entity Key
ShowAllFingerPrintsMightBeTooLong=Show all fingerprints (might be long)
ShowAllFingerPrintsErrorsMightBeTooLong=Show all fingerprints with error (might be long)
DownloadBlockChain=Download fingerprints
KoCheckFingerprintValidity=Fingerprint is not valid
OkCheckFingerprintValidity=Fingerprint is valid
Expand All @@ -14,3 +15,7 @@ logPAYMENT_CUSTOMER_CREATE=Payment of customer created
logBILL_PAYED=Customer bill payed
logBILL_UNPAYED=Customer bill set unpayed
logBILL_VALIDATE=Customer bill set valid from draft
logBILL_SENTBYMAIL=Customer bill send by mail
BlockedlogInfoDialog=Log Details
Fingerprint=Fingerprint
DownloadLogCSV=Download fingerprints CSV

0 comments on commit f780af3

Please sign in to comment.