<?php

include('Dostupnost.php');
include('Administration.php');
include('Hosting.php');
include('Restart.php');
include('Subnet.php');
include('UserHosts.php');
include('NetworkInformation.php');
include('HostList.php');

class NetworkPage extends Page
{
  var $FullTitle = 'Síť';
  var $ShortTitle = 'Síť';
  var $RowPerPage = 20;

  function Show()
  {
    $PageClass = '';
    if(count($this->System->PathItems) > 1)
    { 
      if($this->System->PathItems[1] == 'dostupnost') $PageClass = 'AvailabilityPage';
        else if($this->System->PathItems[1] == 'hosting') $PageClass = 'HostingPage';
        else if($this->System->PathItems[1] == 'sprava') $PageClass = 'NetworkAdministrationPage';
        else if($this->System->PathItems[1] == 'restart-sluzeb') $PageClass = 'ServiceRestartPage';
        else if($this->System->PathItems[1] == 'pocitace') $PageClass = 'HostListPage';
        else if($this->System->PathItems[1] == 'podsite') $PageClass = 'SubnetPage';
        else if($this->System->PathItems[1] == 'registrovane-pocitace') $PageClass = 'NetworkHostList';
        else return(PAGE_NOT_FOUND);
    } else $PageClass = 'NetworkInformationPage';
    if($PageClass != '') 
    {
      $Page = new $PageClass();
      $Page->Database = &$this->Database;
      $Page->Config = &$this->Config;
      $Page->System = &$this->System;
      return($Page->Show());
    }
  }  
}

class NetworkPoint extends Model
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'NetworkPoint';
    $this->AddPropertyString('Name');
    $this->AddPropertyFloat('Latitude');
    $this->AddPropertyFloat('Longitude');
    $this->AddPropertyText('Description');
  }
}

class NetworkLink extends Model
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'NetworkLink';
    $this->AddPropertyOneToMany('Type', 'NetworkInterfaceType');
    $this->AddPropertyOneToMany('Interfaces', 'NetworkInterface');
    $this->AddPropertyManyToMany('NetworkPoint', 'NetworkLinkPoints', 'Link', 'Point');
  }
}

class NetworkInterface extends Model
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'NetworkInterface';
    $this->AddPropertyString('Name');
    $this->AddPropertyOneToMany('Type', 'NetworkInterfaceType');
    $this->AddPropertyString('MAC');
    $this->AddPropertyString('LocalIP');
    $this->AddPropertyString('IPv6');
    $this->AddPropertyString('ExternalIP');
    $this->AddPropertyOneToMany('Device', 'Device');
    $this->AddPropertyBoolean('Online');
    $this->AddPropertyDateTime('LastOnline');
  }
}

class NetworkInterfaceType extends Model
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'NetworkInterfaceType';
    $this->AddPropertyString('Name');
    $this->AddPropertyInteger('MaxSpeed');
    $this->AddPropertyBoolean('FullDuplex');
    $this->AddPropertyString('Color');
  }
}


class NetworkDevice extends Model
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'NetworkDevice';
    $this->AddPropertyString('Name');
    $this->AddPropertyOneToMany('Member', 'Member');
    $this->AddPropertyOneToMany('Location', 'Member');
    $this->AddPropertyOneToMany('Type', 'NetworkDeviceType');
    $this->AddPropertyFloat('PositionLatitude');
    $this->AddPropertyFloat('PositionLongitude');
    $this->AddPropertyBoolean('Used');
    $this->AddPropertyBoolean('Online');
    $this->AddPropertyDateTime('LastOnline');
    $this->AddPropertyBoolean('PermanentOnline');
    $this->AddPropertyInteger('InboundNATPriority');
  }
}

class NetworkDeviceType extends Model
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'NetworkDeviceType';
    $this->AddPropertyString('Name');
    $this->AddPropertyBoolean('ShowOnline');
    $this->AddPropertyString('IconName');
  }
}

class NetworkSubnet extends Model
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'NetworkSubnet';
    $this->AddPropertyString('Name');
    $this->AddPropertyString('AddressRange');
    $this->AddPropertyInteger('Mask');
    $this->AddPropertyString('DHCP');
    $this->AddPropertyString('Gateway');
    $this->AddPropertyString('WINS');
    $this->AddPropertyString('DNS');
    $this->AddPropertyString('Domain');
    $this->AddPropertyString('NTP');
    $this->AddPropertyOneToMany('Member', 'Member');
    $this->AddPropertyString('ExtAddressRange');
    $this->AddPropertyInteger('ExtMask');
    $this->AddPropertyString('AddressRangeIPv6');
    $this->AddPropertyBoolean('Configure');
  }
}

class EmailView extends View
{
  function __construct()
  {
    $this->Name = 'NewEmail';
    $this->Title = 'Nový email';
    $this->SubmitText = 'Odeslat';
    AddItemString('Address', 'Adresa', '');
    AddItemString('Subject', 'Předmět', '');
    AddItemText('Content', 'Obsah', '');
  }
}

/*class NetworkDeviceView extends View
{
  function __construct()
  {
    $this->Name = 'NetworkDevice';
    $
  'NewNetworkDevice' => array(
    'Title' => 'Vložit nové zařízení',
    'Table' => 'network_devices',
    'Items' => array(
      'name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
      'price' => array('Type' => 'Float', 'Caption' => 'Cena', 'Default' => 0),
      'count' => array('Type' => 'Integer', 'Caption' => 'Počet', 'Default' => 1),
      'date' => array('Type' => 'Time', 'Caption' => 'Datum zakoupení', 'Default' => 'Now'),
      'segment' => array('Type' => 'TNetworkSegment', 'Caption' => 'Segment sítě', 'Default' => 0),
      'date' => array('Type' => 'Time', 'Caption' => 'Datum zakoupení', 'Default' => 'Now'),
      'used' => array('Type' => 'TNetworkDeviceState', 'Caption' => 'Stav', 'Default' => 0),
      'consumption' => array('Type' => 'Integer', 'Caption' => 'Spotřeba', 'Default' => 0),
      'user' => array('Type' => 'TFinanceSubject', 'Caption' => 'Subjekt', 'Default' => 0),
      'info' => array('Type' => 'String', 'Caption' => 'Poznámky', 'Default' => ''),
      'shop' => array('Type' => 'String', 'Caption' => 'Obchod', 'Default' => ''),
      'device_id' => array('Type' => 'String', 'Caption' => 'Sériové číslo', 'Default' => ''),
  }
}

 $FormClasses = array(
  'NewNetworkDeviceHistory' => array(
    'Title' => 'Vložit záznam historie zařízení',
    'Table' => 'NetworkDeviceHistory',
    'Items' => array(
      'Device' => array('Type' => 'TNetworkDevice', 'Caption' => 'Zařízení', 'Default' => 0),
      'Time' => array('Type' => 'Time', 'Caption' => 'Čas', 'Default' => 'Now'),
      'Action' => array('Type' => 'TNetworkDeviceAction', 'Caption' => 'Akce', 'Default' => 0),
      'Notice' => array('Type' => 'String', 'Caption' => 'Poznámka', 'Default' => ''),
    ),
  ),
);

  
 */


class ModuleNetwork extends Module
{
  function __construct($Database, $System)
  {
    parent::__construct($Database, $System);
    $this->Name = 'Network';
    $this->Version = '1.0';
    $this->Creator = 'Chronos';
    $this->License = 'GNU/GPL';
    $this->Description = 'Network device, interface and interconnection management';
    $this->Dependencies = array('User', 'Member');
    $this->Models = array('NetworkDevice', 'NetworkDeviceType', 'NetworkInterface',
      'NetworkInterfaceType', 'NetworkPoint', 'NetworkLink', 'NetworkSubnet');
  }
  
  function Init()
  {
    $this->System->Pages['sit'] = 'NetworkPage';
  }
  
  function Install()
  {
    parent::Install();
  }

  function UnInstall()
  {
    parent::UnInstall();  
  }
}

?>
