blockedlog_list.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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. /**
  20. * \file htdocs/blockedlog/admin/blockedlog_list.php
  21. * \ingroup blockedlog
  22. * \brief Page setup for blockedlog module
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/authority.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("admin", "other", "blockedlog", "bills"));
  32. if ((!$user->admin && empty($user->rights->blockedlog->read)) || empty($conf->blockedlog->enabled)) {
  33. accessforbidden();
  34. }
  35. $action = GETPOST('action', 'aZ09');
  36. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'blockedloglist'; // To manage different context of search
  37. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  38. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  39. $search_showonlyerrors = GETPOST('search_showonlyerrors', 'int');
  40. if ($search_showonlyerrors < 0) {
  41. $search_showonlyerrors = 0;
  42. }
  43. $search_startyear = GETPOST('search_startyear', 'int');
  44. $search_startmonth = GETPOST('search_startmonth', 'int');
  45. $search_startday = GETPOST('search_startday', 'int');
  46. $search_endyear = GETPOST('search_endyear', 'int');
  47. $search_endmonth = GETPOST('search_endmonth', 'int');
  48. $search_endday = GETPOST('search_endday', 'int');
  49. $search_id = GETPOST('search_id', 'alpha');
  50. $search_fk_user = GETPOST('search_fk_user', 'intcomma');
  51. $search_start = -1;
  52. if ($search_startyear != '') {
  53. $search_start = dol_mktime(0, 0, 0, $search_startmonth, $search_startday, $search_startyear);
  54. }
  55. $search_end = -1;
  56. if (GETPOST('search_endyear') != '') {
  57. $search_end = dol_mktime(23, 59, 59, GETPOST('search_endmonth'), GETPOST('search_endday'), GETPOST('search_endyear'));
  58. }
  59. $search_code = GETPOST('search_code', 'alpha');
  60. $search_ref = GETPOST('search_ref', 'alpha');
  61. $search_amount = GETPOST('search_amount', 'alpha');
  62. if (($search_start == -1 || empty($search_start)) && !GETPOSTISSET('search_startmonth')) {
  63. $search_start = dol_time_plus_duree(dol_now(), '-1', 'w');
  64. }
  65. // Load variable for pagination
  66. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  67. $sortfield = GETPOST('sortfield', 'aZ09comma');
  68. $sortorder = GETPOST('sortorder', 'aZ09comma');
  69. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  70. if (empty($page) || $page == -1) {
  71. $page = 0;
  72. } // If $page is not defined, or '' or -1
  73. $offset = $limit * $page;
  74. $pageprev = $page - 1;
  75. $pagenext = $page + 1;
  76. if (empty($sortfield)) {
  77. $sortfield = 'rowid';
  78. }
  79. if (empty($sortorder)) {
  80. $sortorder = 'DESC';
  81. }
  82. $block_static = new BlockedLog($db);
  83. $block_static->loadTrackedEvents();
  84. $result = restrictedArea($user, 'blockedlog', 0, '');
  85. $max_execution_time_for_importexport = (empty($conf->global->EXPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->EXPORT_MAX_EXECUTION_TIME); // 5mn if not defined
  86. $max_time = @ini_get("max_execution_time");
  87. if ($max_time && $max_time < $max_execution_time_for_importexport) {
  88. 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.");
  89. @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
  90. }
  91. /*
  92. * Actions
  93. */
  94. // Purge search criteria
  95. 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
  96. $search_id = '';
  97. $search_fk_user = '';
  98. $search_start = -1;
  99. $search_end = -1;
  100. $search_code = '';
  101. $search_ref = '';
  102. $search_amount = '';
  103. $search_showonlyerrors = 0;
  104. $toselect = array();
  105. $search_array_options = array();
  106. }
  107. if ($action === 'downloadblockchain') {
  108. $auth = new BlockedLogAuthority($db);
  109. $bc = $auth->getLocalBlockChain();
  110. header('Content-Type: application/octet-stream');
  111. header("Content-Transfer-Encoding: Binary");
  112. header("Content-disposition: attachment; filename=\"".$auth->signature.".certif\"");
  113. echo $bc;
  114. exit;
  115. } elseif (GETPOST('downloadcsv', 'alpha')) {
  116. $error = 0;
  117. $previoushash = '';
  118. $firstid = '';
  119. if (!$error) {
  120. // Get ID of first line
  121. $sql = "SELECT rowid,date_creation,tms,user_fullname,action,amounts,element,fk_object,date_object,ref_object,signature,fk_user,object_data";
  122. $sql .= " FROM ".MAIN_DB_PREFIX."blockedlog";
  123. $sql .= " WHERE entity = ".$conf->entity;
  124. if (GETPOST('monthtoexport', 'int') > 0 || GETPOST('yeartoexport', 'int') > 0) {
  125. $dates = dol_get_first_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 1);
  126. $datee = dol_get_last_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 12);
  127. $sql .= " AND date_creation BETWEEN '".$db->idate($dates)."' AND '".$db->idate($datee)."'";
  128. }
  129. $sql .= " ORDER BY rowid ASC"; // Required so we get the first one
  130. $sql .= $db->plimit(1);
  131. $res = $db->query($sql);
  132. if ($res) {
  133. // Make the first fetch to get first line
  134. $obj = $db->fetch_object($res);
  135. if ($obj) {
  136. $previoushash = $block_static->getPreviousHash(0, $obj->rowid);
  137. $firstid = $obj->rowid;
  138. } else { // If not data found for filter, we do not need previoushash neither firstid
  139. $previoushash = 'nodata';
  140. $firstid = '';
  141. }
  142. } else {
  143. $error++;
  144. setEventMessages($db->lasterror, null, 'errors');
  145. }
  146. }
  147. if (!$error) {
  148. // Now restart request with all data = no limit(1) in sql request
  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) {
  153. $dates = dol_get_first_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 1);
  154. $datee = dol_get_last_day(GETPOST('yeartoexport', 'int'), GETPOST('monthtoexport', 'int') ?GETPOST('monthtoexport', 'int') : 12);
  155. $sql .= " AND date_creation BETWEEN '".$db->idate($dates)."' AND '".$db->idate($datee)."'";
  156. }
  157. $sql .= " ORDER BY rowid ASC"; // Required so later we can use the parameter $previoushash of checkSignature()
  158. $res = $db->query($sql);
  159. if ($res) {
  160. header('Content-Type: application/octet-stream');
  161. header("Content-Transfer-Encoding: Binary");
  162. 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\"");
  163. print $langs->transnoentities('Id')
  164. .';'.$langs->transnoentities('Date')
  165. .';'.$langs->transnoentities('User')
  166. .';'.$langs->transnoentities('Action')
  167. .';'.$langs->transnoentities('Element')
  168. .';'.$langs->transnoentities('Amounts')
  169. .';'.$langs->transnoentities('ObjectId')
  170. .';'.$langs->transnoentities('Date')
  171. .';'.$langs->transnoentities('Ref')
  172. .';'.$langs->transnoentities('Fingerprint')
  173. .';'.$langs->transnoentities('Status')
  174. .';'.$langs->transnoentities('Note')
  175. .';'.$langs->transnoentities('FullData')
  176. ."\n";
  177. $loweridinerror = 0;
  178. $i = 0;
  179. while ($obj = $db->fetch_object($res)) {
  180. // We set here all data used into signature calculation (see checkSignature method) and more
  181. // IMPORTANT: We must have here, the same rule for transformation of data than into the fetch method (db->jdate for date, ...)
  182. $block_static->id = $obj->rowid;
  183. $block_static->date_creation = $db->jdate($obj->date_creation);
  184. $block_static->date_modification = $db->jdate($obj->tms);
  185. $block_static->action = $obj->action;
  186. $block_static->fk_object = $obj->fk_object;
  187. $block_static->element = $obj->element;
  188. $block_static->amounts = (double) $obj->amounts;
  189. $block_static->ref_object = $obj->ref_object;
  190. $block_static->date_object = $db->jdate($obj->date_object);
  191. $block_static->user_fullname = $obj->user_fullname;
  192. $block_static->fk_user = $obj->fk_user;
  193. $block_static->signature = $obj->signature;
  194. $block_static->object_data = $block_static->dolDecodeBlockedData($obj->object_data);
  195. $checksignature = $block_static->checkSignature($previoushash); // If $previoushash is not defined, checkSignature will search it
  196. if ($checksignature) {
  197. $statusofrecord = 'Valid';
  198. if ($loweridinerror > 0) {
  199. $statusofrecordnote = 'ValidButFoundAPreviousKO';
  200. } else {
  201. $statusofrecordnote = '';
  202. }
  203. } else {
  204. $statusofrecord = 'KO';
  205. $statusofrecordnote = 'LineCorruptedOrNotMatchingPreviousOne';
  206. $loweridinerror = $obj->rowid;
  207. }
  208. if ($i == 0) {
  209. $statusofrecordnote = $langs->trans("PreviousFingerprint").': '.$previoushash.($statusofrecordnote ? ' - '.$statusofrecordnote : '');
  210. }
  211. print $obj->rowid;
  212. print ';'.$obj->date_creation;
  213. print ';"'.str_replace('"', '""', $obj->user_fullname).'"';
  214. print ';'.$obj->action;
  215. print ';'.$obj->element;
  216. print ';'.$obj->amounts;
  217. print ';'.$obj->fk_object;
  218. print ';'.$obj->date_object;
  219. print ';"'.str_replace('"', '""', $obj->ref_object).'"';
  220. print ';'.$obj->signature;
  221. print ';'.$statusofrecord;
  222. print ';'.$statusofrecordnote;
  223. print ';"'.str_replace('"', '""', $obj->object_data).'"';
  224. print "\n";
  225. // Set new previous hash for next fetch
  226. $previoushash = $obj->signature;
  227. $i++;
  228. }
  229. exit;
  230. } else {
  231. setEventMessages($db->lasterror, null, 'errors');
  232. }
  233. }
  234. }
  235. /*
  236. * View
  237. */
  238. $form = new Form($db);
  239. if (GETPOST('withtab', 'alpha')) {
  240. $title = $langs->trans("ModuleSetup").' '.$langs->trans('BlockedLog');
  241. } else {
  242. $title = $langs->trans("BrowseBlockedLog");
  243. }
  244. $help_url="EN:Module_Unalterable_Archives_-_Logs|FR:Module_Archives_-_Logs_Inaltérable";
  245. llxHeader('', $title, $help_url);
  246. $MAXLINES = 10000;
  247. $blocks = $block_static->getLog('all', $search_id, $MAXLINES, $sortfield, $sortorder, $search_fk_user, $search_start, $search_end, $search_ref, $search_amount, $search_code);
  248. if (!is_array($blocks)) {
  249. if ($blocks == -2) {
  250. setEventMessages($langs->trans("TooManyRecordToScanRestrictFilters", $MAXLINES), null, 'errors');
  251. } else {
  252. dol_print_error($block_static->db, $block_static->error, $block_static->errors);
  253. exit;
  254. }
  255. }
  256. $linkback = '';
  257. if (GETPOST('withtab', 'alpha')) {
  258. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php').'">'.$langs->trans("BackToModuleList").'</a>';
  259. }
  260. print load_fiche_titre($title, $linkback);
  261. if (GETPOST('withtab', 'alpha')) {
  262. $head = blockedlogadmin_prepare_head();
  263. print dol_get_fiche_head($head, 'fingerprints', '', -1);
  264. }
  265. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("FingerprintsDesc")."<br></span>\n";
  266. print '<br>';
  267. $param = '';
  268. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  269. $param .= '&contextpage='.urlencode($contextpage);
  270. }
  271. if ($limit > 0 && $limit != $conf->liste_limit) {
  272. $param .= '&limit='.urlencode($limit);
  273. }
  274. if ($search_id != '') {
  275. $param .= '&search_id='.urlencode($search_id);
  276. }
  277. if ($search_fk_user > 0) {
  278. $param .= '&search_fk_user='.urlencode($search_fk_user);
  279. }
  280. if ($search_startyear > 0) {
  281. $param .= '&search_startyear='.urlencode($search_startyear);
  282. }
  283. if ($search_startmonth > 0) {
  284. $param .= '&search_startmonth='.urlencode($search_startmonth);
  285. }
  286. if ($search_startday > 0) {
  287. $param .= '&search_startday='.urlencode($search_startday);
  288. }
  289. if ($search_endyear > 0) {
  290. $param .= '&search_endyear='.urlencode($search_endyear);
  291. }
  292. if ($search_endmonth > 0) {
  293. $param .= '&search_endmonth='.urlencode($search_endmonth);
  294. }
  295. if ($search_endday > 0) {
  296. $param .= '&search_endday='.urlencode($search_endday);
  297. }
  298. if ($search_showonlyerrors > 0) {
  299. $param .= '&search_showonlyerrors='.urlencode($search_showonlyerrors);
  300. }
  301. if ($optioncss != '') {
  302. $param .= '&optioncss='.urlencode($optioncss);
  303. }
  304. if (GETPOST('withtab', 'alpha')) {
  305. $param .= '&withtab='.urlencode(GETPOST('withtab', 'alpha'));
  306. }
  307. // Add $param from extra fields
  308. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  309. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  310. print '<input type="hidden" name="token" value="'.newToken().'">';
  311. print '<div class="right">';
  312. print $langs->trans("RestrictYearToExport").': ';
  313. $smonth = GETPOST('monthtoexport', 'int');
  314. // Month
  315. $retstring = '';
  316. $retstring .= '<select class="flat valignmiddle maxwidth75imp marginrightonly" id="monthtoexport" name="monthtoexport">';
  317. $retstring .= '<option value="0" selected>&nbsp;</option>';
  318. for ($month = 1; $month <= 12; $month++) {
  319. $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
  320. $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
  321. $retstring .= "</option>";
  322. }
  323. $retstring .= "</select>";
  324. print $retstring;
  325. print '<input type="text" name="yeartoexport" class="valignmiddle maxwidth50imp" value="'.GETPOST('yeartoexport', 'int').'">';
  326. print '<input type="hidden" name="withtab" value="'.GETPOST('withtab', 'alpha').'">';
  327. print '<input type="submit" name="downloadcsv" class="button" value="'.$langs->trans('DownloadLogCSV').'">';
  328. if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) {
  329. print ' | <a href="?action=downloadblockchain'.(GETPOST('withtab', 'alpha') ? '&withtab='.GETPOST('withtab', 'alpha') : '').'">'.$langs->trans('DownloadBlockChain').'</a>';
  330. }
  331. print ' </div><br>';
  332. print '</form>';
  333. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  334. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  335. if ($optioncss != '') {
  336. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  337. }
  338. print '<input type="hidden" name="token" value="'.newToken().'">';
  339. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  340. print '<input type="hidden" name="action" value="list">';
  341. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  342. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  343. print '<input type="hidden" name="page" value="'.$page.'">';
  344. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  345. print '<input type="hidden" name="withtab" value="'.GETPOST('withtab', 'alpha').'">';
  346. print '<table class="noborder centpercent">';
  347. // Line of filters
  348. print '<tr class="liste_titre_filter">';
  349. print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="'.dol_escape_htmltag($search_id).'"></td>';
  350. print '<td class="liste_titre">';
  351. //print $langs->trans("from").': ';
  352. print $form->selectDate($search_start, 'search_start');
  353. //print '<br>';
  354. //print $langs->trans("to").': ';
  355. print $form->selectDate($search_end, 'search_end');
  356. print '</td>';
  357. // User
  358. print '<td class="liste_titre">';
  359. print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  360. print '</td>';
  361. // Actions code
  362. $langs->load("blockedlog");
  363. print '<td class="liste_titre">';
  364. print $form->selectarray('search_code', $block_static->trackedevents, $search_code, 1, 0, 0, '', 1, 0, 0, 'ASC', 'maxwidth200', 1);
  365. print '</td>';
  366. // Ref
  367. print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  368. // Link to ref
  369. print '<td class="liste_titre"></td>';
  370. // Amount
  371. print '<td class="liste_titre right"><input type="text" class="maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  372. // Full data
  373. print '<td class="liste_titre"></td>';
  374. // Fingerprint
  375. print '<td class="liste_titre"></td>';
  376. // Status
  377. print '<td class="liste_titre">';
  378. $array = array("1"=>$langs->trans("OnlyNonValid"));
  379. print $form->selectarray('search_showonlyerrors', $array, $search_showonlyerrors, 1);
  380. print '</td>';
  381. // Status note
  382. print '<td class="liste_titre"></td>';
  383. // Action column
  384. print '<td class="liste_titre" align="middle">';
  385. $searchpicto = $form->showFilterButtons();
  386. print $searchpicto;
  387. print '</td>';
  388. print '</tr>';
  389. print '<tr class="liste_titre">';
  390. print getTitleFieldOfList($langs->trans('#'), 0, $_SERVER["PHP_SELF"], 'rowid', '', $param, '', $sortfield, $sortorder, 'minwidth50 ')."\n";
  391. print getTitleFieldOfList($langs->trans('Date'), 0, $_SERVER["PHP_SELF"], 'date_creation', '', $param, '', $sortfield, $sortorder, '')."\n";
  392. print getTitleFieldOfList($langs->trans('Author'), 0, $_SERVER["PHP_SELF"], 'user_fullname', '', $param, '', $sortfield, $sortorder, '')."\n";
  393. print getTitleFieldOfList($langs->trans('Action'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
  394. print getTitleFieldOfList($langs->trans('Ref'), 0, $_SERVER["PHP_SELF"], 'ref_object', '', $param, '', $sortfield, $sortorder, '')."\n";
  395. print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
  396. print getTitleFieldOfList($langs->trans('Amount'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder, '')."\n";
  397. print getTitleFieldOfList($langs->trans('DataOfArchivedEvent'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  398. print getTitleFieldOfList($langs->trans('Fingerprint'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
  399. print getTitleFieldOfList($langs->trans('Status'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  400. print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  401. print getTitleFieldOfList('<span id="blockchainstatus"></span>', 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  402. print '</tr>';
  403. if (!empty($conf->global->BLOCKEDLOG_SCAN_ALL_FOR_LOWERIDINERROR)) {
  404. // This is version that is faster but require more memory and report errors that are outside the filter range
  405. // 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
  406. // to find the $loweridinerror.
  407. } else {
  408. // This is version that optimize the memory (but will not report errors that are outside the filter range)
  409. $loweridinerror = 0;
  410. $checkresult = array();
  411. $checkdetail = array();
  412. if (is_array($blocks)) {
  413. foreach ($blocks as &$block) {
  414. $tmpcheckresult = $block->checkSignature('', 1); // Note: this make a sql request at each call, we can't avoid this as the sorting order is various
  415. $checksignature = $tmpcheckresult['checkresult'];
  416. $checkresult[$block->id] = $checksignature; // false if error
  417. $checkdetail[$block->id] = $tmpcheckresult;
  418. if (!$checksignature) {
  419. if (empty($loweridinerror)) {
  420. $loweridinerror = $block->id;
  421. } else {
  422. $loweridinerror = min($loweridinerror, $block->id);
  423. }
  424. }
  425. }
  426. }
  427. }
  428. if (is_array($blocks)) {
  429. $nbshown = 0;
  430. $MAXFORSHOWLINK = 100;
  431. $object_link = '';
  432. foreach ($blocks as &$block) {
  433. //if (empty($search_showonlyerrors) || ! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror))
  434. if (empty($search_showonlyerrors) || !$checkresult[$block->id]) {
  435. $nbshown++;
  436. if ($nbshown < $MAXFORSHOWLINK) { // For performance and memory purpose, we get/show the link of objects only for the 100 first output
  437. $object_link = $block->getObjectLink();
  438. } else {
  439. $object_link = $block->element.'/'.$block->fk_object;
  440. }
  441. print '<tr class="oddeven">';
  442. // ID
  443. print '<td>'.$block->id.'</td>';
  444. // Date
  445. print '<td>'.dol_print_date($block->date_creation, 'dayhour').'</td>';
  446. // User
  447. print '<td>';
  448. //print $block->getUser()
  449. print $block->user_fullname;
  450. print '</td>';
  451. // Action
  452. print '<td>'.$langs->trans('log'.$block->action).'</td>';
  453. // Ref
  454. print '<td class="nowraponall">';
  455. print $block->ref_object;
  456. print '</td>';
  457. // Link to source object
  458. print '<td'.(preg_match('/<a/', $object_link) ? ' class="nowrap"' : '').'><!-- object_link -->'.$object_link.'</td>';
  459. // Amount
  460. print '<td class="right nowraponall">'.price($block->amounts).'</td>';
  461. // Details link
  462. print '<td align="center"><a href="#" data-blockid="'.$block->id.'" rel="show-info">'.img_info($langs->trans('ShowDetails')).'</a></td>';
  463. // Fingerprint
  464. print '<td class="nowrap">';
  465. $texttoshow = $langs->trans("Fingerprint").' - '.$langs->trans("Saved").':<br>'.$block->signature;
  466. $texttoshow .= '<br><br>'.$langs->trans("Fingerprint").' - Recalculated sha256(previoushash * data):<br>'.$checkdetail[$block->id]['calculatedsignature'];
  467. $texttoshow .= '<br><span class="opacitymedium">'.$langs->trans("PreviousHash").'='.$checkdetail[$block->id]['previoushash'].'</span>';
  468. //$texttoshow .= '<br>keyforsignature='.$checkdetail[$block->id]['keyforsignature'];
  469. print $form->textwithpicto(dol_trunc($block->signature, '8'), $texttoshow, 1, 'help', '', 0, 2, 'fingerprint'.$block->id);
  470. print '</td>';
  471. // Status
  472. print '<td class="center">';
  473. if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error
  474. if ($checkresult[$block->id]) {
  475. print '<span class="badge badge-status4 badge-status" title="'.$langs->trans('OkCheckFingerprintValidityButChainIsKo').'">OK</span>';
  476. } else {
  477. print '<span class="badge badge-status8 badge-status" title="'.$langs->trans('KoCheckFingerprintValidity').'">KO</span>';
  478. }
  479. } else {
  480. print '<span class="badge badge-status4 badge-status" title="'.$langs->trans('OkCheckFingerprintValidity').'">OK</span>';
  481. }
  482. print '</td>';
  483. // Note
  484. print '<td class="center">';
  485. if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error
  486. if ($checkresult[$block->id]) {
  487. print $form->textwithpicto('', $langs->trans('OkCheckFingerprintValidityButChainIsKo'));
  488. }
  489. }
  490. if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
  491. print ' '.($block->certified ? img_picto($langs->trans('AddedByAuthority'), 'info') : img_picto($langs->trans('NotAddedByAuthorityYet'), 'info_black'));
  492. }
  493. print '</td>';
  494. print '<td></td>';
  495. print '</tr>';
  496. }
  497. }
  498. if ($nbshown == 0) {
  499. print '<tr><td colspan="12"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  500. }
  501. }
  502. print '</table>';
  503. print '</div>';
  504. print '</form>';
  505. // Javascript to manage the showinfo popup
  506. print '<script type="text/javascript">
  507. jQuery(document).ready(function () {
  508. jQuery("#dialogforpopup").dialog(
  509. { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
  510. maxHeight: window.innerHeight-60, height: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? 400 : 700).',
  511. modal: true,
  512. autoOpen: false }).css("z-index: 5000");
  513. $("a[rel=show-info]").click(function() {
  514. console.log("We click on tooltip, we open popup and get content using an ajax call");
  515. var fk_block = $(this).attr("data-blockid");
  516. $.ajax({
  517. method: "GET",
  518. data: { token: \''.currentToken().'\' },
  519. url: "'.DOL_URL_ROOT.'/blockedlog/ajax/block-info.php?id="+fk_block,
  520. dataType: "html"
  521. }).done(function(data) {
  522. jQuery("#dialogforpopup").html(data);
  523. });
  524. jQuery("#dialogforpopup").dialog("open");
  525. });
  526. })
  527. </script>'."\n";
  528. if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
  529. ?>
  530. <script type="text/javascript">
  531. $.ajax({
  532. method: "GET",
  533. data: { token: '<?php echo currentToken() ?>' },
  534. url: '<?php echo DOL_URL_ROOT.'/blockedlog/ajax/check_signature.php' ?>',
  535. dataType: 'html'
  536. }).done(function(data) {
  537. if(data == 'hashisok') {
  538. $('#blockchainstatus').html('<?php echo $langs->trans('AuthorityReconizeFingerprintConformity').' '.img_picto($langs->trans('SignatureOK'), 'on') ?>');
  539. }
  540. else{
  541. $('#blockchainstatus').html('<?php echo $langs->trans('AuthorityDidntReconizeFingerprintConformity').' '.img_picto($langs->trans('SignatureKO'), 'off') ?>');
  542. }
  543. });
  544. </script>
  545. <?php
  546. }
  547. if (GETPOST('withtab', 'alpha')) {
  548. print dol_get_fiche_end();
  549. }
  550. print '<br><br>';
  551. // End of page
  552. llxFooter();
  553. $db->close();