Copyright (c) 2002, DM Solutions Group Inc. * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ include_once(dirname(__FILE__)."/../Widget.php"); include_once(dirname(__FILE__)."/../Button.php"); include_once(dirname(__FILE__)."/../Popup.php"); include_once( COMMON."/phpwms/dbf.php"); include_once( COMMON."/phpwms/server_data_manager.php"); /** * a simple widget to link to another page */ class WMSBrowser extends CWCWidget { var $mszWMSCacheDirectory; var $mbUseUserSession = false; var $moButton; var $moPopup; /** * construct a new WMSBrowser widget */ function WMSBrowser() { // invoke constructor of parent parent::CWCWidget(); $this->maAttributes["WMSCACHEDIRECTORY"] = new StringAttribute( "WMSCACHEDIRECTORY", false); $this->maAttributes["USEUSERSESSION"] = new BooleanAttribute( "USEUSERSESSION", false); $this->maAttributes["PREVIEWEXTENTS"] = new StringAttribute( "PREVIEWEXTENTS", false); $this->maAttributes["PREVIEWSRS"] = new StringAttribute( "PREVIEWSRS", false); $this->moButton = new CWCButton( $this ); $this->moPopup = new CWCPopup( $this ); $this->mnPriority = PRIORITY_SUPER; // set the description for this widget $this->szWidgetDescription = <<mnMaturityLevel = MATURITY_BETA; } function InitDefaults() { $oApp = GetChameleonApplication(); parent::InitDefaults(); $this->moButton->InitDefaults(); //this widget should never belong to a toolset $this->maParams["TOOLSET"] = ""; $this->moButton->SetOnClick( 'clickWMSBrowser' ); $this->moPopup->mszLink = $_SESSION['gszCoreWebPath']."/widgets/WMSBrowser/WMSBrowser.php?"; if (isset($this->maParams["USEUSERSESSION"])) $this->mbUseUserSession = (strtoupper($this->maParams["USEUSERSESSION"]) == "TRUE") ? true : false; if (isset($this->maParams["PREVIEWEXTENTS"])) $_SESSION['WMSBROWSER_PREVIEWEXTENTS'] = $this->maParams['PREVIEWEXTENTS']; if (isset($this->maParams["PREVIEWSRS"])) $_SESSION['WMSBROWSER_PREVIEWSRS'] = $this->maParams['PREVIEWSRS']; if (isset($this->maParams["WMSCACHEDIRECTORY"])) { $this->mszWMSCacheDirectory = $oApp->resolvePath2($this->maParams["WMSCACHEDIRECTORY"], $_SESSION['gszAppPath']); } else { $this->mszWMSCacheDirectory = realpath($_SESSION['gszCorePath']."/../data"); } if (!isset($_SESSION['gszServerDataPath'])) { if ($this->mbUseUserSession) { $szDir = str_replace("\\", "/", getSessionSavePath()."/data/"); // Check if data exist in user dir if (!is_dir($szDir)) mkdir($szDir); // copy content of WMS cache dir to user directory $hDir = opendir($this->mszWMSCacheDirectory); while ($szFile = readdir($hDir)) { if (is_file($this->mszWMSCacheDirectory."/".$szFile)) copy($this->mszWMSCacheDirectory."/".$szFile, $szDir."/".$szFile); } $_SESSION["gszServerDataPath"] = $szDir; } else $_SESSION["gszServerDataPath"] = $this->mszWMSCacheDirectory; } } /** * Add WMS layer if any specified */ function ParseURL() { $this->moButton->ParseURL(); if ($this->isVarSet( "WMS_LAYERS_TOADD" ) && $this->getVar( "WMS_LAYERS_TOADD" ) != "") { $szSelectedLayers = $this->getVar( "WMS_LAYERS_TOADD" ); //check the projection attribute before adding WMS layers $szProj = $this->moMapObject->oMap->getProjection(); //initialize the layers array; $aszLayers = array(); if ( $szProj == "" ) { $_SESSION['gErrorManager']->setError(ERR_WARNING, "Projection must be set in map file to add WMS layers!" ); $bWMSProjectionWarning = 1; } else { $aszLayers = explode (',',$szSelectedLayers); foreach($aszLayers as $szLayer) { // add the layer to the map if (is_numeric($szLayer)); { $oWMSDatabase = new WMSDatabase( $_SESSION["gszServerDataPath"] ); $oServerDataManager = new ServerDataManager( $oWMSDatabase ); $oWMSLayer = $oServerDataManager->getLayerObj( $szLayer ); if ($oWMSLayer == null) { $_SESSION['gErrorManager']->setError(ERR_WARNING, "ERROR: could not add layer $szLayer to map!" ); return false; } $oLayer = ms_newLayerObj( $this->moMapObject->oMap, $oWMSLayer ); // get the current map projection $szTempMapProj = $this->moMapObject->oMap->getprojection(); // only set the projection if it's set in the map if ( strlen( trim( $szTempMapProj ) ) > 0 ) { // set layer projection $oLayer->setprojection( $szTempMapProj ); } $_SESSION['gszCurrentState'] = $this->moMapObject->saveState(); } } } } return true; } function GetJavascriptFunctions() { $aReturn = $this->moButton->GetJavascriptFunctions(); $szJsFunctionName = "BrowseWMSCallBack"; $szFunction = <<mszHTMLForm}.WMS_LAYERS_TOADD.value = szSelectedLayers; {$this->mszHTMLForm}.submit(); } else if ( actionId == 1) // cancel { if (!wh.closed) wh.close(); } else if ( actionId == 2) // submit only { {$this->mszHTMLForm}.submit(); } return; } EOT; $aReturn[$szJsFunctionName] = $szFunction; $szPopup = $this->moPopup->DrawPublish(); $szJsFunctionName = "clickWMSBrowser"; $szFunction = <<