/** * @brief Valida los datos recogidos en el arreglo. * * La estructura de dicho arreglo es: * + Como llave el nombre del campo a validar. * + Como valor un arreglo con los siguientes campos: * - type => Indica el tipo de validacion a ejecutar * - include => En caso de ser una validacion tipo include, el rango a tener en cuenta. * - format => Formato sobre el cual contrarestar * @param array $fields Arreglo de campos a validar. * @return bool */ function runValidations($fields) { jimport('Amadeus.Util.Validation'); $mainframe =& JFactory::getApplication(); $_success = true; foreach ($fields as $key => $config) { $value = JRequest::getVar($key, '', 'POST'); $isValid = true; switch ($config['type']) { case 'integer': $isValid = AmadeusUtilValidation::isInteger($value); break; case 'float': $isValid = AmadeusUtilValidation::isFloat($value); break; case 'format': $isValid = AmadeusUtilValidation::isFormat($value, $config['format']); break; case 'include': $isValid = AmadeusUtilValidation::isOneOfThese($value, $config['include']); break; case 'string': $isValid = AmadeusUtilValidation::isString($value); break; default: } $mandatory = true; if (isset($config['mandatory'])) { $mandatory = $config['mandatory']; } if (!$mandatory && ($value == null || $value == '')) { continue; } if (!$isValid) { $msg = JText::_('ERROR_THE_FIELD'); $msg .= $config['label']; $msg .= JText::_('ERROR_' . strtoupper($config['type'])); $mainframe->enqueueMessage($msg, 'error'); $_success = false; } } return $_success; }