public function createFromDb($id)
 {
     try {
         $wmc = new wmc();
         $res = $wmc->createFromDb($id);
         if ($res === false) {
             throw new Exception("Could not create WMC from DB.");
         }
     } catch (Exception $e) {
         throw new Exception("Could not create WMC from DB.");
     }
     return $wmc;
 }
function initWmcById($wmcId, $wmcAction)
{
    $wmc = new wmc();
    $wmc->createFromDb($wmcId);
    $updatedWMC = $wmc->updateUrlsFromDb();
    $wmc->createFromXml($updatedWMC);
    $jsArray = $wmc->toJavaScript();
    if ($jsArray) {
        $jsString = implode("", $jsArray);
        echo $jsString;
    } else {
        $e = new mb_exception("WMC could not be loaded.");
    }
}
     $currentWmc->append($wmcXml);
     // load the merged WMC
     $jsArray = $currentWmc->toJavaScript();
     if (is_array($jsArray) && count($jsArray) > 0) {
         $resultObj["javascript"] = $jsArray;
         $ajaxResponse->setResult($resultObj);
         $ajaxResponse->setSuccess(true);
     } else {
         $ajaxResponse->setMessage(_mb("WMC could not be appended."));
         $ajaxResponse->setSuccess(false);
     }
     break;
 case 'setWMCPublic':
     $wmcId = $ajaxResponse->getParameter("id");
     $public = $ajaxResponse->getParameter("isPublic") == 1 ? true : false;
     $wmc = new wmc();
     $wmc->createFromDb($wmcId);
     if ($wmc->setPublic($public)) {
         $ajaxResponse->setMessage(_mb("Updated public flag"));
         $ajaxResponse->setSuccess(true);
     } else {
         $ajaxResponse->setMessage(_mb("could not update public flag"));
         $ajaxResponse->setSuccess(false);
     }
     break;
 case 'checkConstraints':
     $checkLayerIdExists = $ajaxResponse->getParameter("checkLayerIdExists");
     $checkLayerIdValid = $ajaxResponse->getParameter("checkLayerIdValid");
     $checkLayerPermission = $ajaxResponse->getParameter("checkLayerPermission");
     $checkLayerAvailability = $ajaxResponse->getParameter("checkLayerAvailability");
     $wmcId = $ajaxResponse->getParameter("id");
 /**
  * selects the WMC for a given wmc_id.
  *
  * @param integer			the wms id
  * @return string|boolean	either the wmc as string or false when none exists
  * @deprecated
  */
 function getWmcById($id)
 {
     $e = new mb_notice("administration->getWmcById is deprecated, use wmc->getDocument instead!");
     $wmc = new wmc();
     return $wmc->getDocument($id);
 }
$overwrite = $overwrite == "1" ? true : false;
//for debugging, write mapObject to file
if ($lzwCompressed == 'true') {
    //$e = new mb_exception('mod_savewmc_server.php: mapObject: '.implode(',',$mapObject));
    $mapObject = lzw_decompress($mapObject);
    //$e = new mb_exception('mod_savewmc_server.php: mapObject uncompressed: '.$mapObject);
    //$filename = TMPDIR."/formerly_compressed_json.txt";//will be set to new one cause ?
} else {
    //$filename = TMPDIR."/formerly_uncompressed_json.txt";//will be set to new one cause ?
}
//file_put_contents($filename, $mapObject);
//$e = new mb_exception('mod_savewmc_server.php: mapObject is here ;-)');
$mapObject = $json->decode($mapObject);
$e = new mb_notice('mod_savewmc_server.php: mapObject has been decoded from json');
// create WMC object
$wmc = new wmc();
if ($overwrite) {
    $wmc->createFromJs($mapObject, $attributes->title, $extensionData, $attributes->wmc_id);
} else {
    $wmc->createFromJs($mapObject, $attributes->title, $extensionData);
}
if ($saveInSession === 1) {
    // CLEAN SESSION WMC FILES
    //do this by cronjob!
    //$tmp = scandir(TMPDIR);
    // get all files from tmp folder
    /*for($p = 0; $p < count($tmp); $p++) {
    	// match timestamp on begin of the filename
           	if(preg_match("/^([\d]+).*$/i", $tmp[$p],$timestamp)) {
                	// if file older than 24h, remove it.
                	if((time() - $timestamp[1]) >= 86400) { // 86400 = 24h
 /**
  * Appends the layers of another WMC to this WMC.
  *
  * @return void
  * @param $xml2 Object
  */
 public function append($xml2)
 {
     $someWmc = new wmc();
     $someWmc->createFromXml($xml2);
     $this->mainMap->append($someWmc->mainMap);
     if (isset($this->overviewMap) && isset($someWmc->overviewMap)) {
         // There is only one WMS in the overview map; merge, not append
         $this->overviewMap->merge($someWmc->overviewMap);
     }
 }
require_once dirname(__FILE__) . "/../classes/class_connector.php";
function getConfiguration($key)
{
    //check if key param can be found in SESSION,
    // otherwise take it from GET
    if (Mapbender::session()->exists($key)) {
        return Mapbender::session()->get($key);
    }
    return $_GET[$key];
}
$admin = new administration();
$resultObj = array("noPermission" => array("message" => _mb("You as User") . " '" . Mapbender::session()->get("mb_user_name") . "' " . _mb("have no authorization to access following layers."), "wms" => array()), "withoutId" => array("message" => _mb("Following layers come from an unkown origin. There is no information about the links. They may be broken and the underlaying services may not exist anymore!"), "wms" => array()), "unavailable" => array("message" => _mb("The last monitoring had problems with the following layers. Maybe the underlying services will not be able to answer the requests for sometime."), "wms" => array()), "invalidId" => array("message" => _mb("Following layers have been removed from the registry. They may be broken and the underlaying services may not exist anymore!"), "wms" => array()), "wmcTou" => array("message" => ""));
//
// Load WMC from session or application
//
$wmc = new wmc();
$app = Mapbender::session()->get("mb_user_gui");
//$wmcDocSession = Mapbender::session()->get("mb_wmc");
$wmcDocSession = false;
if (Mapbender::session()->get("mb_wmc")) {
    $wmc_filename = Mapbender::session()->get("mb_wmc");
    $wmcDocSession = file_get_contents($wmc_filename);
}
try {
    $loadFromSession = new ElementVar($app, "loadwmc", "loadFromSession");
    if ($wmcDocSession && $loadFromSession->value === "1") {
        //check if session contains a wmc,
        //otherwise create a new wmc from application
        $e = new mb_notice("trying to load session WMC...");
        if (!$wmc->createFromXml($wmcDocSession)) {
            $e = new mb_notice("loading session WMC failed.");
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once dirname(__FILE__) . "/../php/mb_validateSession.php";
$wmc_id = $_GET["wmc_id"];
$download = $_GET["download"];
if ($wmc_id) {
    require_once dirname(__FILE__) . "/../classes/class_wmc.php";
    $wmc = new wmc();
    $wmc_gml = $wmc->getDocument($wmc_id);
    if ($wmc_gml) {
        //Display WMC
        // if "short open tags" is activated, the xml output is interpreted
        // as php, because the XML begins with "<?xml "
        if (ini_get("short_open_tag") == 1) {
            echo htmlentities($wmc_gml);
            $e = new mb_warning("'Allow short open tags' is 'On' in php.ini...you might want to turn it off to allow proper WMC display.'");
        } else {
            if ($download == 'true') {
                header('Content-disposition: attachment; filename=mapbender_wmc.xml');
                header("Content-type: application/xhtml+xml; charset=" . CHARSET);
                echo $wmc_gml;
            } else {
                header("Content-type: application/xhtml+xml; charset=" . CHARSET);