blockedlog_list.php 25 KB

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