block-info.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. require '../../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
  36. $id = GETPOST('id', 'int');
  37. $block = new BlockedLog($db);
  38. if ((!$user->admin && empty($user->rights->blockedlog->read)) || empty($conf->blockedlog->enabled)) {
  39. accessforbidden();
  40. }
  41. $langs->loadLangs(array("admin"));
  42. /*
  43. * View
  44. */
  45. 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>';
  46. print '<tbody>';
  47. if ($block->fetch($id) > 0) {
  48. $objtoshow = $block->object_data;
  49. print formatObject($objtoshow, '');
  50. } else {
  51. print 'Error, failed to get unalterable log with id '.$id;
  52. }
  53. print '</tbody>';
  54. print '</table></div>';
  55. $db->close();
  56. /**
  57. * formatObject
  58. *
  59. * @param Object $objtoshow Object to show
  60. * @param string $prefix Prefix of key
  61. * @return string String formatted
  62. */
  63. function formatObject($objtoshow, $prefix)
  64. {
  65. $s = '';
  66. $newobjtoshow = $objtoshow;
  67. if (is_object($newobjtoshow) || is_array($newobjtoshow)) {
  68. //var_dump($newobjtoshow);
  69. foreach ($newobjtoshow as $key => $val) {
  70. if (!is_object($val) && !is_array($val)) {
  71. // TODO $val can be '__PHP_Incomplete_Class', the is_object return false
  72. $s .= '<tr><td>'.($prefix ? $prefix.' > ' : '').$key.'</td>';
  73. $s .= '<td>';
  74. if (in_array($key, array('date', 'datef', 'dateh', 'datec', 'datem', 'datep'))) {
  75. //var_dump(is_object($val));
  76. //var_dump(is_array($val));
  77. //var_dump(is_array($val));
  78. //var_dump(@get_class($val));
  79. //var_dump($val);
  80. $s .= dol_print_date($val, 'dayhour');
  81. } else {
  82. $s .= $val;
  83. }
  84. $s .= '</td></tr>';
  85. } elseif (is_array($val)) {
  86. $s .= formatObject($val, ($prefix ? $prefix.' > ' : '').$key);
  87. } elseif (is_object($val)) {
  88. $s .= formatObject($val, ($prefix ? $prefix.' > ' : '').$key);
  89. }
  90. }
  91. }
  92. return $s;
  93. }