public function auth($key = null, $level = array("all" => true), $neverAllowSubUser = false) { if ($_SESSION['subuser'] == \app\conf\Connection::$param['postgisschema'] && $neverAllowSubUser == false) { $response['success'] = true; } elseif ($_SESSION['subuser']) { $text = "You don't have privileges to do this. Please contact the database owner, who can grant you privileges."; if (sizeof($level) == 0) { $response['success'] = false; $response['message'] = $text; $response['code'] = 403; } else { $layer = new \app\models\Layer(); $privileges = (array) json_decode($layer->getValueFromKey($key, "privileges")); //print_r($_SESSION); $subuserLevel = $privileges[$_SESSION['usergroup'] ?: $_SESSION['subuser']]; if (!isset($level[$subuserLevel])) { $response['success'] = false; $response['message'] = $text; $response['code'] = 403; } else { $response['success'] = true; } } } else { $response['success'] = true; } return $response; }
public function createMapFromTable($table) { $split = explode(".", $table); $type = $split[1]; if (mb_substr($type, 0, 1, 'utf-8') == "_") { $type = "a" . $type; } $tableObj = new \app\models\Table($table); $schema = $tableObj->getMapForEs(); $map = array("mappings" => array($type => array("properties" => array("properties" => array("type" => "object", "properties" => array()))))); $layer = new \app\models\Layer(); $esTypes = $layer->getElasticsearchMapping($table); $arr = array(); foreach ($esTypes["data"] as $key => $value) { $arr[$value["column"]] = array("elasticsearchtype" => $value["elasticsearchtype"], "format" => $value["format"], "index" => $value["index"], "analyzer" => $value["analyzer"], "index_analyzer" => $value["index_analyzer"], "search_analyzer" => $value["search_analyzer"], "type" => $value["type"], "boost" => $value["boost"], "null_value" => $value["null_value"]); } foreach ($schema as $key => $value) { $pgType = $value["type"]; $mapArr = array(); $mapArr["type"] = $arr[$key]["elasticsearchtype"]; if (isset($arr[$key]["format"]) && $arr[$key]["format"]) { $mapArr["format"] = $arr[$key]["format"]; } if (isset($arr[$key]["index"]) && $arr[$key]["index"]) { $mapArr["index"] = $arr[$key]["index"]; } if (isset($arr[$key]["analyzer"]) && $arr[$key]["analyzer"]) { $mapArr["analyzer"] = $arr[$key]["analyzer"]; } if (isset($arr[$key]["search_analyzer"]) && $arr[$key]["search_analyzer"]) { $mapArr["search_analyzer"] = $arr[$key]["search_analyzer"]; } if (isset($arr[$key]["index_analyzer"]) && $arr[$key]["index_analyzer"]) { $mapArr["index_analyzer"] = $arr[$key]["index_analyzer"]; } if (isset($arr[$key]["boost"]) && $arr[$key]["boost"]) { $mapArr["boost"] = $arr[$key]["boost"]; } if (isset($arr[$key]["null_value"]) && $arr[$key]["null_value"]) { $mapArr["null_value"] = $arr[$key]["null_value"]; } if ($pgType == "geometry") { if ($mapArr["type"] == "geo_point") { $map["mappings"][$type]["properties"]["geometry"]["properties"]["coordinates"] = $mapArr; } else { $map["mappings"][$type]["properties"]["geometry"] = $mapArr; } } else { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = $mapArr; } } $response = array("map" => $map); return $response["map"]["mappings"]; }
public function createCluster($distance, $data) { $layer = new \app\models\Layer(); $geometryType = $this->geometryType ?: $layer->getValueFromKey($this->layer, "type"); if ($geometryType != "POINT" && $geometryType != "MULTIPOINT") { $response['success'] = false; $response['message'] = "Only point layers can be clustered"; $response['code'] = 400; return $response; } $this->reset(); // Set layer def $def = $this->tile->get(); if (!$def['success']) { $response['success'] = false; $response['message'] = "Error"; $response['code'] = 400; return $response; } $def["data"][0]["cluster"] = $distance; $def["data"][0]["meta_tiles"] = true; $def["data"][0]["meta_size"] = 4; $defJson = json_encode($def["data"][0]); $res = $this->tile->update($defJson); if (!$res['success']) { $response['success'] = false; $response['message'] = "Error"; $response['code'] = 400; return $response; } //Set single class if (\app\conf\App::$param["mapserver_ver_7"]) { $ClusterFeatureCount = "Cluster_FeatureCount"; } else { $ClusterFeatureCount = "Cluster:FeatureCount"; } $expression = "[{$ClusterFeatureCount}]=1"; $name = "Single"; $res = $this->update(0, self::createClass($geometryType, $name, $expression, 10, "#0000FF", $data)); if (!$res['success']) { $response['success'] = false; $response['message'] = "Error"; $response['code'] = 400; return $response; } //Set cluster class $expression = "[{$ClusterFeatureCount}]>1"; $name = "Cluster"; $data->labelText = "[{$ClusterFeatureCount}]"; $data->labelSize = "9"; $data->labelPosition = "cc"; $data->symbolSize = "50"; $data->overlaySize = "35"; $data->overlayColor = "#00FF00"; $data->overlaySymbol = "circle"; $data->symbol = "circle"; $data->opacity = "25"; $data->overlayOpacity = "70"; $data->force = true; $res = $this->update(1, self::createClass($geometryType, $name, $expression, 20, "#00FF00", $data)); if (!$res['success']) { $response['success'] = false; $response['message'] = "Error"; $response['code'] = 400; return $response; } $response['success'] = true; $response['message'] = "Updated 2 classes"; $this->storeWizard(json_encode($data)); return $response; }
public function getXml($schema) { $hostName = \app\conf\App::$param['host']; $postgisdb = $this->postgisdb; $postgisschema = $schema; $tables = new \app\models\Layer(); $meta = $tables->getAll(false, \app\inc\Session::isAuth()); $rows = $meta['data']; foreach ($rows as $arr) { if ($arr['baselayer'] == "t") { $baseLayer = $arr['f_table_schema'] . "." . $arr['f_table_name']; } if ($schema == $arr['f_table_schema']) { if ($arr['f_table_title']) { $titles[$arr['f_table_name']] = $arr['f_table_title']; } else { $titles[$arr['f_table_name']] = $arr['f_table_name']; } if ($arr['layergroup']) { $groups[$arr['f_table_name']] = $arr['layergroup']; } else { $groups[$arr['f_table_name']] = "Default group"; } } } $xml .= "<BaseMap>\n"; $xml .= "\n\t<BaseMapSource>\n\t <Label>Base Map</Label>\n <Extent srs='EPSG:3857'>\n <LowerCorner>-180 -90</LowerCorner>\n <UpperCorner>180 90</UpperCorner>\n </Extent>\n <DefaultBaseMap/>\n\t</BaseMapSource>"; if ($baseLayer) { $xml .= "<BaseMapSource>\n\t <Label>{$baseLayer}</Label>\n\t <Extent srs='EPSG:3857'>\n\t\t<LowerCorner>-20037508.34 -20037508.34</LowerCorner>\n\t\t<UpperCorner>20037508.34 20037508.34</UpperCorner>\n\t </Extent>"; $xml .= "\t\t<WMSServer src='{$hostName}/wms/{$postgisdb}/{$postgisschema}/'>\n"; $xml .= "\t\t\t<Layer id='{$baseLayer}'></Layer>\n"; $xml .= "\t\t</WMSServer>"; $xml .= "</BaseMapSource>"; } foreach ($rows as $row) { if ($schema == $row['f_table_schema']) { //$table = new \app\models\Table("{$row['f_table_schema']}.{$row['f_table_name']}"); $xml .= "<BaseMapSource supplemental='true'>\n"; if ($row['f_table_title']) { $xml .= "\t<Label>{$row['f_table_title']}</Label>\n"; } else { $xml .= "\t<Label>{$row['f_table_name']}</Label>\n"; } $xml .= "<Extent srs='EPSG:3857'>\n\t\t<LowerCorner>-20037508.34 -20037508.34</LowerCorner>\n\t\t<UpperCorner>20037508.34 20037508.34</UpperCorner>\n\t </Extent>"; $xml .= "\t\t<WMSServer src='{$hostName}/wms/{$postgisdb}/{$postgisschema}/'>\n"; if ($baseLayer) { $xml .= "\t\t\t<Layer id='{$baseLayer}'></Layer>\n"; } $xml .= "\t\t\t<Layer id='{$postgisschema}.{$row['f_table_name']}'></Layer>\n"; $xml .= "\t\t</WMSServer>"; $xml .= "</BaseMapSource>\n"; } } /* End of writing WMS as baselayers */ $xml .= "</BaseMap>\n"; /* Start of writing WFS as overlays */ $xml .= "<Overlays>\n"; foreach ($rows as $row) { if ($schema == $row['f_table_schema'] && !$row['wmssource']) { $table = new \app\models\Table("{$row['f_table_schema']}.{$row['f_table_name']}"); switch ($row['type']) { case "POINT": $geoType = "point"; break; case "LINESTRING": $geoType = "line"; break; case "POLYGON": $geoType = "polygon"; break; case "MULTIPOINT": $geoType = "multipoint"; break; case "MULTILINESTRING": $geoType = "multiline"; break; case "MULTIPOLYGON": $geoType = "multipolygon"; break; } $xml .= "<DataLayer editable='true' canAdd='true' canDelete='true'>\n"; $xml .= "\t<DataSource>\n"; $xml .= "\t\t<WFSLayer src='{$hostName}/wfs/{$postgisdb}/{$postgisschema}/4326' shapeType='{$geoType}' typeName='{$postgisdb}:{$row['f_table_name']}'/>\n"; $xml .= "\t</DataSource>\n"; $xml .= "\t<GeometryField property='{$row['f_geometry_column']}'/>\n"; $xml .= "\t<Form>\n"; $cartomobileArr = (array) json_decode($row['cartomobile']); foreach ($table->metaData as $key => $value) { if ($value['type'] != "geometry" && $key != $table->primeryKey['attname'] && $cartomobileArr[$key]->available == 1) { $xml .= "\t\t<FormField property='{$key}'>\n"; $xml .= "\t\t\t<Label>{$key}</Label>\n"; if (!$cartomobileArr[$key]->cartomobiletype) { switch ($table->metaData[$key]['type']) { case "int": $type = "Number"; break; case "number": $type = "Number"; break; case "string": $type = "SingleText"; break; case "text": $type = "TextBox"; break; } } elseif ($cartomobileArr[$key]->cartomobiletype == "PictureURL") { $type = "SingleText"; } else { $type = $cartomobileArr[$key]->cartomobiletype; } $xml .= "\t\t\t<{$type} "; switch ($type) { case "ChoiceList": $xml .= ">\n"; $arr = (array) json_decode($cartomobileArr[$key]->properties); foreach ($arr as $key => $choice) { $xml .= "\t\t\t\t<Choice value='{$key}'>{$choice}</Choice>\n"; } $xml .= "\t\t\t</ChoiceList>\n"; break; case "Picture": $arr = (array) json_decode($cartomobileArr[$key]->properties); foreach ($arr as $key => $value) { $xml .= "{$key}='{$value}' "; } $xml .= "/>\n"; break; default: $xml .= "/>\n"; break; } $xml .= "\t\t</FormField>\n"; } } $xml .= "\t</Form>\n"; //$xml.="\t<PinField property='".$table->primeryKey['attname']."'/>\n"; if ($row['f_table_title']) { $xml .= "\t<Label>{$row['f_table_title']}</Label>\n"; } else { $xml .= "\t<Label>{$row['f_table_name']}</Label>\n"; } $xml .= "</DataLayer>\n"; } } $xml .= "</Overlays>\n"; /* End of writing WFS as overlays */ return $xml; }