Changeset 507


Ignore:
Timestamp:
Apr 1, 2013, 7:14:59 PM (12 years ago)
Author:
chronos
Message:
  • Opraveno: Generování nastavení sítě. Generování front Queue nyní pracuje s přiřazením služeb k zařízením a podsítím.
  • Opraveno: Zjišťování adresáře souborů na disku dle id adresáře.
Location:
trunk
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Form/Types/File.php

    r502 r507  
    6868  {
    6969    parent::__construct($FormManager);
    70     $this->FileDownloadURL = 'File.php';
     70    $this->FileDownloadURL = 'file';
    7171    $this->DirectoryId = null;
    7272  }
     
    7575  {
    7676    $File = &$Item['Value'];
    77     return('<a href="'.$this->FileDownloadURL.'?Id='.$File->Id.'">'.
     77    return('<a href="'.$this->FileDownloadURL.'?id='.$File->Id.'">'.
    7878      $File.'</a> ('.HumanSize($File->Size).')');
    7979  }
  • trunk/Common/Global.php

    r506 r507  
    196196  $System->AddModule(new Bill());
    197197  $System->AddModule(new Finance());
     198  $System->Modules['Finance']->MainSubject = $Config['Finance']['MainSubjectId'];
     199  $System->Modules['Finance']->DirectoryId = $Config['Finance']['DirectoryId'];
    198200  $System->Modules['Finance']->LoadMonthParameters(0);
    199201  RegisterFormClasses($System->FormManager);
  • trunk/Common/Update.php

    r505 r507  
    7676          echo($Query.';<br/>');
    7777          flush();
    78           $this->Database->query($Query);
     78          return($this->Database->query($Query));
    7979  }
    8080}
  • trunk/Common/Version.php

    r505 r507  
    11<?php
    22
    3 $Revision = 505; // Subversion revision
    4 $DatabaseRevision = 505;
    5 $ReleaseTime = '2013-03-31';
     3$Revision = 507; // Subversion revision
     4$DatabaseRevision = 507;
     5$ReleaseTime = '2013-04-01';
    66
    77?>
  • trunk/Modules/File/File.php

    r506 r507  
    5454    {
    5555      $DbRow = $DbResult->fetch_assoc();
    56       if(file_exists($this->FilesDir.'/'.$DbRow['Name']))
     56      if($DbRow['Directory'] != '') $FileName = $this->GetDir($DbRow['Directory']);
     57        else $FileName = $this->FilesDir;
     58      $FileName .= $DbRow['Name'];
     59      if(file_exists($FileName))
    5760      {
    58         Header('Content-Type: '.$this->DetectMimeType($this->FilesDir.'/'.$DbRow['Name']));
     61        Header('Content-Type: '.$this->DetectMimeType($FileName));
    5962        Header('Content-Disposition: attachment; filename="'.$DbRow['Name'].'"');
    60         echo(file_get_contents($this->FilesDir.'/'.$DbRow['Name']));
     63        echo(file_get_contents($FileName));
    6164      } else echo('Soubor nenalezen!');
    6265    } else echo('Soubor nenalezen!');
    6366  }
     67 
     68  function GetDir($Id)
     69  {
     70    $DbResult = $this->Database->select('FileDirectory', '*', 'Id='.$Id);
     71    $DbRow = $DbResult->fetch_assoc();
     72    if($DbRow['Parent'] != '') $Result = $this->GetDir($DbRow['Parent']);
     73      else $Result = $this->FilesDir;
     74    $Result .= $DbRow['Name'].'/';
     75    return($Result);
     76  }
    6477}
     78
    6579
    6680class PageFile extends Page
     
    7387  }
    7488}
    75 
    7689
    7790class ModuleFile extends AppModule
     
    105118    $this->System->RegisterPage('file', 'PageFile');
    106119    $File = new File($this->System->Database);
    107     $File->FilesDir = dirname(__FILE__).'/../../'.$Config['Web']['UploadFileFolder'].'/';   
     120    $File->FilesDir = dirname(__FILE__).'/../../'.$Config['Web']['UploadFileFolder'];   
    108121    $this->System->AddModule($File);
    109122  } 
  • trunk/Modules/OpeningHours/OpeningHours.php

    r501 r507  
    187187      if($Subject['Notice'] != '') $Output .= 'Poznámka: '.$Subject['Notice'].'<br />';
    188188     
    189       if($Subject['Photo'] != 0) $Output .= '<a href="FileDownload.php?Id='.$Subject['Photo'].'">Fotka</a> ';
     189      if($Subject['Photo'] != 0) $Output .= '<a href="file?id='.$Subject['Photo'].'">Fotka</a> ';
    190190     
    191191      if($this->System->Modules['User']->CheckPermission('SubjectOpenTime', 'Edit'))
  • trunk/Readme.txt

    r469 r507  
    22========================================
    33
    4 1) Konfigurační soubory
     41) Instalace a nastavení systému
    55
    6   Zkopírovat soubor config.sample.php na config.php a vyplnit údaje.
     6  V prohlížeči otevřete podadresář admin v umístění, ze kterého je web dostupný.
     7  Zde stiskem tlačítka nastavení nastavíte údaje pro připojení do databáze.
     8  Následně stiskem tlačítka Instalovat se nainstalují tabulky do databáze.
    79
    810
     
    1719
    1820  finance/doklady - účetní doklady
    19   aktuality/uploads - přílohy aktualit
     21  files - úložiště souborů
    2022  galerie - fotogalerie obrázků
    2123  files - načtené soubory přes web
     
    2628  files - vlastníka nastavit na apache
    2729  finance/doklady - vlastníka nastavit na apache
    28   aktuality/uploads - vlastníka nastavit na apache
    2930
    3031 
  • trunk/ToDo.txt

    r499 r507  
    2828- Automatické zasílání SMS informací
    2929- Vytvořit modul pro záznam a vykreslování časových grafů
    30 
     30- V modulu News předělat přílohy na odkazy do tabulky File
    3131
    3232Hotové
  • trunk/admin/DefaultConfig.php

    r491 r507  
    2626  array('Name' => 'Web/UserSupport', 'Type' => 'Boolean', 'Default' => '1', 'Title' => 'Podpora uživatelů'),
    2727  array('Name' => 'Web/UploadFileFolder', 'Type' => 'String', 'Default' => 'files', 'Title' => 'Složka načtených souborů'),
    28   array('Name' => 'Web/FileRootPath', 'Type' => 'String', 'Default' => 'finance/doklady', 'Title' => 'Složka generovaných dokladů'),
    2928  array('Name' => 'Web/News/DaysAgo', 'Type' => 'Integer', 'Default' => '30', 'Title' => 'Stáří zobrazovaných aktualit'),
    3029  array('Name' => 'Web/News/Count', 'Type' => 'Integer', 'Default' => '5', 'Title' => 'Počet zobrazovaných aktualit na skupinu'),
     30  array('Name' => 'Web/News/DirectoryId', 'Type' => 'Integer', 'Default' => '1', 'Title' => 'Id adresáře souborů příloh aktualit'),
    3131  array('Name' => 'Web/GoogleMapsApiKey', 'Type' => 'String', 'Default' => '', 'Title' => 'API google map'),
    3232  array('Name' => 'Web/ItemsPerPage', 'Type' => 'Integer', 'Default' => '50', 'Title' => 'Položek na stránku'),
     
    3939  array('Name' => 'Finance/MainUserId', 'Type' => 'Integer', 'Default' => '1', 'Title' => 'Id hlavního uživatele'),
    4040  array('Name' => 'Finance/MainSubjectId', 'Type' => 'Integer', 'Default' => '1', 'Title' => 'Id hlavního subjektu'),
     41  array('Name' => 'Finance/DirectoryId', 'Type' => 'Integer', 'Default' => '1', 'Title' => 'Id adresáře souborů dokladů'),
    4142  array('Name' => 'MainRouter/HostName', 'Type' => 'String', 'Default' => 'localhost', 'Title' => 'Hlavní brána'),
    4243  array('Name' => 'MainRouter/UserName', 'Type' => 'String', 'Default' => 'admin', 'Title' => 'Uživatelské jméno'),
  • trunk/admin/Updates.php

    r505 r507  
    183183  `Message` varchar(255) NOT NULL DEFAULT '',
    184184  PRIMARY KEY (`Id`)
    185 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    186  
     185) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
     186}
     187
     188function UpdateTo507($Manager)
     189{
     190  $Manager->Execute("INSERT INTO `ISMenuItem` (`Id` ,`Name` ,`Parent` ,`Table` ,`IconName`) ".
     191    "VALUES (NULL , 'Aktuality', NULL, '', '');");
     192  $Id = $Manager->Database->insert_id;
     193  $Manager->Execute("INSERT INTO `ISMenuItem` (`Id` ,`Name` ,`Parent` ,`Table` ,`IconName`) ".
     194    "VALUES (NULL , 'Aktuality', '".$Id."', 'News', '');");
     195  $Manager->Execute("INSERT INTO `ISMenuItem` (`Id` ,`Name` ,`Parent` ,`Table` ,`IconName`) ".
     196    "VALUES (NULL , 'Kategorie aktualit', '".$Id."', 'NewsCategory', '');");
     197  $Manager->Execute("INSERT INTO `FileDirectory` (`Id` ,`Name` ,`Parent`".
     198    ") VALUES (NULL , 'news', NULL);");
     199  $Manager->Execute("ALTER TABLE `File` ADD `Time` DATETIME NOT NULL ");
     200  // Convert Hire column to Service item
     201  $Manager->Execute("INSERT INTO `ServiceCategory` (
     202`Id` ,`Name`) VALUES (NULL , 'Pevný nájem');");
     203  $ServiceCategoryHire = $Manager->Database->insert_id; 
     204  $DbResult = $Manager->Execute("SELECT * FROM Member WHERE Hire>0");
     205  while($Member = $DbResult->fetch_assoc())
     206  {
     207    $Manager->Execute("INSERT INTO `Service` (
     208`Id` ,`Name` ,`Category` ,`Price` ,`VAT` ,`CustomerCount` ,`Action` ,`ReplaceId` ,
     209`Public` ,`InternetSpeedMin` ,`InternetSpeedMax` ,`UploadAsymmetry` ,`Memory` ,`MemorySwap` ,`Storage` ,`CPUCount`)
     210VALUES (
     211NULL , 'Nájem', '".$ServiceCategoryHire."', '-".$Member['Hire']."', '2', '', NULL , NULL , '', '', '', '', '', '', '', ''
     212);");
     213    $ServiceHire = $Manager->Database->insert_id; 
     214    $Manager->Execute("INSERT INTO `ServiceCustomerRel` (`Service`, `Customer`) VALUES ".
     215      "(".$ServiceHire.",".$Member['Id'].")");
     216  }
     217  $Manager->Execute("ALTER TABLE `Member` DROP `Hire`");
     218  // Each device and subnet have to be assigned to payed service to determine service parameters
     219  $Manager->Execute("ALTER TABLE `NetworkDevice` ADD `Service` INT NULL AFTER `Location` ,
     220ADD INDEX ( `Service` )");
     221  $Manager->Execute("ALTER TABLE `NetworkDevice` ADD FOREIGN KEY ( `Service` ) REFERENCES `ServiceCustomerRel` (
     222`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT ;");
     223  $Manager->Execute("UPDATE `NetworkDevice` SET `Service` = (SELECT `Id` FROM `ServiceCustomerRel` WHERE `ServiceCustomerRel`.`Customer` = `NetworkDevice`.`Member` LIMIT 1)");
     224  $Manager->Execute("ALTER TABLE `NetworkSubnet` ADD `Service` INT NULL AFTER `Member` ,
     225ADD INDEX ( `Service` ) ");
     226  $Manager->Execute("ALTER TABLE `NetworkSubnet` ADD FOREIGN KEY ( `Service` ) REFERENCES `ServiceCustomerRel` (
     227`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT ;");
     228  $Manager->Execute("UPDATE `NetworkSubnet` SET `Service` = (SELECT `Id` FROM `ServiceCustomerRel` WHERE `ServiceCustomerRel`.`Customer` = `NetworkSubnet`.`Member` LIMIT 1)");
    187229}
    188230
     
    197239  500 => array('Revision' => 502, 'Function' => 'UpdateTo502'),
    198240  502 => array('Revision' => 505, 'Function' => 'UpdateTo505'),
     241  505 => array('Revision' => 507, 'Function' => 'UpdateTo507'),
    199242);
    200243
  • trunk/finance/finance.php

    r497 r507  
    2626  var $Tariffs;
    2727  var $ExternalSubject = 96;
    28   var $MainSubject = 71;
     28  var $MainSubject;
    2929  var $BillingPeriods;
     30  var $DirectoryId;
    3031 
    3132  function LoadTariffs()
     
    3536    while($Tariff = $DbResult->fetch_array())
    3637    {
    37       $Tariff['InternetSpeedMin'] = $Tariff['InternetSpeedMin'] * 1024;
    38       $Tariff['InternetSpeedMax'] = $Tariff['InternetSpeedMax'] * 1024;
     38      $Tariff['InternetSpeedMin'] = $Tariff['InternetSpeedMin'] * 1000;
     39      $Tariff['InternetSpeedMax'] = $Tariff['InternetSpeedMax'] * 1000;
    3940      $this->Tariffs[$Tariff['Id']] = $Tariff;
    4041    } 
     
    4344  function RecalculateTariffs()
    4445  {
    45     $ResidualSpeed = $this->MaxSpeed * 1024;
     46    $ResidualSpeed = $this->MaxSpeed * 1000;
    4647 
    4748    $this->LoadTariffs();
     
    9293      }
    9394      $this->Database->update('Service', 'Id='.$Tariff['Id'],
    94         array('InternetSpeedMin' => ($Tariff['InternetSpeedMin'] / 1024),
     95        array('InternetSpeedMin' => ($Tariff['InternetSpeedMin'] / 1000),
    9596        'CustomerCount' => $Tariff['CustomerCount']));
    9697    }
     
    211212        else $MonthlyInet = 0;
    212213     
    213       //if($Row['inet'] == 1)
    214214      $Monthly += $MonthlyInet;
    215215      $Monthly -= $this->W2Kc($ConsumptionPlus);
    216       $Monthly -= $Member['Hire'];
    217       //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption);
    218216      $Monthly = round($Monthly);
    219217     
  • trunk/finance/manage.php

    r505 r507  
    381381      }
    382382      $Period = $this->GetBillingPeriod($Member['BillingPeriod']);
    383       if(($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']) and
    384           ($Member['Blocked'] == 0))
     383      if(($Period['MonthCount'] > 0) and ($Member['Blocked'] == 0) and
     384        ($Period['From'] > $Member['UNIX_TIMESTAMP(Member.BillingPeriodLastDate)']))
    385385      {
    386386        $InvoiceItems = array();
     
    398398          $MonthlyTotal += $Service['Price'];
    399399        }
    400         if($Member['Hire'] != 0)
    401         {
    402           $Output .= '<tr><td>Nájem</td><td>'.(-$Member['Hire']).'</td></tr>';
    403           $MonthlyTotal -= $Member['Hire'];
    404         }
    405400        if($Member['MonthlyPlus'] != 0)
    406401        {
     402          $InvoiceItems[] = array('Description' => 'Spotřeba energie', 'Price' => -$Member['MonthlyPlus'],
     403            'Quantity' => $Period['MonthCount'], 'VAT' => 2);
    407404          $MonthlyTotal -= $Member['MonthlyPlus'];
    408405        }
     
    610607    while($Row = $DbResult->fetch_assoc())
    611608    {
    612       $DbResult2 = $this->Database->insert('File', array('Name' => '', 'Size' => 0));
     609      $DbResult2 = $this->Database->insert('File', array('Name' => '', 'Size' => 0,
     610        'Directory' => $this->System->Modules['Finance']->DirectoryId, 'Time' => 'NOW()'));
    613611      $FileId = $this->Database->insert_id;
    614612      $FileName = 'doklad-'.$FileId.'.pdf';
     
    617615      $Bill->System = &$this->System;
    618616      $Bill->InvoiceId = $Row['Id'];
    619       $FullFileName = $this->System->Modules['File']->FilesDir.$FileName;
     617      $FullFileName = $this->System->Modules['File']->GetDir($this->System->Modules['Finance']->DirectoryId).$FileName;
    620618      $Bill->SaveToFile($FullFileName);
    621       $this->Database->update('File', 'Id='.$FileId, array('Name' => $FileName, 'Size' => filesize($FullFileName)));
    622       $this->Database->update('FinanceInvoice', 'Id='.$Row['Id'], array('File' => $FileId));
    623       $Output .= '.';
     619      if(file_exists($FullFileName))
     620      {
     621        $this->Database->update('File', 'Id='.$FileId, array('Name' => $FileName, 'Size' => filesize($FullFileName)));
     622        $this->Database->update('FinanceInvoice', 'Id='.$Row['Id'], array('File' => $FileId));
     623        $Output .= '.';
     624      } else $Output .= 'Soubor "'.$FullFileName.'" se nepodařilo uložit.';
    624625    }
    625626
  • trunk/finance/tarify.php

    r479 r507  
    2525    {
    2626      $Tariff['Aggregation'] = '1:'.round($Tariff['InternetSpeedMax'] / $Tariff['InternetSpeedMin']);
    27       $Output .= '<tr><td style="color: blue;">'.$Tariff['Name'].'</td><td align="center">'.round($Tariff['InternetSpeedMin'] / 1024).'</td><td align="center" style="color: blue;">'.round($Tariff['InternetSpeedMax'] / 1024).'</td><td align="center">'.$Tariff['Aggregation'].'</td><td align="center">'.$Tariff['CustomerCount'].'</td><td align="center" style="color: blue;">'.$Tariff['Price'].'</td><td align="center">'.$Tariff['CustomerCount'] * $Tariff['Price'].'</td></tr>';
     27      $Output .= '<tr><td style="color: blue;">'.$Tariff['Name'].'</td><td align="center">'.round($Tariff['InternetSpeedMin'] / 1000).'</td><td align="center" style="color: blue;">'.round($Tariff['InternetSpeedMax'] / 1000).'</td><td align="center">'.$Tariff['Aggregation'].'</td><td align="center">'.$Tariff['CustomerCount'].'</td><td align="center" style="color: blue;">'.$Tariff['Price'].'</td><td align="center">'.$Tariff['CustomerCount'] * $Tariff['Price'].'</td></tr>';
    2828      $TotalPrice = $TotalPrice + $Tariff['Price'] * $Tariff['CustomerCount'];
    2929      $TotalMemberCount = $TotalMemberCount + $Tariff['CustomerCount'];
  • trunk/finance/user_state.php

    r499 r507  
    8585      if($Row['Value'] > 0) $Row['Value'] = '+'.$Row['Value'];
    8686      if($Row['BillCode'] == '') $Row['BillCode'] = 'PDF';
    87       if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/FileDownload.php?id='.$Row['File']).'">'.$Row['BillCode'].'</a>';
     87      if($Row['File'] > 0) $Invoice = '<a href="'.$this->System->Link('/file?id='.$Row['File']).'">'.$Row['BillCode'].'</a>';
    8888        else $Invoice = '&nbsp;';
    8989      if($Row['PeriodFrom'] != '') $Period = HumanDate($Row['PeriodFrom']).' - '.HumanDate($Row['PeriodTo']);
     
    118118    }
    119119   
    120     if($Member['Hire'] != 0)
    121     {
    122       $Output .= '<tr><td>Nájem</td><td>'.(-$Member['Hire']).'</td></tr>';
    123       $Total -= $Member['Hire'];
    124     }
    125120    if($Member['MonthlyPlus'] != 0)
    126121    {
  • trunk/finance/zivnost.php

    r486 r507  
    88  var $ShortTitle = 'Daňová evidence';
    99  var $ExternalSubject = 96;
    10   var $MainSubject = 71;
    1110  var $StartEvidence = 0;
    1211
  • trunk/form_classes.php

    r502 r507  
    150150    ),
    151151    'ItemActions' => array(
    152       array('Caption' => 'Stáhnout', 'URL' => '/FileDownload.php?download'),
     152      array('Caption' => 'Stáhnout', 'URL' => '/file?download'),
    153153    ),
    154154  ),
     
    456456      'BillingPeriodLastDate' => array('Type' => 'Date', 'Caption' => 'Datum poslední fakturace', 'Default' => ''),
    457457      'NetworkSegment' => array('Type' => 'TNetworkSegment', 'Caption' => 'Úsek sítě', 'Default' => '', 'Null' => true),
    458       'Hire' => array('Type' => 'Integer', 'Caption' => 'Nájem', 'Default' => '0', 'Suffix' => 'Kč'),
    459458      'Blocked' => array('Type' => 'Boolean', 'Caption' => 'Blokování', 'Default' => '0'),
    460459      'PayDay' => array('Type' => 'Integer', 'Caption' => 'Den placení', 'Default' => '0', 'Suffix' => 'den'),
     
    557556      'Member' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => '0'),
    558557      'Location' => array('Type' => 'TMember', 'Caption' => 'Umístění', 'Default' => '0'),
     558      'Service' => array('Type' => 'TServiceCustomerRel', 'Caption' => 'Služba', 'Default' => '', 'Null' => true),
    559559      'Used' => array('Type' => 'Boolean', 'Caption' => 'Použito', 'Default' => '1'),
    560560      'Online' => array('Type' => 'Boolean', 'Caption' => 'Běží', 'Default' => '0', 'ReadOnly' => true),
     
    810810  'News' => array(
    811811    'Title' => 'Nová aktualita',
    812     'Table' => '',
    813     'SubmitText' => 'Vložit',
     812    'Table' => 'News',
    814813    'Items' => array(
    815814      'Category' => array('Type' => 'TNewsCategory', 'Caption' => 'Kategorie', 'Default' => 0),
    816815      'Title' => array('Type' => 'String', 'Caption' => 'Nadpis', 'Default' => ''),
    817816      'Content' => array('Type' => 'Text', 'Caption' => 'Obsah', 'Default' => ''),
    818       'Enclosure1' => array('Type' => 'File', 'Caption' => 'Přílohy (Max. velikost souboru 1 MB)', 'Default' => ''),
    819       'Enclosure2' => array('Type' => 'File', 'Caption' => '', 'Default' => ''),
    820       'Enclosure3' => array('Type' => 'File', 'Caption' => '', 'Default' => ''),
     817      'Date' => array('Type' => 'Date', 'Caption' => 'Datum', 'Default' => ''),
     818      'Author' => array('Type' => 'String', 'Caption' => 'Autor', 'Default' => ''),
     819      'Enclosure' => array('Type' => 'String', 'Caption' => 'Přílohy', 'Default' => ''),
     820      'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => ''),
     821      'IP' => array('Type' => 'String', 'Caption' => 'IP adresa', 'Default' => '', 'ReadOnly' => true),
     822      'Link' => array('Type' => 'Hyperlink', 'Caption' => 'Odkaz', 'Default' => ''),
     823    ),
     824  ),
     825  'NewsCategory' => array(
     826    'Title' => 'Kategorie aktualit',
     827    'Table' => 'NewsCategory',
     828    'Items' => array(
     829      'Caption' => array('Type' => 'String', 'Caption' => 'Titulek', 'Default' => ''),
     830      'RSS' => array('Type' => 'Hyperlink', 'Caption' => 'Zdroj RSS', 'Default' => ''),
     831      'Permission' => array('Type' => 'Boolean', 'Caption' => 'Veřejné upravitelné', 'Default' => ''),
     832      'Sequence' => array('Type' => 'Integer', 'Caption' => 'Pořadí', 'Default' => ''),
     833      'Group' => array('Type' => 'Integer', 'Caption' => 'Skupina', 'Default' => ''),
    821834    ),
    822835  ),
  • trunk/sql/updates/479.sql

    r486 r507  
    4646-- Transform data from FinanceTariff
    4747INSERT INTO Service (SELECT Id AS Id, Name, `Group` AS Category, Price, MemberCount AS CustomerCount,
    48 ReplaceId, Public, SpeedMax AS InternetSpeedMax, SpeedMin AS InternetSpeedMin,
     48ReplaceId, Public, SpeedMin AS InternetSpeedMin, SpeedMax AS InternetSpeedMax,
    4949UploadAsymmetry, 0 AS Memory, 0 AS MemorySwap, 0 AS Storage, 0 AS CPUCount FROM FinanceTariff);
    5050
    51 INSERT INTO ServiceCustomerRel (SELECT NULL AS Id, InternetTariffCurrentMonth AS Serice, Id AS Customer, 0 AS Period FROM `Member`);
    52 INSERT INTO ServiceCustomerRel (SELECT NULL AS Id, InternetTariffNextMonth AS Serice, Id AS Customer, 1 AS Period FROM `Member`);
     51INSERT INTO ServiceCustomerRel (SELECT NULL AS Id, InternetTariffCurrentMonth AS Service, Id AS Customer, 0 AS Period FROM `Member`);
     52INSERT INTO ServiceCustomerRel (SELECT NULL AS Id, InternetTariffNextMonth AS Service, Id AS Customer, 1 AS Period FROM `Member`);
    5353
    5454ALTER TABLE `Member` DROP FOREIGN KEY `Member_ibfk_25` ;
  • trunk/system/generators/dhcp.php

    r440 r507  
    55include('../routerboard.php');
    66$Path = array('ip', 'dhcp-server', 'lease');
     7$Database = &$System->Database;
    78
    89$Routerboard = new Routerboard();
     
    2021  $DbResult2 = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM `NetworkInterface` LEFT JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE '.
    2122  ' CompareNetworkPrefix(INET_ATON(LocalIP), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].') AND (`MAC` != "00:00:00:00:00:00") ORDER BY `LocalIP`');
    22   //echo($Database->error);
    2323  while($Interface = $DbResult2->fetch_assoc())
    2424  {
  • trunk/system/generators/firewall_filter.php

    r440 r507  
    66include('common.php');
    77$Path = array('ip', 'firewall', 'filter');
     8$Database = &$System->Database;
    89
    910$Routerboard = new Routerboard($Config['MainRouter']['HostName']);
  • trunk/system/generators/firewall_mangle.php

    r440 r507  
    99include('common.php');
    1010$PathFirewall = array('ip', 'firewall', 'mangle');
     11$Database = &$System->Database;
    1112
    1213$Routerboard = new Routerboard();
     
    3334
    3435// Process users
    35 $DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject`');
     36$DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` '.
     37  'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '.
     38  'WHERE `Member`.`Blocked` = 0');
    3639while($Member = $DbResult->fetch_assoc())
    3740{
  • trunk/system/generators/firewall_nat.php

    r440 r507  
    66include('common.php');
    77$Path = array('ip', 'firewall', 'nat');
     8$Database = &$System->Database;
    89
    910$Routerboard = new Routerboard($Config['MainRouter']['HostName']);
     
    3637//$Items[] = array('chain' => 'inet-in', 'dst-address' => '172.16.1.1/30', 'action' => 'accept', 'comment' => 'Local_subnet');
    3738
    38 $DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` JOIN `Subject` ON `Member`.`Subject` = `Subject`.`Id`');
     39$DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` '.
     40  'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '.
     41  'WHERE `Member`.`Blocked` = 0');
    3942while($Member = $DbResult->fetch_assoc())
    4043{
  • trunk/system/generators/generate.php

    r440 r507  
    33if(isset($_SERVER['REMOTE_ADDR'])) die();
    44include('../../Common/Global.php');
     5$Database = &$System->Database;
    56
    67$Now = time();
  • trunk/system/generators/netwatch.php

    r440 r507  
    55include('../routerboard.php');
    66$Path = array('tool', 'netwatch');
     7$Database = &$System->Database;
    78
    89$Routerboard = new Routerboard();
     
    2021  while($Subnet = $DbResult->fetch_assoc())
    2122  {
    22     //print_r($Subnet);
    2323    $I = explode('.', $Subnet['AddressRange']);
    2424    $I = $I[2];
  • trunk/system/generators/netwatch_import.php

    r440 r507  
    77$Path = array('tool', 'netwatch');
    88$Period = 60; // every 60 seconds
     9$Database = &$System->Database;
    910
    1011while(1)
  • trunk/system/generators/queue.php

    r479 r507  
    99include('common.php');
    1010$PathQueue = array('queue', 'tree');
     11$Database = &$System->Database;
    1112
    1213$Routerboard = new Routerboard();
     
    2728$InDivider = 1;
    2829$OutDivider = 1;
    29 $TotalMaxSpeedIn = round($Finance->RealMaxSpeed / $InDivider) * 1024;
    30 $TotalMaxSpeedOut = round($Finance->RealMaxSpeed / $OutDivider) * 1024;
    31 $UsersMaxSpeedIn = round($Finance->MaxSpeed / $InDivider) * 1024;
    32 $UsersMaxSpeedOut = round($Finance->MaxSpeed / $OutDivider) * 1024;
     30$TotalMaxSpeedIn = round($Finance->RealMaxSpeed / $InDivider) * 1000;
     31$TotalMaxSpeedOut = round($Finance->RealMaxSpeed / $OutDivider) * 1000;
     32$UsersMaxSpeedIn = round($Finance->MaxSpeed / $InDivider) * 1000;
     33$UsersMaxSpeedOut = round($Finance->MaxSpeed / $OutDivider) * 1000;
    3334$VoipMaxSpeedIn = $TotalMaxSpeedIn - 136;
    3435$VoipMaxSpeedOut = $TotalMaxSpeedOut - 136;
     
    5556
    5657// Process users
    57 $DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject`');
     58$DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` WHERE `Member`.`Blocked`=0');
    5859while($Member = $DbResult->fetch_assoc())
    5960{
    6061  $Member['Name'] = RouterOSIdent($Member['Name'].'-'.$Member['Id'] );
    6162
    62   echo('Uživatel '.$Member['Name'].': ');
    63   $Tariff = $Finance->Tariffs[$Member['InternetTariffCurrentMonth']];
    64   $SpeedIn = round($Tariff['InternetSpeedMin'] / $InDivider);
    65   $SpeedOut = round($Tariff['InternetSpeedMin'] / $OutDivider);
    66   $UserMaxSpeedIn = round($Tariff['InternetSpeedMax'] / $InDivider);
    67   $UserMaxSpeedOut = round($Tariff['InternetSpeedMax'] / $OutDivider);
    68   $ItemsQueue[] = array('name' => $Member['Name'].'-out', 'limit-at' => $SpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => 'main-out');
    69   $ItemsQueue[] = array('name' => $Member['Name'].'-in', 'limit-at' => $SpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => 'main-in');
     63  echo('Zákazník '.$Member['Name']."\n");
     64  $DbResult4 = $Database->query('SELECT `Service`.*, `ServiceCustomerRel`.`Id` AS `RelId` FROM `ServiceCustomerRel` JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` '.
     65    'WHERE (`ServiceCustomerRel`.`Customer` = '.$Member['Id'].') AND (`ServiceCustomerRel`.`Action` IS NULL)');
     66  while($Service = $DbResult4->fetch_assoc())
     67  {
     68    echo('Služba '.$Service['Name'].': ');
     69    $SpeedIn = round($Service['InternetSpeedMin'] / $InDivider) * 1000;
     70    $SpeedOut = round($Service['InternetSpeedMin'] / $OutDivider) * 1000;
     71    $UserMaxSpeedIn = round($Service['InternetSpeedMax'] / $InDivider) * 1000;
     72    $UserMaxSpeedOut = round($Service['InternetSpeedMax'] / $OutDivider) * 1000;
     73    $ItemsQueue[] = array('name' => $Member['Name'].'-out', 'limit-at' => $SpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => 'main-out');
     74    $ItemsQueue[] = array('name' => $Member['Name'].'-in', 'limit-at' => $SpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => 'main-in');
    7075
    71   $DbResult2 = $Database->select('NetworkDevice', 'COUNT(*)', '(`Used` = 1) AND (`Member`='.$Member['Id'].')');
    72   $Row = $DbResult2->fetch_row();
    73   $HostCount = $Row[0];
    74   if($HostCount > 0)
    75   {
    76     $HostSpeedIn = round($SpeedIn / $HostCount);
    77     $HostSpeedOut = round($SpeedOut / $HostCount);
    78   } else
    79   {
    80     $HostSpeedIn = $SpeedIn;
    81     $HostSpeedOut = $SpeedOut;
     76    $Filter = '(`Used` = 1) AND (`Service` = '.$Service['RelId'].')';
     77    $DbResult2 = $Database->select('NetworkDevice', 'COUNT(*)', $Filter);
     78    $Row = $DbResult2->fetch_row();
     79    $HostCount = $Row[0];
     80    if($HostCount > 0)
     81    {
     82      $HostSpeedIn = round($SpeedIn / $HostCount);
     83      $HostSpeedOut = round($SpeedOut / $HostCount);
     84    } else
     85    {
     86      $HostSpeedIn = $SpeedIn;
     87      $HostSpeedOut = $SpeedOut;
     88    }
     89
     90    $DbResult2 = $Database->select('NetworkDevice', '*', $Filter);
     91    while($Device = $DbResult2->fetch_assoc())
     92    {
     93      $DbResult3 = $Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""');
     94      while($Interface = $DbResult3->fetch_assoc())
     95      {
     96        $Name = $Device['Name'];
     97        if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     98        $Name = RouterOSIdent($Name);
     99        echo($Name.', ');
     100        $IPParts = explode('.', $Interface['LocalIP']);
     101        $Subnet = $IPParts[2];
     102        $PacketMark = GetMarkByComment($Name.'-out');
     103        $ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
     104        $PacketMark = GetMarkByComment($Name.'-in');
     105        $ItemsQueue[] = array('name' => $Name.'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
     106      }
     107    }
     108 
     109    $DbResult2 = $Database->select('NetworkSubnet', '*', '`Service`='.$Service['RelId']);
     110    while($Subnet = $DbResult2->fetch_assoc())
     111    {
     112      $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     113      echo($Subnet['Name'].', ');
     114      $IPParts = explode('.', $Subnet['AddressRange']);
     115      $SubnetNumber = $IPParts[2];
     116      $PacketMark = GetMarkByComment($Subnet['Name'].'-out');
     117      $ItemsQueue[] = array('name' => $Subnet['Name'].'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
     118      $PacketMark = GetMarkByComment($Subnet['Name'].'-in');
     119      $ItemsQueue[] = array('name' => $Subnet['Name'].'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
     120    }
     121    echo("\n");
    82122  }
    83 
    84   $DbResult2 = $Database->select('NetworkDevice', '*', '`Used` = 1 AND `Member` = '.$Member['Id']);
    85   while($Device = $DbResult2->fetch_assoc())
    86   {
    87     $DbResult3 = $Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""');
    88     while($Interface = $DbResult3->fetch_assoc())
    89     {
    90       $Name = $Device['Name'];
    91       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    92       $Name = RouterOSIdent($Name);
    93       echo($Name.', ');
    94       $IPParts = explode('.', $Interface['LocalIP']);
    95       $Subnet = $IPParts[2];
    96       $PacketMark = GetMarkByComment($Name.'-out');
    97       $ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
    98       $PacketMark = GetMarkByComment($Name.'-in');
    99       $ItemsQueue[] = array('name' => $Name.'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
    100     }
    101   }
    102  
    103   $DbResult2 = $Database->select('NetworkSubnet', '*', '`Member`='.$Member['Id']);
    104   while($Subnet = $DbResult2->fetch_assoc())
    105   {
    106     $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
    107     echo($Subnet['Name'].', ');
    108     $IPParts = explode('.', $Subnet['AddressRange']);
    109     $SubnetNumber = $IPParts[2];
    110     $PacketMark = GetMarkByComment($Subnet['Name'].'-out');
    111     $ItemsQueue[] = array('name' => $Subnet['Name'].'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
    112     $PacketMark = GetMarkByComment($Subnet['Name'].'-in');
    113     $ItemsQueue[] = array('name' => $Subnet['Name'].'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
    114   }
    115   echo("\n");
    116123}
    117124
Note: See TracChangeset for help on using the changeset viewer.