System = $System; $this->Definition = $FormClass; foreach($this->Definition['Items'] as $Index => $Item) { $this->Values[$Index] = ''; } } function ShowTable() { $Output = $this->ShowTableBlock(); return($Output); } function ShowTableBlock($Context = '') { $Table = array( 'Header' => array('Položka', 'Hodnota'), 'Rows' => array(), ); if($Context != '') $Context = $Context.'-'; foreach($this->Definition['Items'] as $Index => $Item) { if($Item['Type'] != 'Hidden') { if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; $Edit = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnView', array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type'])); array_push($Table['Rows'], array($Item['Caption'], $Edit)); } } $Output = '
'.$this->Definition['Title'].'
'.$this->Table($Table, 'WideTable'); return($Output); } function ShowEditForm() { if(!array_key_exists('SubmitText', $this->Definition)) $this->Definition['SubmitText'] = 'Uložit'; $Output = '
'.$this->ShowEditBlock().'
'; return($Output); } function ShowEditBlock($Context = '') { $Table = array( //'Header' => array('Položka', 'Hodnota'), 'Rows' => array(), ); if($Context != '') $Context = $Context.'-'; foreach($this->Definition['Items'] as $Index => $Item) { if($Item['Type'] != 'Hidden') { if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; $Edit = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnEdit', array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type'])); array_push($Table['Rows'], array($Item['Caption'].':', $Edit)); } } $Output = '
'.$this->Definition['Title'].''.$this->Table($Table, 'BasicTable'). '
'; foreach($this->Definition['Items'] as $Index => $Item) if($Item['Type'] == 'Hidden') $Output .= $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnEdit', array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type'])); return($Output); } function LoadValuesFromDatabase($Id) { $DbResult = $this->System->Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id); if($DbResult->num_rows > 0) $DbRow = $DbResult->fetch_assoc(); foreach($this->Definition['Items'] as $Index => $Item) { if($Item['Type'] != 'Hidden') if($DbResult->num_rows > 0) $this->Values[$Index] = $DbRow[$Index]; else $this->Values[$Index] = ''; } $this->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0); $this->Values['Id'] = $Id; return($DbResult->num_rows > 0); } function SaveValuesToDatabase($Id) { if($Id == 0) { $this->Values['Id'] = $Id; $DbResult = $this->System->Database->replace($this->Definition['Table'], $this->Values); } else $DbResult = $this->System->Database->update($this->Definition['Table'], 'Id='.$Id, $this->Values); } function LoadValuesFromForm() { $this->Values = $this->LoadValuesFromFormBlock(); } function LoadValuesFromFormBlock($Context = '') { if($Context != '') $Context = $Context.'-'; $Values = array(); foreach($this->Definition['Items'] as $Index => $Item) { if(array_key_exists($Context.$Index, $_POST)) $Values[$Index] = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnLoad', array('Name' => $Index, 'Type' => $Item['Type'])); } return($Values); } }