index-tree1.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 class="jstree-node" id="'.$device['id'].'">';
  17. // print $device['parent_port'].'->'.$device['uplink'].'&nbsp';
  18. print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']);
  19. print_child($device['id'],$hash);
  20. print '</li></ul>';
  21. }
  22. }
  23. $dSQL = 'SELECT * FROM devices WHERE deleted=0 '.$filter.' '.$sort_sql;
  24. $switches = get_records_sql($db_link,$dSQL);
  25. $dev_hash = NULL;
  26. foreach ($switches as $row) {
  27. $dev_id=$row['id'];
  28. $dev_hash[$dev_id]['id']=$dev_id;
  29. $dev_hash[$dev_id]['name']=$row['device_name'];
  30. $pSQL = 'SELECT * FROM device_ports WHERE uplink = 1 and device_id='.$dev_id;
  31. $uplink = get_record_sql($db_link,$pSQL);
  32. if (empty($uplink)) { continue; }
  33. if (empty($uplink['target_port_id'])) { continue; }
  34. $dev_hash[$dev_id]['uplink']=$uplink['port_name'];
  35. $parentSQL='SELECT * FROM device_ports WHERE device_ports.id='.$uplink['target_port_id'];
  36. $parent=get_record_sql($db_link,$parentSQL);
  37. $dev_hash[$dev_id]['parent_id']=$parent['device_id'];
  38. $dev_hash[$dev_id]['parent_port']=$parent['port_name'];
  39. }
  40. print '<div id="html1">';
  41. foreach ($dev_hash as $device) {
  42. if (isset($device['parent_id'])) { continue; }
  43. print '<ul><li>';
  44. print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']);
  45. print_child($device['id'],$dev_hash);
  46. print '</li>';
  47. print '</ul>';
  48. }
  49. print '</div>';
  50. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  51. ?>