index-tree.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. <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'] == 1) { $dev_icon = '/img/switch16.png'; }
  24. if ($device['type'] == 2) { $dev_icon = '/img/router.png'; }
  25. if ($device['type'] == 3) { $dev_icon = '/img/gateway.png'; }
  26. print '{ "text" : "'; print $device['parent_port'].'->'.$device['uplink'].'&nbsp'.$device['name']; print '", "icon" : "'.$dev_icon.'", "id" : "'.$device['id'].'","state" : { "opened" : true },';
  27. print '"a_attr" : { "href": "'.reencodeurl('/admin/devices/editdevice.php?id='.$device['id']).'"},';
  28. print '"children" : ['; print_child($device['id'],$hash); print ']';print "},\n";
  29. }
  30. }
  31. $dSQL = 'SELECT * FROM devices WHERE deleted=0 '.$filter.' '.$sort_sql;
  32. $switches = get_records_sql($db_link,$dSQL);
  33. $dev_hash = NULL;
  34. foreach ($switches as $row) {
  35. $dev_id=$row['id'];
  36. $dev_hash[$dev_id]['id']=$dev_id;
  37. $dev_hash[$dev_id]['name']=$row['device_name'];
  38. $dev_hash[$dev_id]['type']=$row['device_type'];
  39. //gateway
  40. if ($row['user_acl'] and $row['device_type'] == 2) { $dev_hash[$dev_id]['type']=3; }
  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", "state" ],';
  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'] == 1) { $dev_icon = '/img/switch16.png'; }
  64. if ($device['type'] == 2) { $dev_icon = '/img/router.png'; }
  65. if ($device['type'] == 3) { $dev_icon = '/img/gateway.png'; }
  66. print '{ "text" : "'; print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']); print '","icon" : "'.$dev_icon.'", "id" : "'.$device['id'].'" ,"state" : { "opened" : true },';
  67. print '"a_attr" : { "href": "'.reencodeurl('/admin/devices/editdevice.php?id='.$device['id']).'"},';
  68. print '"children" : ['; print_child($device['id'],$dev_hash); print "]";
  69. print "},\n";
  70. }
  71. ?>
  72. ]}
  73. }).on('changed.jstree', function (e, data) {
  74. if (data == null) return '';
  75. if (data.node == null) return '';
  76. var href = data.node.a_attr.href;
  77. var parentId = data.node.a_attr.parent_id;
  78. if(href == '#') return '';
  79. var win = window.open(href, "_blank");
  80. });
  81. </script>
  82. <?php
  83. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  84. ?>