Changeset 922


Ignore:
Timestamp:
Feb 28, 2022, 8:53:22 AM (2 years ago)
Author:
chronos
Message:
  • Modified: Do not determine form submit from URL but directly from submit variable and filled form variables.
  • Added: Use system config from /etc/isp-central directory if standard config is not available.
  • Modified: Form file code cleanup. FormManager class moved to separate file.
Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Core.php

    r915 r922  
    33$ConfigFileName = dirname(__FILE__).'/../Config/Config.php';
    44if (file_exists($ConfigFileName)) include_once($ConfigFileName);
     5else
     6{
     7  $ConfigFileName = '/etc/isp-central/Config.php';
     8  if (file_exists($ConfigFileName)) include_once($ConfigFileName);
     9}
    510
    611include_once(dirname(__FILE__).'/Version.php');
  • trunk/Application/Version.php

    r921 r922  
    11<?php
    22
    3 $Revision = 921; // Subversion revision
     3$Revision = 922; // Subversion revision
    44$DatabaseRevision = 921; // SQL structure revision
    5 $ReleaseTime = strtotime('2022-02-24');
     5$ReleaseTime = strtotime('2022-02-28');
  • trunk/Common/Form/Form.php

    r914 r922  
    22
    33include_once(dirname(__FILE__).'/Types/Type.php');
     4include_once(dirname(__FILE__).'/FormManager.php');
    45
    56/*
     
    1920*/
    2021
    21 
    2222class Form
    2323{
     
    6767  {
    6868    $Item = $this->Definition['Items'][$Index];
    69     if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    70     {
    71       if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    72         $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]);
    73       if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    74         $UseType = 'OneToMany';
    75       else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    76         $UseType = 'Enumeration';
    77     } else $UseType = $Item['Type'];
     69    $UseType = $this->GetItemType($Item);   
    7870    return $this->FormManager->Type->ExecuteTypeEvent($UseType, $Event,
    79         array('Value' => $this->Values[$Index], 'Name' => $Index,
    80         'Type' => $Item['Type'], 'Values' => $this->Values,
    81         'Filter' => $this->Values[$Index]));
     71      array('Value' => $this->Values[$Index], 'Name' => $Index,
     72      'Type' => $Item['Type'], 'Values' => $this->Values,
     73      'Filter' => $this->Values[$Index]));
    8274  }
    8375
     
    9486    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    9587    {
    96       if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    97       {
    98         if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    99           $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]);
    100         if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    101           $UseType = 'OneToMany';
    102         else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    103           $UseType = 'Enumeration';
    104       } else $UseType = $Item['Type'];
     88      $UseType = $this->GetItemType($Item);
    10589      $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
    10690        array('Value' => $this->Values[$Index], 'Name' => $Index,
     
    150134          else unset($Parameters['OnPreset']);
    151135
    152         if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    153         {
    154           if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    155             $this->FormManager->Type->RegisterType($Item['Type'], '',
    156               $this->FormManager->FormTypes[$Item['Type']]);
    157           if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    158           {
    159             $UseType = 'OneToMany';
    160           } else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    161             $UseType = 'Enumeration';
    162         } else $UseType = $Item['Type'];
     136        $UseType = $this->GetItemType($Item);
    163137        $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters);
    164138        if (array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix'];
     
    182156  }
    183157
     158  function GetItemType($Item): string
     159  {   
     160    if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     161    {
     162      if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     163        $this->FormManager->Type->RegisterType($Item['Type'], '',
     164          $this->FormManager->FormTypes[$Item['Type']]);
     165      if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     166        $UseType = 'OneToMany';
     167      else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     168        $UseType = 'Enumeration';
     169    } else $UseType = $Item['Type'];
     170   
     171    return $UseType;
     172  }
     173
    184174  function LoadValuesFromDatabase(string $Id): void
    185175  {
    186176    foreach ($this->Definition['Items'] as $Index => $Item)
    187     if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    188     (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    189     ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    190     {
    191         if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    192         {
    193           if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    194             $this->FormManager->Type->RegisterType($Item['Type'], '',
    195               $this->FormManager->FormTypes[$Item['Type']]);
    196           if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    197             $UseType = 'OneToMany';
    198           else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    199             $UseType = 'Enumeration';
    200         } else $UseType = $Item['Type'];
    201       if (!array_key_exists('SQL', $Item)) $Item['SQL'] = '';
    202         else $Item['SQL'] = str_replace('#Id', $Id, $Item['SQL']);
    203       $Columns[] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery',
    204         array('Name' => $Index, 'Type' => $Item['Type'], 'SQL' => $Item['SQL']));
     177    {
     178      if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     179      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     180      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     181      {     
     182        $UseType = $this->GetItemType($Item);
     183        if (!array_key_exists('SQL', $Item)) $Item['SQL'] = '';
     184          else $Item['SQL'] = str_replace('#Id', $Id, $Item['SQL']);
     185        $Columns[] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery',
     186          array('Name' => $Index, 'Type' => $Item['Type'], 'SQL' => $Item['SQL']));
     187      }
    205188    }
    206189    $Columns = implode(',', $Columns);
     
    211194    $DbRow = $DbResult->fetch_array();
    212195    foreach ($this->Definition['Items'] as $Index => $Item)
    213     if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    214     (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    215     ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    216     {
    217         if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    218         {
    219           if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    220             $this->FormManager->Type->RegisterType($Item['Type'], '',
    221               $this->FormManager->FormTypes[$Item['Type']]);
    222           if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    223             $UseType = 'OneToMany';
    224           else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    225             $UseType = 'Enumeration';
    226         } else $UseType = $Item['Type'];
     196    {
     197      if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     198      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     199      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     200      {
     201        $UseType = $this->GetItemType($Item);     
    227202        $this->Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
    228             array('Value' => $DbRow[$Index], 'Name' => $Index,
    229             'Type' => $Item['Type'], 'Values' => $this->Values));
     203          array('Value' => $DbRow[$Index], 'Name' => $Index,
     204          'Type' => $Item['Type'], 'Values' => $this->Values));
    230205        $this->ValuesFilter[$Index] = $DbRow[$Index.'_Filter'];
     206      }
    231207    }
    232208  }
     
    244220        $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index,
    245221          'Type' => $Item['Type'], 'Values' => $this->Values);
    246 
    247         if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    248         {
    249           if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    250             $this->FormManager->Type->RegisterType($Item['Type'], '',
    251               $this->FormManager->FormTypes[$Item['Type']]);
    252           if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    253           {
    254             $UseType = 'OneToMany';
    255           }
    256           else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    257             $UseType = 'Enumeration';
    258         } else $UseType = $Item['Type'];
     222        $UseType = $this->GetItemType($Item);
    259223        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);
    260224        if (($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]);
     
    264228    {
    265229      $Values['Id'] = $Id;
    266       $DbResult = $this->Database->insert($this->Definition['Table'], $Values);
     230      $this->Database->insert($this->Definition['Table'], $Values);
    267231    } else
    268       $DbResult = $this->Database->update($this->Definition['Table'], 'Id='.$Id, $Values);
     232      $this->Database->update($this->Definition['Table'], 'Id='.$Id, $Values);
     233  }
     234
     235  function HasAllPostVariables(): bool
     236  {
     237    $Result = array_key_exists('submit', $_POST);
     238
     239    foreach ($this->Definition['Items'] as $Index => $Item)
     240    {     
     241      if (!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
     242      if ($Item['ReadOnly'] == false)
     243      if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
     244      if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     245      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     246      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     247      {
     248        $UseType = $this->GetItemType($Item);
     249        if (!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnCanLoad',
     250          array('Value' => $this->Values[$Index], 'Name' => $Index,
     251          'Type' => $Item['Type'], 'Values' => $this->Values,
     252          'Filter' => $this->Values[$Index])))       
     253        {         
     254          $Result = false;
     255          break;
     256        }
     257      }     
     258    }
     259
     260    return $Result;
    269261  }
    270262
     
    290282        {
    291283          //if (array_key_exists($Context.$Index, $_POST))
    292           if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    293           {
    294             if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    295               $this->FormManager->Type->RegisterType($Item['Type'], '',
    296                 $this->FormManager->FormTypes[$Item['Type']]);
    297             $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type'];
    298             if ($CustomType == 'Reference')
    299               $UseType = 'OneToMany';
    300             else if ($CustomType == 'Enumeration')
    301               $UseType = 'Enumeration';
    302           } else $UseType = $Item['Type'];
     284          $UseType = $this->GetItemType($Item);
    303285          $Parameters = array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values);
    304286          if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
     
    309291      } else
    310292      {
    311         if (isset($Item['Default'])) {
     293        if (isset($Item['Default']))
     294        {
    312295          if (isset($Item['Null']) and ($Item['Null'] == true))
    313296            $Values[$Index] = null;
     
    319302  }
    320303
     304  // Check if filled value is in valid form
    321305  function Validate(): bool
    322306  {
    323307    $Valid = true;
    324308    foreach ($this->Definition['Items'] as $Index => $Item)
    325     if ((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    326     (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    327     ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
    328     (!array_key_exists('ReadOnly', $Item) or
    329     (array_key_exists('ReadOnly', $Item) and
    330     ($Item['ReadOnly'] != true))))
    331     {
     309    {
     310      if ((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     311      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     312      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
     313      (!array_key_exists('ReadOnly', $Item) or
     314      (array_key_exists('ReadOnly', $Item) and
     315      ($Item['ReadOnly'] != true))))
     316      {
    332317        //if (array_key_exists($Context.$Index, $_POST))
    333         if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    334         {
    335           if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    336             $this->FormManager->Type->RegisterType($Item['Type'], '',
    337               $this->FormManager->FormTypes[$Item['Type']]);
    338           $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type'];
    339           if ($CustomType == 'Reference')
    340             $UseType = 'OneToMany';
    341           else if ($CustomType == 'Enumeration')
    342             $UseType = 'Enumeration';
    343         } else $UseType = $Item['Type'];
    344 
     318        $UseType = $this->GetItemType($Item);
    345319        $Parameters = array('Value' => $this->Values[$Index]);
    346320        if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
    347321          else $Parameters['Null'] = false;
    348322        if (!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate',
    349           $Parameters)) {
    350             $this->ValuesValidate[$Index] = true;
    351             $Valid = false;
    352           }
    353     }
     323          $Parameters))
     324        {
     325          $this->ValuesValidate[$Index] = true;
     326          $Valid = false;
     327        }
     328      }
     329    }
    354330    if ($Valid == false) throw new Exception('not validated');
    355331    return $Valid;
    356332  }
    357333}
    358 
    359334
    360335function MakeLink(string $Target, string $Title): string
     
    386361  return $Result;
    387362}
    388 
    389 class FormManager
    390 {
    391   public array $Classes;
    392   public array $FormTypes;
    393   public Database $Database;
    394   public Type $Type;
    395   public string $RootURL;
    396   public bool $ShowRelation;
    397 
    398   function __construct(Database $Database)
    399   {
    400     $this->Database = &$Database;
    401     $this->Classes = array();
    402     $this->FormTypes = array();
    403     $this->Type = new Type($this);
    404     $this->ShowRelation = false;
    405   }
    406 
    407   function RegisterClass(string $Name, array $Class): void
    408   {
    409     $this->Classes[$Name] = $Class;
    410   }
    411 
    412   function UnregisterClass(string $Name): void
    413   {
    414     unset($this->Classes[$Name]);
    415   }
    416 
    417   function RegisterFormType(string $Name, array $Class): void
    418   {
    419     $this->FormTypes[$Name] = $Class;
    420   }
    421 
    422   function UnregisterFormType(string $Name): void
    423   {
    424     unset($this->FormTypes[$Name]);
    425   }
    426 
    427   function UpdateSQLMeta(): void
    428   {
    429     $this->Database->query('DELETE FROM ModelField');
    430     $this->Database->query('DELETE FROM Model');
    431     $this->Database->query('DELETE FROM DataType WHERE Parent IS NOT NULL');
    432     $this->Database->query('DELETE FROM DataType');
    433 
    434     foreach ($this->Type->TypeDefinitionList as $Name => $Type)
    435     {
    436       $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Name.'"');
    437       if ($DbResult->num_rows == 0)
    438       {
    439         $this->Database->insert('DataType', array('Name' => $Name,
    440           'Title' => $Type['Class']));
    441       } else
    442       {
    443         $DbRow = $DbResult->fetch_assoc();
    444         $this->Database->update('DataType', 'Id='.$DbRow['Id'], array('Name' => $Name,
    445           'Title' => $Type['Class']));
    446       }
    447     }
    448 
    449     foreach ($this->Classes as $Class)
    450     if (!array_key_exists('SQL', $Class) and ($Class['Table'] != ''))
    451     {
    452       if (!$this->Database->TableExists($Class['Table'])) continue;
    453 
    454       echo($Class['Table'].'<br/>');
    455       $Module = 1;
    456       $DbResult = $this->Database->select('Model', 'Id', 'Name="'.$Class['Table'].'"');
    457       if ($DbResult->num_rows == 0)
    458       {
    459         $this->Database->insert('Model', array('Name' => $Class['Table'], 'Title' => $Class['Title'], 'Module' => $Module));
    460         $Model = $this->Database->insert_id;
    461       } else
    462       {
    463         $DbRow = $DbResult->fetch_assoc();
    464         $Model = $DbRow['Id'];
    465         $this->Database->update('Model', 'Id='.$DbRow['Id'], array('Name' => $Class['Table'],
    466           'Title' => $Class['Title'], 'Module' => $Module));
    467       }
    468 
    469       foreach ($Class['Items'] as $Name => $Field)
    470       {
    471         echo($Name.', ');
    472         $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Field['Type'].'"');
    473         if ($DbResult->num_rows > 0)
    474         {
    475           $DbRow = $DbResult->fetch_assoc();
    476           $Type = $DbRow['Id'];
    477         } else {
    478           $Type = $this->FormTypes[$Field['Type']];
    479 
    480           // Search parent type
    481           $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Type['Type'].'"');
    482           if ($DbResult->num_rows > 0)
    483           {
    484             $DbRow = $DbResult->fetch_assoc();
    485             $ParentType = $DbRow['Id'];
    486           } else $ParentType = null;
    487 
    488           $this->Database->insert('DataType', array('Name' => $Field['Type'],
    489             'Title' => '', 'Parent' => $ParentType));
    490           $Type = $this->Database->insert_id;
    491         }
    492 
    493         $DbResult = $this->Database->select('ModelField', 'Id', '(Name="'.$Name.'") AND (Model='.$Model.')');
    494         if ($DbResult->num_rows == 0)
    495         {
    496           $this->Database->insert('ModelField', array('Name' => $Name,
    497             'Title' => $Field['Caption'], 'Model' => $Model, 'Type' => $Type));
    498         } else
    499         {
    500           $DbRow = $DbResult->fetch_assoc();
    501           $this->Database->update('ModelField', 'Id='.$DbRow['Id'], array('Name' => $Name,
    502             'Title' => $Field['Caption'], 'Model' => $Model, 'Type' => $Type));
    503         }
    504       }
    505       echo('<br/>');
    506     }
    507   }
    508 }
  • trunk/Common/Form/Types/Base.php

    r887 r922  
    2828  {
    2929    return '';
     30  } 
     31
     32  function OnCanLoad(array $Item): bool
     33  {
     34    return array_key_exists($Item['Name'], $_POST);
    3035  }
    31 
     36 
    3237  function OnLoadDb(array $Item): ?string
    3338  {
  • trunk/Common/Form/Types/Boolean.php

    r887 r922  
    2828      else return 0;
    2929  }
     30
     31  function OnCanLoad(array $Item): bool
     32  {
     33    return true;
     34  }
    3035}
  • trunk/Common/Form/Types/Date.php

    r887 r922  
    8282  }
    8383
     84  function OnCanLoad(array $Item): bool
     85  {
     86    return array_key_exists($Item['Name'].'-null', $_POST) or (array_key_exists($Item['Name'].'-day', $_POST) and
     87      array_key_exists($Item['Name'].'-month', $_POST) and array_key_exists($Item['Name'].'-year', $_POST));
     88  }
     89
    8490  function OnLoadDb(array $Item): ?string
    8591  {
  • trunk/Common/Form/Types/DateTime.php

    r887 r922  
    108108  }
    109109
     110  function OnCanLoad(array $Item): bool
     111  {
     112    return array_key_exists($Item['Name'].'-null', $_POST) or (array_key_exists($Item['Name'].'-day', $_POST) and
     113      array_key_exists($Item['Name'].'-month', $_POST) and array_key_exists($Item['Name'].'-year', $_POST) and
     114      array_key_exists($Item['Name'].'-hour', $_POST) and array_key_exists($Item['Name'].'-minute', $_POST) and
     115      array_key_exists($Item['Name'].'-second', $_POST)
     116    );
     117  }
     118
    110119  function OnLoadDb(array $Item): ?string
    111120  {
  • trunk/Common/Form/Types/GPS.php

    r908 r922  
    4747  }
    4848
     49  function OnCanLoad(array $Item): bool
     50  {
     51    return array_key_exists($Item['Name'].'-lat-deg', $_POST) and array_key_exists($Item['Name'].'-lat-sec', $_POST) and
     52    array_key_exists($Item['Name'].'-lat-min', $_POST) and array_key_exists($Item['Name'].'-lon-deg', $_POST) and
     53      array_key_exists($Item['Name'].'-lon-min', $_POST) and array_key_exists($Item['Name'].'-lon-sec', $_POST);
     54  }
     55
     56
    4957  function Explode(float $Float): array
    5058  {
  • trunk/Common/Form/Types/Time.php

    r887 r922  
    8080  }
    8181
     82  function OnCanLoad(array $Item): bool
     83  {
     84    return array_key_exists($Item['Name'].'-null', $_POST) or (array_key_exists($Item['Name'].'-hour', $_POST) and
     85    array_key_exists($Item['Name'].'-minute', $_POST) and array_key_exists($Item['Name'].'-second', $_POST)
     86    );
     87  }
     88
    8289  function OnLoadDb(array $Item): ?string
    8390  {
  • trunk/Modules/IS/IS.php

    r920 r922  
    163163    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    164164      return $this->SystemMessage('Oprávnění', 'Nemáte oprávnění');
    165     if (array_key_exists('o', $_GET))
    166     {
    167       if ($_GET['o'] == 'save')
    168       {
    169         if (!array_key_exists('submit', $_POST))
    170           return $this->SystemMessage('Formulář', 'Formulář nebyl řádně odeslán. Vraťte se zpět a odešlete formulář znovu.');
    171         $Form = new Form($this->System->FormManager);
    172         $Form->SetClass($Table);
    173         $Form->LoadValuesFromForm();
    174         $this->Title .= ' - '.$Form->Definition['Title'].' úprava';
    175         try
    176         {
    177           $Form->Validate();
    178           if (array_key_exists('BeforeModify', $Form->Definition))
    179           {
    180             $Class = $Form->Definition['BeforeModify'][0];
    181             $Method = $Form->Definition['BeforeModify'][1];
    182             $Form->Values = $Class->$Method($Form, $Id);
    183           }
    184           $this->LogChange($Form, 'Edit', $Id, $Id);
    185           $Form->SaveValuesToDatabase($Id);
    186           $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
    187           $Output .= $this->ShowView($Table, $Id);
    188           if (array_key_exists('AfterModify', $Form->Definition))
    189           {
    190             $Class = $Form->Definition['AfterModify'][0];
    191             $Method = $Form->Definition['AfterModify'][1];
    192             $Form->Values = $Class->$Method($Form, $Id);
    193           }
    194         } catch (Exception $E)
    195         {
    196           $Output .= $this->SystemMessage('Úprava položky', 'Položku se nepodařilo uložit. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
    197           $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'].'&amp;o=save';
    198           $Output .= $Form->ShowEditForm();
    199           $Output .= '<ul class="ActionMenu">';
    200           $Output .= '<li>'.$this->ShowAction('Prohlížet', '?a=view&amp;t='.$Table.'&amp;i='.$Id,
    201             $this->System->Link('/images/view.png'));
    202           $Output .= '<li>'.$this->ShowAction('Duplikovat', '?a=clone&amp;t='.$Table.'&amp;i='.$Id,
    203             $this->System->Link('/images/clone.png'));
    204           $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
    205             $this->System->Link('/images/list.png'));
    206           $Output .= '<li>'.$this->ShowAction('Odstranit', '?a=delete&amp;t='.$Table.'&amp;i='.$Id,
    207             $this->System->Link('/images/delete.png'), 'Opravdu smazat položku');
    208           $Output .= '</ul>';
    209          }
     165    $Form = new Form($this->System->FormManager);
     166    $Form->SetClass($Table);   
     167    if ($Form->HasAllPostVariables())
     168    {
     169      $Form->LoadValuesFromForm();
     170      $this->Title .= ' - '.$Form->Definition['Title'].' úprava';
     171      try
     172      {
     173        $Form->Validate();
     174        if (array_key_exists('BeforeModify', $Form->Definition))
     175        {
     176          $Class = $Form->Definition['BeforeModify'][0];
     177          $Method = $Form->Definition['BeforeModify'][1];
     178          $Form->Values = $Class->$Method($Form, $Id);
     179        }
     180        $this->LogChange($Form, 'Edit', $Id, $Id);
     181        $Form->SaveValuesToDatabase($Id);
     182        $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
     183        $Output .= $this->ShowView($Table, $Id);
     184        if (array_key_exists('AfterModify', $Form->Definition))
     185        {
     186          $Class = $Form->Definition['AfterModify'][0];
     187          $Method = $Form->Definition['AfterModify'][1];
     188          $Form->Values = $Class->$Method($Form, $Id);
     189        }
     190      } catch (Exception $E)
     191      {
     192        $Output .= $this->SystemMessage('Úprava položky', 'Položku se nepodařilo uložit. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
     193        $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'];
     194        $Output .= $Form->ShowEditForm();
     195        $Output .= '<ul class="ActionMenu">';
     196        $Output .= '<li>'.$this->ShowAction('Prohlížet', '?a=view&amp;t='.$Table.'&amp;i='.$Id,
     197          $this->System->Link('/images/view.png'));
     198        $Output .= '<li>'.$this->ShowAction('Duplikovat', '?a=clone&amp;t='.$Table.'&amp;i='.$Id,
     199          $this->System->Link('/images/clone.png'));
     200        $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
     201          $this->System->Link('/images/list.png'));
     202        $Output .= '<li>'.$this->ShowAction('Odstranit', '?a=delete&amp;t='.$Table.'&amp;i='.$Id,
     203          $this->System->Link('/images/delete.png'), 'Opravdu smazat položku');
     204        $Output .= '</ul>';
    210205      }
    211206    } else
    212207    {
    213       $Form = new Form($this->System->FormManager);
    214       $Form->SetClass($Table);
    215208      $Form->LoadValuesFromDatabase($Id);
    216209      $this->Title .= ' - '.$Form->Definition['Title'].' úprava';
    217       $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'].'&amp;o=save';
     210      $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'];
    218211      $Output .= $Form->ShowEditForm();
    219212      $Output .= '<ul class="ActionMenu">';
     
    238231    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    239232      return 'Nemáte oprávnění';
    240     if (array_key_exists('o', $_GET))
    241     {
    242       if ($_GET['o'] == 'save')
    243       {
    244         $Form = new Form($this->System->FormManager);
    245         $Form->SetClass($Table);
    246         $Form->LoadValuesFromForm();
    247         $this->Title .= ' - '.$Form->Definition['Title'].' duplikování';
    248         try
    249         {
    250           $Form->Validate();
    251           if (array_key_exists('BeforeInsert', $Form->Definition))
    252           {
    253             $Class = $Form->Definition['BeforeInsert'][0];
    254             $Method = $Form->Definition['BeforeInsert'][1];
    255             $Form->Values = $Class->$Method($Form);
    256           }
    257           $Form->Validate();
    258           $Form->SaveValuesToDatabase(0);
    259           $Id = $this->Database->insert_id;
    260           $this->LogChange($Form, 'Clone', $Id, 0);
    261           $Output .= $this->SystemMessage('Duplikování položky', 'Nová kopie položky vytvořena');
    262           $Output .= $this->ShowView($Table, $Id, $_GET['a'] == 'addsub');
    263           if (array_key_exists('AfterInsert', $Form->Definition))
    264           {
    265             $Class = $Form->Definition['AfterInsert'][0];
    266             $Method = $Form->Definition['AfterInsert'][1];
    267             $Form->Values = $Class->$Method($Form, $Id);
    268           }
    269 
    270         //$this->Database->update($Table, 'Id='.$Id,
    271         //  array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'],
    272         //  'TimeCreate' => 'NOW()'));
    273         } catch (Exception $E)
    274         {
    275           $Output .= $this->SystemMessage('Duplikování položky', 'Položku se nepodařilo duplikovat. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
    276           $Form->OnSubmit = '?a=clone&amp;t='.$Table.'&amp;o=save';
    277           $Output .= $Form->ShowEditForm();
    278           $Actions[] = '<a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
    279             $this->System->Link('/images/list.png').'"/>Seznam</a>';
    280         }
    281       }
    282     } else
     233    $Form = new Form($this->System->FormManager);
     234    $Form->SetClass($Table);
     235    if ($Form->HasAllPostVariables())
    283236    {
    284237      $Form = new Form($this->System->FormManager);
    285238      $Form->SetClass($Table);
     239      $Form->LoadValuesFromForm();
     240      $this->Title .= ' - '.$Form->Definition['Title'].' duplikování';
     241      try
     242      {
     243        $Form->Validate();
     244        if (array_key_exists('BeforeInsert', $Form->Definition))
     245        {
     246          $Class = $Form->Definition['BeforeInsert'][0];
     247          $Method = $Form->Definition['BeforeInsert'][1];
     248          $Form->Values = $Class->$Method($Form);
     249        }
     250        $Form->Validate();
     251        $Form->SaveValuesToDatabase(0);
     252        $Id = $this->Database->insert_id;
     253        $this->LogChange($Form, 'Clone', $Id, 0);
     254        $Output .= $this->SystemMessage('Duplikování položky', 'Nová kopie položky vytvořena');
     255        $Output .= $this->ShowView($Table, $Id, $_GET['a'] == 'addsub');
     256        if (array_key_exists('AfterInsert', $Form->Definition))
     257        {
     258          $Class = $Form->Definition['AfterInsert'][0];
     259          $Method = $Form->Definition['AfterInsert'][1];
     260          $Form->Values = $Class->$Method($Form, $Id);
     261        }
     262
     263      //$this->Database->update($Table, 'Id='.$Id,
     264      //  array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'],
     265      //  'TimeCreate' => 'NOW()'));
     266      } catch (Exception $E)
     267      {
     268        $Output .= $this->SystemMessage('Duplikování položky', 'Položku se nepodařilo duplikovat. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
     269        $Form->OnSubmit = '?a=clone&amp;t='.$Table;
     270        $Output .= $Form->ShowEditForm();
     271        $Actions[] = '<a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
     272          $this->System->Link('/images/list.png').'"/>Seznam</a>';
     273      }
     274    } else
     275    {
    286276      $Form->LoadValuesFromDatabase($Id);
    287277      $this->Title .= ' - '.$Form->Definition['Title'].' duplikování';
    288       $Form->OnSubmit = '?a='.$_GET['a'].'&amp;t='.$Table.'&amp;o=save';
     278      $Form->OnSubmit = '?a='.$_GET['a'].'&amp;t='.$Table;
    289279      $Output .= $Form->ShowEditForm();
    290280      $Actions[] = $this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
     
    347337    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    348338      return 'Nemáte oprávnění';
    349     if (array_key_exists('o', $_GET))
    350     {
    351       if ($_GET['o'] == 'save')
    352       {
    353         $Form = new Form($this->System->FormManager);
    354         $Form->SetClass($Table);
    355         $Form->LoadValuesFromForm();
    356         $this->Title .= ' - '.$Form->Definition['Title'].' přidání';
    357         try
    358         {
    359           $Form->Validate();
    360           if (array_key_exists('BeforeInsert', $Form->Definition))
    361           {
    362             $Class = $Form->Definition['BeforeInsert'][0];
    363             $Method = $Form->Definition['BeforeInsert'][1];
    364             $Form->Values = $Class->$Method($Form);
    365           }
    366           $Form->Validate();
    367           $Form->SaveValuesToDatabase(0);
    368           $Id = $this->Database->insert_id;
    369           $this->LogChange($Form, 'Add', $Id, 0);
    370           $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
    371           $Output .= $this->ShowView($Table, $Id, $_GET['a'] == 'addsub');
    372           if (array_key_exists('AfterInsert', $Form->Definition))
    373           {
    374             $Class = $Form->Definition['AfterInsert'][0];
    375             $Method = $Form->Definition['AfterInsert'][1];
    376             $Form->Values = $Class->$Method($Form, $Id);
    377           }
    378           // Add action to update caller form
    379           if ($_GET['a'] == 'addsub')
    380           {
    381             $Type = $this->System->FormManager->FormTypes[$_GET['rt']];
    382             $DbResult = $this->Database->select($Table, '('.$Type['Name'].') AS Name', 'Id='.$Id);
    383             $DbRow = $DbResult->fetch_assoc();
    384             $Actions[] = '<a href="javascript:window.close();" onclick="add_select_item('.$Id.',&quot;'.$DbRow['Name'].'&quot;,&quot;'.
    385               $_GET['r'].'&quot;); set_return ('.$Id.',&quot;'.
    386               $_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
    387               $this->System->Link('/images/select.png').'"/> Vybrat</a>';
    388           }
    389 
    390         //$this->Database->update($Table, 'Id='.$Id,
    391         //  array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'],
    392         //  'TimeCreate' => 'NOW()'));
    393         } catch (Exception $E)
    394         {
    395           $Output .= $this->SystemMessage('Přidání položky', 'Položku se nepodařilo přidat. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
    396           $Form->OnSubmit = '?a=add&amp;t='.$Table.'&amp;o=save';
    397           $Output .= $Form->ShowEditForm();
    398           $Actions[] = '<a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
    399             $this->System->Link('/images/list.png').'"/>Seznam</a>';
    400         }
     339    $Form = new Form($this->System->FormManager);
     340    $Form->SetClass($Table);
     341    if ($Form->HasAllPostVariables())
     342    {
     343      $Form->LoadValuesFromForm();
     344      $this->Title .= ' - '.$Form->Definition['Title'].' přidání';
     345      try
     346      {
     347        $Form->Validate();
     348        if (array_key_exists('BeforeInsert', $Form->Definition))
     349        {
     350          $Class = $Form->Definition['BeforeInsert'][0];
     351          $Method = $Form->Definition['BeforeInsert'][1];
     352          $Form->Values = $Class->$Method($Form);
     353        }
     354        $Form->Validate();
     355        $Form->SaveValuesToDatabase(0);
     356        $Id = $this->Database->insert_id;
     357        $this->LogChange($Form, 'Add', $Id, 0);
     358        $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
     359        $Output .= $this->ShowView($Table, $Id, $_GET['a'] == 'addsub');
     360        if (array_key_exists('AfterInsert', $Form->Definition))
     361        {
     362          $Class = $Form->Definition['AfterInsert'][0];
     363          $Method = $Form->Definition['AfterInsert'][1];
     364          $Form->Values = $Class->$Method($Form, $Id);
     365        }
     366        // Add action to update caller form
     367        if ($_GET['a'] == 'addsub')
     368        {
     369          $Type = $this->System->FormManager->FormTypes[$_GET['rt']];
     370          $DbResult = $this->Database->select($Table, '('.$Type['Name'].') AS Name', 'Id='.$Id);
     371          $DbRow = $DbResult->fetch_assoc();
     372          $Actions[] = '<a href="javascript:window.close();" onclick="add_select_item('.$Id.',&quot;'.$DbRow['Name'].'&quot;,&quot;'.
     373            $_GET['r'].'&quot;); set_return ('.$Id.',&quot;'.
     374            $_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
     375            $this->System->Link('/images/select.png').'"/> Vybrat</a>';
     376        }
     377
     378      //$this->Database->update($Table, 'Id='.$Id,
     379      //  array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'],
     380      //  'TimeCreate' => 'NOW()'));
     381      } catch (Exception $E)
     382      {
     383        $Output .= $this->SystemMessage('Přidání položky', 'Položku se nepodařilo přidat. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
     384        $Form->OnSubmit = '?a=add&amp;t='.$Table;
     385        $Output .= $Form->ShowEditForm();
     386        $Actions[] = '<a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
     387          $this->System->Link('/images/list.png').'"/>Seznam</a>';
    401388      }
    402389    } else
     
    417404      if (array_key_exists('r', $_GET)) $URL = '&amp;r='.$_GET['r'].'&amp;rt='.$_GET['rt'];
    418405        else $URL = '';
    419       $Form->OnSubmit = '?a='.$_GET['a'].'&amp;t='.$Table.'&amp;o=save'.$URL;
     406      $Form->OnSubmit = '?a='.$_GET['a'].'&amp;t='.$Table.$URL;
    420407      $Output .= $Form->ShowEditForm();
    421408      $Actions[] = $this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
  • trunk/Modules/User/UserModel.php

    r916 r922  
    418418        $Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br />".
    419419        "Po přihlášení si prosím změňte heslo na nové.\n\n<br><br>Na tento email neodpovídejte.", 'text/html');
    420       print_r($Mail);
    421420      $Mail->Send();
    422421
  • trunk/Modules/User/UserPage.php

    r912 r922  
    180180        $Form = new Form($this->System->FormManager);
    181181        $Form->SetClass('PasswordRecovery');
    182         $Form->OnSubmit = '?Action=PasswordRecovery2';
    183         $Output .= $Form->ShowEditForm();
    184       } else
    185       if ($Action == 'PasswordRecovery2')
    186       {
    187         $Form = new Form($this->System->FormManager);
    188         $Form->SetClass('PasswordRecovery');
    189         $Form->LoadValuesFromForm();
    190         $Result = $User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
    191         $Output .= $this->SystemMessage('Obnova hesla', $Result);
    192         if ($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
    193         {
     182        if ($Form->HasAllPostVariables())
     183        {
     184          $Form->LoadValuesFromForm();
     185          $Result = $User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
     186          $Output .= $this->SystemMessage('Obnova hesla', $Result);
     187          if ($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
     188          {
     189            $Output .= $Form->ShowEditForm();
     190          }
     191        } else
     192        {
     193          $Form->OnSubmit = '?Action=PasswordRecovery';
    194194          $Output .= $Form->ShowEditForm();
    195195        }
Note: See TracChangeset for help on using the changeset viewer.