Ignore:
Timestamp:
Nov 5, 2015, 9:56:35 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Now network notify state is read from network interface rather then network device.
  • Added: Filter to notify only about network online changes longer then 5 seconds.
  • Modified: Show "still offline" list only if new online or offline is detected.
File:
1 edited

Legend:

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

    r762 r763  
    3737  function OnlineList($Title, $OnlineNow, $OnlinePrevious)
    3838  {
     39    $Time = time();
     40    $MinDuration = 5;
    3941    $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>');
    4042    $Output = '';
    4143    $DbResult3 = $this->Database->query('SELECT CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) AS `Name`, '.
    42       '`NetworkDevice`.`Online`, `NetworkDevice`.`LastOnline` FROM `NetworkInterface` '.
     44      '`NetworkInterface`.`Online`, `NetworkInterface`.`LastOnline` FROM `NetworkInterface` '.
    4345      '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      'WHERE (`NetworkInterface`.`Online` = '.$OnlineNow.') AND (`NetworkInterface`.`OnlineNotify` = '.$OnlinePrevious.') '.
     47      'AND (`NetworkDevice`.`PermanentOnline`=1) AND (`NetworkDevice`.`Used`=1) '.
     48      'AND (`NetworkInterface`.`LastOnline` < "'.TimeToMysqlDateTime($Time - $MinDuration).'") ORDER BY `Name` ASC');
    4649    if($DbResult3->num_rows > 0) {
    4750      $Output .= $Title.'<br/>';
    48       $Output .= '<table border="1" cellspacing="0" cellpadding="5">'.
     51      $Output .= '<table>'.
    4952      '<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";
    5053      while($Item = $DbResult3->fetch_assoc())
    5154      {
    52         $Duration = MysqlDateTimeToTime($Item['LastOnline']);
     55        $Duration = $Time - MysqlDateTimeToTime($Item['LastOnline']);
    5356        $DurationText = sprintf('%02d', floor($Duration / 3600 % 24)).':'.
    54             sprintf('%02d', floor($Duration / 60 % 60)).':'.
    55             sprintf('%02d', floor($Duration % 60));
     57          sprintf('%02d', floor($Duration / 60 % 60)).':'.
     58          sprintf('%02d', floor($Duration % 60));
    5659        $Days = floor($Duration / (60 * 60 * 24));
    5760        if($Days > 0) $DurationText = $Days.' dnů '.$DurationText;
     
    6770  function Check()
    6871  {
    69           echo('ss');
    7072    $Output = '';
    7173    $DbResult = $this->Database->query('SELECT `NotifyUser`.`Id`, `NotifyUser`.`LastTime`, `User`.`Name`, `Contact`.`Value`, `Contact`.`Category` FROM `NotifyUser` '.
     
    8385          $List = $this->OnlineList('Nově online', 1, 0);
    8486          $List .= $this->OnlineList('Nově offline', 0, 1);
    85           $List .= $this->OnlineList('Stále offline', 0, 0);
     87          if($List != '') $List .= $this->OnlineList('Stále offline', 0, 0);
    8688          if($List != '') {
    87             $Output .= 'Category '.$Category['Name'].":\n";
    88             $Content .= 'Category '.$Category['Name']."<br>\n";
     89            $Output .= 'Kategorie: '.$Category['Name'].":\n";
     90            $Content .= 'Kategorie: '.$Category['Name']."<br>\n";
    8991            $Content .= $List;
    9092          }
    9193        }
    9294      }
    93       $this->Database->query('UPDATE `NetworkDevice` SET `OnlineNotify` = `Online` '.
     95      $this->Database->query('UPDATE `NetworkInterface` SET `OnlineNotify` = `Online` '.
    9496        'WHERE `OnlineNotify` != `Online`');
    9597      $this->Database->update('NotifyUser', '`Id`='.$User['Id'], array('LastTime' => TimeToMysqlDateTime($Time)));
     
    100102        $Mail->AddTo($User['Value'], $User['Name']);
    101103        $Mail->AddBody(strip_tags($Content), 'text/plain');
    102         $Mail->AddBody($Content, 'text/html');
     104        $Mail->AddBody('<style>
     105table { border-collapse: collapse; }
     106table, th, td { border: 1px solid black; }
     107td { padding: 5px; }
     108        </style>'.$Content, 'text/html');
    103109        $Mail->Send();
    104110        $Output .= 'Sent email to '.$User['Value'].' ('.$User['Name'].')<br/>';
Note: See TracChangeset for help on using the changeset viewer.