unknown.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/datetimefilter.php");
  6. if (isset($_POST['device_show'])) { $f_id = $_POST['device_show'] * 1; }
  7. if (isset($_GET['device_show'])) { $f_id = $_GET['device_show'] * 1; }
  8. if (!isset($f_id) and isset($_SESSION[$page_url]['device_show'])) { $f_id=$_SESSION[$page_url]['device_show']; }
  9. if (!isset($f_id)) { $f_id=0; }
  10. $_SESSION[$page_url]['device_show']=$f_id;
  11. print_log_submenu($page_url);
  12. $params = [$date1, $date2];
  13. $conditions = [];
  14. // === 2. Условие по устройству ===
  15. if ($f_id > 0) {
  16. $conditions[] = "D.id = ?";
  17. $params[] = (int)$f_id; // приведение к int для безопасности
  18. }
  19. $whereClause = !empty($conditions) ? ' AND ' . implode(' AND ', $conditions) : '';
  20. $countSQL = "
  21. SELECT COUNT(*)
  22. FROM unknown_mac AS U
  23. JOIN devices AS D ON U.device_id = D.id
  24. JOIN device_ports AS DP ON U.port_id = DP.id
  25. WHERE D.device_type <= 2
  26. AND U.ts >= ?
  27. AND U.ts < ?
  28. $whereClause
  29. ";
  30. $count_records = (int)get_single_field($db_link, $countSQL, $params);
  31. $total = ceil($count_records / $displayed);
  32. $page = max(1, min($page, $total));
  33. $start = ($page - 1) * $displayed;
  34. print_navigation($page_url, $page, $displayed, $count_records, $total);
  35. $limit = (int)$displayed;
  36. $offset = (int)$start;
  37. $dataParams = array_merge($params, [$limit, $offset]);
  38. $sSQL = "
  39. SELECT U.mac, U.ts, DP.port, D.device_name
  40. FROM unknown_mac AS U
  41. JOIN devices AS D ON U.device_id = D.id
  42. JOIN device_ports AS DP ON U.port_id = DP.id
  43. WHERE D.device_type <= 2
  44. AND U.ts >= ?
  45. AND U.ts < ?
  46. $whereClause
  47. ORDER BY U.mac
  48. LIMIT ? OFFSET ?
  49. ";
  50. $maclog = get_records_sql($db_link, $sSQL, $dataParams);
  51. ?>
  52. <div id="cont">
  53. <br>
  54. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  55. <?php echo WEB_log_report_by_device; ?>&nbsp<?php print_netdevice_select($db_link, "device_show", $f_id); ?>
  56. <?php print_date_fields($date1,$date2,$date_shift); ?>
  57. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  58. <input type="submit" value="<?php echo WEB_btn_show; ?>">
  59. </form>
  60. <br>
  61. <table class="data" width="750">
  62. <tr align="center">
  63. <td class="data" width=110><b><?php echo WEB_cell_connection; ?></b></td>
  64. <td class="data"><b><?php echo WEB_device_port_name; ?></b></td>
  65. <td class="data"><b><?php echo WEB_cell_mac; ?></b></td>
  66. <td class="data"><b><?php echo WEB_cell_last_found; ?></b></td>
  67. </tr>
  68. <?php
  69. foreach ($maclog as $row) {
  70. print "<tr align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";
  71. print "<td class=\"data\">" . $row['device_name'] . "</td>\n";
  72. print "<td class=\"data\">" . $row['port'] . "</td>\n";
  73. print "<td class=\"data\"><a href=/admin/logs/mac.php?mac=" . mac_simplify($row['mac']) . ">" . mac_dotted($row['mac']) . "</a></td>\n";
  74. print "<td class=\"data\">" . $row['ts'] . "</td>\n";
  75. print "</tr>\n";
  76. }
  77. print "</table>\n";
  78. print_navigation($page_url,$page,$displayed,$count_records,$total);
  79. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  80. ?>