[Mapbender-commits] r6592 - in trunk/mapbender: http/classes http/php lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jul 13 07:45:54 EDT 2010


Author: christoph
Date: 2010-07-13 11:45:54 +0000 (Tue, 13 Jul 2010)
New Revision: 6592

Added:
   trunk/mapbender/lib/editGroup.php
Modified:
   trunk/mapbender/http/classes/class_group.php
   trunk/mapbender/http/php/mod_editFilteredGroup.php
   trunk/mapbender/http/php/mod_editGroup.php
Log:
unified editGroup, editFilteredGroup
added fields from other projects
uses class group, no sql in sources

Modified: trunk/mapbender/http/classes/class_group.php
===================================================================
--- trunk/mapbender/http/classes/class_group.php	2010-07-13 07:22:23 UTC (rev 6591)
+++ trunk/mapbender/http/classes/class_group.php	2010-07-13 11:45:54 UTC (rev 6592)
@@ -108,7 +108,7 @@
 		$sql_group_create = "INSERT INTO mb_group (mb_group_name) VALUES ($1)";
 		$v = array($this->name);
 		$t = array("s");
-		$insert_result = db_query($sql_group_create);
+		$insert_result = db_prep_query($sql_group_create, $v, $t);
 
 		if (!$insert_result) {
 			db_rollback();
@@ -145,14 +145,21 @@
 	public function change($changes) {
         //FIXME: validate input
 
-        if ($changes->owner) {
-			$owner = User::byName($changes->owner);
-        }
 		$this->name = $changes->name ? $changes->name : $this->name;
-		$this->owner = $changes->owner ? $owner->id : $this->owner;
+		$this->owner = $changes->owner ? $changes->owner : $this->owner;
 		$this->description = $changes->description ? $changes->description : $this->description;
-		$this->id = $changes->id ? $changes->id->value : $this->id;
-        return true;
+		$this->id = $changes->id ? $changes->id : $this->id;
+     	$this->title = $changes->title ? $changes->title : $this->title;
+		$this->address = $changes->address ? $changes->address : $this->address;
+		$this->postcode = $changes->postcode ? $changes->postcode : $this->postcode;
+		$this->city = $changes->city ? $changes->city : $this->city;
+		$this->stateorprovince = $changes->stateorprovince ? $changes->stateorprovince : $this->stateorprovince;
+		$this->country = $changes->country ? $changes->country : $this->country;
+		$this->voicetelephone = $changes->voicetelephone ? $changes->voicetelephone : $this->voicetelephone;
+		$this->facsimiletelephone = $changes->facsimiletelephone ? $changes->facsimiletelephone : $this->facsimiletelephone;
+		$this->email = $changes->email ? $changes->email : $this->email;
+		$this->logo_path = $changes->logo_path ? $changes->logo_path : $this->logo_path;
+		return true;
 	}
 
 	public function commit() {
@@ -160,21 +167,47 @@
 		$sql_update = "UPDATE mb_group SET ".
 			"mb_group_name = $1, ".
 			"mb_group_owner = $2, ".
-			"mb_group_description = $3 ".
-			"WHERE mb_group_id = $4;";
+			"mb_group_description = $3, ".
+			"mb_group_title = $4, ".
+			"mb_group_address = $5, ".
+			"mb_group_postcode = $6, ".
+			"mb_group_city = $7, ".
+			"mb_group_stateorprovince = $8, ".
+			"mb_group_country = $9, ".
+			"mb_group_voicetelephone = $10, ".
+			"mb_group_facsimiletelephone = $11, ".
+			"mb_group_email = $12, ".
+			"mb_group_logo_path = $13 ".
+			"WHERE mb_group_id = $14";
 
 
-			$v = array($this->name,
-									$this->owner,
-									$this->description,
-									$this->id);
+			$v = array(
+				$this->name,
+				$this->owner,
+				$this->description,
+				$this->title,
+				$this->address,
+				$this->postcode,
+				$this->city,
+				$this->stateorprovince,
+				$this->country,
+				$this->voicetelephone,
+				$this->facsimiletelephone,
+				$this->email,
+				$this->logo_path,
+				$this->id
+			);
 
-			$t = array("s", "i", "s", "i");
+			$t = array(
+				"s", "i", "s", "s", "s",
+				"i", "s", "s", "s", "s", 
+				"s", "s", "s", "i"
+			);
 
 			$update_result = db_prep_query($sql_update,$v,$t);
-			if(!$update_result)
-			{
+			if(!$update_result)	{
 				throw new Exception("Database error updating Group");
+				return false;
 			}
 
 		return true;
@@ -215,8 +248,7 @@
 			$this->name = $row['mb_group_name'];
 
             //FIXME: needs checking
-            $tmpuser =  new User($row['mb_group_owner']);
-            $this->owner = $tmpuser->name;
+            $this->owner = $row['mb_group_owner'];
             $this->description	= $row['mb_group_description'];
             $this->title = $row["mb_group_title"];
             $this->address = $row["mb_group_address"];
@@ -242,32 +274,57 @@
     */
     public static function getList($filter) {
 
-      //set up filters:
-      $id = $filter->id ? $filter->id : "%";
-      $name = $filter->name ? $filter->name : "%";
+		$name = $filter->name ? $filter->name : null;
+		$id = $filter->id && is_numeric($filter->id) ? 
+			intval($filter->id) : null;
+		$owner = $filter->owner && is_numeric($filter->owner) ? 
+			intval($filter->owner) : null;
+		
+		$groups = Array();
+		$sql_grouplist = "SELECT mb_group_id FROM mb_group";
+	  
+		$andConditions = array();
+		$v = array();
+		$t = array();
 
+		if (!is_null($name)) {
+			$v[]= $name;
+			$t[]= "s";
+	  		$andConditions[]= "mb_group_name LIKE $" . count($v);
+		}
 
+		if (!is_null($id)) {
+			$v[]= $id;
+			$t[]= "i";
+	  		$andConditions[]= "mb_group_id = $" . count($v);
+		}
+		
+		if (!is_null($owner)) {
+			$v[]= $owner;
+			$t[]= "i";
+	  		$andConditions[]= "mb_group_owner = $" . count($v);
+		}
+		
+		if (count($andConditions) > 0) {
+			$sql_grouplist .= " WHERE " . implode("AND", $andConditions);
+		}
+		
+		$sql_grouplist .= " ORDER BY mb_group_name";
 
-      $groups = Array();
-      $sql_grouplist = "SELECT mb_group_id FROM mb_group WHERE mb_group_name LIKE $1;";
-      $v = array($name);
-      $t = array("s");
-      $res_groups = db_prep_query($sql_grouplist,$v,$t);
+		$res_groups = db_prep_query($sql_grouplist,$v,$t);
+		
+		while ($row = db_fetch_array($res_groups)) {
+			try {
+				$groups[] = new Group($row['mb_group_id']);
+			}
+			catch (Exception $E) {
+				continue;
+				//FIXME: should catch some errors here
+			}
+		}
+		return $groups;
+	}
 
-      while($row = db_fetch_array($res_groups)) {
-        try{
-          $groups[] = new Group($row['mb_group_id']);
-        }
-        catch(Exception $E)
-        {
-          continue;
-          //FIXME: should catch some errors here
-        }
-      }
-      return $groups;
-
-    }
-
     /*
     * tries to initialize a Groupobject by Name
     * @return A group Object
@@ -276,17 +333,17 @@
 
     public static function byName($name) {
 
-      if($name == null) { return new Group(null); }
+		if (is_null($name)) { 
+			return new Group(null); 
+		}
 
-      $sql_group = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = $1";
-      $res_group = db_prep_query($sql_group, array($name), array("s"));
-
-      if($row = db_fetch_array($res_group))
-      {
-        return new Group($row['mb_group_id']);
-      }
-      return null;
-
+		$sql_group = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = $1";
+		$res_group = db_prep_query($sql_group, array($name), array("s"));
+		
+		if ($row = db_fetch_array($res_group)) {
+			return new Group($row['mb_group_id']);
+		}
+		return null;
     }
 	
 	public function isValid () {

Modified: trunk/mapbender/http/php/mod_editFilteredGroup.php
===================================================================
--- trunk/mapbender/http/php/mod_editFilteredGroup.php	2010-07-13 07:22:23 UTC (rev 6591)
+++ trunk/mapbender/http/php/mod_editFilteredGroup.php	2010-07-13 11:45:54 UTC (rev 6592)
@@ -21,196 +21,10 @@
 import_request_variables("PG");
 $e_id="editFilteredGroup";
 require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-<?php
-echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
-?>
-<title>Edit Filtered Group</title>
-<?php
-include '../include/dyn_css.php';
-?>
-<script language="JavaScript">
-
-function validate(val){
-   var ok = validateInput();
-   if(ok == 'true'){
-     var permission = false;
-     if(val == 'save'){
-        permission = confirm("Save changes?");
-     }
-     if(val == 'update'){
-        permission = confirm("Save changes?");
-     }
-     if(val == 'delete'){
-        permission = confirm("Delete Group?");
-     }
-     if(permission === true){
-        document.forms[0].action.value = val;
-        document.forms[0].submit();
-     }
-   }
-}
-function validateInput(){
-  var str_alert = "Input incorrect !";
-  if(document.forms[0].name.value === ''){
-      alert(str_alert);
-      document.forms[0].name.focus();
-      return 'false';
-  }
-  return 'true';
-}
-</script>
-
-</head>
-<body>
-<?php
-
-#delete
-if($action == 'delete'){
-	$sql = "DELETE FROM mb_group WHERE mb_group_id = $1";
-	$v = array($selected_group);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	$selected_group = 'new';
-}
-
-#save
-if($action == 'save'){
-	$sql = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = $1 ";
-	$v = array($name);
-	$t = array('s');
-	$res = db_prep_query($sql,$v,$t);
-	if(db_fetch_row($res)){
-		echo "<script language='JavaScript'>alert('groupname must be unique!');</script>";
-	}
-	else{
-		$sql = "Insert INTO mb_group (mb_group_name, mb_group_owner, mb_group_description) VALUES ";
-		$sql.= "($1, $2, $3);";
-		$v = array($name,$owner_id,$description);
-		$t = array('s','i','s');
-		$res = db_prep_query($sql,$v,$t);
-		$selected_group = db_insert_id($res,"mb_group","mb_group_id");
-	}
-}
-
-#update
-if($action == 'update'){
-	$sql = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = $1 AND mb_group_id <> $2";
-	$v = array($name,$selected_group);
-	$t = array('s','i');
-	$res = db_prep_query($sql,$v,$t);
-	if(db_fetch_row($res)){
-		echo "<script language='JavaScript'>alert('Groupname must be unique!');</script>";
-	}
-	else{
-		$sql = "UPDATE mb_group SET mb_group_name = $1";
-		$sql.=", mb_group_description = $2";
-		$sql.=" where mb_group_id = $3";
-		$v = array($name,$description,$selected_group);
-		$t = array('s','s','i');
-		$res = db_prep_query($sql,$v,$t);
-	}
-}
-if (!isset($name) || $selected_group == 'new'){
-  $name = "";
-  $owner_id = Mapbender::session()->get("mb_user_id");
-  $owner_name = Mapbender::session()->get("mb_user_name");
-  $description = "";
-}
+require_once(dirname(__FILE__)."/../classes/class_user.php");
+require_once(dirname(__FILE__)."/../classes/class_group.php");
 $myGroup = true;
 
-/*HTML*****************************************************************************************************/
+include "../../lib/editGroup.php";
 
-echo "<form name='form1' action='" . $self ."' method='post'>";
-echo "<table border='0'>";
-#User
-echo "<tr>";
-   echo "<td>";
-      echo "Group: ";
-   echo "</td>";
-echo "<td>";
-echo "<select name='selected_group' onchange='submit()'>";
-	echo "<option value='new'>NEW...</option>";
-	$sql = "SELECT mb_group_name,mb_group_id FROM mb_group ";
-	$v = array();
-	$t = array();
-	if(isset($myGroup)){ 
-		$sql .= "WHERE mb_group_owner = $1";
-		array_push($v, Mapbender::session()->get("mb_user_id"));
-		array_push($t, "i");
-	}
-	$sql .= " ORDER BY mb_group_name ";
-	$res = db_prep_query($sql, $v, $t);
-	$count=0;
-	while($row = db_fetch_array($res)){
-		echo "<option value='".$row["mb_group_id"]."' ";
-		if($selected_group && $selected_group == $row["mb_group_id"]){
-			echo "selected";
-		}
-		echo ">".$row["mb_group_name"]."</option>";
-		$count++;
-	}
-	echo "</select>";
-	echo "</td>";
-echo "</tr>";
-
-
-if(isset($selected_group) && $selected_group != 0){
-	$sql = "SELECT * FROM mb_group WHERE mb_group_id = $1 ORDER BY mb_group_name ";
-	$v = array($selected_group);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	if($row = db_fetch_array($res)){
-		$name = $row["mb_group_name"];
-		$owner_id = $row["mb_group_owner"];
-		$description = $row["mb_group_description"];
-	}
-	$sql = "SELECT mb_user_name FROM mb_user WHERE mb_user_id = $1";
-	$v = array($owner_id);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	if($row = db_fetch_array($res)){
-		$owner_name = $row["mb_user_name"];
-	}
-}
-#name
-echo "<tr>";
-   echo "<td>Name:</td>";
-   echo "<td>";
-      echo "<input type='text' size='30' name='name' value='".$name."'>";
-   echo "</td>";
-echo "</tr>";
-
-#owner
-echo "<tr>";
-   echo "<td>Owner: </td>";
-   echo "<td>";
-      echo "<input type='text' size='30' name='owner_name' value='".$owner_name."' readonly>";
-      echo "<input type='hidden' size='30' name='owner_id' value='".$owner_id."' readonly>";
-   echo "</td>";
-echo "</tr>";
-
-#description
-echo "<tr>";
-   echo "<td>Description: </td>";
-   echo "<td>";
-      echo "<input type='text' size='30' name='description' value='".$description."'>";
-   echo "</td>";
-echo "</tr>";
-
-echo"</table>";
-if($selected_group == 'new' || !isset($selected_group)){
-   echo "<input type='button' value='save'  onclick='validate(\"save\")'>";
-}
-if(Mapbender::session()->get("mb_user_id") == $owner_id && $selected_group != 'new' && $selected_group != '' ){
-   echo "<input type='button' value='save'  onclick='validate(\"update\")'>";
-   echo "<input type='button' value='delete'  onclick='validate(\"delete\")'>";
-}
 ?>
-<input type='hidden' name='action' value=''>
-</form>
-</body>
-</html>
\ No newline at end of file

Modified: trunk/mapbender/http/php/mod_editGroup.php
===================================================================
--- trunk/mapbender/http/php/mod_editGroup.php	2010-07-13 07:22:23 UTC (rev 6591)
+++ trunk/mapbender/http/php/mod_editGroup.php	2010-07-13 11:45:54 UTC (rev 6592)
@@ -17,196 +17,12 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+import_request_variables("PG");
 $e_id="editGroup";
 require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<?php
-echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
-?>
-<head>
-<title>Edit Group</title>
-<?php
-include '../include/dyn_css.php';
-?>
-<script language="JavaScript">
+require_once(dirname(__FILE__)."/../classes/class_user.php");
+require_once(dirname(__FILE__)."/../classes/class_group.php");
+$myGroup = false;
 
-function validate(val){
-   var ok = validateInput();
-   if(ok == 'true'){
-     var permission = false;
-     if(val == 'save'){
-        permission = confirm("Save changes?");
-     }
-     if(val == 'update'){
-        permission = confirm("Save changes?");
-     }
-     if(val == 'delete'){
-        permission = confirm("Delete Group?");
-     }
-     if(permission == true){
-        document.forms[0].action.value = val;
-        document.forms[0].submit();
-     }
-   }
-}
-function validateInput(){
-  var str_alert = "Input incorrect !";
-  if(document.forms[0].name.value == ''){
-      alert(str_alert);
-      document.forms[0].name.focus();
-      return 'false';
-  }
-  return 'true';
-}
-</script>
-
-</head>
-<body>
-<?php
-#delete
-if($action == 'delete'){
-   $sql = "DELETE FROM mb_group WHERE mb_group_id = $1";
-   $v = array( $selected_group);
-   $t = array('i');
-   $res = db_prep_query($sql,$v,$t);
-   $selected_group = 'new';
-}
-
-#save
-if($action == 'save'){
-   $sql = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = $1 ";
-   $v = array($name);
-   $t = array('s');
-   $res = db_prep_query($sql,$v,$t);
-   if(db_fetch_row($res)){
-      echo "<script language='JavaScript'>alert('groupname must be unique!');</script>";
-   }
-   else{
-     $sql = "Insert INTO mb_group (mb_group_name, mb_group_owner, mb_group_description) VALUES ";
-     $sql.= "($1, $2,$3);";
-     $v = array($name,$owner_id,$description);
-     $t = array('s','i','s');
-     $res = db_prep_query($sql,$v,$t);
-     $selected_group = db_insert_id($res,"mb_group","mb_group_id");
-   }
-}
-
-#update
-if($action == 'update'){
-   $sql = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = $1 AND mb_group_id <> $2";
-   $v = array($name,$selected_group);
-   $t = array('s','i');
-   $res = db_prep_query($sql,$v,$t);
-   if(db_fetch_row($res)){
-      echo "<script language='JavaScript'>alert('Groupname must be unique!');</script>";
-   }
-   else{
-     $sql = "UPDATE mb_group SET mb_group_name = $1";
-     $sql.=", mb_group_description = $2";
-     $sql.=" where mb_group_id = $3";
-     $v = array($name,$description,$selected_group);
-     $t = array('s','s','i');
-     $res = db_prep_query($sql,$v,$t);
-   }
-}
-if (!isset($name) || $selected_group == 'new'){
-  $name = "";
-  $owner_id = Mapbender::session()->get("mb_user_id");
-  $owner_name = Mapbender::session()->get("mb_user_name");
-	$description = "";
-}
-
-/*HTML*****************************************************************************************************/
-
-echo "<form name='form1' action='" . $self ."' method='post'>";
-echo "<table border='0'>";
-#User
-echo "<tr>";
-   echo "<td>";
-      echo "Group: ";
-   echo "</td>";
-echo "<td>";
-   echo "<select name='selected_group' onchange='submit()'>";
-   echo "<option value='new'>NEW...</option>";
-   $sql = "SELECT mb_group_name,mb_group_id FROM mb_group ";
-   $v = array();
-   $t = array();
-   if (isset($myGroup)) { 
-		$sql .= "WHERE mb_group_owner = $1";
-		array_push($v, Mapbender::session()->get("mb_user_id"));
-		array_push($t, "i");
-   }
-   $sql .= " ORDER BY mb_group_name ";
-   $res = db_prep_query($sql, $v, $t);
-   $count=0;
-   while($row = db_fetch_array($res)){
-	 	echo "<option value='".$row["mb_group_id"]."' ";
-		if($selected_group && $selected_group == $row["mb_group_id"]){
-         echo "selected";
-      }
-      echo ">".$row["mb_group_name"]."</option>";
-		$count++;
-   }
-   echo "</select>";
-   echo "</td>";
-echo "</tr>";
-
-
-if(isset($selected_group) && $selected_group != 0){
-   $sql = "SELECT * FROM mb_group WHERE mb_group_id = $1 ORDER BY mb_group_name ";
-   $v = array($selected_group);
-   $t = array('i');
-   $res = db_prep_query($sql,$v,$t);
-   if($row = db_fetch_array($res)){
-      $name = $row["mb_group_name"];
-      $owner_id = $row["mb_group_owner"];
-      $description = $row["mb_group_description"];
-   }
-   $sql = "SELECT mb_user_name FROM mb_user WHERE mb_user_id = $1";
-   $v = array($owner_id);
-   $t = array('i');
-   $res = db_prep_query($sql,$v,$t);
-   if($row = db_fetch_array($res)){
-      $owner_name = $row["mb_user_name"];
-   }
-}
-#name
-echo "<tr>";
-   echo "<td>Name:</td>";
-   echo "<td>";
-      echo "<input type='text' size='30' name='name' value='".$name."'>";
-   echo "</td>";
-echo "</tr>";
-
-#owner
-echo "<tr>";
-   echo "<td>Owner: </td>";
-   echo "<td>";
-      echo "<input type='text' size='30' name='owner_name' value='".$owner_name."' readonly>";
-      echo "<input type='hidden' size='30' name='owner_id' value='".$owner_id."' readonly>";
-   echo "</td>";
-echo "</tr>";
-
-#description
-echo "<tr>";
-   echo "<td>Description: </td>";
-   echo "<td>";
-      echo "<input type='text' size='30' name='description' value='".$description."'>";
-   echo "</td>";
-echo "</tr>";
-
-echo"</table>";
-if($selected_group == 'new' || !isset($selected_group)){
-   echo "<input type='button' value='save'  onclick='validate(\"save\")'>";
-}
-if(Mapbender::session()->get("mb_user_id") == $owner_id && $selected_group != 'new' && $selected_group != '' ){
-   echo "<input type='button' value='save'  onclick='validate(\"update\")'>";
-   echo "<input type='button' value='delete'  onclick='validate(\"delete\")'>";
-}
-?>
-<input type='hidden' name='action' value=''>
-</form>
-</body>
-</html>
\ No newline at end of file
+include "../../lib/editGroup.php";
+?>
\ No newline at end of file

Added: trunk/mapbender/lib/editGroup.php
===================================================================
--- trunk/mapbender/lib/editGroup.php	                        (rev 0)
+++ trunk/mapbender/lib/editGroup.php	2010-07-13 11:45:54 UTC (rev 6592)
@@ -0,0 +1,332 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<?php
+echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
+?>
+<title>Edit Filtered Group</title>
+<?php
+include '../include/dyn_css.php';
+?>
+<script type="text/javascript">
+
+function validate(val){
+   var ok = validateInput();
+   if(ok == 'true'){
+     var permission = false;
+     if(val == 'save'){
+        permission = confirm("Save changes?");
+     }
+     if(val == 'update'){
+        permission = confirm("Save changes?");
+     }
+     if(val == 'delete'){
+        permission = confirm("Delete Group?");
+     }
+     if(permission === true){
+        document.forms[0].action.value = val;
+        document.forms[0].submit();
+     }
+   }
+}
+function validateInput(){
+  var str_alert = "Input incorrect !";
+  if(document.forms[0].name.value === ''){
+      alert(str_alert);
+      document.forms[0].name.focus();
+      return 'false';
+  }
+  return 'true';
+}
+</script>
+
+</head>
+<body>
+<?php
+
+#delete
+if($action == 'delete'){
+	$group = new Group(intval($selected_group));
+	$group->remove();
+	$selected_group = 'new';
+}
+
+#save
+if($action == 'save'){
+	$group = Group::byName($name);
+
+	if(!is_null($group)){
+		echo "<script type='text/javascript'>alert('groupname must be unique!');</script>";
+	}
+	else {
+		$group = new Group(null);
+		$changes = new stdClass();
+		$changes->name = $name;
+		$changes->owner = $owner_id;
+		$changes->description = $description;
+		$changes->title = $title;
+		$changes->address = $address;
+		$changes->postcode = $postcode;
+		$changes->city = $city;
+		$changes->stateorprovince = $stateorprovince;
+		$changes->country = $country;
+		$changes->voicetelephone = $voicetelephone;
+		$changes->facsimiletelephone = $facsimiletelephone;
+		$changes->email = $email;
+		$changes->logo_path = $logo_path;
+		$group->change($changes);	
+		
+		$group->create();	
+
+		$selected_group = $group->getId();
+	}
+}
+
+#update
+if ($action == 'update') {
+	$group = Group::byName($name);
+	if (!is_null($group) && intval($group->getId()) !== intval($selected_group)) {
+		echo "<script type='text/javascript'>alert('Groupname must be unique!');</script>";
+	}
+	else {
+		$group = new Group(intval($selected_group));
+		$changes = new stdClass();
+		$changes->name = $name;
+		$changes->owner = $owner_id;
+		$changes->description = $description;
+		$changes->title = $title;
+		$changes->address = $address;
+		$changes->postcode = $postcode;
+		$changes->city = $city;
+		$changes->stateorprovince = $stateorprovince;
+		$changes->country = $country;
+		$changes->voicetelephone = $voicetelephone;
+		$changes->facsimiletelephone = $facsimiletelephone;
+		$changes->email = $email;
+		$changes->logo_path = $logo_path;
+		$group->change($changes);		
+
+		$group->commit();	
+	}
+}
+
+if (!isset($name) || $selected_group == 'new'){
+	$name = "";
+	$owner_id = Mapbender::session()->get("mb_user_id");
+	$owner = new User(intval($owner_id));
+	$owner_name = $owner->name;
+	$description = "";
+	$title = "";
+	$address = "";
+	$postcode = "";
+	$city = "";
+	$stateorprovince = "";
+	$country = "";
+	$voicetelephone = "";
+	$facsimiletelephone = "";
+	$email = "";
+	$logo_path = "";
+}
+
+/*HTML*****************************************************************************************************/
+
+echo "<form name='form1' action='" . $self ."' method='post'>";
+echo "<table border='0'>";
+#User
+echo "<tr>";
+   echo "<td>";
+      echo "Group: ";
+   echo "</td>";
+echo "<td>";
+echo "<select name='selected_group' onchange='submit()'>";
+	echo "<option value='new'>NEW...</option>";
+	$filter = new stdClass();
+	if (isset($myGroup) && $myGroup) {
+		$filter->owner = Mapbender::session()->get("mb_user_id");
+	}
+	$groupArray = Group::getList($filter);
+	foreach ($groupArray as $group) {
+		echo "<option value='" . 
+			htmlentities($group->getId(), ENT_QUOTES. "UTF-8") . "' ";
+
+		if ($selected_group && intval($selected_group) == $group->getId()) {
+			echo "selected";
+		}
+		echo ">" . 
+			htmlentities($group->name, ENT_QUOTES, "UTF-8") . "</option>";
+	}
+	echo "</select>";
+	echo "</td>";
+echo "</tr>";
+
+
+if(isset($selected_group) && $selected_group != 0){
+	$group = new Group(intval($selected_group));
+	$data = $group->getFields();
+
+	if ($group->isValid()) {
+		$name = $data["name"];
+		$owner_id = $data["owner"];
+		$description = $data["description"];
+		$title = $data["title"]; 
+		$address = $data["address"];
+		$postcode = $data["postcode"];
+		$city = $data["city"]; 
+		$stateorprovince = $data["stateorprovince"]; 
+		$country = $data["country"]; 
+		$voicetelephone = $data["voicetelephone"];
+		$facsimiletelephone = $data["facsimiletelephone"];
+		$email = $data["email"];
+		$logo_path = $data["logo_path"];
+	}
+	$owner = new User(intval($owner_id));
+	if ($owner->isValid()) {
+		$owner_name = $owner->name;
+	}
+}
+#name
+echo "<tr>";
+   echo "<td>"._mb("Name").":</td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='name' value='" . 
+	  	htmlentities($name, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#title
+echo "<tr>";
+   echo "<td>"._mb("Title").":</td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='title' value='" . 
+	  	htmlentities($title, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+
+#owner
+echo "<tr>";
+   echo "<td>"._mb("Owner").": </td>";
+   echo "<td>";
+	echo "<input type='text' size='30' name='owner_name' value='" . 
+	  	htmlentities($owner_name, ENT_QUOTES, "UTF-8") . "' readonly>";
+      echo "<input type='hidden' size='30' name='owner_id' value='" . 
+	  	htmlentities($owner_id, ENT_QUOTES, "UTF-8") . "' readonly>";
+   echo "</td>";
+echo "</tr>";
+
+#description
+echo "<tr>";
+   echo "<td>"._mb("Description").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='description' value='" . 
+	  	htmlentities($description, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#address
+echo "<tr>";
+   echo "<td>"._mb("Address").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='address' value='" . 
+	  htmlentities($address, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#postcode
+echo "<tr>";
+   echo "<td>"._mb("Postcode").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='postcode' value='" . 
+	  	htmlentities($postcode, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#city
+echo "<tr>";
+   echo "<td>"._mb("City").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='city' value='" . 
+	  	htmlentities($city, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#provice
+echo "<tr>";
+   echo "<td>"._mb("Province").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='stateorprovince' value='" . 
+	  htmlentities($stateorprovince, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#country
+echo "<tr>";
+   echo "<td>"._mb("Country").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='country' value='" . 
+	  htmlentities($country, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#voicetelephone
+echo "<tr>";
+   echo "<td>"._mb("Voicetelephone").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='voicetelephone' value='" . 
+	  htmlentities($voicetelephone, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#facsimiletelephone
+echo "<tr>";
+   echo "<td>"._mb("Facsimiletelephone").": </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='facsimiletelephone' value='" . 
+	  htmlentities($facsimiletelephone, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#email
+echo "<tr>";
+   echo "<td>Email: </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='email' value='" . 
+	  htmlentities($email, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+#logo
+echo "<tr>";
+   echo "<td>Logo: </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='logo_path' value='" . 
+	  htmlentities($logo_path, ENT_QUOTES, "UTF-8") . "'>";
+   echo "</td>";
+echo "</tr>";
+
+# blank row
+echo "<tr>";
+   echo "<td colspan='2'>&nbsp;</td>";
+echo "</tr>";
+
+# send form
+echo "<tr>";
+   echo "<td>&nbsp;</td>";
+   echo "<td>";
+	if($selected_group == 'new' || !isset($selected_group)){
+		echo "<input type='button' value='save'  onclick='validate(\"save\")'>";
+	}
+	if(Mapbender::session()->get("mb_user_id") == $owner_id && $selected_group != 'new' && $selected_group != '' ){
+		echo "<input type='button' value='save'  onclick='validate(\"update\")'>";
+		echo "<input type='button' value='delete'  onclick='validate(\"delete\")'>";
+	}
+   echo "</td>";
+echo "</tr>";
+
+echo"</table>";
+
+?>
+<input type='hidden' name='action' value=''>
+</form>
+</body>
+</html>
\ No newline at end of file



More information about the Mapbender_commits mailing list