blockedlog_list.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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, object_version";
  154. $sql .= " FROM ".MAIN_DB_PREFIX."blockedlog";
  155. $sql .= " WHERE entity = ".((int) $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('Version')
  180. .';'.$langs->transnoentities('FullData')
  181. ."\n";
  182. $loweridinerror = 0;
  183. $i = 0;
  184. while ($obj = $db->fetch_object($res)) {
  185. // We set here all data used into signature calculation (see checkSignature method) and more
  186. // IMPORTANT: We must have here, the same rule for transformation of data than into the fetch method (db->jdate for date, ...)
  187. $block_static->id = $obj->rowid;
  188. $block_static->date_creation = $db->jdate($obj->date_creation);
  189. $block_static->date_modification = $db->jdate($obj->tms);
  190. $block_static->action = $obj->action;
  191. $block_static->fk_object = $obj->fk_object;
  192. $block_static->element = $obj->element;
  193. $block_static->amounts = (double) $obj->amounts;
  194. $block_static->ref_object = $obj->ref_object;
  195. $block_static->date_object = $db->jdate($obj->date_object);
  196. $block_static->user_fullname = $obj->user_fullname;
  197. $block_static->fk_user = $obj->fk_user;
  198. $block_static->signature = $obj->signature;
  199. $block_static->object_data = $block_static->dolDecodeBlockedData($obj->object_data);
  200. $block_static->object_version = $obj->object_version;
  201. $checksignature = $block_static->checkSignature($previoushash); // If $previoushash is not defined, checkSignature will search it
  202. if ($checksignature) {
  203. $statusofrecord = 'Valid';
  204. if ($loweridinerror > 0) {
  205. $statusofrecordnote = 'ValidButFoundAPreviousKO';
  206. } else {
  207. $statusofrecordnote = '';
  208. }
  209. } else {
  210. $statusofrecord = 'KO';
  211. $statusofrecordnote = 'LineCorruptedOrNotMatchingPreviousOne';
  212. $loweridinerror = $obj->rowid;
  213. }
  214. if ($i == 0) {
  215. $statusofrecordnote = $langs->trans("PreviousFingerprint").': '.$previoushash.($statusofrecordnote ? ' - '.$statusofrecordnote : '');
  216. }
  217. print $obj->rowid;
  218. print ';'.$obj->date_creation;
  219. print ';"'.str_replace('"', '""', $obj->user_fullname).'"';
  220. print ';'.$obj->action;
  221. print ';'.$obj->element;
  222. print ';'.$obj->amounts;
  223. print ';'.$obj->fk_object;
  224. print ';'.$obj->date_object;
  225. print ';"'.str_replace('"', '""', $obj->ref_object).'"';
  226. print ';'.$obj->signature;
  227. print ';'.$statusofrecord;
  228. print ';'.$statusofrecordnote;
  229. print ';'.$obj->object_version;
  230. print ';"'.str_replace('"', '""', $obj->object_data).'"';
  231. print "\n";
  232. // Set new previous hash for next fetch
  233. $previoushash = $obj->signature;
  234. $i++;
  235. }
  236. exit;
  237. } else {
  238. setEventMessages($db->lasterror, null, 'errors');
  239. }
  240. }
  241. }
  242. /*
  243. * View
  244. */
  245. $form = new Form($db);
  246. if (GETPOST('withtab', 'alpha')) {
  247. $title = $langs->trans("ModuleSetup").' '.$langs->trans('BlockedLog');
  248. } else {
  249. $title = $langs->trans("BrowseBlockedLog");
  250. }
  251. $help_url="EN:Module_Unalterable_Archives_-_Logs|FR:Module_Archives_-_Logs_Inaltérable";
  252. llxHeader('', $title, $help_url);
  253. $MAXLINES = 10000;
  254. $blocks = $block_static->getLog('all', $search_id, $MAXLINES, $sortfield, $sortorder, $search_fk_user, $search_start, $search_end, $search_ref, $search_amount, $search_code);
  255. if (!is_array($blocks)) {
  256. if ($blocks == -2) {
  257. setEventMessages($langs->trans("TooManyRecordToScanRestrictFilters", $MAXLINES), null, 'errors');
  258. } else {
  259. dol_print_error($block_static->db, $block_static->error, $block_static->errors);
  260. exit;
  261. }
  262. }
  263. $linkback = '';
  264. if (GETPOST('withtab', 'alpha')) {
  265. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php').'">'.$langs->trans("BackToModuleList").'</a>';
  266. }
  267. print load_fiche_titre($title, $linkback);
  268. if (GETPOST('withtab', 'alpha')) {
  269. $head = blockedlogadmin_prepare_head();
  270. print dol_get_fiche_head($head, 'fingerprints', '', -1);
  271. }
  272. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("FingerprintsDesc")."<br></span>\n";
  273. print '<br>';
  274. $param = '';
  275. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  276. $param .= '&contextpage='.urlencode($contextpage);
  277. }
  278. if ($limit > 0 && $limit != $conf->liste_limit) {
  279. $param .= '&limit='.((int) $limit);
  280. }
  281. if ($search_id != '') {
  282. $param .= '&search_id='.urlencode($search_id);
  283. }
  284. if ($search_fk_user > 0) {
  285. $param .= '&search_fk_user='.urlencode($search_fk_user);
  286. }
  287. if ($search_startyear > 0) {
  288. $param .= '&search_startyear='.urlencode($search_startyear);
  289. }
  290. if ($search_startmonth > 0) {
  291. $param .= '&search_startmonth='.urlencode($search_startmonth);
  292. }
  293. if ($search_startday > 0) {
  294. $param .= '&search_startday='.urlencode($search_startday);
  295. }
  296. if ($search_endyear > 0) {
  297. $param .= '&search_endyear='.urlencode($search_endyear);
  298. }
  299. if ($search_endmonth > 0) {
  300. $param .= '&search_endmonth='.urlencode($search_endmonth);
  301. }
  302. if ($search_endday > 0) {
  303. $param .= '&search_endday='.urlencode($search_endday);
  304. }
  305. if ($search_showonlyerrors > 0) {
  306. $param .= '&search_showonlyerrors='.urlencode($search_showonlyerrors);
  307. }
  308. if ($optioncss != '') {
  309. $param .= '&optioncss='.urlencode($optioncss);
  310. }
  311. if (GETPOST('withtab', 'alpha')) {
  312. $param .= '&withtab='.urlencode(GETPOST('withtab', 'alpha'));
  313. }
  314. // Add $param from extra fields
  315. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  316. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  317. print '<input type="hidden" name="token" value="'.newToken().'">';
  318. print '<div class="right">';
  319. print $langs->trans("RestrictYearToExport").': ';
  320. $smonth = GETPOST('monthtoexport', 'int');
  321. // Month
  322. $retstring = '';
  323. $retstring .= '<select class="flat valignmiddle maxwidth75imp marginrightonly" id="monthtoexport" name="monthtoexport">';
  324. $retstring .= '<option value="0" selected>&nbsp;</option>';
  325. for ($month = 1; $month <= 12; $month++) {
  326. $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
  327. $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
  328. $retstring .= "</option>";
  329. }
  330. $retstring .= "</select>";
  331. print $retstring;
  332. print '<input type="text" name="yeartoexport" class="valignmiddle maxwidth50imp" value="'.GETPOST('yeartoexport', 'int').'">';
  333. print '<input type="hidden" name="withtab" value="'.GETPOST('withtab', 'alpha').'">';
  334. print '<input type="submit" name="downloadcsv" class="button" value="'.$langs->trans('DownloadLogCSV').'">';
  335. if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) {
  336. print ' | <a href="?action=downloadblockchain'.(GETPOST('withtab', 'alpha') ? '&withtab='.GETPOST('withtab', 'alpha') : '').'">'.$langs->trans('DownloadBlockChain').'</a>';
  337. }
  338. print ' </div><br>';
  339. print '</form>';
  340. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  341. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  342. if ($optioncss != '') {
  343. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  344. }
  345. print '<input type="hidden" name="token" value="'.newToken().'">';
  346. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  347. print '<input type="hidden" name="action" value="list">';
  348. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  349. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  350. print '<input type="hidden" name="page" value="'.$page.'">';
  351. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  352. print '<input type="hidden" name="withtab" value="'.GETPOST('withtab', 'alpha').'">';
  353. print '<table class="noborder centpercent">';
  354. // Line of filters
  355. print '<tr class="liste_titre_filter">';
  356. print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="'.dol_escape_htmltag($search_id).'"></td>';
  357. print '<td class="liste_titre">';
  358. //print $langs->trans("from").': ';
  359. print $form->selectDate($search_start, 'search_start');
  360. //print '<br>';
  361. //print $langs->trans("to").': ';
  362. print $form->selectDate($search_end, 'search_end');
  363. print '</td>';
  364. // User
  365. print '<td class="liste_titre">';
  366. print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  367. print '</td>';
  368. // Actions code
  369. $langs->load("blockedlog");
  370. print '<td class="liste_titre">';
  371. print $form->selectarray('search_code', $block_static->trackedevents, $search_code, 1, 0, 0, '', 1, 0, 0, 'ASC', 'maxwidth200', 1);
  372. print '</td>';
  373. // Ref
  374. print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  375. // Link to ref
  376. print '<td class="liste_titre"></td>';
  377. // Amount
  378. print '<td class="liste_titre right"><input type="text" class="maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  379. // Full data
  380. print '<td class="liste_titre"></td>';
  381. // Fingerprint
  382. print '<td class="liste_titre"></td>';
  383. // Status
  384. print '<td class="liste_titre">';
  385. $array = array("1" => "OnlyNonValid");
  386. print $form->selectarray('search_showonlyerrors', $array, $search_showonlyerrors, 1, 0, 0, '', 1, 0, 0, 'ASC', 'search_status maxwidth200 onrightofpage', 1);
  387. print '</td>';
  388. // Status note
  389. print '<td class="liste_titre"></td>';
  390. // Action column
  391. print '<td class="liste_titre" align="middle">';
  392. $searchpicto = $form->showFilterButtons();
  393. print $searchpicto;
  394. print '</td>';
  395. print '</tr>';
  396. print '<tr class="liste_titre">';
  397. print getTitleFieldOfList($langs->trans('#'), 0, $_SERVER["PHP_SELF"], 'rowid', '', $param, '', $sortfield, $sortorder, 'minwidth50 ')."\n";
  398. print getTitleFieldOfList($langs->trans('Date'), 0, $_SERVER["PHP_SELF"], 'date_creation', '', $param, '', $sortfield, $sortorder, '')."\n";
  399. print getTitleFieldOfList($langs->trans('Author'), 0, $_SERVER["PHP_SELF"], 'user_fullname', '', $param, '', $sortfield, $sortorder, '')."\n";
  400. print getTitleFieldOfList($langs->trans('Action'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
  401. print getTitleFieldOfList($langs->trans('Ref'), 0, $_SERVER["PHP_SELF"], 'ref_object', '', $param, '', $sortfield, $sortorder, '')."\n";
  402. print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
  403. print getTitleFieldOfList($langs->trans('Amount'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder, '')."\n";
  404. print getTitleFieldOfList($langs->trans('DataOfArchivedEvent'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  405. print getTitleFieldOfList($langs->trans('Fingerprint'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n";
  406. print getTitleFieldOfList($langs->trans('Status'), 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  407. print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  408. print getTitleFieldOfList('<span id="blockchainstatus"></span>', 0, $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder, '')."\n";
  409. print '</tr>';
  410. if (!empty($conf->global->BLOCKEDLOG_SCAN_ALL_FOR_LOWERIDINERROR)) {
  411. // This is version that is faster but require more memory and report errors that are outside the filter range
  412. // 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
  413. // to find the $loweridinerror.
  414. } else {
  415. // This is version that optimize the memory (but will not report errors that are outside the filter range)
  416. $loweridinerror = 0;
  417. $checkresult = array();
  418. $checkdetail = array();
  419. if (is_array($blocks)) {
  420. foreach ($blocks as &$block) {
  421. $tmpcheckresult = $block->checkSignature('', 1); // Note: this make a sql request at each call, we can't avoid this as the sorting order is various
  422. $checksignature = $tmpcheckresult['checkresult'];
  423. $checkresult[$block->id] = $checksignature; // false if error
  424. $checkdetail[$block->id] = $tmpcheckresult;
  425. if (!$checksignature) {
  426. if (empty($loweridinerror)) {
  427. $loweridinerror = $block->id;
  428. } else {
  429. $loweridinerror = min($loweridinerror, $block->id);
  430. }
  431. }
  432. }
  433. }
  434. }
  435. if (is_array($blocks)) {
  436. $nbshown = 0;
  437. $MAXFORSHOWLINK = 100;
  438. $object_link = '';
  439. foreach ($blocks as &$block) {
  440. //if (empty($search_showonlyerrors) || ! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror))
  441. if (empty($search_showonlyerrors) || !$checkresult[$block->id]) {
  442. $nbshown++;
  443. if ($nbshown < $MAXFORSHOWLINK) { // For performance and memory purpose, we get/show the link of objects only for the 100 first output
  444. $object_link = $block->getObjectLink();
  445. } else {
  446. $object_link = $block->element.'/'.$block->fk_object;
  447. }
  448. print '<tr class="oddeven">';
  449. // ID
  450. print '<td>'.dol_escape_htmltag($block->id).'</td>';
  451. // Date
  452. print '<td class="nowraponall">'.dol_print_date($block->date_creation, 'dayhour').'</td>';
  453. // User
  454. print '<td>';
  455. //print $block->getUser()
  456. print dol_escape_htmltag($block->user_fullname);
  457. print '</td>';
  458. // Action
  459. print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag($langs->trans('log'.$block->action)).'">'.$langs->trans('log'.$block->action).'</td>';
  460. // Ref
  461. print '<td class="nowraponall">';
  462. print $block->ref_object;
  463. print '</td>';
  464. // Link to source object
  465. print '<td class="tdoverflowmax150"'.(preg_match('/<a/', $object_link) ? '' : 'title="'.dol_escape_htmltag(dol_string_nohtmltag($object_link)).'"').'>';
  466. print '<!-- object_link -->'; // $object_link can be a '<a href' link or a text
  467. print $object_link;
  468. print '</td>';
  469. // Amount
  470. print '<td class="right nowraponall">'.price($block->amounts).'</td>';
  471. // Details link
  472. print '<td align="center"><a href="#" data-blockid="'.$block->id.'" rel="show-info">'.img_info($langs->trans('ShowDetails')).'</a></td>';
  473. // Fingerprint
  474. print '<td class="nowrap">';
  475. $texttoshow = $langs->trans("Fingerprint").' - '.$langs->trans("Saved").':<br>'.$block->signature;
  476. $texttoshow .= '<br><br>'.$langs->trans("Fingerprint").' - Recalculated sha256(previoushash * data):<br>'.$checkdetail[$block->id]['calculatedsignature'];
  477. $texttoshow .= '<br><span class="opacitymedium">'.$langs->trans("PreviousHash").'='.$checkdetail[$block->id]['previoushash'].'</span>';
  478. //$texttoshow .= '<br>keyforsignature='.$checkdetail[$block->id]['keyforsignature'];
  479. print $form->textwithpicto(dol_trunc($block->signature, '8'), $texttoshow, 1, 'help', '', 0, 2, 'fingerprint'.$block->id);
  480. print '</td>';
  481. // Status
  482. print '<td class="center">';
  483. if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error
  484. if ($checkresult[$block->id]) {
  485. print '<span class="badge badge-status4 badge-status" title="'.$langs->trans('OkCheckFingerprintValidityButChainIsKo').'">OK</span>';
  486. } else {
  487. print '<span class="badge badge-status8 badge-status" title="'.$langs->trans('KoCheckFingerprintValidity').'">KO</span>';
  488. }
  489. } else {
  490. print '<span class="badge badge-status4 badge-status" title="'.$langs->trans('OkCheckFingerprintValidity').'">OK</span>';
  491. }
  492. print '</td>';
  493. // Note
  494. print '<td class="center">';
  495. if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error
  496. if ($checkresult[$block->id]) {
  497. print $form->textwithpicto('', $langs->trans('OkCheckFingerprintValidityButChainIsKo'));
  498. }
  499. }
  500. if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
  501. print ' '.($block->certified ? img_picto($langs->trans('AddedByAuthority'), 'info') : img_picto($langs->trans('NotAddedByAuthorityYet'), 'info_black'));
  502. }
  503. print '</td>';
  504. print '<td></td>';
  505. print '</tr>';
  506. }
  507. }
  508. if ($nbshown == 0) {
  509. print '<tr><td colspan="12"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  510. }
  511. }
  512. print '</table>';
  513. print '</div>';
  514. print '</form>';
  515. // Javascript to manage the showinfo popup
  516. print '<script type="text/javascript">
  517. jQuery(document).ready(function () {
  518. jQuery("#dialogforpopup").dialog(
  519. { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
  520. maxHeight: window.innerHeight-60, height: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? 400 : 700).',
  521. modal: true,
  522. autoOpen: false }).css("z-index: 5000");
  523. $("a[rel=show-info]").click(function() {
  524. console.log("We click on tooltip, we open popup and get content using an ajax call");
  525. var fk_block = $(this).attr("data-blockid");
  526. $.ajax({
  527. method: "GET",
  528. data: { token: \''.currentToken().'\' },
  529. url: "'.DOL_URL_ROOT.'/blockedlog/ajax/block-info.php?id="+fk_block,
  530. dataType: "html"
  531. }).done(function(data) {
  532. jQuery("#dialogforpopup").html(data);
  533. });
  534. jQuery("#dialogforpopup").dialog("open");
  535. });
  536. })
  537. </script>'."\n";
  538. if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {
  539. ?>
  540. <script type="text/javascript">
  541. $.ajax({
  542. method: "GET",
  543. data: { token: '<?php echo currentToken() ?>' },
  544. url: '<?php echo DOL_URL_ROOT.'/blockedlog/ajax/check_signature.php' ?>',
  545. dataType: 'html'
  546. }).done(function(data) {
  547. if(data == 'hashisok') {
  548. $('#blockchainstatus').html('<?php echo $langs->trans('AuthorityReconizeFingerprintConformity').' '.img_picto($langs->trans('SignatureOK'), 'on') ?>');
  549. }
  550. else{
  551. $('#blockchainstatus').html('<?php echo $langs->trans('AuthorityDidntReconizeFingerprintConformity').' '.img_picto($langs->trans('SignatureKO'), 'off') ?>');
  552. }
  553. });
  554. </script>
  555. <?php
  556. }
  557. if (GETPOST('withtab', 'alpha')) {
  558. print dol_get_fiche_end();
  559. }
  560. print '<br><br>';
  561. // End of page
  562. llxFooter();
  563. $db->close();