Example #1
0
 function __construct()
 {
     $this->db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $this->db);
     if (sizeof($dbSplit) == 2) {
         $this->db = $dbSplit[1];
     }
     if ($_SESSION['http_auth'] != $this->db) {
         //error_log("WMS-C auth");
         \app\models\Database::setDb($this->db);
         $postgisObject = new \app\inc\Model();
         if ($_SERVER["QUERY_STRING"]) {
             $auth = $postgisObject->getGeometryColumns(\app\inc\Input::get("LAYERS"), "authentication");
         } else {
             $parts = explode("/", $_SERVER['REQUEST_URI']);
             $auth = $postgisObject->getGeometryColumns($parts[4], "authentication");
         }
         if ($auth == "Read/write" || $auth == "Write") {
             include 'inc/http_basic_authen.php';
         }
         $_SESSION['http_auth'] = $this->db;
     }
     if ($_SERVER["QUERY_STRING"]) {
         $this->get_wms();
     } else {
         $this->get_tms();
     }
 }
Example #2
0
 function __construct()
 {
     if (\app\inc\Input::getPath()->part(3) == "tilecache") {
         $postgisschema = \app\inc\Input::getPath()->part(4);
     } else {
         $postgisschema = \app\inc\Input::getPath()->part(3);
     }
     $db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $db);
     if (sizeof($dbSplit) == 2) {
         $db = $dbSplit[1];
     }
     $path = App::$param['path'] . "/app/wms/mapfiles/";
     $name = $db . "_" . $postgisschema . ".map";
     $oMap = new \mapObj($path . $name);
     $request = new \OWSRequestObj();
     if ($_SERVER['REQUEST_METHOD'] === 'GET') {
         foreach ($_GET as $k => $v) {
             if (strtolower($k) == "layers" || strtolower($k) == "layer" || strtolower($k) == "typename" || strtolower($k) == "typenames") {
                 $layers = $v;
             }
             $request->setParameter($k, $v);
         }
     } else {
         $request->loadParams();
     }
     if ($_SESSION['http_auth'] != $db) {
         \app\models\Database::setDb($db);
         $postgisObject = new \app\inc\Model();
         foreach (explode(",", $layers) as $layer) {
             $auth = $postgisObject->getGeometryColumns($layer, "authentication");
             $layerSplit = explode(".", $layer);
             $HTTP_FORM_VARS["TYPENAME"] = $layerSplit[1];
             if ($auth == "Read/write") {
                 include 'inc/http_basic_authen.php';
             } else {
                 include 'inc/http_basic_authen_subuser.php';
             }
         }
     }
     ms_ioinstallstdouttobuffer();
     $oMap->owsdispatch($request);
     $contenttype = ms_iostripstdoutbuffercontenttype();
     if ($contenttype == 'image/png') {
         header('Content-type: image/png');
     } else {
         header('Content-type: text/xml');
     }
     ms_iogetStdoutBufferBytes();
     print "<!--\n";
     include "README";
     print "\n-->\n";
     ms_ioresethandlers();
 }
Example #3
0
<?php

include "../../app/conf/Connection.php";
include "../../app/inc/Model.php";
include "../../app/models/Database.php";
include "../../app/models/Dbchecks.php";
include "sqls.php";
\app\conf\Connection::$param["postgisdb"] = $_REQUEST['db'];
$conn = new \app\inc\Model();
try {
    $conn->connect();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
    die;
}
$conn->begin();
//Try to drop schema
/*
$result = $conn->execQuery("DROP SCHEMA settings CASCADE","PDO","transaction");
if (!$conn->PDOerror[0]) {
	echo "Schema dropped<br/>";
}
else {
	echo "Something went wrong; {$conn->PDOerror[0]}";
	$conn->rollback();
}
*/
//Try to create schema
$result = $conn->execQuery($sqls['schema'], "PDO", "transaction");
if (!$conn->PDOerror[0]) {
    echo "Schema created<br/>";
Example #4
0
    $gmlNameSpaceUri = "http://twitter/" . Connection::$param["postgisdb"];
}
$postgisdb = Connection::$param["postgisdb"];
$postgisschema = Connection::$param["postgisschema"];
$layerObj = new Layer();
$srs = \app\inc\Input::getPath()->part(4);
$timeSlice = \app\inc\Input::getPath()->part(5);
if ($timeSlice != "all") {
    $unixTime = strtotime(urldecode($timeSlice));
    if ($unixTime) {
        $timeSlice = date("Y-m-d G:i:s.u", $unixTime);
    } else {
        $timeSlice = false;
    }
}
$postgisObject = new \app\inc\Model();
$geometryColumnsObj = new \app\controllers\Layer();
function microtime_float()
{
    list($utime, $time) = explode(" ", microtime());
    return (double) $utime + (double) $time;
}
$startTime = microtime_float();
$uri = str_replace("index.php", "", $_SERVER['REDIRECT_URL']);
$uri = str_replace("//", "/", $uri);
$thePath = "http://" . $_SERVER['SERVER_NAME'] . $uri;
$server = "http://" . $_SERVER['SERVER_NAME'];
$BBox = null;
$currentTable = null;
$currentTag = null;
$gen = array();
Example #5
0
 function __construct()
 {
     if (\app\inc\Input::getPath()->part(3) == "tilecache") {
         $postgisschema = \app\inc\Input::getPath()->part(4);
     } else {
         $postgisschema = \app\inc\Input::getPath()->part(3);
     }
     $db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $db);
     if (sizeof($dbSplit) == 2) {
         $db = $dbSplit[1];
     }
     $path = App::$param['path'] . "/app/wms/mapfiles/";
     $name = $db . "_" . $postgisschema . ".map";
     $oMap = new \mapObj($path . $name);
     $request = new \OWSRequestObj();
     if ($_SERVER['REQUEST_METHOD'] === 'GET') {
         foreach ($_GET as $k => $v) {
             if (strtolower($k) == "layers" || strtolower($k) == "layer" || strtolower($k) == "typename" || strtolower($k) == "typenames") {
                 $layers = $v;
             }
             $request->setParameter($k, $v);
         }
     } else {
         $request->loadParams();
     }
     if ($_SESSION['http_auth'] != $db) {
         \app\models\Database::setDb($db);
         $postgisObject = new \app\inc\Model();
         foreach (explode(",", $layers) as $layer) {
             $auth = $postgisObject->getGeometryColumns($layer, "authentication");
             $layerSplit = explode(".", $layer);
             $HTTP_FORM_VARS["TYPENAME"] = $layerSplit[1];
             if ($auth == "Read/write") {
                 include 'inc/http_basic_authen.php';
             } else {
                 include 'inc/http_basic_authen_subuser.php';
             }
         }
     }
     if ($_GET['sql_layer']) {
         include '../libs/functions.php';
         include '../conf/main.php';
         $postgisdb = "mydb";
         $request->setParameter("SLD_BODY", "<StyledLayerDescriptor version='1.1.0'><NamedLayer><Name>sql</Name><UserStyle><Title>xxx</Title><FeatureTypeStyle><Rule><LineSymbolizer><Stroke><CssParameter name='stroke'>#FFFF00</CssParameter><CssParameter name='stroke-width'>15</CssParameter></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>\n                ");
         $postgisObj = new postgis();
         $postgisObj2 = new postgis();
         $view = "public.hello";
         $sqlView = "CREATE VIEW {$view} as " . urldecode($_GET['sql_layer']);
         $postgisObj->connect();
         $postgisObj->execQuery($sqlView);
         $postgisObj->execQuery("CREATE SEQUENCE _serial START 1");
         $arrayWithFields = $postgisObj2->getMetaData($view);
         foreach ($arrayWithFields as $key => $arr) {
             if ($arr['type'] == "geometry") {
                 $fieldsArr[] = "transform(" . $key . ",900913) as the_geom";
             } else {
                 $fieldsArr[] = $key;
             }
         }
         $fieldsArr[] = "nextval('_serial') as _serial";
         $sql = implode(",", $fieldsArr);
         $sql = "SELECT {$sql} FROM {$view}";
         $request->setParameter("LAYERS", $_GET['LAYERS'] . ",sql");
         $layer = ms_newLayerObj($oMap);
         $layer->updateFromString("\n\tLAYER\n\t\tNAME 'sql'\n\t\tSTATUS off\n\t\tPROCESSING 'CLOSE_CONNECTION=DEFER'\n\t\tDATA \"the_geom from ({$sql}) as foo using unique _serial using srid=900913\"\n\t\tTYPE POLYGON\n\t\tCONNECTIONTYPE POSTGIS\n\t\tCONNECTION 'user=postgres dbname=mydb host=127.0.0.1'\n\t\tMETADATA\n\t\t  'wms_title'    'sql'\n\t\t  'wms_srs'    'EPSG:4326'\n\t\t  'wms_name'    'sql'\n\t\tEND\n\t\tPROJECTION\n\t\t  'init=epsg:900913'\n\t\tEND\n\t\tCLASS\n\t\t  NAME 'New style'\n\t\t  STYLE\n\t\t\tOUTLINECOLOR 255 0 0\n\t\t  END\n  \t\tEND\n  \tEND\n\t");
     }
     ms_ioinstallstdouttobuffer();
     $oMap->owsdispatch($request);
     if ($_GET['sql_layer']) {
         $sql = "DROP VIEW {$view}";
         $result = $postgisObj->execQuery($sql);
     }
     $contenttype = ms_iostripstdoutbuffercontenttype();
     if ($contenttype == 'image/png') {
         header('Content-type: image/png');
     } else {
         header('Content-type: text/xml');
     }
     ms_iogetStdoutBufferBytes();
     ms_ioresethandlers();
 }
Example #6
0
 public function post_river()
 {
     if ($response = $this->checkAuth(Input::getPath()->part(5), Input::get('key'))) {
         return $response;
     }
     $triggerInstalled = false;
     $schema = Input::getPath()->part(6);
     $table = Input::getPath()->part(7);
     $index = $schema;
     $type = $table;
     $db = Input::getPath()->part(5);
     $fullIndex = $db . "_" . $index;
     $fullTable = $schema . "." . $table;
     $insert = Input::get('insert') ?: "t";
     $triggerSchema = Input::get('ts') ?: $schema;
     $triggerTable = Input::get('tt') ?: $table;
     $installTrigger = false;
     if (mb_substr($type, 0, 1, 'utf-8') == "_") {
         $type = "a" . $type;
     }
     $model = new \app\inc\Model();
     $relationCheck = $model->isTableOrView($triggerSchema . "." . $triggerTable);
     if (!$relationCheck["success"]) {
         return array("success" => false, "message" => "Trigger table doesn't exists", "code" => "406");
     } else {
         if ($relationCheck["data"] == "table") {
             $installTrigger = true;
         }
     }
     $relationType = $model->isTableOrView($fullTable);
     $priObj = $model->getPrimeryKey($fullTable);
     $priKey = $priObj["attname"];
     $model->close();
     // Close the PDO connection
     $pl = file_get_contents(\app\conf\App::$param["path"] . "/app/scripts/sql/notify_transaction.sql");
     // TODO check if sprintf is needed
     $pl = sprintf($pl, $priKey, $priKey, $priKey);
     $result = $model->execQuery($pl, "PG");
     if (!$result) {
         $response['success'] = false;
         return $response;
     }
     // Drop the trigger
     $pl = "DROP TRIGGER IF EXISTS _gc2_notify_transaction_trigger ON {$triggerSchema}.{$triggerTable}";
     $result = $model->execQuery($pl, "PG");
     // Define default settings for the new index
     $defaultSettings = array("settings" => array("number_of_shards" => 1, "analysis" => array("analyzer" => array("str_search_analyzer" => array("type" => "custom", "tokenizer" => "whitespace", "filter" => array("0" => "lowercase")), "str_index_analyzer" => array("type" => "custom", "tokenizer" => "whitespace", "filter" => array("0" => "lowercase", "1" => "substring"))), "filter" => array("substring" => array("type" => "edgeNGram", "min_gram" => 1, "max_gram" => 255)))));
     // Check if there are custom settings
     if (!($settings = @file_get_contents(\app\conf\App::$param["path"] . "/app/conf/elasticsearch_settings.json"))) {
         $settings = json_encode($defaultSettings);
     }
     $es = new \app\models\Elasticsearch();
     // Delete the type
     $res = $es->delete($fullIndex, $type);
     $obj = json_decode($res["json"], true);
     if (isset($obj["error"]) && $obj["error"] != false) {
         // If type not already exists we just ignore the error.
         // TODO check if type exist before deleting it.
         /*$response['success'] = false;
           $response['message'] = $obj["error"];
           $response['code'] = $obj["status"];
           return $response;*/
     }
     // Create the index with settings
     $res = $es->createIndex($fullIndex, $settings);
     $obj = json_decode($res["json"], true);
     if (isset($obj["error"]) && $obj["error"] != false) {
         // If index already exists we just ignore it.
         // TODO check if index already exists before creating it.
         /*$response['success'] = false;
           $response['message'] = $obj["error"];
           $response['code'] = $obj["status"];
           return $response;*/
     }
     // Mappings from the table
     $map = $es->createMapFromTable($fullTable);
     $res = $es->map($fullIndex, $type, json_encode($map));
     $obj = json_decode($res["json"], true);
     if (isset($obj["error"]) && $obj["error"] != false) {
         $response['success'] = false;
         $response['message'] = $obj["error"];
         $response['code'] = $obj["status"];
         return $response;
     }
     // Bulk insert
     if ($insert == "t") {
         $sql = "SELECT * FROM {$fullTable}";
         $api = new \app\models\Sql_to_es("4326");
         $api->execQuery("set client_encoding='UTF8'", "PDO");
         $res = $api->sql($sql, $index, $type, $priKey, $db);
         if (!$res["success"]) {
             return $res;
         }
         $res["Indexed"] = true;
     } else {
         $res = array("succes" => true, "indexed" => false, "message" => "Indexing skipped");
     }
     // Create the trigger
     $triggerInstalledIn = null;
     if ($relationType["data"] == "table" || $installTrigger) {
         $pl = "CREATE TRIGGER _gc2_notify_transaction_trigger AFTER INSERT OR UPDATE OR DELETE ON {$triggerSchema}.{$triggerTable} FOR EACH ROW EXECUTE PROCEDURE _gc2_notify_transaction('{$priKey}', '{$schema}','{$table}')";
         $result = $model->execQuery($pl, "PG");
         if (!$result) {
             $response['success'] = false;
             return $response;
         }
         $triggerInstalled = true;
         $triggerInstalledIn = "{$triggerSchema}.{$triggerTable}";
     }
     $res["_index"] = $fullIndex;
     $res["_type"] = $type;
     $res["relation"] = $relationType["data"];
     $res["trigger_installed"] = $triggerInstalled;
     $res["trigger_installed_in"] = $triggerInstalledIn;
     return $res;
 }
Example #7
0
 public function get_index()
 {
     $dir = App::$param['path'] . "app/tmp/" . Connection::$param["postgisdb"] . "/__vectors";
     $safeName = \app\inc\Model::toAscii($_REQUEST['name'], array(), "_");
     $skipFailures = $_REQUEST["ignoreerrors"] == "true" ? true : false;
     $append = $_REQUEST["append"] == "true" ? true : false;
     $overwrite = $_REQUEST["overwrite"] == "true" ? true : false;
     if (is_numeric($safeName[0])) {
         $safeName = "_" . $safeName;
     }
     //Check if file is .zip
     $zipCheck1 = explode(".", $_REQUEST['file']);
     $zipCheck2 = array_reverse($zipCheck1);
     if (strtolower($zipCheck2[0]) == "zip" || strtolower($zipCheck2[0]) == "rar") {
         $ext = array("shp", "tab", "geojson", "gml", "kml", "mif", "gdb");
         $folderArr = array();
         $safeNameArr = array();
         for ($i = 0; $i < sizeof($zipCheck1) - 1; $i++) {
             $folderArr[] = $zipCheck1[$i];
         }
         $folder = implode(".", $folderArr);
         if (strtolower($zipCheck2[0]) == "zip") {
             // ZIP start
             $zip = new \ZipArchive();
             $res = $zip->open($dir . "/" . $_REQUEST['file']);
             if ($res === false) {
                 $response['success'] = false;
                 $response['message'] = "Could not unzip file";
                 return Response::json($response);
             }
             $zip->extractTo($dir . "/" . $folder);
             $zip->close();
             // ZIP end
         }
         if (strtolower($zipCheck2[0]) == "rar") {
             // RAR start
             $rar_file = rar_open($dir . "/" . $_REQUEST['file']);
             if (!$rar_file) {
                 $response['success'] = false;
                 $response['message'] = "Could not unrar file";
                 return Response::json($response);
             }
             $list = rar_list($rar_file);
             foreach ($list as $file) {
                 $entry = rar_entry_get($rar_file, $file);
                 $file->extract($dir . "/" . $folder);
                 // extract to the current dir
             }
             rar_close($rar_file);
             // RAR end
         }
         if ($handle = opendir($dir . "/" . $folder)) {
             while (false !== ($entry = readdir($handle))) {
                 if ($entry !== "." && $entry !== "..") {
                     $zipCheck1 = explode(".", $entry);
                     $zipCheck2 = array_reverse($zipCheck1);
                     if (in_array(strtolower($zipCheck2[0]), $ext)) {
                         $_REQUEST['file'] = $folder . "/" . $entry;
                         for ($i = 0; $i < sizeof($zipCheck1) - 1; $i++) {
                             $safeNameArr[] = $zipCheck1[$i];
                         }
                         $safeName = \app\inc\Model::toAscii(implode(".", $safeNameArr), array(), "_");
                         break;
                     }
                     $_REQUEST['file'] = $folder;
                 }
             }
         }
     }
     $srid = $_REQUEST['srid'] ?: "4326";
     $encoding = $_REQUEST['encoding'] ?: "LATIN1";
     switch ($_REQUEST['type']) {
         case "Point":
             $type = "point";
             break;
         case "Polygon":
             $type = "multipolygon";
             break;
         case "Line":
             $type = "multilinestring";
             break;
         case "Geometry":
             $type = "geometry";
             break;
         default:
             $type = "PROMOTE_TO_MULTI";
             break;
     }
     $model = new \app\inc\Model();
     $tableExist = $model->isTableOrView(Connection::$param["postgisschema"] . "." . $safeName);
     $tableExist = $tableExist["success"];
     if ($tableExist == true && $overwrite == false && $append == false) {
         $response['success'] = false;
         $response['message'] = "'{$safeName}' exists already, use 'Overwrite'";
         $response['code'] = 406;
         return $response;
     }
     if ($_REQUEST["append"] == "true") {
         $sql = "DELETE FROM " . Connection::$param["postgisschema"] . "." . $safeName;
         $res = $model->prepare($sql);
         try {
             $res->execute();
         } catch (\PDOException $e) {
             $response['success'] = false;
             $response['message'] = "Could not delete from {$safeName}";
             $response['code'] = 406;
             return $response;
         }
     }
     $cmd = "PGCLIENTENCODING={$encoding} ogr2ogr " . ($skipFailures ? "-skipfailures " : " ") . ($append ? "-append " : " ") . ($overwrite == true && $append == false ? "-overwrite " : " ") . "-dim 2 " . ($append ? "" : "-lco 'GEOMETRY_NAME=the_geom' ") . ($append ? "" : "-lco 'FID=gid' ") . ($append ? "" : "-lco 'PRECISION=NO' ") . ($append ? "" : "-lco 'PG_USE_COPY=YES' ") . "-a_srs 'EPSG:{$srid}' " . "-f 'PostgreSQL' PG:'host=" . Connection::$param["postgishost"] . " user=" . Connection::$param["postgisuser"] . " password=" . Connection::$param["postgispw"] . " dbname=" . Connection::$param["postgisdb"] . " active_schema=" . Connection::$param["postgisschema"] . "' " . "'" . $dir . "/" . $_REQUEST['file'] . "' " . "-nln {$safeName} " . "-nlt {$type}";
     exec($cmd . ' 2>&1', $out, $err);
     $geoType = $model->getGeometryColumns(Connection::$param["postgisschema"] . "." . $safeName, "type");
     $key = Connection::$param["postgisschema"] . "." . $safeName . ".the_geom";
     $class = new \app\models\Classification($key);
     $arr = $class->getAll();
     // Set layer editable
     $join = new \app\models\Table("settings.geometry_columns_join");
     $json = '{"data":{"editable":true,"_key_":"' . $key . '"}}';
     $data = (array) json_decode(urldecode($json));
     $join->updateRecord($data, "_key_");
     if (empty($arr['data'])) {
         $class->insert();
         $class->update("0", \app\models\Classification::createClass($geoType));
     }
     $def = new \app\models\Tile($key);
     $arr = $def->get();
     if (empty($arr['data'][0])) {
         $json = '{
         "theme_column":"",
         "label_column":"",
         "query_buffer":"",
         "opacity":"",
         "label_max_scale":"",
         "label_min_scale":"",
         "meta_tiles":false,
         "meta_size":"3",
         "meta_buffer":"10",
         "ttl":""}';
         $def->update($json);
     }
     if ($out[0] == "") {
         $response['success'] = true;
         $response['message'] = "Layer <b>{$safeName}</b> is created";
         $response['type'] = $geoType;
         // Bust cache, in case of layer already exist
         \app\controllers\Tilecache::bust(Connection::$param["postgisschema"] . "." . $safeName);
     } else {
         $response['success'] = false;
         $response['message'] = $safeName . ": Some thing went wrong. Check the log.";
         $response['out'] = $out[0];
         Session::createLog($out, $_REQUEST['file']);
         // Make sure the table is dropped if not skipping failures and it didn't exists before
         if ($skipFailures == false && $tableExist == false) {
             $sql = "DROP TABLE " . Connection::$param["postgisschema"] . "." . $safeName;
             $res = $model->prepare($sql);
             try {
                 $res->execute();
             } catch (\PDOException $e) {
             }
         }
     }
     $response['cmd'] = $cmd;
     return $response;
 }
Example #8
0
    function get_index()
    {
        $postgisObject = new \app\inc\Model();
        ob_start();
        ?>
        MAP
        #
        # Start of map file
        #
        NAME "<?php 
        echo Connection::$param['postgisdb'];
        ?>
"
        STATUS on
        EXTENT -180 -90 180 90
        SIZE 2000 1500
        MAXSIZE 4096
        #SYMBOLSET "../etc/symbols.sym"
        FONTSET "../fonts/fonts.txt"
        IMAGECOLOR 255 2 255
        UNITS METERS
        INTERLACE OFF
        OUTPUTFORMAT
        NAME "png"
        DRIVER AGG/PNG
        MIMETYPE "image/png"
        IMAGEMODE RGBA
        EXTENSION "png"
        TRANSPARENT ON
        FORMATOPTION "GAMMA=0.75"
        END
        #CONFIG "MS_ERRORFILE" "/srv/www/sites/betamygeocloud/wms/mapfiles/ms_error.txt"
        #DEBUG 5
        WEB
        IMAGEPATH "<?php 
        echo App::$param['path'];
        ?>
/tmp"
        IMAGEURL "<?php 
        echo App::$param['host'];
        ?>
/tmp"
        METADATA
        "wms_title"    "<?php 
        echo Connection::$param['postgisdb'];
        ?>
's awesome WMS"
        "wfs_title"    "<?php 
        echo Connection::$param['postgisdb'];
        ?>
's awesome WFS"
        "wms_srs"    "EPSG:4326 EPSG:3857 EPSG:900913 EPSG:3044 EPSG:25832"
        "wfs_srs"    "EPSG:4326 EPSG:3857 EPSG:900913 EPSG:3044 EPSG:25832"
        "wms_name"    "<?php 
        echo $user;
        ?>
"
        "wfs_name"    "<?php 
        echo $user;
        ?>
"
        "wms_format"    "image/png"
        "wms_onlineresource"    "<?php 
        echo App::$param['protocol'] ?: "http";
        ?>
://<?php 
        echo $_SERVER['HTTP_HOST'];
        ?>
/ows/<?php 
        echo Connection::$param['postgisdb'];
        ?>
/<?php 
        echo Connection::$param['postgisschema'];
        ?>
/"
        "wfs_onlineresource"    "<?php 
        echo App::$param['protocol'] ?: "http";
        ?>
://<?php 
        echo $_SERVER['HTTP_HOST'];
        ?>
/ows/<?php 
        echo Connection::$param['postgisdb'];
        ?>
/<?php 
        echo Connection::$param['postgisschema'];
        ?>
/"
        "ows_enable_request" "*"
        "wms_enable_request" "*"
        "wfs_namespace_prefix" "gc2"
        "wfs_namespace_uri" "http://eu1.mapcentia.com"
        "wms_encoding" "UTF8"
        "wfs_encoding" "UTF8"
        END
        END
        #
        # Start of reference map
        #

        PROJECTION
        "init=epsg:4326"
        END
        #
        # Start of legend
        #
        LEGEND
        STATUS off
        IMAGECOLOR 255 255 255
        KEYSIZE 18 12

        LABEL
        WRAP "#"
        TYPE truetype
        FONT "arialnormal"
        SIZE 8
        COLOR 0 0 0
        #SHADOWSIZE 2 2
        #BACKGROUNDSHADOWSIZE 1 1
        END
        END
        #
        # Start of scalebar
        #
        SCALEBAR
        STATUS off
        COLOR 255 255 255
        OUTLINECOLOR 0 0 0
        BACKGROUNDCOLOR 0 0 0
        IMAGECOLOR 255 255 255
        UNITS METERS
        INTERVALS 3
        SIZE 150 5
        LABEL
        FONT "courierb"
        SIZE SMALL
        COLOR 0 0 0
        SHADOWSIZE 2 2
        END
        END
        Symbol
        Name 'triangle'
        Type VECTOR
        Filled TRUE
        Points
        0 1
        .5 0
        1 1
        0 1
        END
        END
        SYMBOL
        NAME "circle"
        TYPE ellipse
        FILLED true
        POINTS
        1 1
        END
        END
        Symbol
        Name 'square'
        Type VECTOR
        Filled TRUE
        Points
        0 1
        0 0
        1 0
        1 1
        0 1
        END
        END
        Symbol
        Name 'star'
        Type VECTOR
        Filled TRUE
        Points
        0 .375
        .35 .375
        .5 0
        .65 .375
        1 .375
        .75 .625
        .875 1
        .5 .75
        .125 1
        .25 .625
        END
        END
        SYMBOL
        NAME "hatch1"
        TYPE VECTOR
        POINTS
        0 1 1 0
        END
        END
        SYMBOL
        NAME "dashed1"
        TYPE ELLIPSE
        FILLED TRUE
        POINTS 1 1 END
        #STYLE 4 2 END
        END
        SYMBOL
        NAME "arrow"
        TYPE vector
        FILLED true
        POINTS
        0 0.4
        3 0.4
        3 0
        5 0.8
        3 1.6
        3 1.2
        0 1.2
        0 0.4
        END # POINTS
        ANCHORPOINT 0 0.5
        END # SYMBOL

        # ============================================================================
        # Vector Line Types
        # ============================================================================

        SYMBOL
        NAME "continue"
        TYPE ELLIPSE
        FILLED TRUE
        POINTS 1 1 END
        END

        # --------------------

        SYMBOL
        NAME "dashed-line-short"
        TYPE ELLIPSE
        FILLED TRUE
        POINTS 10 1 END
        #STYLE 5 5 END
        END

        # --------------------

        SYMBOL
        NAME "dashed-line-long"
        TYPE ELLIPSE
        FILLED TRUE
        POINTS 10 10 END
        #STYLE 10 10 END
        END

        # --------------------

        SYMBOL
        NAME "dash-dot"
        TYPE ELLIPSE
        FILLED TRUE
        POINTS 20 6 2 6 END
        #STYLE 20 6 2 6 END
        END

        # --------------------

        SYMBOL
        NAME "dash-dot-dot"
        TYPE ELLIPSE
        FILLED TRUE
        POINTS 1 1 END
        #STYLE 10 6 2 6 2 6 END
        END

        # --------------------

        SYMBOL
        NAME "dot-dot"
        TYPE ELLIPSE
        FILLED TRUE
        POINTS 1 1 END
        #STYLE 2 2 END
        END


        #
        # Start of layers
        #
        <?php 
        $sql = "SELECT * FROM settings.getColumns('geometry_columns.f_table_schema=''" . Connection::$param['postgisschema'] . "''','raster_columns.r_table_schema=''" . Connection::$param['postgisschema'] . "''') ORDER BY sort_id";
        $result = $postgisObject->execQuery($sql);
        if ($postgisObject->PDOerror) {
            ob_get_clean();
            return false;
        }
        while ($row = $postgisObject->fetchRow($result)) {
            if ($row['srid'] > 1) {
                $versioning = $postgisObject->doesColumnExist("{$row['f_table_schema']}.{$row['f_table_name']}", "gc2_version_gid");
                $versioning = $versioning["exists"];
                $workflow = $postgisObject->doesColumnExist("{$row['f_table_schema']}.{$row['f_table_name']}", "gc2_status");
                $workflow = $workflow["exists"];
                $arr = (array) json_decode($row['def']);
                // Cast stdclass to array
                $props = array("label_column", "theme_column");
                foreach ($props as $field) {
                    if (!$arr[$field]) {
                        $arr[$field] = "";
                    }
                }
                $layerArr = array("data" => array($arr));
                $sortedArr = array();
                // Sort classes
                $arr = $arr2 = (array) json_decode($row['class']);
                for ($i = 0; $i < sizeof($arr); $i++) {
                    $last = 1000;
                    foreach ($arr2 as $key => $value) {
                        if ($value->sortid < $last) {
                            $temp = $value;
                            $del = $key;
                            $last = $value->sortid;
                        }
                    }
                    array_push($sortedArr, $temp);
                    unset($arr2[$del]);
                    $temp = null;
                }
                $arr = $sortedArr;
                for ($i = 0; $i < sizeof($arr); $i++) {
                    $arrNew[$i] = (array) \app\inc\Util::casttoclass('stdClass', $arr[$i]);
                    $arrNew[$i]['id'] = $i;
                }
                $classArr = array("data" => $arrNew);
                $primeryKey = $postgisObject->getPrimeryKey("{$row['f_table_schema']}.{$row['f_table_name']}");
                unset($arrNew);
                ?>
                LAYER
                NAME "<?php 
                echo $row['f_table_schema'];
                ?>
.<?php 
                echo $row['f_table_name'];
                ?>
"
                STATUS off


                <?php 
                if ($row['filter']) {
                    ?>
                    FILTER "<?php 
                    echo $row['filter'];
                    ?>
"
                <?php 
                }
                ?>
                <?php 
                if ($layerArr['data'][0]['geotype'] && $layerArr['data'][0]['geotype'] != "Default") {
                    $type = $layerArr['data'][0]['geotype'];
                } else {
                    switch ($row['type']) {
                        case "POINT":
                            $type = "POINT";
                            break;
                        case "LINESTRING":
                            $type = "LINE";
                            break;
                        case "POLYGON":
                            $type = "POLYGON";
                            break;
                        case "MULTIPOINT":
                            $type = "POINT";
                            break;
                        case "MULTILINESTRING":
                            $type = "LINE";
                            break;
                        case "MULTIPOLYGON":
                            $type = "POLYGON";
                            break;
                        case "GEOMETRY":
                            $type = "LINE";
                            break;
                        case "RASTER":
                            $type = "RASTER";
                            break;
                    }
                }
                if ($row['wmssource']) {
                    ?>
                    TYPE RASTER
                    CONNECTIONTYPE WMS
                    CONNECTION "<?php 
                    echo $row['wmssource'];
                    ?>
"
                    PROCESSING "RESAMPLE=AVERAGE"

                <?php 
                } elseif ($row['bitmapsource']) {
                    ?>
                    TYPE RASTER
                    DATA "<?php 
                    echo App::$param['path'] . "/app/tmp/" . Connection::$param["postgisdb"] . "/__bitmaps/" . $row['bitmapsource'];
                    ?>
"
                    #PROCESSING "LOAD_WHOLE_IMAGE=YES"
                    PROCESSING "RESAMPLE=AVERAGE"
                <?php 
                } else {
                    if ($type != "RASTER") {
                        if (!$row['data']) {
                            if (preg_match('/[A-Z]/', $row['f_geometry_column'])) {
                                $dataSql = "SELECT *,\\\"{$row['f_geometry_column']}\\\" as " . strtolower($row['f_geometry_column']) . " FROM \\\"{$row['f_table_schema']}\\\".\\\"{$row['f_table_name']}\\\"";
                            } else {
                                $dataSql = "SELECT * FROM \\\"" . "{$row['f_table_schema']}\\\".\\\"{$row['f_table_name']}\\\"";
                            }
                            if ($versioning || $workflow) {
                                $dataSql .= " WHERE 1=1";
                            }
                            if ($versioning) {
                                $dataSql .= " AND gc2_version_end_date IS NULL";
                            }
                            if ($workflow) {
                                //$dataSql .= " AND gc2_status = 3";
                            }
                        } else {
                            $dataSql = $row['data'];
                        }
                        echo "DATA \"" . strtolower($row['f_geometry_column']) . " FROM ({$dataSql}) as foo USING UNIQUE {$primeryKey['attname']} USING srid={$row['srid']}\"\n";
                        ?>
                        CONNECTIONTYPE POSTGIS
                        CONNECTION "user=<?php 
                        echo Connection::$param['postgisuser'];
                        ?>
 dbname=<?php 
                        echo Connection::$param['postgisdb'];
                        if (Connection::$param['postgishost']) {
                            echo " host=" . Connection::$param['postgishost'];
                        }
                        if (Connection::$param['postgisport']) {
                            echo " port=" . Connection::$param['postgisport'];
                        }
                        if (Connection::$param['postgispw']) {
                            echo " password=" . Connection::$param['postgispw'];
                        }
                        ?>
 <?php 
                        if (!Connection::$param['pgbouncer']) {
                            echo "options='-c client_encoding=UTF8'";
                        }
                        ?>
"
                    <?php 
                    } else {
                        echo "DATA \"PG:host=" . (Connection::$param['mapserverhost'] ?: Connection::$param['postgishost']);
                        echo " port=" . (Connection::$param['mapserverport'] ?: Connection::$param['postgisport'] ?: "5432");
                        echo " dbname='" . Connection::$param['postgisdb'] . "' user='" . Connection::$param['postgisuser'] . "' password='" . Connection::$param['postgispw'] . "'\n\t\t                    schema='{$row['f_table_schema']}' table='{$row['f_table_name']}' mode='2'\"\n";
                        echo "PROCESSING \"CLOSE_CONNECTION=ALWAYS\" \n";
                    }
                    ?>
                    TYPE <?php 
                    echo $type . "\n";
                    ?>

                <?php 
                }
                ?>
                #OFFSITE
                <?php 
                if ($layerArr['data'][0]['offsite']) {
                    echo "OFFSITE " . $layerArr['data'][0]['offsite'] . "\n";
                }
                ?>

                #CLASSITEM
                <?php 
                if ($layerArr['data'][0]['theme_column']) {
                    echo "CLASSITEM '" . $layerArr['data'][0]['theme_column'] . "'\n";
                }
                ?>

                #LABELITEM
                <?php 
                if ($layerArr['data'][0]['label_column']) {
                    echo "LABELITEM '" . $layerArr['data'][0]['label_column'] . "'\n";
                }
                ?>

                #LABELMAXSCALEDENOM
                <?php 
                if ($layerArr['data'][0]['label_max_scale']) {
                    echo "LABELMAXSCALEDENOM " . $layerArr['data'][0]['label_max_scale'] . "\n";
                }
                ?>

                #LABELMINSCALEDENOM
                <?php 
                if ($layerArr['data'][0]['label_min_scale']) {
                    echo "LABELMINSCALEDENOM " . $layerArr['data'][0]['label_min_scale'] . "\n";
                }
                ?>

                #OPACITY
                <?php 
                if ($layerArr['data'][0]['opacity']) {
                    echo "OPACITY  " . $layerArr['data'][0]['opacity'] . "\n";
                }
                ?>

                #MAXSCALEDENOM
                <?php 
                if ($layerArr['data'][0]['maxscaledenom']) {
                    echo "MAXSCALEDENOM  " . $layerArr['data'][0]['maxscaledenom'] . "\n";
                }
                ?>

                #MINSCALEDENOM
                <?php 
                if ($layerArr['data'][0]['minscaledenom']) {
                    echo "MINSCALEDENOM  " . $layerArr['data'][0]['minscaledenom'] . "\n";
                }
                ?>

                #MINSCALEDENOM
                <?php 
                if ($layerArr['data'][0]['cluster']) {
                    echo "CLUSTER\n";
                    echo "MAXDISTANCE {$layerArr['data'][0]['cluster']}\n";
                    echo "REGION \"ellipse\"\n";
                    //echo "PROCESSING \"CLUSTER_GET_ALL_SHAPES=false\"\n";
                    echo "END\n";
                }
                ?>

                #LABELMAXSCALE
                METADATA
                "wms_title"    "<?php 
                if ($row['f_table_title']) {
                    echo $row['f_table_title'];
                } else {
                    echo $row['f_table_name'];
                }
                ?>
"
                "wms_srs"    "EPSG:<?php 
                echo $row['srid'];
                ?>
"
                "wms_name"    "<?php 
                echo $row['f_table_name'];
                ?>
"
                "wms_abstract"    "<?php 
                echo $row['f_table_abstract'];
                ?>
"
                "wms_format"    "image/png"
                #"wms_extent" "-180 -90 180 90"
                "appformap_group"  "<?php 
                if ($row['layergroup']) {
                    echo $row['layergroup'];
                } else {
                    echo "Default group";
                }
                ?>
"
                "appformap_queryable"    "true"
                "appformap_loader"    "true"
                "wms_enable_request"    "*"
                "gml_include_items" "all"
                "wms_include_items" "all"
                "wfs_featureid" "<?php 
                echo $primeryKey['attname'];
                ?>
"
                "gml_geometries"    "<?php 
                echo $row['f_geometry_column'];
                ?>
"
                "gml_<?php 
                echo $row['f_geometry_column'];
                ?>
_type" "<?php 
                echo (substr($row['type'], 0, 5) == "MULTI" ? "multi" : "") . strtolower($type);
                ?>
"
                <?php 
                if ($row['wmssource']) {
                    $wmsCon = str_replace(array("layers", "LAYERS"), "LAYER", $row['wmssource']);
                    echo "\"wms_get_legend_url\" \"{$wmsCon}&REQUEST=getlegendgraphic\"\n";
                }
                ?>
                <?php 
                if ($layerArr['data'][0]['query_buffer']) {
                    echo "\"appformap_query_buffer\" \"" . $layerArr['data'][0]['query_buffer'] . "\"\n";
                }
                ?>
                END
                PROJECTION
                "init=epsg:<?php 
                echo $row['srid'];
                ?>
"
                END
                TEMPLATE "test"
                <?php 
                if (is_array($classArr['data'])) {
                    foreach ($classArr['data'] as $class) {
                        ?>
                        CLASS
                        #NAME
                        <?php 
                        if ($class['name']) {
                            echo "NAME '" . $class['name'] . "'\n";
                        }
                        ?>

                        #EXPRESSION
                        <?php 
                        if ($class['expression']) {
                            if ($layerArr['data'][0]['theme_column']) {
                                echo "EXPRESSION \"" . $class['expression'] . "\"\n";
                            } else {
                                echo "EXPRESSION (" . $class['expression'] . ")\n";
                            }
                        } elseif (!$class['expression'] and $layerArr['data'][0]['theme_column']) {
                            echo "EXPRESSION ''\n";
                        }
                        ?>

                        #MAXSCALEDENOM
                        <?php 
                        if ($class['class_maxscaledenom']) {
                            echo "MAXSCALEDENOM {$class['class_maxscaledenom']}\n";
                        }
                        ?>

                        #MINSCALEDENOM
                        <?php 
                        if ($class['class_minscaledenom']) {
                            echo "MINSCALEDENOM {$class['class_minscaledenom']}\n";
                        }
                        ?>

                        STYLE
                        #SYMBOL
                        <?php 
                        if ($class['symbol']) {
                            echo "SYMBOL '" . $class['symbol'] . "'\n";
                        }
                        ?>

                        #PATTERN
                        <?php 
                        if ($class['pattern']) {
                            echo "PATTERN " . $class['pattern'] . " END\n";
                        }
                        ?>

                        #LINECAP
                        <?php 
                        if ($class['linecap']) {
                            echo "LINECAP " . $class['linecap'] . "\n";
                        }
                        ?>

                        #WIDTH
                        <?php 
                        if ($class['width']) {
                            echo "WIDTH " . $class['width'] . "\n";
                        }
                        ?>

                        #COLOR
                        <?php 
                        if ($class['color']) {
                            echo "COLOR " . Util::hex2RGB($class['color'], true, " ") . "\n";
                        }
                        ?>

                        #OUTLINECOLOR
                        <?php 
                        if ($class['outlinecolor']) {
                            echo "OUTLINECOLOR " . Util::hex2RGB($class['outlinecolor'], true, " ") . "\n";
                        }
                        ?>

                        #OPACITY
                        <?php 
                        if ($class['style_opacity']) {
                            echo "OPACITY " . $class['style_opacity'] . "\n";
                        }
                        ?>

                        #SIZE
                        <?php 
                        if ($class['size']) {
                            if (is_numeric($class['size'])) {
                                echo "SIZE " . $class['size'];
                            } else {
                                echo "SIZE [{$class['size']}]";
                            }
                        }
                        echo "\n";
                        ?>

                        #ANGLE
                        <?php 
                        if ($class['angle']) {
                            if (is_numeric($class['angle'])) {
                                echo "ANGLE " . $class['angle'];
                            } else {
                                echo "ANGLE [{$class['angle']}]";
                            }
                        }
                        echo "\n";
                        ?>

                        END # style

                        STYLE
                        #SYMBOL
                        <?php 
                        if ($class['overlaysymbol']) {
                            echo "SYMBOL '" . $class['overlaysymbol'] . "'\n";
                        }
                        ?>

                        #PATTERN
                        <?php 
                        if ($class['overlaypattern']) {
                            echo "PATTERN " . $class['overlaypattern'] . " END\n";
                        }
                        ?>

                        #LINECAP
                        <?php 
                        if ($class['overlaylinecap']) {
                            echo "LINECAP " . $class['overlaylinecap'] . "\n";
                        }
                        ?>

                        #WIDTH
                        <?php 
                        if ($class['overlaywidth']) {
                            echo "WIDTH " . $class['overlaywidth'] . "\n";
                        }
                        ?>

                        #COLOR
                        <?php 
                        if ($class['overlaycolor']) {
                            echo "COLOR " . Util::hex2RGB($class['overlaycolor'], true, " ") . "\n";
                        }
                        ?>

                        #OUTLINECOLOR
                        <?php 
                        if ($class['overlayoutlinecolor']) {
                            echo "OUTLINECOLOR " . Util::hex2RGB($class['overlayoutlinecolor'], true, " ") . "\n";
                        }
                        ?>

                        #OPACITY
                        <?php 
                        if ($class['overlaystyle_opacity']) {
                            echo "OPACITY " . $class['overlaystyle_opacity'] . "\n";
                        }
                        ?>
                        #SIZE
                        <?php 
                        if ($class['overlaysize']) {
                            if (is_numeric($class['overlaysize'])) {
                                echo "SIZE " . $class['overlaysize'];
                            } else {
                                echo "SIZE [{$class['overlaysize']}]";
                            }
                        }
                        echo "\n";
                        ?>
                        #ANGLE
                        <?php 
                        if ($class['overlayangle']) {
                            if (is_numeric($class['overlayangle'])) {
                                echo "ANGLE " . $class['overlayangle'];
                            } else {
                                echo "ANGLE [{$class['overlayangle']}]";
                            }
                        }
                        echo "\n";
                        ?>

                        END # style

                        #TEMPLATE "ttt"

                        #LABEL
                        <?php 
                        if ($class['label']) {
                            ?>
                            LABEL
                            <?php 
                            if ($class['label_text']) {
                                echo "TEXT '" . $class['label_text'] . "'\n";
                            }
                            ?>
                            TYPE truetype
                            FONT <?php 
                            echo ($class['label_font'] ?: "arial") . ($class['label_fontweight'] ?: "normal");
                            ?>
                            SIZE <?php 
                            if ($class['label_size']) {
                                if (is_numeric($class['label_size'])) {
                                    echo $class['label_size'];
                                } else {
                                    echo "[{$class['label_size']}]";
                                }
                            } else {
                                echo "11";
                            }
                            echo "\n";
                            ?>
                            COLOR <?php 
                            echo $class['label_color'] ? Util::hex2RGB($class['label_color'], true, " ") : "1 1 1";
                            echo "\n";
                            ?>
                            OUTLINECOLOR <?php 
                            echo $class['label_outlinecolor'] ? Util::hex2RGB($class['label_outlinecolor'], true, " ") : "255 255 255";
                            echo "\n";
                            ?>
                            SHADOWSIZE 2 2
                            ANTIALIAS true
                            FORCE <?php 
                            echo $class['label_force'] ? "true" : "false";
                            echo "\n";
                            ?>
                            POSITION <?php 
                            echo $class['label_position'] ?: "auto";
                            echo "\n";
                            ?>
                            PARTIALS false
                            MINSIZE 6
                            <?php 
                            if ($class['label_maxscaledenom']) {
                                echo "MAXSCALEDENOM {$class['label_maxscaledenom']}\n";
                            }
                            ?>
                            <?php 
                            if ($class['label_minscaledenom']) {
                                echo "MINSCALEDENOM {$class['label_minscaledenom']}\n";
                            }
                            ?>
                            <?php 
                            if ($class['label_buffer']) {
                                echo "BUFFER {$class['label_buffer']}\n";
                            }
                            ?>
                            <?php 
                            if ($class['label_repeatdistance']) {
                                echo "REPEATDISTANCE {$class['label_repeatdistance']}\n";
                            }
                            ?>

                            <?php 
                            if ($class['label_expression']) {
                                echo "EXPRESSION (" . $class['label_expression'] . ")\n";
                            }
                            ?>
                            #ANGLE
                            <?php 
                            if ($class['label_angle']) {
                                if (is_numeric($class['label_angle']) or $class['label_angle'] == 'auto' or $class['label_angle'] == 'auto2' or $class['label_angle'] == 'follow') {
                                    echo "ANGLE " . $class['label_angle'];
                                } else {
                                    echo "ANGLE [{$class['label_angle']}]";
                                }
                            }
                            echo "\n";
                            ?>
                            WRAP "\n"
                            OFFSET <?php 
                            echo $class['label_offsetx'] ?: "0";
                            ?>
 <?php 
                            echo $class['label_offsety'] ?: "0";
                            ?>
                            STYLE
                            <?php 
                            if ($class['label_backgroundcolor']) {
                                $labelBackgroundColor = Util::hex2RGB($class['label_backgroundcolor'], true, " ");
                                echo "GEOMTRANSFORM 'labelpoly'\n" . "COLOR {$labelBackgroundColor}\n";
                                echo "OUTLINECOLOR {$labelBackgroundColor}\n" . "WIDTH " . ($class['label_backgroundpadding'] ?: "1") . "\n";
                            }
                            ?>
                            END # STYLE
                            END #Label
                        <?php 
                        }
                        ?>
                        #LABEL2
                        <?php 
                        if ($class['label2']) {
                            ?>
                            LABEL
                            <?php 
                            if ($class['label2_text']) {
                                echo "TEXT '" . $class['label2_text'] . "'\n";
                            }
                            ?>
                            TYPE truetype
                            FONT <?php 
                            echo ($class['label2_font'] ? $class['label2_font'] : "arial") . $class['label2_fontweight'] ?: "normal";
                            ?>
                            SIZE <?php 
                            if ($class['label2_size']) {
                                if (is_numeric($class['label2_size'])) {
                                    echo $class['label2_size'];
                                } else {
                                    echo "[{$class['label2_size']}]";
                                }
                            } else {
                                echo "11";
                            }
                            echo "\n";
                            ?>
                            COLOR <?php 
                            echo $class['label2_color'] ? Util::hex2RGB($class['label2_color'], true, " ") : "1 1 1";
                            echo "\n";
                            ?>
                            OUTLINECOLOR <?php 
                            echo $class['label2_outlinecolor'] ? Util::hex2RGB($class['label2_outlinecolor'], true, " ") : "255 255 255";
                            echo "\n";
                            ?>
                            SHADOWSIZE 2 2
                            ANTIALIAS true
                            FORCE <?php 
                            echo $class['label2_force'] ? "true" : "false";
                            echo "\n";
                            ?>
                            POSITION <?php 
                            echo $class['label2_position'] ?: "auto";
                            echo "\n";
                            ?>
                            PARTIALS false
                            MINSIZE 6
                            <?php 
                            if ($class['label2_maxscaledenom']) {
                                echo "MAXSCALEDENOM {$class['label2_maxscaledenom']}\n";
                            }
                            ?>
                            <?php 
                            if ($class['label2_minscaledenom']) {
                                echo "MINSCALEDENOM {$class['label2_minscaledenom']}\n";
                            }
                            ?>
                            <?php 
                            if ($class['label2_buffer']) {
                                echo "BUFFER {$class['label2_buffer']}\n";
                            }
                            ?>
                            <?php 
                            if ($class['label2_repeatdistance']) {
                                echo "REPEATDISTANCE {$class['label2_repeatdistance']}\n";
                            }
                            ?>

                            <?php 
                            if ($class['label2_expression']) {
                                echo "EXPRESSION (" . $class['label2_expression'] . ")\n";
                            }
                            ?>
                            #ANGLE
                            <?php 
                            if ($class['label2_angle']) {
                                if (is_numeric($class['label2_angle']) or $class['label2_angle'] == 'auto' or $class['label2_angle'] == 'auto2' or $class['label2_angle'] == 'follow') {
                                    echo "ANGLE " . $class['label2_angle'];
                                } else {
                                    echo "ANGLE [{$class['label2_angle']}]";
                                }
                            }
                            echo "\n";
                            ?>
                            WRAP "\n"
                            OFFSET <?php 
                            echo $class['label2_offsetx'] ?: "0";
                            ?>
 <?php 
                            echo $class['label2_offsety'] ?: "0";
                            ?>
                            STYLE
                            <?php 
                            if ($class['label2_backgroundcolor']) {
                                $labelBackgroundColor = Util::hex2RGB($class['label2_backgroundcolor'], true, " ");
                                echo "GEOMTRANSFORM 'labelpoly'\n" . "COLOR {$labelBackgroundColor}\n";
                                if ($class['label2_backgroundpadding']) {
                                    echo "OUTLINECOLOR {$labelBackgroundColor}\n" . "WIDTH {$class['label2_backgroundpadding']}\n";
                                }
                            }
                            ?>
                            END # STYLE
                            END #Label
                        <?php 
                        }
                        ?>

                        <?php 
                        if ($class['leader']) {
                            ?>
                            LEADER
                            GRIDSTEP <?php 
                            echo $class['leader_gridstep'] ? $class['leader_gridstep'] : "5";
                            echo "\n";
                            ?>
                            MAXDISTANCE <?php 
                            echo $class['leader_maxdistance'] ? $class['leader_maxdistance'] : "30";
                            echo "\n";
                            ?>
                            STYLE
                            COLOR <?php 
                            echo $class['leader_color'] ? Util::hex2RGB($class['leader_color'], true, " ") : "1 1 1";
                            echo "\n";
                            ?>
                            WIDTH 1
                            END
                            END
                        <?php 
                        }
                        ?>
                        END # Class
                    <?php 
                    }
                }
                ?>
                END #Layer
            <?php 
            }
        }
        ?>
        END #MapFile
        <?php 
        $data = ob_get_clean();
        $path = App::$param['path'] . "/app/wms/mapfiles/";
        $name = Connection::$param['postgisdb'] . "_" . Connection::$param['postgisschema'] . ".map";
        @unlink($path . $name);
        $fh = fopen($path . $name, 'w');
        fwrite($fh, $data);
        fclose($fh);
        return array("success" => true, "message" => "Mapfile written", "ch" => $path . $name);
    }
Example #9
0
    print $cmd . "\n";
    print_r($out);
    $sql = "UPDATE jobs SET lastcheck=:lastcheck WHERE id=:id";
    $values = array(":lastcheck" => 0, ":id" => $jobId);
}
\app\models\Database::setDb("gc2scheduler");
$model = new \app\inc\Model();
$res = $model->prepare($sql);
try {
    $res->execute($values);
} catch (\PDOException $e) {
    print_r($e);
}
if ($extra) {
    \app\models\Database::setDb($db);
    $model = new \app\inc\Model();
    $fieldObj = json_decode($extra);
    $fieldName = $fieldObj->name;
    $fieldType = $fieldObj->type ?: "varchar";
    $fieldValue = $fieldObj->value;
    $sql = "ALTER TABLE \"{$schema}\".\"{$safeName}\" ADD COLUMN {$fieldName} {$fieldType}";
    $res = $model->prepare($sql);
    try {
        $res->execute();
    } catch (\PDOException $e) {
        print_r($e);
    }
    $sql = "UPDATE \"{$schema}\".\"{$safeName}\" SET {$fieldName} =:value";
    $res = $model->prepare($sql);
    try {
        $res->execute(array(":value" => $fieldValue));
Example #10
0
        }
        fclose($handle);
    }
}
\app\models\Database::setDb("gc2scheduler");
$model = new \app\inc\Model();
$res = $model->prepare($sql);
try {
    $res->execute($values);
} catch (\PDOException $e) {
    print_r($e);
}
# Add extra field and insert values
if ($extra && $pass) {
    \app\models\Database::setDb($db);
    $model = new \app\inc\Model();
    $fieldObj = json_decode($extra);
    $fieldName = $fieldObj->name;
    $fieldType = isset($fieldObj->type) ?: "varchar";
    $fieldValue = $fieldObj->value;
    $check = $model->doesColumnExist($schema . "." . $safeName, $fieldName);
    if (!$check["exists"]) {
        $sql = "ALTER TABLE \"{$schema}\".\"{$safeName}\" ADD COLUMN {$fieldName} {$fieldType}";
        print "SQL run:\n";
        print $sql . "\n\n";
        $res = $model->prepare($sql);
        try {
            $res->execute();
        } catch (\PDOException $e) {
            print_r($e);
        }