public static function check(FormChecker_Field &$oField, $params)
 {
     $fields = array(clone $oField);
     if (is_array($params)) {
         foreach ($params as $idx => $fieldName) {
             $tmpField = $oField->getForm()->getField($fieldName);
             if (!is_null($tmpField)) {
                 $fields[] = clone $tmpField;
             }
         }
     } else {
         $tmpField = $oField->getForm()->getField($params);
         if (!is_null($tmpField)) {
             $fields[] = clone $tmpField;
         }
     }
     // on a cloner les objets afin de ne pas lancer d'erreur lors de la phase qui suit
     $rv = false;
     foreach ($fields as $idx => $tmpField) {
         if (FormChecker_Helper_RequiredValue::check($tmpField, null)) {
             $rv = true;
         }
     }
     if ($rv) {
         return true;
     } else {
         $fieldNames = '';
         foreach ($fields as $idx => &$tmpField) {
             $fieldNames .= '"' . $tmpField->getLabel() . '",';
         }
         $fieldNames = substr($fieldNames, 0, strlen($fieldNames) - 1);
         return $oField->raiseError(sprintf('Veuillez remplir au moins un des champs %s', $fieldNames));
     }
 }
Example #2
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     if (is_null($params) || !is_int($params)) {
         throw new Exception('Please provide the maximum length as an integer parameter');
     }
     $oField->setValue(substr($oField->getValue(), 0, $params));
 }
Example #3
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $source = $oField->getForm()->getField($params['source']);
     if (strcmp($source->getValue(), $oField->getValue()) == $params['sign']) {
         return $oField->raiseError($params['error']);
     }
     return true;
 }
Example #4
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     if (!isset($params['pattern'])) {
         throw new Exception('Please provide the "pattern" parameter to the Replace modifier');
     }
     if (!isset($params['replacement'])) {
         throw new Exception('Please provide the "replacement" parameter to the Replace modifier');
     }
     $oField->setValue(preg_replace($params['pattern'], $params['replacement'], $oField->getValue()));
 }
Example #5
0
 public static function process(FormChecker_Field &$oField, $params)
 {
     if (!is_array($params)) {
         $oField->raiseError('Les paramètres pour le fichier n\'ont pas été spécifiés');
     }
     if (!isset($params['directory'])) {
         $oField->raiseError('Veuillez indiquer le répertoire de stockage');
     }
     if (!isset($params['filename']) && !isset($params['rename_callback'])) {
         $oField->raiseError('Veuillez indiquer le nom du fichier à stocker ou une callback de renommage');
     }
     if (isset($params['rename_callback']) && !is_callable($params['rename_callback'])) {
         $oField->raiseError('Callback introuvable');
     }
     if (DIRECTORY_SEPARATOR != substr($params['directory'], -1)) {
         $params['directory'] .= DIRECTORY_SEPARATOR;
     }
     $value = $oField->getValue();
     if (!is_array($value)) {
         $oField->raiseError('Wrong value format');
     } else {
         if (!@file_exists($params['directory'])) {
             @mkdir($params['directory']);
         }
         if (isset($params['rename_callback'])) {
             $params['filename'] = call_user_func_array($params['rename_callback'], array($value['name']));
         }
         if (!move_uploaded_file($value['tmp_name'], $params['directory'] . $params['filename'])) {
             return $oField->raiseError('Le fichier n\'a pu être copié');
         }
         $oField->setValue($params['filename']);
     }
 }
Example #6
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $source = $oField->getForm()->getField($params['source']);
     $cmp_sign = 0;
     $source = (int) $source->getValue();
     $field = (int) $oField->getValue();
     if ($source < $field) {
         $cmp_sign = -1;
     } elseif ($source > $field) {
         $cmp_sign = 1;
     }
     if ($cmp_sign !== $params['sign']) {
         return $oField->raiseError($params['error']);
     }
     return true;
 }
Example #7
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $value = $oField->getValue();
     if (is_array($value)) {
         $rv = self::checkArrayNonEmpty($value);
     } else {
         $rv = mb_strlen($value) > 0;
     }
     if (!$rv) {
         if (isset($params['error'])) {
             return $oField->raiseError($params['error']);
         } else {
             return $oField->raiseError(sprintf('Veuillez remplir le champ "%s"', $oField->getLabel()));
         }
     }
     return true;
 }
Example #8
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     if (!isset($params['char'])) {
         throw new Exception('Please provide the "char" parameter to the Pad modifier');
     }
     if (!isset($params['len'])) {
         throw new Exception('Please provide the "len" parameter to the Pad modifier');
     }
     $padType = STR_PAD_BOTH;
     if (isset($params['type'])) {
         if ('left' == $params['type']) {
             $padType = STR_PAD_LEFT;
         } elseif ('right' == $params['type']) {
             $padType = STR_PAD_RIGHT;
         }
     }
     $oField->setValue(str_pad($oField->getValue(), $params['len'], $params['char'], $padType));
 }
Example #9
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $value = $oField->getValue();
     if (is_null($value) && !$oField->isRequired()) {
         return true;
     }
     if (!mb_eregi('^[a-z0-9\\._-]+@[a-z0-9\\._-]+$', $value)) {
         //      if ( !mb_eregi( '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $value ) )
         return $oField->raiseError('Votre email n\'est pas correct');
     } else {
         $tmp = explode('@', $value);
         if (!is_array($tmp)) {
             return false;
         } elseif (!dns_check_record($tmp[1], 'MX')) {
             return $oField->raiseError('Votre nom de domaine n\'est pas valide, veuillez vérifier votre saisie');
         }
     }
     return true;
 }
Example #10
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     if (!is_array($params)) {
         return $oField->raiseError('Les clés possibles doivent être fournies via un tableau associatif');
     }
     if (is_null($oField->getValue()) && !$oField->isRequired()) {
         return true;
     }
     if (!array_key_exists($oField->getValue(), $params)) {
         return $oField->raiseError(sprintf('La clé "%s" n\'est pas permise pour le champ "%s"', $oField->getValue(), $oField->getLabel()));
     }
     return true;
 }
Example #11
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $value = $oField->getValue();
     if (is_null($value) && !$oField->isRequired()) {
         return true;
     }
     switch ($params) {
         case 'YYYY-mm-dd':
         case 'Y-m-d':
             $regPattern = '^[0-9]{4}-[0-9]{2}-[0-9]{2}$';
             break;
         case 'jj-mm-aaaa':
         case 'd-m-Y':
             $regPattern = '^[0-9]{2}-[0-9]{2}-[0-9]{4}$';
             break;
     }
     if (!mb_eregi($regPattern, $value)) {
         return $oField->raiseError('Mauvais format de date : ' . $params);
     }
     return true;
 }
 public static function check(FormChecker_Field &$oField, $params)
 {
     if (is_null($oField->getValue()) && !$oField->isRequired()) {
         return true;
     }
     if (!preg_match($params['pattern'], $oField->getValue())) {
         return $oField->raiseError(sprintf($params['error'], $oField->getLabel()));
     }
     return true;
 }
Example #13
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     if (is_array($params) || !isset($params['value'])) {
         return $oField->raiseError('La valeur attendue doit être scalaire');
     }
     if (is_null($oField->getValue()) && !$oField->isRequired()) {
         return true;
     }
     if ($oField->getValue() != $params['value']) {
         $err_msg = isset($params['error']) ? $params['error'] : sprintf('La valeur du champ "%s" n\'est pas valide', $oField->getLabel());
         return $oField->raiseError($err_msg);
     }
     return true;
 }
 public static function check(FormChecker_Field &$oField, $params)
 {
     if (!is_array($params) || !array_key_exists('master', $params)) {
         return $oField->raiseError(sprintf('"%s": RequiredDependency est mal configuré', $oField->getLabel()));
     }
     $master_field =& $oField->getForm()->getField($params['master']);
     if (is_null($master_field)) {
         return $oField->raiseError(sprintf('Le champ "%s" n\'est pas défini pour ce formulaire', $params['master']));
     }
     $master_needed_value = array_key_exists('value', $params) ? $params['value'] : null;
     $rv = !is_null($master_needed_value) ? $master_field->getValue() == $master_needed_value : !is_null($master_field->getValue());
     return $rv ? FormChecker_Helper_RequiredValue::check($oField, null) : true;
 }
Example #15
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $fields = array();
     if (is_array($params)) {
         foreach ($params as $idx => $fieldName) {
             $tmpField = $oField->getForm()->getField($fieldName);
             if (!is_null($tmpField)) {
                 $fields[] =& $tmpField;
             }
         }
     } else {
         $tmpField = $oField->getForm()->getField($params);
         if (!is_null($tmpField)) {
             $fields[] =& $tmpField;
         }
     }
     $rv = true;
     foreach ($fields as $idx => &$tmpField) {
         if ($oField->getValue() != $tmpField->getValue()) {
             $rv = false;
         }
     }
     return !$rv ? $oField->raiseError(sprintf('Le champ "%s" ne correspond pas', $oField->getLabel())) : true;
 }
Example #16
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     $oField->setValue(mb_strtolower($oField->getValue()));
 }
Example #17
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $value = $oField->getValue();
     if (!isset($value['value'])) {
         return $oField->raiseError('Wrong data structure for upload field');
     }
     $newValue = $value['value'];
     $oldValue = isset($value['old']) ? $value['old'] : null;
     // Si on a une ancienne valeur et que rien de nouveau n'a été soumis, on s'arrête là
     if (!is_null($oldValue) && UPLOAD_ERR_NO_FILE & $newValue['error']) {
         return true;
     }
     // Il y a une nouvelle valeur > on vérifie le type mime si nécessaire
     if (!is_null($newValue['tmp_name']) && UPLOAD_ERR_OK == $newValue['error']) {
         if (!is_null($params) && '*' != $params) {
             // On a spécifié des types mimes autorisés
             $allowedTypes = explode(';', $params);
             if (is_null($newValue['type'])) {
                 return $oField->raiseError(sprintf('Le type du fichier pour "%s" n\'a pu être déterminé', $oField->getLabel()));
             } elseif (!in_array($newValue['type'], $allowedTypes)) {
                 return $oField->raiseError(sprintf('[%s] Ce type de fichier n\'est pas autorisé : %s', $oField->getLabel(), $params));
             }
         }
         return true;
     }
     if (UPLOAD_ERR_NO_FILE & $newValue['error']) {
         return !$oField->isRequired() ? true : $oField->raiseError(sprintf('Veuillez remplir le champ "%s"', $oField->getLabel()));
     }
     // Si on est pas encore sortie de la méthode c'est qu'il y a eu un soucis
     // on revérifie la valeur de $newValue[ 'error' ]
     if ((UPLOAD_ERR_INI_SIZE | UPLOAD_ERR_FORM_SIZE) & $newValue['error']) {
         $maxSize = $oField->getForm()->getContext()->getParam('MAX_FILE_SIZE');
         if (is_null($maxSize)) {
             $maxSize = ini_get('upload_max_filesize');
         } elseif (is_numeric($maxSize)) {
             $maxSize .= ' octets';
         }
         return $oField->raiseError(sprintf('Le fichier "%s" est trop volumineux - limite %s', $oField->getLabel(), $maxSize));
     } elseif (UPLOAD_ERR_PARTIAL & $newValue['error']) {
         return $oField->raiseError(sprintf('Le fichier "%s" n\'a pas été entièrement téléchargé', $oField->getLabel()));
     }
     return false;
 }
Example #18
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     $oField->setValue(strip_tags($oField->getValue()));
 }