index.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/devtypesfilter.php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/devmodelsfilter.php");
  6. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/buildingfilter.php");
  7. $default_sort='device_name';
  8. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
  9. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  10. if (isset($_POST["remove_device"])) {
  11. $dev_ids = $_POST["fid"];
  12. foreach ($dev_ids as $key => $val) {
  13. if ($val) { delete_device($db_link,$val); }
  14. }
  15. header("Location: " . $_SERVER["REQUEST_URI"]);
  16. exit;
  17. }
  18. print_device_submenu($page_url);
  19. ?>
  20. <div id="cont">
  21. <br>
  22. <form name="def" action="index.php" method="post">
  23. <table class="data">
  24. <tr class="info" align="right">
  25. <td class="info" colspan=3> <?php print WEB_device_type_show; print_devtypes_select($db_link, "devtypes", $f_devtype_id, "id<3"); ?>
  26. <td class="info" colspan=3 align=left> <?php print WEB_models; print_devmodels_select($db_link, "devmodels", $f_devmodel_id); ?>
  27. <?php print WEB_device_show_location; print_building_select($db_link, "building_id", $f_building_id); ?></td>
  28. <td class="info"><input type="submit" id="apply" name="apply" value="<?php echo WEB_btn_show; ?>"></td>
  29. <td class="info" colspan=3><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove_device" value="<?php echo WEB_btn_delete; ?>"></td>
  30. </tr>
  31. <tr align="center">
  32. <td align=Center><input type="checkbox" onClick="checkAll(this.checked);"></td>
  33. <td><b><a href=index.php?sort=device_type&order=<?php print $new_order; ?>><?php echo WEB_cell_type; ?></a></b></td>
  34. <td><b><a href=index.php?sort=device_name&order=<?php print $new_order; ?>><?php echo WEB_cell_name; ?></a></b></td>
  35. <td><b><a href=index.php?sort=ip_int&order=<?php print $new_order; ?>><?php echo WEB_cell_ip; ?></a></b></td>
  36. <td><b><a href=index.php?sort=model_name&order=<?php print $new_order; ?>><?php echo WEB_cell_host_model; ?></a></b></td>
  37. <td style="width: 1%; white-space: nowrap;"><b><?php echo WEB_cell_sn; ?></b></td>
  38. <td><b><a href=index.php?sort=building_name&order=<?php print $new_order; ?>><?php echo WEB_location_name; ?></a></b></td>
  39. <td><b><?php echo WEB_device_port_count; ?></b></td>
  40. <td><b><?php echo WEB_nagios; ?></b></td>
  41. <td><b><?php echo WEB_network_discovery; ?></b></td>
  42. </tr>
  43. <?php
  44. $filter = '';
  45. $params=[];
  46. if ($f_building_id > 0) { $filter .= ' and building_id=?'; $params[]=$f_building_id; }
  47. if ($f_devtype_id >= 0) { $filter .= ' and device_type=?'; $params[]=$f_devtype_id; } else { $filter .= ' and device_type<=2'; }
  48. if ($f_devmodel_id > 0) { $filter .= ' and device_model_id=?'; $params[]= $f_devmodel_id; }
  49. #$countSQL = "SELECT COUNT(*) FROM devices D
  50. #LEFT JOIN device_models DM ON D.device_model_id = DM.id
  51. #LEFT JOIN building B ON D.building_id = B.id
  52. #WHERE D.deleted = 0 $filter";
  53. #$count_records = get_single_field($db_link, $countSQL, $params);
  54. #$total=ceil($count_records/$displayed);
  55. #if ($page>$total) { $page=$total; }
  56. #if ($page<1) { $page=1; }
  57. #$start = ($page * $displayed) - $displayed;
  58. #print_navigation($page_url,$page,$displayed,$count_records,$total);
  59. $sort_sql=" ORDER BY device_name";
  60. if (!empty($sort_field) and !empty($order)) { $sort_sql = " ORDER BY $sort_field $order"; }
  61. $dSQL = 'SELECT D.*, DM.model_name, B.name AS building_name FROM devices D
  62. LEFT JOIN device_models DM ON D.device_model_id = DM.id
  63. LEFT JOIN building B ON D.building_id = B.id
  64. WHERE D.deleted = 0 ' . $filter . ' ' . $sort_sql;
  65. $switches = get_records_sql($db_link,$dSQL, $params);
  66. foreach ($switches as $row) {
  67. print "<tr align=center>\n";
  68. $cl = "data";
  69. if (isset($row['nagios_status'])) {
  70. $cl = 'shutdown';
  71. if ($row['nagios_status'] == 'UP') { $cl = 'up'; }
  72. }
  73. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$row['id']."></td>\n";
  74. print "<td class=\"$cl\">".get_devtype_name($db_link,$row['device_type'])."</td>\n";
  75. print "<td class=\"$cl\" align=left><a href=editdevice.php?id=".$row['id'].">" . $row['device_name'] . "</a></td>\n";
  76. if (isset($row['user_id']) and $row['user_id']>0) {
  77. print "<td class=\"$cl\"><a href=/admin/users/edituser.php?id=".$row['user_id'].">".$row['ip']."</a></td>\n";
  78. } else {
  79. print "<td class=\"$cl\">".$row['ip']."</td>\n";
  80. }
  81. print "<td class=\"$cl\">" . get_vendor_name($db_link, $row['vendor_id']) . " " . $row['model_name'] . "</td>\n";
  82. print '<td class="'.$cl.'" style="width: 1%; white-space: nowrap;">' . $row['SN'] ."</td>\n";
  83. print "<td class=\"$cl\">" . get_building($db_link, $row['building_id']);
  84. if (!empty($row['description'])) { print '<hr style="opacity: 0;">' . $row['description']; }
  85. print "</td>\n";
  86. print "<td class=\"$cl\">" . $row['port_count'] . "</td>\n";
  87. print "<td class=\"$cl\">" . get_qa($row['nagios']) . "</td>\n";
  88. print "<td class=\"$cl\">" . get_qa($row['discovery']) . "</td>\n";
  89. }
  90. ?>
  91. </table>
  92. </form>
  93. <table class="data">
  94. <tr><td><?php echo WEB_color_device_description; ?></td></tr>
  95. <tr>
  96. <td class="shutdown"><?php echo WEB_device_down; ?></td>
  97. <td class="up"><?php echo WEB_device_online; ?></td>
  98. <tr>
  99. </table>
  100. <script>
  101. document.getElementById('devtypes').addEventListener('change', function(event) {
  102. const buttonApply = document.getElementById('apply');
  103. buttonApply.click();
  104. });
  105. document.getElementById('devmodels').addEventListener('change', function(event) {
  106. const buttonApply = document.getElementById('apply');
  107. buttonApply.click();
  108. });
  109. document.getElementById('building_id').addEventListener('change', function(event) {
  110. const buttonApply = document.getElementById('apply');
  111. buttonApply.click();
  112. });
  113. </script>
  114. <?php
  115. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
  116. ?>