Index: sandbox/jabberit_messenger/trophy_expresso/xsl/listLdapContacts.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/xsl/listLdapContacts.xsl	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/xsl/listLdapContacts.xsl	(revision 2411)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+	<xsl:output method="html" omit-xml-declaration="yes"/>
+
+	<xsl:param name="lang_addContact" />
+	<xsl:param name="lang_empty" />
+	<xsl:param name="lang_many_results" />
+	
+	<xsl:template match="/">
+		<xsl:choose>
+			<xsl:when test="error">
+				<label><xsl:value-of select="$lang_many_results" /></label>
+			</xsl:when>
+			<xsl:when test="empty">
+				<label><xsl:value-of select="$lang_empty" /></label>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:apply-templates select="uids/*" mode="uids" />
+			</xsl:otherwise>
+		</xsl:choose>
+	</xsl:template>
+
+	<xsl:template match="*" mode="uids">
+		<xsl:for-each select="data">
+			<xsl:sort select="cn"/>
+			<span value="{mail};{uid}" jid="{jid}" ou="{ou}" photo="{photo}">
+				<span id="{mail};{uid}" style="display:none;"><xsl:value-of select="cn" /></span>
+				<b><xsl:value-of select="name(..)"/></b>
+				<br/><xsl:value-of select="cn" />
+				<br/>
+				<br/>
+				<label id="__label__{mail};{uid}" style="color:blue;cursor:pointer;"><xsl:value-of select="$lang_addContact" /></label>
+				<br/>
+			</span>
+		</xsl:for-each>
+	</xsl:template>
+
+</xsl:stylesheet>
Index: sandbox/jabberit_messenger/trophy_expresso/xsl/addUser.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/xsl/addUser.xsl	(revision 2397)
+++ sandbox/jabberit_messenger/trophy_expresso/xsl/addUser.xsl	(revision 2411)
@@ -3,34 +3,31 @@
 	<xsl:output method="html" omit-xml-declaration="yes"/>
 
-	
+	<xsl:param name="lang_group" />
+	<xsl:param name="lang_load" />
+	<xsl:param name="lang_name_contact" />
+	<xsl:param name="lang_result" />
+	<xsl:param name="path" />
+
 	<xsl:template match="userinfo">
 
-	<xsl:param name="lang1" />
-	<xsl:param name="lang2" />
-	<xsl:param name="lang3" />
-	<xsl:param name="lang4" />
-	<xsl:param name="lang5" />
-	<xsl:param name="lang6" />
-	<xsl:param name="lang7" />
-	<xsl:param name="path" />
+		<div style="margin:2px">
+			<div style="margin:5px 0px 5px 5px;">
+				<span style="width:150px;"><xsl:value-of select="$lang_name_contact" /> .: </span>
+				<input id="search_user_jabber" type="text" size="30" onclick="this.select();" onkeypress="loadIM.keyPressSearch(event, this);" />
+				<br style="clear:both"/>
+				<button style="margin:-17px 0px 0px 290px;" onclick="loadIM.searchUser()"><img src="{$path}templates/default/images/users.png"/></button>
+			</div>
 
-
-		
-		<div style="margin:2px">
-			<div class="search_user">
-				<span style="width:130px;"><xsl:value-of select="$lang1" /> .: </span>
-				<input type="text" size="30" onclick="this.select();" onkeypress="alert(event);" style="margin: 0 10 0 0px;"/>
-				<input type="image" src='{$path}templates/default/images/users.png' value="{$lang2}" onclick="alert(this);" />
-			</div>
-			<br/>
-			<div class="add_organization_members">
-				<span style="margin: 5px; width:auto;"><xsl:value-of select="$lang3"/> .: </span>
+			<div style="margin:7px 0px 5px 5px;">
+				<span style="width:auto;text-decoration:underline;"><xsl:value-of select="$lang_result"/> .: </span>
 				<br style="clear:both"/>
-				<div id="im_ldap_user"></div>
+				<div id="list_users_ldap_im"></div>
 			</div>
 		</div>
 
 		<span id="im_status_add" style="color:#f00;"></span>
-		<span id="__span_load_im" style="background-color:#cc4444;color:white;display:none;position:absolute;right:5px;top:26px">Carregando .....</span>
+		<span id="span_searching_im" style="background-color:#cc4444;color:white;display:none;position:absolute;right:5px;top:26px;padding:2px;">
+			<xsl:value-of select="$lang_load" /> ...
+		</span>
 		<input id="im_jidUser" type="hidden" />
 		<input id="im_jid" type="hidden" />
@@ -41,5 +38,4 @@
 	<xsl:template match="adduser">
 		
-
 		<div class="add_member_info">
 			<span><xsl:value-of select="$lang4"/> : </span>
Index: sandbox/jabberit_messenger/trophy_expresso/controller.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/controller.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/controller.php	(revision 2411)
@@ -0,0 +1,37 @@
+<?php
+
+if(!isset($GLOBALS['phpgw_info']))
+{
+        $GLOBALS['phpgw_info']['flags'] = array(
+                'currentapp' => 'jabberit_messenger',
+        );
+}
+
+require_once '../header.session.inc.php';
+
+$request_method = '_' . $_SERVER['REQUEST_METHOD'];
+switch ( $request_method )
+{
+	case '_GET' :
+		$params = $_GET;
+	break;
+	case '_POST' :
+		$params = $_POST;
+	break;
+	case '_HEAD' :
+	case '_PUT' :
+	default :
+		echo "controller - request method not avaible";
+		return false;
+}
+
+if( file_exists(dirname(__FILE__) . "/inc/Controller.class.php") )
+{
+	require_once dirname(__FILE__) . '/inc/Controller.class.php';
+
+	$controller = new Controller();
+	printf("%s", $controller->exec($$request_method, dirname(__FILE__)));
+	exit(0);
+}
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/controller.xml
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/controller.xml	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/controller.xml	(revision 2411)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<controller>
+	<controller-security>
+		<string-access>act</string-access>
+		<string-delimiter>.</string-delimiter>
+	</controller-security>
+	<controller-contentes>
+		<item param="c" section="css" />
+		<item param="j" section="js" />
+		<item param="p" section="php" />
+		<item param="xm" section="xml" />
+		<item param="xs" section="xsl" />
+	</controller-contentes>
+	<controller-sections>
+		<css></css>
+		<js path="/js" suffix=".js">
+			<item ref="connector" js="connector" />
+		</js>
+		<php path="/inc" suffix=".class.php">
+			<item ref="cc" alias="getListContacts" class="ContactsIm" method="getListContacts" prefix="class." suffix=".inc.php"/>
+		</php>
+		<xml></xml>
+		<xsl></xsl>
+	</controller-sections>
+</controller>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/webservice.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/webservice.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/webservice.php	(revision 2411)
@@ -0,0 +1,408 @@
+<?php
+  /***************************************************************************\
+  *  Expresso - Expresso Messenger                                            *
+  *  	- Alexandre Correia / Rodrigo Souza							          *
+  *  	- JETI - http://jeti-im.org/										  *
+  * ------------------------------------------------------------------------- *
+  *  This program is free software; you can redistribute it and/or modify it  *
+  *  under the terms of the GNU General Public License as published by the    *
+  *  Free Software Foundation; either version 2 of the License, or (at your   *
+  *  option) any later version.                                               *
+  \***************************************************************************/
+
+class webService
+{
+	private $attribute;
+	private $conn;
+	private $contextLdap;
+	private $userLDAP;	
+	private $jabberName = null;
+	private $passwd;
+	private $photo_user = array();
+	private $refer;
+	private $serverLdap;
+	private $fileLdapInternal = false;
+	private $fileLdapExternal = false;
+	private $version3;
+	
+	function __construct()
+	{
+		if ( file_exists('confLDAPInternal.php') )
+		{
+			require_once('confLDAPInternal.php');
+			$handle   = unserialize(base64_decode($LDAP_INTERNAL));
+	
+			$this->jabberName	= $handle['jabberName'];
+			$this->serverLdap	= $handle['serverLdap'];
+			$this->contextLdap	= $handle['contextLdap'];
+			$this->userLDAP		= $handle['user'];
+			$this->passwd		= $handle['password'];
+			
+			$this->refer  	= true;
+			$this->version3 = true;
+			
+			$this->fileLdapInternal = true;
+		}
+		
+		$this->attribute = "uid";
+		
+		if ( file_exists('attributeLdap.php') )
+		{
+			require_once('attributeLdap.php');
+			$this->attribute = trim($attributeTypeName);
+		}
+	}
+	
+	private final function ldapConnect()
+	{
+		if(!function_exists('ldap_connect'))
+			return False;
+		
+		if(!$this->conn = ldap_connect($this->serverLdap))
+			return False;
+
+		if( $this->version3 )
+			if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) )
+				$this->version3 = false;
+
+		ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer);
+
+		// Bind as Admin
+		if( $this->userLDAP && $this->passwd && !ldap_bind($this->conn, $this->userLDAP . "," . $this->contextLdap, $this->passwd) )
+			return False;
+		
+		// Bind as Anonymous
+		if( !$this->userLDAP && !$this->passwd && !@ldap_bind($this->conn) )
+			return False;
+	}
+
+	private final function ldapConnectExternal($pHostJabber)
+	{
+		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->fileLdapExternal = true;
+				}
+			}		
+	
+			$this->refer  	= true;
+			$this->version3 = true;
+			
+			$this->ldapConnect();
+		}
+	}
+	
+	public final function CallVoipConnect($pVoipFrom, $pVoipTo)
+	{
+		$this->ldapConnect();
+
+		if( $this->conn )
+		{
+			$filter  = "(|(&(phpgwaccounttype=u)(uid=".$pVoipFrom."))(&(phpgwaccounttype=u)(uid=".$pVoipTo.")))";
+			$justthese = array("telephoneNumber", "uid");
+			$search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
+			$entry = ldap_get_entries($this->conn,$search);
+
+			$fromNumber = $entry[0]['telephonenumber'][0];
+			$toNumber = $entry[1]['telephonenumber'][0];
+
+			if ( trim($entry[0]['uid'][0]) !== trim($pVoipFrom) )
+			{
+				$fromNumber = $entry[1]['telephonenumber'][0];
+				$toNumber = $entry[0]['telephonenumber'][0];
+			}
+		}
+		
+		if( $fromNumber && $toNumber )
+		{
+			$voipServer	= "www.pabx.celepar.parana";
+			$voipUrl	= "/telefoniaip/servicos/voip.php";
+			$voipPort	= "80";
+	
+			if( !$voipServer || !$voipUrl || !$voipPort )
+				return false;
+			
+			$url		= "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber;
+			$sMethod	= 'GET ';
+			$crlf		= "\r\n";
+			$sRequest	= " HTTP/1.1" . $crlf;
+			$sRequest	.= "Host: localhost" . $crlf;
+			$sRequest	.= "Accept: */* " . $crlf;
+			$sRequest	.= "Connection: Close" . $crlf . $crlf;            
+			$sRequest	= $sMethod . $url . $sRequest;    
+			$sockHttp	= socket_create(AF_INET, SOCK_STREAM, SOL_TCP);            
+			
+			if ( !$sockHttp )
+			    return false;
+			
+			$resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort);
+			
+			if ( !$resSocketConnect )
+			    return false;
+	
+			$resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest));
+	
+			if ( !$resSocketWrite )
+			    return false;
+	    
+			$sResponse = '';    
+	
+			while ($sRead = socket_read($sockHttp, 512))
+			{
+			    $sResponse .= $sRead;
+			}            
+			
+			socket_close($sockHttp);            
+			
+			$pos = strpos($sResponse, $crlf . $crlf);
+			
+			return substr($sResponse, $pos + 2 * strlen($crlf));
+		}
+		
+		return "ERRO";									
+	}
+	
+	
+	public final function getNameOrganization($pJid, $pCharset)
+	{
+		$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->fileLdapInternal )
+			{
+				if( $this->conn )
+				{
+					$filter = "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese = array($this->attribute,"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 )
+				{
+					$filter = "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese = array($this->attribute,"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");
+
+	}
+	
+	public final function getPhotoLdap( $pJid , $pLdapInternal )
+	{
+		$uid = substr($pJid, 0, strpos($pJid, "@"));
+
+		if( $pLdapInternal )
+		{
+			if( !$this->fileLdapInternal )
+				return false;
+
+			if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
+			{
+				
+				$this->ldapConnect();
+				
+				if( $this->conn )
+				{
+					$filter			= "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))";
+					$justthese		= array($this->attribute,"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;								
+					}
+				}
+			}
+		}
+		else
+		{					
+			if( !$this->fileLdapExternal )
+				return false;
+				
+			$jabberName = substr($pJid, strpos($pJid, "@") + 1 );
+
+			if( strpos($jabberName, "/") )
+				$jabberName = substr($jabberName, 0, strpos($jabberName, "/"));
+
+			$this->ldapConnectExternal($jabberName);
+
+			if( $this->conn )
+			{
+				$filter			= "(&(phpgwaccounttype=u)(".$this->attribute."=".$uid.")(!(phpgwaccountvisible=-1)))";
+				$justthese		= array($this->attribute,"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;
+	}
+	
+	public final function getPhotoSession($pUid, $pOu)
+	{
+		$uid = $pUid;
+		if( strpos($pUid, "@") )
+			$uid = substr($pUid, 0, strpos($pUid, "@"));
+		
+		require_once("../../header.session.inc.php");
+		
+		if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]) )
+		{
+			$photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
+
+			header("Content-Type: image/jpeg");
+			$width = imagesx($photo);
+			$height = imagesy($photo);
+			$twidth = 60;
+			$theight = 80;
+			$small_photo = imagecreatetruecolor ($twidth, $theight);
+			imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
+			imagejpeg($small_photo,'',100);
+
+			unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
+
+			return;	
+		}
+	}
+}
+
+// Applet - utilizando o serviço Voip;
+if(trim($_REQUEST['javaVoipFrom']) != "" && trim($_REQUEST['javaVoipTo']) != "" )
+{
+	$obj = new webService();
+	$voipFrom = $_REQUEST['javaVoipFrom'];
+	$voipTo = $_REQUEST['javaVoipTo'];
+	printf("%s",$obj->CallVoipConnect($voipFrom, $voipTo));
+}
+
+// Applet - fotos pelo applet; 
+if(trim($_REQUEST['javaPhoto']) != "" )
+{
+	$obj = new webService();
+	$jid = $_REQUEST['javaPhoto'];
+	$jid = ( strpos($jid, "/") !== false ) ? substr($jid, 0, strpos($jid, "/")) : $jid;
+	
+	$photo = $obj->getPhotoLdap( $jid, true );
+	$photoWidth = 70;
+	$photoHeight = 90;
+	$newImage = imagecreatetruecolor($photoWidth,$photoHeight);		
+
+	if( $photo )
+	{
+		$photo = imagecreatefromstring($photo);
+		imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
+	}
+	else
+	{
+		$photo = $obj->getPhotoLdap($jid, false);
+		if( $photo )
+		{
+			$photo = imagecreatefromstring($photo);
+			imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
+		}
+		else
+		{
+			$photo = @imagecreatefrompng("../templates/default/images/photo.png");
+			imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
+		}
+	}
+	
+	ob_start();
+	imagepng($newImage);
+	$imagePhoto = ob_get_contents();
+	imagedestroy($newImage);
+	ob_end_clean();
+	printf("%s",base64_encode($imagePhoto));
+}
+
+// Applet - jid;
+if(trim($_REQUEST['jid']) != "")
+{
+	
+	$jid = trim($_REQUEST['jid']);
+	$charset = trim($_REQUEST['charset']);
+	$obj = new webService();
+	
+	printf("%s",$obj->getNameOrganization($jid, $charset));
+}
+
+// Php - fotos pelo php;
+if(trim($_REQUEST['phpPhoto']) != "")
+{
+	$obj = new webservice();
+	$ou = $_REQUEST['phpOu'];
+	$jid = $_REQUEST['phpPhoto'];
+	
+	$obj->getPhotoSession($jid, $ou);
+}
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/class.ContactsIm.inc.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/class.ContactsIm.inc.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/class.ContactsIm.inc.php	(revision 2411)
@@ -0,0 +1,423 @@
+<?php
+
+require_once "class.DataBaseIM.inc.php";
+require_once "class.LdapIM.inc.php";
+
+class ContactsIm
+{
+	private $db;
+	private $dn_User;
+	private $hostsJabberLdap;	
+	private $ldap;
+	private $ou_User;
+	private $serverJabber;
+	private $serverLdap;
+		
+	function __construct()
+	{
+		$this->ldap	= new LdapIM();
+		$this->db	= new DataBaseIM();
+
+		// (DN) User
+		$this->dn_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
+
+		// (OU) User
+		$this->ou_User = $this->dn_User;
+		$this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
+		$this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
+		
+		// Server Name Jabber
+		$this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit'];
+	
+		// Server Name Ldap
+		$this->serverLdap	= $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'];
+		
+		// Hosts Jabber / Ldap
+		$this->hostsJabberLdap = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);	
+	}
+
+	public final function getListContacts($param)
+	{
+		
+		// TESTE REMOVER 
+		$param['name'] = "alexandre*correia";
+		
+		$order		= array();
+		$ou_User	= substr($this->ou_User, (strpos($this->ou_User,"=")+1));
+		$return		= '<empty/>';
+		$users		= $this->getUsersIm($param['name']);
+
+		
+		if (!is_array($users) && trim($users) === 'Many Results')
+			return "<error>Many Results</error>";
+
+		// Hosts Jabber
+		$hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
+
+		if( is_array($users) )
+		{	
+			for($i = 0; $i < count($users); $i++)				
+			{
+				if( is_array($hostsJabber) )
+				{
+					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'];
+						}
+						
+						if( array_key_exists('ouAll', $users[$i]) && trim($itens['org']) === "*" )
+						{
+							$users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];
+						}
+					}
+				}
+
+				if( strpos($users[$i]['jid'],"@") === false )
+				{
+					$users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
+				}
+			}
+
+			foreach($users as $tmp)
+			{
+				if ( !array_key_exists($tmp['ou'], $order) )
+					$order[$tmp['ou']] = array();
+
+				$order[$tmp['ou']][] = '<data><ou>'.$tmp['ou'].'</ou><cn>'.$tmp['cn'].'</cn><mail>'.$tmp['mail'].'</mail><uid>'.$tmp['uid'].'</uid><jid>'.$tmp['jid'].'</jid><photo>'.$tmp['photo'].'</photo></data>';
+			}
+			
+			ksort($order);
+				
+			$return	= '<uids>';
+			foreach ( $order as $key => $val )
+				$return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>';
+			$return .= '</uids>';
+		}
+		
+		return $return;
+	}
+
+	private final function getUsersIm($pName)
+	{   
+		$array_uids		= array();
+        $members		= array();
+        $result			= array();
+        $uidType		= "uid";
+		$serversLdap	= unserialize(trim($_SESSION['phpgw_info']['jabberit_messenger']['groups_search']));
+		
+        if( $serversLdap )
+        {
+	        if( array_key_exists($this->serverLdap, $serversLdap) )
+	        {
+	        	$groups = unserialize($serversLdap[$this->serverLdap]);
+	        }
+
+	        if( count($groups) > 0 )
+	        {
+				foreach($groups as $tmp)
+				{
+					$group = explode(":",$tmp);
+					$array_result = $this->ldap->getGroupsMemberUid($group[0], $this->serverLdap );
+					@array_shift($array_result[0]['memberuid']);
+					$array_uids = @array_merge($array_uids, $array_result[0]['memberuid']);
+					unset($array_result);
+				}
+	        }
+        }        			
+		
+        if( count($array_uids) == 0 )
+        {
+        	$array_uids = $this->db->get_accounts_acl();
+        	$uidType = "uidnumber";	
+        }        
+
+        for( $i = 0; $i < count($array_uids) ; $i+=50 )
+        {   
+            $partial_uids = array_slice($array_uids,$i,50);
+            $filter_uid = implode(")(".$uidType."=",$partial_uids);
+            $filter_uid = "(".$uidType."=". $filter_uid. ")";
+
+			if( $this->groupsLocked() )
+			{
+	            $orgs[] = $this->ou_User;
+	            $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']); 
+	            
+				foreach( $orgsGroupsLocked as $tmp )
+				{
+					if( $tmp != "" )
+					{
+						if( strpos($tmp, "/") !== false )
+						{
+							$tt = explode("/", $tmp);
+							$newOU = implode(",OU=",array_reverse($tt));
+							$orgs[] = "OU=". $newOU ;
+						}
+						else 
+							$orgs[] = "OU=". $tmp;
+					}            
+				}
+
+	            $orgs = array_unique($orgs);
+
+				foreach( $orgs as $orgB )
+					$result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB );
+
+			}
+			else
+				$result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid);
+        }
+	
+        if( !$this->groupsLocked() )
+        {
+			unset($serversLdap[$this->serverLdap]);
+
+			if( $serversLdap  && count($serversLdap))
+			{
+				foreach( $serversLdap as $key => $tmp )
+				{
+					$array_uids_external = array( );
+					$groupsExternal = unserialize($tmp);
+
+					if( count($groupsExternal) )
+					{
+						foreach( $groupsExternal as $tmpExt )
+						{
+							$group = explode(":",$tmpExt);
+							$array_result = $this->ldap->getGroupsMemberUid( $group[0], $key );
+							
+							if( $array_result[0]['memberuid']['count'] )
+								unset($array_result[0]['memberuid']['count']);
+
+							$array_uids_external = @array_merge($array_uids_external, $array_result[0]['memberuid']);
+						}
+						
+						
+						if( is_array($array_uids_external) )
+						{
+							for( $i = 0; $i < count( $array_uids_external ) ; $i+=50 )
+		        			{   
+			            		$partial_uids_external	= array_slice($array_uids_external,$i,50);
+			            		$filter_uid_external	= implode(")(uid=",$partial_uids_external);
+		    	        		$filter_uid_external	= "(uid=". $filter_uid_external. ")";
+		    	        		$result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", $filter_uid_external, $key );
+		        			}
+		        		}
+					}
+				}
+			}
+
+			if( count($this->hostsJabberLdap) )
+			{
+				for($i = 0 ; $i < count($this->hostsJabberLdap); $i++)
+				{
+					if( !@array_key_exists($this->hostsJabberLdap[$i]['serverLdap'], $serversLdap) )
+					{
+						$result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", false, $this->hostsJabberLdap[$i]['serverLdap'] );
+					}
+				}
+			}
+        }
+        
+        if ( is_array($result) )
+        {
+          	for( $i = 0; $i < count($result); $i++ )
+           		if( is_array($result[$i]) )
+           			$members = @array_merge($members,$result[$i]);
+        }
+	     
+        if( count($members) > 150)
+        {
+	    	$ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 );
+	    	
+			for($i = 0 ; $i < count($members); $i++ )
+			{
+				if( $ou == $members[$i]['ou'] )
+				{
+					$uids_org[] = $members[$i];
+				}
+				else
+				{
+					if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']))
+						unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]);
+				}
+			}
+			
+			return $uids_org;
+        }            
+
+		return $members;        
+	}
+	
+	private final function groupsLocked()
+	{
+		$memberShip = array();
+		$groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
+		
+		foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp)
+			$memberShip[] = $tmp['account_name'];
+		
+		foreach($groupsLocked as $tmp)
+		{
+			$groups = explode(":", $tmp);
+			
+			if( array_search($groups[1], $memberShip) !== False )
+			{	
+				$_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2]; 
+				return true;
+			}
+		}
+		
+		return false;
+	}
+	
+	private final function strallpos($haystack, $needle, $offset = 0)
+	{
+	    $result = array();
+	    for($i = $offset; $i< strlen($haystack); $i++ )
+	    {
+	        $pos = strpos($haystack,$needle,$i);
+	        if($pos !== FALSE)
+	        {
+	            $offset =  $pos;
+	            if($offset >= $i)
+	                $result[] = $i = $offset;
+	        }
+	    }
+    	
+    	return $result;
+	} 
+
+	public final function verifyAddNewContact($pUid)
+	{
+		$groupsLocked	= explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
+		$gidNumbers		= array();
+		$uid			= $pUid['uid'];
+		$uid_User		= substr($this->dn_User, 0, strpos($this->dn_User, ","));
+		$uid_User		= substr($uid_User, 4);
+		
+		foreach($groupsLocked as $tmp)
+		{
+			$groups = explode(":", $tmp);
+			$gidNumbers[] = $groups[1];
+		}
+
+		$filter_gid = implode(")(gidnumber=",$gidNumbers);
+	    $filter_gid = "(gidnumber=". $filter_gid. ")";
+	
+		$result = $this->ldap->getGroupsMemberUid( $filter_gid, "localhost" );
+
+		if( $result && is_array($result) )
+		{
+			array_shift($result);
+			$i = 0;
+			
+			foreach($result as $value)
+			{
+				$Groups[$i]['dn'] = $value['dn'];
+				$Groups[$i]['gidnumber'] = $value['gidnumber'][0];
+				if(array_key_exists('memberuid',$value))
+				{
+					array_shift($value['memberuid']);
+					$Groups[$i++]['memberuid'] = $value['memberuid'];
+				}
+			}
+
+			$search = array();
+			$search_Gid = array();
+
+			// Verifica Uid em Grupo Bloqueado
+			foreach($Groups as $value)
+			{			
+				if( array_search( $uid , $value['memberuid'] ) !== false )
+				{
+					$ou = substr($value['dn'],strpos($value['dn'], "ou="));
+					if( array_search($uid_User, $value['memberuid']) === false )
+					{
+						$search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
+						$search_Gid[] = $value['gidnumber'];
+					}
+				}
+			}
+		}
+		
+	
+		if( $this->groupsLocked() )
+		{
+			if( count($search) > 0 )
+			{
+				// Verifica permissões do grupo
+				foreach($groupsLocked as $value)
+				{							
+					$tpGroups = explode(":",$value);
+					if( $tpGroups[1] == $search_Gid[0] )
+					{
+						$ousTp = explode(",",$tpGroups[2]);
+						$ou_User = strtoupper(trim($this->dn_User));
+						
+						$posAll = $this->strallpos($ou_User, "OU=" );
+						$orgs = array();
+				
+						for( $i = 0 ; $i < count($posAll); $i++ )
+						{
+							$pos = strpos($ou_User, ",");
+							$tmpString = substr($ou_User, $posAll[$i] + 3);
+							$orgs[] = substr($tmpString, 0, strpos($tmpString, ","));
+						}
+				
+						$ou_User = implode("/", array_reverse($orgs));
+
+						if( array_search( $ou_User, $ousTp) !== false )
+							return "true";
+					}
+				}
+				return "false";
+			}
+			else
+				return "true";
+		} 
+		else
+		{		
+			// Se Bloqueado verifica o Grupo	
+			if( count($search) > 0 )
+			{
+				if( array_search($this->ou_User, $search) === false )
+				{
+					// Verifica permissões do grupo
+					foreach($groupsLocked as $value)
+					{							
+						$tpGroups = explode(":",$value);
+						
+						if( $tpGroups[1] == $search_Gid[0] )
+						{
+							$ousTp = explode(",",$tpGroups[2]);
+							$ou_User = strtoupper(trim($this->dn_User));
+					
+							$posAll = $this->strallpos($ou_User, "OU=" );
+							$orgs = array();
+					
+							for( $i = 0 ; $i < count($posAll); $i++ )
+							{
+								$pos = strpos($ou_User, ",");
+								$tmpString = substr($ou_User, $posAll[$i] + 3);
+								$orgs[] = substr($tmpString, 0, strpos($tmpString, ","));
+							}
+					
+							$ou_User = implode("/", array_reverse($orgs));
+							
+							if( array_search( $ou_User, $ousTp) !== false )
+								return "true";
+						}
+					}
+					return "false";
+				}
+				return "true";
+			}					
+			return "true";
+		}
+	}
+
+}
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/class.teste.inc.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/class.teste.inc.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/class.teste.inc.php	(revision 2411)
@@ -0,0 +1,13 @@
+<?php
+
+class teste
+{
+	
+	function aqui_dentro()
+	{
+		return "Function aqui dentro";		
+	}
+	
+}
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/class.LdapIM.inc.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/class.LdapIM.inc.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/class.LdapIM.inc.php	(revision 2411)
@@ -0,0 +1,407 @@
+<?php
+  /***************************************************************************\
+  *  Expresso - Expresso Messenger                                            *
+  *  	- Alexandre Correia / Rodrigo Souza							          *
+  *  	- JETI - http://jeti-im.org/										  *
+  * ------------------------------------------------------------------------- *
+  *  This program is free software; you can redistribute it and/or modify it  *
+  *  under the terms of the GNU General Public License as published by the    *
+  *  Free Software Foundation; either version 2 of the License, or (at your   *
+  *  option) any later version.                                               *
+  \***************************************************************************/
+
+if( is_dir('../phpgwapi/inc') )
+	define('PHPGW_API_INC','../phpgwapi/inc');
+else
+	define('PHPGW_API_INC','../../phpgwapi/inc');
+
+require_once( PHPGW_API_INC . '/class.common.inc.php');
+
+class LdapIM
+{
+	private $attribute;
+	private $common;
+	private $hostsJabber;
+	private $ldap;
+	private $ldap_context;
+	private $ldap_user;
+	private $ldap_host;
+	private $ldap_org;
+	private $ldap_pass;
+	private $max_result;
+	
+	public final function __construct()
+	{
+		$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'];
+
+		// Hosts Jabber
+		$this->hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
+		
+		// Result Ldap
+		$this->max_result = 20;
+		
+		if ( file_exists('inc/attributeLdap.php') )
+		{
+			require_once('attributeLdap.php');
+			$this->attribute = trim($attributeTypeName);
+		}
+	}
+
+	public final function __destruct()
+	{
+		if( $this->ldap )
+			@ldap_close($this->ldap);
+	}	
+
+	private final function ldapConn()
+	{
+		$this->common = new common();		
+		
+		$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 );
+	}
+	
+	private final function ldapRoot()
+	{
+		$this->ldapConn();
+	}
+
+	private final function ldapCatalog()
+	{
+		$version3 = true;
+		$refer	= true;
+
+		if(!function_exists('ldap_connect'))
+			return false;
+		
+		if(!$conn = ldap_connect($this->ldap_host))
+			return false;
+
+		if( $version3 )
+			if( !ldap_set_option($conn,LDAP_OPT_PROTOCOL_VERSION,3) )
+				$version3 = false;
+
+		ldap_set_option($conn, LDAP_OPT_REFERRALS, $refer);
+
+		// Bind as Admin
+		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_user && !$this->ldap_pass && !@ldap_bind($conn))
+			return false;
+
+		return $conn;
+	}
+
+	public final function getGroupsLdap($pData)
+	{
+		$result_groups = "";
+		
+		if( $pData['serverLdap'] == $this->ldap_host || $pData['serverLdap'] == 'localhost' )
+		{
+			$this->ldapRoot();
+		}
+		else
+		{
+			$confHosts	= $this->hostsJabber;
+			
+			for($i = 0; $i < count($confHosts); $i++ )
+			{
+				if( $pData['serverLdap'] == $confHosts[$i]['serverLdap'] )
+				{
+					$this->ldap_host 	= $confHosts[$i]['serverLdap'];
+					$this->ldap_context = $confHosts[$i]['contextLdap'];
+					$this->ldap_user	= $confHosts[$i]['user'];
+					$this->ldap_org		= $confHosts[$i]['org'];
+					$this->ldap_pass	= $confHosts[$i]['password'];
+				
+					$this->ldap = $this->ldapCatalog();
+				}
+			}
+		}		
+
+		if( $this->ldap )	
+		{
+			if( !$pData['search'] && $pData['ou'] != "-1" )
+			{
+				$filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))";
+				$justthese = array("cn","gidNumber");
+				$search = ldap_list( $this->ldap, $pData['ou'] , $filter, $justthese );
+				$entry = ldap_get_entries( $this->ldap, $search );
+			}
+			
+			if( $pData['search'] )
+			{
+				$filter = "(&(phpgwAccountType=g)(&(objectClass=posixGroup)(cn=".$pData['search']."*)))";
+				$justthese = array("cn","gidNumber");
+				$search = ldap_search( $this->ldap, $this->ldap_context , $filter, $justthese );
+				$entry = ldap_get_entries( $this->ldap, $search );
+			}
+			
+			if( $entry && $entry['count'] > 0 )
+			{					
+				array_shift($entry);
+
+				foreach($entry as $tmp)
+					$groups[] = $tmp['cn'][0]."/".$tmp['gidnumber'][0];
+				
+				natsort($groups);
+				
+				$result_groups = "<ldap>";
+				foreach($groups as $gtmp)
+				{
+					$tmp = explode("/",$gtmp);	
+					$result_groups .= "<org><cn>".$tmp[0]."</cn><gid>".$tmp[1]."</gid></org>";
+				}
+				$result_groups .= "</ldap>";
+			}
+		}
+
+		return $result_groups;
+	}
+
+	public final function getGroupsMemberUid( $pGroup, $pLdap )
+	{
+		if( $pLdap == $this->ldap_host || $pLdap == 'localhost' )
+		{
+			$this->ldapRoot();
+			
+			if( $this->ldap )
+			{
+				$filter = "(&(objectclass=posixgroup)(|".$pGroup."))";
+				if( strpos($pGroup, "gidnumber") === false )
+					$filter = "(&(objectclass=posixgroup)(cn=".$pGroup."))";
+					
+				$justthese = array("dn","memberuid","gidnumber");
+				$search = ldap_search($this->ldap, $this->ldap_context, $filter, $justthese);
+				$result = ldap_get_entries($this->ldap,$search);
+			}
+		}
+		else
+		{
+			$confHosts	= $this->hostsJabber;
+		
+			for($i = 0; $i < count($confHosts); $i++ )
+			{
+				if( $this->ldap )
+					@ldap_close($this->ldap);
+					
+				if( trim($pLdap) === trim($confHosts[$i]['serverLdap']) )
+				{
+					$this->ldap_host 	= $confHosts[$i]['serverLdap'];
+					$this->ldap_context = $confHosts[$i]['contextLdap'];
+					$this->ldap_user	= $confHosts[$i]['user'];
+					$this->ldap_org		= $confHosts[$i]['org'];
+					$this->ldap_pass	= $confHosts[$i]['password'];
+					$this->ldap = $this->ldapCatalog();
+					
+					if( $this->ldap )
+					{
+						$filter = "(&(objectclass=posixgroup)(cn=".$pGroup."))";
+						$justthese = array("dn","memberuid","gidnumber");
+						$search = ldap_search($this->ldap,$this->ldap_context,$filter, $justthese);
+						$result = ldap_get_entries($this->ldap,$search);
+					}
+					
+				}
+			}
+		}
+
+		if( $result['count'] > 0 )
+			return $result;
+
+		return false;
+	}
+
+	public final function getOrganizationsLdap($pLdap_host)
+	{
+
+		if( $pLdap_host == $this->ldap_host || $pLdap_host == 'localhost' )
+		{
+			$this->ldapRoot();
+		}
+		else
+		{
+			$confHosts	= $this->hostsJabber;
+			
+			for($i = 0; $i < count($confHosts); $i++ )
+			{
+				if( $pLdap_host == $confHosts[$i]['serverLdap'] )
+				{
+					$this->ldap_host 	= $confHosts[$i]['serverLdap'];
+					$this->ldap_context = $confHosts[$i]['contextLdap'];
+					$this->ldap_user	= $confHosts[$i]['user'];
+					$this->ldap_org		= $confHosts[$i]['org'];
+					$this->ldap_pass	= $confHosts[$i]['password'];
+				
+					$this->ldap = $this->ldapCatalog();
+				}
+			}
+		}
+		
+		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'];
+			}	
+		}
+
+		// 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;
+
+	}
+
+	public final function getUsersLdapCatalog( $search, $uid = false, $pLdap = false )
+	{
+		$confHosts	= $this->hostsJabber;
+		$result = array();
+		$return	= array();
+		$conn	= "";		
+
+		for( $i = 0; $i < count($confHosts); $i++ )
+		{
+			if( $pLdap && $pLdap == $confHosts[$i]['serverLdap'] )
+			{
+				$this->ldap_host 	= $confHosts[$i]['serverLdap'];
+				$this->ldap_context = $confHosts[$i]['contextLdap'];
+				$this->ldap_user	= $confHosts[$i]['user'];
+				$this->ldap_org		= $confHosts[$i]['org'];
+				$this->ldap_pass	= $confHosts[$i]['password'];
+				$this->ldap 		= $this->ldapCatalog();
+
+				if( $this->ldap )
+				{
+					$filter 	= ( $uid ) ? "(&(phpgwaccounttype=u)(|".$uid.")(".$search ."))" : "(&(phpgwaccounttype=u)(".$search ."))";
+					$justthese	= array( $this->attribute ,"uidNumber" ,"cn" ,"mail" ,"phpgwAccountVisible" ,"dn" ,"jpegPhoto" );								
+					$searchRoot	= ( $this->ldap_org != "*" ) ? "ou=".$this->ldap_org.",".$this->ldap_context : $this->ldap_context;
+					$search1	= @ldap_search($this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1);
+					$entry1		= @ldap_get_entries( $this->ldap, $search1 );
+					$result 	= $this->resultArray( $entry1, $this->ldap, $this->ldap_org );
+	
+					if( count($return) > 0 )
+			          	$return = array_merge($return, $result);
+					else
+						$return = $result;				
+				}
+				
+				if( $this->ldap )
+					ldap_close($this->ldap);
+			}
+		}
+		
+		return $return;
+	}
+
+	public final function getUsersLdapRoot( $search, $uidnumber, $ous = false )
+	{
+		$result = array();
+		$this->ldapRoot();
+
+		if( $this->ldap )
+		{
+			$searchRoot	= ( $ous ) ? $ous.",".$this->ldap_context : $this->ldap_context ;
+			$filter		= "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))";
+			$justthese	= array( $this->attribute, "uidNumber", "cn", "mail", "phpgwAccountVisible", "dn", "jpegPhoto" );								
+			$search		= ldap_search( $this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1);
+			$entry		= ldap_get_entries( $this->ldap, $search );
+			$result		= $this->resultArray( $entry, $this->ldap );
+		}		
+
+		return $result;
+	}
+	
+	private final function resultArray($pArray, $pConn, $pOrg = false)
+	{
+		$entry	= $pArray;
+		$result	= array();
+		$j		= 0;
+		
+		for( $i = 0 ; $i < $entry['count']; $i++ )
+		{
+			if ( $entry[$i]['phpgwaccountvisible'][0] != '-1' )
+			{
+				$result[$j]['uidnumber']	= $entry[$i]['uidnumber'][0];			
+				$result[$j]['mail']			= $entry[$i]['mail'][0];
+				$result[$j]['uid']			= $entry[$i][$this->attribute][0];
+				$result[$j]['jid']			= $entry[$i][$this->attribute][0];
+				
+				$ou = explode("dc=", $entry[$i]['dn']);
+				$ou = explode("ou=",$ou[0]);
+				$ou = array_pop($ou);
+				$result[$j]['ou']	= strtoupper(substr($ou,0,strlen($ou)-1));
+				
+				if( $pOrg === "*" )
+					$result[$j]['ouAll'] = "*";
+										
+				if( $entry[$i]['jpegphoto'][0] )
+				{
+					$result[$j]['photo'] = "1";
+					$filterPhoto = "(objectclass=*)";
+					$photoLdap = ldap_read($pConn, $entry[$i]['dn'], $filterPhoto, array("jpegPhoto"));
+					$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];
+				}
+				else
+					$result[$j]['photo'] = "0";
+
+				$result[$j++]['cn']	= $entry[$i]['cn'][0];
+			}
+		
+			$organization = $this->attr_org;
+		}
+		
+		return $result;
+	}
+}
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/class.DataBaseIM.inc.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/class.DataBaseIM.inc.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/class.DataBaseIM.inc.php	(revision 2411)
@@ -0,0 +1,721 @@
+<?php
+  /***************************************************************************\
+  *  Expresso - Expresso Messenger                                            *
+  *  	- Alexandre Correia / Rodrigo Souza							          *
+  *  	- JETI - http://jeti-im.org/										  *
+  * ------------------------------------------------------------------------- *
+  *  This program is free software; you can redistribute it and/or modify it  *
+  *  under the terms of the GNU General Public License as published by the    *
+  *  Free Software Foundation; either version 2 of the License, or (at your   *
+  *  option) any later version.                                               *
+  \***************************************************************************/
+
+define('PHPGW_INCLUDE_ROOT','../');	
+define('PHPGW_API_INC','../phpgwapi/inc');
+require_once(PHPGW_API_INC . '/class.db.inc.php');
+//require_once "class.fileDefine.inc.php";
+	
+class DataBaseIM
+{	
+	private $db;
+	private $db_name;
+	private $db_host;
+	private $db_port;
+	private $db_user;
+	private $db_pass;
+	private $db_type;
+	private $user_id;
+	private $fileD;
+	
+	public final function __construct()
+	{
+		//$this->fileD = new fileDefine();
+		$this->db_name = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name'];
+		$this->db_host = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host'];
+		$this->db_port = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_port'];
+		$this->db_user = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_user'];
+		$this->db_pass = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_pass'];
+		$this->db_type = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_type'];
+		$this->user_id = $_SESSION['phpgw_info']['jabberit_messenger']['user_id'];		
+		$this->connectDB();
+	}
+
+	private final function connectDB()
+	{
+		$this->db = new db();
+		$this->db_name = ( !$this->db_name ) ? $_SESSION['phpgwinfo']['db_name'] : $this->db_name;
+		$this->db_host = ( !$this->db_host ) ? $_SESSION['phpgwinfo']['db_host'] : $this->db_host;
+		$this->db_port = ( !$this->db_port ) ? $_SESSION['phpgwinfo']['db_port'] : $this->db_port;
+		$this->db_user = ( !$this->db_user ) ? $_SESSION['phpgwinfo']['db_user'] : $this->db_user;
+		$this->db_pass = ( !$this->db_pass ) ? $_SESSION['phpgwinfo']['db_pass'] : $this->db_pass;
+		$this->db_type = ( !$this->db_type ) ? $_SESSION['phpgwinfo']['db_type'] : $this->db_type;
+		
+		$this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type);		
+	}	
+
+	public final function editHostJabber($pItem)
+	{
+		$hostsJabber = unserialize($this->getHostsJabber());
+		$findHosts	= explode(":", $pItem['item']);
+		$return = "";	
+		
+		for( $i = 0 ; $i < count($hostsJabber); $i++ )
+			if( $hostsJabber[$i]['org'] == $findHosts[0] && $hostsJabber[$i]['jabberName'] == $findHosts[1] )
+			{
+				$return = "org:" . $hostsJabber[$i]['org'] . ";" .
+						  "jabberName:" . $hostsJabber[$i]['jabberName'] . ";" .						  	 
+						  "serverLdap:" . $hostsJabber[$i]['serverLdap'] . ";" .
+						  "contextLdap:" . $hostsJabber[$i]['contextLdap'] . ";" .
+						  "user:" . $hostsJabber[$i]['user'] . ";" .
+						  "password:" . $hostsJabber[$i]['password'] ;						  						  						  						  
+			}
+
+		return trim($return);
+	}
+	
+	public final function getApplicationsEnabled()
+	{
+		
+		$this->db->query("SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'");
+		if($this->db->num_rows())
+		{
+			$tmp = "";
+			while($this->db->next_record())
+			{
+				$tmp[]= $this->db->row();
+			}
+			return $tmp[0]['config_value'];
+		}
+		return false;
+	}
+	
+	public final function getApplicationsList()
+	{
+		$this->db->query("SELECT * FROM phpgw_applications WHERE app_enabled = '1' order by app_name");
+		if($this->db->num_rows())
+		{
+			while ($this->db->next_record())
+			{
+				$app = $this->db->f('app_name');
+				$title = @$GLOBALS['phpgw_info']['apps'][$app]['title'];
+				if (empty($title))
+				{
+					$title = lang($app) == $app.'*' ? $app : lang($app);
+				}
+				$apps[$app] = array(
+					'title'  => $title,
+					'name'   => $app,
+					'status' => $this->db->f('app_enabled')
+				);
+			}
+		}
+		return $apps;
+	}
+
+	public final function get_accounts_acl()
+	{
+		$query  = "SELECT acl_account FROM phpgw_acl WHERE acl_location IN (SELECT CAST(acl_account AS varchar) FROM phpgw_acl WHERE acl_appname = 'jabberit_messenger') ";
+		$query .= "UNION SELECT acl_account FROM phpgw_acl WHERE acl_appname = 'jabberit_messenger'";
+		
+		if( $this->db->query($query) )	
+		{
+			$users = array();
+			$new_users = array();
+			while($this->db->next_record())
+				$users[] = $this->db->row();
+
+			if(is_array($users))
+				foreach($users as $tmp)
+					$new_users[] = $tmp['acl_account'];
+			
+			return $new_users;
+		}
+		
+		return false;
+	}
+	
+	public final function getGroupsBlocked()
+	{
+		$return = "";
+		
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";	
+			
+			if($this->db->query($query))
+			{
+
+				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 getGroupsSearch()
+	{
+		$return = "";
+	
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_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 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()
+	{
+		$result = array();
+		$query = "SELECT * FROM phpgw_preferences WHERE preference_owner = '".$this->user_id."' AND preference_app = 'jabberit_messenger'";
+		
+ 		if ( $this->db->query($query) )
+		{	
+			while($this->db->next_record())
+				$result[] = $this->db->row();
+	
+			if( count($result) > 0 )
+			{
+				$_return = unserialize($result[0]['preference_value']);
+				
+				if( is_array($_return) )
+					return $_return['preferences'];
+				else
+					return $_return;
+			}
+		}
+
+		return "openWindowJabberit:true;openWindowJabberitPopUp:false;flagAwayIM:5";
+	}
+
+	public final function setApplications($pApplications)
+	{
+		$apps = serialize($pApplications);
+		
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'";
+				
+			$this->db->query($query);
+					
+			if(!$this->db->next_record())
+			{
+				$query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')";
+				$this->db->query($query);
+				return true;
+			}
+			else
+			{
+				$query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'";
+				$this->db->query($query);
+				return true;
+			}
+		}
+		return false;	
+	}
+	
+	public final function setAttributesLdap($pAttributes)
+	{
+		$values = $pAttributes['conf'];
+		$attributesOrg = "";		
+
+		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'];
+			}
+
+			if( trim($attributesOrg) == "" )
+			{
+				$query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','attributes_org_ldap_jabberit','".$values."')";
+				$this->db->query($query);
+				
+				$attr = explode(";", $values);
+				$values = "<return><ou attr='".$attr[1]."'>".$attr[0]."</ou></return>";
+				return $values;
+			}
+			else
+			{
+				$org = explode(",", $attributesOrg);
+				$newValue = explode(";", $values);
+				
+				foreach( $org as $tmp )
+				{
+					$attr = explode(";",$tmp);
+					if( strtolower(trim($attr[0])) == strtolower(trim($newValue[0])) )
+						return false;
+				}
+
+				$values = $values . "," . $attributesOrg;
+				$query = "UPDATE phpgw_config SET config_value = '".$values."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'";
+				$this->db->query($query);
+
+				$return = explode(",",$values);
+				natcasesort($return);
+
+				$values = "<return>";
+				
+				foreach($return as $tmp)
+				{
+					$attr = explode(";", $tmp);
+					$values .= "<ou attr='" . $attr[1] . "'>" . $attr[0] . "</ou>";
+				}
+					
+				$values .= "</return>";
+				
+				return $values;				
+			}
+		}
+		return false; 
+	}
+
+	public final function setAddGroupsSearch($pData)
+	{
+		if( $pData)
+		{
+			if( $this->db )
+			{
+				$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND  config_name = 'groups_search_jabberit';";
+				
+				if( $this->db->query($query) )
+				{
+					while( $this->db->next_record())
+						$result[] = $this->db->row();				
+				}
+				
+				if( count($result) == 0 )
+				{
+					$query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_search_jabberit','".serialize($pData)."');";
+					$this->db->query($query);
+					return true;
+				}
+				else
+				{
+					$keyLdap = array_keys($pData);
+					$resultQuery = unserialize($result[0]['config_value']);					
+					
+					if( is_array(unserialize($pData[$keyLdap[0]])) )
+						$resultQuery[$keyLdap[0]] = $pData[$keyLdap[0]];
+					else
+						unset($resultQuery[$keyLdap[0]]);
+
+					if( count($resultQuery))
+						$query = "UPDATE phpgw_config SET config_value = '".serialize($resultQuery)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';";
+					else
+						$query = "DELETE FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';";
+						
+					$this->db->query($query);
+					return true;
+				}
+			}			
+		}
+	}
+
+	public final function setGroupsLocked($pGroups)
+	{
+		$groups = "";
+		
+		if( is_array($pGroups) )
+		{
+			foreach($pGroups as $tmp)		
+				if(trim($tmp) != "")
+					$groups .= $tmp . ";";
+		
+			$groups = substr($groups, 0, strlen($groups) - 1 );		
+		}
+		
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";	
+			
+			if($this->db->query($query))
+			{
+
+				if ( $this->db->query($query) )
+				{	
+					while($this->db->next_record())
+						$result[] = $this->db->row();
+				}
+
+				if( count($result) == 0 )
+				{
+					$query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_locked_jabberit','".$groups."');";
+					$this->db->query($query);
+					return true;
+				}
+				else
+				{
+					$query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
+					$this->db->query($query);
+					return true;
+				}
+			}
+		}
+		
+		return false;
+	}
+	
+	public final function setHostJabber($pParam)
+	{
+		$confHostsJabber =  array();
+
+		foreach($pParam as $key => $itens)
+			$confHostsJabber[$key] = ( $key === 'org' ) ? strtoupper($itens) : $itens;
+
+		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 = "<return><confServer ou='".strtoupper($confHostsJabber['org'])."' serverName='".$confHostsJabber['jabberName']."'>".strtoupper($confHostsJabber['org']).":".$confHostsJabber['jabberName']."</confServer></return>";				
+				$hostsJabber[0] = $confHostsJabber;
+				
+				$this->fileD->ldapExternal($hostsJabber);
+				 
+				$query = "INSERT INTO phpgw_config(config_app, config_name, config_value) VALUES('phpgwapi','map_org_realm_jabberit','".serialize($hostsJabber)."')";
+				$this->db->query($query);				
+			}
+			else
+			{
+				$resultQuery = unserialize($result[0]['config_value']);	
+				$foundOrg = false;
+				
+				foreach($resultQuery as $key => $itens)
+				{
+					$foundString = array_search($confHostsJabber['org'], $itens);
+					if( $foundString )
+					{
+						$foundOrg = $foundString;
+						$ky = $key;
+					}
+				}	
+
+				if( ! $foundOrg )
+					$resultQuery[] = $confHostsJabber;	
+				else
+					$resultQuery[$ky] = $confHostsJabber;
+
+				$return = "<return>";
+				
+				foreach( $resultQuery as $itens )
+					$return .= "<confServer ou='".$itens['org']."' serverName='".$itens['jabberName']."'>".$itens['org'].":".$itens['jabberName']."</confServer>";
+				
+				$return .= "</return>";
+				
+				$this->fileD->ldapExternal($resultQuery);
+				
+				$query = "UPDATE phpgw_config SET config_value = '".serialize($resultQuery)."' WHERE config_name = 'map_org_realm_jabberit';";
+				$this->db->query($query);
+			}
+			return $return;
+		}	
+		return false;
+	}
+	
+	public final function setOuGroupsLocked($pGroup)
+	{
+		
+		function strallpos($haystack, $needle, $offset = 0)
+		{
+		    $result = array();
+		    for($i = $offset; $i< strlen($haystack); $i++ )
+		    {
+		        $pos = strpos($haystack,$needle,$i);
+		        if($pos !== FALSE)
+		        {
+		            $offset =  $pos;
+		            if($offset >= $i)
+		                $result[] = $i = $offset;
+		        }
+		    }
+	    	
+	    	return $result;
+		} 
+
+		$group = $pGroup['group'];
+		$gidnumber = $pGroup['gidnumber'];
+		$organization = strtoupper(trim($pGroup['ou']));
+
+		$posAll = strallpos($organization, "OU=" );
+		$orgs = array();
+
+		for( $i = 0 ; $i < count($posAll); $i++ )
+		{
+			$pos = strpos($organization, ",");
+			$tmpString = substr($organization, $posAll[$i] + 3);
+			$orgs[] = substr($tmpString, 0, strpos($tmpString, ","));
+		}
+
+		$organization = implode("/", array_reverse($orgs));
+
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";	
+			
+			if($this->db->query($query))
+			{
+
+				if ( $this->db->query($query) )
+				{	
+					while($this->db->next_record())
+						$result[] = $this->db->row();
+				}
+
+				$groupsLocked = explode(";",$result[0]['config_value']);
+					
+				foreach( $groupsLocked as $tmp )
+				{
+					$aux = explode(":", $tmp);
+					if(($group.":".$gidnumber) == ($aux[0].":".$aux[1]))
+					{
+						if( $aux[2] )
+						{
+							$ou_groups = explode(",",$aux[2]);
+							natcasesort($ou_groups);
+							$key = array_search($organization, $ou_groups);
+							
+							if( $key === false )
+								array_push($ou_groups, $organization);
+							
+							$groups .= $group.":".$gidnumber.":";
+							
+							$return = "<return>";						
+							
+							foreach($ou_groups as $tmp)
+							{
+								$return .= "<ou attr='".$tmp."'>".$tmp."</ou>";
+								$groups .= $tmp .",";	
+							}
+							
+							$return .= "</return>";
+							
+							$groups  = substr($groups,0,strlen($groups)-1);
+							$groups .= ";";
+						}
+						else
+						{
+							$groups .= $group.":".$gidnumber.":".$organization.";";
+							$return = "<return><ou attr='".$organization."'>".$organization."</ou></return>";
+						}
+					}
+					else
+						$groups .= $tmp . ";" ;
+				}
+
+				$groups = substr($groups,0,strlen($groups)-1);
+
+				$query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
+				$this->db->query($query);
+				
+				return $return;
+			}
+		}
+		
+		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']);
+					$hosts = explode(":", $pItem['item']);
+					$key = "";
+
+					if( count($confHostsOrgs) > 0 )
+					{
+						for( $i = 0; $i < count($confHostsOrgs); $i++)
+							if( $confHostsOrgs[$i]['org'] == $hosts[0] && $confHostsOrgs[$i]['jabberName'] == $hosts[1])
+								$key = $i;	
+
+						array_splice($confHostsOrgs, $key, 1);
+				
+						if(count($confHostsOrgs) > 0)
+						{					
+							$this->fileD->ldapExternal($confHostsOrgs);
+							$query = "UPDATE phpgw_config SET config_value = '".serialize($confHostsOrgs)."' WHERE config_name = 'map_org_realm_jabberit';";
+						}
+						else
+						{
+							$this->fileD->ldapExternal("");
+							$query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';";
+						}
+					}
+					else
+					{	
+						$this->fileD->ldapExternal("");						
+						$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)
+	{
+		$group = $pGroup['group'];
+		$gidnumber = $pGroup['gidnumber'];
+		$organization = strtoupper($pGroup['ou']);
+		$return = false;
+		
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";	
+			
+			if($this->db->query($query))
+			{
+
+				if ( $this->db->query($query) )
+				{	
+					while($this->db->next_record())
+						$result[] = $this->db->row();
+				}
+
+				$groupsLocked = explode(";",$result[0]['config_value']);
+				
+				foreach( $groupsLocked as $tmp )
+				{
+					$aux = explode(":",$tmp);
+					
+					if(($group.":".$gidnumber) == ($aux[0].":".$aux[1]))
+					{
+						$ous = explode(",", $aux[2]);
+						$key = array_search($organization, $ous);
+
+						if( $key !== false )
+							unset($ous[$key]);
+
+						$groups .= $group.":".$gidnumber.":";
+						
+						foreach($ous as $ouTmp)
+							$groups .= $ouTmp .",";	
+						
+						$groups  = substr($groups,0,strlen($groups)-1);
+						$groups .= ";";
+					}
+					else
+						$groups .= $tmp . ";" ;									
+				}
+					
+				$groups  = substr($groups,0,strlen($groups)-1);
+			
+				$query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
+
+				if( $this->db->query($query))
+					$return = true;
+			}
+		}	
+		
+		return $return;
+	}
+
+}
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/Controller.class.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/Controller.class.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/Controller.class.php	(revision 2411)
@@ -0,0 +1,204 @@
+<?php
+  /***************************************************************************\
+  *  Expresso - Expresso Messenger                                            *
+  *  	- Alexandre Correia / Rodrigo Souza							          *
+  * ------------------------------------------------------------------------- *
+  *  This program is free software; you can redistribute it and/or modify it  *
+  *  under the terms of the GNU General Public License as published by the    *
+  *  Free Software Foundation; either version 2 of the License, or (at your   *
+  *  option) any later version.                                               *
+  \***************************************************************************/
+
+class Controller
+{
+	const __CONTROLLER_SECURITY__				= 'controller-security';
+	const __CONTROLLER_CONTENTES__				= 'controller-contentes';
+	const __CONTROLLER_SECTIONS__				= 'controller-sections';
+
+	const __STRING_ACCESS__						= 'string-access';
+	const __STRING_DELIMITER__					= 'string-delimiter';
+
+	const __CONTROLLER_CONTENTES_ITEM__			= 'item';
+	const __CONTROLLER_CONTENTES_ITEM_PARAM__	= 'param';
+	const __CONTROLLER_CONTENTES_ITEM_SECTION__	= 'section';
+
+	const __CONTROLLER_SECTIONS_ITEM__			= 'item';
+
+	private $fatalError							= false;
+	private $_PATH								= "";
+
+	public function __construct()
+	{
+		try
+		{
+			$controler_xml = dirname(__FILE__) . '/controller.xml';
+			
+			if ( !file_exists($controler_xml) )
+				throw new Exception(__CLASS__ . ' [ ERROR ] :: the configuration file does not exist');
+
+			$this->dom = new DOMDocument;
+			$this->dom->preserveWhiteSpace = FALSE;
+			$this->dom->load($controler_xml);
+
+			unset($controler_xml);
+
+			$this->controller_security = $this->dom->getElementsByTagName(self::__CONTROLLER_SECURITY__);
+			if ( $this->controller_security->length === (int)0 )
+				throw new Exception(__CLASS__ . ' [ ERROR #0 ] :: the tag "' . self::__CONTROLLER_SECURITY__ . '" does not exist');
+			if ( $this->controller_security->length !== (int)1 )
+				throw new Exception(__CLASS__ . ' [ ERROR #1 ] :: exists more of a tag "' . self::__CONTROLLER_SECURITY__ . '"');
+
+			$this->controller_contentes = $this->dom->getElementsByTagName(self::__CONTROLLER_CONTENTES__);
+			if ( $this->controller_contentes->length === (int)0 )
+				throw new Exception(__CLASS__ . ' [ ERROR #2 ] :: the tag "' . self::__CONTROLLER_CONTENTES__ . '" does not exist');
+			if ( $this->controller_contentes->length !== (int)1 )
+				throw new Exception(__CLASS__ . ' [ ERROR #3 ] :: exists more of a tag "' . self::__CONTROLLER_CONTENTES__ . '"');
+			$this->controller_contentes = $this->controller_contentes->item(0);
+
+			$this->controller_sections = $this->dom->getElementsByTagName("controller-sections");
+			if ( $this->controller_sections->length === (int)0 )
+				throw new Exception(__CLASS__ . ' [ ERROR #4 ] :: the tag "' . self::__CONTROLLER_SECTIONS__ . '" does not exist');
+			if ( $this->controller_sections->length !== (int)1 )
+				throw new Exception(__CLASS__ . ' [ ERROR #5 ] :: exists more of a tag "' . self::__CONTROLLER_SECTIONS__ . '"');
+			$this->controller_sections = $this->controller_sections->item(0);
+
+			$this->string_access = $this->controller_security->item(0)->getElementsByTagName(self::__STRING_ACCESS__);
+			if ( $this->string_access->length === (int)0 )
+				throw new Exception(__CLASS__ . ' [ ERROR #6 ] :: the tag "' . self::__STRING_ACCESS__ . '" does not exist');
+			if ( $this->string_access->length !== (int)1 )
+				throw new Exception(__CLASS__ . ' [ ERROR #7 ] :: exists more of a tag "' . self::__STRING_ACCESS__ . '"');
+			$this->string_access = $this->string_access->item(0)->nodeValue;
+
+			$this->string_delimiter = $this->controller_security->item(0)->getElementsByTagName(self::__STRING_DELIMITER__);
+			( $this->string_delimiter->length === (int)0 )
+				and die(__CLASS__ . ' [ ERROR #8 ] :: the tag "' . self::__STRING_DELIMITER__ . '" does not exist');
+			if ( $this->string_delimiter->length !== (int)1 )
+				throw new Exception(__CLASS__ . ' [ ERROR #9 ] :: exists more of a tag "' . self::__STRING_DELIMITER__ . '"');
+			$this->string_delimiter = $this->string_delimiter->item(0)->nodeValue;
+		}
+		catch(Exception $e)
+		{
+			$this->fatalError = true;
+			return $e->getMessage();
+		}
+	}
+
+	public function __call($name, $arguments)
+	{
+		if ( !$this->fatalError )
+			switch ( $name )
+			{
+				case 'exec' :
+					return $this->_exec($arguments[0], $arguments[1]);
+				break;
+				default : return "Method not avaible";
+			}
+	}
+
+	public function __toString()
+	{
+		return __CLASS__;
+	}
+
+	private final function _exec(array &$pRequest, $pPath)
+	{
+		( $pRequest[$this->string_access] )
+			or die(__CLASS__ . ' [ ERROR #10 ] :: bad string action argument');
+
+		list($section_name, $ref, $alias) = explode($this->string_delimiter, $pRequest[$this->string_access]);
+		unset($pRequest[$this->string_access]);
+
+		$contents_itens = $this->controller_contentes->getElementsByTagName(self::__CONTROLLER_CONTENTES_ITEM__);
+
+		for ( $i = 0; $i < $contents_itens->length && $contents_itens->item($i)->getAttribute(self::__CONTROLLER_CONTENTES_ITEM_PARAM__) != $section_name; $i++ );
+		( !($i < $contents_itens->length) )
+			and die(__CLASS__ . ' [ ERROR #11 ] :: invalid section "' . $section_name . '"');
+
+		$section_name = $contents_itens->item($i)->getAttribute(self::__CONTROLLER_CONTENTES_ITEM_SECTION__);
+
+		$section = $this->controller_sections->getElementsByTagName($section_name);
+		( $section->length === (int)0 )
+			and die(__CLASS__ . ' [ ERROR #12 ] :: the tag "' . $section_name . '" does not exist');
+		( $section->length === (int)1 )
+			or die(__CLASS__ . ' [ ERROR #13 ] :: exists more of a tag "' . $section_name . '"');
+		$section = $section->item(0);
+
+		$section_itens = $section->getElementsByTagName(self::__CONTROLLER_SECTIONS_ITEM__);
+
+		if ( empty($alias) && $alias !== '0' )
+			for ( $i = 0; $i < $section_itens->length && $section_itens->item($i)->getAttribute('ref') != $ref; $i++ );
+		else
+			for ( $i = 0; $i < $section_itens->length && ( $section_itens->item($i)->getAttribute('ref') != $ref || $section_itens->item($i)->getAttribute('alias') !== $alias); $i++ );
+
+		( !($i < $section_itens->length) )
+			and die(__CLASS__ . ' [ ERROR #14 ] :: invalid reference "' . $ref . '"');
+
+		if( $section_itens->item($i)->getAttribute('path') )
+			$path = $section_itens->item($i)->getAttribute('path');
+		else if	( $section->getAttribute('path') )
+			$path = $pPath . $section->getAttribute('path');
+			
+		if( !$path ) die(__CLASS__ . ' [ ERROR #15 ] :: bad path argument');
+
+		$prefix = $section_itens->item($i)->getAttribute('prefix')
+			or $prefix = $section->getAttribute('prefix');
+
+		$suffix = $section_itens->item($i)->getAttribute('suffix')
+			or $suffix = $section->getAttribute('suffix')
+			or die(__CLASS__ . ' [ ERROR #16 ] :: bad suffix argument');
+
+		return $this->$section_name(array("pSectionItem" => $section_itens->item($i), "pPath" => $path, "pPrefix" => $prefix, "pSuffix" => $suffix, "pRequest" => $pRequest));
+	}
+
+	private final function php()
+	{
+		$params = func_get_args();
+		extract($params[0]);
+
+		$class = $pSectionItem->getAttribute('class')
+			and $method = $pSectionItem->getAttribute('method')
+			or die(__CLASS__ . ' [ ERROR #17 ] :: bad class or method argument');
+
+		$file = "{$pPath}/{$pPrefix}{$class}{$pSuffix}";
+
+		file_exists($file)
+			or die(__CLASS__ . ' [ ERROR #18 ] :: the file that has the class was not opened');
+
+		require_once $file;
+
+		$obj = new ReflectionClass($class);
+
+		if ( $pRequest['classConstructor'] )
+		{
+			$obj = $obj->newInstance($pRequest['classConstructor']);
+			unset($pRequest['classConstructor']);
+		}
+		else
+			$obj = $obj->newInstance();
+
+		$method = new ReflectionMethod($class, $method);
+		$result = $method->invoke($obj, $pRequest);
+
+		return $result;
+	}
+
+	private final function js()
+	{
+		$params = func_get_args();
+		extract($params[0]);
+
+		$js = $pSectionItem->getAttribute('js')
+			or die(__CLASS__ . ' [ ERROR #18 ] :: bad js argument');
+
+		$file = "{$pPath}/{$pPrefix}{$js}{$pSuffix}";
+
+		file_exists($file)
+			or die(__CLASS__ . ' [ ERROR #19 ] :: the file that has the class was not opened');
+
+		$debug = $pSectionItem->parentNode->getAttribute('debug');
+		
+		return file_get_contents($file);
+	}
+}
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/teste.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/teste.php	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/teste.php	(revision 2411)
@@ -0,0 +1,39 @@
+<?php
+
+//COM PARAMETRO
+// act=$this.contacts_im.list_contacts&name=alexandre
+
+//SEM PARAMETRO
+//act=$this.preferences.getPreferences
+//act=$this.teste.aqui_dentro
+
+$request_method = '_' . $_SERVER['REQUEST_METHOD'];
+
+switch ( $request_method )
+{
+	case '_GET' :
+		$params = $_GET;
+	break;
+	case '_POST' :
+		$params = $_POST;
+	break;
+	case '_HEAD' :
+	case '_PUT' :
+	default :
+		echo "controller - request method not avaible";
+		return false;
+}
+
+if( file_exists(dirname(__FILE__) . "/inc/Controller.class.php") )
+{
+	require_once dirname(__FILE__) . '/inc/Controller.class.php';
+	
+	$controller = new Controller();
+	
+	printf("%s", $controller->exec($$request_method, dirname(__FILE__)));
+	
+	exit(0);
+
+}
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js	(revision 2397)
+++ sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js	(revision 2411)
@@ -4,4 +4,5 @@
 	var path			= "";
 	var addUser			= null;
+	var conn			= null
 	var showhidden 		= null;
 	var Xtools			= null;
@@ -43,10 +44,4 @@
 	function addContacts()
 	{
-		if( addUser == null )
-		{	
-			setXTools();
-			addUser = new addUserIM(Xtools);
-		}
-		
 		addUser.show();
 	}
@@ -147,5 +142,5 @@
 
 			var _options = [
-			                	['Adicionar Contato', 'alert("1")' ],
+			                	['Adicionar Contato', 'loadIM.addContacts();' ],
 			                	['Ajuda', 'alert("2")' ],
 			                	['Preferências', 'alert("3")'],
@@ -229,8 +224,22 @@
 	}
 	
+	function keyPressSearch()
+	{
+		if( arguments.length > 0 )
+		{
+			var ev 		= arguments[0];
+			var element	= arguments[1];
+	
+			if ( ev.keyCode == 13 )
+				if( element.value.length >= 4 )
+					searchUser( element.value );	
+				else
+					alert('Your search argument must be longer than 4 characters.');
+		}
+	}
+
+	
 	function loginPage()
 	{
-		setXTools();
-		
 		var winLoginPage =
 		{	
@@ -338,6 +347,4 @@
 	function rosterDiv()
 	{
-		setXTools();			
-
 		var paramListContact = 
 		{
@@ -365,4 +372,9 @@
 	}
 
+	function searchUser()
+	{
+		addUser.search();
+	}
+	
 	function setPresence()
 	{
@@ -425,11 +437,5 @@
 		}
 	}
-	
-	function setXTools()
-	{
-		if( Xtools == null )
-			Xtools = new xtools(path_jabberit);
-	}
-	
+
 	function loadIM()
 	{
@@ -437,4 +443,5 @@
 		{
 			var files = [
+			             		path_jabberit + 'js/connector.js',
 			            	 	path_jabberit + 'js/xtools.js',
 			            	 	path_jabberit +	'js/dragdrop.js',
@@ -446,14 +453,30 @@
 			            	 	path_jabberit + 'templates/default/css/' + theme_jabberit
 			            ];
-			
+			// FullName
 			fullName = arguments[0];
 			
 			loadScripts(files);
-			
-			// Add Jabber in StatusBar;
-			addIcon();
 			
 			// User & Password Jabber;
 			setUserCurrent( arguments[1], arguments[2]);
+			
+			setTimeout(function()
+			{
+				// Object Xtools	
+				if( Xtools == null )
+					Xtools = new xtools(path_jabberit);
+				
+				// Object Conector
+				if( conn == null )
+					conn = new AjaxConnector(path_jabberit);
+				
+				// Object Add User
+				if( addUser == null )
+					addUser = new addUserIM(Xtools, conn);
+
+				// Add Jabber in StatusBar;
+				addIcon();
+				
+			}, 1000);
 		}
 	}
@@ -466,7 +489,9 @@
 	loadIM.prototype.groupsHidden		= groupsHidden;
 	loadIM.prototype.groupsVisible		= groupsVisible;
+	loadIM.prototype.keyPressSearch		= keyPressSearch;	
 	loadIM.prototype.loginPage			= loginPage;
 	loadIM.prototype.parse				= parse;
 	loadIM.prototype.setPresence		= setPresence;
+	loadIM.prototype.searchUser			= searchUser
 	loadIM.prototype.setStatusJabber	= setStatusJabber;
 	loadIM.prototype.rosterDiv			= rosterDiv;
Index: sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js	(revision 2397)
+++ sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js	(revision 2411)
@@ -1,5 +1,6 @@
 (function()
 {
-		var Xtools = null;
+		var Xtools	= null;
+		var conn	= null;	
 	
 		function addContacts()
@@ -16,14 +17,60 @@
 		}
 		
+		function search()
+		{
+			var _input	= document.getElementById('search_user_jabber');
+			var _span	= document.getElementById('span_searching_im');
+			var _div	= document.getElementById('list_users_ldap_im');
+
+			_span.style.display = "block";
+			
+			conn.go('p.cc.getListContacts',
+					function(data)
+					{	
+						var _paramsVar =
+						{
+							'lang_addContact'	: 'Adicionar Contatos',
+							'lang_empty' 		: 'None result was found.',
+							'lang_many_results' : 'Many results. Please, try to refine your search.'
+						};	
+						
+						_div.innerHTML = Xtools.parse( data, 'listLdapContacts.xsl', _paramsVar );
+
+						var _member = _div.firstChild;
+						
+						while ( _member )
+						{
+							if( _member.getAttribute('photo') === '1' )
+							{
+								var jid		= _member.getAttribute('jid'); 
+								var ou	 	= _member.getAttribute('ou');
+
+								var _img_path  = path_jabberit + 'inc/webservice.php?' + Date.parse( new Date );
+									_img_path += '&phpPhoto=' + jid + '&phpOu=' + ou;
+
+								_member.style.backgroundImage = 'url(' + _img_path + ')';
+							}
+							
+							//_config(_member, 'onclick', _show);
+							
+							_member = _member.nextSibling;
+						}
+
+						_input.focus();
+						_input.value	 	= "";
+						_span.style.display = "none";
+						
+					});
+		}
+		
 		function showForm()
 		{
 			var _paramsWindAddUser =
 			{
-					'lang1'	: 'Nome do Contato',
-					'lang2'	: 'Search',
-					'lang3'	: 'Resulado da Busca',
-					'lang4'	: 'Nickname',
-					'lang5'	: 'group',
-					'path'	: path_jabberit	
+					'lang_group'		: 'Grupo',
+					'lang_load'			: 'Carregando',
+					'lang_name_contact'	: 'Nome do Contato',
+					'lang_result'		: 'Resultado da Busca',
+					'path'				: path_jabberit	
 			};
 
@@ -51,11 +98,13 @@
 			if( arguments.length > 0 )
 			{
-				Xtools = arguments[0];
+				Xtools	= arguments[0];
+				conn	= arguments[1];				 
 			}	
 		}
 
 		loadAddUser.prototype.add		= addContacts;
+		loadAddUser.prototype.search	= search;
 		loadAddUser.prototype.show		= showForm;
-		
+				
 		window.addUserIM	= loadAddUser;
 })();
Index: sandbox/jabberit_messenger/trophy_expresso/js/connector.js
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/js/connector.js	(revision 2411)
+++ sandbox/jabberit_messenger/trophy_expresso/js/connector.js	(revision 2411)
@@ -0,0 +1,298 @@
+(function()
+{
+	var _THREADS = [];
+	var _ie;
+
+	function _config(pObj, pEvent, pHandler)
+	{
+		if ( typeof pObj == 'object' )
+		{
+			if ( pEvent.substring(0, 2) == 'on' )
+				pEvent = pEvent.substring(2, pEvent.length);
+
+			if ( pObj.addEventListener )
+				pObj.addEventListener(pEvent, pHandler, false);
+			else if ( pObj.attachEvent )
+				pObj.attachEvent('on' + pEvent, pHandler);
+		}
+	}
+
+	/**
+	 * xhr = XMLHttpRequest
+	 */
+	
+	function _xhr()
+	{
+		try
+		{
+			return new XMLHttpRequest();
+		}
+		catch (_e)
+		{
+			_ie = true;
+			try
+			{
+				return new ActiveXObject('Msxml2.XMLHTTP');
+			}
+			catch (_e1)
+			{
+				try
+				{
+					return new ActiveXObject('Microsoft.XMLHTTP');
+				}
+				catch (_e2)
+				{
+					return false;
+				}
+			}
+		}
+	}
+
+	function _HANDLER()
+	{
+		var _ID = arguments[0];
+
+		if  ( _THREADS[_ID] )
+		{
+			if ( _ie && _THREADS[_ID]._XHR.readyState != 4 )
+				return false;
+
+			switch ( _THREADS[_ID]._XHR.readyState )
+			{
+				case 3 :
+					if ( _THREADS[_ID]._HANDLER.stream )
+					{
+						var _data = _THREADS[_ID]._XHR.responseText.substr(_THREADS[_ID]._index).replace(/^ +| +$/g, '');
+						
+						_THREADS[_ID]._rtlen = _THREADS[_ID]._XHR.responseText.length;
+
+						if ( _THREADS[_ID]._index < _THREADS[_ID]._rtlen && _data.length )
+						{
+							try
+							{
+								_THREADS[_ID]._HANDLER.stream(_data);
+							}
+							catch(_e)
+							{
+								//alert("#stream\n\n" + _e + "\n\n" + _e.description);
+							}
+						}
+						
+						if ( _THREADS[_ID] )
+						{
+							_THREADS[_ID]._index = _THREADS[_ID]._rtlen;
+						}
+					}
+				break;
+				case 4 :
+					try
+					{
+						switch ( _THREADS[_ID]._XHR.status )
+						{
+							case 200:
+								var _data = ( _THREADS[_ID]._MODE == 'XML' ) ?
+									_THREADS[_ID]._XHR.responseXML :
+									_THREADS[_ID]._XHR.responseText;
+
+								if ( _ie && _THREADS[_ID]._HANDLER.stream )
+									_THREADS[_ID]._HANDLER.stream(_data);
+
+								var _request = ( _THREADS[_ID]._HANDLER.request ) ?
+									_THREADS[_ID]._HANDLER.request : false;
+
+								delete _THREADS[_ID];
+
+								if ( _request )
+									try
+									{
+										_request(_data);
+									}
+									catch(_e)
+									{
+										//alert("#request\n\n" + _e + "\n\n" + _e.description);
+									}
+
+							break; // [case : status 200]
+							case 404:
+								delete _THREADS[_ID];
+								alert('Page Not Found!');
+							break; // [case : status 404]
+							default:
+								delete _THREADS[_ID];
+						}
+					}
+					catch(e)
+					{
+					}
+				break;
+				default :
+			}
+		}
+	}
+
+	function _execute()
+	{
+		var _ID = arguments[0];
+		var _ACTION = 'act=' + _ID;
+		var _TARGET = this._PATH;
+		var _SEND = null;
+
+		if ( _TARGET != '' && _TARGET.lastIndexOf('/') != (_TARGET.length - 1) )
+			_TARGET += '/';
+
+		_TARGET += ( this._CONTROLLER ) ?
+			this._CONTROLLER  : 'controller.php';
+
+		if ( _THREADS[_ID]._METHOD == 'GET' )
+			_TARGET += '?' + _ACTION;
+
+		_THREADS[_ID]._XHR.open(_THREADS[_ID]._METHOD, _TARGET, true);
+
+		if ( _THREADS[_ID]._METHOD == 'POST' )
+		{
+			_THREADS[_ID]._XHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
+			_THREADS[_ID]._XHR.setRequestHeader('Cache-Control',  'no-store, no-cache, must-revalidate');
+			_THREADS[_ID]._XHR.setRequestHeader('Cache-Control', 'post-check=0, pre-check=0');
+			_THREADS[_ID]._XHR.setRequestHeader('Pragma', 'no-cache');
+			_SEND = _ACTION + '&' + arguments[1];
+		}
+
+		_THREADS[_ID]._XHR.onreadystatechange = function(){_HANDLER(_ID);};
+		_THREADS[_ID]._XHR.send(_SEND);
+	}
+
+	function usage()
+	{
+		return ""+
+			"Description:\n"+
+			"\t<obj>.go(string access, [mixed handler[, mixed post]])\n\n"+
+			"Parameters:\n"+
+			"\taccess : assinatura de acesso Ã  camada de controle.\n"+
+			"\thandler : uma funÃ§Ã£o a ser executada no fim da requisiÃ§Ã£o\n"+
+			"\t\tou um objeto que poderÃ¡ conter dois Ã­ndices sendo\n"+
+			"\t\tque ambos deverÃ£o ser uma funÃ§Ã£o que serÃ¡ executada\n"+
+			"\t\tconforme o status do objeto xhr, sendo que na posiÃ§Ã£o\n"+
+			"\t\t'stream' serÃ¡ a funÃ§Ã£o a ser executada a cada iteraÃ§Ã£o\n"+
+			"\t\tdo objeto xhr e na posiÃ§Ã£o 'request' serÃ¡ a funÃ§Ã£o\n"+
+			"\t\ta ser executada no fim da requisiÃ§Ã£o.\n"+
+			"\tpost : se especificado deverÃ¡ ser uma query string ou um\n"+
+			"\tXML bem formatado.\n\n";
+	}
+
+	// @PARAM arguments[0] string :
+	//		assinatura de acesso a camada de controle
+	//
+	// @PARAM arguments[1] object :
+	//		OBS : neste caso a conexão assumirá que se trata de uma stream
+	//		objeto contendo dois duas funções, sendo,
+	//		no índice stream deverá conter uma função que será executada
+	//		a cada mudança de status do objeto xhr
+	//	
+	// @PARAM arguments[1] function : função a ser executada no retorno da requisição
+	//		OBS : neste caso a conexão assumirá que se trata de uma
+	//		requisição função que será executada no final da requisição
+	//
+	// @PARAM arguments[2] string :
+	//		este parâmetro define se a conexão é via GET ou POST
+	//		caso o parâmetro não esteja presente a conexão será executada
+	//		via GET, por outro lado, caso ele exista deverá ser uma query
+	//		string válida ou um xml bem formatado
+	//
+	function go()
+	{
+		var _argv = arguments;
+		var _argc = _argv.length;
+		var _ID = _argv[0];
+		var _POST;
+		if ( _argc < 1 || _argc > 3 )
+			return {'error' : "#0\n\n" + usage()};
+
+		if ( typeof _ID != 'string' )
+			return {'error' : "#1\n\n" + usage()};
+
+		_THREADS[_ID] = {
+			'_HANDLER'	: {},
+			'_METHOD'	: ( _argv[2] ) ? 'POST' : 'GET',  // [GET | POST]
+			'_MODE'		: null,	// [XML | TEXT]
+			'_TYPE'		: null,	// [4 for request | 3 for stream]
+			'_XHR'		: null	// [4 for request | 3 for stream]
+		};
+
+		if ( _argv[2] )
+			_POST = _argv[2];
+
+		if ( _argv[1] )
+			switch ( typeof _argv[1] )
+			{
+				case 'function' :
+					_THREADS[_ID]._HANDLER = {'request' : _argv[1]};
+				break;
+				case 'object' :
+					for ( var i in _argv[1] )
+						if ( i != 'stream' && i != 'request' )
+						{
+							delete _THREADS[_ID];
+							return {'error' : "#3\n\n" + usage()};
+						}
+						else if ( i == 'stream' )
+						{
+							_THREADS[_ID]._index = 0;
+							_THREADS[_ID]._rtlen = 0;
+						}
+						_THREADS[_ID]._HANDLER = _argv[1];
+				break;
+				case 'string' :
+					if ( _argc == 2 )
+					{
+						_THREADS[_ID]._METHOD = 'POST';
+						_POST = _argv[1];
+					}
+				break;
+				default :
+					//delete _THREADS[_ID];
+					//return {'error' : "#4\n\n" + usage()};
+			}
+
+		if ( !(_THREADS[_ID]._XHR = _xhr()) )
+			return {'error' : "#4 it cannot make a xhr object"};
+
+		( _THREADS[_ID]._METHOD == 'GET' ) ?
+			_execute.call(this, _ID) : _execute.call(this, _ID, _POST);
+		return {'success' : "your thread is running and the response "+
+							"will be manipulated by the handler"};
+	}
+
+	function abort()
+	{
+		for ( var _ID in _THREADS )
+		{
+			// @TODO
+			// try/catch for unknown error of IE.
+			// Check, store and retrieve the try/catch.
+			try
+			{
+				if ( _THREADS[_ID] && _THREADS[_ID]._XHR && _THREADS[_ID]._XHR.abort )
+					_THREADS[_ID]._XHR.abort();
+
+				delete _THREADS[_ID];
+			}
+			catch(e){}
+		}
+	}
+
+	function Connector()
+	{
+		var _argv = arguments;
+		this._PATH = ( _argv.length > 0 ) ?
+			_argv[0] : '';
+		this._CONTROLLER = ( _argv.length == 2 ) ?
+			_argv[1] : false;
+	}
+
+	Connector.prototype.go		= go;
+	Connector.prototype.abort	= abort;
+	window.AjaxConnector		= Connector;
+
+	_config( window, 'onbeforeunload', abort );
+	
+})();
