unknown.php 3.0 KB

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