2017-06-10 09:25:32 +02:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2017 ATM Consulting < contact @ atm - consulting . fr >
* Copyright ( C ) 2017 - 2018 Laurent Destailleur < eldy @ destailleur . fr >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2017-06-10 09:25:32 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-06-10 09:25:32 +02:00
*/
/**
2017-11-30 15:13:23 +01:00
* \file htdocs / blockedlog / admin / blockedlog_list . php
2017-06-16 11:51:33 +02:00
* \ingroup blockedlog
2017-06-10 09:25:32 +02:00
* \brief Page setup for blockedlog module
*/
require '../../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/blockedlog/lib/blockedlog.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php' ;
2017-06-11 00:03:01 +02:00
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/authority.class.php' ;
2017-06-10 09:25:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
2018-01-12 20:24:09 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2017-06-10 09:25:32 +02:00
2018-05-27 09:58:23 +02:00
// Load translation files required by the page
2017-12-14 17:18:26 +01:00
$langs -> loadLangs ( array ( " admin " , " other " , " blockedlog " , " bills " ));
2017-06-10 09:25:32 +02:00
2021-10-23 07:13:08 +02:00
if (( ! $user -> admin && empty ( $user -> rights -> blockedlog -> read )) || empty ( $conf -> blockedlog -> enabled )) {
2021-03-01 00:19:52 +01:00
accessforbidden ();
}
2017-06-16 11:51:33 +02:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2020-04-10 10:59:32 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'blockedloglist' ; // To manage different context of search
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
2017-12-09 00:40:22 +01:00
2019-01-27 11:55:16 +01:00
$search_showonlyerrors = GETPOST ( 'search_showonlyerrors' , 'int' );
2021-03-01 00:19:52 +01:00
if ( $search_showonlyerrors < 0 ) {
$search_showonlyerrors = 0 ;
}
2017-06-13 10:04:05 +02:00
2021-08-25 11:29:29 +02:00
$search_startyear = GETPOST ( 'search_startyear' , 'int' );
$search_startmonth = GETPOST ( 'search_startmonth' , 'int' );
$search_startday = GETPOST ( 'search_startday' , 'int' );
$search_endyear = GETPOST ( 'search_endyear' , 'int' );
$search_endmonth = GETPOST ( 'search_endmonth' , 'int' );
$search_endday = GETPOST ( 'search_endday' , 'int' );
2021-02-04 23:24:59 +01:00
$search_id = GETPOST ( 'search_id' , 'alpha' );
2020-04-10 10:59:32 +02:00
$search_fk_user = GETPOST ( 'search_fk_user' , 'intcomma' );
2017-12-14 17:08:43 +01:00
$search_start = - 1 ;
2021-08-25 11:29:29 +02:00
if ( $search_startyear != '' ) {
$search_start = dol_mktime ( 0 , 0 , 0 , $search_startmonth , $search_startday , $search_startyear );
2021-03-01 00:19:52 +01:00
}
2017-12-14 17:08:43 +01:00
$search_end = - 1 ;
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'search_endyear' ) != '' ) {
$search_end = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_endmonth' ), GETPOST ( 'search_endday' ), GETPOST ( 'search_endyear' ));
}
2018-01-05 04:31:48 +01:00
$search_code = GETPOST ( 'search_code' , 'alpha' );
2017-12-14 17:08:43 +01:00
$search_ref = GETPOST ( 'search_ref' , 'alpha' );
$search_amount = GETPOST ( 'search_amount' , 'alpha' );
2021-03-01 00:19:52 +01:00
if (( $search_start == - 1 || empty ( $search_start )) && ! GETPOSTISSET ( 'search_startmonth' )) {
$search_start = dol_time_plus_duree ( dol_now (), '-1' , 'w' );
}
2017-12-14 17:08:43 +01:00
2017-11-30 15:13:23 +01:00
// Load variable for pagination
2020-04-10 10:59:32 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-03-01 00:19:52 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2017-11-30 15:13:23 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-03-01 00:19:52 +01:00
if ( empty ( $sortfield )) {
$sortfield = 'rowid' ;
}
if ( empty ( $sortorder )) {
$sortorder = 'DESC' ;
}
2017-12-09 00:40:22 +01:00
2017-12-15 15:15:14 +01:00
$block_static = new BlockedLog ( $db );
2021-02-04 23:03:09 +01:00
$block_static -> loadTrackedEvents ();
2017-12-08 17:15:24 +01:00
2017-12-15 15:15:14 +01:00
$result = restrictedArea ( $user , 'blockedlog' , 0 , '' );
2017-06-10 09:25:32 +02:00
2017-11-30 15:13:23 +01:00
2021-02-04 22:14:46 +01:00
$max_execution_time_for_importexport = ( empty ( $conf -> global -> EXPORT_MAX_EXECUTION_TIME ) ? 300 : $conf -> global -> EXPORT_MAX_EXECUTION_TIME ); // 5mn if not defined
$max_time = @ ini_get ( " max_execution_time " );
2021-03-01 00:19:52 +01:00
if ( $max_time && $max_time < $max_execution_time_for_importexport ) {
2021-02-04 22:14:46 +01:00
dol_syslog ( " max_execution_time= " . $max_time . " is lower than max_execution_time_for_importexport= " . $max_execution_time_for_importexport . " . We try to increase it dynamically. " );
@ ini_set ( " max_execution_time " , $max_execution_time_for_importexport ); // This work only if safe mode is off. also web servers has timeout of 300
}
2017-11-30 14:21:55 +01:00
/*
* Actions
*/
2017-12-09 00:40:22 +01:00
// Purge search criteria
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
2021-02-04 23:24:59 +01:00
$search_id = '' ;
2017-12-16 21:36:36 +01:00
$search_fk_user = '' ;
2017-12-09 00:40:22 +01:00
$search_start = - 1 ;
$search_end = - 1 ;
2018-01-05 04:31:48 +01:00
$search_code = '' ;
2017-12-14 17:08:43 +01:00
$search_ref = '' ;
$search_amount = '' ;
2018-01-12 20:24:09 +01:00
$search_showonlyerrors = 0 ;
2022-05-08 18:25:22 +02:00
$toselect = array ();
2020-04-10 10:59:32 +02:00
$search_array_options = array ();
2017-12-09 00:40:22 +01:00
}
if ( $action === 'downloadblockchain' ) {
2017-06-11 00:03:01 +02:00
$auth = new BlockedLogAuthority ( $db );
2017-06-16 11:51:33 +02:00
2017-06-11 00:03:01 +02:00
$bc = $auth -> getLocalBlockChain ();
2017-06-16 11:51:33 +02:00
2017-06-11 00:03:01 +02:00
header ( 'Content-Type: application/octet-stream' );
header ( " Content-Transfer-Encoding: Binary " );
2020-04-10 10:59:32 +02:00
header ( " Content-disposition: attachment; filename= \" " . $auth -> signature . " .certif \" " );
2017-06-16 11:51:33 +02:00
2017-06-11 00:03:01 +02:00
echo $bc ;
2017-06-16 11:51:33 +02:00
2017-06-11 00:03:01 +02:00
exit ;
2019-01-27 23:23:38 +01:00
} elseif ( GETPOST ( 'downloadcsv' , 'alpha' )) {
2018-01-25 12:57:36 +01:00
$error = 0 ;
2017-06-16 11:51:33 +02:00
2020-04-10 10:59:32 +02:00
$previoushash = '' ;
$firstid = '' ;
2018-01-05 13:40:56 +01:00
2021-03-01 00:19:52 +01:00
if ( ! $error ) {
2018-01-25 12:57:36 +01:00
// Get ID of first line
$sql = " SELECT rowid,date_creation,tms,user_fullname,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user,object_data " ;
2020-04-10 10:59:32 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " blockedlog " ;
$sql .= " WHERE entity = " . $conf -> entity ;
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'monthtoexport' , 'int' ) > 0 || GETPOST ( 'yeartoexport' , 'int' ) > 0 ) {
2020-04-10 10:59:32 +02:00
$dates = dol_get_first_day ( GETPOST ( 'yeartoexport' , 'int' ), GETPOST ( 'monthtoexport' , 'int' ) ? GETPOST ( 'monthtoexport' , 'int' ) : 1 );
$datee = dol_get_last_day ( GETPOST ( 'yeartoexport' , 'int' ), GETPOST ( 'monthtoexport' , 'int' ) ? GETPOST ( 'monthtoexport' , 'int' ) : 12 );
$sql .= " AND date_creation BETWEEN ' " . $db -> idate ( $dates ) . " ' AND ' " . $db -> idate ( $datee ) . " ' " ;
2017-06-13 10:04:05 +02:00
}
2020-04-10 10:59:32 +02:00
$sql .= " ORDER BY rowid ASC " ; // Required so we get the first one
$sql .= $db -> plimit ( 1 );
2017-06-16 11:51:33 +02:00
2018-01-25 12:57:36 +01:00
$res = $db -> query ( $sql );
2021-03-01 00:19:52 +01:00
if ( $res ) {
2018-01-25 12:57:36 +01:00
// Make the first fetch to get first line
$obj = $db -> fetch_object ( $res );
2021-03-01 00:19:52 +01:00
if ( $obj ) {
2018-08-09 22:29:02 +02:00
$previoushash = $block_static -> getPreviousHash ( 0 , $obj -> rowid );
$firstid = $obj -> rowid ;
2020-05-21 15:05:19 +02:00
} else { // If not data found for filter, we do not need previoushash neither firstid
2018-08-09 22:29:02 +02:00
$previoushash = 'nodata' ;
$firstid = '' ;
}
2020-05-21 15:05:19 +02:00
} else {
2018-01-25 12:57:36 +01:00
$error ++ ;
2018-07-23 17:57:11 +02:00
setEventMessages ( $db -> lasterror , null , 'errors' );
2018-01-25 12:57:36 +01:00
}
2017-06-13 10:04:05 +02:00
}
2018-01-25 12:57:36 +01:00
2021-03-01 00:19:52 +01:00
if ( ! $error ) {
2018-08-09 22:29:02 +02:00
// Now restart request with all data = no limit(1) in sql request
2018-01-25 12:57:36 +01:00
$sql = " SELECT rowid,date_creation,tms,user_fullname,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user,object_data " ;
2020-04-10 10:59:32 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " blockedlog " ;
$sql .= " WHERE entity = " . $conf -> entity ;
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'monthtoexport' , 'int' ) > 0 || GETPOST ( 'yeartoexport' , 'int' ) > 0 ) {
2020-04-10 10:59:32 +02:00
$dates = dol_get_first_day ( GETPOST ( 'yeartoexport' , 'int' ), GETPOST ( 'monthtoexport' , 'int' ) ? GETPOST ( 'monthtoexport' , 'int' ) : 1 );
$datee = dol_get_last_day ( GETPOST ( 'yeartoexport' , 'int' ), GETPOST ( 'monthtoexport' , 'int' ) ? GETPOST ( 'monthtoexport' , 'int' ) : 12 );
$sql .= " AND date_creation BETWEEN ' " . $db -> idate ( $dates ) . " ' AND ' " . $db -> idate ( $datee ) . " ' " ;
2018-01-25 12:57:36 +01:00
}
2020-04-10 10:59:32 +02:00
$sql .= " ORDER BY rowid ASC " ; // Required so later we can use the parameter $previoushash of checkSignature()
2018-01-25 12:57:36 +01:00
$res = $db -> query ( $sql );
2021-03-01 00:19:52 +01:00
if ( $res ) {
2018-01-25 12:57:36 +01:00
header ( 'Content-Type: application/octet-stream' );
header ( " Content-Transfer-Encoding: Binary " );
2020-04-10 10:59:32 +02:00
header ( " Content-disposition: attachment; filename= \" unalterable-log-archive- " . $dolibarr_main_db_name . " - " . ( GETPOST ( 'yeartoexport' , 'int' ) > 0 ? GETPOST ( 'yeartoexport' , 'int' ) . ( GETPOST ( 'monthtoexport' , 'int' ) > 0 ? sprintf ( " %02d " , GETPOST ( 'monthtoexport' , 'int' )) : '' ) . '-' : '' ) . $previoushash . " .csv \" " );
2018-01-25 12:57:36 +01:00
print $langs -> transnoentities ( 'Id' )
. ';' . $langs -> transnoentities ( 'Date' )
. ';' . $langs -> transnoentities ( 'User' )
. ';' . $langs -> transnoentities ( 'Action' )
. ';' . $langs -> transnoentities ( 'Element' )
. ';' . $langs -> transnoentities ( 'Amounts' )
. ';' . $langs -> transnoentities ( 'ObjectId' )
. ';' . $langs -> transnoentities ( 'Date' )
. ';' . $langs -> transnoentities ( 'Ref' )
. ';' . $langs -> transnoentities ( 'Fingerprint' )
. ';' . $langs -> transnoentities ( 'Status' )
. ';' . $langs -> transnoentities ( 'Note' )
. ';' . $langs -> transnoentities ( 'FullData' )
. " \n " ;
$loweridinerror = 0 ;
$i = 0 ;
2021-03-01 00:19:52 +01:00
while ( $obj = $db -> fetch_object ( $res )) {
2018-01-25 12:57:36 +01:00
// We set here all data used into signature calculation (see checkSignature method) and more
// IMPORTANT: We must have here, the same rule for transformation of data than into the fetch method (db->jdate for date, ...)
$block_static -> id = $obj -> rowid ;
$block_static -> date_creation = $db -> jdate ( $obj -> date_creation );
$block_static -> date_modification = $db -> jdate ( $obj -> tms );
$block_static -> action = $obj -> action ;
$block_static -> fk_object = $obj -> fk_object ;
$block_static -> element = $obj -> element ;
$block_static -> amounts = ( double ) $obj -> amounts ;
$block_static -> ref_object = $obj -> ref_object ;
$block_static -> date_object = $db -> jdate ( $obj -> date_object );
$block_static -> user_fullname = $obj -> user_fullname ;
$block_static -> fk_user = $obj -> fk_user ;
$block_static -> signature = $obj -> signature ;
2018-03-07 17:22:38 +01:00
$block_static -> object_data = $block_static -> dolDecodeBlockedData ( $obj -> object_data );
2018-01-25 12:57:36 +01:00
2020-04-10 10:59:32 +02:00
$checksignature = $block_static -> checkSignature ( $previoushash ); // If $previoushash is not defined, checkSignature will search it
2018-01-25 12:57:36 +01:00
2021-03-01 00:19:52 +01:00
if ( $checksignature ) {
2018-01-25 12:57:36 +01:00
$statusofrecord = 'Valid' ;
2021-03-01 00:19:52 +01:00
if ( $loweridinerror > 0 ) {
$statusofrecordnote = 'ValidButFoundAPreviousKO' ;
} else {
$statusofrecordnote = '' ;
}
2020-05-21 15:05:19 +02:00
} else {
2018-01-25 12:57:36 +01:00
$statusofrecord = 'KO' ;
$statusofrecordnote = 'LineCorruptedOrNotMatchingPreviousOne' ;
$loweridinerror = $obj -> rowid ;
}
2021-03-01 00:19:52 +01:00
if ( $i == 0 ) {
2020-04-10 10:59:32 +02:00
$statusofrecordnote = $langs -> trans ( " PreviousFingerprint " ) . ': ' . $previoushash . ( $statusofrecordnote ? ' - ' . $statusofrecordnote : '' );
2018-01-25 12:57:36 +01:00
}
2020-04-26 23:06:52 +02:00
print $obj -> rowid ;
print ';' . $obj -> date_creation ;
print ';"' . str_replace ( '"' , '""' , $obj -> user_fullname ) . '"' ;
print ';' . $obj -> action ;
print ';' . $obj -> element ;
print ';' . $obj -> amounts ;
print ';' . $obj -> fk_object ;
print ';' . $obj -> date_object ;
print ';"' . str_replace ( '"' , '""' , $obj -> ref_object ) . '"' ;
print ';' . $obj -> signature ;
print ';' . $statusofrecord ;
print ';' . $statusofrecordnote ;
print ';"' . str_replace ( '"' , '""' , $obj -> object_data ) . '"' ;
print " \n " ;
2018-01-25 12:57:36 +01:00
// Set new previous hash for next fetch
$previoushash = $obj -> signature ;
$i ++ ;
}
exit ;
2020-05-21 15:05:19 +02:00
} else {
2018-07-23 17:57:11 +02:00
setEventMessages ( $db -> lasterror , null , 'errors' );
2018-01-25 12:57:36 +01:00
}
2017-06-13 10:04:05 +02:00
}
}
2017-06-10 09:25:32 +02:00
2017-11-30 14:21:55 +01:00
2017-06-10 09:25:32 +02:00
/*
* View
*/
2020-04-10 10:59:32 +02:00
$form = new Form ( $db );
2017-06-10 09:25:32 +02:00
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'withtab' , 'alpha' )) {
2020-04-10 10:59:32 +02:00
$title = $langs -> trans ( " ModuleSetup " ) . ' ' . $langs -> trans ( 'BlockedLog' );
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$title = $langs -> trans ( " BrowseBlockedLog " );
2018-01-04 21:06:39 +01:00
}
2021-08-17 14:44:26 +02:00
$help_url = " EN:Module_Unalterable_Archives_-_Logs|FR:Module_Archives_-_Logs_Inaltérable " ;
2018-01-04 21:06:39 +01:00
2021-08-17 14:44:26 +02:00
llxHeader ( '' , $title , $help_url );
2017-06-10 09:25:32 +02:00
2021-02-05 00:04:44 +01:00
$MAXLINES = 10000 ;
2018-01-12 20:24:09 +01:00
2021-02-04 23:24:59 +01:00
$blocks = $block_static -> getLog ( 'all' , $search_id , $MAXLINES , $sortfield , $sortorder , $search_fk_user , $search_start , $search_end , $search_ref , $search_amount , $search_code );
2021-03-01 00:19:52 +01:00
if ( ! is_array ( $blocks )) {
if ( $blocks == - 2 ) {
2018-01-12 20:24:09 +01:00
setEventMessages ( $langs -> trans ( " TooManyRecordToScanRestrictFilters " , $MAXLINES ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-01-12 20:24:09 +01:00
dol_print_error ( $block_static -> db , $block_static -> error , $block_static -> errors );
exit ;
}
2017-12-14 17:08:43 +01:00
}
2020-04-10 10:59:32 +02:00
$linkback = '' ;
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'withtab' , 'alpha' )) {
2020-04-10 10:59:32 +02:00
$linkback = '<a href="' . ( $backtopage ? $backtopage : DOL_URL_ROOT . '/admin/modules.php' ) . '">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
2017-12-16 21:36:36 +01:00
}
2017-06-10 09:25:32 +02:00
2018-01-04 21:06:39 +01:00
print load_fiche_titre ( $title , $linkback );
2017-06-10 09:25:32 +02:00
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'withtab' , 'alpha' )) {
2020-04-10 10:59:32 +02:00
$head = blockedlogadmin_prepare_head ();
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'fingerprints' , '' , - 1 );
2017-12-16 21:36:36 +01:00
}
2017-06-10 09:25:32 +02:00
2018-11-27 09:22:59 +01:00
print '<span class="opacitymedium hideonsmartphone">' . $langs -> trans ( " FingerprintsDesc " ) . " <br></span> \n " ;
2017-06-10 09:25:32 +02:00
print '<br>' ;
2020-04-10 10:59:32 +02:00
$param = '' ;
2021-03-01 00:19:52 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $search_id != '' ) {
$param .= '&search_id=' . urlencode ( $search_id );
}
if ( $search_fk_user > 0 ) {
$param .= '&search_fk_user=' . urlencode ( $search_fk_user );
}
if ( $search_startyear > 0 ) {
2021-08-25 11:29:29 +02:00
$param .= '&search_startyear=' . urlencode ( $search_startyear );
2021-03-01 00:19:52 +01:00
}
if ( $search_startmonth > 0 ) {
2021-08-25 11:29:29 +02:00
$param .= '&search_startmonth=' . urlencode ( $search_startmonth );
2021-03-01 00:19:52 +01:00
}
if ( $search_startday > 0 ) {
2021-08-25 11:29:29 +02:00
$param .= '&search_startday=' . urlencode ( $search_startday );
2021-03-01 00:19:52 +01:00
}
if ( $search_endyear > 0 ) {
2021-08-25 11:29:29 +02:00
$param .= '&search_endyear=' . urlencode ( $search_endyear );
2021-03-01 00:19:52 +01:00
}
if ( $search_endmonth > 0 ) {
2021-08-25 11:29:29 +02:00
$param .= '&search_endmonth=' . urlencode ( $search_endmonth );
2021-03-01 00:19:52 +01:00
}
if ( $search_endday > 0 ) {
2021-08-25 11:29:29 +02:00
$param .= '&search_endday=' . urlencode ( $search_endday );
2021-03-01 00:19:52 +01:00
}
if ( $search_showonlyerrors > 0 ) {
$param .= '&search_showonlyerrors=' . urlencode ( $search_showonlyerrors );
}
if ( $optioncss != '' ) {
$param .= '&optioncss=' . urlencode ( $optioncss );
}
if ( GETPOST ( 'withtab' , 'alpha' )) {
$param .= '&withtab=' . urlencode ( GETPOST ( 'withtab' , 'alpha' ));
}
2017-12-16 21:36:36 +01:00
2017-12-09 00:40:22 +01:00
// Add $param from extra fields
//include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
2018-01-25 12:57:36 +01:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2020-09-24 17:08:31 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-12-09 00:40:22 +01:00
2019-01-31 13:29:34 +01:00
print '<div class="right">' ;
2018-01-25 13:18:52 +01:00
print $langs -> trans ( " RestrictYearToExport " ) . ': ' ;
2020-04-10 10:59:32 +02:00
$smonth = GETPOST ( 'monthtoexport' , 'int' );
2018-08-09 22:29:02 +02:00
// Month
2020-04-10 10:59:32 +02:00
$retstring = '' ;
$retstring .= '<select class="flat valignmiddle maxwidth75imp marginrightonly" id="monthtoexport" name="monthtoexport">' ;
$retstring .= '<option value="0" selected> </option>' ;
2021-03-01 00:19:52 +01:00
for ( $month = 1 ; $month <= 12 ; $month ++ ) {
2020-04-10 10:59:32 +02:00
$retstring .= '<option value="' . $month . '"' . ( $month == $smonth ? ' selected' : '' ) . '>' ;
$retstring .= dol_print_date ( mktime ( 12 , 0 , 0 , $month , 1 , 2000 ), " %b " );
$retstring .= " </option> " ;
2018-08-09 22:29:02 +02:00
}
2020-04-10 10:59:32 +02:00
$retstring .= " </select> " ;
2018-08-09 22:29:02 +02:00
print $retstring ;
2019-01-27 11:55:16 +01:00
print '<input type="text" name="yeartoexport" class="valignmiddle maxwidth50imp" value="' . GETPOST ( 'yeartoexport' , 'int' ) . '">' ;
print '<input type="hidden" name="withtab" value="' . GETPOST ( 'withtab' , 'alpha' ) . '">' ;
2018-01-25 12:57:36 +01:00
print '<input type="submit" name="downloadcsv" class="button" value="' . $langs -> trans ( 'DownloadLogCSV' ) . '">' ;
2021-03-01 00:19:52 +01:00
if ( ! empty ( $conf -> global -> BLOCKEDLOG_USE_REMOTE_AUTHORITY )) {
print ' | <a href="?action=downloadblockchain' . ( GETPOST ( 'withtab' , 'alpha' ) ? '&withtab=' . GETPOST ( 'withtab' , 'alpha' ) : '' ) . '">' . $langs -> trans ( 'DownloadBlockChain' ) . '</a>' ;
}
2018-01-25 13:18:52 +01:00
print ' </div><br>' ;
2017-06-13 10:04:05 +02:00
2018-01-25 12:57:36 +01:00
print '</form>' ;
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2017-06-10 09:25:32 +02:00
2020-04-10 10:59:32 +02:00
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2017-12-08 17:15:24 +01:00
2021-03-01 00:19:52 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-01-05 04:31:48 +01:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="page" value="' . $page . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="withtab" value="' . GETPOST ( 'withtab' , 'alpha' ) . '">' ;
2017-12-08 17:15:24 +01:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2018-01-05 04:31:48 +01:00
// Line of filters
2017-12-08 17:15:24 +01:00
print '<tr class="liste_titre_filter">' ;
2017-12-14 17:08:43 +01:00
2021-02-04 23:24:59 +01:00
print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="' . dol_escape_htmltag ( $search_id ) . '"></td>' ;
2017-12-08 17:15:24 +01:00
print '<td class="liste_titre">' ;
2018-01-05 04:31:48 +01:00
//print $langs->trans("from").': ';
2019-01-27 11:55:16 +01:00
print $form -> selectDate ( $search_start , 'search_start' );
2018-01-05 04:31:48 +01:00
//print '<br>';
//print $langs->trans("to").': ';
2019-01-27 11:55:16 +01:00
print $form -> selectDate ( $search_end , 'search_end' );
2017-12-08 17:15:24 +01:00
print '</td>' ;
2017-12-16 21:36:36 +01:00
// User
print '<td class="liste_titre">' ;
2018-08-09 22:52:43 +02:00
print $form -> select_dolusers ( $search_fk_user , 'search_fk_user' , 1 , null , 0 , '' , '' , 0 , 0 , 0 , '' , 0 , '' , 'maxwidth200' );
2018-01-26 23:54:45 +01:00
2017-12-16 21:36:36 +01:00
print '</td>' ;
2018-01-05 04:31:48 +01:00
// Actions code
$langs -> load ( " blockedlog " );
print '<td class="liste_titre">' ;
print $form -> selectarray ( 'search_code' , $block_static -> trackedevents , $search_code , 1 , 0 , 0 , '' , 1 , 0 , 0 , 'ASC' , 'maxwidth200' , 1 );
print '</td>' ;
2017-12-14 17:08:43 +01:00
// Ref
print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_ref" value="' . dol_escape_htmltag ( $search_ref ) . '"></td>' ;
2018-08-09 22:52:43 +02:00
// Link to ref
2017-12-14 17:08:43 +01:00
print '<td class="liste_titre"></td>' ;
// Amount
print '<td class="liste_titre right"><input type="text" class="maxwidth50" name="search_amount" value="' . dol_escape_htmltag ( $search_amount ) . '"></td>' ;
2018-01-12 20:24:09 +01:00
// Full data
2017-12-14 17:08:43 +01:00
print '<td class="liste_titre"></td>' ;
2018-01-12 20:24:09 +01:00
// Fingerprint
2017-12-14 17:08:43 +01:00
print '<td class="liste_titre"></td>' ;
2017-12-08 17:15:24 +01:00
2018-01-12 20:24:09 +01:00
// Status
print '<td class="liste_titre">' ;
2020-04-10 10:59:32 +02:00
$array = array ( " 1 " => $langs -> trans ( " OnlyNonValid " ));
2018-01-12 20:24:09 +01:00
print $form -> selectarray ( 'search_showonlyerrors' , $array , $search_showonlyerrors , 1 );
print '</td>' ;
2018-01-25 12:57:36 +01:00
// Status note
print '<td class="liste_titre"></td>' ;
2017-12-08 17:15:24 +01:00
// Action column
print '<td class="liste_titre" align="middle">' ;
2020-04-10 10:59:32 +02:00
$searchpicto = $form -> showFilterButtons ();
2017-12-08 17:15:24 +01:00
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
2017-06-16 11:51:33 +02:00
2017-11-30 10:45:55 +01:00
print '<tr class="liste_titre">' ;
2019-01-27 11:55:16 +01:00
print getTitleFieldOfList ( $langs -> trans ( '#' ), 0 , $_SERVER [ " PHP_SELF " ], 'rowid' , '' , $param , '' , $sortfield , $sortorder , 'minwidth50 ' ) . " \n " ;
print getTitleFieldOfList ( $langs -> trans ( 'Date' ), 0 , $_SERVER [ " PHP_SELF " ], 'date_creation' , '' , $param , '' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( $langs -> trans ( 'Author' ), 0 , $_SERVER [ " PHP_SELF " ], 'user_fullname' , '' , $param , '' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( $langs -> trans ( 'Action' ), 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( $langs -> trans ( 'Ref' ), 0 , $_SERVER [ " PHP_SELF " ], 'ref_object' , '' , $param , '' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( '' , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , '' ) . " \n " ;
2019-02-01 18:31:44 +01:00
print getTitleFieldOfList ( $langs -> trans ( 'Amount' ), 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , 'class="right"' , $sortfield , $sortorder , '' ) . " \n " ;
2019-01-27 11:55:16 +01:00
print getTitleFieldOfList ( $langs -> trans ( 'DataOfArchivedEvent' ), 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , 'align="center"' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( $langs -> trans ( 'Fingerprint' ), 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( $langs -> trans ( 'Status' ), 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , 'align="center"' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( '' , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , 'align="center"' , $sortfield , $sortorder , '' ) . " \n " ;
print getTitleFieldOfList ( '<span id="blockchainstatus"></span>' , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , $param , 'align="center"' , $sortfield , $sortorder , '' ) . " \n " ;
2017-06-10 09:25:32 +02:00
print '</tr>' ;
2020-04-10 10:59:32 +02:00
if ( ! empty ( $conf -> global -> BLOCKEDLOG_SCAN_ALL_FOR_LOWERIDINERROR )) {
2018-01-12 20:24:09 +01:00
// This is version that is faster but require more memory and report errors that are outside the filter range
2018-01-05 13:40:56 +01:00
// TODO Make a full scan of table in reverse order of id of $block, so we can use the parameter $previoushash into checkSignature to save requests
// to find the $loweridinerror.
2020-05-21 15:05:19 +02:00
} else {
2018-01-12 20:24:09 +01:00
// This is version that optimize the memory (but will not report errors that are outside the filter range)
2020-04-10 10:59:32 +02:00
$loweridinerror = 0 ;
$checkresult = array ();
2021-02-04 22:03:58 +01:00
$checkdetail = array ();
2021-03-01 00:19:52 +01:00
if ( is_array ( $blocks )) {
foreach ( $blocks as & $block ) {
2021-02-04 22:03:58 +01:00
$tmpcheckresult = $block -> checkSignature ( '' , 1 ); // Note: this make a sql request at each call, we can't avoid this as the sorting order is various
$checksignature = $tmpcheckresult [ 'checkresult' ];
2020-04-10 10:59:32 +02:00
$checkresult [ $block -> id ] = $checksignature ; // false if error
2021-02-04 22:03:58 +01:00
$checkdetail [ $block -> id ] = $tmpcheckresult ;
2021-03-01 00:19:52 +01:00
if ( ! $checksignature ) {
if ( empty ( $loweridinerror )) {
$loweridinerror = $block -> id ;
} else {
$loweridinerror = min ( $loweridinerror , $block -> id );
}
2018-01-12 20:24:09 +01:00
}
2018-01-05 13:40:56 +01:00
}
}
}
2017-11-30 15:13:23 +01:00
2021-03-01 00:19:52 +01:00
if ( is_array ( $blocks )) {
2021-02-04 22:20:57 +01:00
$nbshown = 0 ;
2021-02-05 00:04:44 +01:00
$MAXFORSHOWLINK = 100 ;
$object_link = '' ;
2021-02-04 22:20:57 +01:00
2021-03-01 00:19:52 +01:00
foreach ( $blocks as & $block ) {
2018-01-25 12:57:36 +01:00
//if (empty($search_showonlyerrors) || ! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror))
2021-03-01 00:19:52 +01:00
if ( empty ( $search_showonlyerrors ) || ! $checkresult [ $block -> id ]) {
2021-02-04 22:20:57 +01:00
$nbshown ++ ;
2021-02-05 00:04:44 +01:00
if ( $nbshown < $MAXFORSHOWLINK ) { // For performance and memory purpose, we get/show the link of objects only for the 100 first output
$object_link = $block -> getObjectLink ();
} else {
$object_link = $block -> element . '/' . $block -> fk_object ;
}
2021-03-01 00:19:52 +01:00
print '<tr class="oddeven">' ;
2018-01-29 18:22:26 +01:00
2021-03-01 00:19:52 +01:00
// ID
print '<td>' . $block -> id . '</td>' ;
2018-01-29 18:22:26 +01:00
2021-03-01 00:19:52 +01:00
// Date
print '<td>' . dol_print_date ( $block -> date_creation , 'dayhour' ) . '</td>' ;
2018-01-29 18:22:26 +01:00
2018-01-12 20:24:09 +01:00
// User
2021-03-01 00:19:52 +01:00
print '<td>' ;
//print $block->getUser()
print $block -> user_fullname ;
print '</td>' ;
// Action
print '<td>' . $langs -> trans ( 'log' . $block -> action ) . '</td>' ;
// Ref
print '<td class="nowraponall">' ;
print $block -> ref_object ;
print '</td>' ;
// Link to source object
print '<td' . ( preg_match ( '/<a/' , $object_link ) ? ' class="nowrap"' : '' ) . '><!-- object_link -->' . $object_link . '</td>' ;
// Amount
print '<td class="right nowraponall">' . price ( $block -> amounts ) . '</td>' ;
// Details link
print '<td align="center"><a href="#" data-blockid="' . $block -> id . '" rel="show-info">' . img_info ( $langs -> trans ( 'ShowDetails' )) . '</a></td>' ;
// Fingerprint
print '<td class="nowrap">' ;
$texttoshow = $langs -> trans ( " Fingerprint " ) . ' - ' . $langs -> trans ( " Saved " ) . ':<br>' . $block -> signature ;
$texttoshow .= '<br><br>' . $langs -> trans ( " Fingerprint " ) . ' - Recalculated sha256(previoushash * data):<br>' . $checkdetail [ $block -> id ][ 'calculatedsignature' ];
$texttoshow .= '<br><span class="opacitymedium">' . $langs -> trans ( " PreviousHash " ) . '=' . $checkdetail [ $block -> id ][ 'previoushash' ] . '</span>' ;
//$texttoshow .= '<br>keyforsignature='.$checkdetail[$block->id]['keyforsignature'];
print $form -> textwithpicto ( dol_trunc ( $block -> signature , '8' ), $texttoshow , 1 , 'help' , '' , 0 , 2 , 'fingerprint' . $block -> id );
print '</td>' ;
// Status
print '<td class="center">' ;
if ( ! $checkresult [ $block -> id ] || ( $loweridinerror && $block -> id >= $loweridinerror )) { // If error
if ( $checkresult [ $block -> id ]) {
print '<span class="badge badge-status4 badge-status" title="' . $langs -> trans ( 'OkCheckFingerprintValidityButChainIsKo' ) . '">OK</span>' ;
} else {
print '<span class="badge badge-status8 badge-status" title="' . $langs -> trans ( 'KoCheckFingerprintValidity' ) . '">KO</span>' ;
}
} else {
print '<span class="badge badge-status4 badge-status" title="' . $langs -> trans ( 'OkCheckFingerprintValidity' ) . '">OK</span>' ;
}
print '</td>' ;
// Note
print '<td class="center">' ;
if ( ! $checkresult [ $block -> id ] || ( $loweridinerror && $block -> id >= $loweridinerror )) { // If error
if ( $checkresult [ $block -> id ]) {
print $form -> textwithpicto ( '' , $langs -> trans ( 'OkCheckFingerprintValidityButChainIsKo' ));
}
}
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>' ;
2018-01-12 20:24:09 +01:00
print '<td></td>' ;
print '</tr>' ;
}
2017-06-13 10:04:05 +02:00
}
2021-02-04 22:03:58 +01:00
2021-02-04 22:20:57 +01:00
if ( $nbshown == 0 ) {
2021-02-04 22:03:58 +01:00
print '<tr><td colspan="12"><span class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</span></td></tr>' ;
}
2017-06-10 09:25:32 +02:00
}
print '</table>' ;
2017-12-08 17:15:24 +01:00
2017-11-30 10:45:55 +01:00
print '</div>' ;
2017-06-10 09:25:32 +02:00
2018-01-25 12:57:36 +01:00
print '</form>' ;
2018-01-05 04:31:48 +01:00
2018-01-25 12:57:36 +01:00
// Javascript to manage the showinfo popup
2017-11-30 10:45:55 +01:00
print ' < script type = " text/javascript " >
2017-06-16 11:51:33 +02:00
2017-11-30 10:45:55 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( " #dialogforpopup " ) . dialog (
{ closeOnEscape : true , classes : { " ui-dialog " : " highlight " },
maxHeight : window . innerHeight - 60 , height : window . innerHeight - 60 , width : '.($conf->browser->layout == ' phone ' ? 400 : 700).' ,
modal : true ,
autoOpen : false }) . css ( " z-index: 5000 " );
2017-06-16 11:51:33 +02:00
2017-11-30 10:45:55 +01:00
$ ( " a[rel=show-info] " ) . click ( function () {
2017-06-12 10:26:24 +02:00
2018-01-25 12:57:36 +01:00
console . log ( " We click on tooltip, we open popup and get content using an ajax call " );
2017-06-16 11:51:33 +02:00
2017-11-30 10:45:55 +01:00
var fk_block = $ ( this ) . attr ( " data-blockid " );
2017-06-12 10:26:24 +02:00
2017-11-30 10:45:55 +01:00
$ . ajax ({
2021-06-17 03:37:52 +02:00
method : " GET " ,
data : { token : \ '' . currentToken () . ' \ ' },
url : " '.DOL_URL_ROOT.'/blockedlog/ajax/block-info.php?id= " + fk_block ,
dataType : " html "
2017-11-30 10:45:55 +01:00
}) . done ( function ( data ) {
2018-01-25 12:57:36 +01:00
jQuery ( " #dialogforpopup " ) . html ( data );
2017-11-30 10:45:55 +01:00
});
2017-06-16 11:51:33 +02:00
2017-11-30 10:45:55 +01:00
jQuery ( " #dialogforpopup " ) . dialog ( " open " );
2017-06-12 10:26:24 +02:00
});
2017-11-30 10:45:55 +01:00
})
</ script > ' . " \n " ;
2017-06-12 10:26:24 +02:00
2021-03-01 00:19:52 +01:00
if ( ! empty ( $conf -> global -> BLOCKEDLOG_USE_REMOTE_AUTHORITY ) && ! empty ( $conf -> global -> BLOCKEDLOG_AUTHORITY_URL )) {
2020-10-31 14:32:18 +01:00
?>
2018-01-05 04:31:48 +01:00
< script type = " text/javascript " >
2017-06-16 11:51:33 +02:00
2018-01-05 04:31:48 +01:00
$ . ajax ({
2021-06-17 03:37:52 +02:00
method : " GET " ,
data : { token : '<?php echo currentToken() ?>' },
url : '<?php echo DOL_URL_ROOT.' / blockedlog / ajax / check_signature . php ' ?>' ,
dataType : 'html'
2018-01-05 04:31:48 +01:00
}) . done ( function ( data ) {
if ( data == 'hashisok' ) {
2020-04-10 10:59:32 +02:00
$ ( '#blockchainstatus' ) . html ( '<?php echo $langs->trans(' AuthorityReconizeFingerprintConformity ').' '.img_picto($langs->trans(' SignatureOK '), ' on ') ?>' );
2018-01-05 04:31:48 +01:00
}
else {
2020-04-10 10:59:32 +02:00
$ ( '#blockchainstatus' ) . html ( '<?php echo $langs->trans(' AuthorityDidntReconizeFingerprintConformity ').' '.img_picto($langs->trans(' SignatureKO '), ' off ') ?>' );
2018-01-05 04:31:48 +01:00
}
2017-06-16 11:51:33 +02:00
2018-01-05 04:31:48 +01:00
});
2017-06-16 11:51:33 +02:00
2018-01-05 04:31:48 +01:00
</ script >
2021-03-01 00:19:52 +01:00
< ? php
2017-06-12 10:26:24 +02:00
}
2021-03-01 00:19:52 +01:00
if ( GETPOST ( 'withtab' , 'alpha' )) {
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-12-16 21:36:36 +01:00
}
2017-06-10 09:25:32 +02:00
print '<br><br>' ;
2018-07-29 11:33:52 +02:00
// End of page
2017-06-10 09:25:32 +02:00
llxFooter ();
2019-01-27 23:23:38 +01:00
$db -> close ();