Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

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

    r872 r873  
    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))
     69    if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     70    {
     71      if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    7272        $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]);
    73       if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     73      if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    7474        $UseType = 'OneToMany';
    75       else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     75      else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    7676        $UseType = 'Enumeration';
    7777    } else $UseType = $Item['Type'];
     
    8888      'Rows' => array(),
    8989    );
    90     foreach($this->Definition['Items'] as $Index => $Item)
    91     if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
    92     if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     90    foreach ($this->Definition['Items'] as $Index => $Item)
     91    if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
     92    if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    9393    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    9494    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    9595    {
    96       if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    97       {
    98         if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     96      if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     97      {
     98        if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    9999          $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]);
    100         if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     100        if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    101101          $UseType = 'OneToMany';
    102         else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     102        else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    103103          $UseType = 'Enumeration';
    104104      } else $UseType = $Item['Type'];
     
    107107        'Type' => $Item['Type'], 'Values' => $this->Values,
    108108        'Filter' => $this->ValuesFilter[$Index]));
    109       if(array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix'];
    110       if(!$this->FormManager->Type->IsHidden($UseType))
     109      if (array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix'];
     110      if (!$this->FormManager->Type->IsHidden($UseType))
    111111        array_push($Table['Rows'], array($Item['Caption'].':', $Edit));
    112112    }
    113113    $Output = '<fieldset><legend>'.$this->Definition['Title'].'</legend>'.Table($Table).
    114114    '</fieldset>';
    115     return($Output);
     115    return ($Output);
    116116  }
    117117
    118118  function ShowEditForm()
    119119  {
    120     if(!array_key_exists('SubmitText', $this->Definition)) $this->Definition['SubmitText'] = 'Uložit';
     120    if (!array_key_exists('SubmitText', $this->Definition)) $this->Definition['SubmitText'] = 'Uložit';
    121121    $Output = '<form enctype="multipart/form-data" class="Form" action="'.$this->OnSubmit.'" method="post">'.$this->ShowEditBlock().
    122122      '<div><input name="submit" type="submit" value="'.$this->Definition['SubmitText'].'" /> '.
    123123      '<input type="button" value="Zrušit" onclick="location.href=\'?\'"/></div></form>';
    124     return($Output);
     124    return ($Output);
    125125  }
    126126
     
    184184  function LoadValuesFromDatabase($Id)
    185185  {
    186     foreach($this->Definition['Items'] as $Index => $Item)
    187     if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     186    foreach ($this->Definition['Items'] as $Index => $Item)
     187    if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    188188    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    189189    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    190190    {
    191         if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    192         {
    193           if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     191        if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     192        {
     193          if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    194194            $this->FormManager->Type->RegisterType($Item['Type'], '',
    195195              $this->FormManager->FormTypes[$Item['Type']]);
    196           if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     196          if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    197197            $UseType = 'OneToMany';
    198           else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     198          else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    199199            $UseType = 'Enumeration';
    200200        } else $UseType = $Item['Type'];
    201       if(!array_key_exists('SQL', $Item)) $Item['SQL'] = '';
     201      if (!array_key_exists('SQL', $Item)) $Item['SQL'] = '';
    202202        else $Item['SQL'] = str_replace('#Id', $Id, $Item['SQL']);
    203203      $Columns[] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery',
     
    205205    }
    206206    $Columns = implode(',', $Columns);
    207     if(array_key_exists('SQL', $this->Definition))
     207    if (array_key_exists('SQL', $this->Definition))
    208208      $SourceTable = '('.$this->Definition['SQL'].') AS `TX`';
    209209      else $SourceTable = '`'.$this->Definition['Table'].'` AS `TX`';
    210210    $DbResult = $this->Database->query('SELECT '.$Columns.' FROM '.$SourceTable.' WHERE `TX`.`Id`='.$Id);
    211211    $DbRow = $DbResult->fetch_array();
    212     foreach($this->Definition['Items'] as $Index => $Item)
    213     if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     212    foreach ($this->Definition['Items'] as $Index => $Item)
     213    if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    214214    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    215215    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    216216    {
    217         if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    218         {
    219           if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     217        if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     218        {
     219          if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    220220            $this->FormManager->Type->RegisterType($Item['Type'], '',
    221221              $this->FormManager->FormTypes[$Item['Type']]);
    222           if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     222          if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    223223            $UseType = 'OneToMany';
    224           else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     224          else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    225225            $UseType = 'Enumeration';
    226226        } else $UseType = $Item['Type'];
     
    235235  {
    236236    $Values = array();
    237     foreach($this->Definition['Items'] as $Index => $Item)
    238     {
    239       if(array_key_exists($Index, $this->Values))
    240       if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     237    foreach ($this->Definition['Items'] as $Index => $Item)
     238    {
     239      if (array_key_exists($Index, $this->Values))
     240      if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    241241      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    242242      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     
    245245          'Type' => $Item['Type'], 'Values' => $this->Values);
    246246
    247         if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    248         {
    249           if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     247        if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     248        {
     249          if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    250250            $this->FormManager->Type->RegisterType($Item['Type'], '',
    251251              $this->FormManager->FormTypes[$Item['Type']]);
    252           if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     252          if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    253253          {
    254254            $UseType = 'OneToMany';
    255255          }
    256           else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     256          else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    257257            $UseType = 'Enumeration';
    258258        } else $UseType = $Item['Type'];
    259259        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);
    260         if(($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]);
    261       }
    262     }
    263     if($Id == 0)
     260        if (($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]);
     261      }
     262    }
     263    if ($Id == 0)
    264264    {
    265265      $Values['Id'] = $Id;
     
    316316      }
    317317    }
    318     return($Values);
     318    return ($Values);
    319319  }
    320320
     
    322322  {
    323323    $Valid = true;
    324     foreach($this->Definition['Items'] as $Index => $Item)
    325     if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     324    foreach ($this->Definition['Items'] as $Index => $Item)
     325    if ((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    326326    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    327327    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
     
    330330    ($Item['ReadOnly'] != true))))
    331331    {
    332         //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))
     332        //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))
    336336            $this->FormManager->Type->RegisterType($Item['Type'], '',
    337337              $this->FormManager->FormTypes[$Item['Type']]);
    338338          $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type'];
    339           if($CustomType == 'Reference')
     339          if ($CustomType == 'Reference')
    340340            $UseType = 'OneToMany';
    341           else if($CustomType == 'Enumeration')
     341          else if ($CustomType == 'Enumeration')
    342342            $UseType = 'Enumeration';
    343343        } else $UseType = $Item['Type'];
    344344
    345345        $Parameters = array('Value' => $this->Values[$Index]);
    346         if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
     346        if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
    347347          else $Parameters['Null'] = false;
    348         if(!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate',
     348        if (!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate',
    349349          $Parameters)) {
    350350            $this->ValuesValidate[$Index] = true;
     
    352352          }
    353353    }
    354     if($Valid == false) throw new Exception('not validated');
    355     return($Valid);
     354    if ($Valid == false) throw new Exception('not validated');
     355    return ($Valid);
    356356  }
    357357}
     
    360360function MakeLink($Target, $Title)
    361361{
    362   return('<a href="'.$Target.'">'.$Title.'</a>');
     362  return ('<a href="'.$Target.'">'.$Title.'</a>');
    363363}
    364364
     
    366366{
    367367  $Result = '<table class="BasicTable">';
    368   if(array_key_exists('Header', $Table))
     368  if (array_key_exists('Header', $Table))
    369369  {
    370370    $Result .= '<tr>';
    371     foreach($Table['Header'] as $Item)
     371    foreach ($Table['Header'] as $Item)
    372372      $Result .= '<th>'.$Item.'</th>';
    373373    $Result .= '</tr>';
    374374  }
    375   foreach($Table['Rows'] as $Row)
     375  foreach ($Table['Rows'] as $Row)
    376376  {
    377377    $Result .= '<tr>';
    378     foreach($Row as $Index => $Item)
    379     {
    380       if($Index == 0) $Class = ' class="Header"'; else $Class = '';
     378    foreach ($Row as $Index => $Item)
     379    {
     380      if ($Index == 0) $Class = ' class="Header"'; else $Class = '';
    381381      $Result .= '<td'.$Class.' style="width: '.(floor(100 / count($Row))).'%">'.$Item.'</td>';
    382382    }
     
    384384  }
    385385  $Result .= '</table>';
    386   return($Result);
     386  return ($Result);
    387387}
    388388
     
    432432    $this->Database->query('DELETE FROM DataType');
    433433
    434     foreach($this->Type->TypeDefinitionList as $Name => $Type)
     434    foreach ($this->Type->TypeDefinitionList as $Name => $Type)
    435435    {
    436436      $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Name.'"');
    437       if($DbResult->num_rows == 0)
     437      if ($DbResult->num_rows == 0)
    438438      {
    439439        $this->Database->insert('DataType', array('Name' => $Name,
     
    447447    }
    448448
    449     foreach($this->Classes as $Class)
    450     if(!array_key_exists('SQL', $Class) and ($Class['Table'] != ''))
     449    foreach ($this->Classes as $Class)
     450    if (!array_key_exists('SQL', $Class) and ($Class['Table'] != ''))
    451451    {
    452452      $DbResult = $this->Database->query('SELECT * FROM information_schema.tables  WHERE table_schema = "centrala_big"
    453453          AND table_name = "'.$Class['Table'].'" LIMIT 1');
    454       if($DbResult->num_rows == 0) continue;
     454      if ($DbResult->num_rows == 0) continue;
    455455
    456456      echo($Class['Table'].'<br>');
    457457      $Module = 1;
    458458      $DbResult = $this->Database->select('Model', 'Id', 'Name="'.$Class['Table'].'"');
    459       if($DbResult->num_rows == 0)
     459      if ($DbResult->num_rows == 0)
    460460      {
    461461        $this->Database->insert('Model', array('Name' => $Class['Table'], 'Title' => $Class['Title'], 'Module' => $Module));
     
    469469      }
    470470
    471       foreach($Class['Items'] as $Name => $Field)
     471      foreach ($Class['Items'] as $Name => $Field)
    472472      {
    473473        echo($Name.', ');
    474474        $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Field['Type'].'"');
    475         if($DbResult->num_rows > 0)
     475        if ($DbResult->num_rows > 0)
    476476        {
    477477          $DbRow = $DbResult->fetch_assoc();
     
    482482          // Search parent type
    483483          $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Type['Type'].'"');
    484           if($DbResult->num_rows > 0)
     484          if ($DbResult->num_rows > 0)
    485485          {
    486486            $DbRow = $DbResult->fetch_assoc();
     
    494494
    495495        $DbResult = $this->Database->select('ModelField', 'Id', '(Name="'.$Name.'") AND (Model='.$Model.')');
    496         if($DbResult->num_rows == 0)
     496        if ($DbResult->num_rows == 0)
    497497        {
    498498          $this->Database->insert('ModelField', array('Name' => $Name,
Note: See TracChangeset for help on using the changeset viewer.