public function GetClassNames($resId, $schemaName, $format)
 {
     //Check for unsupported representations
     $fmt = $this->ValidateRepresentation($format, array("xml", "json", "html"));
     $sessionId = "";
     if ($resId->GetRepositoryType() == MgRepositoryType::Session) {
         $sessionId = $resId->GetRepositoryName();
     }
     $resIdStr = $resId->ToString();
     $mimeType = $this->GetMimeTypeForFormat($fmt);
     $this->EnsureAuthenticationForSite($sessionId, false, $mimeType);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     $site = $siteConn->GetSite();
     $this->VerifyWhitelist($resIdStr, $mimeType, "GETCLASSNAMES", $fmt, $site, $this->userName);
     $selfUrl = $this->app->config("SelfUrl");
     $that = $this;
     $this->EnsureAuthenticationForHttp(function ($req, $param) use($that, $fmt, $schemaName, $resIdStr, $selfUrl) {
         $param->AddParameter("OPERATION", "GETCLASSES");
         $param->AddParameter("VERSION", "1.0.0");
         if ($fmt === "json") {
             $param->AddParameter("FORMAT", MgMimeType::Json);
         } else {
             if ($fmt === "xml") {
                 $param->AddParameter("FORMAT", MgMimeType::Xml);
             } else {
                 if ($fmt === "html") {
                     $param->AddParameter("FORMAT", MgMimeType::Xml);
                     $param->AddParameter("X-OVERRIDE-CONTENT-TYPE", MgMimeType::Html);
                     $param->AddParameter("XSLSTYLESHEET", "ClassNameList.xsl");
                     $param->AddParameter("XSLPARAM.ASSETPATH", MgUtils::GetSelfUrlRoot($selfUrl) . "/assets");
                 }
             }
         }
         $param->AddParameter("RESOURCEID", $resIdStr);
         $param->AddParameter("SCHEMA", $schemaName);
         $that->ExecuteHttpRequest($req);
     }, false, "", $sessionId, $mimeType);
 }
 public function EnumerateResources($resId, $format)
 {
     //Check for unsupported representations
     $fmt = $this->ValidateRepresentation($format, array("xml", "json", "html"));
     $resIdStr = $resId->ToString();
     $sessionId = $this->GetRequestParameter("session", "");
     $mimeType = $this->GetMimeTypeForFormat($fmt);
     try {
         $this->EnsureAuthenticationForSite($sessionId, false, $mimeType);
         $siteConn = new MgSiteConnection();
         $siteConn->Open($this->userInfo);
         $site = $siteConn->GetSite();
     } catch (MgException $ex) {
         $this->OnException($ex, $mimeType);
         return;
     }
     $this->VerifyWhitelist($resIdStr, $mimeType, "ENUMERATERESOURCES", $fmt, $site, $this->userName);
     $pathInfo = $this->app->request->getPathInfo();
     $selfUrl = $this->app->config("SelfUrl");
     $that = $this;
     $this->EnsureAuthenticationForHttp(function ($req, $param) use($that, $fmt, $resIdStr, $selfUrl, $pathInfo) {
         $param->AddParameter("OPERATION", "ENUMERATERESOURCES");
         $param->AddParameter("VERSION", "1.0.0");
         $param->AddParameter("TYPE", $that->GetRequestParameter("type"));
         $param->AddParameter("COMPUTECHILDREN", $that->GetBooleanRequestParameter("computechildren", "0"));
         //Default the depth to 1 if not specified (think of the MapGuide Server!)
         $param->AddParameter("DEPTH", $that->GetRequestParameter("depth", "1"));
         if ($fmt === "json") {
             $param->AddParameter("FORMAT", MgMimeType::Json);
         } else {
             if ($fmt === "xml") {
                 $param->AddParameter("FORMAT", MgMimeType::Xml);
             } else {
                 if ($fmt === "html") {
                     $thisUrl = $selfUrl . $pathInfo;
                     //Chop off the list.html
                     $rootPath = substr($thisUrl, 0, strlen($thisUrl) - strlen("list.html"));
                     $folderPath = substr($pathInfo, 0, strlen($pathInfo) - strlen("list.html"));
                     $tokens = explode("/", $pathInfo);
                     if (count($tokens) > 3) {
                         //Pop off list.html and current folder name
                         array_pop($tokens);
                         array_pop($tokens);
                         $parentPath = implode("/", $tokens);
                         $param->AddParameter("XSLPARAM.PARENTPATHROOT", $selfUrl . $parentPath);
                     }
                     $param->AddParameter("XSLPARAM.ASSETPATH", MgUtils::GetSelfUrlRoot($selfUrl) . "/assets");
                     $param->AddParameter("XSLPARAM.FOLDERPATH", $folderPath);
                     $param->AddParameter("XSLPARAM.ROOTPATH", $rootPath);
                     $param->AddParameter("FORMAT", MgMimeType::Xml);
                     $param->AddParameter("X-OVERRIDE-CONTENT-TYPE", MgMimeType::Html);
                     $param->AddParameter("XSLSTYLESHEET", "ResourceList.xsl");
                 }
             }
         }
         $param->AddParameter("RESOURCEID", $resIdStr);
         $that->ExecuteHttpRequest($req);
     }, false, "", $sessionId, $mimeType);
 }
 public function LaunchResourcePreview($resId)
 {
     $sessionId = "";
     if ($resId->GetRepositoryType() == MgRepositoryType::Session) {
         $sessionId = $resId->GetRepositoryName();
     } else {
         $sessionId = $this->app->request->params("session");
     }
     $this->EnsureAuthenticationForSite($sessionId, true);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     if ($sessionId == null) {
         $site = $siteConn->GetSite();
         $sessionId = $site->CreateSession();
         $userInfo = new MgUserInformation($sessionId);
         $siteConn->Open($userInfo);
     }
     $selfUrl = MgUtils::GetSelfUrlRoot($this->app->config("SelfUrl"));
     switch ($resId->GetResourceType()) {
         case MgResourceType::FeatureSource:
             $this->app->redirect("{$selfUrl}/../schemareport/describeschema.php?viewer=basic&schemaName=&className=&resId=" . $resId->ToString() . "&sessionId=" . $sessionId);
             break;
         case MgResourceType::LayerDefinition:
             $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
             $featSvc = $siteConn->CreateService(MgServiceType::FeatureService);
             $bbox = $this->GetLayerBBOX($featSvc, $resSvc, $resId);
             $content = file_get_contents(dirname(__FILE__) . "/../res/preview_mapdefinition.xml");
             $content = sprintf($content, $bbox->coordsys, $bbox->minx, $bbox->maxx, $bbox->miny, $bbox->maxy, $this->CreateLayerXmlFragment($resId), "");
             //echo $content; die;
             $mdfSource = new MgByteSource($content, strlen($content));
             $mdfbr = $mdfSource->GetReader();
             $mdfPreviewId = new MgResourceIdentifier("Session:{$sessionId}//Preview.MapDefinition");
             $resSvc->SetResource($mdfPreviewId, $mdfbr, NULL);
             $content = file_get_contents(dirname(__FILE__) . "/../res/preview_weblayout.xml");
             $content = sprintf($content, $mdfPreviewId->ToString());
             $source = new MgByteSource($content, strlen($content));
             $br = $source->GetReader();
             $previewId = new MgResourceIdentifier("Session:{$sessionId}//Preview.WebLayout");
             $resSvc->SetResource($previewId, $br, NULL);
             $this->app->redirect("{$selfUrl}/../mapviewerajax/?SESSION={$sessionId}&USERNAME=Anonymous&WEBLAYOUT=" . $previewId->ToString());
             break;
         case MgResourceType::MapDefinition:
             $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
             //$map = new MgMap();
             //$map->Create($resSvc, $mdfId, $resId->GetName());
             //$sel = new MgSelection($map);
             //$sel->Save($resSvc, $resId->GetName());
             //$map->Save($resSvc, $resId);
             $content = file_get_contents(dirname(__FILE__) . "/../res/preview_weblayout.xml");
             $content = sprintf($content, $resId->ToString());
             $source = new MgByteSource($content, strlen($content));
             $br = $source->GetReader();
             $previewId = new MgResourceIdentifier("Session:{$sessionId}//Preview.WebLayout");
             $resSvc->SetResource($previewId, $br, NULL);
             $this->app->redirect("{$selfUrl}/../mapviewerajax/?SESSION={$sessionId}&USERNAME=Anonymous&WEBLAYOUT=" . $previewId->ToString());
             break;
         case MgResourceType::SymbolDefinition:
             $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
             $mapSvc = $siteConn->CreateService(MgServiceType::MappingService);
             $content = file_get_contents(dirname(__FILE__) . "/../res/preview_symbollayer.xml");
             $content = sprintf($content, $resId->ToString());
             $ldfSource = new MgByteSource($content, strlen($content));
             $ldfBr = $ldfSource->GetReader();
             $ldfId = new MgResourceIdentifier("Session:{$sessionId}//SymbolPreview.LayerDefinition");
             $resSvc->SetResource($ldfId, $ldfBr, NULL);
             $br = $mapSvc->GenerateLegendImage($ldfId, 42, 100, 50, "PNG", 4, 0);
             //NOXLATE
             $this->OutputByteReader($br);
             break;
         case "WatermarkDefinition":
             $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
             $content = file_get_contents(dirname(__FILE__) . "/../res/preview_mapdefinition.xml");
             $content = sprintf($content, self::XY_COORDSYS, 0, 0, 0, 0, "", $this->CreateWatermarkFragment($resId));
             //echo $content; die;
             $mdfSource = new MgByteSource($content, strlen($content));
             $mdfbr = $mdfSource->GetReader();
             $mdfPreviewId = new MgResourceIdentifier("Session:{$sessionId}//Preview.MapDefinition");
             $resSvc->SetResource($mdfPreviewId, $mdfbr, NULL);
             $content = file_get_contents(dirname(__FILE__) . "/../res/preview_weblayout.xml");
             $content = sprintf($content, $mdfPreviewId->ToString());
             $source = new MgByteSource($content, strlen($content));
             $br = $source->GetReader();
             $previewId = new MgResourceIdentifier("Session:{$sessionId}//Preview.WebLayout");
             $resSvc->SetResource($previewId, $br, NULL);
             $this->app->redirect("{$selfUrl}/../mapviewerajax/?SESSION={$sessionId}&USERNAME=Anonymous&WEBLAYOUT=" . $previewId->ToString());
             break;
         default:
             $this->BadRequest($this->app->localizer->getText("E_UNPREVIEWABLE_RESOURCE_TYPE"), MgMimeType::Html);
             break;
     }
 }
 public function GetFeaturesKml($resId, $format = "kml")
 {
     //Check for unsupported representations
     $fmt = $this->ValidateRepresentation($format, array("kml", "kmz"));
     $bbox = $this->GetRequestParameter("bbox", null);
     $dpi = $this->GetRequestParameter("dpi", 96);
     $width = $this->GetRequestParameter("width", null);
     $height = $this->GetRequestParameter("height", null);
     $drawOrder = $this->GetRequestParameter("draworder", null);
     $sessionId = "";
     if ($resId->GetRepositoryType() == MgRepositoryType::Session) {
         $sessionId = $resId->GetRepositoryName();
     } else {
         $sessionId = $this->GetRequestParameter("session", "");
     }
     if ($width == null) {
         $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "width"), $this->GetMimeTypeForFormat($format));
     }
     if ($height == null) {
         $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "height"), $this->GetMimeTypeForFormat($format));
     }
     if ($drawOrder == null) {
         $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "draworder"), $this->GetMimeTypeForFormat($format));
     }
     if ($bbox == null) {
         $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "bbox"), $this->GetMimeTypeForFormat($format));
     }
     //We still need the mapagent URL so that GETFEATURESKML can generate legend icons from
     //within the operation
     $agentUri = MgUtils::GetSelfUrlRoot($this->app->config("SelfUrl")) . "/../mapagent/mapagent.fcgi";
     $that = $this;
     $this->EnsureAuthenticationForHttp(function ($req, $param) use($that, $fmt, $resId, $bbox, $width, $height, $drawOrder, $dpi) {
         $param->AddParameter("OPERATION", "GETFEATURESKML");
         $param->AddParameter("VERSION", "1.0.0");
         $param->AddParameter("LAYERDEFINITION", $resId->ToString());
         $param->AddParameter("BBOX", $bbox);
         $param->AddParameter("WIDTH", $width);
         $param->AddParameter("HEIGHT", $height);
         $param->AddParameter("DRAWORDER", $drawOrder);
         $param->AddParameter("DPI", $dpi);
         $param->AddParameter("FORMAT", strtoupper($fmt));
         $param->AddParameter("X-CHUNK-RESPONSE", "true");
         $that->ExecuteHttpRequest($req);
     }, true, $agentUri, $sessionId);
 }