Ignore:
Timestamp:
Apr 6, 2020, 9:19:50 PM (4 years ago)
Author:
chronos
Message:
  • Fixed: Show DateTime form field type with null value as unchecked checkbox.
  • Fixed: Add form action error for fields with default null value.
  • Added: Show Service form field NetworkSubnet.
  • Modified: Code formatting.
File:
1 edited

Legend:

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

    r747 r871  
    4343  function LoadDefaults()
    4444  {
    45     foreach($this->Definition['Items'] as $Index => $Item)
    46     if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    47     (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    48     ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    49     {
    50       if(!array_key_exists($Index, $this->Values) and isset($Item['Default']))
    51         $this->Values[$Index] = $Item['Default'];
     45    foreach ($this->Definition['Items'] as $Index => $Item)
     46    {
     47      if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     48      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     49      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     50      {
     51        if (!array_key_exists($Index, $this->Values))
     52          $this->Values[$Index] = $Item['Default'];
     53      }
    5254    }
    5355  }
     
    128130      'Rows' => array(),
    129131    );
    130     if($Context != '') $Context = $Context.'-';
    131     foreach($this->Definition['Items'] as $Index => $Item)
    132     {
    133       if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    134     if($Item['ReadOnly'] == false)
    135     if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
    136     if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    137     (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    138     ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    139     {
     132    if ($Context != '') $Context = $Context.'-';
     133    foreach ($this->Definition['Items'] as $Index => $Item)
     134    {
     135      if (!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
     136      if ($Item['ReadOnly'] == false)
     137      if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
     138      if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     139      (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     140      ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     141      {
    140142        $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index,
    141             'Type' => $Item['Type'], 'Values' => $this->Values);
    142         if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
     143          'Type' => $Item['Type'], 'Values' => $this->Values);
     144        if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
    143145          else unset($Parameters['Null']);
    144         if(array_key_exists('OnPreset', $Item)) $Parameters['OnPreset'] = $Item['OnPreset'];
     146        if (array_key_exists('OnPreset', $Item)) $Parameters['OnPreset'] = $Item['OnPreset'];
    145147          else unset($Parameters['OnPreset']);
    146148
    147         if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    148         {
    149           if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     149        if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     150        {
     151          if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    150152            $this->FormManager->Type->RegisterType($Item['Type'], '',
    151153              $this->FormManager->FormTypes[$Item['Type']]);
    152           if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     154          if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    153155          {
    154156            $UseType = 'OneToMany';
    155           } else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     157          } else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    156158            $UseType = 'Enumeration';
    157159        } else $UseType = $Item['Type'];
    158160        $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters);
    159         if(array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix'];
    160 
    161       $Caption = $Item['Caption'].':';
    162       if(array_key_exists($Index, $this->ValuesValidate) and
    163         $this->ValuesValidate[$Index]) {
     161        if (array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix'];
     162
     163        $Caption = $Item['Caption'].':';
     164        if (array_key_exists($Index, $this->ValuesValidate) and
     165          $this->ValuesValidate[$Index])
     166        {
    164167          $Format = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'GetValidationFormat', array());
    165           if($Format != '') $Caption .= '<br/><small>'.$Format.'</small>';
     168          if ($Format != '') $Caption .= '<br/><small>'.$Format.'</small>';
    166169          $Caption = '<span style="color:red;">'.$Caption.'</span>';
    167170        }
    168       if(!$this->FormManager->Type->IsHidden($UseType))
     171        if (!$this->FormManager->Type->IsHidden($UseType))
    169172          array_push($Table['Rows'], array($Caption, $Edit));
    170       else $Hidden .= $Edit;
    171     }
     173        else $Hidden .= $Edit;
     174      }
    172175    }
    173176    $Output = '<fieldset><legend>'.$this->Definition['Title'].'</legend>'.Table($Table).
    174177    $Hidden.'</fieldset>';
    175     return($Output);
     178    return $Output;
    176179  }
    177180
     
    270273  function LoadValuesFromFormBlock($Context = '')
    271274  {
    272     if($Context != '') $Context = $Context.'-';
     275    if ($Context != '') $Context = $Context.'-';
    273276    $Values = array();
     277    foreach ($this->Definition['Items'] as $Index => $Item)
     278    {
     279      if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
     280      {
     281        if ((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     282        (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     283        ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
     284        (!array_key_exists('ReadOnly', $Item) or
     285        (array_key_exists('ReadOnly', $Item) and
     286        ($Item['ReadOnly'] != true))))
     287        {
     288          //if (array_key_exists($Context.$Index, $_POST))
     289          if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     290          {
     291            if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     292              $this->FormManager->Type->RegisterType($Item['Type'], '',
     293                $this->FormManager->FormTypes[$Item['Type']]);
     294            $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type'];
     295            if ($CustomType == 'Reference')
     296              $UseType = 'OneToMany';
     297            else if ($CustomType == 'Enumeration')
     298              $UseType = 'Enumeration';
     299          } else $UseType = $Item['Type'];
     300          $Parameters = array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values);
     301          if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
     302            else unset($Parameters['Null']);
     303          $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad',
     304            $Parameters);
     305        }
     306      } else
     307      {
     308        if (isset($Item['Default'])) {
     309          if (isset($Item['Null']) and ($Item['Null'] == true))
     310            $Values[$Index] = null;
     311          else $Values[$Index] = $Item['Default'];
     312        }
     313      }
     314    }
     315    return($Values);
     316  }
     317
     318  function Validate()
     319  {
     320    $Valid = true;
    274321    foreach($this->Definition['Items'] as $Index => $Item)
    275     if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))
    276     {
    277322    if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    278323    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     
    294339            $UseType = 'Enumeration';
    295340        } else $UseType = $Item['Type'];
    296         $Parameters = array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values);
    297         if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
    298           else unset($Parameters['Null']);
    299         $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad',
    300           $Parameters);
    301     }
    302     } else
    303     {
    304       if(isset($Item['Default'])) {
    305         if(isset($Item['Null']) and ($Item['Null'] == true))
    306           $Values[$Index] = null;
    307         else $Values[$Index] = $Item['Default'];
    308       }
    309     }
    310     return($Values);
    311   }
    312 
    313   function Validate()
    314   {
    315     $Valid = true;
    316     foreach($this->Definition['Items'] as $Index => $Item)
    317     if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    318     (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    319     ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
    320     (!array_key_exists('ReadOnly', $Item) or
    321     (array_key_exists('ReadOnly', $Item) and
    322     ($Item['ReadOnly'] != true))))
    323     {
    324         //if(array_key_exists($Context.$Index, $_POST))
    325         if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
    326         {
    327           if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
    328             $this->FormManager->Type->RegisterType($Item['Type'], '',
    329               $this->FormManager->FormTypes[$Item['Type']]);
    330           $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type'];
    331           if($CustomType == 'Reference')
    332             $UseType = 'OneToMany';
    333           else if($CustomType == 'Enumeration')
    334             $UseType = 'Enumeration';
    335         } else $UseType = $Item['Type'];
    336341
    337342        $Parameters = array('Value' => $this->Values[$Index]);
Note: See TracChangeset for help on using the changeset viewer.