dolibarr  16.0.5
blockedlog_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
3  * Copyright (C) 2017-2018 Laurent Destailleur <eldy@destailleur.fr>
4  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
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';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("admin", "other", "blockedlog", "bills"));
35 
36 if ((!$user->admin && empty($user->rights->blockedlog->read)) || empty($conf->blockedlog->enabled)) {
38 }
39 
40 $action = GETPOST('action', 'aZ09');
41 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'blockedloglist'; // To manage different context of search
42 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
43 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
44 
45 $search_showonlyerrors = GETPOST('search_showonlyerrors', 'int');
46 if ($search_showonlyerrors < 0) {
47  $search_showonlyerrors = 0;
48 }
49 
50 $search_startyear = GETPOST('search_startyear', 'int');
51 $search_startmonth = GETPOST('search_startmonth', 'int');
52 $search_startday = GETPOST('search_startday', 'int');
53 $search_endyear = GETPOST('search_endyear', 'int');
54 $search_endmonth = GETPOST('search_endmonth', 'int');
55 $search_endday = GETPOST('search_endday', 'int');
56 $search_id = GETPOST('search_id', 'alpha');
57 $search_fk_user = GETPOST('search_fk_user', 'intcomma');
58 $search_start = -1;
59 if ($search_startyear != '') {
60  $search_start = dol_mktime(0, 0, 0, $search_startmonth, $search_startday, $search_startyear);
61 }
62 $search_end = -1;
63 if (GETPOST('search_endyear') != '') {
64  $search_end = dol_mktime(23, 59, 59, GETPOST('search_endmonth'), GETPOST('search_endday'), GETPOST('search_endyear'));
65 }
66 $search_code = GETPOST('search_code', 'alpha');
67 $search_ref = GETPOST('search_ref', 'alpha');
68 $search_amount = GETPOST('search_amount', 'alpha');
69 
70 if (($search_start == -1 || empty($search_start)) && !GETPOSTISSET('search_startmonth')) {
71  $search_start = dol_time_plus_duree(dol_now(), '-1', 'w');
72 }
73 
74 // Load variable for pagination
75 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
76 $sortfield = GETPOST('sortfield', 'aZ09comma');
77 $sortorder = GETPOST('sortorder', 'aZ09comma');
78 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
79 if (empty($page) || $page == -1) {
80  $page = 0;
81 } // If $page is not defined, or '' or -1
82 $offset = $limit * $page;
83 $pageprev = $page - 1;
84 $pagenext = $page + 1;
85 
86 if (empty($sortfield)) {
87  $sortfield = 'rowid';
88 }
89 if (empty($sortorder)) {
90  $sortorder = 'DESC';
91 }
92 
93 $block_static = new BlockedLog($db);
94 $block_static->loadTrackedEvents();
95 
96 $result = restrictedArea($user, 'blockedlog', 0, '');
97 
98 
99 $max_execution_time_for_importexport = (empty($conf->global->EXPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->EXPORT_MAX_EXECUTION_TIME); // 5mn if not defined
100 $max_time = @ini_get("max_execution_time");
101 if ($max_time && $max_time < $max_execution_time_for_importexport) {
102  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.");
103  @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
104 }
105 
106 
107 /*
108  * Actions
109  */
110 
111 // Purge search criteria
112 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
113  $search_id = '';
114  $search_fk_user = '';
115  $search_start = -1;
116  $search_end = -1;
117  $search_code = '';
118  $search_ref = '';
119  $search_amount = '';
120  $search_showonlyerrors = 0;
121  $toselect = array();
122  $search_array_options = array();
123 }
124 
125 if ($action === 'downloadblockchain') {
126  $auth = new BlockedLogAuthority($db);
127 
128  $bc = $auth->getLocalBlockChain();
129 
130  header('Content-Type: application/octet-stream');
131  header("Content-Transfer-Encoding: Binary");
132  header("Content-disposition: attachment; filename=\"".$auth->signature.".certif\"");
133 
134  echo $bc;
135 
136  exit;
137 } elseif (GETPOST('downloadcsv', 'alpha')) {
138  $error = 0;
139 
140  $previoushash = '';
141  $firstid = '';
142 
143  if (!$error) {
144  // Get ID of first line
145  $sql = "SELECT rowid,date_creation,tms,user_fullname,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user,object_data";
146  $sql .= " FROM ".MAIN_DB_PREFIX."blockedlog";
147  $sql .= " WHERE entity = ".$conf->entity;
148  if (GETPOST('monthtoexport', 'int') > 0 || GETPOST('yeartoexport', 'int') > 0) {
149  $dates = dol_get_first_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 1);
150  $datee = dol_get_last_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 12);
151  $sql .= " AND date_creation BETWEEN '".$db->idate($dates)."' AND '".$db->idate($datee)."'";
152  }
153  $sql .= " ORDER BY rowid ASC"; // Required so we get the first one
154  $sql .= $db->plimit(1);
155 
156  $res = $db->query($sql);
157  if ($res) {
158  // Make the first fetch to get first line
159  $obj = $db->fetch_object($res);
160  if ($obj) {
161  $previoushash = $block_static->getPreviousHash(0, $obj->rowid);
162  $firstid = $obj->rowid;
163  } else { // If not data found for filter, we do not need previoushash neither firstid
164  $previoushash = 'nodata';
165  $firstid = '';
166  }
167  } else {
168  $error++;
169  setEventMessages($db->lasterror, null, 'errors');
170  }
171  }
172 
173  if (!$error) {
174  // Now restart request with all data = no limit(1) in sql request
175  $sql = "SELECT rowid,date_creation,tms,user_fullname,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user,object_data";
176  $sql .= " FROM ".MAIN_DB_PREFIX."blockedlog";
177  $sql .= " WHERE entity = ".$conf->entity;
178  if (GETPOST('monthtoexport', 'int') > 0 || GETPOST('yeartoexport', 'int') > 0) {
179  $dates = dol_get_first_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 1);
180  $datee = dol_get_last_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 12);
181  $sql .= " AND date_creation BETWEEN '".$db->idate($dates)."' AND '".$db->idate($datee)."'";
182  }
183  $sql .= " ORDER BY rowid ASC"; // Required so later we can use the parameter $previoushash of checkSignature()
184 
185  $res = $db->query($sql);
186  if ($res) {
187  header('Content-Type: application/octet-stream');
188  header("Content-Transfer-Encoding: Binary");
189  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\"");
190 
191  print $langs->transnoentities('Id')
192  .';'.$langs->transnoentities('Date')
193  .';'.$langs->transnoentities('User')
194  .';'.$langs->transnoentities('Action')
195  .';'.$langs->transnoentities('Element')
196  .';'.$langs->transnoentities('Amounts')
197  .';'.$langs->transnoentities('ObjectId')
198  .';'.$langs->transnoentities('Date')
199  .';'.$langs->transnoentities('Ref')
200  .';'.$langs->transnoentities('Fingerprint')
201  .';'.$langs->transnoentities('Status')
202  .';'.$langs->transnoentities('Note')
203  .';'.$langs->transnoentities('FullData')
204  ."\n";
205 
206  $loweridinerror = 0;
207  $i = 0;
208 
209  while ($obj = $db->fetch_object($res)) {
210  // We set here all data used into signature calculation (see checkSignature method) and more
211  // IMPORTANT: We must have here, the same rule for transformation of data than into the fetch method (db->jdate for date, ...)
212  $block_static->id = $obj->rowid;
213  $block_static->date_creation = $db->jdate($obj->date_creation);
214  $block_static->date_modification = $db->jdate($obj->tms);
215  $block_static->action = $obj->action;
216  $block_static->fk_object = $obj->fk_object;
217  $block_static->element = $obj->element;
218  $block_static->amounts = (double) $obj->amounts;
219  $block_static->ref_object = $obj->ref_object;
220  $block_static->date_object = $db->jdate($obj->date_object);
221  $block_static->user_fullname = $obj->user_fullname;
222  $block_static->fk_user = $obj->fk_user;
223  $block_static->signature = $obj->signature;
224  $block_static->object_data = $block_static->dolDecodeBlockedData($obj->object_data);
225 
226  $checksignature = $block_static->checkSignature($previoushash); // If $previoushash is not defined, checkSignature will search it
227 
228  if ($checksignature) {
229  $statusofrecord = 'Valid';
230  if ($loweridinerror > 0) {
231  $statusofrecordnote = 'ValidButFoundAPreviousKO';
232  } else {
233  $statusofrecordnote = '';
234  }
235  } else {
236  $statusofrecord = 'KO';
237  $statusofrecordnote = 'LineCorruptedOrNotMatchingPreviousOne';
238  $loweridinerror = $obj->rowid;
239  }
240 
241  if ($i == 0) {
242  $statusofrecordnote = $langs->trans("PreviousFingerprint").': '.$previoushash.($statusofrecordnote ? ' - '.$statusofrecordnote : '');
243  }
244  print $obj->rowid;
245  print ';'.$obj->date_creation;
246  print ';"'.str_replace('"', '""', $obj->user_fullname).'"';
247  print ';'.$obj->action;
248  print ';'.$obj->element;
249  print ';'.$obj->amounts;
250  print ';'.$obj->fk_object;
251  print ';'.$obj->date_object;
252  print ';"'.str_replace('"', '""', $obj->ref_object).'"';
253  print ';'.$obj->signature;
254  print ';'.$statusofrecord;
255  print ';'.$statusofrecordnote;
256  print ';"'.str_replace('"', '""', $obj->object_data).'"';
257  print "\n";
258 
259  // Set new previous hash for next fetch
260  $previoushash = $obj->signature;
261 
262  $i++;
263  }
264 
265  exit;
266  } else {
267  setEventMessages($db->lasterror, null, 'errors');
268  }
269  }
270 }
271 
272 
273 /*
274  * View
275  */
276 
277 $form = new Form($db);
278 
279 if (GETPOST('withtab', 'alpha')) {
280  $title = $langs->trans("ModuleSetup").' '.$langs->trans('BlockedLog');
281 } else {
282  $title = $langs->trans("BrowseBlockedLog");
283 }
284 $help_url="EN:Module_Unalterable_Archives_-_Logs|FR:Module_Archives_-_Logs_Inaltérable";
285 
286 llxHeader('', $title, $help_url);
287 
288 $MAXLINES = 10000;
289 
290 $blocks = $block_static->getLog('all', $search_id, $MAXLINES, $sortfield, $sortorder, $search_fk_user, $search_start, $search_end, $search_ref, $search_amount, $search_code);
291 if (!is_array($blocks)) {
292  if ($blocks == -2) {
293  setEventMessages($langs->trans("TooManyRecordToScanRestrictFilters", $MAXLINES), null, 'errors');
294  } else {
295  dol_print_error($block_static->db, $block_static->error, $block_static->errors);
296  exit;
297  }
298 }
299 
300 $linkback = '';
301 if (GETPOST('withtab', 'alpha')) {
302  $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php').'">'.$langs->trans("BackToModuleList").'</a>';
303 }
304 
305 print load_fiche_titre($title, $linkback);
306 
307 if (GETPOST('withtab', 'alpha')) {
309  print dol_get_fiche_head($head, 'fingerprints', '', -1);
310 }
311 
312 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("FingerprintsDesc")."<br></span>\n";
313 
314 print '<br>';
315 
316 $param = '';
317 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
318  $param .= '&contextpage='.urlencode($contextpage);
319 }
320 if ($limit > 0 && $limit != $conf->liste_limit) {
321  $param .= '&limit='.urlencode($limit);
322 }
323 if ($search_id != '') {
324  $param .= '&search_id='.urlencode($search_id);
325 }
326 if ($search_fk_user > 0) {
327  $param .= '&search_fk_user='.urlencode($search_fk_user);
328 }
329 if ($search_startyear > 0) {
330  $param .= '&search_startyear='.urlencode($search_startyear);
331 }
332 if ($search_startmonth > 0) {
333  $param .= '&search_startmonth='.urlencode($search_startmonth);
334 }
335 if ($search_startday > 0) {
336  $param .= '&search_startday='.urlencode($search_startday);
337 }
338 if ($search_endyear > 0) {
339  $param .= '&search_endyear='.urlencode($search_endyear);
340 }
341 if ($search_endmonth > 0) {
342  $param .= '&search_endmonth='.urlencode($search_endmonth);
343 }
344 if ($search_endday > 0) {
345  $param .= '&search_endday='.urlencode($search_endday);
346 }
347 if ($search_showonlyerrors > 0) {
348  $param .= '&search_showonlyerrors='.urlencode($search_showonlyerrors);
349 }
350 if ($optioncss != '') {
351  $param .= '&optioncss='.urlencode($optioncss);
352 }
353 if (GETPOST('withtab', 'alpha')) {
354  $param .= '&withtab='.urlencode(GETPOST('withtab', 'alpha'));
355 }
356 
357 // Add $param from extra fields
358 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
359 
360 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
361 print '<input type="hidden" name="token" value="'.newToken().'">';
362 
363 print '<div class="right">';
364 print $langs->trans("RestrictYearToExport").': ';
365 $smonth = GETPOST('monthtoexport', 'int');
366 // Month
367 $retstring = '';
368 $retstring .= '<select class="flat valignmiddle maxwidth75imp marginrightonly" id="monthtoexport" name="monthtoexport">';
369 $retstring .= '<option value="0" selected>&nbsp;</option>';
370 for ($month = 1; $month <= 12; $month++) {
371  $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
372  $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
373  $retstring .= "</option>";
374 }
375 $retstring .= "</select>";
376 print $retstring;
377 print '<input type="text" name="yeartoexport" class="valignmiddle maxwidth50imp" value="'.GETPOST('yeartoexport', 'int').'">';
378 print '<input type="hidden" name="withtab" value="'.GETPOST('withtab', 'alpha').'">';
379 print '<input type="submit" name="downloadcsv" class="button" value="'.$langs->trans('DownloadLogCSV').'">';
380 if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) {
381  print ' | <a href="?action=downloadblockchain'.(GETPOST('withtab', 'alpha') ? '&withtab='.GETPOST('withtab', 'alpha') : '').'">'.$langs->trans('DownloadBlockChain').'</a>';
382 }
383 print ' </div><br>';
384 
385 print '</form>';
386 
387 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
388 
389 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
390 
391 if ($optioncss != '') {
392  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
393 }
394 print '<input type="hidden" name="token" value="'.newToken().'">';
395 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
396 print '<input type="hidden" name="action" value="list">';
397 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
398 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
399 print '<input type="hidden" name="page" value="'.$page.'">';
400 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
401 print '<input type="hidden" name="withtab" value="'.GETPOST('withtab', 'alpha').'">';
402 
403 print '<table class="noborder centpercent">';
404 
405 // Line of filters
406 print '<tr class="liste_titre_filter">';
407 
408 print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="'.dol_escape_htmltag($search_id).'"></td>';
409 
410 print '<td class="liste_titre">';
411 //print $langs->trans("from").': ';
412 print $form->selectDate($search_start, 'search_start');
413 //print '<br>';
414 //print $langs->trans("to").': ';
415 print $form->selectDate($search_end, 'search_end');
416 print '</td>';
417 
418 // User
419 print '<td class="liste_titre">';
420 print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
421 
422 print '</td>';
423 
424 // Actions code
425 $langs->load("blockedlog");
426 print '<td class="liste_titre">';
427 print $form->selectarray('search_code', $block_static->trackedevents, $search_code, 1, 0, 0, '', 1, 0, 0, 'ASC', 'maxwidth200', 1);
428 print '</td>';
429 
430 // Ref
431 print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
432 
433 // Link to ref
434 print '<td class="liste_titre"></td>';
435 
436 // Amount
437 print '<td class="liste_titre right"><input type="text" class="maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
438 
439 // Full data
440 print '<td class="liste_titre"></td>';
441 
442 // Fingerprint
443 print '<td class="liste_titre"></td>';
444 
445 // Status
446 print '<td class="liste_titre">';
447 $array = array("1"=>$langs->trans("OnlyNonValid"));
448 print $form->selectarray('search_showonlyerrors', $array, $search_showonlyerrors, 1);
449 print '</td>';
450 
451 // Status note
452 print '<td class="liste_titre"></td>';
453 
454 // Action column
455 print '<td class="liste_titre" align="middle">';
456 $searchpicto = $form->showFilterButtons();
457 print $searchpicto;
458 print '</td>';
459 
460 print '</tr>';
461 
462 print '<tr class="liste_titre">';
463 print getTitleFieldOfList($langs->trans('#'), 0, $_SERVER["PHP_SELF"], 'rowid', '', $param, '', $sortfield, $sortorder, 'minwidth50 ')."\n";
464 print getTitleFieldOfList($langs->trans('Date'), 0, $_SERVER["PHP_SELF"], 'date_creation', '', $param, '', $sortfield, $sortorder, '')."\n";
465 print getTitleFieldOfList($langs->trans('Author'), 0, $_SERVER["PHP_SELF"], 'user_fullname', '', $param, '', $sortfield, $sortorder, '')."\n";
466 print getTitleFieldOfList($langs->trans('Action'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
467 print getTitleFieldOfList($langs->trans('Ref'), 0, $_SERVER["PHP_SELF"], 'ref_object', '', $param, '', $sortfield, $sortorder, '')."\n";
468 print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
469 print getTitleFieldOfList($langs->trans('Amount'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder, '')."\n";
470 print getTitleFieldOfList($langs->trans('DataOfArchivedEvent'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
471 print getTitleFieldOfList($langs->trans('Fingerprint'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
472 print getTitleFieldOfList($langs->trans('Status'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
473 print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
474 print getTitleFieldOfList('<span id="blockchainstatus"></span>', 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
475 print '</tr>';
476 
477 if (!empty($conf->global->BLOCKEDLOG_SCAN_ALL_FOR_LOWERIDINERROR)) {
478  // This is version that is faster but require more memory and report errors that are outside the filter range
479 
480  // 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
481  // to find the $loweridinerror.
482 } else {
483  // This is version that optimize the memory (but will not report errors that are outside the filter range)
484  $loweridinerror = 0;
485  $checkresult = array();
486  $checkdetail = array();
487  if (is_array($blocks)) {
488  foreach ($blocks as &$block) {
489  $tmpcheckresult = $block->checkSignature('', 1); // Note: this make a sql request at each call, we can't avoid this as the sorting order is various
490 
491  $checksignature = $tmpcheckresult['checkresult'];
492 
493  $checkresult[$block->id] = $checksignature; // false if error
494  $checkdetail[$block->id] = $tmpcheckresult;
495 
496  if (!$checksignature) {
497  if (empty($loweridinerror)) {
498  $loweridinerror = $block->id;
499  } else {
500  $loweridinerror = min($loweridinerror, $block->id);
501  }
502  }
503  }
504  }
505 }
506 
507 if (is_array($blocks)) {
508  $nbshown = 0;
509  $MAXFORSHOWLINK = 100;
510  $object_link = '';
511 
512  foreach ($blocks as &$block) {
513  //if (empty($search_showonlyerrors) || ! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror))
514  if (empty($search_showonlyerrors) || !$checkresult[$block->id]) {
515  $nbshown++;
516 
517  if ($nbshown < $MAXFORSHOWLINK) { // For performance and memory purpose, we get/show the link of objects only for the 100 first output
518  $object_link = $block->getObjectLink();
519  } else {
520  $object_link = $block->element.'/'.$block->fk_object;
521  }
522 
523  print '<tr class="oddeven">';
524 
525  // ID
526  print '<td>'.$block->id.'</td>';
527 
528  // Date
529  print '<td>'.dol_print_date($block->date_creation, 'dayhour').'</td>';
530 
531  // User
532  print '<td>';
533  //print $block->getUser()
534  print $block->user_fullname;
535  print '</td>';
536 
537  // Action
538  print '<td>'.$langs->trans('log'.$block->action).'</td>';
539 
540  // Ref
541  print '<td class="nowraponall">';
542  print $block->ref_object;
543  print '</td>';
544 
545  // Link to source object
546  print '<td'.(preg_match('/<a/', $object_link) ? ' class="nowrap"' : '').'><!-- object_link -->'.$object_link.'</td>';
547 
548  // Amount
549  print '<td class="right nowraponall">'.price($block->amounts).'</td>';
550 
551  // Details link
552  print '<td align="center"><a href="#" data-blockid="'.$block->id.'" rel="show-info">'.img_info($langs->trans('ShowDetails')).'</a></td>';
553 
554  // Fingerprint
555  print '<td class="nowrap">';
556  $texttoshow = $langs->trans("Fingerprint").' - '.$langs->trans("Saved").':<br>'.$block->signature;
557  $texttoshow .= '<br><br>'.$langs->trans("Fingerprint").' - Recalculated sha256(previoushash * data):<br>'.$checkdetail[$block->id]['calculatedsignature'];
558  $texttoshow .= '<br><span class="opacitymedium">'.$langs->trans("PreviousHash").'='.$checkdetail[$block->id]['previoushash'].'</span>';
559  //$texttoshow .= '<br>keyforsignature='.$checkdetail[$block->id]['keyforsignature'];
560  print $form->textwithpicto(dol_trunc($block->signature, '8'), $texttoshow, 1, 'help', '', 0, 2, 'fingerprint'.$block->id);
561  print '</td>';
562 
563  // Status
564  print '<td class="center">';
565  if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error
566  if ($checkresult[$block->id]) {
567  print '<span class="badge badge-status4 badge-status" title="'.$langs->trans('OkCheckFingerprintValidityButChainIsKo').'">OK</span>';
568  } else {
569  print '<span class="badge badge-status8 badge-status" title="'.$langs->trans('KoCheckFingerprintValidity').'">KO</span>';
570  }
571  } else {
572  print '<span class="badge badge-status4 badge-status" title="'.$langs->trans('OkCheckFingerprintValidity').'">OK</span>';
573  }
574  print '</td>';
575 
576  // Note
577  print '<td class="center">';
578  if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error
579  if ($checkresult[$block->id]) {
580  print $form->textwithpicto('', $langs->trans('OkCheckFingerprintValidityButChainIsKo'));
581  }
582  }
583 
584  if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
585  print ' '.($block->certified ? img_picto($langs->trans('AddedByAuthority'), 'info') : img_picto($langs->trans('NotAddedByAuthorityYet'), 'info_black'));
586  }
587  print '</td>';
588 
589  print '<td></td>';
590 
591  print '</tr>';
592  }
593  }
594 
595  if ($nbshown == 0) {
596  print '<tr><td colspan="12"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
597  }
598 }
599 
600 print '</table>';
601 
602 print '</div>';
603 
604 print '</form>';
605 
606 // Javascript to manage the showinfo popup
607 print '<script type="text/javascript">
608 
609 jQuery(document).ready(function () {
610  jQuery("#dialogforpopup").dialog(
611  { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
612  maxHeight: window.innerHeight-60, height: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? 400 : 700).',
613  modal: true,
614  autoOpen: false }).css("z-index: 5000");
615 
616  $("a[rel=show-info]").click(function() {
617 
618  console.log("We click on tooltip, we open popup and get content using an ajax call");
619 
620  var fk_block = $(this).attr("data-blockid");
621 
622  $.ajax({
623  method: "GET",
624  data: { token: \''.currentToken().'\' },
625  url: "'.DOL_URL_ROOT.'/blockedlog/ajax/block-info.php?id="+fk_block,
626  dataType: "html"
627  }).done(function(data) {
628  jQuery("#dialogforpopup").html(data);
629  });
630 
631  jQuery("#dialogforpopup").dialog("open");
632  });
633 })
634 </script>'."\n";
635 
636 
637 if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
638  ?>
639  <script type="text/javascript">
640 
641  $.ajax({
642  method: "GET",
643  data: { token: '<?php echo currentToken() ?>' },
644  url: '<?php echo DOL_URL_ROOT.'/blockedlog/ajax/check_signature.php' ?>',
645  dataType: 'html'
646  }).done(function(data) {
647  if(data == 'hashisok') {
648  $('#blockchainstatus').html('<?php echo $langs->trans('AuthorityReconizeFingerprintConformity').' '.img_picto($langs->trans('SignatureOK'), 'on') ?>');
649  }
650  else{
651  $('#blockchainstatus').html('<?php echo $langs->trans('AuthorityDidntReconizeFingerprintConformity').' '.img_picto($langs->trans('SignatureKO'), 'off') ?>');
652  }
653 
654  });
655 
656  </script>
657  <?php
658 }
659 
660 if (GETPOST('withtab', 'alpha')) {
661  print dol_get_fiche_end();
662 }
663 
664 print '<br><br>';
665 
666 // End of page
667 llxFooter();
668 $db->close();
dol_trunc
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.
Definition: functions.lib.php:3805
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5049
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
img_info
img_info($titlealt='default')
Show info logo.
Definition: functions.lib.php:4502
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_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)
Definition: functions.lib.php:3880
blockedlogadmin_prepare_head
blockedlogadmin_prepare_head()
Define head array for tabs of blockedlog tools setup pages.
Definition: blockedlog.lib.php:29
BlockedLog
Class to manage Blocked Log.
Definition: blockedlog.class.php:26
BlockedLogAuthority
Class to manage certif authority.
Definition: authority.class.php:21
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:551
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:570
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mktime
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...
Definition: functions.lib.php:2757
currentToken
currentToken()
Return the value of token currently saved into session with name 'token'.
Definition: functions.lib.php:10889
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59