Changeset 16 for www/is/topologie-img.php
- Timestamp:
- Jan 17, 2008, 7:13:44 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
www/is/topologie-img.php
r4 r16 13 13 global $debug, $bbound; 14 14 15 if ($i=@$vfirst[$id]) 15 if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0; 16 if($i = $vfirst[$id]) 16 17 { 17 if ($debug==2) echo @$id.':'.@$i.','.@$vpred[$i].'-'.@$vleft[@$vpred[$i]]."\n";18 if (( @$vlast[$id]>0)&&(@$vleft[$id]>@$vleft[$vlast[$id]]))18 //if ($debug==2) echo $id.':'.@$i.','.@$vpred[$i].'-'.@$vleft[@$vpred[$i]]."\n"; 19 if (($vlast[$id] > 0) && ($vleft[$id] > $vleft[$vlast[$id]])) 19 20 { 20 21 $diff=$vleft[$id]-$vleft[$vlast[$id]]; 21 22 $i=$vfirst[$id]; 22 if ($vleft[$id] >=@$tbound[$level])23 { 24 $tbound[$level] =$vleft[$id]+2;25 if ($vleft[$id] >$width) $width=$vleft[$id];23 if ($vleft[$id] >= $tbound[$level]) 24 { 25 $tbound[$level] = $vleft[$id] + 2; 26 if ($vleft[$id] > $width) $width = $vleft[$id]; 26 27 } 27 28 } else { … … 36 37 $vleft[$i]+=$diff; 37 38 $limit = balance($i,$level+1, $vlast,$vleft,$vpred, $vfirst,$vnext,$tbound, $width, $limit) + 2; 38 $i=@$vnext[$i]; 39 if(!array_key_exists($i, $vnext)) $vnext[$i] = 0; 40 $i = $vnext[$i]; 39 41 } 40 42 } … … 63 65 $height = 0; // Hloubka stromu 64 66 65 $parent[$level]=0; // Rodič dané úrovně 66 $position[$level]=0; // Aktuální pozice prvku na dané úrovni 67 $count[$level]=0; // Počet prvků na dané úrovni 68 67 $parent[$level] = 0; // Rodič dané úrovně 68 $position[$level] = 0; // Aktuální pozice prvku na dané úrovni 69 $count[$level] = 0; // Počet prvků na dané úrovni 70 71 $maxindex = 0; 72 $tbound[$level] = 0; 73 $tranger[$level] = 0; 74 69 75 // --- Hlavní cyklus --------------------------------------------------------- 70 76 do … … 72 78 // --- Proveď databázový dotaz ----------------------------------------------- 73 79 $query = 'SELECT * FROM hosts WHERE used=1 AND '; 74 if ($level ==0)80 if ($level == 0) 75 81 { 76 82 $query .= 'name = "'.$TopHostName.'" ORDER BY id'; … … 81 87 if ($mode) $query.=' DESC'; 82 88 $query .= ' LIMIT '.$position[$level].',1'; 89 //echo($query.'<br>'); 83 90 $DbResult = $Database->query($query); 84 91 $item = $DbResult->fetch_array(); 85 if ($item) { 92 //print_r($item); 93 if($item) 94 { 86 95 // --- Zpracování položky z DB ----------------------------------------------- 87 96 if($position[$level] > 0) 88 97 { 89 $vnext[$curr] =$item['id']; // Neprvní položka, nastav předchozí98 $vnext[$curr] = $item['id']; // Neprvní položka, nastav předchozí 90 99 } 91 100 $curr = $item['id']; 92 if ($curr > @$maxindex) $maxindex=$curr;101 if ($curr > $maxindex) $maxindex = $curr; 93 102 if ($position[$level] == 0) $vfirst[$parent[$level]]=$curr; // První položka, nastav první 94 $vlast[$parent[$level]] =$curr;103 $vlast[$parent[$level]] = $curr; 95 104 $vtop[$curr] = $level; 96 $vleft[$curr] = @$tbound[$level]; 97 $vpred[$curr] = @$tranger[$level]; 105 if(!array_key_exists($level, $tbound)) $tbound[$level] = 0; 106 $vleft[$curr] = $tbound[$level]; 107 if(!array_key_exists($level, $tranger)) $tranger[$level] = 0; 108 $vpred[$curr] = $tranger[$level]; 98 109 $tranger[$level] = $curr; 99 110 if (($debug == 3) && ($level == 8)) echo $curr.','; … … 104 115 $childcnt = $DbResult->fetch_array(); 105 116 if ($childcnt[0] > 0) 106 { // Uzelový vrchol 107 if(@$tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = @$tbound[$level + 1]; 117 { 118 // Uzelový vrchol 119 if(array_key_exists($level + 1, $tbound)) 120 if($tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = $tbound[$level + 1]; 108 121 } 109 122 $tbound[$level] = $vleft[$curr] + 2; … … 114 127 if ($level > $height) $height = $level; 115 128 $parent[$level] = $curr; 116 $position[$level] =0;129 $position[$level] = 0; 117 130 $count[$level] = 0; 118 131 } else $index++; // Listový vrchol 119 } else { 132 } else 133 { 120 134 // --- Zarovnávání prvků kvůli vzhledu 121 if (@$vleft[$vfirst[$parent[$level]]]>@$vleft[$parent[$level]]) { 135 if(!array_key_exists($vfirst[$parent[$level]], $vleft)) $vleft[$vfirst[$parent[$level]]] = 0; 136 if(!array_key_exists($parent[$level], $vleft)) $vleft[$parent[$level]] = 0; 137 if ($vleft[$vfirst[$parent[$level]]] > $vleft[$parent[$level]]) 138 { 122 139 $vleft[$parent[$level]] = $vleft[$vfirst[$parent[$level]]]; 123 140 if ($vleft[$parent[$level]]+2>$tbound[$level-1]) $tbound[$level-1] = $vleft[$parent[$level]]+2; 124 141 } 125 balance(@$parent[$level],$level, $vlast,$vleft,$vpred,$vfirst,$vnext,$tbound, $width, 0); 126 if (@$position[$level]==1) { 127 $vleft[$vfirst[$parent[$level]]]=@$vleft[$parent[$level]]; 142 balance($parent[$level],$level, $vlast,$vleft,$vpred,$vfirst,$vnext,$tbound, $width, 0); 143 if ($position[$level]==1) 144 { 145 $vleft[$vfirst[$parent[$level]]] = $vleft[$parent[$level]]; 128 146 } 129 147 $level--; 130 $curr=@$vlast[$parent[$level]]; 131 if (@$tbound[$level]>@$tbound[$level+1]) $tbound[$level+1]=$tbound[$level]; 148 if(!array_key_exists($level, $parent)) $parent[$level] = 0; 149 if(!array_key_exists($parent[$level], $vlast)) $vlast[$parent[$level]] = 0; 150 $curr = $vlast[$parent[$level]]; 151 152 if(!array_key_exists($level, $tbound)) $tbound[$level] = 0; 153 if(!array_key_exists($level + 1, $tbound)) $tbound[$level + 1] = 0; 154 if($tbound[$level] > $tbound[$level + 1]) $tbound[$level + 1] = $tbound[$level]; 132 155 } 133 156 } while($level >= 0); 134 $data = compact('tbound', 'count','tbound','vfirst','vlast','vtop','vleft','height','width','index','maxindex');135 return $data;157 $data = compact('tbound', 'count', 'tbound', 'vfirst', 'vlast', 'vtop', 'vleft', 'height', 'width', 'index', 'maxindex'); 158 return($data); 136 159 }; 137 160 … … 140 163 // exit(); 141 164 $data = gentree(1); 142 $datawidth = @$data['width']; 143 for ($i=0; $i<=$maxindex; $i++) $vleft[$i]=.2+(@$vleft[$i]+($datawidth-@$data['vleft'][$i]))/2; 144 145 $spacex=32; 146 $spacey=68; 147 $halfx=$spacex/2; 148 $halfy=$spacey/2; 165 $datawidth = $data['width']; 166 for($i=0; $i <= $maxindex; $i++) 167 { 168 if(!array_key_exists($i, $vleft)) $vleft[$i] = 0; 169 if(!array_key_exists($i, $data['vleft'])) $data['vleft'][$i] = 0; 170 $vleft[$i] = .2 + ($vleft[$i] + ($datawidth - $data['vleft'][$i])) / 2; 171 } 172 173 $spacex = 32; 174 $spacey = 68; 175 $halfx = $spacex / 2; 176 $halfy = $spacey / 2; 149 177 // === Načtení pomocných obrázků =============================================== 150 $im_comp = @imagecreatefrompng('images/comp.png');151 $im_dev = @imagecreatefrompng('images/device.png');178 $im_comp = imagecreatefrompng('images/comp.png'); 179 $im_dev = imagecreatefrompng('images/device.png'); 152 180 // === Generování obrázku ====================================================== 153 $im = @imagecreate(($width+1.6)*$spacex, ($height+1)*$spacey);181 $im = imagecreate(($width + 1.6) * $spacex, ($height + 1) * $spacey); 154 182 $background_color = imagecolorallocate($im, 255, 255, 255); 155 $black = imagecolorallocate($im, 0,0,0); 156 $red = imagecolorallocate($im, 255,0,0); 157 $green = imagecolorallocate($im, 0,128,0); 158 $blue = imagecolorallocate($im, 100,100,255); 159 $gray = imagecolorallocate($im, 160,160,160); 160 161 function xpos($id) { 183 $black = imagecolorallocate($im, 0, 0, 0); 184 $red = imagecolorallocate($im, 255, 0, 0); 185 $green = imagecolorallocate($im, 0, 128, 0); 186 $blue = imagecolorallocate($im, 100, 100, 255); 187 $gray = imagecolorallocate($im, 160, 160, 160); 188 189 function xpos($id) 190 { 162 191 global $vleft, $spacex; 163 return @$vleft[$id]*$spacex;192 return($vleft[$id] * $spacex); 164 193 } 165 194 166 195 $DbResult = $Database->query("SELECT * FROM hosts WHERE used=1"); 167 while 196 while($item = $DbResult->fetch_array()) 168 197 { 169 198 $id = $item['id']; 170 if ((@$vtop[$id]>0)||($item['name']==$TopHostName)) 199 if(!array_key_exists($id, $vtop)) $vtop[$id] = 0; 200 if(($vtop[$id] > 0) || ($item['name'] == $TopHostName)) 171 201 { 172 if ($vtop[$id]>0) imageline($im,xpos($id)+$halfx,@$vtop[$id]*$spacey,xpos($id)+$halfx,@$vtop[$id]*$spacey+8,$black); 173 if (@$vfirst[$id]>0) { 174 imageline($im,xpos($vfirst[$id])+$halfx,$vtop[$id]*$spacey+$spacey,xpos($vlast[$id])+$halfx,$vtop[$id]*$spacey+$spacey,$black); 175 imageline($im,xpos($id)+$halfx,($vtop[$id]+1)*$spacey-10,xpos($id)+$halfx,($vtop[$id]+1)*$spacey,$black); 176 } 177 $ip=explode('.',$item['IP']); 178 if (@$ip[3]<100) { $image=$im_comp; } else $image=$im_dev; 202 if($vtop[$id] > 0) imageline($im, xpos($id) + $halfx, $vtop[$id] * $spacey, xpos($id) + $halfx, $vtop[$id] * $spacey + 8, $black); 203 if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0; 204 if($vfirst[$id] > 0) 205 { 206 imageline($im, xpos($vfirst[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, xpos($vlast[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, $black); 207 imageline($im, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey - 10, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey, $black); 208 } 209 $ip = explode('.',$item['IP']); 210 if(!array_key_exists(3, $ip)) $ip[3] = ''; 211 if($ip[3] < 100) 212 { 213 $image = $im_comp; 214 } else $image = $im_dev; 179 215 if(($ip[0] != 192) and ($ip[0] != 168)) 180 216 { … … 185 221 $color = $gray; 186 222 $image = $im_dev; 187 } else { 188 if ((($ip[0] != 192) and ($ip[0] != 168)) or ($ip[3]>=100) or ($ip[3]==1)) 223 } else 224 { 225 if((($ip[0] != 192) and ($ip[0] != 168)) or ($ip[3] >= 100) or ($ip[3] == 1)) 189 226 { 190 227 if($item['online'] == 1) { $color = $green; } else $color = $red; 191 } else { 228 } else 229 { 192 230 if($item['online'] == 1) { $color = $green; } else $color = $black; 193 231 } … … 204 242 205 243 // === Sestavení výsledného souboru ============================================ 206 if(!($debug >1))244 if(!($debug > 1)) 207 245 { 208 246 header("Content-type: image/png");
Note:
See TracChangeset
for help on using the changeset viewer.