if (is_object($tree)) {
        foreach ($tree as $key => $value) {
            $tree->{$key} = translateTree($value);
        }
    } else {
        if (is_array($tree)) {
            // strings with arguments, like 'Found %d results'
            $tree = call_user_func_array("_mb", $tree);
        } else {
            if (is_string($tree)) {
                $tree = _mb($tree);
            }
        }
    }
    return $tree;
}
$ajaxResponse = new AjaxResponse($_POST);
switch ($ajaxResponse->getMethod()) {
    case "translate":
        $localeObj = new Mb_locale($ajaxResponse->getParameter("locale"));
        $msg_obj = $ajaxResponse->getParameter("data");
        $translated_obj = translateTree($msg_obj);
        $ajaxResponse->setSuccess(true);
        $ajaxResponse->setResult(array("data" => $translated_obj, "locale" => $localeObj->name));
        break;
    default:
        $ajaxResponse->setSuccess(false);
        $ajaxResponse->setMessage(_mb("An unknown error occured."));
        break;
}
$ajaxResponse->send();
        $sql = <<<SQL
\t
SELECT mb_user_wmc.wmc_serial_id as wmc_id, mb_user_wmc.wmc_title, mb_user_wmc.wmc_timestamp, wmc_load_count.load_count FROM mb_user_wmc 
LEFT JOIN wmc_load_count ON wmc_load_count.fkey_wmc_serial_id = mb_user_wmc.wmc_serial_id WHERE wmc_serial_id IN ({$wmcList});

SQL;
        $res = db_query($sql);
        $resultObj = array("header" => array("WMC ID", "Titel", "Timestamp", "Load Count", ""), "data" => array());
        while ($row = db_fetch_row($res)) {
            // convert NULL to '', NULL values cause datatables to crash
            $walk = array_walk($row, create_function('&$s', '$s=strval($s);'));
            $link = "<a class='cancelClickEvent' target='_blank' href='../php/mod_showMetadata.php?" . "languageCode=" . Mapbender::session()->get("mb_lang") . "&resource=wmc&id=" . $row[0] . "'>" . _mb("Metadata") . "</a>";
            array_push($row, $link);
            $resultObj["data"][] = $row;
        }
        $ajaxResponse->setResult($resultObj);
        $ajaxResponse->setSuccess(true);
        break;
    case "getWmcMetadata":
        $wmcId = $ajaxResponse->getParameter("id");
        $sql = <<<SQL
\t
SELECT wmc_serial_id as wmc_id, abstract, wmc_title, 
wmc_timestamp, wmc_timestamp_create, wmc_public 
FROM mb_user_wmc WHERE wmc_serial_id = {$wmcId};

SQL;
        $res = db_query($sql);
        $row = db_fetch_assoc($res);
        $resultObj = array();
        $resultObj['wmc_id'] = $row['wmc_id'];
     if (!$wfsConfIdString) {
         $ajaxResponse->setSuccess($false);
         $ajaxResponse->setMessage("missing wfsConfIdString");
         $ajaxResponse->send();
         break;
     }
     $wfsConfIdString = trim($wfsConfIdString, ',');
     $wfsConfIds = explode(',', $wfsConfIdString);
     $result = array();
     foreach ($wfsConfIds as $wfsId) {
         $currentWfsConf = WfsConfiguration::createFromDb($wfsId);
         if ($currentWfsConf !== null) {
             $result[] = $currentWfsConf;
         }
     }
     $ajaxResponse->setResult($result);
     $ajaxResponse->send();
     break;
 case "getWfsConfs":
     $currentUser = new User(Mapbender::session()->get("mb_user_id"));
     $wfsConfIds = $currentUser->getWfsConfByWfsOwner();
     if ($wfsConfIds === null) {
         $wfsConfIds = array();
     }
     $result = array();
     foreach ($wfsConfIds as $id) {
         $currentWfsConf = WfsConfiguration::createFromDb($id);
         if ($currentWfsConf !== null) {
             $result[] = $currentWfsConf;
         }
     }
# and Simplified BSD license.
# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
require_once dirname(__FILE__) . "/../../core/globalSettings.php";
require_once dirname(__FILE__) . "/../classes/class_administration.php";
require_once dirname(__FILE__) . "/../classes/class_wfs_conf.php";
$ajaxResponse = new AjaxResponse($_POST);
$myGui = $ajaxResponse->getParameter('gui');
$myWms = $ajaxResponse->getParameter('wms');
$myLayer = $ajaxResponse->getParameter('layer');
$myWfsConf = $ajaxResponse->getParameter('wfsConf');
try {
    switch ($ajaxResponse->getMethod()) {
        case "getWfsConfs":
            $result = getWfsConfs($myGui);
            $ajaxResponse->setSuccess(true);
            $ajaxResponse->setResult($result);
            break;
        case "saveLayerWfsConnection":
            $result = saveLayerWfsConnection($myWfsConf, $myGui, $myLayer);
            if ($result === true) {
                $ajaxResponse->setSuccess(true);
            } else {
                $ajaxResponse->setSuccess(false);
                $ajaxResponse->setMessage("An error occured performing UPDATE");
            }
            break;
        default:
            $ajaxResponse->setSuccess(false);
            $ajaxResponse->setMessage("method invalid");
    }
} catch (Exception $E) {
    if (is_object($tree)) {
        foreach ($tree as $key => $value) {
            $tree->{$key} = translateTree($value);
        }
    } else {
        if (is_array($tree)) {
            foreach ($tree as $key => $value) {
                $tree[$key] = translateTree($value);
            }
        } else {
            if (is_string($tree)) {
                $tree = _mb($tree);
            }
        }
    }
    return $tree;
}
$ajaxResponse = new AjaxResponse($_POST);
switch ($ajaxResponse->getMethod()) {
    case "translateServiceData":
        $msg_obj = $ajaxResponse->getParameter("data");
        $translated_obj = translateTree($msg_obj);
        $ajaxResponse->setSuccess(true);
        $ajaxResponse->setResult($translated_obj);
        break;
    default:
        $ajaxResponse->setSuccess(false);
        $ajaxResponse->setMessage(_mb("An unknown error occured."));
        break;
}
$ajaxResponse->send();
                $relation_bbox_x = $extentx / $extenty;
                if ($relation_bbox_x <= $relation_px_x) {
                    $centerx = $minx + $extentx / 2;
                    $minx = $centerx - $relation_px_x * $extenty / 2;
                    $maxx = $centerx + $relation_px_x * $extenty / 2;
                }
                if ($relation_bbox_x > $relation_px_x) {
                    $centery = $miny + $extenty / 2;
                    $miny = $centery - $relation_px_y * $extentx / 2;
                    $maxy = $centery + $relation_px_y * $extentx / 2;
                }
                if ($currentEpsg->frameName) {
                    $epsgObj[$i] = array("frameName" => $currentEpsg->frameName, "newSrs" => $newSrs, "minx" => $minx, "miny" => $miny, "maxx" => $maxx, "maxy" => $maxy);
                } else {
                    $epsgObj[$i] = array("wms" => $currentEpsg->wms, "newSrs" => $newSrs, "minx" => $minx, "miny" => $miny, "maxx" => $maxx, "maxy" => $maxy);
                }
            } else {
                $ajaxResponse->setSuccess(false);
                $ajaxResponse->setMessage(_mb("An unknown error occured."));
                $ajaxResponse->send();
            }
        }
        $ajaxResponse->setSuccess(true);
        $ajaxResponse->setResult($epsgObj);
        break;
    default:
        $ajaxResponse->setSuccess(false);
        $ajaxResponse->setMessage(_mb("An unknown error occured."));
        break;
}
$ajaxResponse->send();
try {
    switch ($method) {
        case "intersect":
            $geometries = $request->getParameter("geometries");
            $clickPoint = $request->getparameter("clickPoint");
            $resultGeometries = array();
            $i = 0;
            foreach ($geometries as $geometry) {
                $sql = "SELECT ST_Intersects ('{$clickPoint}'::geometry, '{$geometry}'::geometry);";
                $dbresult = db_query($sql);
                $row = db_fetch_array($dbresult);
                $result = $row["st_intersects"] == "f" ? false : true;
                if ($result) {
                    $resultGeometries[$i] = $geometry;
                }
                $i++;
            }
            $request->setSuccess(true);
            $request->setResult(array("geometries" => $resultGeometries));
            break;
        default:
            $e = new mb_exception(__FILE__ . ": RPC called with invalid Method '{$method}'");
            $request->setSuccess(false);
            $request->setMessage(__FILE__ . ": RPC called with invalid Method '{$method}'");
    }
} catch (Exception $E) {
    $e = new mb_exception(__FILE__ . ": RPC failed. Exception: '{$E}'");
    $request->setSuccess(false);
    $request->setMessage(__FILE__ . ": RPC failed. Exception: '{$E}'");
}
$request->send();
    //Mapbender::session()->set("mb_wmc",$wmc->xml);
    //$epsgTest=$wmc->mainMap->extent->toJavaScript();
    $epsgString = $wmc->mainMap->extentToJavascript();
    // get epsg code from jquery string
    preg_match('/EPSG:\\d{4,5}/', $epsgString, $matches);
    $epsgString = $matches[0];
    if (preg_match('/EPSG:\\d{4,5}/', $epsgString, $matches)) {
        $epsgString = $matches[0];
        $e = new mb_notice("epsg: " . $epsgString);
        $epsg = str_replace("EPSG:", "", $epsgString);
        Mapbender::session()->set("epsg", $epsg);
    }
    Mapbender::session()->set("previous_gui", Mapbender::session()->get("mb_user_gui"));
    $e = new mb_notice("mod_insertWMCIntoDB: save WMC in session succeeded.");
    $ajaxResponse->setSuccess(true);
    $ajaxResponse->setResult(_mb("saved wmc document to session"));
} else {
    // insert WMC into database
    if (isset($attributes->title)) {
        $attributes->title = trim($attributes->title);
        if ($attributes->title == "") {
            $ajaxResponse->setSuccess(false);
            $ajaxResponse->setMessage(_mb("WMC document must have a title."));
            $ajaxResponse->send();
            exit;
        }
    } else {
        $ajaxResponse->setSuccess(false);
        $ajaxResponse->setMessage(_mb("WMC document must have a title."));
        $ajaxResponse->send();
        exit;
#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
# Copyright (C) 2002 CCGIS
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# 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";
$buttonObj = array();
$sql = "SELECT e_id, gettext(\$1, e_title) AS e_title FROM gui_element WHERE fkey_gui_id = \$2 AND e_element = 'img'";
$v = array(Mapbender::session()->get("mb_lang"), Mapbender::session()->get("mb_user_gui"));
$t = array("s", "s");
$res = db_prep_query($sql, $v, $t);
while ($row = db_fetch_array($res)) {
    array_push($buttonObj, array("id" => $row["e_id"], "title" => $row["e_title"]));
}
$ajaxResponse = new AjaxResponse($_REQUEST);
$ajaxResponse->setResult($buttonObj);
$ajaxResponse->send();
//$output = $json->encode($buttonObj);
//header("Content-type:text/plain; charset=utf-8");
//echo $output;
//ajax wrapper for class_tou.php
$ajaxResponse = new AjaxResponse($_POST);
$json = new Mapbender_JSON();
$touObject = new tou();
//$currentUser = new User();
//$wmc = new wmc();
$resultObj = array();
//obj structure in session for acceptedTou (see class_tou.php):
//acceptedTou {
//		wms [100,101,112],
//		wfs [12,34]
//		}
switch ($ajaxResponse->getMethod()) {
    case 'checkAcceptedTou':
        $result = $touObject->check($ajaxResponse->getParameter("serviceType"), $ajaxResponse->getParameter("serviceId"));
        $ajaxResponse->setResult($result['accepted']);
        //1 or 0
        $ajaxResponse->setMessage(_mb($result['message']));
        $ajaxResponse->setSuccess(true);
        break;
    case 'setAcceptedTou':
        $serviceType = $ajaxResponse->getParameter("serviceType");
        $serviceId = $ajaxResponse->getParameter("serviceId");
        $result = $touObject->set($ajaxResponse->getParameter("serviceType"), $ajaxResponse->getParameter("serviceId"));
        $ajaxResponse->setResult($result['setTou']);
        //1 or 0
        $ajaxResponse->setMessage(_mb($result['message']));
        $ajaxResponse->setSuccess(true);
        break;
        // Invalid command
    // Invalid command
# 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 dirname(__FILE__) . "/mb_validateSession.php";
$epsgObj = array();
$ajaxResponse = new AjaxResponse($_POST);
switch ($ajaxResponse->getMethod()) {
    case "translateServiceData":
        $msg_obj = $ajaxResponse->getParameter("data");
        $newMsgObj = array();
        if (is_array($msg_obj)) {
            foreach ($msg_obj as $wmsId => $wmsObj) {
                $newMsgObj[$wmsId] = array("title" => _mb($wmsObj->title), "layer" => array());
                if (is_array($msg_obj->layer)) {
                    foreach ($wmsObj->layer as $layerId => $layerObj) {
                        $newMsgObj[$wmsId]["layer"][$layerId] = array("title" => _mb($layerObj->title));
                    }
                }
            }
        }
        $ajaxResponse->setSuccess(true);
        $ajaxResponse->setResult($newMsgObj);
        break;
    default:
        $ajaxResponse->setSuccess(false);
        $ajaxResponse->setMessage(_mb("An unknown error occured."));
        break;
}
$ajaxResponse->send();