index-tree.php 3.9 KB

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