Ejemplo n.º 1
0
function CCParseValue($ParsingValue, $Format, $DataType, $ErrorClass, $FieldName, $isDBFormat = false)
{
    global $CCSLocales;
    $errors = new clsErrors();
    $varResult = "";
    if (CCCheckValue($ParsingValue, $DataType)) {
        $varResult = $ParsingValue;
    } else {
        if (strlen($ParsingValue)) {
            switch ($DataType) {
                case ccsDate:
                    $DateValidation = true;
                    if (CCValidateDateMask($ParsingValue, $Format)) {
                        $varResult = CCParseDate($ParsingValue, $Format);
                        if (!CCValidateDate($varResult)) {
                            $DateValidation = false;
                            $varResult = "";
                        }
                    } else {
                        $DateValidation = false;
                    }
                    if (!$DateValidation && $ErrorClass->Count() == 0) {
                        if (is_array($Format)) {
                            $FormatString = join("", $Format);
                        } else {
                            $FormatString = $Format;
                        }
                        $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $FormatString)));
                    }
                    break;
                case ccsBoolean:
                    if (CCValidateBoolean($ParsingValue, $Format)) {
                        $varResult = CCParseBoolean($ParsingValue, $Format);
                    } else {
                        if ($ErrorClass->Count() == 0) {
                            if (is_array($Format)) {
                                $FormatString = CCGetBooleanFormat($Format);
                            } else {
                                $FormatString = $Format;
                            }
                            $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $FormatString)));
                        }
                    }
                    break;
                case ccsInteger:
                    if (CCValidateNumber($ParsingValue, $Format, $isDBFormat)) {
                        $varResult = CCParseInteger($ParsingValue, $Format, $isDBFormat);
                    } else {
                        if ($ErrorClass->Count() == 0) {
                            $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $Format)));
                        }
                    }
                    break;
                case ccsFloat:
                    if (CCValidateNumber($ParsingValue, $Format, $isDBFormat)) {
                        $varResult = CCParseFloat($ParsingValue, $Format, $isDBFormat);
                    } else {
                        if ($ErrorClass->Count() == 0) {
                            $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $Format)));
                        }
                    }
                    break;
                case ccsText:
                case ccsMemo:
                    $varResult = strval($ParsingValue);
                    break;
            }
        }
    }
    if (is_string($ErrorClass)) {
        return $varResult;
    } else {
        $ErrorClass->AddErrors($errors);
        return array($varResult, $ErrorClass);
    }
}
Ejemplo n.º 2
0
 function SetText($Text, $RowNumber = "")
 {
     $ControlName = $RowNumber === "" ? $this->Name : $this->Name . "_" . $RowNumber;
     if (CCCheckValue($Text, $this->DataType)) {
         $this->SetValue($Text);
     } else {
         if ($this->ControlType == ccsCheckBox) {
             $RequestParameter = CCGetParam($ControlName);
             if (strlen($Text) && strlen($RequestParameter) && $Text == $RequestParameter) {
                 $this->Value = true;
                 $this->IsNull = false;
             } else {
                 $Value = $this->GetParsedValue($Text);
                 $this->SetValue($Value);
             }
         } else {
             $this->Text = is_null($Text) ? "" : $Text;
             $this->Value = $this->GetParsedValue($this->Text);
             if (is_null($Text)) {
                 $this->Value = "";
                 $this->IsNull = true;
             } else {
                 $this->IsNull = false;
             }
             if (!$this->isInternal) {
                 $this->initialValue = $this->Value;
             }
         }
     }
 }