Example #1
0
function ProcessItem($formid, $fvalue, $params, $output_type)
{
    global $TOOL_SHORT;
    $PASS_VALUE = "ok";
    $FAIL_VALUE = "error";
    global $VALIDATE_TEXT;
    $failed = false;
    $VALIDATE_TEXT = "";
    // clear before doing the validation
    if (!validateRequired($fvalue) && !array_key_exists("required", $params)) {
        // blank and not required
        return "";
    }
    // do the validation
    foreach ($params as $value) {
        if ($failed) {
            break;
        }
        $type = $value;
        if (strpos($value, ";") !== false) {
            // get the special rule type
            $type = substr($value, 0, strpos($value, ";"));
        }
        writeLog($TOOL_SHORT, "ajax", "validate:" . $type . ":" . $fvalue);
        if ($type == "required" || $type == "notblank") {
            if (!validateRequired($fvalue)) {
                $failed = true;
            }
        } else {
            if ($type == "email") {
                if (!validateEmail($fvalue)) {
                    $failed = true;
                }
            } else {
                if ($type == "phone") {
                    if (!validatePhone($fvalue)) {
                        $failed = true;
                    }
                } else {
                    if ($type == "date") {
                        if (!validateDate($fvalue)) {
                            $failed = true;
                        }
                    } else {
                        if ($type == "time") {
                            if (!validateTime($fvalue)) {
                                $failed = true;
                            }
                        } else {
                            if ($type == "zip" || $type == "zipcode") {
                                if (!validateZip($fvalue)) {
                                    $failed = true;
                                }
                            } else {
                                if ($type == "nospaces" || $type == "password") {
                                    if (!validateNoSpaces($fvalue)) {
                                        $failed = true;
                                    }
                                } else {
                                    if ($type == "alpha") {
                                        if (!validateAlpha($fvalue)) {
                                            $failed = true;
                                        }
                                    } else {
                                        if ($type == "alphanum") {
                                            if (!validateAlphaNumeric($fvalue)) {
                                                $failed = true;
                                            }
                                        } else {
                                            if ($type == "number") {
                                                if (!validateNumeric($fvalue)) {
                                                    $failed = true;
                                                }
                                            } else {
                                                if ($type == "name") {
                                                    if (!validateAlphaName($fvalue)) {
                                                        $failed = true;
                                                    }
                                                } else {
                                                    if ($type == "namespaces") {
                                                        if (!validateAlphaNameSpaces($fvalue)) {
                                                            $failed = true;
                                                        }
                                                    } else {
                                                        if ($type == "uniquesql") {
                                                            // should be uniquesql;(columnname);(tablename);(tableid);(userid)
                                                            $parts = split(';', $value);
                                                            if (!validateUniqueSQL($parts[1], $parts[2], $fvalue, $parts[3], $parts[4])) {
                                                                $VALIDATE_TEXT = $formid . " already used";
                                                                $failed = true;
                                                            }
                                                        } else {
                                                            if ($type == "uniqueinstp") {
                                                                // should be uniqueinstp;(value);($field);(idval)
                                                                $parts = split(';', $value);
                                                                if (!validateUniqueInst($fvalue, $parts[1], $parts[2])) {
                                                                    $VALIDATE_TEXT = $formid . " already used";
                                                                    $failed = true;
                                                                }
                                                            } else {
                                                                if ($type == "uniqueuserp") {
                                                                    // should be uniqueuserp;(value);($field);(idval)
                                                                    $parts = split(';', $value);
                                                                    if (!validateUniqueUser($fvalue, $parts[1], $parts[2])) {
                                                                        $VALIDATE_TEXT = $formid . " already used";
                                                                        $failed = true;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($output_type == "ajax") {
        $status = $PASS_VALUE;
        if ($failed) {
            $status = $FAIL_VALUE;
        }
        $ajaxReturn = "{$status}|{$formid}|{$VALIDATE_TEXT}";
        echo $ajaxReturn;
        writeLog($TOOL_SHORT, "ajax", "return={$ajaxReturn}");
    } else {
        if ($output_type == "print") {
            if ($failed) {
                print $VALIDATE_TEXT . "<br>";
            }
        } else {
            if ($output_type == "array") {
                if ($failed) {
                    return $VALIDATE_TEXT;
                }
            }
        }
    }
    // defaults to "return"
    if ($failed) {
        return $VALIDATE_TEXT . "<br>";
    }
    return "";
}
Example #2
0
require_once 'database/FileUtil.php';
require_once 'security/validation.php';
require_once 'security/rbac.php';
?>

<?php 
if (!authenticate(3)) {
    die("没有权限");
}
?>

<?php 
//PDO_Class_Wrapper version
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $pageId = validateId(htmlspecialchars($_POST["pageId"]));
    $publishTime = validateTime(htmlspecialchars($_POST["publishTime"]));
    date_default_timezone_set("Asia/Chongqing");
    $publishTimeFormated = date("Y-m-d H:i:s", strtotime($publishTime));
    $type = 0;
    $picturePath = "";
    if (isset($_POST['isTopArticle'])) {
        $type = 1;
        if (!empty($_FILES['topArticlePicture']['name'])) {
            $picturePath = saveImageFile("topArticlePicture", "picture/");
        } else {
            die("请上传置顶滑动图片");
        }
        if ($picturePath == NULL) {
            die("图片上传失败");
        }
    }