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