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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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,
Note: See TracChangeset for help on using the changeset viewer.