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/Common/Global.php

    r869 r873  
    2525
    2626  $UnitIndex = 0;
    27   while($Value > 1024)
     27  while ($Value > 1024)
    2828  {
    2929    $Value = round($Value / 1024, 3);
    3030    $UnitIndex++;
    3131  }
    32   return($Value.' '.$UnitNames[$UnitIndex]);
     32  return ($Value.' '.$UnitNames[$UnitIndex]);
    3333}
    3434
     
    4848function HumanDate($Time)
    4949{
    50   if($Time != '') {
     50  if ($Time != '') {
    5151    $Date = explode(' ', $Time);
    5252    $Parts = explode('-', $Date[0]);
    53     if($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
    54     else return(' ');
    55   } else return(' ');
     53    if ($Date != '0000-00-00') return (($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
     54    else return (' ');
     55  } else return (' ');
    5656}
    5757
     
    6262  $Around = 10;
    6363  $Result = '';
    64   if($Count>1)
    65   {
    66     if($Page>0)
     64  if ($Count>1)
     65  {
     66    if ($Page>0)
    6767    {
    6868      $Result.= '<a href="'.$URL.'0">&lt;&lt;</a> ';
     
    7171    $PagesMax = $Count-1;
    7272    $PagesMin = 0;
    73     if($PagesMax>($Page+$Around)) $PagesMax = $Page+$Around;
    74     if($PagesMin<($Page-$Around))
     73    if ($PagesMax>($Page+$Around)) $PagesMax = $Page+$Around;
     74    if ($PagesMin<($Page-$Around))
    7575    {
    7676      $Result.= ' .. ';
    7777      $PagesMin = $Page-$Around;
    7878    }
    79     for($i=$PagesMin;$i<=$PagesMax;$i++)
    80     {
    81       if($i==$Page) $Result.= '<strong>';
     79    for ($i=$PagesMin;$i<=$PagesMax;$i++)
     80    {
     81      if ($i==$Page) $Result.= '<strong>';
    8282      $Result.= '<a href="'.$URL.$i.'">'.($i+1).'</a> ';
    83       if($i==$Page) $Result.= '</strong>';
    84     }
    85     if($PagesMax<($Count-1)) $Result .= ' .. ';
    86     if($Page<($Count-1))
     83      if ($i==$Page) $Result.= '</strong>';
     84    }
     85    if ($PagesMax<($Count-1)) $Result .= ' .. ';
     86    if ($Page<($Count-1))
    8787    {
    8888      $Result.= '<a href="'.$URL.($Page+1).'">&gt;</a> ';
     
    9090    }
    9191  }
    92   return($Result);
     92  return ($Result);
    9393}
    9494
    9595function ExtractTime($Time)
    9696{
    97   return(array(
     97  return (array(
    9898    'Year' => date('Y', $Time),
    9999    'Month' => date('n', $Time),
     
    109109  $Result = array();
    110110  $Parts = explode('&', $QueryString);
    111   foreach($Parts as $Part)
    112   {
    113     if($Part != '')
    114     {
    115       if(!strpos($Part, '=')) $Part .= '=';
     111  foreach ($Parts as $Part)
     112  {
     113    if ($Part != '')
     114    {
     115      if (!strpos($Part, '=')) $Part .= '=';
    116116      $Item = explode('=', $Part);
    117117      $Result[$Item[0]] = $Item[1];
    118118    }
    119119  }
    120   return($Result);
     120  return ($Result);
    121121}
    122122
     
    124124{
    125125  $Parts = array();
    126   foreach($QueryStringArray as $Index => $Item)
     126  foreach ($QueryStringArray as $Index => $Item)
    127127  {
    128128    $Parts[] = $Index.'='.$Item;
    129129  }
    130   return(implode('&amp;', $Parts));
     130  return (implode('&amp;', $Parts));
    131131}
    132132
     
    138138
    139139  $Result = '';
    140   if(array_key_exists('all', $QueryItems))
     140  if (array_key_exists('all', $QueryItems))
    141141  {
    142142    $PageCount = 1;
     
    149149  }
    150150
    151   if(!array_key_exists($ObjectName.'Page', $_SESSION)) $_SESSION[$ObjectName.'Page'] = 0;
    152   if(array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) {
    153     if(array_key_exists('page', $_GET)) $_SESSION[$ObjectName.'Page'] = $_GET['page'] * 1;
    154   }
    155   if($_SESSION[$ObjectName.'Page'] < 0) $_SESSION[$ObjectName.'Page'] = 0;
    156   if($_SESSION[$ObjectName.'Page'] >= $PageCount) $_SESSION[$ObjectName.'Page'] = $PageCount - 1;
     151  if (!array_key_exists($ObjectName.'Page', $_SESSION)) $_SESSION[$ObjectName.'Page'] = 0;
     152  if (array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) {
     153    if (array_key_exists('page', $_GET)) $_SESSION[$ObjectName.'Page'] = $_GET['page'] * 1;
     154  }
     155  if ($_SESSION[$ObjectName.'Page'] < 0) $_SESSION[$ObjectName.'Page'] = 0;
     156  if ($_SESSION[$ObjectName.'Page'] >= $PageCount) $_SESSION[$ObjectName.'Page'] = $PageCount - 1;
    157157  $CurrentPage = $_SESSION[$ObjectName.'Page'];
    158158
     
    161161
    162162  $Result = '';
    163   if($PageCount > 1)
    164   {
    165     if($CurrentPage > 0)
     163  if ($PageCount > 1)
     164  {
     165    if ($CurrentPage > 0)
    166166    {
    167167      $QueryItems['page'] = 0;
     
    172172    $PagesMax = $PageCount - 1;
    173173    $PagesMin = 0;
    174     if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
    175     if($PagesMin < ($CurrentPage - $Around))
     174    if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
     175    if ($PagesMin < ($CurrentPage - $Around))
    176176    {
    177177      $Result.= ' ... ';
    178178      $PagesMin = $CurrentPage - $Around;
    179179    }
    180     for($i = $PagesMin; $i <= $PagesMax; $i++)
    181     {
    182       if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
     180    for ($i = $PagesMin; $i <= $PagesMax; $i++)
     181    {
     182      if ($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
    183183      else {
    184184       $QueryItems['page'] = $i;
     
    186186      }
    187187    }
    188     if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
    189     if($CurrentPage < ($PageCount - 1))
     188    if ($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
     189    if ($CurrentPage < ($PageCount - 1))
    190190    {
    191191      $QueryItems['page'] = ($CurrentPage + 1);
     
    196196  }
    197197  $QueryItems['all'] = '1';
    198   if($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
     198  if ($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
    199199
    200200  $Result = '<div style="text-align: center">'.$Result.'</div>';
    201   return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
     201  return (array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
    202202    'Page' => $CurrentPage,
    203203    'Output' => $Result,
     
    212212  global $OrderDirSQL, $OrderArrowImage, $Config, $System;
    213213
    214   if(array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName))
    215   {
    216     if(array_key_exists('OrderCol', $_GET)) $_SESSION[$ObjectName.'OrderCol'] = $_GET['OrderCol'];
    217     if(array_key_exists('OrderDir', $_GET)) $_SESSION[$ObjectName.'OrderDir'] = $_GET['OrderDir'];
    218   }
    219   if(!array_key_exists($ObjectName.'OrderCol', $_SESSION)) $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn;
    220   if(!array_key_exists($ObjectName.'OrderDir', $_SESSION) ) $_SESSION[$ObjectName.'OrderDir'] = $DefaultOrder;
     214  if (array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName))
     215  {
     216    if (array_key_exists('OrderCol', $_GET)) $_SESSION[$ObjectName.'OrderCol'] = $_GET['OrderCol'];
     217    if (array_key_exists('OrderDir', $_GET)) $_SESSION[$ObjectName.'OrderDir'] = $_GET['OrderDir'];
     218  }
     219  if (!array_key_exists($ObjectName.'OrderCol', $_SESSION)) $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn;
     220  if (!array_key_exists($ObjectName.'OrderDir', $_SESSION) ) $_SESSION[$ObjectName.'OrderDir'] = $DefaultOrder;
    221221
    222222  // Check OrderCol
    223223  $Found = false;
    224   foreach($Columns as $Column)
    225   {
    226     if($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])
     224  foreach ($Columns as $Column)
     225  {
     226    if ($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])
    227227    {
    228228      $Found = true;
     
    230230    }
    231231  }
    232   if(($_SESSION[$ObjectName.'OrderCol'] == '') or ($Found == false))
     232  if (($_SESSION[$ObjectName.'OrderCol'] == '') or ($Found == false))
    233233  {
    234234    $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn;
     
    236236  }
    237237  // Check OrderDir
    238   if(($_SESSION[$ObjectName.'OrderDir'] != 0) and ($_SESSION[$ObjectName.'OrderDir'] != 1))
     238  if (($_SESSION[$ObjectName.'OrderDir'] != 0) and ($_SESSION[$ObjectName.'OrderDir'] != 1))
    239239    $_SESSION[$ObjectName.'OrderDir'] = 0;
    240240
    241241  $Result = '';
    242242  $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
    243   foreach($Columns as $Index => $Column)
     243  foreach ($Columns as $Index => $Column)
    244244  {
    245245    $QueryItems['ObjectName'] = $ObjectName;
    246246    $QueryItems['OrderCol'] = $Column['Name'];
    247247    $QueryItems['OrderDir'] = 1 - $_SESSION[$ObjectName.'OrderDir'];
    248     if($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])
     248    if ($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])
    249249      $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.
    250250      $System->Link('/images/'.$OrderArrowImage[$_SESSION[$ObjectName.'OrderDir']]).'" alt="order arrow">';
    251251      else $ArrowImage = '';
    252     if($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';
     252    if ($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';
    253253      else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>';
    254254  }
    255   return(array(
     255  return (array(
    256256    'SQL' => ' ORDER BY `'.$_SESSION[$ObjectName.'OrderCol'].'` '.$OrderDirSQL[$_SESSION[$ObjectName.'OrderDir']],
    257257    'Output' => '<tr>'.$Result.'</tr>',
     
    263263function GetRemoteAddress()
    264264{
    265   if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
     265  if (array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
    266266  else $IP = '0.0.0.0';
    267   return($IP);
     267  return ($IP);
    268268}
    269269
     
    274274  $Result = true;
    275275  $RemoteAddr = GetRemoteAddress();
    276   foreach($Config['Web']['IntranetSubnets'] as $Subnet)
    277   {
    278     if(substr($RemoteAddr, 0, strlen($Subnet)) == $Subnet)
     276  foreach ($Config['Web']['IntranetSubnets'] as $Subnet)
     277  {
     278    if (substr($RemoteAddr, 0, strlen($Subnet)) == $Subnet)
    279279    {
    280280      $Result = false;
     
    282282    }
    283283  }
    284   return($Result);
     284  return ($Result);
    285285}
    286286
     
    292292  '(SELECT `Member` FROM `NetworkDevice` WHERE (SELECT `Device` FROM `NetworkInterface` '.
    293293  'WHERE `LocalIP` = "'.$IP.'") = `NetworkDevice`.`Id`) = `Member`.`Id`');
    294   if($DbResult->num_rows > 0)
     294  if ($DbResult->num_rows > 0)
    295295  {
    296296    $DbRow = $DbResult->fetch_assoc();
    297     return($DbRow['Id']);
    298   } else return('');
     297    return ($DbRow['Id']);
     298  } else return ('');
    299299}
    300300
     
    302302{
    303303  $Result = shell_exec('which '.$Command);
    304   return(!empty($Result));
     304  return (!empty($Result));
    305305}
    306306
    307307function RemoveDiacritic($Text)
    308308{
    309   return(str_replace(
     309  return (str_replace(
    310310    array('á', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ň', 'ó', 'ř', 'š', 'ť', 'ú', 'ů',
    311311      'ý', 'ž', 'Á', 'Č', 'Ď', 'É', 'Ě', 'Í', 'Ľ', 'Ň', 'Ó', 'Ř', 'Š', 'Ť', 'Ú', 'Ů', 'Ý', 'Ž'),
     
    317317function RouterOSIdent($Name)
    318318{
    319   return(strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-', ',' => '-',
     319  return (strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-', ',' => '-',
    320320  'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y',
    321321  'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd',
     
    329329function NotBlank($Text)
    330330{
    331   if($Text == '') return('&nbsp');
    332     else return($Text);
     331  if ($Text == '') return ('&nbsp');
     332    else return ($Text);
    333333}
    334334
     
    352352function ProcessURL()
    353353{
    354   if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
     354  if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
    355355    $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
    356356    else $PathString = '';
    357   if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
     357  if (substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
    358358  $PathItems = explode('/', $PathString);
    359   if(array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false))
     359  if (array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false))
    360360    $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
    361361    else $_SERVER['QUERY_STRING'] = '';
    362362  parse_str($_SERVER['QUERY_STRING'], $_GET);
    363   return($PathItems);
     363  return ($PathItems);
    364364}
    365365
    366366function RepeatFunction($Period, $Callback)
    367367{
    368   while(1)
     368  while (1)
    369369  {
    370370    $StartTime = time();
     
    372372    $EndTime = time();
    373373    $Delay = $Period - ($EndTime - $StartTime);
    374     if($Delay < 0) $Delay = 0;
     374    if ($Delay < 0) $Delay = 0;
    375375
    376376    echo('Waiting remaining '.$Delay.' of '.$Period.' seconds period...'."\n");
Note: See TracChangeset for help on using the changeset viewer.