block-info.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/blockedlog/ajax/block-info.php
  20. * \ingroup blockedlog
  21. * \brief block-info
  22. */
  23. // This script is called with a POST method.
  24. // Directory to scan (full path) is inside POST['dir'].
  25. if (!defined('NOTOKENRENEWAL')) {
  26. define('NOTOKENRENEWAL', 1); // Disables token renewal
  27. }
  28. if (!defined('NOREQUIREMENU')) {
  29. define('NOREQUIREMENU', '1');
  30. }
  31. if (!defined('NOREQUIREHTML')) {
  32. define('NOREQUIREHTML', '1');
  33. }
  34. // Load Dolibarr environment
  35. require '../../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
  37. $id = GETPOST('id', 'int');
  38. $block = new BlockedLog($db);
  39. if ((!$user->admin && empty($user->rights->blockedlog->read)) || empty($conf->blockedlog->enabled)) {
  40. accessforbidden();
  41. }
  42. $langs->loadLangs(array("admin"));
  43. /*
  44. * View
  45. */
  46. top_httphead();
  47. print '<div id="pop-info"><table width="100%" height="80%" class="border"><thead><th width="50%" class="left">'.$langs->trans('Field').'</th><th class="left">'.$langs->trans('Value').'</th></thead>';
  48. print '<tbody>';
  49. if ($block->fetch($id) > 0) {
  50. $objtoshow = $block->object_data;
  51. print formatObject($objtoshow, '');
  52. } else {
  53. print 'Error, failed to get unalterable log with id '.$id;
  54. }
  55. print '</tbody>';
  56. print '</table></div>';
  57. $db->close();
  58. /**
  59. * formatObject
  60. *
  61. * @param Object $objtoshow Object to show
  62. * @param string $prefix Prefix of key
  63. * @return string String formatted
  64. */
  65. function formatObject($objtoshow, $prefix)
  66. {
  67. $s = '';
  68. $newobjtoshow = $objtoshow;
  69. if (is_object($newobjtoshow) || is_array($newobjtoshow)) {
  70. //var_dump($newobjtoshow);
  71. foreach ($newobjtoshow as $key => $val) {
  72. if (!is_object($val) && !is_array($val)) {
  73. // TODO $val can be '__PHP_Incomplete_Class', the is_object return false
  74. $s .= '<tr><td>'.($prefix ? $prefix.' > ' : '').$key.'</td>';
  75. $s .= '<td>';
  76. if (in_array($key, array('date', 'datef', 'dateh', 'datec', 'datem', 'datep'))) {
  77. //var_dump(is_object($val));
  78. //var_dump(is_array($val));
  79. //var_dump(is_array($val));
  80. //var_dump(@get_class($val));
  81. //var_dump($val);
  82. $s .= dol_print_date($val, 'dayhour');
  83. } else {
  84. $s .= $val;
  85. }
  86. $s .= '</td></tr>';
  87. } elseif (is_array($val)) {
  88. $s .= formatObject($val, ($prefix ? $prefix.' > ' : '').$key);
  89. } elseif (is_object($val)) {
  90. $s .= formatObject($val, ($prefix ? $prefix.' > ' : '').$key);
  91. }
  92. }
  93. }
  94. return $s;
  95. }