26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/authority.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 $langs->loadLangs(array(
"admin",
"other",
"blockedlog",
"bills"));
36 if ((!$user->admin && !$user->rights->blockedlog->read) || empty($conf->blockedlog->enabled))
accessforbidden();
38 $action =
GETPOST(
'action',
'aZ09');
39 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'blockedloglist';
40 $backtopage =
GETPOST(
'backtopage',
'alpha');
41 $optioncss =
GETPOST(
'optioncss',
'aZ');
43 $search_showonlyerrors =
GETPOST(
'search_showonlyerrors',
'int');
44 if ($search_showonlyerrors < 0) $search_showonlyerrors = 0;
46 $search_fk_user =
GETPOST(
'search_fk_user',
'intcomma');
51 $search_code =
GETPOST(
'search_code',
'alpha');
52 $search_ref =
GETPOST(
'search_ref',
'alpha');
53 $search_amount =
GETPOST(
'search_amount',
'alpha');
58 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
59 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
60 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
62 if (empty($page) || $page == -1) { $page = 0; }
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
67 if (empty($sortfield)) $sortfield =
'rowid';
68 if (empty($sortorder)) $sortorder =
'DESC';
81 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha'))
89 $search_showonlyerrors = 0;
91 $search_array_options = array();
94 if ($action ===
'downloadblockchain') {
97 $bc = $auth->getLocalBlockChain();
99 header(
'Content-Type: application/octet-stream');
100 header(
"Content-Transfer-Encoding: Binary");
101 header(
"Content-disposition: attachment; filename=\"".$auth->signature.
".certif\"");
106 } elseif (
GETPOST(
'downloadcsv',
'alpha')) {
115 $sql =
"SELECT rowid,date_creation,tms,user_fullname,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user,object_data";
116 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
117 $sql .=
" WHERE entity = ".$conf->entity;
118 if (
GETPOST(
'monthtoexport',
'int') > 0 ||
GETPOST(
'yeartoexport',
'int') > 0)
122 $sql .=
" AND date_creation BETWEEN '".$db->idate($dates).
"' AND '".$db->idate($datee).
"'";
124 $sql .=
" ORDER BY rowid ASC";
125 $sql .= $db->plimit(1);
127 $res = $db->query($sql);
131 $obj = $db->fetch_object($res);
134 $previoushash = $block_static->getPreviousHash(0, $obj->rowid);
135 $firstid = $obj->rowid;
137 $previoushash =
'nodata';
149 $sql =
"SELECT rowid,date_creation,tms,user_fullname,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user,object_data";
150 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
151 $sql .=
" WHERE entity = ".$conf->entity;
152 if (
GETPOST(
'monthtoexport',
'int') > 0 ||
GETPOST(
'yeartoexport',
'int') > 0)
156 $sql .=
" AND date_creation BETWEEN '".$db->idate($dates).
"' AND '".$db->idate($datee).
"'";
158 $sql .=
" ORDER BY rowid ASC";
160 $res = $db->query($sql);
163 header(
'Content-Type: application/octet-stream');
164 header(
"Content-Transfer-Encoding: Binary");
165 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\"");
167 print $langs->transnoentities(
'Id')
168 .
';'.$langs->transnoentities(
'Date')
169 .
';'.$langs->transnoentities(
'User')
170 .
';'.$langs->transnoentities(
'Action')
171 .
';'.$langs->transnoentities(
'Element')
172 .
';'.$langs->transnoentities(
'Amounts')
173 .
';'.$langs->transnoentities(
'ObjectId')
174 .
';'.$langs->transnoentities(
'Date')
175 .
';'.$langs->transnoentities(
'Ref')
176 .
';'.$langs->transnoentities(
'Fingerprint')
177 .
';'.$langs->transnoentities(
'Status')
178 .
';'.$langs->transnoentities(
'Note')
179 .
';'.$langs->transnoentities(
'FullData')
185 while ($obj = $db->fetch_object($res))
189 $block_static->id = $obj->rowid;
190 $block_static->date_creation = $db->jdate($obj->date_creation);
191 $block_static->date_modification = $db->jdate($obj->tms);
192 $block_static->action = $obj->action;
193 $block_static->fk_object = $obj->fk_object;
194 $block_static->element = $obj->element;
195 $block_static->amounts = (double) $obj->amounts;
196 $block_static->ref_object = $obj->ref_object;
197 $block_static->date_object = $db->jdate($obj->date_object);
198 $block_static->user_fullname = $obj->user_fullname;
199 $block_static->fk_user = $obj->fk_user;
200 $block_static->signature = $obj->signature;
201 $block_static->object_data = $block_static->dolDecodeBlockedData($obj->object_data);
203 $checksignature = $block_static->checkSignature($previoushash);
207 $statusofrecord =
'Valid';
208 if ($loweridinerror > 0) $statusofrecordnote =
'ValidButFoundAPreviousKO';
209 else $statusofrecordnote =
'';
211 $statusofrecord =
'KO';
212 $statusofrecordnote =
'LineCorruptedOrNotMatchingPreviousOne';
213 $loweridinerror = $obj->rowid;
218 $statusofrecordnote = $langs->trans(
"PreviousFingerprint").
': '.$previoushash.($statusofrecordnote ?
' - '.$statusofrecordnote :
'');
221 print ';'.$obj->date_creation;
222 print ';"'.str_replace(
'"',
'""', $obj->user_fullname).
'"';
223 print ';'.$obj->action;
224 print ';'.$obj->element;
225 print ';'.$obj->amounts;
226 print ';'.$obj->fk_object;
227 print ';'.$obj->date_object;
228 print ';"'.str_replace(
'"',
'""', $obj->ref_object).
'"';
229 print ';'.$obj->signature;
230 print ';'.$statusofrecord;
231 print ';'.$statusofrecordnote;
232 print ';"'.str_replace(
'"',
'""', $obj->object_data).
'"';
236 $previoushash = $obj->signature;
253 $form =
new Form($db);
255 if (
GETPOST(
'withtab',
'alpha'))
257 $title = $langs->trans(
"ModuleSetup").
' '.$langs->trans(
'BlockedLog');
259 $title = $langs->trans(
"BrowseBlockedLog");
262 llxHeader(
'', $langs->trans(
"BrowseBlockedLog"));
266 $blocks = $block_static->getLog(
'all', 0, $MAXLINES, $sortfield, $sortorder, $search_fk_user, $search_start, $search_end, $search_ref, $search_amount, $search_code);
267 if (!is_array($blocks))
271 setEventMessages($langs->trans(
"TooManyRecordToScanRestrictFilters", $MAXLINES), null,
'errors');
273 dol_print_error($block_static->db, $block_static->error, $block_static->errors);
279 if (
GETPOST(
'withtab',
'alpha'))
281 $linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
286 if (
GETPOST(
'withtab',
'alpha'))
292 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"FingerprintsDesc").
"<br></span>\n";
297 if (!empty($contextpage) && $contextpage !=
$_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
298 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
299 if ($search_fk_user > 0) $param .=
'&search_fk_user='.urlencode($search_fk_user);
300 if ($search_startyear > 0) $param .=
'&search_startyear='.urlencode(
GETPOST(
'search_startyear',
'int'));
301 if ($search_startmonth > 0) $param .=
'&search_startmonth='.urlencode(
GETPOST(
'search_startmonth',
'int'));
302 if ($search_startday > 0) $param .=
'&search_startday='.urlencode(
GETPOST(
'search_startday',
'int'));
303 if ($search_endyear > 0) $param .=
'&search_endyear='.urlencode(
GETPOST(
'search_endyear',
'int'));
304 if ($search_endmonth > 0) $param .=
'&search_endmonth='.urlencode(
GETPOST(
'search_endmonth',
'int'));
305 if ($search_endday > 0) $param .=
'&search_endday='.urlencode(
GETPOST(
'search_endday',
'int'));
306 if ($search_showonlyerrors > 0) $param .=
'&search_showonlyerrors='.urlencode($search_showonlyerrors);
307 if ($optioncss !=
'') $param .=
'&optioncss='.urlencode($optioncss);
308 if (
GETPOST(
'withtab',
'alpha')) $param .=
'&withtab='.urlencode(
GETPOST(
'withtab',
'alpha'));
313 print '<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
314 print '<input type="hidden" name="token" value="'.newToken().
'">';
316 print '<div class="right">';
317 print $langs->trans(
"RestrictYearToExport").
': ';
318 $smonth =
GETPOST(
'monthtoexport',
'int');
321 $retstring .=
'<select class="flat valignmiddle maxwidth75imp marginrightonly" id="monthtoexport" name="monthtoexport">';
322 $retstring .=
'<option value="0" selected> </option>';
323 for ($month = 1; $month <= 12; $month++)
325 $retstring .=
'<option value="'.$month.
'"'.($month == $smonth ?
' selected' :
'').
'>';
326 $retstring .=
dol_print_date(mktime(12, 0, 0, $month, 1, 2000),
"%b");
327 $retstring .=
"</option>";
329 $retstring .=
"</select>";
331 print '<input type="text" name="yeartoexport" class="valignmiddle maxwidth50imp" value="'.GETPOST(
'yeartoexport',
'int').
'">';
332 print '<input type="hidden" name="withtab" value="'.GETPOST(
'withtab',
'alpha').
'">';
333 print '<input type="submit" name="downloadcsv" class="button" value="'.$langs->trans(
'DownloadLogCSV').
'">';
334 if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY))
print ' | <a href="?action=downloadblockchain'.(GETPOST(
'withtab',
'alpha') ?
'&withtab='.GETPOST(
'withtab',
'alpha') :
'').
'">'.$langs->trans(
'DownloadBlockChain').
'</a>';
339 print '<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
341 print '<div class="div-table-responsive">';
343 if ($optioncss !=
'')
print '<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
344 print '<input type="hidden" name="token" value="'.newToken().
'">';
345 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
346 print '<input type="hidden" name="action" value="list">';
347 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
348 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
349 print '<input type="hidden" name="page" value="'.$page.
'">';
350 print '<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
351 print '<input type="hidden" name="withtab" value="'.GETPOST(
'withtab',
'alpha').
'">';
353 print '<table class="noborder centpercent">';
356 print '<tr class="liste_titre_filter">';
358 print '<td class="liste_titre"> </td>';
360 print '<td class="liste_titre">';
362 print $form->selectDate($search_start,
'search_start');
365 print $form->selectDate($search_end,
'search_end');
369 print '<td class="liste_titre">';
370 print $form->select_dolusers($search_fk_user,
'search_fk_user', 1, null, 0,
'',
'', 0, 0, 0,
'', 0,
'',
'maxwidth200');
375 $langs->load(
"blockedlog");
376 print '<td class="liste_titre">';
377 print $form->selectarray(
'search_code', $block_static->trackedevents, $search_code, 1, 0, 0,
'', 1, 0, 0,
'ASC',
'maxwidth200', 1);
381 print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
384 print '<td class="liste_titre"></td>';
387 print '<td class="liste_titre right"><input type="text" class="maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
390 print '<td class="liste_titre"></td>';
393 print '<td class="liste_titre"></td>';
396 print '<td class="liste_titre">';
397 $array = array(
"1"=>$langs->trans(
"OnlyNonValid"));
398 print $form->selectarray(
'search_showonlyerrors', $array, $search_showonlyerrors, 1);
402 print '<td class="liste_titre"></td>';
405 print '<td class="liste_titre" align="middle">';
406 $searchpicto = $form->showFilterButtons();
412 print '<tr class="liste_titre">';
420 print getTitleFieldOfList($langs->trans(
'DataOfArchivedEvent'), 0,
$_SERVER[
"PHP_SELF"],
'',
'', $param,
'align="center"', $sortfield, $sortorder,
'').
"\n";
424 print getTitleFieldOfList(
'<span id="blockchainstatus"></span>', 0,
$_SERVER[
"PHP_SELF"],
'',
'', $param,
'align="center"', $sortfield, $sortorder,
'').
"\n";
427 if (!empty($conf->global->BLOCKEDLOG_SCAN_ALL_FOR_LOWERIDINERROR)) {
435 $checkresult = array();
436 if (is_array($blocks))
438 foreach ($blocks as &$block)
440 $checksignature = $block->checkSignature();
441 $checkresult[$block->id] = $checksignature;
442 if (!$checksignature)
444 if (empty($loweridinerror)) $loweridinerror = $block->id;
445 else $loweridinerror = min($loweridinerror, $block->id);
451 if (is_array($blocks))
453 foreach ($blocks as &$block)
455 $object_link = $block->getObjectLink();
458 if (empty($search_showonlyerrors) || !$checkresult[$block->id])
460 print '<tr class="oddeven">';
463 print '<td>'.$block->id.
'</td>';
466 print '<td>'.dol_print_date($block->date_creation,
'dayhour').
'</td>';
471 print $block->user_fullname;
475 print '<td>'.$langs->trans(
'log'.$block->action).
'</td>';
478 print '<td class="nowrap">'.$block->ref_object.
'</td>';
481 print '<td'.(preg_match(
'/<a/', $object_link) ?
' class="nowrap"' :
'').
'><!-- object_link -->'.$object_link.
'</td>';
484 print '<td class="right nowraponall">'.price($block->amounts).
'</td>';
487 print '<td align="center"><a href="#" data-blockid="'.$block->id.
'" rel="show-info">'.
img_info($langs->trans(
'ShowDetails')).
'</a></td>';
490 print '<td class="nowrap">';
491 print $form->textwithpicto(
dol_trunc($block->signature,
'8'), $block->signature, 1,
'help',
'', 0, 2,
'fingerprint'.$block->id);
495 print
'<td class="center">';
496 if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror))
498 if ($checkresult[$block->id]) print
img_picto($langs->trans(
'OkCheckFingerprintValidityButChainIsKo'),
'statut4');
499 else print
img_picto($langs->trans(
'KoCheckFingerprintValidity'),
'statut8');
501 print
img_picto($langs->trans(
'OkCheckFingerprintValidity'),
'statut4');
507 print
'<td class="center">';
508 if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror))
510 if ($checkresult[$block->id]) print $form->textwithpicto(
'', $langs->trans(
'OkCheckFingerprintValidityButChainIsKo'));
513 if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
514 print
' '.($block->certified ?
img_picto($langs->trans(
'AddedByAuthority'),
'info') :
img_picto($langs->trans(
'NotAddedByAuthorityYet'),
'info_black'));
532 print
'<script type="text/javascript">
534 jQuery(document).ready(function () {
535 jQuery("#dialogforpopup").dialog(
536 { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
537 maxHeight: window.innerHeight-60, height: window.innerHeight-60, width: '.($conf->browser->layout ==
'phone' ? 400 : 700).
',
539 autoOpen: false }).css("z-index: 5000");
541 $("a[rel=show-info]").click(function() {
543 console.log("We click on tooltip, we open popup and get content using an ajax call");
545 var fk_block = $(this).attr("data-blockid");
548 url:"../ajax/block-info.php?id="+fk_block
550 }).done(function(data) {
551 jQuery("#dialogforpopup").html(data);
554 jQuery("#dialogforpopup").dialog("open");
560 if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL))
563 <script
type=
"text/javascript">
566 url :
"<?php echo dol_buildpath('/blockedlog/ajax/check_signature.php', 1) ?>"
568 }).done(
function(data) {
570 if(data ==
'hashisok') {
571 $(
'#blockchainstatus').html(
'<?php echo $langs->trans('AuthorityReconizeFingerprintConformity
').' '.img_picto($langs->trans('SignatureOK
'), 'on
') ?>');
574 $(
'#blockchainstatus').html(
'<?php echo $langs->trans('AuthorityDidntReconizeFingerprintConformity
').' '.img_picto($langs->trans('SignatureKO
'), 'off
') ?>');
583 if (
GETPOST(
'withtab',
'alpha'))
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
Class to manage certif authority.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
blockedlogadmin_prepare_head()
Define head array for tabs of blockedlog tools setup pages.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Class to manage Blocked Log.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_info($titlealt= 'default')
Show info logo.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type