function GetClassDefinition() { $featureService = $this->site->CreateService(MgServiceType::FeatureService); $featureSourceId = $this->GetFeatureSource(); $classNames = new MgStringCollection(); $classNames->Add("Markup"); $schemas = $featureService->DescribeSchema($featureSourceId, "", $classNames); $schema = $schemas->GetItem(0); $classes = $schema->GetClasses(); return $classes->GetItem(0); }
$oldUserList = GetUserMembers($selectedGroup); // Find users to delete from group. $revokeList = array_diff($oldUserList, $usersSelected); if (!empty($revokeList)) { $usersToDelete = new MgStringCollection(); foreach ($revokeList as $userToDelete) { $usersToDelete->Add($userToDelete); } $site->RevokeGroupMembershipsFromUsers($groupToUpdate, $usersToDelete); } // Find users to add to group. $grantList = array_diff($usersSelected, $oldUserList); if (!empty($grantList)) { $usersToAdd = new MgStringCollection(); foreach ($grantList as $userToAdd) { $usersToAdd->Add($userToAdd); } $site->GrantGroupMembershipsToUsers($groupToUpdate, $usersToAdd); } // Everything is OK. $confirmationMsg = sprintf($confSuccessfulUpdate, $selectedGroup); SaveSessionVars(); header('Location: groupmanagement.php?' . strip_tags(SID)); exit; } } catch (MgException $e) { CheckForFatalMgException($e); $errorMsg = $e->GetExceptionMessage(); } catch (Exception $e) { $errorMsg = $e->getMessage(); }
throw new Exception($errUserIDMissing); } if (empty($userName)) { throw new Exception($errUserNameMissing); } if (empty($password)) { throw new Exception($errPasswordMissing); } if ($password != $passwordConfirmation) { throw new Exception($errPasswordConfirmationFailed); } // Add new user. $site->AddUser($userID, $userName, $password, $description); // Create MgStringCollection with just one user to update group memberships. $usersToUpdate = new MgStringCollection(); $usersToUpdate->Add($userID); // Grant group memberships. if (!empty($groupsSelected)) { $groupMembershipsToGrant = new MgStringCollection(); foreach ($groupsSelected as $groupToGrant) { if ($groupToGrant != MgGroup::Everyone) { $groupMembershipsToGrant->Add($groupToGrant); } } if ($groupMembershipsToGrant->GetCount() > 0) { $site->GrantGroupMembershipsToUsers($groupMembershipsToGrant, $usersToUpdate); } } // Everything is OK. $confirmationMsg = sprintf($confSuccessfulAddition, $userID); $selectedUser = $userID;
private function DescribeRuntimeMapXml($mapDefinition, $map, $sessionId, $mapName, $iconFormat, $iconWidth, $iconHeight, $reqFeatures, $iconsPerScaleRange, $resSvc, $mappingSvc) { //TODO: Caching opportunity here $admin = new MgServerAdmin(); $admin->Open($this->userInfo); $siteVersion = $admin->GetSiteVersion(); $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $xml .= "<RuntimeMap xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"RuntimeMap-2.6.0.xsd\">\n"; // ---------------------- Site Version --------------------------- // $xml .= "<SiteVersion>{$siteVersion}</SiteVersion>\n"; // ---------------------- Session ID --------------------------- // $xml .= "<SessionId>{$sessionId}</SessionId>\n"; // ---------------------- Map Name --------------------------- // $xml .= "<Name>{$mapName}</Name>\n"; // ---------------------- Map Definition --------------------------- // $xml .= "<MapDefinition>{$mapDefinition}</MapDefinition>\n"; // ---------------------- Background Color --------------------------- // $bgColor = $map->GetBackgroundColor(); $xml .= "<BackgroundColor>{$bgColor}</BackgroundColor>\n"; // ---------------------- Display DPI --------------------------- // $dpi = $map->GetDisplayDpi(); $xml .= "<DisplayDpi>{$dpi}</DisplayDpi>"; // ---------------------- Icon MIME Type --------------------------- // if (($reqFeatures & self::REQUEST_LAYER_ICONS) == self::REQUEST_LAYER_ICONS) { switch ($iconFormat) { case "JPG": $xml .= "<IconMimeType>" . MgMimeType::Jpeg . "</IconMimeType>\n"; break; case "GIF": $xml .= "<IconMimeType>" . MgMimeType::Gif . "</IconMimeType>\n"; break; case "PNG8": $xml .= "<IconMimeType>" . MgMimeType::Png . "</IconMimeType>\n"; break; default: $xml .= "<IconMimeType>" . MgMimeType::Png . "</IconMimeType>\n"; break; } } // ---------------------- Coordinate System --------------------------- // $csFactory = new MgCoordinateSystemFactory(); $metersPerUnit = 1.0; $wkt = $map->GetMapSRS(); $csCode = ""; $epsg = ""; try { $cs = $csFactory->Create($wkt); $metersPerUnit = $cs->ConvertCoordinateSystemUnitsToMeters(1.0); $epsg = $cs->GetEpsgCode(); $csCode = $cs->GetCsCode(); } catch (MgException $ex) { } $xml .= "<CoordinateSystem>\n<Wkt>{$wkt}</Wkt>\n<MentorCode>{$csCode}</MentorCode>\n<EpsgCode>{$epsg}</EpsgCode>\n<MetersPerUnit>{$metersPerUnit}</MetersPerUnit>\n</CoordinateSystem>"; // ---------------------- Map Extents--------------------------- // $extents = $map->GetMapExtent(); $ll = $extents->GetLowerLeftCoordinate(); $ur = $extents->GetUpperRightCoordinate(); $minX = $ll->GetX(); $minY = $ll->GetY(); $maxX = $ur->GetX(); $maxY = $ur->GetY(); $xml .= "<Extents>\n<LowerLeftCoordinate><X>{$minX}</X><Y>{$minY}</Y></LowerLeftCoordinate>\n<UpperRightCoordinate><X>{$maxX}</X><Y>{$maxY}</Y></UpperRightCoordinate></Extents>\n"; $layerDefinitionMap = array(); // ---------------------- Optional things if requested --------------------------- // if (($reqFeatures & self::REQUEST_LAYER_STRUCTURE) == self::REQUEST_LAYER_STRUCTURE) { $layers = $map->GetLayers(); $layerCount = $layers->GetCount(); //Build our LayerDefinition map for code below that requires it if (($reqFeatures & self::REQUEST_LAYER_ICONS) == self::REQUEST_LAYER_ICONS) { $layerIds = new MgStringCollection(); for ($i = 0; $i < $layerCount; $i++) { $layer = $layers->GetItem($i); $ldfId = $layer->GetLayerDefinition(); $layerIds->Add($ldfId->ToString()); } $layerContents = $resSvc->GetResourceContents($layerIds, null); $layerIdCount = $layerIds->GetCount(); for ($i = 0; $i < $layerIdCount; $i++) { $ldfId = $layerIds->GetItem($i); $content = $layerContents->GetItem($i); $layerDefinitionMap[$ldfId] = $content; } } // ----------- Some pre-processing before we do groups/layers ------------- // $groups = $map->GetLayerGroups(); $groupCount = $groups->GetCount(); for ($i = 0; $i < $groupCount; $i++) { $group = $groups->GetItem($i); $parent = $group->GetGroup(); $xml .= self::CreateGroupItem($group, $parent); } $doc = new DOMDocument(); for ($i = 0; $i < $layerCount; $i++) { $layer = $layers->GetItem($i); $parent = $layer->GetGroup(); $ldf = $layer->GetLayerDefinition(); $layerId = $ldf->ToString(); $layerDoc = null; if (array_key_exists($layerId, $layerDefinitionMap)) { $doc->loadXML($layerDefinitionMap[$layerId]); $layerDoc = $doc; } $xml .= self::CreateLayerItem($reqFeatures, $iconsPerScaleRange, $iconFormat, $iconWidth, $iconHeight, $layer, $parent, $layerDoc, $mappingSvc); } } else { //Base Layer Groups need to be outputted regardless, otherwise a client application doesn't have enough information to build GETTILEIMAGE requests $groups = $map->GetLayerGroups(); $groupCount = $groups->GetCount(); for ($i = 0; $i < $groupCount; $i++) { $group = $groups->GetItem($i); if ($group->GetLayerGroupType() != MgLayerGroupType::BaseMap) { continue; } $parent = $group->GetGroup(); $xml .= self::CreateGroupItem($group, $parent); } } // ------------------------ Finite Display Scales (if any) ------------------------- // $fsCount = $map->GetFiniteDisplayScaleCount(); if ($fsCount > 0) { for ($i = 0; $i < $fsCount; $i++) { $xml .= "<FiniteDisplayScale>"; $xml .= $map->GetFiniteDisplayScaleAt($i); $xml .= "</FiniteDisplayScale>"; } } $xml .= "</RuntimeMap>"; $bs = new MgByteSource($xml, strlen($xml)); $bs->SetMimeType(MgMimeType::Xml); $br = $bs->GetReader(); return $br; }
//connect to the site and get an instance of each service used in this script // $site = new MgSiteConnection(); $site->Open($cred); $featureSrvc = $site->CreateService(MgServiceType::FeatureService); $renderingSrvc = $site->CreateService(MgServiceType::RenderingService); $resourceSrvc = $site->CreateService(MgServiceType::ResourceService); //load the map runtime state // $map = new MgMap(); $map->Open($resourceSrvc, $mapName); $layers = explode(",", $layers); if (count($layers) > 0) { $layerNames = new MgStringCollection(); for ($i = 0; $i < count($layers); $i++) { $layerNames->Add($layers[$i]); } // create a multi-polygon or a multi-geometry containing the input selected features // $inputGeom = MultiGeometryFromSelection($featureSrvc, $map, $inputSel); if ($inputGeom) { // Query all the features belonging the the layer list that intersects with the input geometries // $fi = $renderingSrvc->QueryFeatures($map, $layerNames, $inputGeom, MgFeatureSpatialOperations::Intersects, -1); if ($fi) { $resultSel = $fi->GetSelection(); if ($resultSel) { //return XML header("Content-type: text/xml"); echo $resultSel->ToXml(); }
$oldGroupMemberships = GetGroupMemberships($userID); // Find group memberships to revoke. $revokeList = array_diff($oldGroupMemberships, $groupsSelected); if ($revokeList != null && !empty($revokeList)) { $groupMembershipsToRevoke = new MgStringCollection(); foreach ($revokeList as $groupToRevoke) { $groupMembershipsToRevoke->Add($groupToRevoke); } $site->RevokeGroupMembershipsFromUsers($groupMembershipsToRevoke, $userToUpdate); } // Find new group memberships to grant. $grantList = array_diff($groupsSelected, $oldGroupMemberships); if ($grantList != null && !empty($grantList)) { $groupMembershipsToGrant = new MgStringCollection(); foreach ($grantList as $groupToGrant) { $groupMembershipsToGrant->Add($groupToGrant); } $site->GrantGroupMembershipsToUsers($groupMembershipsToGrant, $userToUpdate); } // Everything is OK. $confirmationMsg = sprintf($confSuccessfulUpdate, $userID); SaveSessionVars(); header('Location: usermanagement.php?' . strip_tags(SID)); exit; } } catch (MgException $e) { CheckForFatalMgException($e); $errorMsg = $e->GetExceptionMessage(); } catch (Exception $e) { $errorMsg = $e->getMessage(); }
function DeleteGroup($groupName) { global $site; global $groupData; // Validate $groups = GetGroupData(); if (empty($groupName) || !array_key_exists($groupName, $groups)) { return false; } // Delete the group $groupToDelete = new MgStringCollection(); $groupToDelete->Add($groupName); $site->DeleteGroups($groupToDelete); // Update local groupData array // Note that this is done rather than calling EnumerateGroups, again, because EnumerateGroups may take some time // to execute. $oldGroupData = array(); CopyArray($groupData, $oldGroupData); $groupData = array(); foreach ($oldGroupData as $key => $val) { if ($key != $groupName) { $groupData[$key] = $val; } } return true; }
SetUserSortColumn($sortColumn); if (array_key_exists($selectedUserID, $_GET)) { $highlightedUser = $_GET[$selectedUserID]; } // Save data, if requested. if (CheckForSaveData()) { // Update admin role. $usersToGrant = new MgStringCollection(); $usersToRevoke = new MgStringCollection(); $roleToUpdate = new MgStringCollection(); $roleToUpdate->Add(ADMIN_ROLE); foreach ($userUpdateList as $userID) { if (in_array($userID, $adminOnList)) { $usersToGrant->Add($userID); } else { $usersToRevoke->Add($userID); } } $site->GrantRoleMembershipsToUsers($roleToUpdate, $usersToGrant); $site->RevokeRoleMembershipsFromUsers($roleToUpdate, $usersToRevoke); $confirmationMsg = $confSuccessfulRoleUpdate; // Update author role. $usersToGrant->Clear(); $usersToRevoke->Clear(); $roleToUpdate->SetItem(0, AUTHOR_ROLE); foreach ($userUpdateList as $userID) { if (in_array($userID, $authorOnList)) { $usersToGrant->Add($userID); } else { $usersToRevoke->Add($userID); }
function RemoveUserFromGroup($group, $username) { try { $user = new MgUserInformation(MG_ADMIN_USER, MG_ADMIN_PASSWD); $siteConnection = new MgSiteConnection(); $siteConnection->Open($user); $site = $siteConnection->GetSite(); $userToRemove = new MgStringCollection(); $userToRemove->Add($username); $groupToUpdate = new MgStringCollection(); $groupToUpdate->Add($group); $site->RevokeGroupMembershipsFromUsers($groupToUpdate, $userToRemove); } catch (MgException $e) { return FALSE; } return TRUE; }
public static function StringToMgStringCollection($string) { $mgCollection = new MgStringCollection(); $stringArray = explode(",", $string); for ($i = 0; $i < count($stringArray); $i++) { $mgCollection->Add($stringArray[$i]); } return $mgCollection; }
$mapObj->mapName = addslashes($mapName); //Any code that may need the map definition xml document can use $mdfDoc $mapContent = $resourceService->GetResourceContent(new MgResourceIdentifier($mapid)); $mdfDoc = DOMDocument::loadXML(ByteReaderToString($mapContent)); $mapObj->backgroundColor = getMapBackgroundColor($map, $mdfDoc); $mapObj->extent = array($oMin->GetX(), $oMin->GetY(), $oMax->GetX(), $oMax->GetY()); $layers = $map->GetLayers(); //layers $mapObj->layers = array(); $layerDefinitionIds = new MgStringCollection(); $featureSourceIds = new MgStringCollection(); for ($i = 0; $i < $layers->GetCount(); $i++) { $layer = $layers->GetItem($i); $lid = $layer->GetLayerDefinition(); $layerDefinitionIds->Add($lid->ToString()); $featureSourceIds->Add($layer->GetFeatureSourceId()); } //Get the layer contents in a single batch $layerDefinitionContents = $resourceService->GetResourceContents($layerDefinitionIds, null); $featureSourceContents = $resourceService->GetResourceContents($featureSourceIds, null); $layerDocs = array(); $fsDocs = array(); for ($i = 0; $i < $layers->GetCount(); $i++) { $ldfContent = $layerDefinitionContents->GetItem($i); $ldfdoc = DOMDocument::LoadXML($ldfContent); array_push($layerDocs, $ldfdoc); $fsContent = $featureSourceContents->GetItem($i); $fsDoc = DOMDocument::LoadXML($fsContent); array_push($fsDocs, $fsDoc); } for ($i = 0; $i < $layers->GetCount(); $i++) {
function SetupTestData() { global $adminUser; global $adminPass; global $user1User; global $user1Pass; global $user2User; global $user2Pass; global $userGroup; $webConfigPath = dirname(__FILE__) . "/../../webconfig.ini"; MgInitializeWebTier($webConfigPath); $mgp = dirname(__FILE__) . "/data/Sheboygan.mgp"; if (!file_exists($mgp)) { echo "Please put Sheboygan.mgp into the /data directory before running this test suite"; die; } if (!is_dir(dirname(__FILE__) . "/../conf/data/test_anonymous/")) { mkdir(dirname(__FILE__) . "/../conf/data/test_anonymous/"); } copy(dirname(__FILE__) . "/data/restcfg_anonymous.json", dirname(__FILE__) . "/../conf/data/test_anonymous/restcfg.json"); if (!is_dir(dirname(__FILE__) . "/../conf/data/test_author/")) { mkdir(dirname(__FILE__) . "/../conf/data/test_author/"); } copy(dirname(__FILE__) . "/data/restcfg_author.json", dirname(__FILE__) . "/../conf/data/test_author/restcfg.json"); if (!is_dir(dirname(__FILE__) . "/../conf/data/test_administrator/")) { mkdir(dirname(__FILE__) . "/../conf/data/test_administrator/"); } copy(dirname(__FILE__) . "/data/restcfg_administrator.json", dirname(__FILE__) . "/../conf/data/test_administrator/restcfg.json"); if (!is_dir(dirname(__FILE__) . "/../conf/data/test_wfsuser/")) { mkdir(dirname(__FILE__) . "/../conf/data/test_wfsuser/"); } copy(dirname(__FILE__) . "/data/restcfg_wfsuser.json", dirname(__FILE__) . "/../conf/data/test_wfsuser/restcfg.json"); if (!is_dir(dirname(__FILE__) . "/../conf/data/test_wmsuser/")) { mkdir(dirname(__FILE__) . "/../conf/data/test_wmsuser/"); } copy(dirname(__FILE__) . "/data/restcfg_wmsuser.json", dirname(__FILE__) . "/../conf/data/test_wmsuser/restcfg.json"); if (!is_dir(dirname(__FILE__) . "/../conf/data/test_group/")) { mkdir(dirname(__FILE__) . "/../conf/data/test_group/"); } copy(dirname(__FILE__) . "/data/restcfg_group.json", dirname(__FILE__) . "/../conf/data/test_group/restcfg.json"); if (!is_dir(dirname(__FILE__) . "/../conf/data/test_mixed/")) { mkdir(dirname(__FILE__) . "/../conf/data/test_mixed/"); } copy(dirname(__FILE__) . "/data/restcfg_mixed.json", dirname(__FILE__) . "/../conf/data/test_mixed/restcfg.json"); $source = new MgByteSource($mgp); $br = $source->GetReader(); $siteConn = new MgSiteConnection(); $userInfo = new MgUserInformation($adminUser, $adminPass); $siteConn->Open($userInfo); $site = new MgSite(); $site->Open($userInfo); //Set up any required users try { $site->AddGroup($userGroup, "Group for mapguide-rest test suite users"); } catch (MgException $ex) { } try { $site->AddUser($user1User, $user1User, $user1Pass, "Test user for mapguide-rest test suite"); } catch (MgException $ex) { } try { $site->AddUser($user2User, $user2User, $user2Pass, "Test user for mapguide-rest test suite"); } catch (MgException $ex) { } try { $groups = new MgStringCollection(); $users = new MgStringCollection(); $groups->Add($userGroup); $users->Add($user1User); $users->Add($user2User); $site->GrantGroupMembershipsToUsers($groups, $users); } catch (MgException $ex) { } $resSvc = $siteConn->CreateService(MgServiceType::ResourceService); $resSvc->ApplyResourcePackage($br); $srcId = new MgResourceIdentifier("Library://Samples/Sheboygan/Data/Parcels.FeatureSource"); $dstId = new MgResourceIdentifier("Library://RestUnitTests/Parcels.FeatureSource"); $resSvc->CopyResource($srcId, $dstId, true); $bsWriteable = new MgByteSource(dirname(__FILE__) . "/data/Parcels_Writeable.FeatureSource.xml"); $brWriteable = $bsWriteable->GetReader(); $resSvc->SetResource($dstId, $brWriteable, null); $rdsdfsource = new MgByteSource(dirname(__FILE__) . "/data/RedlineLayer.sdf"); $rdsdfrdr = $rdsdfsource->GetReader(); $resId = new MgResourceIdentifier("Library://RestUnitTests/RedlineLayer.FeatureSource"); $rdXml = '<?xml version="1.0"?><FeatureSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="FeatureSource-1.0.0.xsd"><Provider>OSGeo.SDF</Provider><Parameter><Name>File</Name><Value>%MG_DATA_FILE_PATH%RedlineLayer.sdf</Value></Parameter></FeatureSource>'; $rdXmlSource = new MgByteSource($rdXml, strlen($rdXml)); $rdXmlRdr = $rdXmlSource->GetReader(); $resSvc->SetResource($resId, $rdXmlRdr, null); $resSvc->SetResourceData($resId, "RedlineLayer.sdf", MgResourceDataType::File, $rdsdfrdr); }
public function GetSelectedFeatures($sessionId, $mapName, $layerName, $format) { $fmt = $this->ValidateRepresentation($format, array("xml", "geojson", "html")); $propList = $this->GetRequestParameter("properties", ""); $pageSize = $this->GetRequestParameter("pagesize", -1); $pageNo = $this->GetRequestParameter("page", -1); $orientation = $this->GetRequestParameter("orientation", "h"); //Internal debugging flag $chunk = $this->GetBooleanRequestParameter("chunk", true); try { $this->EnsureAuthenticationForSite($sessionId); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $resSvc = $siteConn->CreateService(MgServiceType::ResourceService); $featSvc = $siteConn->CreateService(MgServiceType::FeatureService); $map = new MgMap($siteConn); $map->Open($mapName); $selection = new MgSelection($map); $selection->Open($resSvc, $mapName); $layers = $selection->GetLayers(); if ($layers != null) { $lidx = -1; $layerCount = $layers->GetCount(); for ($i = 0; $i < $layerCount; $i++) { $currentlayer = $layers->GetItem($i); if ($currentlayer->GetName() == $layerName) { $lidx = $i; break; } } if ($lidx < 0) { $this->NotFound($this->app->localizer->getText("E_LAYER_NOT_IN_SELECTION", $layerName), $this->GetMimeTypeForFormat($fmt)); } else { $layer = $layers->GetItem($lidx); $bMapped = $this->GetBooleanRequestParameter("mappedonly", "0") == "1"; $transformto = $this->GetRequestParameter("transformto", ""); $transform = null; if ($transformto !== "") { $resId = new MgResourceIdentifier($layer->GetFeatureSourceId()); $tokens = explode(":", $layer->GetFeatureClassName()); $transform = MgUtils::GetTransform($featSvc, $resId, $tokens[0], $tokens[1], $transformto); } $owriter = null; if ($chunk === "0") { $owriter = new MgSlimChunkWriter($this->app); } else { $owriter = new MgHttpChunkWriter(); } //NOTE: This does not do a query to ascertain a total, this is already a pre-computed property of the selection set. $total = $selection->GetSelectedFeaturesCount($layer, $layer->GetFeatureClassName()); if (strlen($propList) > 0) { $tokens = explode(",", $propList); $propNames = new MgStringCollection(); foreach ($tokens as $propName) { $propNames->Add($propName); } $reader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), $propNames); } else { $reader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), $bMapped); } if ($pageSize > 0) { $pageReader = new MgPaginatedFeatureReader($reader, $pageSize, $pageNo, $total); $result = new MgReaderChunkedResult($featSvc, $pageReader, -1, $owriter, $this->app->localizer); } else { $result = new MgReaderChunkedResult($featSvc, $reader, -1, $owriter, $this->app->localizer); } $result->CheckAndSetDownloadHeaders($this->app, $format); if ($transform != null) { $result->SetTransform($transform); } if ($fmt === "html") { $result->SetAttributeDisplayOrientation($orientation); $result->SetHtmlParams($this->app); } $result->Output($format); } } else { $owriter = new MgHttpChunkWriter(); $reader = new MgNullFeatureReader(); $result = new MgReaderChunkedResult($featSvc, $reader, -1, $owriter, $this->app->localizer); if ($fmt === "html") { $result->SetAttributeDisplayOrientation($orientation); $result->SetHtmlParams($this->app); } $result->Output($format); } } catch (MgException $ex) { $this->OnException($ex, $this->GetMimeTypeForFormat($format)); } }
$features = $featureSrvc->SelectFeatures($featureSource, $featureClassName, $query); $featCount = 0; while ($features->ReadNext()) { if ($featCount++ == 1) { break; } } $features->Close(); if ($featCount != 1) { echo "Error: There must be exactly one feature in the set."; ///NOXLATE dbg report only return; } $renderingSrvc = $site->CreateService(MgServiceType::RenderingService); $layerNames = new MgStringCollection(); $layerNames->Add($layer->GetName()); $featInfo = $renderingSrvc->QueryFeatures($map, $layerNames, NULL, MgFeatureSpatialOperations::Intersects, $selText, 1, 2); header('Content-Type: text/xml; charset: UTF-8'); echo $featInfo->ToXml()->ToString(); } } catch (MgException $e) { echo "ClearSelection Exception: " . $e->GetDetails(); } function GetParameters($params) { global $mapName, $sessionId, $selText, $queryInfo; $sessionId = ValidateSessionId(GetParameter($params, 'SESSION')); $mapName = ValidateMapName(GetParameter($params, 'MAPNAME')); if (isset($params['QUERYINFO'])) { $queryInfo = GetIntParameter($params, 'QUERYINFO') == 1; }
GetUsersOrGroupsByRole(false, $selectedRole, $oldGroupsForRoleList); // Find groups to lose role permission. $revokeList = array_diff($oldGroupsForRoleList, $groupsSelected); if ($revokeList != null && !empty($revokeList)) { $permissionsToRevoke = new MgStringCollection(); foreach ($revokeList as $permissionToRevoke) { $permissionsToRevoke->Add($permissionToRevoke); } $site->RevokeRoleMembershipsFromGroups($roleToUpdate, $permissionsToRevoke); } // Find groups to gain role permission. $grantList = array_diff($groupsSelected, $oldGroupsForRoleList); if ($grantList != null && !empty($grantList)) { $permissionsToGrant = new MgStringCollection(); foreach ($grantList as $permissionToGrant) { $permissionsToGrant->Add($permissionToGrant); } $site->GrantRoleMembershipsToGroups($roleToUpdate, $permissionsToGrant); } // Everything is OK. $confirmationMsg = sprintf($confSuccessfulUpdate, $selectedRole); } } catch (MgException $e) { CheckForFatalMgException($e); $errorMsg = $e->GetExceptionMessage(); } catch (Exception $e) { $errorMsg = $e->getMessage(); } ?> <!-- PAGE DEFINITION -->
$thisFile = __FILE__; $pos = strrpos($thisFile, '\\'); if ($pos == false) { $pos = strrpos($thisFile, '/'); } $configFilePath = substr($thisFile, 0, $pos + 1) . "../webconfig.ini"; MgInitializeWebTier($configFilePath); $userInfo = new MgUserInformation($sessionId); $site = new MgSiteConnection(); $site->Open($userInfo); $featureSrvc = $site->CreateService(MgServiceType::FeatureService); $resId = new MgResourceIdentifier($resName); $classCollection = $featureSrvc->GetClasses($resId, $schemaName); $firstClass = substr(strrchr($classCollection->GetItem(0), ":"), 1); $classNames = new MgStringCollection(); $classNames->Add($className); $xml = $featureSrvc->DescribeSchemaAsXml($resId, $schemaName, $classNames); // Parse the xml for encoded characters, however, the 'xmlns' attribute under 'targetNamespace' element // cannot contain the translated or encoded characters. This replaces '-xffXX-' with 'ffXX' for that // particular string while the rest of the encoded chars are translated properly. $subXml = substr($xml, strpos($xml, 'xs:element'), -1); $subXml = preg_replace("/-x([A-Za-z0-9]{1,4})-/e", "html_entity_decode('&#'.hexdec('\$1').';',ENT_NOQUOTES,'UTF-8')", $subXml); $subXml = preg_replace("/_x([A-Za-z0-9]{1,4})-/e", "html_entity_decode('&#'.hexdec('\$1').';',ENT_NOQUOTES,'UTF-8')", $subXml); $xml = substr_replace($xml, $subXml, strpos($xml, 'xs:element'), -1); $nameSpaceStart = strpos($xml, 'targetNamespace="'); $nameSpaceEnd = strpos($xml, '"', $nameSpaceStart + 17); $nameSpace = substr($xml, $nameSpaceStart, $nameSpaceEnd - $nameSpaceStart); $nameSpaceModified = preg_replace("/-x([A-Za-z0-9]{1,4})-/e", "html_entity_decode('&#'.hexdec('\$1').';',ENT_NOQUOTES,'UTF-8')", $nameSpace); $nameSpaceModified = preg_replace("/_x([A-Za-z0-9]{1,4})-/e", "html_entity_decode('&#'.hexdec('\$1').';',ENT_NOQUOTES,'UTF-8')", $nameSpace); $xml = str_replace($nameSpace, $nameSpaceModified, $xml); $xml = preg_replace("/-x([A-Za-z0-9]{1,4})-/e", "'\$1'", $xml);
function BuildLayerTree($map, $resSrvc) { $tree = array(); $knownGroups = array(); $unresolved = array(); $groups = $map->GetLayerGroups(); for ($i = 0; $i < $groups->GetCount(); $i++) { $rtGroup = $groups->GetItem($i); $node = new TreeItem($rtGroup->GetName(), true, $rtGroup, null); $knownGroups[$node->name] = $node; $parentGroup = $rtGroup->GetGroup(); if ($parentGroup == null) { array_push($tree, $node); } else { $parentName = $parentGroup->GetName(); $parentNode = $knownGroups[$parentName]; if ($parentNode != null) { $parentNode->Attach($node); } else { $node->parentName = $parentName; array_push($unresolved, $node); } } } if (count($unresolved) > 0) { for ($i = 0; $i < $count($unresolved); $i++) { $node = $unresolved[$i]; $parentNode = $knownGroups[$node->parentName]; if ($parentNode != null) { $parentNode->Attach($node); } else { array_push($tree, $node); } //should not happen. place group in the root if parent is not known } } // Get the layers $layers = $map->GetLayers(); // Get the resource Ids of the layers $resIds = new MgStringCollection(); for ($i = 0; $i < $layers->GetCount(); $i++) { $rtLayer = $layers->GetItem($i); $resId = $rtLayer->GetLayerDefinition(); $resIds->Add($resId->ToString()); } $layersData = $resSrvc->GetResourceContents($resIds, null); for ($i = 0; $i < $layers->GetCount(); $i++) { $rtLayer = $layers->GetItem($i); $node = new TreeItem($rtLayer->GetName(), false, $rtLayer, $layersData->GetItem($i)); $parentGroup = $rtLayer->GetGroup(); if ($parentGroup == null) { array_push($tree, $node); } else { $parentNode = $knownGroups[$parentGroup->GetName()]; if ($parentNode != null) { $parentNode->Attach($node); } else { array_push($tree, $node); } //should not happen. place layer in the root if parent is not known } } return $tree; }
/** * Queries the configured feature source and returns a MgReader based on the current GET query parameters and adapter configuration */ protected function CreateQueryOptions($single) { $query = new MgFeatureQueryOptions(); $this->EnsureQualifiedClassName(); $tokens = explode(":", $this->className); $clsDef = null; $clsDef = $this->featSvc->GetClassDefinition($this->featureSourceId, $tokens[0], $tokens[1]); if ($single === true) { if ($this->featureId == null) { throw new Exception($this->app->localizer->getText("E_NO_FEATURE_ID_SET")); } $idType = MgPropertyType::String; if ($this->featureIdProp == null) { $idProps = $clsDef->GetIdentityProperties(); if ($idProps->GetCount() == 0) { throw new Exception($this->app->localizer->getText("E_CANNOT_QUERY_NO_ID_PROPS", $this->className, $this->featureSourceId->ToString())); } else { if ($idProps->GetCount() > 1) { throw new Exception($this->app->localizer->getText("E_CANNOT_QUERY_MULTIPLE_ID_PROPS", $this->className, $this->featureSourceId->ToString())); } else { $idProp = $idProps->GetItem(0); $this->featureIdProp = $idProp->GetName(); $idType = $idProp->GetDataType(); } } } else { $props = $clsDef->GetProperties(); $iidx = $props->IndexOf($this->featureIdProp); if ($iidx >= 0) { $propDef = $props->GetItem($iidx); if ($propDef->GetPropertyType() != MgFeaturePropertyType::DataProperty) { throw new Exception($this->app->localizer->getText("E_ID_PROP_NOT_DATA", $this->featureIdProp)); } } else { throw new Exception($this->app->localizer->getText("E_ID_PROP_NOT_FOUND", $this->featureIdProp)); } } if ($idType == MgPropertyType::String) { $query->SetFilter($this->featureIdProp . " = '" . $this->featureId . "'"); } else { $query->SetFilter($this->featureIdProp . " = " . $this->featureId); } } else { $flt = $this->app->request->get("filter"); if ($flt != null) { $query->SetFilter($flt); } $bbox = $this->app->request->get("bbox"); if ($bbox != null) { $parts = explode(",", $bbox); if (count($parts) == 4) { $wktRw = new MgWktReaderWriter(); $geom = $wktRw->Read(MgUtils::MakeWktPolygon($parts[0], $parts[1], $parts[2], $parts[3])); $query->SetSpatialFilter($clsDef->GetDefaultGeometryPropertyName(), $geom, MgFeatureSpatialOperations::EnvelopeIntersects); } } } if (isset($this->app->ComputedProperties)) { $compProps = $this->app->ComputedProperties; foreach ($compProps as $alias => $expression) { $this->computedPropertyList[$alias] = $expression; } } $bAppliedComputedProperties = false; if (count($this->computedPropertyList) > 0) { foreach ($this->computedPropertyList as $alias => $expression) { $query->AddComputedProperty($alias, $expression); $bAppliedComputedProperties = true; } } //If computed properties were applied, add all properties from the class definition if no //explicit property list supplied if ($bAppliedComputedProperties && count($this->propertyList) == 0) { $clsProps = $clsDef->GetProperties(); for ($i = 0; $i < $clsProps->GetCount(); $i++) { $propDef = $clsProps->GetItem($i); $query->AddFeatureProperty($propDef->GetName()); } } else { if (count($this->propertyList) > 0) { foreach ($this->propertyList as $propName) { $query->AddFeatureProperty($propName); } } } $orderby = $this->app->request->get("orderby"); $orderOptions = $this->app->request->get("orderoption"); if ($orderby != null) { if ($orderOptions == null) { $orderOptions = "asc"; } $orderPropNames = explode(",", $orderby); //If you have a comma in your property names, it's your own fault :) $orderProps = new MgStringCollection(); foreach ($orderPropNames as $propName) { $orderProps->Add($propName); } $orderOpt = MgOrderingOption::Ascending; if (strtolower($orderOptions) === "desc") { $orderOpt = MgOrderingOption::Descending; } $query->SetOrderingFilter($orderProps, $orderOpt); } return $query; }
public function SelectFeatures($resId, $schemaName, $className, $format) { //Check for unsupported representations $fmt = $this->ValidateRepresentation($format, array("xml", "html", "geojson")); $mimeType = $this->GetMimeTypeForFormat($fmt); try { $sessionId = ""; if ($resId->GetRepositoryType() == MgRepositoryType::Session) { $sessionId = $resId->GetRepositoryName(); } $this->EnsureAuthenticationForSite($sessionId, true, $mimeType); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $site = $siteConn->GetSite(); $this->VerifyWhitelist($resId->ToString(), $mimeType, "SELECTFEATURES", $fmt, $site, $this->userName); $featSvc = $siteConn->CreateService(MgServiceType::FeatureService); $query = new MgFeatureQueryOptions(); $filter = $this->GetRequestParameter("filter", ""); $propList = $this->GetRequestParameter("properties", ""); $orderby = $this->GetRequestParameter("orderby", ""); $orderOptions = $this->GetRequestParameter("orderoption", "asc"); $maxFeatures = $this->GetRequestParameter("maxfeatures", ""); $transformto = $this->GetRequestParameter("transformto", ""); $bbox = $this->GetRequestParameter("bbox", ""); $pageSize = $this->GetRequestParameter("pagesize", -1); $pageNo = $this->GetRequestParameter("page", -1); //Internal debugging flag $chunk = $this->GetBooleanRequestParameter("chunk", true); if ($pageNo >= 0 && $pageSize === -1) { $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "pagesize"), $mimeType); } if ($filter !== "") { $query->SetFilter($filter); } $limit = -1; if ($maxFeatures !== "") { $limit = intval($maxFeatures); } if ($propList !== "") { $propNames = explode(",", $propList); //If you have a comma in your property names, it's your own fault :) foreach ($propNames as $propName) { $query->AddFeatureProperty($propName); } } if ($orderby !== "") { $orderPropNames = explode(",", $orderby); //If you have a comma in your property names, it's your own fault :) $orderProps = new MgStringCollection(); foreach ($orderPropNames as $propName) { $orderProps->Add($propName); } $orderOpt = MgOrderingOption::Ascending; if (strtolower($orderOptions) === "desc") { $orderOpt = MgOrderingOption::Descending; } $query->SetOrderingFilter($orderProps, $orderOpt); } $transform = null; if ($transformto !== "") { $transform = MgUtils::GetTransform($featSvc, $resId, $schemaName, $className, $transformto); } if ($bbox !== "") { $parts = explode(",", $bbox); if (count($parts) == 4) { $wktRw = new MgWktReaderWriter(); $geom = $wktRw->Read(MgUtils::MakeWktPolygon($parts[0], $parts[1], $parts[2], $parts[3])); //Transform the bbox if we have the flag indicating so $bboxIsTargetCs = $this->GetBooleanRequestParameter("bboxistargetcs", false); if ($bboxIsTargetCs) { //Because it has been declared the bbox is in target coordiantes, we have to transform that bbox back to the //source, which means we need an inverse transform $invTx = MgUtils::GetTransform($featSvc, $resId, $schemaName, $className, $transformto, true); $geom = $geom->Transform($invTx); } $clsDef = $featSvc->GetClassDefinition($resId, $schemaName, $className); $query->SetSpatialFilter($clsDef->GetDefaultGeometryPropertyName(), $geom, MgFeatureSpatialOperations::EnvelopeIntersects); } } $reader = $featSvc->SelectFeatures($resId, "{$schemaName}:{$className}", $query); $owriter = null; if ($chunk === "0") { $owriter = new MgSlimChunkWriter($this->app); } else { $owriter = new MgHttpChunkWriter(); } if ($pageSize > 0) { if ($pageNo < 1) { $pageNo = 1; } $pageReader = new MgPaginatedFeatureReader($reader, $pageSize, $pageNo, $limit); $result = new MgReaderChunkedResult($featSvc, $pageReader, $limit, $owriter, $this->app->localizer); } else { $result = new MgReaderChunkedResult($featSvc, $reader, $limit, $owriter, $this->app->localizer); } $result->CheckAndSetDownloadHeaders($this->app, $format); if ($transform != null) { $result->SetTransform($transform); } if ($fmt === "html") { $result->SetHtmlParams($this->app); } $result->Output($format); } catch (MgException $ex) { $this->OnException($ex, $mimeType); } }
SetGroupSortDirection($sortDirection); if (array_key_exists($selectedGroupID, $_GET)) { $highlightedGroup = $_GET[$selectedGroupID]; } // Save data, if requested. if (CheckForSaveData()) { // Update admin role. $groupsToGrant = new MgStringCollection(); $groupsToRevoke = new MgStringCollection(); $roleToUpdate = new MgStringCollection(); $roleToUpdate->Add(ADMIN_ROLE); foreach ($groupUpdateList as $groupName) { if (in_array($groupName, $adminOnList)) { $groupsToGrant->Add($groupName); } else { $groupsToRevoke->Add($groupName); } } $site->GrantRoleMembershipsToGroups($roleToUpdate, $groupsToGrant); $site->RevokeRoleMembershipsFromGroups($roleToUpdate, $groupsToRevoke); $confirmationMsg = $confSuccessfulRoleUpdate; // Update author role. $groupsToGrant->Clear(); $groupsToRevoke->Clear(); $roleToUpdate->SetItem(0, AUTHOR_ROLE); foreach ($groupUpdateList as $groupName) { if (in_array($groupName, $authorOnList)) { $groupsToGrant->Add($groupName); } else { $groupsToRevoke->Add($groupName); }