Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkTopology/topologie-img.php

    r738 r873  
    33include('../global.php');
    44
    5 if(array_key_exists('debug', $_GET)) $debug = $_GET['debug'];
     5if (array_key_exists('debug', $_GET)) $debug = $_GET['debug'];
    66else $debug = 0;
    77$TopHostName = 'nix-router';
     
    1313  global $debug, $bbound;
    1414
    15   if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0;
    16   if($i = $vfirst[$id])
     15  if (!array_key_exists($id, $vfirst)) $vfirst[$id] = 0;
     16  if ($i = $vfirst[$id])
    1717  {
    1818    //if ($debug==2) echo $id.':'.@$i.','.@$vpred[$i].'-'.@$vleft[@$vpred[$i]]."\n";
     
    3737      $vleft[$i]+=$diff;
    3838      $limit = balance($i,$level+1, $vlast,$vleft,$vpred, $vfirst,$vnext,$tbound, $width, $limit) + 2;
    39       if(!array_key_exists($i, $vnext)) $vnext[$i] = 0;
     39      if (!array_key_exists($i, $vnext)) $vnext[$i] = 0;
    4040      $i = $vnext[$i];
    4141    }
     
    9191    $item = $DbResult->fetch_array();
    9292    //print_r($item);
    93     if($item)
     93    if ($item)
    9494    {
    9595  // --- Zpracování položky z DB -----------------------------------------------
    96       if($position[$level] > 0)
     96      if ($position[$level] > 0)
    9797      {
    9898        $vnext[$curr] = $item['id']; // Neprvní položka, nastav předchozí
     
    103103      $vlast[$parent[$level]] = $curr;
    104104      $vtop[$curr] = $level;
    105       if(!array_key_exists($level, $tbound)) $tbound[$level] = 0;
     105      if (!array_key_exists($level, $tbound)) $tbound[$level] = 0;
    106106      $vleft[$curr] = $tbound[$level];
    107       if(!array_key_exists($level, $tranger)) $tranger[$level] = 0;
     107      if (!array_key_exists($level, $tranger)) $tranger[$level] = 0;
    108108      $vpred[$curr] = $tranger[$level];
    109109      $tranger[$level] = $curr;
     
    117117      {
    118118        // Uzelový vrchol
    119         if(array_key_exists($level + 1, $tbound))
    120           if($tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = $tbound[$level + 1];
     119        if (array_key_exists($level + 1, $tbound))
     120          if ($tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = $tbound[$level + 1];
    121121      }
    122122      $tbound[$level] = $vleft[$curr] + 2;
     
    133133    {
    134134  // --- Zarovnávání prvků kvůli vzhledu
    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;
     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;
    137137      if ($vleft[$vfirst[$parent[$level]]] > $vleft[$parent[$level]])
    138138      {
     
    146146      }
    147147      $level--;
    148       if(!array_key_exists($level, $parent)) $parent[$level] = 0;
    149       if(!array_key_exists($parent[$level], $vlast)) $vlast[$parent[$level]] = 0;
     148      if (!array_key_exists($level, $parent)) $parent[$level] = 0;
     149      if (!array_key_exists($parent[$level], $vlast)) $vlast[$parent[$level]] = 0;
    150150      $curr = $vlast[$parent[$level]];
    151151
    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];
    155     }
    156   } while($level >= 0);
     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];
     155    }
     156  } while ($level >= 0);
    157157  $data = compact('tbound', 'count', 'tbound', 'vfirst', 'vlast', 'vtop', 'vleft', 'height', 'width', 'index', 'maxindex');
    158   return($data);
     158  return ($data);
    159159};
    160160
     
    164164$data = gentree(1);
    165165$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;
     166for ($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;
    170170  $vleft[$i] = .2 + ($vleft[$i] + ($datawidth - $data['vleft'][$i])) / 2;
    171171}
     
    179179$IconList = array();
    180180$DbResult = $Database->query('SELECT * FROM HostType');
    181 while($HostType = $DbResult->fetch_assoc())
     181while ($HostType = $DbResult->fetch_assoc())
    182182  $IconList[$HostType['Id']] = imagecreatefrompng('images/'.$HostType['IconName'].'.png');
    183183
     
    194194{
    195195  global $vleft, $spacex;
    196   return($vleft[$id] * $spacex);
     196  return ($vleft[$id] * $spacex);
    197197}
    198198
    199199$DbResult = $Database->query('SELECT * FROM hosts JOIN HostType ON HostType.Id = hosts.type WHERE hosts.used=1');
    200 while($item = $DbResult->fetch_array())
     200while ($item = $DbResult->fetch_array())
    201201{
    202202  $id = $item['id'];
    203   if(!array_key_exists($id, $vtop)) $vtop[$id] = 0;
    204   if(($vtop[$id] > 0) || ($item['name'] == $TopHostName))
     203  if (!array_key_exists($id, $vtop)) $vtop[$id] = 0;
     204  if (($vtop[$id] > 0) || ($item['name'] == $TopHostName))
    205205  {
    206     if($vtop[$id] > 0) imageline($im, xpos($id) + $halfx, $vtop[$id] * $spacey, xpos($id) + $halfx, $vtop[$id] * $spacey + 8, $black);
    207     if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0;
    208     if($vfirst[$id] > 0)
     206    if ($vtop[$id] > 0) imageline($im, xpos($id) + $halfx, $vtop[$id] * $spacey, xpos($id) + $halfx, $vtop[$id] * $spacey + 8, $black);
     207    if (!array_key_exists($id, $vfirst)) $vfirst[$id] = 0;
     208    if ($vfirst[$id] > 0)
    209209    {
    210210      imageline($im, xpos($vfirst[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, xpos($vlast[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, $black);
     
    213213
    214214    $image = $IconList[$item['type']];
    215     if($item['IP'] == '')
     215    if ($item['IP'] == '')
    216216    {
    217217      $color = $gray;
    218218    } 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;
     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;
    225225    }
    226226//      $text='IP: '.$ip[0];
     
    228228    imagecopy($im, $image, xpos($id) + $halfx - 15, $vtop[$id] * $spacey + 12, 0, 0, 30, 30);
    229229//    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)
    231231    {
    232232      imagestring($im, 2, xpos($id) + ($spacex - strlen($item['id']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), $item['id'], $color);
     
    237237
    238238// === Sestavení výsledného souboru ============================================
    239 if(!($debug > 1))
     239if (!($debug > 1))
    240240{
    241241  header('Content-type: image/png');
Note: See TracChangeset for help on using the changeset viewer.