/**
  * Selects all WMS of the current user from the database.
  * Then it creates the corresponding WMS object and returns
  * these objects as an array.
  * 
  * @return wms[]
  * @param $appId String
  */
 public static function selectMyWmsByApplication($appId)
 {
     // check if user is permitted to access the application
     $currentUser = new User(Mapbender::session()->get("mb_user_id"));
     $appArray = $currentUser->getApplicationsByPermission(false);
     if (!in_array($appId, $appArray)) {
         $e = new mb_warning("class_wms.php: selectMyWmsByApplication(): User '" . $currentUser . "' is not allowed to acces application '" . $appId . "'.");
         return array();
     }
     // get WMS of this application
     $sql = "SELECT fkey_wms_id FROM gui_wms WHERE " . "fkey_gui_id = \$1 ORDER BY gui_wms_position";
     $v = array($appId);
     $t = array('s');
     $res = db_prep_query($sql, $v, $t);
     // instantiate PHP objects and store in array
     $wmsArray = array();
     while ($row = db_fetch_array($res)) {
         $currentWms = new wms();
         $currentWms->createObjFromDB($appId, $row["fkey_wms_id"]);
         array_push($wmsArray, $currentWms);
     }
     return $wmsArray;
 }
 */

var ol_map = Mapbender.modules[options.target[0]];
ol_map.mapbenderEvents.mapInstantiated.register(function () {
	var ol_map = Mapbender.modules[options.target[0]];
<?php 
require_once dirname(__FILE__) . "/../php/mb_validateSession.php";
require_once dirname(__FILE__) . "/../classes/class_wms.php";
$sql = "SELECT fkey_wms_id FROM gui_wms WHERE fkey_gui_id = \$1 ORDER BY gui_wms_position";
$v = array(Mapbender::session()->get("mb_user_gui"));
$t = array('s');
$res = db_prep_query($sql, $v, $t);
$cnt = 0;
while ($row = db_fetch_array($res)) {
    $mywms = new wms();
    $mywms->createObjFromDB(Mapbender::session()->get("mb_user_gui"), $row["fkey_wms_id"]);
    // create the first OL-layer as baselayer
    $isBaseLayer = $cnt === 0 ? true : false;
    $mywms->createOlObjFromWMS($isBaseLayer);
    $cnt++;
}
?>
	// fire the mapInstantiated event
	// often the controls will be listening to this event 
	ol_map.mapbenderEvents.layersAdded.trigger();
	// fire the mapInstantiated event
	ol_map.mapbenderEvents.mapReady.trigger();
});


                 if (is_string($val)) {
                     $currentWms->createObjFromXML($val);
                 }
             }
             array_push($wmsArray, $currentWms);
             $wmcGetApi->mergeWmsArray($wmsArray);
             $wmsArray = array();
         } else {
             $singleAssocArray[$key] = $val;
         }
     }
 }
 //get WMS by ID with settings of given application
 if (array_key_exists('application', $singleAssocArray) && array_key_exists('id', $singleAssocArray)) {
     $currentWms = new wms();
     $currentWms->createObjFromDB($singleAssocArray['application'], $singleAssocArray['id']);
     array_push($wmsArray, $currentWms);
     $options['visible'] = $singleAssocArray['visible'] === "1" ? true : false;
     $options['zoom'] = $singleAssocArray['zoom'] === "1" ? true : false;
     $wmcGetApi->mergeWmsArray($wmsArray, $options);
     $wmsArray = array();
     $singleAssocArray = array();
 } elseif (array_key_exists('url', $singleAssocArray)) {
     $currentWms = new wms();
     $currentWms->createObjFromXML($singleAssocArray['url']);
     array_push($wmsArray, $currentWms);
     if ($singleAssocArray['visible']) {
         $options['visible'] = $singleAssocArray['visible'] === "1" ? true : false;
     }
     if ($singleAssocArray['zoom']) {
         $options['zoom'] = $singleAssocArray['zoom'] === "1" ? true : false;
# 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";
require_once dirname(__FILE__) . "/../classes/class_wms.php";
require_once dirname(__FILE__) . "/../classes/class_administration.php";
$wms_id = $_GET["wms_id"];
$gui_id = $_GET["gui_id"];
$user_id = $_SESSION["mb_user_id"];
$noHtml = intval($_GET["noHtml"]);
$js = "";
// check if user is allowed to access this wms
$admin = new administration();
if ($admin->getWmsPermission($wms_id, $user_id)) {
    $mywms = new wms();
    if ($gui_id !== '') {
        $mywms->createObjFromDB($gui_id, $wms_id);
    } else {
        $mywms->createObjFromDBNoGui($wms_id);
    }
    if ($noHtml) {
        $output .= $mywms->createJsObjFromWMS_(false);
    } else {
        $output .= $mywms->createJsObjFromWMS_(true);
    }
    $js .= administration::convertOutgoingString($output);
    unset($output);
} else {
    $e = new mb_exception("You are not allowed to access this WMS (WMS ID " . $wms_id . ").");
}
if ($noHtml) {
    echo $js;