Ignore:
Timestamp:
Nov 5, 2015, 9:38:59 AM (9 years ago)
Author:
chronos
Message:
  • Modified: Notification of network interface state now show separate state table for "Now online", "Now offline", "Still offline".
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Notify/Notify.php

    r758 r762  
    3535  }
    3636
     37  function OnlineList($Title, $OnlineNow, $OnlinePrevious)
     38  {
     39    $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>');
     40    $Output = '';
     41    $DbResult3 = $this->Database->query('SELECT CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) AS `Name`, '.
     42      '`NetworkDevice`.`Online`, `NetworkDevice`.`LastOnline` FROM `NetworkInterface` '.
     43      'LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '.
     44      'WHERE (`NetworkDevice`.`Online` = '.$OnlineNow.') AND (`NetworkDevice`.`OnlineNotify` = '.$OnlinePrevious.') '.
     45      'AND (`NetworkDevice`.`PermanentOnline`=1) ORDER BY `Name` DESC');
     46    if($DbResult3->num_rows > 0) {
     47      $Output .= $Title.'<br/>';
     48      $Output .= '<table border="1" cellspacing="0" cellpadding="5">'.
     49      '<tr><th align="center">Jméno</th><th align="center">Stav</th><th align="center">Čas</th><th align="center">Trvání</th></tr>'."\n";
     50      while($Item = $DbResult3->fetch_assoc())
     51      {
     52        $Duration = MysqlDateTimeToTime($Item['LastOnline']);
     53        $DurationText = sprintf('%02d', floor($Duration / 3600 % 24)).':'.
     54            sprintf('%02d', floor($Duration / 60 % 60)).':'.
     55            sprintf('%02d', floor($Duration % 60));
     56        $Days = floor($Duration / (60 * 60 * 24));
     57        if($Days > 0) $DurationText = $Days.' dnů '.$DurationText;
     58
     59        $Output .= '<tr><td>'.$Item['Name'].'</td><td>'.$OnlineText[$Item['Online']].
     60        '</td><td>'.$Item['LastOnline'].'</td><td>'.$DurationText.'</td></tr>'."\n";
     61      }
     62      $Output .= '</table><br/>'."\n";
     63    }
     64    return $Output;
     65  }
     66
    3767  function Check()
    3868  {
    39     $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>');
     69          echo('ss');
    4070    $Output = '';
    4171    $DbResult = $this->Database->query('SELECT `NotifyUser`.`Id`, `NotifyUser`.`LastTime`, `User`.`Name`, `Contact`.`Value`, `Contact`.`Category` FROM `NotifyUser` '.
     
    5181      {
    5282        if($Category['SysName'] == 'NetworkReachability') {
    53           $DbResult3 = $this->Database->query('SELECT CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) AS `Name`, '.
    54             '`NetworkInterfaceUpDown`.`State`, `NetworkInterfaceUpDown`.`Duration`, `NetworkInterfaceUpDown`.`Time` FROM `NetworkInterfaceUpDown` '.
    55             'LEFT JOIN `NetworkInterface` ON `NetworkInterface`.`Id` = `NetworkInterfaceUpDown`.`Interface` '.
    56             'LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '.
    57             'WHERE (`Time` > "'.$User['LastTime'].'") AND (`Time` <= "'.TimeToMysqlDateTime($Time).'") '.
    58             'AND (`NetworkDevice`.`PermanentOnline`=1) ORDER BY `NetworkInterfaceUpDown`.`Time` DESC');
    59           if($DbResult3->num_rows > 0) {
     83          $List = $this->OnlineList('Nově online', 1, 0);
     84          $List .= $this->OnlineList('Nově offline', 0, 1);
     85          $List .= $this->OnlineList('Stále offline', 0, 0);
     86          if($List != '') {
    6087            $Output .= 'Category '.$Category['Name'].":\n";
    6188            $Content .= 'Category '.$Category['Name']."<br>\n";
    62             $Content .= '<table><tr><th align="center">Jméno</th><th align="center">Stav</th><th align="center">Čas</th><th align="center">Trvání</th></tr>'."\n";
    63             while($Item = $DbResult3->fetch_assoc())
    64             {
    65               $Duration = sprintf('%02d', floor($Item['Duration'] / 3600 % 24)).':'.
    66                 sprintf('%02d', floor($Item['Duration'] / 60 % 60)).':'.
    67                 sprintf('%02d', floor($Item['Duration'] % 60));
    68               $Days = floor($Item['Duration'] / (60 * 60 * 24));
    69               if($Days > 0) $Duration = $Days.' dnů '.$Duration;
    70 
    71               $Content .= '<tr><td>'.$Item['Name'].'</td><td>'.$OnlineText[$Item['State']].
    72                 '</td><td>'.$Item['Time'].'</td><td>'.$Duration.'</td></tr>'."\n";
    73             }
    74             $Content .= '</table>'."\n";
     89            $Content .= $List;
    7590          }
    7691        }
    7792      }
     93      $this->Database->query('UPDATE `NetworkDevice` SET `OnlineNotify` = `Online` '.
     94        'WHERE `OnlineNotify` != `Online`');
    7895      $this->Database->update('NotifyUser', '`Id`='.$User['Id'], array('LastTime' => TimeToMysqlDateTime($Time)));
    7996
Note: See TracChangeset for help on using the changeset viewer.