function remove_exterior_spaces($string)
{
    if (preg_does_match("/^\\s*\$/", $string)) {
        return "";
    }
    return preg_replace("/^\\s*(\\S(.*\\S)?)\\s*\$/", "\$1", $string);
}
function validate_input($required_parameters, $optional_parameters = array(), $method = "get")
{
    switch ($method) {
        case "get":
            $input_parameters = $_GET;
            break;
        case "post":
            $input_parameters = $_POST;
            break;
        case "session":
            $input_parameters = $_SESSION;
            break;
    }
    $valid = true;
    foreach ($required_parameters as $parameter) {
        $valid = $valid && isset($input_parameters[$parameter]);
    }
    if ($valid) {
        foreach ($input_parameters as $parameter => $value) {
            if (in_array($parameter, array_merge($required_parameters, $optional_parameters))) {
                switch ($parameter) {
                    case "action":
                        $valid = $valid && preg_does_match("/^[a-z_]+|[0-9]+\$/", $value);
                        break;
                    case "controller":
                        $valid = $valid && preg_does_match("/^[a-z_]+\$/", $value);
                        break;
                    case "prefix":
                        $valid = $valid && in_array($value, array("binet"));
                        break;
                    case "tags":
                        $tags = explode(" ", $value);
                        foreach ($tags as $tag) {
                            $valid = $valid && $tag == preg_does_match("/^([" . allowed_clean_string_characters() . "])+\$/", $tag);
                        }
                        break;
                    case "binet":
                        $valid = $valid && preg_does_match("/^([" . allowed_clean_string_characters() . "])+\$/", $value);
                        break;
                    case "term":
                        $valid = $valid && is_numeric($value);
                        break;
                    case "budget":
                        $valid = $valid && is_numeric($value);
                        break;
                    case "operation":
                        $valid = $valid && is_numeric($value);
                        break;
                    case "tag":
                        $valid = $valid && is_numeric($value);
                        break;
                    case "wave":
                        $valid = $valid && is_numeric($value);
                        break;
                    case "member":
                        $valid = $valid && is_numeric($value);
                        break;
                    case "student":
                        $valid = $valid && is_numeric($value);
                        break;
                }
            }
        }
        return $valid;
    } else {
        return false;
    }
}
Exemple #3
0
function form_group_date($label, $field, $prefill_value, $form_name)
{
    $regex = "/^([0-9]{4})-([0-9]{2})-([0-9]{2})\$/";
    if (preg_does_match($regex, $prefill_value)) {
        $prefill_value = preg_replace($regex, "\$3/\$2/\$1", $prefill_value);
    }
    return form_group($label, $field, "<input type=\"text\" class=\"form-control\" id=\"" . $field . "\" name=\"" . $field . "\" value=\"" . $prefill_value . "\">\n      <script type=\"text/javascript\">\n      \$(function () {\n        \$('#" . $field . "').datetimepicker({\n          format: 'DD/MM/YYYY'\n        });\n      });\n      </script>", $form_name);
}