Index: /trunk/jabberit_messenger/inc/class.db_im.inc.php
===================================================================
--- /trunk/jabberit_messenger/inc/class.db_im.inc.php	(revision 697)
+++ /trunk/jabberit_messenger/inc/class.db_im.inc.php	(revision 896)
@@ -137,4 +137,25 @@
 	}
 	
+	public final function getHostsJabber()
+	{
+		$return = "";
+	
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';";
+			
+			if($this->db->query($query))
+			{
+				while($this->db->next_record())
+					$result[] = $this->db->row();				
+			}
+
+			if( count($result) > 0 )
+				$return = $result[0]['config_value'];
+		}
+		
+		return $return;
+	}
+	
 	public final function getPreferences()
 	{
@@ -152,5 +173,4 @@
 
 		return "openWindowJabberit:true;openWindowJabberitPopUp:false;flagAwayIM:5";
-		//return "openWindowJabberit:true;openWindowJabberitPopUp:false";		
 	}
 
@@ -313,4 +333,62 @@
 		}
 		
+		return false;
+	}
+	
+	public final function setHostJabber($pParam)
+	{
+		$organization	= $pParam['organization'];
+		$hostJabber		= $pParam['hostJabber'];
+	
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';";
+			
+			if($this->db->query($query))
+			{
+			
+				if ( $this->db->query($query) )
+				{	
+					while($this->db->next_record())
+						$result[] = $this->db->row();
+				}
+				
+				if( count($result) == 0 )
+				{
+					$confHostJabber = strtoupper($organization).":".$hostJabber;
+					$return = "<return><confServer ou='".strtoupper($organization)."' serverName='".$hostJabber."'>".$confHostJabber."</confServer></return>";
+					$query = "INSERT INTO phpgw_config(config_app,config_name, config_value) VALUES('phpgwapi','map_org_realm_jabberit','".serialize($confHostJabber)."')";
+					$_SESSION['debug']['gravar'] = $confHostJabber;
+					$this->db->query($query);					
+				}
+				else
+				{
+					$confHostJabber = unserialize($result[0]['config_value']);
+					$OrgHosts = explode(";", $confHostJabber);
+					$stringSearch = strtoupper($organization).":".$hostJabber;
+					$FoundString = array_search($stringSearch, $OrgHosts);
+
+					if( $FoundString === false)
+						$confHostJabber .= ";" . $stringSearch;
+				
+					$items = explode(";", $confHostJabber);
+					natcasesort($items);
+											
+					$return = "<return>";
+					foreach($items as $tmp)
+					{
+						$aux = explode(":",$tmp);
+						$return .= "<confServer ou='".$aux[0]."' serverName='".$aux[1]."'>".$tmp."</confServer>";
+					}					
+					$return .= "</return>";
+
+					$query = "UPDATE phpgw_config SET config_value = '".serialize($confHostJabber)."' WHERE config_name = 'map_org_realm_jabberit';";
+					$this->db->query($query);
+				}
+				
+				return $return;
+			}
+		}
+
 		return false;
 	}
@@ -473,5 +551,88 @@
 		return false; 
 	}
-	
+
+	public final function removeAttributesLdap($pOrg)
+	{
+		$organization = $pOrg['org'];
+		
+		if( $this->db )
+		{
+			$query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'";
+				
+			if ( $this->db->query($query) )
+			{	
+				while( $this->db->next_record() )
+					$result[] = $this->db->row();
+		
+				if( count($result) > 0 )
+					$attributesOrg = $result[0]['config_value'];
+			}
+
+			$attributesOrg = explode(",", $attributesOrg);
+			$newValue = ""; 
+			foreach($attributesOrg as $tmp)
+			{
+				$attr = explode(";",$tmp);
+				 
+				if( strtolower(trim($attr[0])) != strtolower(trim($organization)))
+				{
+					$newValue .= $attr[0] . ";" . $attr[1] . ",";
+				}
+			}
+			
+			$newValue = substr($newValue, 0,(strlen($newValue) -1 ));
+			
+			if( trim($newValue) != "")
+				$query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'";
+			else
+				$query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'";
+				
+			if( $this->db->query($query))
+				return true;
+			else
+				return false;
+		}
+		return false;	
+	}
+
+	public final function removeHostsJabber($pItem)
+	{
+		$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';";
+
+		if( $this->db )
+		{
+			if($this->db->query($query))
+			{
+				while($this->db->next_record())
+					$result[] = $this->db->row();
+					
+				if( count($result) > 0 )
+				{
+					$confHostsOrgs = unserialize($result[0]['config_value']);
+					$confHostsOrgs = explode(";", $confHostsOrgs);					
+					$foundValue = array_search($pItem['item'], $confHostsOrgs);					
+	
+					if( $foundValue !== false )
+						array_splice($confHostsOrgs, $foundValue, 1);
+					
+					if(count($confHostsOrgs) > 0 )
+					{
+						foreach( $confHostsOrgs as $values )
+							$stringHostsOrgs .= $values . ";";
+	
+						$stringHostsOrgs = substr($stringHostsOrgs, 0, strlen($stringHostsOrgs) -1 );
+						$query = "UPDATE phpgw_config SET config_value = '".serialize($stringHostsOrgs)."' WHERE config_name = 'map_org_realm_jabberit';";
+					}
+					else
+						$query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';";
+					
+					if( $this->db->query($query) )
+						return "true";
+				}		
+			}			
+		}
+		return "false";
+	}
+
 	public final function removeOuGroupsLocked($pGroup)
 	{
@@ -532,11 +693,12 @@
 	}
 	
-	public final function removeAttributesLdap($pOrg)
-	{
-		$organization = $pOrg['org'];
-		
-		if( $this->db )
-		{
-			$query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'";
+	public final function removeParticipantsExternal($pOrganization)
+	{
+		
+		$organization = $pOrganization['participants'];	
+		
+		if( $this->db )
+		{
+			$query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'";
 				
 			if ( $this->db->query($query) )
@@ -546,17 +708,14 @@
 		
 				if( count($result) > 0 )
-					$attributesOrg = $result[0]['config_value'];
-			}
-
-			$attributesOrg = explode(",", $attributesOrg);
+					$valueDB = $result[0]['config_value'];
+			}
+
+			$OrgDB = explode(",", $valueDB);
 			$newValue = ""; 
-			foreach($attributesOrg as $tmp)
-			{
-				$attr = explode(";",$tmp);
-				 
-				if( strtolower(trim($attr[0])) != strtolower(trim($organization)))
-				{
-					$newValue .= $attr[0] . ";" . $attr[1] . ",";
-				}
+
+			foreach($OrgDB as $tmp)
+			{
+				if( strtolower(trim($tmp)) != strtolower(trim($organization)))
+					$newValue .= $tmp . ",";
 			}
 			
@@ -564,7 +723,7 @@
 			
 			if( trim($newValue) != "")
-				$query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'";
-			else
-				$query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'";
+				$query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'";
+			else
+				$query = "DELETE from phpgw_config where config_name = 'conf_organization_jabberit'";
 				
 			if( $this->db->query($query))
@@ -575,46 +734,4 @@
 		return false;	
 	}
-	
-	public final function removeParticipantsExternal($pOrganization)
-	{
-		
-		$organization = $pOrganization['participants'];	
-		
-		if( $this->db )
-		{
-			$query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'";
-				
-			if ( $this->db->query($query) )
-			{	
-				while( $this->db->next_record() )
-					$result[] = $this->db->row();
-		
-				if( count($result) > 0 )
-					$valueDB = $result[0]['config_value'];
-			}
-
-			$OrgDB = explode(",", $valueDB);
-			$newValue = ""; 
-
-			foreach($OrgDB as $tmp)
-			{
-				if( strtolower(trim($tmp)) != strtolower(trim($organization)))
-					$newValue .= $tmp . ",";
-			}
-			
-			$newValue = substr($newValue, 0,(strlen($newValue) -1 ));
-			
-			if( trim($newValue) != "")
-				$query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'";
-			else
-				$query = "DELETE from phpgw_config where config_name = 'conf_organization_jabberit'";
-				
-			if( $this->db->query($query))
-				return true;
-			else
-				return false;
-		}
-		return false;	
-	}
 }
 ?>
