<?php
    if (!defined("CNCAT_ENGINE")) die();

    function cn_extFieldValidate($field, $value, &$error) {
        GLOBAL $CNCAT;
        $error = "";

        // user defined validators
        switch ($field) {
            /*case "ext_int1":
                if ((int)$value < 0) {
                    $error = $CNCAT["lang"]["validator_ext_int1"];
                }
            break;*/
        }

        // universal validators
        if (!empty($error)) {
            return;
        }
    
        switch ($CNCAT["config"]["extfields"]["items"][$field]["type"]) {
            case 1:
            break;
            case 2:
            break;
            case 3:
                if (cn_strlen($value) > 255) {
                    $error = cn_str_replace(array("%FIELD%", "%LEN%", "%COUNT%"), array($CNCAT["lang"]["extfield_" . $field], 255, cn_strlen($value)), $CNCAT["lang"]["field_to_long"]);
                }
            break;
            case 4:
                if (!preg_match("#^[0-9]{1,2}:[0-9]{1,2} [0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}$#", $value)) {
                    $error = $CNCAT["lang"]["invalid_date_format"];
                }
            break;
            case 5:
                if (cn_strlen($value) > 16777215) {
                    $error = cn_str_replace(array("%FIELD%", "%LEN%"), array($CNCAT["lang"]["extfield_" . $field], 255), $CNCAT["lang"]["field_to_long"]);
                }
            break;
        }
    }
?>
