Changeset 78


Ignore:
Timestamp:
Sep 11, 2009, 8:18:38 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Zrušeny samostatné include soubory a správně vloženy přímé závislosti pomocí include_once do všech souborů. Takto se budou načítat jen ty třídy, které jsou skutenčě potřeba.
  • Upraveno: Aplikace se nyní inicializuje přes soubor Application.php, kde je vložena třída odvozená z třídy System. Hlavní soubor index.php se pak odkazuje na soubor aplikace.
  • Objekty Database, Config a Translation jsou nyní lokální v rámci třídy System.
  • Přidáno: Třída pro odesílání pošty. Použita v třídě User.
Location:
trunk/www
Files:
5 added
7 deleted
52 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/Application/Controller/Backup.php

    r73 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class BackupController extends Controller
  • trunk/www/Application/Controller/Client.php

    r72 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class ClientController extends Controller
  • trunk/www/Application/Controller/Cluster.php

    r76 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class ClusterController extends Controller
  • trunk/www/Application/Controller/Debug.php

    r72 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class DebugController extends Controller
  • trunk/www/Application/Controller/Emulator.php

    r72 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class EmulatorController extends Controller
  • trunk/www/Application/Controller/HomePage.php

    r76 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
     4include_once(dirname(__FILE__).'/../View/Page.php');
     5include_once(dirname(__FILE__).'/../View/HomePage.php');
    26
    37class HomePageController extends Controller
  • trunk/www/Application/Controller/News.php

    r72 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class NewsController extends Controller
  • trunk/www/Application/Controller/Realm.php

    r72 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class RealmController extends Controller
  • trunk/www/Application/Controller/Server.php

    r74 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class ServerController extends Controller
  • trunk/www/Application/Controller/Task.php

    r72 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class TaskController extends Controller
     
    68  {
    79    $Page = new PageView($this->System);
    8     $View = new TaskView($this->System);
    9     return($Page->GetOutput($View->ItemList()));
     10    if($this->System->Modules['Permission']->Check('Task', 'ItemList'))
     11    {
     12      $View = new TaskView($this->System);
     13      return($Page->GetOutput($View->ItemList()));
     14    } else return($Page->AccessDenied());
    1015  }   
    1116 
     
    1318  {
    1419    $Page = new PageView($this->System);
    15     $View = new TaskView($this->System);
    16     return($Page->GetOutput($View->ErrorLog()));
     20    if($this->System->Modules['Permission']->Check('Task', 'ErrorLog'))
     21    {
     22      $View = new TaskView($this->System);
     23      return($Page->GetOutput($View->ErrorLog()));
     24    } else return($Page->AccessDenied());
    1725  }   
    1826
     
    2028  {
    2129    $Page = new PageView($this->System);
    22     $View = new TaskView($this->System);
    23     return($Page->GetOutput($View->StandardLog()));
     30    if($this->System->Modules['Permission']->Check('Task', 'StandardLog'))
     31    {
     32      $View = new TaskView($this->System);
     33      return($Page->GetOutput($View->StandardLog()));
     34    } else return($Page->AccessDenied());
    2435  }   
    2536}
  • trunk/www/Application/Controller/Update.php

    r73 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
    24
    35class UpdateController extends Controller
  • trunk/www/Application/Controller/User.php

    r76 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Controller.php');
     4include_once(dirname(__FILE__).'/../View/Page.php');
     5include_once(dirname(__FILE__).'/../View/User.php');
    26
    37class UserController extends Controller
  • trunk/www/Application/Model/Backup.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Backup extends Model
  • trunk/www/Application/Model/Cluster.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Cluster extends Model
  • trunk/www/Application/Model/ClusterList.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class ClusterList extends Model
  • trunk/www/Application/Model/Emulator.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Emulator extends Model
  • trunk/www/Application/Model/History.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class History extends Model
  • trunk/www/Application/Model/Log.php

    r76 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Log extends Model
  • trunk/www/Application/Model/MangosConfigurationFile.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class MangosConfigurationFile extends Model
  • trunk/www/Application/Model/MangosDebug.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class MangosDebug extends Model
  • trunk/www/Application/Model/Permission.php

    r76 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Permission extends Model
  • trunk/www/Application/Model/Platform.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Platform extends Model
  • trunk/www/Application/Model/Realm.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Realm extends Model
  • trunk/www/Application/Model/Server.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Server extends Model
  • trunk/www/Application/Model/Shell.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Shell extends Model
  • trunk/www/Application/Model/Task.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
    24
    35class Task extends Model
  • trunk/www/Application/Model/User.php

    r75 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/Model.php');
     4include_once(dirname(__FILE__).'/../../Base/Mail.php');
     5include_once(dirname(__FILE__).'/Log.php');
    26
    37class User extends Model
     
    711  var $DefaultRole = 2;
    812  var $OnlineStateTimeout = 600; // in seconds
    9 
    10   var $Roles = array('Unknown', 'Anonymous', 'User', 'Administrator');
    1113
    1214  function PasswordHash($Name, $Password)
     
    3133    $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
    3234    if($Query->num_rows == 0)
    33       $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => $this->Config['Web']['UserAnonymousId'], 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()', 'IpAddress' => GetRemoteAddress(), 'HostName' => gethostbyaddr(GetRemoteAddress()), 'ScriptName' => $_SERVER['PHP_SELF']));
     35      $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => $this->Config['Web']['UserAnonymousId'], 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()', 'IpAddress' => $this->System->GetRemoteAddress(), 'HostName' => gethostbyaddr($this->System->GetRemoteAddress()), 'ScriptName' => $_SERVER['PHP_SELF']));
    3436    //echo($this->Database->LastQuery);
    3537
     
    5153    // Refresh time of last access
    5254    $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('ActivityTime' => 'NOW()'));
    53 
    54     //$this->LoadPermission($this->Data['Role']);
    55 
    56     // Role and permission
    57     //$this->LoadRoles();
    5855  }
    5956
     
    7976          else
    8077          {
    81             $this->Database->insert('User', array('Name' => $Name, 'Login' => $Login, 'Password' => $this->PasswordHash($Login, $Password), 'Email' => $Email, 'RegistrationTime' => 'NOW()', 'Locked' => 1, 'Role' => 2));
     78            $this->Database->insert('User', array('Name' => $Name, 'Login' => $Login, 'Password' => $this->PasswordHash($Login, $Password), 'Email' => $Email, 'RegistrationTime' => 'NOW()', 'Locked' => 1));
    8279            $UserId = $this->Database->insert_id;
    8380           
    84             $Subject = FromUTF8('Registrace nového účtu', 'iso2');
    85             $Message = 'Provedli jste registraci nového účtu na serveru <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder']."/</a>.<br>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br><br>\n\nVáš účet je: ".$Login."\n<br>Pro dokončení registrace klikněte na tento odkaz: ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'</a>.'."\n<br> \n\n<br><br>Na tento email neodpovídejte.";
    86             $AdditionalHeaders = "To: ".$Name." <".$Email.">\n"."From: ".FromUTF8($Config['Web']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8";
    87             mail($Email, $Subject, $Message, $AdditionalHeaders);
     81            $Mail = new Mail();
     82            $Mail->Content = 'Provedli jste registraci nového účtu na serveru <a href="http://'.$this->Config['Web']['Host'].$this->Config['Web']['RootFolder'].'/">http://'.$this->Config['Web']['Host'].$this->Config['Web']['RootFolder']."/</a>.<br>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br><br>\n\nVáš účet je: ".$Login."\n<br>Pro dokončení registrace klikněte na tento odkaz: ".'<a href="http://'.$this->Config['Web']['Host'].$this->Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'">http://'.$this->Config['Web']['Host'].$this->Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'</a>.'."\n<br> \n\n<br><br>Na tento email neodpovídejte.";
     83            $Mail->Subject = 'Registrace nového účtu';
     84            $Mail->RecipientName = $Name;
     85            $Mail->RecipientAddress = $Email;
     86            $Mail->SenderName = $this->Config['Web']['Title'];
     87            $Mail->SenderAddress = 'noreplay@zdechov.net';
     88            $Mail->Send();
     89
    8890            $Result = $this->System->Translate('UserRegistrated');
    8991            $this->System->Modules['Log']->NewRecord('User', 'NewRegistration', $Login);
     
    142144  }
    143145
    144   function LoadRoles()
    145   {
    146     $this->Roles = array();
    147     $DbResult = $this->Database->select('UserRole', '*');
    148     while($DbRow = $DbResult->fetch_array())
    149       $this->Roles[] = $DbRow;
    150   }
    151 
    152   function LoadPermission($Role)
    153   {
    154     $this->Data['Permission'] = array();
    155     $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description` FROM `UserRolePermission` JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` WHERE `UserRolePermission`.`Role` = '.$Role);
    156     if($DbResult->num_rows > 0)
    157     while($DbRow = $DbResult->fetch_array())
    158       $this->Data['Permission'][$DbRow['Operation']] = $DbRow;
    159   }
    160 
    161   function PermissionMatrix()
    162   {
    163     $Result = array();
    164     $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description`, `UserRole`.`Title` FROM `UserRolePermission` LEFT JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` LEFT JOIN `UserRole` ON `UserRole`.`Id` = `UserRolePermission`.`Role`');
    165     while($DbRow = $DbResult->fetch_array())
    166     {
    167       $Value = '';
    168       if($DbRow['Read']) $Value .= 'R';
    169       if($DbRow['Write']) $Value .= 'W';
    170       $Result[$DbRow['Description']][$DbRow['Title']] = $Value;
    171     }
    172     return($Result);
    173   }
    174 
    175   function CheckGroupPermission($GroupId, $OperationId)
    176   {
    177     // Check group-group relation
    178     $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `Type`="Group"');
    179     while($DbRow = $DbResult->fetch_array())
    180     {
    181        if($this->CheckGroupPermission($DbRow['GroupOrOperation'], $OperationId) == true) return(true);
    182     }
    183 
    184     // Check group-operation relation
    185     $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `GroupOrOperation`="'.$OperationId.'" AND `Type`="Operation"');
    186     if($DbResult->num_rows > 0) return(true);
    187     return(false);
    188   }
    189 
    190   function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0)
    191   {
    192   $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
    193     if($DbResult->num_rows > 0)
    194     {
    195       $DbRow = $DbResult->fetch_array();
    196       $OperationId = $DbRow['Id'];
    197 
    198       // Check user-operation relation
    199       $DbResult = $this->Database->select('PermissionUserAssignment', '*', '`User`="'.$this->Data['Id'].'" AND `GroupOrOperation`="'.$OperationId.'" AND `Type`="Operation"');
    200       if($DbResult->num_rows > 0) return(true);
    201 
    202       // Check user-group relation
    203       $DbResult = $this->Database->select('PermissionUserAssignment', 'GroupOrOperation', '`User`="'.$this->Data['Id'].'" AND `Type`="Group"');
    204       while($DbRow = $DbResult->fetch_array())
    205       {
    206          if($this->CheckGroupPermission($DbRow['GroupOrOperation'], $OperationId) == true) return(true);
    207       }
    208       return(false);
    209     } else return(false);
    210   }
    211 
    212146  function PasswordRecoveryRequest($Login, $Email)
    213147  {
    214     global $Config;
    215 
    216148    $DbResult = $this->Database->select('User', 'Login, Name, Id, Email, Password', '`Login`="'.$Login.'" AND `Email`="'.$Email.'"');
    217149    if($DbResult->num_rows > 0)
     
    220152      $NewPassword = substr(sha1(strtoupper($Row['Login'])), 0, 7);
    221153
    222       $Subject = 'Obnova hesla';
    223       $Message = 'Požádali jste o zaslání nového hesla na serveru <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder']."</a>.<br />\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br /><br />\n\nVaše nové heslo k účtu ".$Row['Login']." je: ".$NewPassword."\n<br>Pro aktivaci tohoto hesla klikněte na ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=PasswordRecoveryConfirm&User='.$Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br /> Po přihlášení si prosím změňte heslo na nové.\n\n<br><br>Na tento email neodpovídejte.";
    224       $AdditionalHeaders = "To: ".$Row['Name']." <".$Row['Email'].">\n"."From: ".FromUTF8($Config['Web']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8";
    225       mail($Row['Email'], $Subject, $Message, $AdditionalHeaders);
     154      $Mail = new Mail();
     155      $Mail->Subject = 'Obnova hesla';
     156      $Mail->Content = 'Požádali jste o zaslání nového hesla na serveru <a href="http://'.$this->Config['Web']['Host'].$this->Config['Web']['RootFolder'].'">http://'.$this->Config['Web']['Host'].$this->Config['Web']['RootFolder']."</a>.<br />\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br /><br />\n\nVaše nové heslo k účtu ".$Row['Login']." je: ".$NewPassword."\n<br>Pro aktivaci tohoto hesla klikněte na ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=PasswordRecoveryConfirm&User='.$Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br /> Po přihlášení si prosím změňte heslo na nové.\n\n<br><br>Na tento email neodpovídejte.";
     157      $Mail->RecipientName = $Row['Name'];
     158      $Mail->RecipientAddress = $Row['Email'];
     159      $Mail->SenderName = $this->Config['Web']['Title'];
     160      $Mail->SenderAddress = 'noreplay@zdechov.net';
     161      $Mail->Send();
     162     
    226163      $Output = $this->System->Translate('UserPasswordRecoverySuccess');
    227164      $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'Login='.$Login.',Email='.$Email);
     
    246183    return($Output);
    247184  }
    248  
    249   function ServerCount()
    250   {
    251     $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->Data['Id']);
    252     $DbRow = $DbResult->fetch_row();
    253     return($DbRow[0]);
    254   }
    255 
    256   function RealmCount()
    257   {
    258     $Total = 0;
    259     $DbResult = $this->Database->query('SELECT Id FROM Server WHERE User='.$this->User['Id']);
    260     while($DbRow = $DbResult->fetch_assoc())
    261     {
    262       $Server = new Server($this->Database, $DbRow['Id']);
    263       $Total += $Server->RealmCount();
    264     }
    265     return($Total);   
    266   }
    267185}
    268186
  • trunk/www/Application/View/Backup.php

    r69 r78  
    11<?php
    22
    3 class BackupView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class BackupView extends View
    46{
    57  var $ItemListFormClass = array(
  • trunk/www/Application/View/Client.php

    r77 r78  
    11<?php
    22
    3 class ClientView extends Module
     3include_once(dirname(__FILE__).'/../../Base/Module.php');
     4
     5class ClientView extends View
    46{
    57  var $ItemListFormClass = array(
  • trunk/www/Application/View/Cluster.php

    r76 r78  
    11<?php
    22
    3 class ClusterView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class ClusterView extends View
    46{
    57  var $ItemListFormClass = array(
  • trunk/www/Application/View/Database.php

    r69 r78  
    11<?php
    22
    3 class DatabaseView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class DatabaseView extends View
    46{
    57  function Import()
  • trunk/www/Application/View/Debug.php

    r72 r78  
    11<?php
    22
    3 class DebugView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class DebugView extends View
    46{
    57  var $ItemListFormClass = array(
  • trunk/www/Application/View/Emulator.php

    r77 r78  
    11<?php
    22
    3 class EmulatorView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class EmulatorView extends View
    46{
    57  var $ItemFormClass = array(
  • trunk/www/Application/View/HomePage.php

    r73 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4include_once(dirname(__FILE__).'/../Model/Platform.php');
    25
    36class HomePageView extends View
  • trunk/www/Application/View/News.php

    r72 r78  
    11<?php
    22
    3 class NewsView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class NewsView extends View
    46{
    57  var $ItemFormClass = array(
     
    4345    while($DbRow = $DbResult->fetch_assoc())
    4446    {
    45       $Output .= '<div><strong>'.$DbRow['Title'].'</strong>('.HumanDate($DbRow['Time']).')<br />'.$DbRow['Content'].'</div>';
     47      $Output .= '<div><strong>'.$DbRow['Title'].'</strong>('.$DbRow['Time'].')<br />'.$DbRow['Content'].'</div>';
    4648    }
    4749    $Output .= '</td>';
  • trunk/www/Application/View/Page.php

    r77 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4include_once(dirname(__FILE__).'/News.php');
    25
    36class PageView extends View
     
    5659   '<li>Správce: '.$this->Config['Web']['Admin'].'</li>'.
    5760   '<li>E-mail: '.$this->Config['Web']['AdminEmail'].'</li>';
    58     if($this->Config['Web']['ShowRuntimeInfo'] == true) $Output .= '<li>Doba generování: '.$Time.' s / '.ini_get('max_execution_time').' s</li><li>Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B</li>';
     61    if($this->Config['Web']['ShowRuntimeInfo'] == true) $Output .= '<li>Doba generování: '.$Time.' s / '.ini_get('max_execution_time').' s</li><li>Použitá paměť: '.$this->System->AddPrefixMultipliers(memory_get_peak_usage(FALSE), 'B').' / '.ini_get('memory_limit').'B</li>';
    5962  $Output .= '</ul></div></body></html>';
    6063    return($Output);
  • trunk/www/Application/View/Realm.php

    r77 r78  
    11<?php
    22
    3 class RealmView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class RealmView extends View
    46{
    57  var $ItemFormClass = array(
  • trunk/www/Application/View/Server.php

    r77 r78  
    11<?php
    22
    3 class ServerView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class ServerView extends View
    46{
    57  var $ItemFormClass = array(
     
    256258      $Form->LoadValuesFromDatabase($_GET['Id']);
    257259      $Form->Values['ServerId'] = $_GET['Id'];
    258       $Form->OnSubmit = '?Action=ServerSave';
     260      $Form->OnSubmit = '?Module=Server&amp;Action=Save';
    259261      $Output .= $Form->ShowEditForm();
    260262    } else $Output = $this->System->SystemMessage('Nastavení serveru', 'Nemáte oprávnění');
  • trunk/www/Application/View/Task.php

    r72 r78  
    11<?php
    22
    3 class TaskView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class TaskView extends View
    46{
    57  var $ItemListFormClass = array(
     
    2628    global $Config;
    2729   
    28     if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
     30    $Output = '<h4>Fronta úloh</h4>';
     31    $Table = new Table($this->ItemListFormClass);
     32    $Table->OnRow = array($this, 'ShowListOnRow');
     33    $Table->Definition['Table'] = '(SELECT Id, (COALESCE(UNIX_TIMESTAMP(TimeEnd), UNIX_TIMESTAMP(NOW())) - UNIX_TIMESTAMP(TimeStart)) AS Duration, TimeCreate, Title, State FROM Task WHERE User='.$this->System->Modules['User']->User['Id'].' ORDER BY Id DESC)';
     34    $Table->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => '', 'Default' => '');
     35    $Table->LoadValuesFromDatabase($this->Database);
     36    $Table->Definition['Items']['Actions'] = array('Type' => 'String', 'Caption' => '', 'Default' => '');
     37    foreach($Table->Values as $Index => $Item)
    2938    {
    30       $Output = '<h4>Fronta úloh</h4>';
    31       $Table = new Table($this->ItemListFormClass);
    32       $Table->OnRow = array($this, 'ShowListOnRow');
    33       $Table->Definition['Table'] = '(SELECT Id, (COALESCE(UNIX_TIMESTAMP(TimeEnd), UNIX_TIMESTAMP(NOW())) - UNIX_TIMESTAMP(TimeStart)) AS Duration, TimeCreate, Title, State FROM Task WHERE User='.$this->System->Modules['User']->User['Id'].' ORDER BY Id DESC)';
    34       $Table->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => '', 'Default' => '');
    35       $Table->LoadValuesFromDatabase($this->Database);
    36       $Table->Definition['Items']['Actions'] = array('Type' => 'String', 'Caption' => '', 'Default' => '');
    37       foreach($Table->Values as $Index => $Item)
    38       {
    39         $Table->Values[$Index]['Actions'] = '<a href="?Module=Task&amp;Action=ErrorLog&amp;Id='.$Item['Id'].'">Výpis chyb</a> <a href="?Module=Task&amp;Action=StandardLog&amp;Id='.$Item['Id'].'">Výpis výstupu</a> ';
    40         unset($Table->Values[$Index]['Id']);
    41       }
    42       $Output .= $Table->Show();
    43       $Output .= '<br /><div style="text-align: center;"><a href="?Action=TaskList">Obnovit pohled</a></dev>';     
    44     } else $Output = USER_BAD_ROLE;
     39      $Table->Values[$Index]['Actions'] = '<a href="?Module=Task&amp;Action=ErrorLog&amp;Id='.$Item['Id'].'">Výpis chyb</a> <a href="?Module=Task&amp;Action=StandardLog&amp;Id='.$Item['Id'].'">Výpis výstupu</a> ';
     40      unset($Table->Values[$Index]['Id']);
     41    }
     42    $Output .= $Table->Show();
     43    $Output .= '<br /><div style="text-align: center;"><a href="?Action=TaskList">Obnovit pohled</a></dev>';     
    4544    return($Output);
    4645  }
  • trunk/www/Application/View/Update.php

    r69 r78  
    11<?php
    22
    3 class UpdateView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class UpdateView extends View
    46{
    57  function ItemList()
  • trunk/www/Application/View/User.php

    r77 r78  
    11<?php
    22
    3 class UserView extends Module
     3include_once(dirname(__FILE__).'/../../Base/View.php');
     4
     5class UserView extends View
    46{
    57  var $OptionsFormClass = array(
     
    142144  {
    143145    $UserOptions = new Form($this->System, $this->OptionsFormClass);
    144     $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']);
     146    $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->Data['Id']);
    145147    $UserOptions->OnSubmit = '?Module=User&amp;Action=UserOptionsSave';
    146148    $Output = $UserOptions->ShowEditForm();
     
    152154    $UserOptions = new Form($this->System, $this->OptionsFormClass, array());
    153155    $UserOptions->LoadValuesFromForm();
    154     $UserOptions->SaveValuesToDatabase($this->System->Modules['User']->User['Id']);
     156    $UserOptions->SaveValuesToDatabase($this->System->Modules['User']->Data['Id']);
    155157    $Page = new PageView($this->System);
    156158    $Output = $Page->SystemMessage('Nastavení', 'Nastavení uloženo.');
    157159    $this->System->Modules['Log']->NewRecord('User', 'Nastavení uživatele změněno', $UserOptions->Values['Name']);
    158     $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']);
     160    $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->Data['Id']);
    159161    $UserOptions->OnSubmit = '?Module=User&amp;Action=UserOptionsSave';
    160162    $Output .= $UserOptions->ShowEditForm();
  • trunk/www/Base/Controller.php

    r69 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/Model.php');
    24
    35class Controller extends Module
    46{
     7  function Process()
     8  {
     9    if(array_key_exists('Action', $_GET)) $Action = $_GET['Action'];
     10      else $Action = 'Show';
     11    if(method_exists($this, $Action))
     12    {
     13      if($this->System->Modules['Permission']->Check(substr(get_class($this), 0, -10), $Action))
     14        return($this->$Action());
     15        else return('Nemáte oprávnění provést akci '.$Action.' modulu '.substr(get_class($this), 0, -10));
     16    } else return('Metoda '.$Action.' modulu '.get_class($this).' nenalezena.');
     17  }
    518}
    619
  • trunk/www/Base/Form.php

    r71 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/Types/Type.php');
     4include_once(dirname(__FILE__).'/Module.php');
     5include_once(dirname(__FILE__).'/Html.php');
    26
    37class Form extends Module
  • trunk/www/Base/Global.php

    r74 r78  
    66$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
    77
    8 function HumanSize($Value)
    9 {
    10   global $UnitNames;
    11 
    12   $UnitIndex = 0;
    13   while($Value > 1024)
    14   {
    15     $Value = round($Value / 1024, 3);
    16     $UnitIndex++;
    17   }
    18   return($Value.' '.$UnitNames[$UnitIndex]);
    19 }
    20 
    21 function HumanDate($Time)
    22 {
    23   $Date = explode(' ', $Time);
    24   $Parts = explode('-', $Date[0]);
    25   if($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
    26   else return('&nbsp;');
    27 }
    28 
    298function TimeToHumanTime($Value)
    309{
    3110  return(floor($Value / 3600 / 24).' dnů, '.date('H:i:s', $Value - 3600));
    32 }
    33 
    34 function GetRemoteAddress()
    35 {
    36   if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) $IP = $_SERVER['HTTP_X_FORWARDED_FOR'] ;
    37   else if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
    38   else $IP = '0.0.0.0';
    39   return($IP);
    4011}
    4112
  • trunk/www/Base/Model.php

    r69 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/Module.php');
    24
    35class Model extends Module
  • trunk/www/Base/Module.php

    r69 r78  
    1010  {
    1111    $this->Database = $System->Database;
    12     $this->Config = $System->Config;
     12    $this->Config = &$System->Config;
    1313    $this->System = $System;
    1414  }
  • trunk/www/Base/System.php

    r76 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/Database.php');
     4include_once(dirname(__FILE__).'/Form.php');
     5include_once(dirname(__FILE__).'/Table.php');
     6include_once(dirname(__FILE__).'/Error.php');
    27
    38$PrefixMultipliers = array
     
    7984  var $Database;
    8085  var $Config;
     86  var $TimeStart;
     87  var $Translation;
     88 
     89  function __construct()
     90  {
     91    // Change current directory to script location
     92    $BaseDir = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/'));
     93    if($BaseDir != '') chdir($BaseDir);
     94
     95    if(array_key_exists('argv', $_SERVER))
     96      $_GET = array_merge($_GET, ParseCommandLineArgs($_SERVER['argv']));
     97
     98    // SQL injection hack protection
     99    foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
     100    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
     101
     102    if(isset($_SERVER['REMOTE_ADDR'])) session_start();
     103     
     104    $FileName = dirname(__FILE__).'/../Application/Config/Config.php';
     105    if(file_exists($FileName)) include_once($FileName);
     106      else die('Nenalezen soubor '.$FileName.'. Vytvořte jej kopií ze souboru ConfigSample.php umístěném ve stejné složce.');
     107    $this->Config = $Config;
     108   
     109    $FileName = dirname(__FILE__).'/../Application/Localization/'.$Config['Web']['Locale'].'.php';
     110    if(file_exists($FileName)) include_once($FileName);
     111      else die('Nenalezen soubor '.$FileName.'. Buď máte špatně nastaven jazyk nebo vám chybí jazykový soubor.');
     112    $this->Translation = $Translation;
     113
     114    $this->TimeStart = $this->GetMicrotime();
     115    $this->Database = new Database($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']);
     116    $this->Database->Prefix = $this->Config['Database']['Prefix'];
     117    $this->Database->charset($this->Config['Database']['Charset']);   
     118  }
     119 
     120  function Run()
     121  {
     122    if(array_key_exists('Module', $_GET)) $Module = $_GET['Module'];
     123      else $Module = 'HomePage';
     124
     125    $ControllerName = $Module.'Controller';
     126    $FileName = dirname(__FILE__).'/../Application/Controller/'.$Module.'.php';
     127    if(!file_exists($FileName))
     128      echo('Soubor '.$FileName.' nenalezen.');
     129      else include($FileName);
     130    if(class_exists($ControllerName))
     131    {
     132      $Controller = new $ControllerName($this);
     133      echo($Controller->Process());
     134    } else echo('Modul '.$ControllerName.' nenalezen.');
     135  }
    81136
    82137  function ModulePresent($Name)
     
    85140  }
    86141
    87   function AddModule($Module)
    88   {
    89     global $Database;
    90 
    91     //echo('Přidávám modul '.get_class($Module).'<br />');
    92     $this->Modules[get_class($Module)] = $Module;
    93   }
    94  
    95   function AddEmailToQueue($Address, $Subject, $Content, $Headers = '')
    96   {
    97     $this->Database->insert('EmailQueue', array('Address' => $Address, 'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()', 'Headers' => $Headers));
    98   }
    99  
    100   function MailUTF8($To, $Subject = '(No subject)', $Message = '', $Header = '')
    101   {
    102     $Header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n".$Header;
    103     mail($To, '=?UTF-8?B?'.base64_encode($Subject).'?=', $Message, $Header);
    104     //echo('mail('.$To.', =?UTF-8?B?'.base64_encode($Subject).'?=, '.$Message.', '.$Header.')<br/>');
    105   }
    106 
    107   function ProcessEmailQueue()
    108   {
    109     $Output = '';
    110     $DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');
    111     while($DbRow = $DbResult->fetch_assoc())
    112     {     
    113       $this->MailUTF8($DbRow['Address'], $DbRow['Subject'], $DbRow['Content'], $DbRow['Headers']);
    114       //echo('mail('.$DbRow['Address'].', '.$DbRow['Subject'].', '.$DbRow['Content'].', FromUTF8('.$DbRow['Headers'].', \'iso2\'));');
    115       $this->Database->update('EmailQueue', 'Id='.$DbRow['Id'], array('Archive' => 1));
    116       $this->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);
    117       $Output .= 'To: '.$DbRow['Address'].'  Subject: '.$DbRow['Subject'].'<br />';
    118     }   
    119     return($Output);
     142  function AddModule($Name)
     143  {
     144    $this->Modules[$Name] = new $Name($this);
    120145  }
    121146 
     
    189214  function Translate($Text)
    190215  {
    191     global $Translation;
    192 
    193     if(array_key_exists($Text, $Translation)) return($Translation[$Text]);
     216    if(array_key_exists($Text, $this->Translation)) return($this->Translation[$Text]);
    194217      else return('#'.$Text);
    195218  }
     219 
     220  function GetRemoteAddress()
     221  {
     222    if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) $IP = $_SERVER['HTTP_X_FORWARDED_FOR'] ;
     223    else if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
     224    else $IP = '0.0.0.0';
     225    return($IP);
     226  } 
    196227}
    197228
  • trunk/www/Base/Table.php

    r71 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/Types/Type.php');
    24
    35class Table
  • trunk/www/Base/Types/Base.php

    r71 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/../Module.php');
    24
    35class TypeBase extends Module
  • trunk/www/Base/View.php

    r69 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/Module.php');
    24
    35class View extends Module
  • trunk/www/Include.php

    r69 r78  
    11<?php
    22
    3 // Change current directory to script location
    4 $BaseDir = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/'));
    5 if($BaseDir != '') chdir($BaseDir);
    63
    74include('Base/Include.php');
  • trunk/www/index.php

    r77 r78  
    11<?php
    22
    3 include('Include.php');
    4 if(array_key_exists('argv', $_SERVER))
    5   $_GET = array_merge($_GET, ParseCommandLineArgs($_SERVER['argv']));
    6 
    7 // SQL injection hack protection
    8 foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
    9 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
    10 
    11 if(isset($_SERVER['REMOTE_ADDR'])) session_start();
    12 
    13 $System = new System();
    14 $ScriptTimeStart = $System->GetMicrotime();
    15 $System->Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);
    16 $System->Database->Prefix = $Config['Database']['Prefix'];
    17 $System->Database->charset($Config['Database']['Charset']);
    18 $System->Config = $Config;
    19 $System->AddModule(new Log($System));
    20 $System->AddModule(new User($System));
    21 $System->AddModule(new Permission($System));
    22 if(isset($_SERVER['REMOTE_ADDR'])) $System->Modules['User']->Check();
    23   else $System->Modules['User']->Data['Id'] = $Config['Web']['UserConsoleId'];
    24 $System->Modules['Permission']->LoadForUser($System->Modules['User']->Data['Id']);
    25 //print_r($System->Modules['Permission']->Data);
    26 
    27 if(array_key_exists('Module', $_GET)) $Module = $_GET['Module'];
    28   else $Module = 'HomePage';
    29 if(array_key_exists('Action', $_GET)) $Action = $_GET['Action'];
    30   else $Action = 'Show';
    31 
    32 $ControllerName = $Module.'Controller';
    33 if(class_exists($ControllerName))
    34 {
    35   $Controller = new $ControllerName($System);
    36   if(method_exists($Controller, $Action)) $Output = $Controller->$Action();
    37     else $Output = 'Metoda '.$Action.' modulu '.$Module.' neexistuje.';
    38 } else $Output = 'Třída '.$ControllerName.' neexistuje.';
    39 
    40 echo($Output);
     3include_once(dirname(__FILE__).'/Application/Application.php');
    414
    425?>
Note: See TracChangeset for help on using the changeset viewer.