Example #1
0
function getDetails($db, $id, $type, $langs, $offset)
{
    global $format, $callback;
    // request
    $request = "SELECT\n\t\t\t\ttags->'addr:street' AS \"street\",\n\t\t\t\ttags->'addr:housenumber' AS \"housenumber\",\n\t\t\t\ttags->'addr:housename' AS \"housename\",\n\t\t\t\ttags->'addr:country' AS \"country\",\n\t\t\t\ttags->'addr:postcode' AS \"postcode\",\n\t\t\t\ttags->'addr:city' AS \"city\",\n\t\t\t\ttags->'addr:suburb' AS \"suburb\",\n\t\t\t\ttags->'addr:province' AS \"province\",\n\t\t\t\ttags->'addr:unit' AS \"unit\",\n\t\t\t\ttags->'addr:floor' AS \"floor\",\n\t\t\t\ttags->'addr:door' AS \"door\",\n\t\t\t\ttags->'phone' AS \"phone1\",\n\t\t\t\ttags->'contact:phone' AS \"phone2\",\n\t\t\t\ttags->'addr:phone' AS \"phone3\",\n\t\t\t\ttags->'fax' AS \"fax1\",\n\t\t\t\ttags->'contact:fax' AS \"fax2\",\n\t\t\t\ttags->'addr:fax' AS \"fax3\",\n\t\t\t\ttags->'website' AS \"website1\",\n\t\t\t\ttags->'url' AS \"website2\",\n\t\t\t\ttags->'url:official' AS \"website3\",\n\t\t\t\ttags->'contact:website' AS \"website4\",\n\t\t\t\ttags->'operator' AS \"operator\",\n\t\t\t\ttags->'email' AS \"email1\",\n\t\t\t\ttags->'contact:email' AS \"email2\",\n\t\t\t\ttags->'addr:email' AS \"email3\",\n\t\t\t\ttags->'opening_hours' AS \"openinghours\",\n\t\t\t\ttags->'service_times' AS \"servicetimes\",\n\t\t\t\ttags->'image' AS \"image\"\n\t\t\tFROM " . $type . "s WHERE (id = " . $id . ");";
    $wikipediarequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 9) = 'wikipedia';";
    $namerequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 4) = 'name';";
    // connnecting to database
    $connection = connectToDatabase($db);
    // if there is no connection
    if (!$connection) {
        exit;
    }
    $response = requestDetails($request, $connection);
    $wikipediaresponse = requestDetails($wikipediarequest, $connection);
    $nameresponse = requestDetails($namerequest, $connection);
    pg_close($connection);
    if ($response) {
        if ($format == "text") {
            echo textDetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset);
        } else {
            if ($format == "json") {
                echo jsonDetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type, $callback);
            } else {
                echo xmlDetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type);
            }
        }
        return true;
    } else {
        return false;
    }
}
Example #2
0
function getDetails($ptdb, $id, $type, $langs, $offset)
{
    global $format, $callback;
    // request
    $wikipediarequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 9) = 'wikipedia';";
    $namerequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 4) = 'name';";
    // connnecting to database
    $connection = connectToDatabase($ptdb);
    // if there is no connection
    if (!$connection) {
        exit;
    }
    $wikipediaresponse = requestDetails($wikipediarequest, $connection);
    $nameresponse = requestDetails($namerequest, $connection);
    pg_close($connection);
    $response = tagTransform("../locales/departures.xml", getTags($ptdb, $id, $type), $type);
    if ($response) {
        if ($format == "text") {
            echo textDetailsOut($response, $nameresponse, $wikipediaresponse, $langs, $offset);
        } else {
            if ($format == "json") {
                echo jsonDetailsOut($response, $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type, $callback);
            } else {
                echo xmlDetailsOut($response, $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type);
            }
        }
        return true;
    } else {
        return false;
    }
}