コード例 #1
0
        $db_opts = get_db_options();
        $pgcon = connectPostgreSQL($db_opts["sql_db_name"]);
        $fw_core_tbl = $db_opts['fw_core_table_name'];
        $del_stmt = "DELETE FROM {$fw_core_tbl} WHERE uuid='{$uuid}'";
        $del_result = pg_query($del_stmt);
        if (!$del_result) {
            header("HTTP/1.0 500 Internal Server Error");
            $error = pg_last_error();
            die($error);
        }
        $rows_deleted = pg_affected_rows($del_result);
        if ($rows_deleted != 1) {
            header("HTTP/1.0 400 Bad Request");
            die("The specified UUID was not found from the database!");
        }
        $components = get_supported_components();
        $m_db = connectMongoDB($db_opts['mongo_db_name']);
        foreach ($components as $component) {
            if ($component == "fw_core") {
                continue;
            }
            $collection = $m_db->{$component};
            $collection->remove(array("_id" => $uuid));
        }
        header("Access-Control-Allow-Origin: *");
        echo "POI deleted succesfully";
    } else {
        header("HTTP/1.0 400 Bad Request");
        die("'poi_id' parameter must be specified!");
    }
} else {
コード例 #2
0
function handle_common_search_params()
{
    $params = array();
    $params['max_results'] = 9999;
    $params['components'] = get_supported_components();
    if (isset($_GET['category'])) {
        $category = $_GET['category'];
        $esc_categories = escape_csv($category, "\"");
        $params['categories'] = $esc_categories;
    }
    if (isset($_GET['component'])) {
        $component = $_GET['component'];
        $esc_components = pg_escape_string($component);
        $components = explode(",", $esc_components);
        $params['components'] = $components;
    }
    if (isset($_GET['max_results'])) {
        $max_res = $_GET['max_results'];
        if (!is_numeric($max_res)) {
            header("HTTP/1.0 400 Bad Request");
            die("'max_results' must be a positive integer value!");
        }
        $max_results = intval($max_res);
        if ($max_results < 1) {
            header("HTTP/1.0 400 Bad Request");
            die("'max_results' must be a positive integer value!");
        }
        $params['max_results'] = $max_results;
    }
    if (isset($_GET['begin_time']) and isset($_GET['end_time'])) {
        $min_minutes = 1;
        //Default value
        if (isset($_GET['min_minutes'])) {
            $min_minutes = $_GET['min_minutes'];
            if (!is_numeric($min_minutes)) {
                header("HTTP/1.0 400 Bad Request");
                die("'min_minutes' must be a positive integer value!");
            }
            $min_minutes = intval($min_minutes);
            if ($min_minutes < 1) {
                header("HTTP/1.0 400 Bad Request");
                die("'min_minutes' must be a positive integer value!");
            }
        }
        $params['min_minutes'] = $min_minutes;
        if (isset($_GET['schedule'])) {
            $schedule_json = $_GET['schedule'];
            $schedule = json_decode($schedule_json);
            if ($schedule == NULL) {
                header("HTTP/1.0 400 Bad Request");
                die("JSON decoding failed for 'schedule'. Is it valid JSON and properly url-encoded?");
            }
            //TODO: Validate the schedule JSON against schema!
            $schedule_valid = validate_poi_data($schedule, 'schedule_schema_3.3.json');
            if (!$schedule_valid) {
                header("HTTP/1.0 400 Bad Request");
                die("'schedule' does not validate against JSON schema!");
            }
            $schedule = json_decode($schedule_json, true);
            $params['schedule'] = $schedule;
        }
        $begin_time = $_GET['begin_time'];
        $end_time = $_GET['end_time'];
        $begin_time_obj = date_parse($begin_time);
        $end_time_obj = date_parse($end_time);
        if ($begin_time_obj['error_count'] != 0) {
            header("HTTP/1.0 400 Bad Request");
            die("Error parsing 'begin_time'!");
        }
        if ($end_time_obj['error_count'] != 0) {
            header("HTTP/1.0 400 Bad Request");
            die("Error parsing 'end_time'!");
        }
        $params['begin_time'] = $begin_time_obj;
        $params['end_time'] = $end_time_obj;
    }
    return $params;
}