Changeset 738 for trunk/Modules/NetworkTopology/topologie-img.php
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkTopology/topologie-img.php
r548 r738 9 9 10 10 // === Zpětné vyvážení stromu do hloubky ======================================= 11 function balance($id, $level, &$vlast, &$vleft, &$vpred, &$vfirst, &$vnext, &$tbound, &$width, $limit) 11 function balance($id, $level, &$vlast, &$vleft, &$vpred, &$vfirst, &$vnext, &$tbound, &$width, $limit) 12 12 { 13 13 global $debug, $bbound; 14 14 15 15 if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0; 16 if($i = $vfirst[$id]) 16 if($i = $vfirst[$id]) 17 17 { 18 18 //if ($debug==2) echo $id.':'.@$i.','.@$vpred[$i].'-'.@$vleft[@$vpred[$i]]."\n"; 19 if (($vlast[$id] > 0) && ($vleft[$id] > $vleft[$vlast[$id]])) 19 if (($vlast[$id] > 0) && ($vleft[$id] > $vleft[$vlast[$id]])) 20 20 { 21 21 $diff=$vleft[$id]-$vleft[$vlast[$id]]; 22 22 $i=$vfirst[$id]; 23 if ($vleft[$id] >= $tbound[$level]) 23 if ($vleft[$id] >= $tbound[$level]) 24 24 { 25 25 $tbound[$level] = $vleft[$id] + 2; … … 28 28 } else { 29 29 $diff=0; 30 if ($vpred[$i]&&($vleft[$i]<=$vleft[$vpred[$i]])) 30 if ($vpred[$i]&&($vleft[$i]<=$vleft[$vpred[$i]])) 31 31 { 32 32 $diff=$vleft[$i]-$vleft[$vpred[$i]]+2; 33 33 } else $i = 0; 34 34 } 35 while ($i>0) 35 while ($i>0) 36 36 { 37 37 $vleft[$i]+=$diff; … … 45 45 // === Generování rovinné stromové struktury =================================== 46 46 function gentree($mode) // depth-first algorithm 47 { 47 { 48 48 global $debug, $TopHostName, $Database; 49 49 50 50 // --- Inicializace ---------------------------------------------------------- 51 51 $tbound = array(); // Hranice pozic jednotlivých úrovní … … 58 58 $vtop = array(); // Pozice prvku shora 59 59 $vpred = array(); // Vedlejsi prvek na řádku 60 60 61 61 $index = 0; // Index aktuálního prvku 62 62 $curr = 0; // Aktuální prvek … … 68 68 $position[$level] = 0; // Aktuální pozice prvku na dané úrovni 69 69 $count[$level] = 0; // Počet prvků na dané úrovni 70 70 71 71 $maxindex = 0; 72 72 $tbound[$level] = 0; 73 73 $tranger[$level] = 0; 74 74 75 75 // --- Hlavní cyklus --------------------------------------------------------- 76 do 76 do 77 77 { 78 78 // --- Proveď databázový dotaz ----------------------------------------------- 79 79 $query = 'SELECT * FROM hosts WHERE used=1 AND '; 80 if ($level == 0) 81 { 82 $query .= 'name = "'.$TopHostName.'" ORDER BY id'; 83 } else 80 if ($level == 0) 81 { 82 $query .= 'name = "'.$TopHostName.'" ORDER BY id'; 83 } else 84 84 { 85 85 $query .= ' parent = '.$parent[$level].' ORDER BY id'; … … 91 91 $item = $DbResult->fetch_array(); 92 92 //print_r($item); 93 if($item) 93 if($item) 94 94 { 95 95 // --- Zpracování položky z DB ----------------------------------------------- 96 if($position[$level] > 0) 96 if($position[$level] > 0) 97 97 { 98 98 $vnext[$curr] = $item['id']; // Neprvní položka, nastav předchozí … … 114 114 $DbResult = $Database->query('SELECT COUNT(*) FROM hosts WHERE used=1 AND parent = '.$curr); 115 115 $childcnt = $DbResult->fetch_array(); 116 if ($childcnt[0] > 0) 117 { 116 if ($childcnt[0] > 0) 117 { 118 118 // Uzelový vrchol 119 if(array_key_exists($level + 1, $tbound)) 119 if(array_key_exists($level + 1, $tbound)) 120 120 if($tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = $tbound[$level + 1]; 121 121 } 122 122 $tbound[$level] = $vleft[$curr] + 2; 123 123 if ($vleft[$curr] > $width) $width = $vleft[$curr]; 124 if ($childcnt[0] > 0) 124 if ($childcnt[0] > 0) 125 125 { 126 126 $level++; … … 130 130 $count[$level] = 0; 131 131 } else $index++; // Listový vrchol 132 } else 132 } else 133 133 { 134 134 // --- Zarovnávání prvků kvůli vzhledu 135 135 if(!array_key_exists($vfirst[$parent[$level]], $vleft)) $vleft[$vfirst[$parent[$level]]] = 0; 136 136 if(!array_key_exists($parent[$level], $vleft)) $vleft[$parent[$level]] = 0; 137 if ($vleft[$vfirst[$parent[$level]]] > $vleft[$parent[$level]]) 137 if ($vleft[$vfirst[$parent[$level]]] > $vleft[$parent[$level]]) 138 138 { 139 139 $vleft[$parent[$level]] = $vleft[$vfirst[$parent[$level]]]; … … 141 141 } 142 142 balance($parent[$level],$level, $vlast,$vleft,$vpred,$vfirst,$vnext,$tbound, $width, 0); 143 if ($position[$level]==1) 143 if ($position[$level]==1) 144 144 { 145 145 $vleft[$vfirst[$parent[$level]]] = $vleft[$parent[$level]]; … … 149 149 if(!array_key_exists($parent[$level], $vlast)) $vlast[$parent[$level]] = 0; 150 150 $curr = $vlast[$parent[$level]]; 151 151 152 152 if(!array_key_exists($level, $tbound)) $tbound[$level] = 0; 153 153 if(!array_key_exists($level + 1, $tbound)) $tbound[$level + 1] = 0; … … 165 165 $datawidth = $data['width']; 166 166 for($i = 0; $i <= $maxindex; $i++) 167 { 167 { 168 168 if(!array_key_exists($i, $vleft)) $vleft[$i] = 0; 169 169 if(!array_key_exists($i, $data['vleft'])) $data['vleft'][$i] = 0; … … 179 179 $IconList = array(); 180 180 $DbResult = $Database->query('SELECT * FROM HostType'); 181 while($HostType = $DbResult->fetch_assoc()) 181 while($HostType = $DbResult->fetch_assoc()) 182 182 $IconList[$HostType['Id']] = imagecreatefrompng('images/'.$HostType['IconName'].'.png'); 183 183 … … 191 191 $gray = imagecolorallocate($im, 160, 160, 160); 192 192 193 function xpos($id) 193 function xpos($id) 194 194 { 195 195 global $vleft, $spacex; … … 198 198 199 199 $DbResult = $Database->query('SELECT * FROM hosts JOIN HostType ON HostType.Id = hosts.type WHERE hosts.used=1'); 200 while($item = $DbResult->fetch_array()) 200 while($item = $DbResult->fetch_array()) 201 201 { 202 202 $id = $item['id']; 203 203 if(!array_key_exists($id, $vtop)) $vtop[$id] = 0; 204 if(($vtop[$id] > 0) || ($item['name'] == $TopHostName)) 204 if(($vtop[$id] > 0) || ($item['name'] == $TopHostName)) 205 205 { 206 206 if($vtop[$id] > 0) imageline($im, xpos($id) + $halfx, $vtop[$id] * $spacey, xpos($id) + $halfx, $vtop[$id] * $spacey + 8, $black); 207 207 if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0; 208 if($vfirst[$id] > 0) 208 if($vfirst[$id] > 0) 209 209 { 210 210 imageline($im, xpos($vfirst[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, xpos($vlast[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, $black); 211 211 imageline($im, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey - 10, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey, $black); 212 212 } 213 213 214 214 $image = $IconList[$item['type']]; 215 215 if($item['IP'] == '') … … 228 228 imagecopy($im, $image, xpos($id) + $halfx - 15, $vtop[$id] * $spacey + 12, 0, 0, 30, 30); 229 229 // imagerectangle($im,xpos($id)+$halfx-6,$vtop[$id]*$spacey+16,xpos($id)+$halfx+6,$vtop[$id]*$spacey+28,$color); 230 if($debug) 230 if($debug) 231 231 { 232 232 imagestring($im, 2, xpos($id) + ($spacex - strlen($item['id']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), $item['id'], $color); 233 } else 233 } else 234 234 imagestring($im, 2, xpos($id) + ($spacex - strlen($item['name']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), strtoupper($item['name']), $color); 235 235 }
Note:
See TracChangeset
for help on using the changeset viewer.