Ignore:
Timestamp:
Apr 26, 2009, 11:30:31 PM (16 years ago)
Author:
george
Message:
  • Přidáno: Tabulka HostType definující účel zařízení v síti.
  • Opraveno: Zobrazování online stavu počítačů v topologii s adresou IP vyšší než 100.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/is/topologie-img.php

    r129 r192  
    112112      $count[$level]++;
    113113  // --- Zjisti existenci potomků ----------------------------------------------
    114       $DbResult = $Database->query("SELECT COUNT(*) FROM hosts WHERE used=1 AND parent = ".$curr);
     114      $DbResult = $Database->query('SELECT COUNT(*) FROM hosts WHERE used=1 AND parent = '.$curr);
    115115      $childcnt = $DbResult->fetch_array();
    116116      if ($childcnt[0] > 0)
     
    164164$data = gentree(1);
    165165$datawidth = $data['width'];
    166 for($i=0; $i <= $maxindex; $i++)
     166for($i = 0; $i <= $maxindex; $i++)
    167167{
    168168  if(!array_key_exists($i, $vleft)) $vleft[$i] = 0;
     
    175175$halfx = $spacex / 2;
    176176$halfy = $spacey / 2;
    177 // === Načtení pomocných obrázků ===============================================
    178 $im_comp = imagecreatefrompng('images/comp.png');
    179 $im_dev = imagecreatefrompng('images/device.png');
     177
     178// Preload icon images
     179$IconList = array();
     180$DbResult = $Database->query('SELECT * FROM HostType');
     181while($HostType = $DbResult->fetch_assoc())
     182  $IconList[$HostType['Id']] = imagecreatefrompng('images/'.$HostType['IconName'].'.png');
     183
    180184// === Generování obrázku ======================================================
    181 $im = imagecreate(($datawidth+$width+3.2) * $halfx, ($height + 1) * $spacey);
     185$im = imagecreate(($datawidth + $width + 3.2) * $halfx, ($height + 1) * $spacey);
    182186$background_color = imagecolorallocate($im, 255, 255, 255);
    183187$black = imagecolorallocate($im, 0, 0, 0);
     
    193197}
    194198
    195 $DbResult = $Database->query("SELECT * FROM hosts WHERE used=1");
     199$DbResult = $Database->query('SELECT * FROM hosts JOIN HostType ON HostType.Id = hosts.type WHERE hosts.used=1');
    196200while($item = $DbResult->fetch_array())
    197201{
     
    207211      imageline($im, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey - 10, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey, $black);
    208212    }
    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; 
    215     if(($ip[0] != 192) and ($ip[0] != 168))
    216     {
    217       $image = $im_dev;
    218     }
    219     if($item['IP'] == '')
    220     {
     213   
     214    $image = $IconList[$item['type']];
     215    if($item['IP'] == '')
     216    {
    221217      $color = $gray;
    222       $image = $im_dev;
    223     } else
    224     {
    225       if((($ip[0] != 192) and ($ip[0] != 168)) or ($ip[3] >= 100) or ($ip[3] == 1))
    226       {
    227         if($item['online'] == 1) { $color = $green; } else $color = $red;
    228       } else
    229       {
    230         if($item['online'] == 1) { $color = $green; } else $color = $black;
    231       }
     218    } else
     219    if($item['ShowOnline'] == 1)
     220    {
     221      if($item['online'] == 1) $color = $green; else $color = $black;
     222    } else
     223    {
     224      if($item['online'] == 1) $color = $green; else $color = $red;
    232225    }
    233226//      $text='IP: '.$ip[0];
    234227//      imagestring($im,2,xpos($id)+($spacex-strlen($text)*imagefontwidth(2))/2,$vtop[$id]*$spacey+24+imagefontheight(2),$text,$black);
    235     imagecopy($im, $image, xpos($id)+$halfx-15,$vtop[$id]*$spacey+12, 0, 0, 30, 30);
     228    imagecopy($im, $image, xpos($id) + $halfx - 15, $vtop[$id] * $spacey + 12, 0, 0, 30, 30);
    236229//    imagerectangle($im,xpos($id)+$halfx-6,$vtop[$id]*$spacey+16,xpos($id)+$halfx+6,$vtop[$id]*$spacey+28,$color);
    237     if ($debug) {
     230    if($debug)
     231    {
    238232      imagestring($im, 2, xpos($id) + ($spacex - strlen($item['id']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), $item['id'], $color);
    239     } else imagestring($im, 2, xpos($id) + ($spacex - strlen($item['name']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), strtoupper($item['name']), $color);
     233    } else
     234      imagestring($im, 2, xpos($id) + ($spacex - strlen($item['name']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), strtoupper($item['name']), $color);
    240235  }
    241236}
     
    244239if(!($debug > 1))
    245240{
    246   header("Content-type: image/png");
    247   header("Cache-Control: no-cache");    // Dynamický graf, nekešovat
     241  header('Content-type: image/png');
     242  header('Cache-Control: no-cache');
    248243  imagepng($im);
    249244  imagedestroy($im);
    250   imagedestroy($im_comp);
    251   imagedestroy($im_dev);
    252 }
     245}
     246
    253247?>
Note: See TracChangeset for help on using the changeset viewer.