[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/settings/ -> validation.php (source)

   1  <?php
   2  //
   3  // SOFTWARE NAME: eZ publish
   4  // SOFTWARE RELEASE: 3.9.0
   5  // BUILD VERSION: 17785
   6  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   7  // SOFTWARE LICENSE: GNU General Public License v2.0
   8  // NOTICE: >
   9  //   This program is free software; you can redistribute it and/or
  10  //   modify it under the terms of version 2.0  of the GNU General
  11  //   Public License as published by the Free Software Foundation.
  12  //
  13  //   This program is distributed in the hope that it will be useful,
  14  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  //   GNU General Public License for more details.
  17  //
  18  //   You should have received a copy of version 2.0 of the GNU General
  19  //   Public License along with this program; if not, write to the Free
  20  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21  //   MA 02110-1301, USA.
  22  //
  23  //
  24  
  25  /*! \file validation.php
  26  */
  27  
  28  function validate( $fields, $type, $spacesAllowed = true )
  29  {
  30      $validationMessage = '';
  31      $fieldContainingError = '';
  32      $validationErrorType = '';
  33      $hasValidationError = false;
  34      $fieldNumber = 0;
  35      foreach( $fields as $fieldName=>$fieldValue )
  36      {
  37          if ( $fieldValue == '' )
  38          {
  39              $validationErrorType = 'empty';
  40              $validationMessage = 'Please specify a value';
  41              $hasValidationError = true;
  42          }
  43  
  44          if ( $spacesAllowed == false )
  45          {
  46              if ( strstr( $fieldValue, " " ) )
  47              {
  48                  $validationErrorType = 'contain_spaces';
  49                  $validationMessage = 'spaces is not allowed, but field contains spaces';
  50                  $hasValidationError = true;
  51              }
  52          }
  53  
  54          if ( !$hasValidationError )
  55          {
  56              switch ( $type[$fieldNumber] )
  57              {
  58                  case 'array':
  59                      break;
  60                  case 'name':
  61                      if ( !preg_match( "/^[A-Za-z0-9]*$/", $fieldValue ) )
  62                      {
  63                          $validationErrorType = 'not_valid_name';
  64                          $validationMessage = 'Name contains illegal characters';
  65                          $hasValidationError = true;
  66                      }
  67                      break;
  68                  case 'string':
  69                      if ( !is_string( $fieldValue ) or
  70                           ( is_string( $fieldValue ) and is_numeric( $fieldValue ) ) )
  71                      {
  72                          $validationErrorType = 'not_string';
  73                          $validationMessage = 'Field is not a string';
  74                          $hasValidationError = true;
  75                      }
  76                      break;
  77                  case 'numeric':
  78                      if ( !is_numeric( $fieldValue ) )
  79                      {
  80                          $validationErrorType = 'not_numeric';
  81                          $validationMessage = 'Field is not a numeric';
  82                          $hasValidationError = true;
  83                      }
  84                      break;
  85              }
  86          }
  87  
  88          if ( $hasValidationError )
  89          {
  90              $fieldContainingError = $fieldName;
  91              break;
  92          }
  93          ++$fieldNumber;
  94      }
  95      return array( 'hasValidationError' => $hasValidationError,
  96                    'fieldContainingError' => $fieldContainingError,
  97                    'type' => $validationErrorType,
  98                    'message' => $validationMessage );
  99  }
 100  
 101  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7