index.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. if (cfr('SWITCHESEDIT')) {
  3. /**
  4. * Returns some switch psycho-pass
  5. *
  6. * @param int $count
  7. *
  8. * @return string
  9. */
  10. function zb_SwitchesPsychoPass($count) {
  11. $result = '';
  12. if ($count <= 3) {
  13. $color = '#00b12e';
  14. }
  15. if (($count > 3)) {
  16. $color = '#c3cf00';
  17. }
  18. if (($count > 5)) {
  19. $color = '#e56600';
  20. }
  21. if (($count > 7)) {
  22. $color = '#e53000';
  23. }
  24. if ($count == 0) {
  25. $color = '';
  26. }
  27. $result = wf_tag('font', false, '', 'color="' . $color . '"') . $count . wf_tag('font', true);
  28. return ($result);
  29. }
  30. if (wf_CheckGet(array('ajax'))) {
  31. $alllinks = array();
  32. $allSwitches = array();
  33. $switchModels = zb_SwitchModelsGetAllTag();
  34. $tmpSwitches = zb_SwitchesGetAll();
  35. $psychoPower = array();
  36. $json = new wf_JqDtHelper();
  37. if (!empty($tmpSwitches)) {
  38. //transform array to id=>switchdata
  39. foreach ($tmpSwitches as $io => $each) {
  40. $allSwitches[$each['id']] = $each;
  41. }
  42. foreach ($tmpSwitches as $io => $each) {
  43. $alllinks[$each['id']] = $each['parentid'];
  44. }
  45. }
  46. if (!empty($allSwitches)) {
  47. foreach ($allSwitches as $ia => $each) {
  48. if (!empty($each['parentid'])) {
  49. if (isset($allSwitches[$each['parentid']])) {
  50. $traceId = $each['id'];
  51. if (!empty($traceId)) {
  52. $psychoPower[$traceId] = sizeof(zb_SwitchGetParents($alllinks, $traceId)) - 2; // minus self and last
  53. }
  54. }
  55. } else {
  56. $psychoPower[$each['id']] = 0;
  57. }
  58. }
  59. }
  60. if (!empty($psychoPower)) {
  61. foreach ($psychoPower as $io => $parentCount) {
  62. $switchData = $allSwitches[$io];
  63. $data[] = $switchData['id'];
  64. $data[] = $switchData['ip'];
  65. $data[] = $switchData['location'];
  66. $data[] = @$switchModels[$switchData['modelid']];
  67. $data[] = $switchData['desc'];
  68. $data[] = zb_SwitchesPsychoPass($parentCount);
  69. $actLinks = wf_Link('?module=switches&edit=' . $switchData['id'], web_edit_icon());
  70. $data[] = $actLinks;
  71. $json->addRow($data);
  72. unset($data);
  73. }
  74. $json->getJson();
  75. }
  76. }
  77. $columns = array('ID', 'IP', 'Location', 'Model', 'Description', 'Psycho-Pass', 'Actions');
  78. $opts = '"order": [[ 5, "desc" ]]';
  79. $backControl = wf_BackLink('?module=switches') . wf_delimiter();
  80. show_window(__('Switches') . ': ' . __('Psycho-Pass'), $backControl . wf_JqDtLoader($columns, '?module=saikopasu&ajax=true', false, 'Switches', 100, $opts));
  81. } else {
  82. show_error('Access denied');
  83. }
  84. ?>