Example #1
0
function request()
{
    global $app;
    $httprequest = new Phalcon\Http\Request();
    $datain = $httprequest->get();
    $data = array();
    foreach ($datain as $key => $value) {
        $data[strtolower($key)] = $value;
    }
    $filter = new \Phalcon\Filter();
    $request = $filter->sanitize($data["request"], array("string", "lower"));
    $response = null;
    switch ($request) {
        case "getcapabilities":
            $response = getCapabilities();
            break;
        case "describefeaturetype":
            $response = describeFeatureType($data);
            break;
        case "getfeatures":
            $response = getFeatures($data);
            break;
        case "delete":
            $response = delete($data);
            break;
        case "create":
            $response = create($data);
            break;
        case "update":
            $response = update($data);
            break;
        case "transaction":
            $response = transaction($data);
            break;
    }
    $app->response->setContentType('application/json; charset=UTF-8')->sendHeaders();
    echo json_encode($response);
}
Example #2
0
 * date: 25/10/12
 *
 * LOTS OF WORK NEEDED HERE - GET WORKS BUT NOT PUT OR POST
 */
$path = $_SERVER['DOCUMENT_ROOT'];
$config = $path . "/rcs/php/config.php";
include_once $config;
$rest = $path . "/rcs/php/rest.php";
include_once $rest;
if (isset($_POST['action']) && !empty($_POST['action'])) {
    $action = $_POST['action'];
    $authuser = $_POST['authuser'];
    $authpw = $_POST['authpw'];
    switch ($action) {
        case 'getCapabilities':
            getCapabilities($_POST['username'], $authuser, $authpw);
            break;
        case 'setCapabilities':
            setCapabilities($_POST['username'], $authuser, $authpw);
            break;
    }
}
/*
 * 4.5.1.Retrieve own capabilities
 * HTTP GET http://{serverRoot}/capabilities/{apiVersion}/{userId}
 */
function getCapabilities($username, $authuser, $authpw)
{
    global $SERVER_URL, $APIVERSION;
    $url = $SERVER_URL . 'capabilities/' . $APIVERSION . '/' . $username;
    echo $url;
Example #3
0
    foreach ($tables as $table) {
        if (!$bbox[4]) {
            $bbox[4] = $postgisObject->getGeometryColumns($postgisschema . "." . $table, "srid");
        }
        $axisOrder = gmlConverter::getAxisOrderFromEpsg($bbox[4]);
        if ($axisOrder == "longitude") {
            $wheres[$table] .= "intersects" . "(public.ST_Transform(public.ST_GeometryFromText('POLYGON((" . $bbox[0] . " " . $bbox[1] . "," . $bbox[0] . " " . $bbox[3] . "," . $bbox[2] . " " . $bbox[3] . "," . $bbox[2] . " " . $bbox[1] . "," . $bbox[0] . " " . $bbox[1] . "))'," . gmlConverter::parseEpsgCode($bbox[4]) . ")," . $postgisObject->getGeometryColumns($postgisschema . "." . $table, "srid") . ")," . $postgisObject->getGeometryColumns($postgisschema . "." . $table, "f_geometry_column") . ")";
        } else {
            $wheres[$table] .= "intersects" . "(public.ST_Transform(public.ST_GeometryFromText('POLYGON((" . $bbox[1] . " " . $bbox[0] . "," . $bbox[3] . " " . $bbox[0] . "," . $bbox[3] . " " . $bbox[2] . "," . $bbox[1] . " " . $bbox[2] . "," . $bbox[1] . " " . $bbox[0] . "))'," . gmlConverter::parseEpsgCode($bbox[4]) . ")," . $postgisObject->getGeometryColumns($postgisschema . "." . $table, "srid") . ")," . $postgisObject->getGeometryColumns($postgisschema . "." . $table, "f_geometry_column") . ")";
        }
    }
}
//get the request
switch (strtoupper($HTTP_FORM_VARS["REQUEST"])) {
    case "GETCAPABILITIES":
        getCapabilities($postgisObject);
        break;
    case "GETFEATURE":
        if (!$gmlFeatureCollection) {
            $gmlFeatureCollection = "wfs:FeatureCollection";
        }
        print "<" . $gmlFeatureCollection . "\n";
        print "xmlns=\"http://www.opengis.net/wfs\"\n";
        print "xmlns:wfs=\"http://www.opengis.net/wfs\"\n";
        print "xmlns:gml=\"http://www.opengis.net/gml\"\n";
        print "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
        print "xmlns:{$gmlNameSpace}=\"{$gmlNameSpaceUri}\"\n";
        if ($gmlSchemaLocation) {
            print "xsi:schemaLocation=\"{$gmlSchemaLocation}\"";
        } else {
            //print "xsi:schemaLocation=\"{$gmlNameSpaceUri} {$thePath}?REQUEST=DescribeFeatureType&amp;TYPENAME=".$HTTP_FORM_VARS["TYPENAME"]." http://www.opengis.net/wfs ".str_replace("server.php","",$thePath)."schemas/wfs/1.0.0/WFS-basic.xsd\"";
Example #4
0
function request()
{
    global $app;
    $httprequest = new Phalcon\Http\Request();
    $datain = $httprequest->get();
    $data = array();
    foreach ($datain as $key => $value) {
        $data[strtolower($key)] = $value;
    }
    $filter = new \Phalcon\Filter();
    $request = $filter->sanitize($data["request"], array("string", "lower"));
    $response = null;
    switch ($request) {
        case "getcapabilities":
            $response = getCapabilities();
            break;
        case "describefeaturetype":
            $response = describeFeatureType($data);
            break;
        case "getfeatures":
            $response = getFeatures($data);
            break;
        case "delete":
            $response = delete($data);
            break;
        case "create":
            $response = create($data);
            break;
        case "update":
            $response = update($data);
            break;
        case "transaction":
            $response = transaction($data);
            break;
            /* For grouping*/
        /* For grouping*/
        case "getassoclayers":
            $response = getAssocLayers($data);
            break;
        case "getgrouping":
            $response = getGrouping($data);
            break;
        case "describegrouping":
            $response = describeGrouping($data);
            break;
        case "creategrouping":
            $response = createGrouping($data);
            break;
        case "updategrouping":
            $response = updateGrouping($data);
            break;
        case "deletegrouping":
            $response = deleteGrouping($data);
            break;
        case "getFeaturesFk":
            $response = getFeaturesFk($data);
            break;
        case "duplicategrouping":
            $response = duplicateGrouping($data);
            break;
        case "associatedocument":
            $response = associateDocument($data);
            break;
        case "deletedocument":
            $response = deleteDocument($data);
            break;
        case "downloaddocument":
            $response = downloadDocument($data);
            echo $response;
            break;
        case "getdocumentlist":
            $response = getDocumentList($data);
            break;
        case "getdocumentdescription":
            $response = getDocumentDescription($data);
            break;
        default:
            $response = false;
            break;
    }
    $app->response->setContentType('application/json; charset=UTF-8')->sendHeaders();
    echo json_encode($response);
}
Example #5
0
 function wfs_server()
 {
     // Manually tested this piece of code in order to check the requests.
     // Code based on a similar idea but build in Java
     header('Content-Type:text/xml; charset=UTF-8', TRUE);
     header('Connection:close', TRUE);
     //$userFromUri = "mhoegh"; // for testing
     logfile::write($userFromUri . "\n\n");
     // We connect to the users db
     $postgisdb = $userFromUri;
     $srs = $srsFromUri;
     $postgisschema = $schemaFromUri;
     $postgisObject = new postgis();
     //$user = new users($userFromUri);
     //$version = new version($user);
     $geometryColumnsObj = new GeometryColumns();
     function microtime_float()
     {
         list($utime, $time) = explode(" ", microtime());
         return (double) $utime + (double) $time;
     }
     $startTime = microtime_float();
     //ini_set("display_errors", "On");
     $thePath = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REDIRECT_URL'];
     //$thePath= "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
     $server = "http://" . $_SERVER['SERVER_NAME'];
     $BBox = null;
     //end added
     $currentTable = null;
     $currentTag = null;
     $gen = array();
     $gen[0] = "";
     $level = 0;
     $depth = 0;
     $tables = array();
     $fields = array();
     $wheres = array();
     $limits = array();
     logfile::write("\nRequest\n\n");
     logfile::write($HTTP_RAW_POST_DATA . "\n\n");
     $unserializer_options = array('parseAttributes' => TRUE, 'typeHints' => FALSE);
     $unserializer = new XML_Unserializer($unserializer_options);
     /*$HTTP_RAW_POST_DATA = '<?xml version="1.0" encoding="utf-8"?><wfs:Transaction service="WFS" version="1.0.0" xmlns="http://www.opengis.net/wfs" xmlns:mrhg="http://twitter/mrhg" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wfs:Insert idgen="GenerateNew"><mrhg:hej><the_geom><gml:MultiPolygon srsName="urn:x-ogc:def:crs:EPSG:6.9:4326"><gml:polygonMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:coordinates>5.0657329559,-41.1107215881 8.4824724197,-39.3435783386 4.3241734505,-34.6001853943 5.0657329559,-41.1107215881 </gml:coordinates></gml:LinearRing></gml:exterior></gml:Polygon></gml:polygonMember></gml:MultiPolygon></the_geom></mrhg:hej></wfs:Insert></wfs:Transaction>';*/
     /*$HTTP_RAW_POST_DATA = '<?xml version="1.0"?><DescribeFeatureType  version="1.1.0"  service="WFS"  xmlns="http://www.opengis.net/wfs"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">    <TypeName>california_coastline</TypeName></DescribeFeatureType>';
      */
     // Post method is used
     if ($HTTP_RAW_POST_DATA) {
         //$forUseInSpatialFilter = $HTTP_RAW_POST_DATA; // We store a unaltered version of the raw request
         $HTTP_RAW_POST_DATA = dropNameSpace($HTTP_RAW_POST_DATA);
         logfile::write($HTTP_RAW_POST_DATA . "\n\n");
         $status = $unserializer->unserialize($HTTP_RAW_POST_DATA);
         $arr = $unserializer->getUnserializedData();
         $request = $unserializer->getRootName();
         //print_r($arr);
         switch ($request) {
             case "GetFeature":
                 if (!is_array($arr['Query'][0])) {
                     $arr['Query'] = array(0 => $arr['Query']);
                 }
                 for ($i = 0; $i < sizeof($arr['Query']); $i++) {
                     if (!is_array($arr['Query'][$i]['PropertyName'])) {
                         $arr['Query'][$i]['PropertyName'] = array(0 => $arr['Query'][$i]['PropertyName']);
                     }
                 }
                 $HTTP_FORM_VARS["REQUEST"] = "GetFeature";
                 foreach ($arr['Query'] as $queries) {
                     $HTTP_FORM_VARS["TYPENAME"] .= $queries['typeName'] . ",";
                     if ($queries['PropertyName'][0]) {
                         foreach ($queries['PropertyName'] as $PropertyNames) {
                             // We check if typeName is prefix and add it if its not
                             if (strpos($PropertyNames, ".")) {
                                 $HTTP_FORM_VARS["PROPERTYNAME"] .= $PropertyNames . ",";
                             } else {
                                 $HTTP_FORM_VARS["PROPERTYNAME"] .= $queries['typeName'] . "." . $PropertyNames . ",";
                             }
                         }
                     }
                     if (is_array($queries['Filter']) && $arr['version'] == "1.0.0") {
                         @($checkXml = simplexml_load_string($queries['Filter']));
                         if ($checkXml === FALSE) {
                             makeExceptionReport("Filter is not valid");
                         }
                         $wheres[$queries['typeName']] = parseFilter($queries['Filter'], $queries['typeName']);
                     }
                 }
                 $HTTP_FORM_VARS["TYPENAME"] = dropLastChrs($HTTP_FORM_VARS["TYPENAME"], 1);
                 $HTTP_FORM_VARS["PROPERTYNAME"] = dropLastChrs($HTTP_FORM_VARS["PROPERTYNAME"], 1);
                 break;
             case "DescribeFeatureType":
                 $HTTP_FORM_VARS["REQUEST"] = "DescribeFeatureType";
                 $HTTP_FORM_VARS["TYPENAME"] = $arr['TypeName'];
                 //if (!$HTTP_FORM_VARS["TYPENAME"]) $HTTP_FORM_VARS["TYPENAME"] = $arr['typeName'];
                 break;
             case "GetCapabilities":
                 $HTTP_FORM_VARS["REQUEST"] = "GetCapabilities";
                 break;
             case "Transaction":
                 $HTTP_FORM_VARS["REQUEST"] = "Transaction";
                 if (isset($arr["Insert"])) {
                     $transactionType = "Insert";
                 }
                 if ($arr["Update"]) {
                     $transactionType = "update";
                 }
                 if ($arr["Delete"]) {
                     $transactionType = "Delete";
                 }
                 break;
         }
     } else {
         if (sizeof($_GET) > 0) {
             logfile::write($_SERVER['QUERY_STRING'] . "\n\n");
             $HTTP_FORM_VARS = $_GET;
             $HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER);
             // Make keys case insensative
             $HTTP_FORM_VARS["TYPENAME"] = dropNameSpace($HTTP_FORM_VARS["TYPENAME"]);
             // We remove name space, so $where will get key without it.
             if ($HTTP_FORM_VARS['FILTER']) {
                 @($checkXml = simplexml_load_string($HTTP_FORM_VARS['FILTER']));
                 if ($checkXml === FALSE) {
                     makeExceptionReport("Filter is not valid");
                 }
                 //$forUseInSpatialFilter = $HTTP_FORM_VARS['FILTER'];
                 $status = $unserializer->unserialize(dropNameSpace($HTTP_FORM_VARS['FILTER']));
                 $arr = $unserializer->getUnserializedData();
                 $wheres[$HTTP_FORM_VARS['TYPENAME']] = parseFilter($arr, $HTTP_FORM_VARS['TYPENAME']);
             }
         } else {
             $HTTP_FORM_VARS = array("");
         }
     }
     //HTTP_FORM_VARS is set in script if POST is used
     $HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER);
     // Make keys case
     $HTTP_FORM_VARS["TYPENAME"] = dropNameSpace($HTTP_FORM_VARS["TYPENAME"]);
     $tables = explode(",", $HTTP_FORM_VARS["TYPENAME"]);
     $properties = explode(",", dropNameSpace($HTTP_FORM_VARS["PROPERTYNAME"]));
     $featureids = explode(",", $HTTP_FORM_VARS["FEATUREID"]);
     $bbox = explode(",", $HTTP_FORM_VARS["BBOX"]);
     // Start HTTP basic authentication
     //if(!$_SESSION["oauth_token"]) {
     $auth = $postgisObject->getGeometryColumns($postgisschema . "." . $HTTP_FORM_VARS["TYPENAME"], "authentication");
     //}
     // End HTTP basic authentication
     print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     ob_start();
     if (!empty($properties[0])) {
         foreach ($properties as $property) {
             $__u = explode(".", $property);
             // Is it "/" for get method?
             // We first check if typeName is namespace
             if ($__u[1]) {
                 foreach ($tables as $table) {
                     if ($table == $__u[0]) {
                         $fields[$table] .= $__u[1] . ",";
                     }
                 }
             } else {
                 foreach ($tables as $table) {
                     $fields[$table] .= $property . ",";
                 }
             }
         }
     }
     if (!empty($featureids[0])) {
         foreach ($featureids as $featureid) {
             $__u = explode(".", $featureid);
             foreach ($tables as $table) {
                 $primeryKey = $postgisObject->getPrimeryKey($postgisschema . "." . $table);
                 if ($table == $__u[0]) {
                     $wheresArr[$table][] = "{$primeryKey['attname']}={$__u[1]}";
                 }
                 $wheres[$table] = implode(" OR ", $wheresArr[$table]);
             }
         }
     }
     //get the request
     switch (strtoupper($HTTP_FORM_VARS["REQUEST"])) {
         case "GETCAPABILITIES":
             getCapabilities($postgisObject);
             break;
         case "GETFEATURE":
             if (!$gmlFeatureCollection) {
                 $gmlFeatureCollection = "wfs:FeatureCollection";
             }
             print "<" . $gmlFeatureCollection . "\n";
             print "xmlns=\"http://www.opengis.net/wfs\"\n";
             print "xmlns:wfs=\"http://www.opengis.net/wfs\"\n";
             print "xmlns:gml=\"http://www.opengis.net/gml\"\n";
             print "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
             print "xmlns:{$gmlNameSpace}=\"{$gmlNameSpaceUri}\"\n";
             if ($gmlSchemaLocation) {
                 print "xsi:schemaLocation=\"{$gmlSchemaLocation}\"";
             } else {
                 //print "xsi:schemaLocation=\"{$gmlNameSpaceUri} {$thePath}?REQUEST=DescribeFeatureType&amp;TYPENAME=".$HTTP_FORM_VARS["TYPENAME"]." http://www.opengis.net/wfs ".str_replace("server.php","",$thePath)."schemas/wfs/1.0.0/WFS-basic.xsd\"";
                 print "xsi:schemaLocation=\"{$gmlNameSpaceUri} {$thePath}?REQUEST=DescribeFeatureType&amp;TYPENAME=" . $HTTP_FORM_VARS["TYPENAME"] . " http://www.opengis.net/wfs http://wfs.plansystem.dk:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd\"";
             }
             print ">\n";
             doQuery("Select");
             print "</" . $gmlFeatureCollection . ">";
             break;
         case "DESCRIBEFEATURETYPE":
             getXSD($postgisObject);
             break;
         case "TRANSACTION":
             doParse($arr);
             break;
         default:
             makeExceptionReport("Don't know that request");
             break;
     }
 }
#$mb_exception = new mb_exception("auth: ".$auth['username']);
if ($auth['auth_type'] == '') {
    unset($auth);
}
/*************  workflow ************/
$n = new administration();
switch (strtolower($reqParams['request'])) {
    case 'getcapabilities':
        $arrayOnlineresources = checkWmsPermission($query->getOwsproxyServiceId());
        $query->setOnlineResource($arrayOnlineresources['wms_getcapabilities']);
        $request = $query->getRequest();
        if (isset($auth)) {
            getCapabilities($request, $auth);
            #$mb_exception = new mb_exception("auth: ".$auth['auth_type']);
        } else {
            getCapabilities($request);
        }
        break;
    case 'getfeatureinfo':
        $arrayOnlineresources = checkWmsPermission($query->getOwsproxyServiceId());
        $query->setOnlineResource($arrayOnlineresources['wms_getfeatureinfo']);
        $request = $query->getRequest();
        if (isset($auth)) {
            getFeatureInfo($request, $auth);
        } else {
            getFeatureInfo($request);
        }
        break;
    case 'getmap':
        $arrayOnlineresources = checkWmsPermission($owsproxyService);
        $query->setOnlineResource($arrayOnlineresources['wms_getmap']);
switch (strtolower($reqParams['request'])) {
    case 'getcapabilities':
        $arrayOnlineresources = checkWmsPermission($wmsId, $userInformation[0]);
        $query->setOnlineResource($arrayOnlineresources['wms_getcapabilities']);
        //$request = preg_replace("/(.*)frames\/login.php/", "$1php/wms.php?layer_id=".$layerId, LOGIN);
        if (isset($_SERVER["HTTPS"])) {
            $urlPrefix = "https://";
        } else {
            $urlPrefix = "http://";
        }
        $request = $urlPrefix . $_SERVER['HTTP_HOST'] . "/mapbender/php/wms.php?layer_id=" . $layerId;
        $requestFull .= $request . '&REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS';
        if (isset($auth)) {
            getCapabilities($request, $requestFull, $auth);
        } else {
            getCapabilities($request, $requestFull);
        }
        break;
    case 'getfeatureinfo':
        $arrayOnlineresources = checkWmsPermission($wmsId, $userInformation[0]);
        $query->setOnlineResource($arrayOnlineresources['wms_getfeatureinfo']);
        $layers = checkLayerPermission($wmsId, $reqParams['layers'], $userInformation[0]);
        if ($layers == '') {
            throwE("GetFeatureInfo permission denied on layer with id" . $layerId);
            die;
        }
        $request = $query->getRequest();
        if (isset($auth)) {
            getFeatureInfo($request, $auth);
        } else {
            getFeatureInfo($request);