Index: trunk/jabberit_messenger/inc/webservice.php
===================================================================
--- trunk/jabberit_messenger/inc/webservice.php	(revision 1139)
+++ trunk/jabberit_messenger/inc/webservice.php	(revision 1160)
@@ -15,5 +15,5 @@
 	private $conn;
 	private $contextLdap;
-	private $userDn;	
+	private $userLDAP;	
 	private $jabberName = null;
 	private $passwd;
@@ -21,4 +21,6 @@
 	private $refer;
 	private $serverLdap;
+	private $fileLdapInternal = false;
+	private $fileLdapExternal = false;
 	
 	function __construct()
@@ -32,9 +34,11 @@
 			$this->serverLdap	= $handle['serverLdap'];
 			$this->contextLdap	= $handle['contextLdap'];
-			$this->userDn		= $handle['user'];
+			$this->userLDAP		= $handle['user'];
 			$this->passwd		= $handle['password'];
 			
 			$this->refer  	= true;
 			$this->version3 = true;
+			
+			$this->fileLdapInternal = true;
 		}
 	}
@@ -55,9 +59,9 @@
 
 		// Bind as Admin
-		if($this->userDn && $this->passwd && !ldap_bind($this->conn, $this->userDn, $this->passwd))
+		if( $this->userLDAP && $this->passwd && !ldap_bind($this->conn, $this->userLDAP . "," . $this->contextLdap, $this->passwd) )
 			return False;
 		
 		// Bind as Anonymous
-		if(!$this->userDn && !$this->passwd && !@ldap_bind($this->conn))
+		if( !$this->userLDAP && !$this->passwd && !@ldap_bind($this->conn) )
 			return False;
 	}
@@ -65,21 +69,26 @@
 	private final function ldapConnectExternal($pHostJabber)
 	{
-		require_once('confLDAPExternal.php');
-		$handle   = unserialize(base64_decode($LDAP_EXTERNAL));
-
-		foreach($handle as $itens)
-			if(trim($pHostJabber) == $itens['jabberName'])
-			{
-				$this->jabberName	= $itens['jabberName'];
-				$this->serverLdap	= $itens['serverLdap'];
-				$this->contextLdap	= $itens['contextLdap'];
-				$this->userDn		= $itens['user'];
-				$this->passwd		= $itens['password'];
-			}		
-
-		$this->refer  	= true;
-		$this->version3 = true;
-		
-		$this->ldapConnect();
+		if( file_exists('confLDAPExternal.php'))
+		{
+			require_once('confLDAPExternal.php');
+			$handle   = unserialize(base64_decode($LDAP_EXTERNAL));
+	
+			foreach($handle as $itens)
+				if(trim($pHostJabber) == $itens['jabberName'])
+				{
+					$this->jabberName	= $itens['jabberName'];
+					$this->serverLdap	= $itens['serverLdap'];
+					$this->contextLdap	= $itens['contextLdap'];
+					$this->userLDAP		= $itens['user'];
+					$this->passwd		= $itens['password'];
+				}		
+	
+			$this->refer  	= true;
+			$this->version3 = true;
+			
+			$this->ldapConnect();
+			
+			$this->fileLdapExternal = true;
+		}
 	}
 	
@@ -161,22 +170,29 @@
 	{
 		$uid = substr($pJid, 0, strpos($pJid,"@"));
+		$return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado");
 		
 		if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
 		{
 			$this->ldapConnect();
-			
-			if( $this->conn )
-			{
-				$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
-				$justthese = array("uid","cn","dn");
-				$search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
-				$entry = ldap_get_entries($this->conn,$search);
-				$cn = $entry[0]['cn'][0];
-				$ou = explode("dc=", $entry[0]['dn']);
-				$ou = explode("ou=",$ou[0]);
-				$ou = array_pop($ou);
-				$dn = strtoupper(substr($ou,0,strlen($ou)-1));
-	
-				$return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn);
+
+			if( $this->fileLdapInternal )
+			{
+				if( $this->conn )
+				{
+					$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese = array("uid","cn","dn");
+					$search = ldap_search( $this->conn, $this->contextLdap, $filter,$justthese);
+					$get_entries = ldap_get_entries( $this->conn, $search);
+		
+					if( $get_entries['count'] > 0 )
+					{					
+						$cn = $get_entries[0]['cn'][0];
+						$ou = explode("dc=", $get_entries[0]['dn']);
+						$ou = explode("ou=",$ou[0]);
+						$ou = array_pop($ou);
+						$dn = strtoupper(substr($ou,0,strlen($ou)-1));
+						$return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn);
+					}
+				}
 			}
 		}
@@ -184,64 +200,64 @@
 		{
 			$this->ldapConnectExternal(substr($pJid, strpos($pJid, "@") + 1 ));
-
-			if( $this->conn )
-			{
-				$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
-				$justthese = array("uid","cn","dn");
-				$search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
-				$entry = ldap_get_entries($this->conn,$search);
-				$cn = $entry[0]['cn'][0];
-				$ou = explode("dc=", $entry[0]['dn']);
-				$ou = explode("ou=",$ou[0]);
-				$ou = array_pop($ou);
-				$dn = strtoupper(substr($ou,0,strlen($ou)-1));
-	
-				$return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn);
-			}
-		}
-
-		if( $pCharset === "1" )
+			
+			if( $this->fileLdapExternal )
+			{
+				if( $this->conn )
+				{
+					$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese = array("uid","cn","dn");
+					$search = ldap_search( $this->conn, $this->contextLdap, $filter, $justthese);
+					$get_entries = ldap_get_entries( $this->conn, $search);
+					
+					if( $get_entries['count'] > 0 )
+					{
+						$cn = $get_entries[0]['cn'][0];
+						$ou = explode("dc=", $get_entries[0]['dn']);
+						$ou = explode("ou=",$ou[0]);
+						$ou = array_pop($ou);
+						$dn = strtoupper(substr($ou,0,strlen($ou)-1));
+						$return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn);
+					}
+				}
+			}
+		}
+
+		if( $pCharset === "1" || $pCharset === 1 )
 			return $return;
 		else
 			return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
 
-		$return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado");			
-
-		if( $pCharset === 1 )
-			return $return;
-		else
-			return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
-
-	}
-	
-	public final function getPhotoLdap( $pJid, $pCatalog )
-	{
-		if ( ! $this->jabberName )
-			return false;
-
-		$uid = substr($pJid, 0, strpos($pJid,"@"));
-		
-		if( ($this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 ))) && $pCatalog)
-		{
-			$this->ldapConnect();
-			
-			if( $this->conn )
-			{
-				$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
-				$justthese = array("uid","jpegPhoto");
+	}
+	
+	public final function getPhotoLdap( $pJid , $pLdapInternal )
+	{
+		$uid = substr($pJid, 0, strpos($pJid, "@"));
+
+		if( $pLdapInternal )
+		{
+			if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
+			{
+				if( ! $this->fileLdapInternal )
+					return false;
 				
-				$search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
-				$entry1 = ldap_get_entries($this->conn,$search);
-				$entry = ldap_first_entry( $this->conn, $search );
-				if( $entry1['count'] > 0 )
-				{
-					$i = 0;
-					$photo = "";
-					$return_photo = "";
-					$photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto');
-
-					if ($photo)
-						$return_photo = $photo[0];								
-					return $return_photo;
+				$this->ldapConnect();
+				
+				if( $this->conn )
+				{
+					$filter			= "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese		= array("uid","jpegPhoto");
+					$search			= ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
+					$get_entries	= ldap_get_entries($this->conn,$search);
+					
+					if( $get_entries['count'] > 0 )
+					{
+						$first_entry = ldap_first_entry( $this->conn, $search );
+						$photo = @ldap_get_values_len($this->conn, $first_entry, 'jpegphoto');
+						
+						if ( $photo )
+							return $photo[0];
+						
+						return false;								
+					}
 				}
 			}
@@ -250,5 +266,5 @@
 		{					
 			$jabberName = substr($pJid, strpos($pJid, "@") + 1 );
-			
+
 			if( strpos($jabberName, "/") )
 				$jabberName = substr($jabberName, 0, strpos($jabberName, "/"));
@@ -256,24 +272,27 @@
 			$this->ldapConnectExternal($jabberName);
 
+			if( !$this->fileLdapExternal )
+				return false;
+
 			if( $this->conn )
 			{
-				$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
-				$justthese = array("uid","jpegPhoto");
-				$search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
-				$entry1 = ldap_get_entries($this->conn,$search);
-				$entry = ldap_first_entry( $this->conn, $search );
-				if( $entry1['count'] > 0 )
-				{
-					$i = 0;
-					$photo = "";
-					$return_photo = "";
-					$photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto');
-					if ($photo)
-						$return_photo = $photo[0];								
-					return $return_photo;
+				$filter			= "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
+				$justthese		= array("uid","jpegPhoto");
+				$search			= ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
+				$get_entries	= ldap_get_entries($this->conn,$search);
+				
+				if( $get_entries['count'] > 0 )
+				{
+					$first_entry = ldap_first_entry( $this->conn, $search );
+					$photo = @ldap_get_values_len($this->conn, $first_entry, 'jpegphoto');
+					
+					if ( $photo )
+						return $photo[0];
+					
+					return false;								
 				}
 			}
 		}
-					
+		
 		return false;
 	}
@@ -305,5 +324,5 @@
 }
 
-// Utilizando o serviço Asteriks;
+// Applet - utilizando o serviço Voip;
 if(trim($_REQUEST['javaVoipFrom']) != "" && trim($_REQUEST['javaVoipTo']) != "" )
 {
@@ -314,12 +333,12 @@
 }
 
-// Fotos pelo applet; 
+// Applet - fotos pelo applet; 
 if(trim($_REQUEST['javaPhoto']) != "" )
 {
 	$obj = new webService();
 	$jid = $_REQUEST['javaPhoto'];
-	$jid = strpos($jid, "/") ? substr($jid, 0, strpos($jid, "/")) : $jid;
-	
-	$photo = $obj->getPhotoLdap($jid, true);
+	$jid = ( strpos($jid, "/") !== false ) ? substr($jid, 0, strpos($jid, "/")) : $jid;
+	
+	$photo = $obj->getPhotoLdap( $jid, true );
 	$photoWidth = 70;
 	$photoHeight = 90;
@@ -352,12 +371,12 @@
 	ob_end_clean();
 	printf("%s",base64_encode($imagePhoto));
-	
-}
-
-// Jid pelo applet;
-if(trim($_POST['jid']) != "")
-{
-	$jid = trim($_POST['jid']);
-	$charset = trim($_POST['charset']);
+}
+
+// Applet - jid;
+if(trim($_REQUEST['jid']) != "")
+{
+	
+	$jid = trim($_REQUEST['jid']);
+	$charset = trim($_REQUEST['charset']);
 	$obj = new webService();
 	
@@ -365,5 +384,5 @@
 }
 
-// Fotos pelo php;
+// Php - fotos pelo php;
 if(trim($_REQUEST['phpPhoto']) != "")
 {
Index: trunk/jabberit_messenger/inc/class.contacts_im.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/class.contacts_im.inc.php	(revision 991)
+++ trunk/jabberit_messenger/inc/class.contacts_im.inc.php	(revision 1160)
@@ -34,4 +34,5 @@
 		// Server Name Jabber
 		$this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit'];
+		
 	}
 
@@ -69,5 +70,5 @@
 		// Hosts Jabber
 		$hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
-			
+
 		if( is_array($users) )
 		{	
@@ -78,12 +79,14 @@
 					foreach($hostsJabber as $itens)
 					{
-						if( trim($users[$i]['ou']) === trim($itens['org']) && strpos($users[$i]['jid'],"@") === false)
-								$users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];						
-						else
+						if( trim($users[$i]['ou']) === trim($itens['org']) && strpos($users[$i]['jid'],"@") === false )
 						{
-							if(strpos($users[$i]['jid'],"@") === false)
-									$users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
+							$users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];
 						}
 					}
+				}
+
+				if( strpos($users[$i]['jid'],"@") === false )
+				{
+					$users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
 				}
 			}
@@ -139,5 +142,6 @@
 				$result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid);
         }
-        if(!$this->groupsLocked())
+        
+        if( !$this->groupsLocked() )
 	        $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*");
 
Index: trunk/jabberit_messenger/inc/class.ldap_im.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/class.ldap_im.inc.php	(revision 988)
+++ trunk/jabberit_messenger/inc/class.ldap_im.inc.php	(revision 1160)
@@ -22,5 +22,5 @@
 	private $ldap;
 	private $ldap_context;
-	private $ldap_dn;
+	private $ldap_user;
 	private $ldap_host;
 	private $ldap_org;
@@ -52,5 +52,5 @@
 		$GLOBALS['phpgw_info']['server']['ldap_version3'] = true;
 
-		$this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_dn, $this->ldap_pass, false );
+		$this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_user . "," . $this->ldap_context , $this->ldap_pass, false );
 	}
 	
@@ -59,5 +59,5 @@
 		$this->ldap_host 	= (isset($_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_host'];
 		$this->ldap_context	= (isset($_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_context'];
-		$this->ldap_dn		= (isset($_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
+		$this->ldap_user	= (isset($_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
 		$this->ldap_pass	= (isset($_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
 
@@ -83,11 +83,11 @@
 
 		// Bind as Admin
-		if($this->ldap_dn && $this->ldap_pass && !ldap_bind($conn, $this->ldap_dn, $this->ldap_pass))
+		if($this->ldap_user && $this->ldap_pass && !ldap_bind($conn, $this->ldap_user . "," .$this->ldap_context, $this->ldap_pass))
 			return false;
 		
 		// Bind as Anonymous
-		if(!$this->ldap_dn && !$this->ldap_pass && !@ldap_bind($conn))
-			return false;
-			
+		if(!$this->ldap_user && !$this->ldap_pass && !@ldap_bind($conn))
+			return false;
+
 		return $conn;
 	}
@@ -96,6 +96,7 @@
 	{
 		$this->ldapRoot();
-
-		if( $this->ldap )	
+		$result_groups = "";
+
+		if( $this->ldap && $pOrg['ou'] != "-1")	
 		{
 			$organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context;
@@ -114,6 +115,8 @@
 				$result_groups .= "</ldap>";						
 			}
-		}
-
+			
+			return $result_groups;
+		}
+		
 		return $result_groups;
 	}
@@ -140,5 +143,5 @@
 	{
 		$this->ldapRoot();
-	
+		
 		if( $this->ldap )
 		{
@@ -168,5 +171,5 @@
 			$this->ldap_host 	= $confHosts[$i]['serverLdap'];
 			$this->ldap_context = $confHosts[$i]['contextLdap'];
-			$this->ldap_dn		= $confHosts[$i]['user'];
+			$this->ldap_user	= $confHosts[$i]['user'];
 			$this->ldap_org		= $confHosts[$i]['org'];
 			$this->ldap_pass	= $confHosts[$i]['password'];
@@ -179,8 +182,9 @@
 				$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");								
 				$searchRoot = ( $this->ldap_org != "*" ) ? "ou=".$this->ldap_org.",".$this->ldap_context : $this->ldap_context;
+				
 				$search1 = @ldap_search($conn, $searchRoot, $filter, $justthese, 0, $this->max_result + 1);
 				$entry1 = @ldap_get_entries( $conn, $search1 );
 				$result = $this->resultArray($entry1, $conn );
-
+				
 				if( count($return) > 0 )
 		          	$return = array_merge($return, $result);
