[Mapbender-commits] r1236 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Mar 20 08:47:20 EDT 2007


Author: christoph
Date: 2007-03-20 08:47:20 -0400 (Tue, 20 Mar 2007)
New Revision: 1236

Modified:
   trunk/mapbender/http/php/mb_listWMCs.php
Log:
refactored according to code conventions

Modified: trunk/mapbender/http/php/mb_listWMCs.php
===================================================================
--- trunk/mapbender/http/php/mb_listWMCs.php	2007-03-19 09:45:26 UTC (rev 1235)
+++ trunk/mapbender/http/php/mb_listWMCs.php	2007-03-20 12:47:20 UTC (rev 1236)
@@ -12,115 +12,92 @@
 # 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.
 
-ob_start(); 
 session_start();
+$gui_id = $_SESSION["mb_user_gui"];
+$user_id = $_SESSION["mb_user_id"];
+
+$action = $_GET["action"];
+$wmcId = $_GET["wmc_id"];
+
+$delWmcId = $_POST["del_wmc_id"];
+
+$form_target = $_SERVER["PHP_SELF"] . "?" . SID;
+
 require_once("../../conf/mapbender.conf");
+require_once("../classes/class_administration.php");
+require_once("../classes/class_mb_exception.php");
+require_once("../classes/class_wmc.php");
+
 $con = db_connect($DBSERVER,$OWNER,$PW);
 db_select_db(DB,$con);
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+	<head>
+		<meta http-equiv="cache-control" content="no-cache">
+		<meta http-equiv="pragma" content="no-cache">
+		<meta http-equiv="expires" content="0">
+		<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET;?>">	
+		<title>Select web map contect document from list</title>
+	</head>
+	<body>
+		<form name='delete_wmc' action='<?php echo $form_target; ?>' method='POST'>
+			<input type='hidden' id='delete_wmc' name='del_wmc_id' value ='' >
+		</form>
 
-<html>
-<head>
-<!-- 
-Licensing: See the GNU General Public License for more details.
-http://www.gnu.org/copyleft/gpl.html
-or:
-mapbender/licence/ 
--->
-<meta http-equiv="cache-control" content="no-cache">
-<meta http-equiv="pragma" content="no-cache">
-<meta http-equiv="expires" content="0">
 <?php
-echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
-?>
-<title>Select web map contect document from list</title>
-</head>
-<body>
-<?php
-echo "<form name='delete_wmc' action='" . $PHP_SELF . "?".SID."' method='POST'>";
-echo "<input type='hidden' id='delete_wmc' name='del_wmc_id' value ='' />";
-echo "</form>";
+function mb_listWMCs($wmcIdArray, $form_target){
+	$display = "<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;background-color: White;'><font align='left' color='#000000'>Ma</font><font color='#0000CE'>p</font><font color='#C00000'>b</font><font color='#000000'>ender WMC list</font></h2>";
+	$display .= "<table width='90%' style='font-family: Arial, Helvetica, sans-serif;font-size : 12px;color: #808080;' border='1' cellpadding='3' rules='rows'><tr style='background-color:#F0F0F0;' width='80px'><td ><b>WMC name</b></td><td><b>last update</b></td><td colspan=5></td></tr>";
 
-function mb_listWMCs($wmcList){
-	$display = "<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;background-color: White;'><font align='left' color='#000000'>Ma</font><font color='#0000CE'>p</font><font color='#C00000'>b</font><font color='#000000'>ender WMC list </font> </h2>";
-	$display .= "<table width='90%' style='font-family: Arial, Helvetica, sans-serif;font-size : 12px;color: #808080;' border='1' cellpadding='3' rules='rows'><tr style='background-color:#F0F0F0;' width='80px'><td ><b>WMC name</b></td><td><b>last update</b></td><td colspan=5></td></tr>";
-	if(count($wmcList)>0){
+	if (count($wmcIdArray) > 0) {
 		$v = array();
 		$t = array();
-		$sql_list_wmcs = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp FROM mb_user_wmc ";
-		$sql_list_wmcs .= "WHERE wmc_id IN (";
-		for($i=0; $i<count($wmcList); $i++){
-			if($i>0){$sql_list_wmcs .= ",";}
-			$sql_list_wmcs .= "$".($i+1);
-			array_push($v, $wmcList[$i]);
+
+		$wmcIdList = "";
+		for ($i = 0; $i < count($wmcIdArray); $i++){
+			if ($i > 0){ 
+				$wmcIdList .= ",";
+			}
+			$wmcIdList .= "$".($i+1);
+			array_push($v, $wmcIdArray[$i]);
 			array_push($t, 's');
 		}
-		$sql_list_wmcs .= ") ";
+		$sql_list_wmcs = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp FROM mb_user_wmc ";
+		$sql_list_wmcs .= "WHERE wmc_id IN (" . $wmcIdList . ") ";
 		$sql_list_wmcs .= "ORDER BY wmc_timestamp DESC";
+		
 		$res_list_wmcs = db_prep_query($sql_list_wmcs, $v, $t);
-		$cnt_list_wmcs = 0;
 		while($row = db_fetch_array($res_list_wmcs)){
-			$display .= "<tr  onmouseover='this.style.backgroundColor = \"#F08080\"' onmouseout='this.style.backgroundColor = \"#ffffff\"'";
-			if(($cnt_list_wmcs % 2) == 0){ $display .= "  ";}
-			$display .= ">";
-			$display .= "<td>".$row["wmc_title"]."</td>";
-			$timestamp = date("M d Y H:i:s", $row["wmc_timestamp"]); 
 			$this_id = $row["wmc_id"];
-			$display .= "<td>".$timestamp. "</td>";
-			
-			$display .= "<td><a href=\"" . $_SERVER['PHP_SELF'] ."?" . SID . "&action=load&wmc_id=".$this_id."\"><img src=\"../img/button_gray/wmc_load.png\" title=\"load this WMC\"  border=0></a></td>";
-			$display .= "<td><a href=\"" . $_SERVER['PHP_SELF'] ."?" . SID . "&action=merge&wmc_id=".$this_id."\"><img src=\"../img/button_gray/wmc_merge.png\" title=\"merge WMC\"  border=0></a></td>";
-			$display .= "<td><a href=\"" . $_SERVER['PHP_SELF'] ."?" . SID . "&action=append&wmc_id=".$this_id."\"><img src=\"../img/button_gray/wmc_append.png\" title=\"append WMC\"  border=0></a></td>";
+			$this_title = $row["wmc_title"];
+			$this_timestamp = date("M d Y H:i:s", $row["wmc_timestamp"]); 
+
+			$display .= "<tr onmouseover='this.style.backgroundColor = \"#F08080\"' onmouseout='this.style.backgroundColor = \"#ffffff\"'>";
+			$display .= "<td>".$this_title."</td>";
+			$display .= "<td>".$this_timestamp. "</td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=load&wmc_id=".$this_id."\"><img src=\"../img/button_gray/wmc_load.png\" title=\"load this WMC\"  border=0></a></td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=merge&wmc_id=".$this_id."\"><img src=\"../img/button_gray/wmc_merge.png\" title=\"merge WMC\"  border=0></a></td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=append&wmc_id=".$this_id."\"><img src=\"../img/button_gray/wmc_append.png\" title=\"append WMC\"  border=0></a></td>";
 			$display .= "<td><a href='../javascripts/mod_displayWmc.php?wmc_id=".$this_id."' target = '_blank'><img src=\"../img/button_gray/wmc_xml.png\" title=\"display WMC XML\"  border=0></a></td>";
-			
-			$display .= "<td><a href=\"" . $_SERVER['PHP_SELF'] ."?" . SID . "&action=delete&wmc_id=".$this_id."\"><img src=\"../img/button_gray/del.png\" title=\"delete this WMC\"  border=0></a></td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=delete&wmc_id=".$this_id."\"><img src=\"../img/button_gray/del.png\" title=\"delete this WMC\"  border=0></a></td>";
 			$display .= "</tr>";
-			$cnt_list_wmcs++;
 		}
-	}else{
+	}
+	else{
 		$display .= "<tr><td>There are no WMCs availiable</td></tr>";
 	}	
 	$display .= "</table>";
 	   
-   return $display;
+	return $display;
 }
 
-require_once("../classes/class_administration.php");
-require_once("../classes/class_wmc.php");
-$admin = new administration();
-$wmcList = $admin->getWmcByOwner($_SESSION["mb_user_id"]);
-		
-if ($_POST["del_wmc_id"] ) {
-	$result = $admin->deleteWmc($_POST["del_wmc_id"], $_SESSION["mb_user_id"]);
-	if (!$result) {
-		echo "<script language='javascript'>";
-		echo "alert('WMC could not be deleted!');";
-		echo "</script>";
-	}
-}
-
-echo mb_listWMCs($wmcList);
-
-if ($_GET["wmc_id"] && $_GET["action"] == "delete" && in_array($_GET["wmc_id"], $wmcList)){
-	echo "<script language='javascript'>";
-	echo "value = confirm('Do you really want to delete this document?');";
-	echo "if (value == true) {";
-	echo "document.delete_wmc.del_wmc_id.value = '" . $_GET["wmc_id"] . "';";
-	echo "document.delete_wmc.submit();";
-	echo "}";
-	echo "</script>";
-}
-
-if ($_GET["wmc_id"] && ($_GET["action"] == "append" || $_GET["action"] == "merge" || $_GET["action"] == "load") && in_array($_GET["wmc_id"], $wmcList)){
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db(DB,$con);
-	$sql = "SELECT e_requires, e_target FROM gui_element WHERE e_id = 'loadwmc' AND fkey_gui_id = '".$_SESSION['mb_user_gui']."'";
+function getTarget($gui_id) {
+	$sql = "SELECT e_requires, e_target FROM gui_element WHERE e_id = 'loadwmc' AND fkey_gui_id = '".$gui_id."'";
 	$res = db_query($sql);
 	$cnt = 0;
 	while($row = db_fetch_array($res)){ 
@@ -128,31 +105,60 @@
 		$e_require = $row["e_requires"];
 		$cnt++;
 	}
-	$target = explode(",", $e_target);
-	if (in_array('mapframe1', $target)) {
-		$mytarget = 'mapframe1';
+	if ($cnt > 1) { 
+		$e = new mb_exception("listWMCs: e_id 'loadwmc' not unique in GUI '" . $gui_id . "'!");
 	}
+
+	$targetArray = explode(",", $e_target);
+	if (in_array('mapframe1', $targetArray)) {
+		return 'mapframe1';
+	}
 	else {
-		$mytarget = $target[0];
+		return trim($targetArray[0]);
 	}
-	$wmc = new wmc();
-	$wmc->createObjFromWMC_id($_GET["wmc_id"]);
-	if ($_GET["action"] == "append" || $_GET["action"] == "merge" || $_GET["action"] == "load") {
-		$js = $wmc->createJsObjFromWMC("window.opener.", trim($mytarget), $_GET["action"]);
-	}	
-	// display all JavaScript statements as debugging text
-	//echo $js;
-	echo "<script language='javascript'>";
-	if($cnt > 1){ echo "alert('addWMS: ID not unique!');\n";}
-	echo $js;
+}
 
-	$title = $wmc->getTitle();
-	if ($title) {$title = "'" . $title . "' ";}
-	echo "alert(\"WMC " . $title . ": " . $_GET["action"] . " successful.\");\n";
+$admin = new administration();
+$wmcIdArray = $admin->getWmcByOwner($user_id);
 
-	echo "window.close();";
-	echo "</script>";
+if (!empty($delWmcId)) {
+	$result = $admin->deleteWmc($delWmcId, $user_id);
+	if (!$result) {
+		echo "<script language='javascript'>";
+		echo "alert('WMC could not be deleted!');";
+		echo "</script>";
+	}
 }
+
+echo mb_listWMCs($wmcIdArray, $form_target);
+		
+if ($wmcId && in_array($wmcId, $wmcIdArray)){
+	if ($action == "delete") {
+		echo "<script language='javascript'>";
+		echo "value = confirm('Do you really want to delete this document?');";
+		echo "if (value == true) {";
+		echo "document.delete_wmc.del_wmc_id.value = '" . $wmcId . "';";
+		echo "document.delete_wmc.submit();";
+		echo "}";
+		echo "</script>";
+	}
+	else if ($action == "append" || $action == "merge" || $action == "load") {
+		$mytarget = getTarget($gui_id);
+
+		$wmc = new wmc();
+		$wmc->createObjFromWMC_id($wmcId);
+		$js = $wmc->createJsObjFromWMC("window.opener.", $mytarget, $action);
+
+		echo "<script language='javascript'>";
+		echo $js;
+		if ($wmc->getTitle()) {
+			$title = "'" . $wmc->getTitle() . "' ";
+		}
+		echo "alert(\"WMC " . $title . ": " . $action . " successful.\");\n";
+		echo "window.close();";
+		echo "</script>";
+	}
+}
 ?>
 </body>
-</html>
+</html>
\ No newline at end of file



More information about the Mapbender_commits mailing list