Changeset 763


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.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r762 r763  
    11<?php
    22
    3 $Revision = 762; // Subversion revision
    4 $DatabaseRevision = 762; // SQL structure revision
     3$Revision = 763; // Subversion revision
     4$DatabaseRevision = 763; // SQL structure revision
    55$ReleaseTime = strtotime('2015-11-05');
  • trunk/Common/Setup/Updates.php

    r762 r763  
    15981598}
    15991599
     1600function UpdateTo763($Manager)
     1601{
     1602  $Manager->Execute('ALTER TABLE `NetworkInterface` ADD `OnlineNotify` INT NOT NULL AFTER `LastOnline`;');
     1603  $Manager->Execute('ALTER TABLE `NetworkDevice` DROP `OnlineNotify`;');
     1604}
    16001605
    16011606
     
    16761681      755 => array('Revision' => 759, 'Function' => 'UpdateTo759'),
    16771682      759 => array('Revision' => 762, 'Function' => 'UpdateTo762'),
     1683      762 => array('Revision' => 763, 'Function' => 'UpdateTo763'),
    16781684    ));
    16791685  }
  • 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.