index-tree-simple.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".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['parent_port'].'->'.$device['uplink'].'&nbsp'.$device['name'].'&nbsp::&nbsp<small><i>['.$device['model_name'].']</i></small>','/admin/devices/editdevice.php?id='.$device['id']);
  18. print_child($device['id'],$hash);
  19. print '</li></ul>';
  20. }
  21. }
  22. $dSQL = 'SELECT D.*,DM.model_name FROM devices as D,device_models as DM WHERE D.device_model_id=DM.id AND (deleted=0 and device_type<=2)';
  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. $dev_hash[$dev_id]['model_name']=$row['model_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="html">';
  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. ?>