1
0

index-tree.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. <script>
  9. $.getScript("/js/jstree/jstree.min.js")
  10. .fail(function(jqxhr, settings, exception) {
  11. window.location.href = '/admin/devices/index-tree-simple.php';
  12. });
  13. </script>
  14. <div id="cont">
  15. <br>
  16. <?php
  17. function print_child($device_id,$hash)
  18. {
  19. foreach ($hash as $device) {
  20. if (!isset($device['parent_id'])) { continue; }
  21. if ($device['parent_id'] !== $device_id) { continue; }
  22. $dev_icon = '/img/server.png';
  23. if ($device['type'] == 0) { $dev_icon = '/img/router.png'; }
  24. if ($device['type'] == 1) { $dev_icon = '/img/switch16.png'; }
  25. if ($device['type'] == 2) { $dev_icon = '/img/gateway.png'; }
  26. if ($device['type'] == 3) { $dev_icon = '/img/server.png'; }
  27. if ($device['type'] == 4) { $dev_icon = '/img/ap.png'; }
  28. print '{ "text" : "'; print $device['parent_port'].'->'.$device['uplink'].'&nbsp'.$device['name']; print '", "icon" : "'.$dev_icon.'", "id" : "'.$device['id'].'","state" : { "opened" : true },';
  29. print '"a_attr" : { "href": "'.reencodeurl('/admin/devices/editdevice.php?id='.$device['id']).'"},';
  30. print '"children" : ['; print_child($device['id'],$hash); print ']';print "},\n";
  31. }
  32. }
  33. $dSQL = 'SELECT * FROM devices WHERE deleted=0 and device_type<=2';
  34. $switches = get_records_sql($db_link,$dSQL);
  35. $dev_hash = NULL;
  36. foreach ($switches as $row) {
  37. $dev_id=$row['id'];
  38. $dev_hash[$dev_id]['id']=$dev_id;
  39. $dev_hash[$dev_id]['name']=$row['device_name'];
  40. $dev_hash[$dev_id]['type']=$row['device_type'];
  41. $pSQL = 'SELECT * FROM device_ports WHERE uplink = 1 and device_id='.$dev_id;
  42. $uplink = get_record_sql($db_link,$pSQL);
  43. if (empty($uplink)) { continue; }
  44. if (empty($uplink['target_port_id'])) { continue; }
  45. //$dev_hash[$dev_id]['uplink']=$uplink['ifName'];
  46. $dev_hash[$dev_id]['uplink']=$uplink['port_name'];
  47. $parentSQL='SELECT * FROM device_ports WHERE device_ports.id='.$uplink['target_port_id'];
  48. $parent=get_record_sql($db_link,$parentSQL);
  49. $dev_hash[$dev_id]['parent_id']=$parent['device_id'];
  50. //$dev_hash[$dev_id]['parent_port']=$parent['ifName'];
  51. $dev_hash[$dev_id]['parent_port']=$parent['port_name'];
  52. }
  53. print '<div id="frmt" class="tree"></div>';
  54. print "\n";
  55. print '<script>';
  56. print "$('#frmt').jstree({";
  57. print '"themes" : { "theme" : "default", "dots" : false, "icons" : false }, "plugins" : [ "themes", "html_data", "ui", "sort" ],';
  58. print "'core' : { 'data' : [";
  59. print "\n";
  60. foreach ($dev_hash as $device) {
  61. if (isset($device['parent_id'])) { continue; }
  62. $dev_icon = '/img/server.png';
  63. if ($device['type'] == 0) { $dev_icon = '/img/router.png'; }
  64. if ($device['type'] == 1) { $dev_icon = '/img/switch16.png'; }
  65. if ($device['type'] == 2) { $dev_icon = '/img/gateway.png'; }
  66. if ($device['type'] == 3) { $dev_icon = '/img/server.png'; }
  67. if ($device['type'] == 4) { $dev_icon = '/img/ap.png'; }
  68. print '{ "text" : "'; print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']); print '","icon" : "'.$dev_icon.'", "id" : "'.$device['id'].'" ,"state" : { "opened" : true },';
  69. print '"a_attr" : { "href": "'.reencodeurl('/admin/devices/editdevice.php?id='.$device['id']).'"},';
  70. print '"children" : ['; print_child($device['id'],$dev_hash); print "]";
  71. print "},\n";
  72. }
  73. ?>
  74. ]}
  75. }).on('changed.jstree', function (e, data) {
  76. if (data == null) return '';
  77. if (data.node == null) return '';
  78. var href = data.node.a_attr.href;
  79. var parentId = data.node.a_attr.parent_id;
  80. if(href == '#') return '';
  81. var win = window.open(href, "_blank");
  82. });
  83. </script>
  84. <?php
  85. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  86. ?>