index-tree.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/gateway.png'; }
  24. if ($device['type'] == 1) { $dev_icon = '/img/switch16.png'; }
  25. if ($device['type'] == 2) { $dev_icon = '/img/router.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. //gateway
  42. if ($row['user_acl'] and $row['device_type'] == 2) { $dev_hash[$dev_id]['type']=0; }
  43. $pSQL = 'SELECT * FROM device_ports WHERE uplink = 1 and device_id='.$dev_id;
  44. $uplink = get_record_sql($db_link,$pSQL);
  45. if (empty($uplink)) { continue; }
  46. if (empty($uplink['target_port_id'])) { continue; }
  47. //$dev_hash[$dev_id]['uplink']=$uplink['ifName'];
  48. $dev_hash[$dev_id]['uplink']=$uplink['port_name'];
  49. $parentSQL='SELECT * FROM device_ports WHERE device_ports.id='.$uplink['target_port_id'];
  50. $parent=get_record_sql($db_link,$parentSQL);
  51. $dev_hash[$dev_id]['parent_id']=$parent['device_id'];
  52. //$dev_hash[$dev_id]['parent_port']=$parent['ifName'];
  53. $dev_hash[$dev_id]['parent_port']=$parent['port_name'];
  54. }
  55. print '<div id="frmt" class="tree"></div>';
  56. print "\n";
  57. print '<script>';
  58. print "$('#frmt').jstree({";
  59. print '"themes" : { "theme" : "default", "dots" : false, "icons" : false }, "plugins" : [ "themes", "html_data", "ui", "sort" ],';
  60. print "'core' : { 'data' : [";
  61. print "\n";
  62. foreach ($dev_hash as $device) {
  63. if (isset($device['parent_id'])) { continue; }
  64. $dev_icon = '/img/server.png';
  65. if ($device['type'] == 0) { $dev_icon = '/img/gateway.png'; }
  66. if ($device['type'] == 1) { $dev_icon = '/img/switch16.png'; }
  67. if ($device['type'] == 2) { $dev_icon = '/img/router.png'; }
  68. if ($device['type'] == 3) { $dev_icon = '/img/server.png'; }
  69. if ($device['type'] == 4) { $dev_icon = '/img/ap.png'; }
  70. print '{ "text" : "'; print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']); print '","icon" : "'.$dev_icon.'", "id" : "'.$device['id'].'" ,"state" : { "opened" : true },';
  71. print '"a_attr" : { "href": "'.reencodeurl('/admin/devices/editdevice.php?id='.$device['id']).'"},';
  72. print '"children" : ['; print_child($device['id'],$dev_hash); print "]";
  73. print "},\n";
  74. }
  75. ?>
  76. ]}
  77. }).on('changed.jstree', function (e, data) {
  78. if (data == null) return '';
  79. if (data.node == null) return '';
  80. var href = data.node.a_attr.href;
  81. var parentId = data.node.a_attr.parent_id;
  82. if(href == '#') return '';
  83. var win = window.open(href, "_blank");
  84. });
  85. </script>
  86. <?php
  87. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  88. ?>