Index: /trunk/jabberit_messenger/inc/webservice.php
===================================================================
--- /trunk/jabberit_messenger/inc/webservice.php	(revision 1214)
+++ /trunk/jabberit_messenger/inc/webservice.php	(revision 1502)
@@ -31,9 +31,9 @@
 			$handle   = unserialize(base64_decode($LDAP_INTERNAL));
 	
-			$this->jabberName	= $handle['jabberName'];
-			$this->serverLdap	= $handle['serverLdap'];
+			$this->jabberName		= $handle['jabberName'];
+			$this->serverLdap		= $handle['serverLdap'];
 			$this->contextLdap	= $handle['contextLdap'];
 			$this->userLDAP		= $handle['user'];
-			$this->passwd		= $handle['password'];
+			$this->passwd			= $handle['password'];
 			
 			$this->refer  	= true;
@@ -170,51 +170,36 @@
 		
 		if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
-		{
 			$this->ldapConnect();
-
-			if( $this->fileLdapInternal )
-			{
-				if( $this->conn )
-				{
+		else
+			$this->ldapConnectExternal(substr($pJid, strpos($pJid, "@") + 1 ));
+
+		if( $this->conn )
+		{
+			// Verificando atributo que a organização utiliza para autenticar no servidor jabber
+			switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
+			{
+				case 'description':
+					$filter = "(&(phpgwaccounttype=u)(description=".$uid.")(!(phpgwaccountvisible=-1)))";
+					break;
+				case 'uid':
 					$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);
-					}
-				}
-			}
-		}
-		else
-		{
-			$this->ldapConnectExternal(substr($pJid, strpos($pJid, "@") + 1 ));
-			
-			if( $this->fileLdapExternal )
-			{
-				if( $this->conn )
-				{
+					break;
+				case 'mail':
 					$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);
+					break;
+			}
+
+			$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( $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);
 			}
 		}
@@ -239,23 +224,4 @@
 				
 				$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;								
-					}
-				}
 			}
 		}
@@ -271,22 +237,37 @@
 			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);
-				$get_entries	= ldap_get_entries($this->conn,$search);
+		}
+
+		if( $this->conn )
+		{
+			// Verificando atributo que a organização utiliza para autenticar no servidor jabber
+			switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
+			{
+				case 'description':
+					$filter = "(&(phpgwaccounttype=u)(description=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese = array("description","jpegPhoto");
+					break;
+				case 'uid':
+					$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese = array("uid","jpegPhoto");
+					break;
+				case 'mail':
+					$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese = array("uid","jpegPhoto");
+					break;
+			}
+
+			$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;								
-				}
+			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;								
 			}
 		}
Index: /trunk/jabberit_messenger/inc/login.php
===================================================================
--- /trunk/jabberit_messenger/inc/login.php	(revision 1430)
+++ /trunk/jabberit_messenger/inc/login.php	(revision 1502)
@@ -2,6 +2,6 @@
   /***************************************************************************\
   *  Expresso - Expresso Messenger                                            *
-  *  	- Alexandre Correia / Rodrigo Souza							          *
-  *  	- JETI - http://jeti-im.org/										  *
+  *  	- Alexandre Correia / Rodrigo Souza							          			*
+  *  	- JETI - http://jeti-im.org/										  					*
   * ------------------------------------------------------------------------- *
   *  This program is free software; you can redistribute it and/or modify it  *
@@ -16,5 +16,5 @@
 
 	if(isset($_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']))
-    {
+	{
 		// Path Server
 		$path = $_SESSION['phpgw_info']['jabberit_messenger']['webserver_url'];
@@ -24,26 +24,37 @@
 		 ******  Type Protocol http / https **********************************************************
 		 *	Esta variável é carregada no header.inc.php, onde é possível definir
-		 * 	se será com http ou https. Verifique em seu arquivo header.inc.php como está configurada
+		 *	se será com http ou https. Verifique em seu arquivo header.inc.php como está configurada
 		 *	a variável $GLOBALS['phpgw_info']['server']['use_https']. 
 		 *	Abaixo segue esquema :
 		 *	Expresso 0 = Sem https
 		 *	Expresso 1 = Com https apenas no login
-		 * 	Expresso 2 = Completo
+		 *	Expresso 2 = Completo
 		 *********************************************************************************************
 		 **/
 
-		$PROTOCOL = trim("http");
-		if( $_SESSION['phpgw_info']['jabberit_messenger']['use_https'] === 2 )
-			$PROTOCOL = trim("https");
+		// ESSA VARIAVEL PRECISA REFLETIR A CONFIGURACAO DO PRIMEIRO PROXY
+      $PROTOCOL = trim("http");
 
-		// Uid user
-		$uid = $_SESSION['phpgw_info']['jabberit_messenger']['user_jabber'];
-		
-		$organization = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']);
+      $pattern = '/https:\/\//';
+      if (preg_match($pattern,$_SERVER[HTTP_REFERER]))
+      	$PROTOCOL = trim("https");
 
-		$organization_user = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
-		$organization_user = substr($organization_user, strpos($organization_user,"ou=") + 3 , strlen($organization_user));
-		$organization_user = substr($organization_user, 0, strpos($organization_user, ","));
-		
+		// UID
+		// Verificando atributo que a organização utiliza para autenticar no servidor jabber
+      switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
+		{
+      	case 'description':
+				$uid = $_SESSION['phpgw_info']['jabberit_messenger']['user_jabber'];
+            break;
+         case 'uid':
+            $uid = $_SESSION['phpgw_info']['jabberit_messenger']['user_id'];
+				$uid = substr($uid,0,strpos($uid,"@"));
+            break;
+   		case 'mail':
+         	$uid = $_SESSION['phpgw_info']['jabberit_messenger']['user_id'];
+				$uid = substr($uid,0,strpos($uid,"@"));
+            break;
+   	}
+
 		// FirstName
 		$CnName = explode(" ",$_SESSION['phpgw_info']['jabberit_messenger']['fullname']);
@@ -55,28 +66,4 @@
 		$preferences = explode(":", $preferences);
 		
-		if(is_array($organization))
-		{
-			foreach($organization as $attr)
-			{
-				$tmp = explode(";",$attr);
-				if( strtolower(trim($tmp[0])) == strtolower(trim($organization_user)))
-				{
-					switch(strtolower(trim($tmp[1])))
-					{
-						case "mail" :
-								$uid = $_SESSION['phpgw_info']['jabberit_messenger']['mail'];
-								$uid = substr($uid,0,strpos($uid,"@"));	
-								break;
-	
-						case "description" :
-								// SERPRO
-								// parte antes do arroba;
-								// Informe aqui a parte da sessão correspondente; 
-								$uid = "description"; 										
-								break;
-					}
-				}
-			}
-		}
 
 		//Enable/Disable VoIP Service -> Voip Server Config
@@ -127,19 +114,4 @@
 		$language = $lang[0];
 		
-		// Porta/(SSL)? 		
-		$conn_SSL = "false";
-		$port_jabber = "5222";
-		
-		if( $_SESSION['phpgw_info']['jabberit_messenger']['port_1_jabberit'] === "true" )
-		{	
-			$conn_SSL = "true";
-			$port_jabber = "5223";
-		}
-				
-		if( trim($_SESSION['phpgw_info']['jabberit_messenger']['port_2_jabberit']) )
-		{		
-			$port_jabber = $_SESSION['phpgw_info']['jabberit_messenger']['port_2_jabberit'];
-		}
-		
 		// Load Template;
 		$template = new Template('templates/default');
@@ -151,15 +123,16 @@
 		$template->set_var("value_country", $country);
 		$template->set_var("value_expresso", $SERVER_EXPRESSO);		
-		$template->set_var("value_host", $_SESSION['phpgw_info']['jabberit_messenger']['ip_server_jabberit']);
+		$template->set_var("value_host", $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']);
 		$template->set_var("value_javaPlugins", $javaPlugins);
 		$template->set_var("value_language", $language);			
 		$template->set_var("value_password", $_SESSION['phpgw_info']['jabberit_messenger']['passwd']);
-		$template->set_var("value_port", $port_jabber);
+		$template->set_var("value_port", $_SESSION['phpgw_info']['jabberit_messenger']['port_jabberit']);
 		$template->set_var("value_resource", $_SESSION['phpgw_info']['jabberit_messenger']['resource_jabberit']);
 		$template->set_var("value_server", $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']);
-		$template->set_var("value_ssl", $conn_SSL);
+		$template->set_var("value_ssl", $_SESSION['phpgw_info']['jabberit_messenger']['use_ssl_jabberit']);
 		$template->set_var("value_use_https", $PROTOCOL);
 		$template->set_var("value_user", $uid);
-
+		$template->set_var("value_userproxy", $_SESSION['phpgw_info']['jabberit_messenger']['use_proxy_java']);
+		
 		if( strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") )
 			$template->set_file(Array('jabberit_messenger' => 'jabberIM_IE.tpl'));
Index: /trunk/jabberit_messenger/inc/jabberit_sessions.inc.php
===================================================================
--- /trunk/jabberit_messenger/inc/jabberit_sessions.inc.php	(revision 1431)
+++ /trunk/jabberit_messenger/inc/jabberit_sessions.inc.php	(revision 1502)
@@ -11,52 +11,85 @@
   \***************************************************************************/
 
-		//User
-		$_SESSION['phpgw_info']['jabberit_messenger']['user_jabber']	= $GLOBALS['phpgw_info']['user']['account_lid'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['user_id']		= $GLOBALS['phpgw_info']['user']['account_id'];		
-        $_SESSION['phpgw_info']['jabberit_messenger']['passwd']			= $GLOBALS['phpgw_info']['user']['passwd'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['mail']			= $GLOBALS['phpgw_info']['user']['email'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['fullname']		= $GLOBALS['phpgw_info']['user']['fullname'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['account_dn']		= $GLOBALS['phpgw_info']['user']['account_dn'];
 
-		// User Lang 
-		$_SESSION['phpgw_info']['jabberit_messenger']['applet_lang']	= $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; 
-		
-		//Members Group
-		$_SESSION['phpgw_info']['jabberit_messenger']['membership']		= $GLOBALS['phpgw']->accounts->membership();
+	// Identifica que atributo a organizaÃ§Ã£o utiliza para autenticar no servidor jabber
+	$ou = explode(",",$GLOBALS['phpgw_info']['user']['account_dn']);
+	$ou = explode("=",$ou[3]);
+	$ou = $ou[1];
 
-		//Groups Locked
-		$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']	= $GLOBALS['phpgw_info']['server']['groups_locked_jabberit'];
+	$org_array = explode(",",$GLOBALS['phpgw_info']['server']['attributes_org_ldap_jabberit']);
 
-		//Server http or https 
-		$_SESSION['phpgw_info']['jabberit_messenger']['use_https']		= $GLOBALS['phpgw_info']['server']['use_https'];
+	for($i = 0; $i < sizeof($org_array); ++$i)
+	{
+	    $org = explode(";",$org_array[$i]);
+	    if ($org[0] == $ou)
+	    {
+	        $org = $org[1]; 
+	        break;
+	    }
+	}
 
-		//Organization Ldap
-		$_SESSION['phpgw_info']['jabberit_messenger']['account_dn']		= $GLOBALS['phpgw_info']['user']['account_dn'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'] = $org;
+	
+	// Seta a variÃ¡vel user_jabber de acordo com o atributo adotado pela organizaÃ§Ã£o
+	switch ($org) 
+	{
+		case 'uid':
+			$_SESSION['phpgw_info']['jabberit_messenger']['user_jabber'] = $GLOBALS['phpgw_info']['user']['account_lid'];
+			break;
+		case 'mail':
+			$_SESSION['phpgw_info']['jabberit_messenger']['user_jabber'] = $GLOBALS['phpgw_info']['user']['mail'];
+			break;
+		case 'description':
+        	$description = explode("@", $GLOBALS['phpgw_info']['user']['email']);
+			$_SESSION['phpgw_info']['jabberit_messenger']['user_jabber'] = $description[0];
+			break;
+	}
+	
+	$_SESSION['phpgw_info']['jabberit_messenger']['user_id']		= $GLOBALS['phpgw_info']['user']['account_id'];		
+   $_SESSION['phpgw_info']['jabberit_messenger']['passwd']		= $GLOBALS['phpgw_info']['user']['passwd'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['mail']			= $GLOBALS['phpgw_info']['user']['email'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['fullname']	= $GLOBALS['phpgw_info']['user']['fullname'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['account_dn']	= $GLOBALS['phpgw_info']['user']['account_dn'];
 
-		//Ldap
-		$_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']   = $GLOBALS['phpgw_info']['server']['server_ldap_jabberit'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit']  = $GLOBALS['phpgw_info']['server']['context_ldap_jabberit'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit']     = $GLOBALS['phpgw_info']['server']['user_ldap_jabberit'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'] = $GLOBALS['phpgw_info']['server']['password_ldap_jabberit'];
+	// User Lang 
+	$_SESSION['phpgw_info']['jabberit_messenger']['applet_lang'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; 
+	
+	//Members Group
+	$_SESSION['phpgw_info']['jabberit_messenger']['membership']	= $GLOBALS['phpgw']->accounts->membership();
+
+	//Groups Locked
+	$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked'] = $GLOBALS['phpgw_info']['server']['groups_locked_jabberit'];
+
+	//Server http or https 
+	$_SESSION['phpgw_info']['jabberit_messenger']['use_https'] 	= $GLOBALS['phpgw_info']['server']['use_https'];
+
+	//Organization Ldap
+	$_SESSION['phpgw_info']['jabberit_messenger']['account_dn']	= $GLOBALS['phpgw_info']['user']['account_dn'];
+
+	//Ldap
+	$_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']   = $GLOBALS['phpgw_info']['server']['server_ldap_jabberit'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit']  = $GLOBALS['phpgw_info']['server']['context_ldap_jabberit'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit']     = $GLOBALS['phpgw_info']['server']['user_ldap_jabberit'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'] = $GLOBALS['phpgw_info']['server']['password_ldap_jabberit'];
         
-        //DB
-        $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name']	 = $GLOBALS['phpgw_info']['server']['db_name'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host']	 = $GLOBALS['phpgw_info']['server']['db_host'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_port']	 = $GLOBALS['phpgw_info']['server']['db_port'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_user']	 = $GLOBALS['phpgw_info']['server']['db_user'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_pass']	 = $GLOBALS['phpgw_info']['server']['db_pass'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_type'] 	 = $GLOBALS['phpgw_info']['server']['db_type'];
+   //DB
+   $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name']	 = $GLOBALS['phpgw_info']['server']['db_name'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host']	 = $GLOBALS['phpgw_info']['server']['db_host'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_port']	 = $GLOBALS['phpgw_info']['server']['db_port'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_user']	 = $GLOBALS['phpgw_info']['server']['db_user'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_pass']	 = $GLOBALS['phpgw_info']['server']['db_pass'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_type'] 	 = $GLOBALS['phpgw_info']['server']['db_type'];
 
-		//Jabberd
-        $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']					= $GLOBALS['phpgw_info']['server']['name_jabberit'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['ip_server_jabberit']				= $GLOBALS['phpgw_info']['server']['ip_server_jabberit'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['port_1_jabberit']				= $GLOBALS['phpgw_info']['server']['port_1_jabberit'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['port_2_jabberit']				= $GLOBALS['phpgw_info']['server']['port_2_jabberit'];        
-        $_SESSION['phpgw_info']['jabberit_messenger']['resource_jabberit']				= $GLOBALS['phpgw_info']['server']['resource_jabberit'];
-        $_SESSION['phpgw_info']['jabberit_messenger']['group_chat_jabberit']			= $GLOBALS['phpgw_info']['server']['group_chat_server_jabberit'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['name_company']					= $GLOBALS['phpgw_info']['server']['name_company_applet_jabberit'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['use_attribute_jabberit']			= $GLOBALS['phpgw_info']['server']['use_attribute_jabberit'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']	= $GLOBALS['phpgw_info']['server']['attributes_org_ldap_jabberit'];
-		$_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']			= $GLOBALS['phpgw_info']['server']['map_org_realm_jabberit'];
+	//Jabberd
+   $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']						= $GLOBALS['phpgw_info']['server']['name_jabberit'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['port_jabberit']						= $GLOBALS['phpgw_info']['server']['port_jabberit'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['resource_jabberit']				= $GLOBALS['phpgw_info']['server']['resource_jabberit'];
+   $_SESSION['phpgw_info']['jabberit_messenger']['group_chat_jabberit']				= $GLOBALS['phpgw_info']['server']['group_chat_server_jabberit'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['use_ssl_jabberit']					= $GLOBALS['phpgw_info']['server']['use_ssl_jabberit'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['use_proxy_java']					= $GLOBALS['phpgw_info']['server']['use_proxy_java'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['name_company']						= $GLOBALS['phpgw_info']['server']['name_company_applet_jabberit'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['use_attribute_jabberit'] 		= $GLOBALS['phpgw_info']['server']['use_attribute_jabberit'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']	= $GLOBALS['phpgw_info']['server']['attributes_org_ldap_jabberit'];
+	$_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']			= $GLOBALS['phpgw_info']['server']['map_org_realm_jabberit'];
 
 ?>
Index: /trunk/jabberit_messenger/inc/class.ldap_im.inc.php
===================================================================
--- /trunk/jabberit_messenger/inc/class.ldap_im.inc.php	(revision 1438)
+++ /trunk/jabberit_messenger/inc/class.ldap_im.inc.php	(revision 1502)
@@ -2,6 +2,6 @@
   /***************************************************************************\
   *  Expresso - Expresso Messenger                                            *
-  *  	- Alexandre Correia / Rodrigo Souza							          *
-  *  	- JETI - http://jeti-im.org/										  *
+  *  	- Alexandre Correia / Rodrigo Souza			              						*
+  *  	- JETI - http://jeti-im.org/					      								*
   * ------------------------------------------------------------------------- *
   *  This program is free software; you can redistribute it and/or modify it  *
@@ -17,5 +17,4 @@
 class ldap_im
 {
-	private $attr_org;
 	private $common;
 	private $hostsJabber;
@@ -30,7 +29,4 @@
 	public final function __construct()
 	{
-		// Attributes org ldap;
-		$this->attr_org = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']);
-		
 		// Hosts Jabber
 		$this->hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
@@ -51,17 +47,14 @@
 		
 		$GLOBALS['phpgw_info']['server']['ldap_version3'] = true;
-		
-		if( $this->ldap_user && $this->ldap_pass )
-			$this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_user . "," . $this->ldap_context , $this->ldap_pass, false );
-		else
-			$this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_context , "", false );
+
+		$this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_user . "," . $this->ldap_context , $this->ldap_pass, false );
 	}
 	
 	private final function ldapRoot()
 	{
-		$this->ldap_host 	= $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'];
-		$this->ldap_context	= $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'];
-		$this->ldap_user	= $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'];
-		$this->ldap_pass	= $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'];
+		$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_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'];
 
 		$this->ldapConn();
@@ -149,52 +142,17 @@
 		if( $this->ldap )
 		{
-			$filter = "(ou=*)";
-			$justthese = array("dn");
-			$search = ldap_search($this->ldap, $this->ldap_context, $filter, $justthese);
-			$info = ldap_get_entries($this->ldap, $search);
-		
-			for ($i=0; $i<$info["count"]; $i++)
-				$a_sectors[] = $info[$i]['dn'];	
+			$filter="ou=*";		
+			$justthese = array("ou");
+			$search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese);			
+			$entry = ldap_get_entries($this->ldap, $search);
 		}
 
-		// Retiro o count do array info e inverto o array para ordenação.
-		foreach ($a_sectors as $context)
-		{
-			$array_dn = ldap_explode_dn ( $context, 1 );
-			$array_dn_reverse  = array_reverse ( $array_dn, true );
-			array_pop ( $array_dn_reverse );
-			$inverted_dn[$context] = implode ( "#", $array_dn_reverse );
-		}
-		
-		// Ordenação
-		natcasesort($inverted_dn);
-
-		foreach ( $inverted_dn as $dn=>$invert_ufn )
-		{
-            $display = '';
-
-            $array_dn_reverse = explode ( "#", $invert_ufn );
-            $array_dn  = array_reverse ( $array_dn_reverse, true );
-
-            $level = count( $array_dn ) - (int)(count(explode(",", $this->ldap_context)) + 1);
-
-            if ($level == 0)
-                    $display .= '+';
-            else 
-            {
-				for( $i = 0; $i < $level; $i++)
-					$display .= '---';
-            }
-
-            reset ( $array_dn );
-            $display .= ' ' . (current ( $array_dn ) );
-			
-			$dn = trim(strtolower($dn));
-			$options[$dn] = $display;
-    	}
-
-	    return $options;
-
-	}
+		foreach($entry as $tmp)
+			if($tmp['ou'][0] != "")
+				$result_org[] = $tmp['ou'][0];  
+
+		return $result_org;
+	}
+
 
 	public final function getUsersLdapCatalog( $search )
@@ -208,5 +166,5 @@
 		{
 			$this->ldap_host 	= $confHosts[$i]['serverLdap'];
-			$this->ldap_context = $confHosts[$i]['contextLdap'];
+			$this->ldap_context	= $confHosts[$i]['contextLdap'];
 			$this->ldap_user	= $confHosts[$i]['user'];
 			$this->ldap_org		= $confHosts[$i]['org'];
@@ -218,5 +176,19 @@
 			{
 				$filter = "(&(phpgwaccounttype=u)(".$search ."))";
-				$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");								
+
+				// Verificando atributo que a organizaÃ§Ã£o utiliza para autenticar no servidor jabber
+				switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
+				{
+					case 'description':
+	            	$justthese = array("uid","uidNumber","cn","description", "mail","phpgwAccountVisible","dn","jpegPhoto");
+						break;
+					case 'uid':
+						$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");	
+						break;
+					case 'mail':
+						$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");	
+						break;
+				}
+
 				$searchRoot = ( $this->ldap_org != "*" ) ? "ou=".$this->ldap_org.",".$this->ldap_context : $this->ldap_context;
 				
@@ -248,5 +220,19 @@
 			$searchRoot = ( $ous ) ? $ous.",".$this->ldap_context : $this->ldap_context ;
 			$filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))";
-			$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");								
+
+			// Verificando atributo que a organizaÃ§Ã£o utiliza para autenticar no servidor jabber
+			switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
+			{
+				case 'description':
+					$justthese = array("uid","uidNumber","cn","description", "mail","phpgwAccountVisible","dn","jpegPhoto");
+					break;
+				case 'uid':
+					$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");
+					break;
+				case 'mail':
+					$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");
+					break;
+			}
+
 			$search = ldap_search($this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1);
 			$entry = ldap_get_entries( $this->ldap, $search );
@@ -269,7 +255,21 @@
 			{
 				$result[$j]['uidnumber'] = $entry[$i]['uidnumber'][0];			
-				$result[$j]['mail']	=  $entry[$i]['mail'][0];
-				$result[$j]['uid']	=  $entry[$i]['uid'][0];
-				$result[$j]['jid']	= $entry[$i]['uid'][0];
+				$result[$j]['mail']	 = $entry[$i]['mail'][0];
+				$result[$j]['uid']	 = $entry[$i]['uid'][0];
+
+				// Verificando atributo que a organizaÃ§Ã£o utiliza para autenticar no servidor jabber
+				switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
+				{
+					case 'description':
+						$result[$j]['jid'] = $entry[$i]['description'][0];
+						break;
+					case 'uid':
+						$result[$j]['jid'] = $entry[$i]['uid'][0];
+						break;
+					case 'mail':
+						$result[$j]['jid'] = $entry[$i]['uid'][0];
+						break;
+				}
+
 				$ou = explode("dc=", $entry[$i]['dn']);
 				$ou = explode("ou=",$ou[0]);
@@ -283,5 +283,18 @@
 					$firstEntry = ldap_first_entry($pConn, $photoLdap);
 					$photo = ldap_get_values_len($pConn, $firstEntry, "jpegPhoto");
-					$_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result[$j]['ou'])][trim($result[$j]['uid'])] = $photo[0];
+
+					// Verificando atributo que a organizaÃ§Ã£o utiliza para autenticar no servidor jabber
+					switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
+					{
+						case 'description':
+							$_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result[$j]['ou'])][trim($result[$j]['jid'])] = $photo[0];
+							break;
+						case 'uid':
+							$_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result[$j]['ou'])][trim($result[$j]['uid'])] = $photo[0];
+							break;
+						case 'mail':
+							$_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result[$j]['ou'])][trim($result[$j]['uid'])] = $photo[0];
+							break;
+					}
 				}
 				else
@@ -290,30 +303,21 @@
 				$result[$j++]['cn']	= $entry[$i]['cn'][0];
 			}
-		
-			$organization = $this->attr_org;
-	
-			if(is_array($organization))
+	                                
+			// Verificando atributo que a organizaÃ§Ã£o utiliza para autenticar no servidor jabber
+			switch ($_SESSION['phpgw_info']['jabberit_messenger']['user_org_att'])
 			{
-				foreach($organization as $attr)
-				{
-					$tmp = explode(";",$attr);
-					if( strtolower(trim($tmp[0])) == strtolower(trim($result[$i]['dn'])) )
-					{
-						switch(strtolower(trim($tmp[1])))
-						{
-							case "mail" :
-									$uid = $result[$i]['mail'];
-									$uid = substr($uid,0,strpos($uid,"@"));	
-									$result[$i]['uid'] = $uid;
-									break;
-	
-							case "description" :
-									// SERPRO
-									// parte antes do arroba; 
-									$result[$i]['uid'] = $result[$i]['description']; 										
-									break;
-						}
-					}
-				}
+				case 'description':
+					$result[$i]['uid'] = $result[$i]['description'];
+					break;
+				case 'uid':
+					$uid = $result[$i]['mail'];
+					$uid = substr($uid,0,strpos($uid,"@")); 
+					$result[$i]['uid'] = $uid;
+					break;
+				case 'mail':
+					$uid = $result[$i]['mail'];
+					$uid = substr($uid,0,strpos($uid,"@")); 
+					$result[$i]['uid'] = $uid;
+					break;  
 			}
 		}
