index-tree-simple.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. unset($_POST);
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  6. print_device_submenu($page_url);
  7. ?>
  8. <div id="cont">
  9. <br>
  10. <?php
  11. function print_child($device_id,$hash)
  12. {
  13. foreach ($hash as $device) {
  14. if (!isset($device['parent_id'])) { continue; }
  15. if ($device['parent_id'] !== $device_id) { continue; }
  16. print '<ul><li>';
  17. print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']);
  18. print_child($device['id'],$hash);
  19. print '</li></ul>';
  20. }
  21. }
  22. $dSQL = 'SELECT * FROM devices WHERE deleted=0';
  23. $switches = get_records_sql($db_link,$dSQL);
  24. $dev_hash = NULL;
  25. foreach ($switches as $row) {
  26. $dev_id=$row['id'];
  27. $dev_hash[$dev_id]['id']=$dev_id;
  28. $dev_hash[$dev_id]['name']=$row['device_name'];
  29. $pSQL = 'SELECT * FROM device_ports WHERE uplink = 1 and device_id='.$dev_id;
  30. $uplink = get_record_sql($db_link,$pSQL);
  31. if (empty($uplink)) { continue; }
  32. if (empty($uplink['target_port_id'])) { continue; }
  33. $dev_hash[$dev_id]['uplink']=$uplink['port_name'];
  34. $parentSQL='SELECT * FROM device_ports WHERE device_ports.id='.$uplink['target_port_id'];
  35. $parent=get_record_sql($db_link,$parentSQL);
  36. $dev_hash[$dev_id]['parent_id']=$parent['device_id'];
  37. $dev_hash[$dev_id]['parent_port']=$parent['port_name'];
  38. }
  39. print '<div id="html">';
  40. foreach ($dev_hash as $device) {
  41. if (isset($device['parent_id'])) { continue; }
  42. print '<ul><li>';
  43. print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']);
  44. print_child($device['id'],$dev_hash);
  45. print '</li>';
  46. print '</ul>';
  47. }
  48. print '</div>';
  49. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  50. ?>