Changeset 605 for trunk/Common/Form


Ignore:
Timestamp:
Dec 8, 2013, 4:38:25 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: Podpora pro ověřování zadaných dat pro IPv4, IPv6 a MAC adresu.
Location:
trunk/Common/Form
Files:
4 edited

Legend:

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

    r581 r605  
    243243    return($Values);
    244244  }
     245
     246  function Validate()
     247  {
     248    $Values = array();
     249    foreach($this->Definition['Items'] as $Index => $Item)
     250    if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     251    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     252    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
     253    (!array_key_exists('ReadOnly', $Item) or
     254    (array_key_exists('ReadOnly', $Item) and
     255    ($Item['ReadOnly'] != true))))
     256    {     
     257        //if(array_key_exists($Context.$Index, $_POST))
     258        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     259        {           
     260          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     261            $this->FormManager->Type->RegisterType($Item['Type'], '',
     262              $this->FormManager->FormTypes[$Item['Type']]);
     263          $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type'];
     264          if($CustomType == 'Reference')
     265            $UseType = 'OneToMany';
     266          else if($CustomType == 'Enumeration')
     267            $UseType = 'Enumeration';
     268        } else $UseType = $Item['Type'];
     269       
     270        $Parameters = array('Value' => $this->Values[$Index]);
     271        if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];
     272          else $Parameters['Null'] = false;
     273        if(!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate',
     274          $Parameters)) throw new Exception('not validated');
     275    }
     276    return($Values);
     277  }
    245278}
     279
    246280
    247281function MakeLink($Target, $Title)
  • trunk/Common/Form/Types/Base.php

    r601 r605  
    6060    return($Output);
    6161  }
     62 
     63  function Validate($Item)
     64  {
     65        return(true);
     66  }
    6267}
  • trunk/Common/Form/Types/IPv4Address.php

    r548 r605  
    2121    return($_POST[$Item['Name']]);
    2222  }
     23 
     24  function Validate($Item)
     25  {
     26        if($Item['Null'] and ($Item['Value'] == '')) return(true);
     27        return(filter_var($Item['Value'], FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV4)));
     28  }
    2329}
  • trunk/Common/Form/Types/Type.php

    r574 r605  
    1919include(dirname(__FILE__).'/GPS.php');
    2020include(dirname(__FILE__).'/IPv4Address.php');
     21include(dirname(__FILE__).'/IPv6Address.php');
    2122include(dirname(__FILE__).'/Color.php');
    2223include(dirname(__FILE__).'/RandomHash.php');
     24include(dirname(__FILE__).'/MacAddress.php');
    2325
    2426class Type
     
    5254      'Color' => array('Name' => 'Color', 'Class' => 'Color', 'ParentType' => '', 'Parameters' => array()),
    5355      'RandomHash' => array('Name' => 'RandomHash', 'Class' => 'RandomHash', 'ParentType' => '', 'Parameters' => array()),
     56      'MacAddress' => array('Name' => 'MacAddress', 'Class' => 'MacAddress', 'ParentType' => '', 'Parameters' => array()),
     57      'IPv6Address' => array('Name' => 'IPv6Address', 'Class' => 'IPv6Address', 'ParentType' => '', 'Parameters' => array()),
    5458    );
    5559  }
Note: See TracChangeset for help on using the changeset viewer.