blockedlog_list.php 27 KB

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