index.php 6.0 KB

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