<?php
include_once('../global.php');

class FinanceDeviceListPage extends Page
{
  var $FullTitle = 'Zařízení sítě';
  var $ShortTitle = 'Zařízení';

  function Show()
  {
    // Seznam segmentů a zařízení
    $Output = 'Seznam segmentů a zařízení:<br><table style="font-size: smaller;" class="WideTable"><tr><th>Název</th><th>Spotřeba<br>[W]</th><th>Datum<br>zakoupení</th><th>Cena [Kč]</th></tr>';
    $DbResult = $this->Database->query('SELECT * FROM network_segments');    
    while($Row = $DbResult->fetch_array())
    {
      $Output .= '<tr><td style="text-align: left" colspan="3"><strong>Segment: '.$Row['name'].' ('.$Row['users'].')</strong></td><td style="font-weight: Bold;" align="right">'.$Row['price'].'</td></tr>';
      $DbResult2 = $this->Database->query('SELECT * FROM network_devices WHERE segment='.$Row['id'].' AND used=1');
      while($Row = $DbResult2->fetch_array())
      {
        $Output .= '<tr><td style="text-align: left; padding-left: 20px;">'.$Row['name'].'</td><td align="right">'.$Row['consumption'].'</td><td align="right">'.HumanDate($Row['date']).'</td><td align="right">'.$Row['price'].'</td></tr>';
      }
    }
    $DbResult = $this->Database->query('SELECT SUM(price) FROM network_devices WHERE used=1');
    $Row = $DbResult->fetch_array();
    $Output .= '<tr><td colspan="3"><strong>Celkem:</strong></td><td align="right"><strong>'.$Row[0].'</strong></td></tr>';
    $Output .= '</table>';
    return($Output);
  }
}

$System->AddModule(new FinanceDeviceListPage());
$System->Modules['FinanceDeviceListPage']->GetOutput()

?>
