Index: /trunk/contactcenter/setup/tables_update.inc.php
===================================================================
--- /trunk/contactcenter/setup/tables_update.inc.php	(revision 203)
+++ /trunk/contactcenter/setup/tables_update.inc.php	(revision 284)
@@ -56,24 +56,3 @@
 		return $GLOBALS['setup_info']['contactcenter']['currentver'];
 	}
-	$test[] = '1.0.005';
-	function contactcenter_upgrade1_0_005() {
-		$GLOBALS['setup_info']['contactcenter']['currentver'] = '1.14';
-		return $GLOBALS['setup_info']['contactcenter']['currentver'];
-	}
-	$test[] = '1.14';
-	function contactcenter_upgrade1_14() {				
-		$GLOBALS['phpgw_setup']->db->query("ALTER TABLE phpgw_cc_connections ALTER COLUMN connection_value TYPE varchar(100)");
-		$GLOBALS['setup_info']['contactcenter']['currentver'] = '1.150';
-		return $GLOBALS['setup_info']['contactcenter']['currentver'];
-	}
-	$test[] = '1.15';
-	function contactcenter_upgrade1_15() {
-		$GLOBALS['phpgw_setup']->db->query("ALTER TABLE phpgw_cc_contact ADD COLUMN last_status char(1) DEFAULT 'N'::bpchar");
-		$GLOBALS['phpgw_setup']->db->query("ALTER TABLE phpgw_cc_contact ADD COLUMN last_update int8 DEFAULT (date_part('epoch'::text, ('now'::text)::timestamp(3) with time zone) * (1000)::double precision)");
-		$GLOBALS['phpgw_setup']->db->query("ALTER TABLE phpgw_cc_contact ADD COLUMN category character varying(20)");
-
-		$GLOBALS['setup_info']['contactcenter']['currentver'] = '1.20';
-		return $GLOBALS['setup_info']['contactcenter']['currentver'];
-	}
-
 ?>
Index: /trunk/contactcenter/setup/external_catalogs.inc.php
===================================================================
--- /trunk/contactcenter/setup/external_catalogs.inc.php	(revision 284)
+++ /trunk/contactcenter/setup/external_catalogs.inc.php	(revision 284)
@@ -0,0 +1,47 @@
+<?php
+/*
+ * Created on 20/08/2007 Por Bruno costa
+ *
+ *	Arquivo de configuração de catálogos externos
+ *
+ */
+
+/*
+ * This file is comprised of two arrays describing the external catalogs ($external_srcs) and their attribute mappings
+ * ($external_mappings). The mapping between an external catalog and his attribute mappings are made with the array indices, i. e.
+ * a catalog at external_srcs with indice = 1 use the mapping with indice = 1 at external_mapping.
+ *
+ * external_srcs' format:
+ *
+ * 	$external_srcs	=	array(
+ * 					1	=>	array(
+ * 						'name'		=>	'Catalog's name',
+ * 						'host'		=>	'catalog's hostname',
+ * 						'dn'		=>	'catalog's base dn',
+ * 						'acc'		=>	'catalog's bind dn',
+ * 						'pw'		=>	'bind dn's password',
+ * 						'obj'		=>	'objectClass that will be used in searches',
+ * 						'branch'	=>	strtolower('attribute used as branches in the catalog tree'),
+ * 					),
+ * 					2 	=>	array(
+ * 						...
+ * 					),
+ * 	);
+ *
+ * external_mappings' format:
+ *
+ * 	$external_mappings	=	array(
+ *							1	=>	array(
+ *								'contact.id_contact'				=>	array('dn'),
+ *								'contact.photo'						=>	array('jpegPhoto'),
+ *								'contact.prefixes.prefix'			=>	false, //used when you don't have an attribute or don't want to use one
+ *								...
+ *							),
+ *							2	=>	array(
+ *								...
+ *							),
+ *		);
+ *
+ */
+
+ 
Index: /trunk/contactcenter/setup/setup.inc.php
===================================================================
--- /trunk/contactcenter/setup/setup.inc.php	(revision 203)
+++ /trunk/contactcenter/setup/setup.inc.php	(revision 284)
@@ -37,5 +37,5 @@
 	$setup_info['contactcenter']['hooks'][] = 'preferences';
 	$setup_info['contactcenter']['hooks'][] = 'config_validate';
-	
+
 	/* ContactCenter Tables */
 	$setup_info['contactcenter']['tables'][] = 'phpgw_cc_status';
@@ -69,7 +69,7 @@
 	$setup_info['contactcenter']['tables'][] = 'phpgw_cc_contact_company';
 	$setup_info['contactcenter']['tables'][] = 'phpgw_cc_contact_grps';
-	
+
 	$setup_info['contactcenter']['tables'][] = 'phpgw_cc_groups';
-	
+
 	/* Dependencies for this app to work */
 	$setup_info['contactcenter']['depends'][] = array(
Index: /trunk/contactcenter/doc/change_log.txt
===================================================================
--- /trunk/contactcenter/doc/change_log.txt	(revision 56)
+++ /trunk/contactcenter/doc/change_log.txt	(revision 284)
@@ -3,11 +3,5 @@
 Nilton Emilio Buhrer Neto.
 
---------------------------- NOTA IMPORTANTE --------------------------
 
-A partir de Agosto de 2007, todos os registros de bugs aqui relatados foram
-transferidos para o site do ExpressoLivre, no Wiki-Trac do módulo.
-Vide: http://www.expressolivre.org/dev/wiki/contactcenter/changelog
-
-----------------------------------------------------------------------
 27/02/2007 - [1.0.005]
 - Excluído o diretorio contactcenter/templates/celepar e seus arquivos foram movidos para
Index: /trunk/contactcenter/inc/ThreadUtility.inc.php
===================================================================
--- /trunk/contactcenter/inc/ThreadUtility.inc.php	(revision 284)
+++ /trunk/contactcenter/inc/ThreadUtility.inc.php	(revision 284)
@@ -0,0 +1,32 @@
+<?php
+	/***********************************************************************************\
+	* eGroupWare - Contacts Center                                              		*
+	* http://www.egroupware.org                                                 		*
+	* Written by:                                                               		*
+	*  - Brian W. Bosh from	Multi-threading strategies in PHP at						*
+	* http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html	*
+	* Adapted by:																		*
+	*  - Mário César Kolling <mario.kolling@serpro.gov.br>								*
+	* ----------------------------------------------------------------------------------*
+	*  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.                                               		*
+	\***********************************************************************************/
+
+	/*
+	 * Utility class used in the "Thread" solution
+	 */
+
+	function response ($status, $response) {
+		echo $status . "\n";
+		echo base64_encode(serialize($response)), "\n";
+	}
+	function processresponse ($string) {
+		$parts = explode ("\n", $string);
+		$status = $parts[0];
+		$data = unserialize (base64_decode ($parts[1]));
+		return array ("status" => $status, "data" => $data);
+	}
+
+?>
Index: /trunk/contactcenter/inc/class.bo_ldap_manager.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 23)
+++ /trunk/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 284)
@@ -12,23 +12,24 @@
   \***************************************************************************/
 
-	
+
 	/*
 		This class is responsible for the LDAP control/generic functions and for
 		configuration gathering
 	*/
-
-	class bo_ldap_manager 
+	include_once('class.Thread.inc.php');
+
+	class bo_ldap_manager
 	{
-		
+
 		var $srcs;
 
-		
 		function bo_ldap_manager ()
 		{
+
 			if (!($this->srcs = $GLOBALS['phpgw']->session->appsession('bo_ldap_manager.srcs','contactcenter')))
 			{
 				$c = CreateObject('phpgwapi.config','contactcenter');
 				$data = $c->read_repository();
-				
+
 				if (!$data or $data['cc_global_source0'] !== 'ldap')
 				{
@@ -36,5 +37,5 @@
 					return;
 				}
-				
+
 				$this->srcs = array(
 					1 => array(
@@ -47,4 +48,5 @@
 						'branch' => strtolower('ou')
 					)
+
 				);
 			}
@@ -54,11 +56,11 @@
 		{
 		}
-	
+
 		/*
-		
+
 			@function get_all_ldap_sources
 			@abstract Returns an array containing all LDAP sources informations
 			@author Raphael Derosso Pereira
-		
+
 			@return array All LDAP information
 				$return = array(
@@ -67,9 +69,9 @@
 						'dn'   => (string),
 						'acc'  => (string),
-						'pw'   => (string)   
+						'pw'   => (string)
 					),
 					...
 				)
-				
+
 			TODO: Return multiple sources...
 		*/
@@ -78,8 +80,27 @@
 			return $this->srcs;
 		}
-		
+
+		/*
+		* @function get_external_ldap_sources
+		* @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		* @abstract returns an array with the external sources
+		* @return (array) the external sources
+		*/
+
+		function get_external_ldap_sources()
+		{
+			include(PHPGW_INCLUDE_ROOT . '/contactcenter/setup/external_catalogs.inc.php' );
+			//include('external_catalogs.inc.php' );
+			return $external_srcs;
+		}
+
+		/*
+		 * @function get_ldap_fields_association
+		 * @abstract get the fields associantion for ldap source
+		 * @return an array with attribute mappings
+		 */
 		function get_ldap_fields_association ( $id_source )
 		{
-			
+
 			$op_iop = array(
 				'contact.id_contact'               => array('dn'),
@@ -90,4 +111,5 @@
 				'contact.family_names'             => array('sn'),
 				'contact.names_ordered'            => array('cn'),//,'displayName'),
+
 				'contact.suffixes.suffix'          => false,
 				'contact.birthdate'                => false,
@@ -95,11 +117,15 @@
 				'contact.pgp_key'                  => false,
 				'contact.notes'                    => false,
-				'contact.mail_forwarding_address' => array('mailForwardingAddress'),
-				'contact.account_type' => array('phpgwAccountType'),
+				'contact.mail_forwarding_address'  => array('mailForwardingAddress'),
+				'contact.account_type'             => array('phpgwAccountType'),
+				'contact.account_status'           => array('phpgwAccountStatus'),
+				'contact.account_visible'          => array('phpgwAccountVisible'),
+				'contact.object_class'             => array('objectClass'),
 				'contact.business_info.title'      => array('title'),
-				'contact.business_info.department' => array('ou'),
+				'contact.business_info.department' => array('ou'), // Setor do empregado...
+				'contact.business_info.empNumber'  => array('employeeNumber'), // Matricula do empregado
 				'contact.company.company_name'     => array('o'),
 				'contact.company.company_notes'    => array('businessCategory'),
-				
+
 				'contact.contact_related.names_ordered' => 'contact.contact_related.typeof_relation.contact_relation_name',
 				'contact.contact_related.typeof_relation.contact_relation_name' =>  array(
@@ -107,30 +133,30 @@
 					'secretary' => array('secretary')
 				),
-				
+
 				'contact.address.address1'         => 'contact.address.typeof_address.contact_address_type_name',
 				'contact.address.typeof_address.contact_address_type_name' => array(
 					'home' => array('street', 'st', 'postalAddress', 'homePostalAddress'),
 				),
-				
+
 				'contact.address.postal_code'      => 'contact.address.typeof_address.contact_address_type_name',
 				'contact.address.typeof_address.contact_address_type_name' => array(
 					'home' => array('PostalCode'),
 				),
-				
+
 				'contact.address.city.city_name'   => 'contact.address.typeof_address.contact_address_type_name',
 				'contact.address.typeof_address.contact_address_type_name' => array(
 					'home' => array('l'),
 				),
-				
+
 				'contact.address.city.state.state_name'       => 'contact.address.typeof_address.contact_address_type_name',
 				'contact.address.typeof_address.contact_address_type_name' => array(
 					'home' => false,
 				),
-				
+
 				'contact.address.city.country.id_country'     => 'contact.address.typeof_address.contact_address_type_name',
 				'contact.address.typeof_address.contact_address_type_name' => array(
 					'home' => array('c')
 				),
-				
+
 				'contact.connection.connection_value'         => 'contact.connection.typeof_connection.contact_connection_type_name',
 				'contact.connection.typeof_connection.contact_connection_type_name' => array (
@@ -143,23 +169,81 @@
 				),
 			);
-			
+
 			return $op_iop;
+
+		}
+
+		/*
+		 * @function get_external_ldap_fields_association
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 * @abstract get the fields association for an external ldap_source
+		 * @return an array with attribute mappings
+		 */
+		function get_external_ldap_fields_association ( $id_source )
+		{
+			include(PHPGW_INCLUDE_ROOT . '/contactcenter/setup/external_catalogs.inc.php' );
+			//include('external_catalogs.inc.php' );
+			return $external_mappings[$id_source];
+		}
+
+		/*
+		 * @function test_connection
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 * @abstract Test if we can bind to a ldap server in a reasonable time
+		 * @param (string) $host ldap server's hostname
+		 * @param (string) $account ldap bind dn
+		 * @param (string) $password a bind dn's password
+		 * @return (array) an array with the answer from the subprocess, null otherwise
+		 */
+		function test_connection($host, $account, $password, $timeout = 5)
+		{
+			//opens a subprocess for nonblocking bind
+			$tsearch = Thread::Create('class.ldap_assync.inc.php', array('host'	=> $host,
+																'account'	=> $account,
+																'password'	=> $password
+																)
+			);
+
+			// It's problably more efficient to let method readResponse control the timeout through
+			// stream_select native timeout.
+			$response = NULL;
+			for ($i = 0; $i < $timeout; $i++)
+			{
+				if ($tsearch->isActive())
+				{
+					sleep(1);
+					if (($response = $tsearch->readResponse()) !== NULL)
+					{
+						$tsearch->close();
+						return $response;
+					}
+
+				}
+				else
+				{
+					$response = $tsearch->readResponse();
+					break;
+				}
+			}
+
+			$tsearch->close();
+			return null;
 		}
 
 		/*!
-		
+
 			@function get_ldap_tree
 			@abstract Returns the LDAP tree corresponding to the specified level
 			@author Raphael Derosso Pereira
-			
+
 			@param (integer) $id_source The ID of the LDAP source
-			
+
 			@param (string)  $context The context to be used as root branch
-				
+
 			@param (boolean) $recursive Make it a recursive construction.
 				CAUTION! This is EXTREMELY SLOW on large LDAP databases,
 				specially when they're not indexed
-		*/		
-		function get_ldap_tree($id_source, $context = false, $recursive = false) 
+		*/
+		function get_ldap_tree($id_source, $context = false, $recursive = false)
 		{
 			if (!$this->srcs[$id_source])
@@ -167,5 +251,5 @@
 				return null;
 			}
-			
+
 			$ldap = $GLOBALS['phpgw']->common->ldapConnect($this->srcs[$id_source]['host'], $this->srcs[$id_source]['acc'],$this->srcs[$id_source]['pw'], false);
 			if (!$ldap)
@@ -173,5 +257,5 @@
 				return false;
 			}
-			
+
 			if ($recursive)
 			{
@@ -181,8 +265,59 @@
 				return $tree;
 			}
-			
-			return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']);
-		}
-
+
+			return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch'], 0);
+		}
+
+		/*!
+
+			@function get_external_ldap_tree
+			@abstract Returns the LDAP external tree corresponding to the specified level
+			@author Mário César Kolling <mario.kolling@serpro.gov.br>
+			@param (integer) $id_source The ID of the external LDAP source
+			@param (string)  $context The context to be used as root branch
+			@param (boolean) $recursive Make it a recursive construction.
+				CAUTION! This is EXTREMELY SLOW on large LDAP databases,
+				specially when they're not indexed
+		*/
+		function get_external_ldap_tree($id_source, $context = false, $recursive = false)
+		{
+
+
+			include(PHPGW_INCLUDE_ROOT . '/contactcenter/setup/external_catalogs.inc.php' );
+			//include('external_catalogs.inc.php' );
+
+			if (!$external_srcs[$id_source])
+			{
+				return null;
+			}
+
+			// calls test_connection first. If succeeded continue, return error message otherwise.
+			if (!($response = $this->test_connection($external_srcs[$id_source]['host'], $external_srcs[$id_source]['acc'], $external_srcs[$id_source]['pw'], 10)))
+			{
+				return array(
+					'msg'		=>	lang("Catalog %1 temporarily unavailable. Please try again later!", $external_srcs[$id_source]['name']),
+					'timeout'	=>	'true'
+				);
+			}
+
+			$ldap = $GLOBALS['phpgw']->common->ldapConnect($external_srcs[$id_source]['host'], $external_srcs[$id_source]['acc'],$external_srcs[$id_source]['pw'], false);
+			if (!$ldap)
+			{
+				return false;
+			}
+
+			// Option recursive commented out
+			/*
+			if ($recursive)
+			{
+				$tree = $this->get_ldap_tree_recursive($ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']);
+				$tree['recursive'] = true;
+
+				return $tree;
+			}
+			*/
+
+			return $this->get_ldap_tree_level($id_source, $ldap, $context, $external_srcs[$id_source]['obj'],$external_srcs[$id_source]['branch'], 1);
+		}
 
 		/*!
@@ -201,5 +336,5 @@
 				return null;
 			}
-			
+
 			$count = ldap_count_entries($resource,$result_res);
 			if ( $count == 0 )
@@ -218,14 +353,16 @@
 				}
 			}
-			
+
 			$entries = ldap_get_entries($resource, $result_res);
-			
+
 			for ($i = 0; $i < $entries['count']; $i++)
 			{
 				$subtree = $this->get_ldap_tree_recursive($resource, $entries[$i]['dn'], $objectClass);
-				
+
 				$dn_parts=ldap_explode_dn($entries[$i]['dn'],1);
-				
-				if ($subtree !== null and is_array($subtree)) 
+
+
+
+				if ($subtree !== null and is_array($subtree))
 				{
 					$tree[$i]['name'] = $dn_parts[0];
@@ -244,5 +381,5 @@
 						'sub_branch' => false
 					);
-				} 
+				}
 			}
 
@@ -256,17 +393,17 @@
 			}
 		}
-		
+
 		function get_ldap_referrals($ds, $dn, $filter) {
-			
+
 			ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
 			ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3);
-			
+
 			if ($ds) {
 			    ldap_bind($ds);
-			   	$sr=ldap_list($ds,$dn, $filter);		    
+			   	$sr=ldap_list($ds,$dn, $filter);
 			   	$ref = ldap_first_reference($ds, $sr);
 			   	$array_referral = array();
 			   	$idx = 0;
-			    	
+
 				 while ($ref) {
 					$array_referral[$idx++] = ldap_get_dn($ds, $ref);
@@ -275,50 +412,82 @@
 				return $array_referral;
 			}
-			else 
+			else
 				return false;
 		}
 
 		function get_ldap_sub_branches_referrals($ds, $dn, $filter) {
-			
+
 			$referral = $this -> get_ldap_referrals($ds, $dn, $filter);
 			$sub_branches = array();
-			
+
 			for($i = 0; $i <count($referral); $i++) {
 				$dn = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $referral[$i]));
-				$dn = explode(",",$dn);				
+				$dn = explode(",",$dn);
 				$dn = strtoupper(str_replace("ou=", "",$dn[0]));
 				$dn = str_replace("DC=", "",$dn);
-																						
+
 				$sub_branch = array(
 											'name' => $dn,
 					                    	'type' => 'unknown',
                     						'value' => $referral[$i],
-                    						'sub_branch' => false		
-										);															
-				$sub_branches[$i] = $sub_branch;			
+                    						'sub_branch' => false
+										);
+				$sub_branches[$i] = $sub_branch;
 			}
 			return $sub_branches;
 		}
-		
-
-		function get_ldap_tree_level($id_source, $resource, $context, $objectClass, $branch_dn)
+
+		function translate_accentuation($text)
+		{
+			/*
+			 * Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada
+			 * pela função ldap_explode_dn().
+			 */
+
+			return utf8_decode(preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $text));
+		}
+
+		function get_ldap_tree_level($id_source, $resource, $context, $objectClass, $branch_dn, $external = 0)
 		{
 			if(strstr($context, "ldap://")){
-				$refer_context = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $context));												
-				$host	= preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $context);																
+				$refer_context = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $context));
+				$host	= preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $context);
 				$resource = ldap_connect($host);
-				ldap_bind($resource);	
-			}
-			$dn_parts = ldap_explode_dn(($refer_context ? $refer_context : $context),1);			
+				ldap_bind($resource);
+			}
+
+			/*
+			 * TODO: Search timeouts
+			 */
+
+			$dn_parts = ldap_explode_dn(($refer_context ? $refer_context : $context),1);
 			//$filter = '(!(objectClass='.$objectClass.'))';
 			// Don't show OU's whith phpgwAccountVisible equal to '-1'
-			$filter = '(&(!(objectClass='.$objectClass.')) (!(phpgwAccountVisible=-1)))';
-			$result_res = @ldap_list($resource,  ($refer_context ? $refer_context : $context), $filter);
+
+			if ($external)
+			{
+				// external source: get all organizationalUnits
+				$filter = '(objectClass=organizationalUnit)';
+			}
+			else
+			{
+				// get any objectClass except the objectClass used for the source
+				// and whose attribute phpgwAccountVisible value is different from -1
+				$filter = '(&(!(objectClass='.$objectClass.')) (!(phpgwAccountVisible=-1)))';
+			}
+			$result_res = @ldap_list($resource,  ($refer_context ? $refer_context : $context), $filter, array(), 0, 0);
 			@ldap_sort($resource, $result_res, 'ou');
 
+			// Timeouts commented out
+			/*
 			if ($result_res === false)
 			{
+				if (ldap_errno($resource) === 3)
+				{
+					return array('error_msg' => ldap_error($resource));
+				}
 				return null;
 			}
+			*/
 
 			$count = ldap_count_entries($resource,$result_res);
@@ -326,6 +495,7 @@
 			if ( $count == 0 )
 			{
-				$filter = 'objectClass='.$objectClass;
-				$result_res2 = @ldap_list($resource, ($refer_context ? $refer_context : $context), $filter);
+				$filter = '(objectClass='.$objectClass.')';
+				// Get only one attribute of the source's objectClass
+				$result_res2 = @ldap_list($resource, ($refer_context ? $refer_context : $context), $filter, Array('cn'), 0, 1);
 				$entries_count = ldap_count_entries($resource, $result_res2);
 
@@ -333,8 +503,9 @@
 				{
 					return array(
-						'name'       => $dn_parts[0],
+						'name'       => $this->translate_accentuation($dn_parts[0]),
 						'type'       => 'catalog',
 						'class'      => 'bo_global_ldap_catalog',
-						'class_args' => array($id_source, $context),
+						// Pass the variable $external as a parameter to the constructor
+						'class_args' => array($id_source, $context, $external),
 						'icon'       => 'globalcatalog-mini.png',
 						'value'      => $context,
@@ -345,5 +516,5 @@
 				{
 					return array(
-						'name' => $dn_parts[0],
+						'name' => $this->translate_accentuation($dn_parts[0]),
 						'type' => 'empty'
 					);
@@ -361,12 +532,13 @@
 				$dn_parts_full = ldap_explode_dn($dn,0);
 				list($group) = explode('=',$dn_parts_full[0]);
-				
-				if ($group == $branch_dn or $branch_dn === 'all')
+
+				//Faz a comparação do branch como case insensitive
+				if (strtolower($group) == strtolower($branch_dn) or $branch_dn === 'all')
 				{
 					$tree['sub_branch'][$i] = array(
-						'name'  => $dn_parts_1[0],
+						'name'  => $this->translate_accentuation($dn_parts_1[0]),
 						'type'  => 'unknown',
 						'value' =>  ($refer_context ? $host."/" : "").$dn,
-						'sub_branch' => false					
+						'sub_branch' => false
 					);
 					$sub_branch_found = true;
@@ -374,5 +546,5 @@
 				$i++;
 			}
-			
+
 			if(! $refer_context) {
 				$array_referral = $this -> get_ldap_sub_branches_referrals($resource, $context,'(objectClass=organizationalUnit)');
@@ -383,13 +555,14 @@
 
 			$filter = 'objectClass='.$objectClass;
-			$result_res2 = @ldap_list($resource, ($refer_context ? $refer_context : $context), $filter);
+			$result_res2 = @ldap_list($resource, ($refer_context ? $refer_context : $context), $filter, Array('cn'), 0, 1);
 			$entries_count = ldap_count_entries($resource, $result_res2);
 
 			if ($result_res2 !== false && $entries_count > 0 && $sub_branch_found)
 			{
-				$tree['name']       = $dn_parts[0];
+				$tree['name']       = $this->translate_accentuation($dn_parts[0]);
 				$tree['type']       = 'mixed_catalog_group';
 				$tree['class']      = 'bo_global_ldap_catalog';
-				$tree['class_args'] = array($id_source,$context);
+				// Pass the variable $external as a parameter to the constructor
+				$tree['class_args'] = array($id_source,$context,$external);
 				$tree['icon']       = 'globalcatalog-mini.png';
 				$tree['value']      = $context;
@@ -398,8 +571,9 @@
 			{
 				return array(
-					'name'       => $dn_parts[0],
+					'name'       => $this->translate_accentuation($dn_parts[0]),
 					'type'       => 'catalog',
 					'class'      => 'bo_global_ldap_catalog',
-					'class_args' => array($id_source, $context),
+					// Pass the variable $external as a parameter to the constructor
+					'class_args' => array($id_source, $context,$external),
 					'icon'       => 'globalcatalog-mini.png',
 					'value'      => $context,
@@ -409,12 +583,12 @@
 			else
 			{
-				$tree['name']       = $dn_parts[0];
+				$tree['name']       = $this->translate_accentuation($dn_parts[0]);
 				$tree['type']       = 'catalog_group';
 				$tree['class']      = 'bo_catalog_group_catalog';
-				$tree['class_args'] = array('$this', '$this->get_branch_by_level($this->catalog_level[0])');
+				// Pass the variable $external as a parameter to the constructor
+				$tree['class_args'] = array('$this', '$this->get_branch_by_level($this->catalog_level[0])', $external);
 				$tree['value']      = $context;
 				$tree['ldap']       = array('id_source' => $id_source, 'context' => $context);
 			}
-			
 			usort($tree['sub_branch'], array($this, "compareTreeNodes"));
 			return $tree;
@@ -422,7 +596,7 @@
 
 		function compareTreeNodes($a, $b)	{
-						
+
 			return strnatcasecmp($a['name'], $b['name']);
-		}	
+		}
 
 	}
Index: /trunk/contactcenter/inc/class.so_group.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.so_group.inc.php	(revision 258)
+++ /trunk/contactcenter/inc/class.so_group.inc.php	(revision 284)
@@ -117,5 +117,5 @@
 			'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '.
 			'C.connection_is_default = true and B.id_typeof_contact_connection = 1 and '.
-			'A.id_owner ='.$this->owner.' order by A.names_ordered,C.connection_value';
+			'A.id_owner ='.$this->owner.' order by A.names_ordered';
 
 					
Index: /trunk/contactcenter/inc/class.bo_catalog_group_catalog.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_catalog_group_catalog.inc.php	(revision 2)
+++ /trunk/contactcenter/inc/class.bo_catalog_group_catalog.inc.php	(revision 284)
@@ -20,8 +20,10 @@
 
 	include_once('class.abo_catalog.inc.php');
-	
+
 	class bo_catalog_group_catalog extends abo_catalog
 	{
-			
+
+		var $external;
+
 		var $fields = array(
 			'id_contact'    => true,
@@ -38,5 +40,5 @@
 			'pgp_key'       => true,
 			'notes'         => true,
-			
+
 			/* Array fields */
 			'companies'     => true,
@@ -45,18 +47,19 @@
 			'connections'   => true
 		);
-	
-		/*!
-		
+
+		/*!
+
 		 @function bo_people_catalog
 		 @abstract Constructor
 	 	 @author Raphael Derosso Pereira
-	 	 
+
 	 	*/
-		function bo_catalog_group_catalog(& $bo_contactcenter, & $catalog)
+		function bo_catalog_group_catalog(& $bo_contactcenter, & $catalog, $external = 0)
 		{
 			$this->bo_contactcenter = & $bo_contactcenter;
 			$this->catalog = & $catalog;
-		}
-		 	
+			$this->external = $external;
+		}
+
 
 		/*!
@@ -68,5 +71,5 @@
 
 		 @param SEE class bo_contactcenter for usage
-		
+
 		*/
 		function find($what, $rules, $other)
@@ -74,10 +77,11 @@
 			if ($ldap_info = $this->catalog['ldap'])
 			{
-				$meta_catalog =& CreateObject('contactcenter.bo_global_ldap_catalog',$ldap_info['id_source'], $ldap_info['context']);
+
+				$meta_catalog =& CreateObject('contactcenter.bo_global_ldap_catalog',$ldap_info['id_source'], $ldap_info['context'], $this->external);
 				return $meta_catalog->find($what, $rules, $other);
 			}
-			
+
 			$results = array();
-			
+
 			reset($this->catalog);
 			while(list(, $new_catalog) = each($this->catalog['sub_branch']))
@@ -86,12 +90,12 @@
 				//echo 'Setting catalog: <b>'.$new_catalog['name'].'</b><br>';
 				$new_catalog = $this->bo_contactcenter->set_catalog($new_catalog);
-				
+
 				//if($new_catalog) echo 'Setado corretamente!<br><br>'; else echo 'Erro ao setar<br><br>';
-				
+
 				if ($new_catalog['type'] === 'empty')
 				{
 					continue;
 				}
-				
+
 				$temp_res = $this->bo_contactcenter->catalog->find($what, $rules, $other);
 				if (is_array($temp_res) and count($temp_res))
@@ -107,21 +111,21 @@
 			return $result;
 		}
-		
-		/*!
-		
+
+		/*!
+
 		 @function get_single_entry
 		 @abstract Returns all information requested about one contact
 		 @author Raphael Derosso Pereira
-		     
+
 		 @param integer $id_contact The contact ID
 		 @param array $fields The array returned by get_fields whith true
 		 	on the fields to be taken.
-		 	
+
 		*/
 		function get_single_entry ( $id_contact, $fields )
-		{	
-			if (!is_array($fields)) 
-			{
-				if (is_object($GLOBALS['phpgw']->log)) 
+		{
+			if (!is_array($fields))
+			{
+				if (is_object($GLOBALS['phpgw']->log))
 				{
 					$GLOBALS['phpgw']->log->message(array(
@@ -129,15 +133,15 @@
 						'line' => __LINE__,
 						'file' => __FILE__));
-					
+
 					$GLOBALS['phpgw']->log->commit();
 				}
-				else 
+				else
 				{
 					exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
 				}
 			}
-			
+
 			$contact_array = $this->get_multiple_entries(array($id_contact), $fields);
-			
+
 			if (!count($contact_array))
 			{
@@ -149,15 +153,15 @@
 			else
 				$contact_data = $contact_array[$id_contact];
-			
+
 			if (!is_array($contact_data))
 			{
 				return false;
 			}
-			
+
 			return $contact_data;
 		}
-	
-		/*!
-		 
+
+		/*!
+
 		 @function get_multiple_entries
 		 @abstract Returns multiple Contacts data into one array
@@ -172,6 +176,6 @@
 		 		'sort'      => <sort>,
 		 		'order_by'  => <order by>
-		 	); 
-		
+		 	);
+
 		*/
 		function get_multiple_entries ( $id_contacts, $fields, $other_data = false )
@@ -179,5 +183,5 @@
 			if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data)))
 			{
-				if (is_object($GLOBALS['phpgw']->log)) 
+				if (is_object($GLOBALS['phpgw']->log))
 				{
 					$GLOBALS['phpgw']->log->message(array(
@@ -185,5 +189,5 @@
 						'line' => __LINE__,
 						'file' => __FILE__));
-					
+
 					$GLOBALS['phpgw']->log->commit();
 				}
@@ -192,12 +196,14 @@
 				}
 			}
-			
+
 			$contacts = array();
-	
+
 			if ($other_data)
 			{
 				//TODO
 			}
-	
+
+			//error_log("bo_ldap_catalog_group_catalog->get_multiple_entries \n", 3, '/var/www/teste.log');
+
 			/* First check if this is a LDAP Catalog Group. In this case, just leave the
 			 * subtree search for the LDAP server
@@ -205,8 +211,8 @@
 			if ($ldap_info = $this->catalog['ldap'])
 			{
-				$meta_catalog = CreateObject('contactcenter.bo_global_ldap_catalog', $ldap_info['id_source'], $ldap_info['context']);
+				$meta_catalog = CreateObject('contactcenter.bo_global_ldap_catalog', $ldap_info['id_source'], $ldap_info['context'], $this->external);
 				return $meta_catalog->get_multiple_entries($id_contacts, $fields, $other_data);
 			}
-			
+
 			/* Search for the catalog of the first entry and try to get all ids from that
 			 * catalog. Repeat to the ones not found until there's none missing or no more
@@ -220,5 +226,5 @@
 				$this->bo_contactcenter->set_catalog($branch);
 				$contacts += $this->bo_contactcenter->catalog->get_multiple_entries($id_contacts, $fields, $other_data);
-				
+
 				reset($contacts);
 				while (list($id) = each($contacts))
@@ -237,8 +243,8 @@
 
 			$this->bo_contactcenter->set_catalog($this->catalog);
-			
+
 			return $contacts;
 		}
-	
+
 		function get_all_entries_ids ()
 		{
@@ -246,9 +252,9 @@
 			return null;
 		}
-		
+
 		/*********************************************************************\
 		 *                Methods to get general fields                      *
 		\*********************************************************************/
-		
+
 		/*********************************************************************\
 		 *                   Methods to Include Data                         *
Index: /trunk/contactcenter/inc/class.ldap_assync.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.ldap_assync.inc.php	(revision 284)
+++ /trunk/contactcenter/inc/class.ldap_assync.inc.php	(revision 284)
@@ -0,0 +1,63 @@
+<?php
+	/***********************************************************************************\
+	* eGroupWare - Contacts Center                                              		*
+	* http://www.egroupware.org                                                 		*
+	* Written by:                                                               		*
+	*  - Mário César Kolling <mario.kolling@serpro.gov.br>								*
+	* Based on:																			*
+	* - Multi-threading strategies in PHP from 											*
+	* http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html	*
+	* ----------------------------------------------------------------------------------*
+	*  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.                                               		*
+	\***********************************************************************************/
+
+	require_once('class.ThreadInstance.inc.php');
+
+	/*
+	 * This is the Main Class that will be called in a new php process to test a bind in an ldap source
+	 */
+
+	class ldap_assync extends ThreadInstance
+	{
+
+		var $ldap;
+		var $account;
+		var $password;
+		var $host;
+
+		function ldap_assync($host, $account = false, $password = false)
+		{
+			$this->host = $host;
+			$this->account = $account;
+			$this->password = $password;
+			$this->ldap = ldap_connect($this->host);
+
+			$this->setup();
+			$this->go();
+		}
+
+		function go ()
+		{
+			if (ldap_bind($this->ldap, $this->account, $this->password))
+			{
+				$this->response("ok", ldap_error($this->ldap));
+			}
+			else
+			{
+				$this->response("no", ldap_error($this->ldap));
+			}
+
+		}
+
+	}
+
+	/*
+	 * Here is where we instantiate the new class. All the parameters are passed to the php process
+	 * as environment variables
+	 */
+	$search_ldap = new ldap_assync($_ENV['host'], $_ENV['account'], $_ENV['password']);
+
+?>
Index: /trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 167)
+++ /trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 284)
@@ -16,13 +16,16 @@
 	*/
 	include_once('class.abo_catalog.inc.php');
-	
+
 	class bo_global_ldap_catalog extends abo_catalog
 	{
 		var $ldap;
-	
+
 		var $src_info;
-		
+
 		var $trans_table;
-		
+
+		// used to determine if a catalog is external
+		var $external;
+
 		var $fields = array(
 			'id_contact'    => true,
@@ -40,5 +43,8 @@
 			'pgp_key'       => true,
 			'notes'         => true,
-			
+			'department'    => true,
+
+			'empNumber'     => true,
+
 			/* Array fields */
 			'companies'     => true,
@@ -47,24 +53,37 @@
 			'connections'   => true
 		);
-		
+
 		/*
-		
+
 			@function global_ldap_catalog
 			@abstract Constructor
 			@author Raphael Derosso Pereira
-			
+			@author Mário César Kolling (external catalogs)
+
 			@param integer $id_source The ID of the LDAP source
-			
+			@param string $context Ldap bind DN
+			@param integer $external 0 = internal catalog, 1 = external catalog
+
 		*/
-		function bo_global_ldap_catalog ( $id_source, $context )
-		{
+		function bo_global_ldap_catalog ( $id_source, $context, $external = 0 )
+		{
+
+			$this->external = $external;
+
 			if (!function_exists('ldap_search'))
 			{
 				exit('PHP LDAP support Unavailable!');
 			}
-			
+
 			$this->ldap = CreateObject('contactcenter.bo_ldap_manager');
-			
-			$all_src = $this->ldap->get_all_ldap_sources();
+
+			if ($this->external)
+			{
+				$all_src = $this->ldap->get_external_ldap_sources();
+			}
+			else
+			{
+				$all_src = $this->ldap->get_all_ldap_sources();
+			}
 
 			if (!$all_src[$id_source] or !$context)
@@ -75,9 +94,17 @@
 			$this->src_info = $all_src[$id_source];
 			$this->src_info['context'] = $context;
-			$this->trans_table = $this->ldap->get_ldap_fields_association($id_source);
-		}
-		
+
+			if ($this->external)
+			{
+				$this->trans_table = $this->ldap->get_external_ldap_fields_association($id_source);
+			}
+			else
+			{
+				$this->trans_table = $this->ldap->get_ldap_fields_association($id_source);
+			}
+		}
+
 		/*
-		
+
 			@function find
 			@abstract Searches the LDAP directory for the specified fields with
@@ -85,5 +112,5 @@
 				that matches the rules.
 			@author Raphael Derosso Pereira
-			
+
 			@param array $what The fields to be taken
 			@param array $rules The rules to be match. See class.abo_catalog.inc.php
@@ -94,12 +121,12 @@
 					'offset' => (integer) [NOT IMPLEMENTED]
 				)
-		
+
 		*/
 		function find($what, $rules=false, $other=false)
 		{
 			$restric_fields = $this->get_restrictions_without_branch($rules);
-			
+
 			$trans_f = $this->translate_fields($what, $restric_fields);
-			
+
 			foreach($trans_f as $orig => $field_a)
 			{
@@ -109,26 +136,30 @@
 				}
 			}
-			
+
 			$fields = array_unique($fields);
-			
+
 			$filter = $this->process_restrictions($rules, $trans_f);
 
 			if(strstr($this->src_info['context'], "ldap://")) {
 				$refer_context 	= str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $this->src_info['context']));
-				$host	= preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $this->src_info['context']);				
+				$host	= preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $this->src_info['context']);
 				$this->src_info['host'] = $host;
-				//$this->src_info['acc'] = '';
-				//$this->src_info['pw']  = '';				
-			}			
+				$this->src_info['acc'] = '';
+				$this->src_info['pw']  = '';
+			}
 
 			$ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true);
-			
+
 			if (!$ldap)
 			{
 				return false;
 			}
-			
-			$fields[]  ='phpgwAccountVisible';
-			$result_r = @ldap_search($ldap ,($refer_context  ? $refer_context  : $this->src_info['context']), $filter, $fields);
+
+			if (!$this->external)
+			{
+				$fields[]  ='phpgwAccountVisible';
+			}
+
+			$result_r = @ldap_search($ldap ,($refer_context  ? $refer_context  : $this->src_info['context']), $filter, $fields, 0);
 
 			if (!$result_r)
@@ -136,5 +167,5 @@
 				return false;
 			}
-			
+
 			if ($other['order'])
 			{
@@ -150,15 +181,15 @@
 				}
 			}
-			
+
 			$result_u = ldap_get_entries($ldap, $result_r);
-			
+
 			$i = 0;
 			foreach ($result_u as $index => $result_p)
 			{
-				if ($index === 'count' or $index === 'dn' or $result_p['phpgwaccountvisible'][0] == '-1')
+				if ($index === 'count' or $index === 'dn' or (!$this->external and $result_p['phpgwaccountvisible'][0] == '-1'))
 				{
 					continue;
 				}
-				
+
 				foreach ($trans_f as $orig => $trans)
 				{
@@ -178,23 +209,23 @@
 				$i++;
 			}
-			
+
 			return $return;
 		}
-		
+
 		/*
-		
+
 			@function translate_fields
 			@abstract Return the LDAP objectClass fields that corresponds to the
 				specified parameter fields
 			@author Raphael Derosso Pereira
-			
+
 			@param array $fields The fields in the standard ContactCenter format
 			@param array $rules The rules
-		
+
 		*/
 		function translate_fields ( $fields, &$restric_fields )
 		{
 			$return = array();
-			
+
 			$i = 0;
 			foreach ($fields as $field)
@@ -204,12 +235,13 @@
 					continue;
 				}
-				
+
 				if (!is_array($this->trans_table[$field]))
 				{
 					$reference = $this->trans_table[$field];
-					
+
 					reset($restric_fields);
 					while(list(,$field_r) = each($restric_fields))
 					{
+
 						if ($field_r['field'] === $reference and array_key_exists($field_r['value'], $this->trans_table[$reference]))
 						{
@@ -220,4 +252,5 @@
 				else
 				{
+
 					if (!is_array($return[$field]))
 					{
@@ -230,22 +263,22 @@
 				}
 			}
-			
+
 			if (count($return))
 			{
 				return $return;
 			}
-			
+
 			return false;
 		}
-		
+
 		/*
-		
+
 			@function process_restrictions
 			@abstract Returns a LDAP filter string that corresponds to the
 				specified restriction rules
 			@author Raphael Derosso Pereira
-			
+
 			@param string $rules The restriction rules
-		
+
 		*/
 		function process_restrictions( $rules, &$trans_table, $join_type='&' )
@@ -255,5 +288,5 @@
 				return null;
 			}
-			
+
 			foreach($rules as $rule_i => $rule)
 			{
@@ -267,13 +300,13 @@
 								$join = '|';
 								break;
-								
+
 							case 'AND':
 								$join = '&';
 								break;
-								
+
 							case 'NOT':
 								$join = '!';
 								break;
-								
+
 							default:
 								$join = $join_type;
@@ -281,5 +314,5 @@
 						$return_t[] = $this->process_restrictions($rule['sub_branch'], $trans_table, $join);
 						break;
-						
+
 					case '=':
 						if (array_key_exists($rule['field'], $trans_table))
@@ -292,6 +325,6 @@
 						}
 						break;
-					
-					case '!=':	
+
+					case '!=':
 						if (array_key_exists($rule['field'], $trans_table))
 						{
@@ -303,5 +336,5 @@
 						}
 						break;
-					
+
 					case '<=':
 					case '<':
@@ -315,5 +348,5 @@
 						}
 						break;
-					
+
 					case '>':
 					case '>=':
@@ -327,5 +360,5 @@
 						}
 						break;
-						
+
 					case 'NULL':
 						if (array_key_exists($rule['field'], $trans_table))
@@ -338,5 +371,5 @@
 						}
 						break;
-					
+
 					case 'IN':
 						if (array_key_exists($rule['field'], $trans_table))
@@ -358,5 +391,5 @@
 							$value_1 = strtoupper(str_replace('%', '*', $rule['value']));
 							$value_2 = strtolower($value_1);
-							
+
 							foreach($trans_table[$rule['field']] as $field)
 							{
@@ -367,10 +400,10 @@
 						}
 						break;
-						
+
 */					case 'LIKE':
 						if (array_key_exists($rule['field'], $trans_table))
 						{
 							$value = str_replace('%', '*', $rule['value']);
-							
+
 							foreach($trans_table[$rule['field']] as $field)
 							{
@@ -380,5 +413,5 @@
 						}
 						break;
-						
+
 					case 'NOT NULL':
 						if (array_key_exists($rule['field'], $trans_table))
@@ -391,5 +424,5 @@
 						}
 						break;
-					
+
 					case 'NOT IN':
 						if (array_key_exists($rule['field'], $trans_table))
@@ -411,5 +444,5 @@
 							$value_1 = strtoupper(str_replace('%', '*', $rule['value']));
 							$value_2 = strtolower($value_1);
-							
+
 							foreach($trans_table[$rule['field']] as $field)
 							{
@@ -425,5 +458,5 @@
 						{
 							$value = str_replace('%', '*', $rule['value']);
-							
+
 							foreach($trans_table[$rule['field']] as $field)
 							{
@@ -435,5 +468,5 @@
 				}
 			}
-			
+
 			if (count($return_t))
 			{
@@ -453,12 +486,12 @@
 
 		/*!
-		
+
 			@function get_restrictions_without_branch
 			@abstract Returns an array containing the restrictions ignoring the
 				branches
 			@author Raphael Derosso Pereira
-			
+
 			@param array $restrictions The restrictions
-		
+
 		*/
 		function get_restrictions_without_branch(&$restrictions)
@@ -468,7 +501,7 @@
 				return null;
 			}
-			
+
 			$fields = array();
-			
+
 			foreach ($restrictions as $restrict_data)
 			{
@@ -478,7 +511,7 @@
 						$fields = array_merge($fields, $this->get_restrictions_without_branch($restrict_data['sub_branch']));
 						break;
-						
+
 					case '=':
-					case '!=':	
+					case '!=':
 					case '<=':
 					case '<':
@@ -495,35 +528,35 @@
 						array_push($fields, $restrict_data);
 						break;
-						
+
 					default:
-						exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']);					
-				}
-			}
-			
+						exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']);
+				}
+			}
+
 			return $fields;
 		}
-		
-		
+
+
 		/*********************************************************************\
 		 *                        Methods to Get Data                        *
 		\*********************************************************************/
-		
-	
+
+
 		/*!
-		
+
 		 @function get_single_entry
 		 @abstract Returns all information requested about one contact
 		 @author Raphael Derosso Pereira
-		     
+
 		 @param integer $id_contact The contact ID
 		 @param array $fields The array returned by get_fields with true
 		 	on the fields to be taken.
-		 	
+
 		*/
 		function get_single_entry ( $id_contact, $fields )
 		{
-			if (!is_array($fields)) 
-			{
-				if (is_object($GLOBALS['phpgw']->log)) 
+			if (!is_array($fields))
+			{
+				if (is_object($GLOBALS['phpgw']->log))
 				{
 					$GLOBALS['phpgw']->log->message(array(
@@ -531,20 +564,20 @@
 						'line' => __LINE__,
 						'file' => __FILE__));
-					
+
 					$GLOBALS['phpgw']->log->commit();
 				}
-				else 
+				else
 				{
 					exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
 				}
 			}
-			
+
 			$ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true);
-			
+
 			if (!$ldap)
 			{
 				return false;
 			}
-			
+
 			$resource = ldap_read($ldap, $id_contact, 'objectClass='.$this->src_info['obj']);
 			$n_entries = ldap_count_entries($ldap, $resource);
@@ -553,15 +586,15 @@
 				return false;
 			}
-			
+
 			$first_entry = ldap_first_entry($ldap, $resource);
 			$contact = ldap_get_attributes($ldap,$first_entry);
-			if($contact['jpegPhoto']){	
-				$contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); 
+			if($contact['jpegPhoto']){
+				$contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto");
 			}
 
 //			print_r($contact);
-			
+
 		//	$contact_data = $this->fields;
-			
+
 			foreach($fields as $field => $trueness)
 			{
@@ -571,5 +604,5 @@
 					continue;
 				}
-				
+
 				switch ($field)
 				{
@@ -580,5 +613,5 @@
 						$l_fields['department']    = $this->trans_table['contact.business_info.department'];
 						$l_fields['company_notes'] = $this->trans_table['contact.company.company_notes'];
-						
+
 						$contact_data['companies'] = array();
 						foreach($l_fields as $l_field => $l_value)
@@ -588,8 +621,8 @@
 								continue;
 							}
-							
-							$contact_data['companies']['company1'][$l_field] = $contact[$l_value[0]][0];
-						}
-						
+
+							$contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]);
+						}
+
 						if (!(count($contact_data['companies'])))
 						{
@@ -597,5 +630,5 @@
 						}
 						break;
-					
+
 					case 'relations':
 						unset($l_fields);
@@ -604,5 +637,5 @@
 							unset($contact_data['relations']);
 						}
-						
+
 						$contact_data['relations'] = array();
 						if (!is_array($this->trans_table['contact.contact_related.names_ordered']))
@@ -612,5 +645,5 @@
 								continue;
 							}
-							
+
 							$i = 1;
 							foreach($trans as $l_type => $l_type_fields)
@@ -620,11 +653,11 @@
 									continue;
 								}
-								
+
 								$contact_data['relations']['relation'.$i]['type'] = $l_type;
-								$contact_data['relations']['relation'.$i]['names_ordered'] = $contact[$l_type_fields[0]][0];
+								$contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]);
 								$i++;
 							}
 						}
-						
+
 						if (!(count($contact_data['relations'])))
 						{
@@ -632,5 +665,5 @@
 						}
 						break;
-					
+
 					case 'addresses':
 						unset($l_fields);
@@ -661,5 +694,5 @@
 									continue;
 								}
-								
+
 								$i = 1;
 								foreach($trans as $l_type => $l_type_fields)
@@ -669,7 +702,7 @@
 										continue;
 									}
-									
+
 									$contact_data['addresses']['address'.$i]['type'] = $l_type;
-									$contact_data['addresses']['address'.$i][$l_field] = $contact[$l_type_fields[0]][0];
+									$contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]);
 									$i++;
 								}
@@ -677,8 +710,8 @@
 							else
 							{
-								$contact_data['addresses']['address1'][$l_field] = $contact[$l_value[0]][0];
-							}
-						}
-						
+								$contact_data['addresses']['address1'][$l_field] = utf8_decode($contact[$l_value[0]][0]);
+							}
+						}
+
 						if (!(count($contact_data['addresses'])))
 						{
@@ -686,5 +719,5 @@
 						}
 						break;
-					
+
 					case 'connections':
 	                    $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
@@ -707,5 +740,5 @@
 									continue;
 								}
-								
+
 								$i = 1;
 								foreach($trans as $l_type => $l_type_fields)
@@ -715,5 +748,5 @@
 										continue;
 									}
-									
+
 									switch ($l_type)
 									{
@@ -726,5 +759,5 @@
 									}
 									$contact_data['connections']['connection'.$i]['type'] = $l_type;
-									$contact_data['connections']['connection'.$i][$l_field] = $contact[$l_type_fields[0]][0];
+									$contact_data['connections']['connection'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]);
 									$i++;
 								}
@@ -732,8 +765,8 @@
 							else
 							{
-								$contact_data['connections']['connection1'][$l_field] = $contact[$l_value[0]][0];
-							}
-						}
-						
+								$contact_data['connections']['connection1'][$l_field] = utf8_decode($contact[$l_value[0]][0]);
+							}
+						}
+
 						if (!(count($contact_data['connections'])))
 						{
@@ -741,5 +774,5 @@
 						}
 						break;
-					
+
 					case 'prefix':
 						unset($l_fields);
@@ -750,8 +783,8 @@
 							continue;
 						}
-						
-						$contact_data['prefix'] = $contact[$l_fields[0]][0];
-						break;
-						
+
+						$contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]);
+						break;
+
 					case 'suffix':
 						unset($l_fields);
@@ -762,8 +795,8 @@
 							continue;
 						}
-						
-						$contact_data['suffix'] = $contact[$l_fields[0]][0];
-						break;
-						
+
+						$contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]);
+						break;
+
 					case 'status':
 						unset($l_fields);
@@ -774,8 +807,8 @@
 							continue;
 						}
-						
-						$contact_data['status'] = $contact[$l_fields[0]][0];
-						break;
-						
+
+						$contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]);
+						break;
+
 						case 'photo':
 						unset($l_fields);
@@ -786,7 +819,7 @@
 							continue;
 						}
-						
+
 						$contact_data['photo'] = $contact[$l_fields[0]][0];
-						break;											
+						break;
 
 					default:
@@ -798,27 +831,360 @@
 							continue;
 						}
-						
+
 						if(count($contact[$l_fields[0]]) > 1)
-							$contact_data[$field] = $contact[$l_fields[0]];
+						{
+							$tmp = array();
+							foreach ($contact[$l_fields[0]] as $i => $j)
+							{
+								$tmp["$i"] = utf8_decode($j);
+							}
+							//$contact_data[$field] = $contact[$l_fields[0]];
+							$contact_data[$field] = $tmp;
+						}
 						else
-							$contact_data[$field] = $contact[$l_fields[0]][0];
-
-						break;
-				}
-			}
-			
+							$contact_data[$field] = utf8_decode($contact[$l_fields[0]][0]);
+
+						break;
+				}
+			}
+
 			if (!is_array($contact_data))
 			{
 				return false;
 			}
-			
+
 			return $contact_data;
 		}
-		
+
+		/*!
+
+		 @function get_all_entries
+		 @abstract Returns all information requested about a bunch of contacts, usually a page
+		 @author Raphael Derosso Pereira
+		 @author Mário César Kolling
+
+		 @param string $filter Filter (returned by generate_filter).
+		 @param array $fields The array returned by get_fields with true
+		 	on the fields to be taken.
+
+		*/
+		function get_all_entries($filter, $fields)
+		{
+			if (!is_array($fields))
+			{
+				if (is_object($GLOBALS['phpgw']->log))
+				{
+					$GLOBALS['phpgw']->log->message(array(
+						'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.',
+						'line' => __LINE__,
+						'file' => __FILE__));
+
+					$GLOBALS['phpgw']->log->commit();
+				}
+				else
+				{
+					exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
+				}
+			}
+
+			$ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true);
+
+			if (!$ldap)
+			{
+				return false;
+			}
+
+			$resource = @ldap_search($ldap, $this->src_info['dn'], $filter);
+			$n_entries = @ldap_count_entries($ldap, $resource);
+
+			ldap_sort($ldap, $resource, 'cn');
+
+			if ( $n_entries < 1)
+			{
+				return false;
+			}
+
+			$contacts = array();
+
+			for ($entry = ldap_first_entry($ldap, $resource);
+				 $entry != false;
+				 $entry = ldap_next_entry($ldap, $entry))
+			{
+				$contact = ldap_get_attributes($ldap,$entry);
+				if($contact['jpegPhoto']){
+					$contact['jpegPhoto'] = ldap_get_values_len ($ldap, $entry, "jpegPhoto");
+				}
+
+				foreach($fields as $field => $trueness)
+				{
+					if (!$trueness)
+					{
+						//unset($contact_data[$field]);
+						continue;
+					}
+
+					switch ($field)
+					{
+						case 'companies':
+							unset($l_fields);
+							$l_fields['company_name']  = $this->trans_table['contact.company.company_name'];
+							$l_fields['title']         = $this->trans_table['contact.business_info.title'];
+							$l_fields['department']    = $this->trans_table['contact.business_info.department'];
+							$l_fields['company_notes'] = $this->trans_table['contact.company.company_notes'];
+
+							///Relaciona o array com o atributo 'employeeNumber' do RHDS
+							$l_fields['empNumber']     = $this->trans_table['contact.business_info.empNumber'];
+
+							$contact_data['companies'] = array();
+							foreach($l_fields as $l_field => $l_value)
+							{
+								if (!( $contact[$l_value[0]][0]))
+								{
+									continue;
+								}
+
+								$contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]);
+							}
+
+							if (!(count($contact_data['companies'])))
+							{
+								unset($contact_data['companies']);
+							}
+							break;
+
+						case 'relations':
+							unset($l_fields);
+							if (!$this->trans_table['contact.contact_related.names_ordered'])
+							{
+								unset($contact_data['relations']);
+							}
+
+							$contact_data['relations'] = array();
+							if (!is_array($this->trans_table['contact.contact_related.names_ordered']))
+							{
+								if (!($trans = $this->trans_table[$this->trans_table['contact.contact_related.names_ordered']]))
+								{
+									continue;
+								}
+
+								$i = 1;
+								foreach($trans as $l_type => $l_type_fields)
+								{
+									if (!($contact[$l_type_fields[0]][0]))
+									{
+										continue;
+									}
+
+									$contact_data['relations']['relation'.$i]['type'] = $l_type;
+									$contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]);
+									$i++;
+								}
+							}
+
+							if (!(count($contact_data['relations'])))
+							{
+								unset($contact_data['relations']);
+							}
+							break;
+
+						case 'addresses':
+							unset($l_fields);
+							$l_fields['address1'] = $this->trans_table['contact.address.address1'];
+					 		$l_fields['address2'] = $this->trans_table['contact.address.address2'];
+					 		$l_fields['complement'] = $this->trans_table['contact.address.complement'];
+					 		$l_fields['address_other'] = $this->trans_table['contact.address.address_other'];
+							$l_fields['postal_code'] = $this->trans_table['contact.address.postal_code'];
+					 		$l_fields['po_box'] = $this->trans_table['contact.address.po_box'];
+					 		$l_fields['id_city'] = $this->trans_table['contact.address.city.id_city'];
+							$l_fields['city_name'] = $this->trans_table['contact.address.city.city_name'];
+							$l_fields['city_timezone'] = $this->trans_table['contact.address.city.city_timezone'];
+							$l_fields['city_geo_location'] = $this->trans_table['contact.address.city.city_geo_location'];
+							$l_fields['id_state'] = $this->trans_table['contact.address.city.state.id_state'];
+							$l_fields['state_name'] = $this->trans_table['contact.address.city.state.state_name'];
+							$l_fields['state_symbol'] = $this->trans_table['contact.address.city.state.state_symbol'];
+							$l_fields['id_country'] = $this->trans_table['contact.address.city.country.id_country'];
+							$l_fields['country_name'] = $this->trans_table['contact.address.city.country.country_name'];
+					 		$l_fields['address_is_default'] = $this->trans_table['contact.address.address_is_default'];
+
+							$contact_data['addresses'] = array();
+							foreach($l_fields as $l_field => $l_value)
+							{
+								if (!is_array($l_value))
+								{
+									if (!($trans = $this->trans_table[$l_value]))
+									{
+										continue;
+									}
+
+									$i = 1;
+									foreach($trans as $l_type => $l_type_fields)
+									{
+										if (!($contact[$l_type_fields[0]][0]))
+										{
+											continue;
+										}
+
+										$contact_data['addresses']['address'.$i]['type'] = $l_type;
+										$contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]);
+										$i++;
+									}
+								}
+								else
+								{
+									$contact_data['addresses']['address1'][$l_field] = utf8_decode($contact[$l_value[0]][0]);
+								}
+							}
+
+							if (!(count($contact_data['addresses'])))
+							{
+								unset($contact_data['addresses']);
+							}
+							break;
+
+						case 'connections':
+		                    $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
+		                    if (!is_array($preferences))
+		                    {
+								$preferences['personCardEmail'] = 1;
+								$preferences['personCardPhone'] = 2;
+							}
+							unset($l_fields);
+					 		$l_fields['connection_name'] = $this->trans_table['contact.connection.connection_name'];
+					 		$l_fields['connection_value'] = $this->trans_table['contact.connection.connection_value'];
+
+							$contact_data['connections'] = array();
+							foreach($l_fields as $l_field => $l_value)
+							{
+								if (!is_array($l_value))
+								{
+									if (!($trans = $this->trans_table[$l_value]))
+									{
+										continue;
+									}
+
+									$i = 1;
+									foreach($trans as $l_type => $l_type_fields)
+									{
+										if (!($contact[$l_type_fields[0]][0]))
+										{
+											continue;
+										}
+
+										switch ($l_type)
+										{
+											case 'email':
+											$contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardEmail'];
+											break;
+
+											default:
+											$contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardPhone'];
+										}
+										$contact_data['connections']['connection'.$i]['type'] = $l_type;
+										$contact_data['connections']['connection'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]);
+										$i++;
+									}
+								}
+								else
+								{
+									$contact_data['connections']['connection1'][$l_field] = utf8_decode($contact[$l_value[0]][0]);
+								}
+							}
+
+							if (!(count($contact_data['connections'])))
+							{
+								unset($contact_data['connections']);
+							}
+							break;
+
+						case 'prefix':
+							unset($l_fields);
+							$l_fields = $this->trans_table['contact.prefixes.prefix'];
+							if (!$l_fields or !$contact[$l_fields[0]][0])
+							{
+								unset($contact_data['prefix']);
+								continue;
+							}
+
+							$contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]);
+							break;
+
+						case 'suffix':
+							unset($l_fields);
+							$l_fields = $this->trans_table['contact.suffixes.suffix'];
+							if (!$l_fields or !$contact[$l_fields[0]][0])
+							{
+								unset($contact_data['suffix']);
+								continue;
+							}
+
+							$contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]);
+							break;
+
+						case 'status':
+							unset($l_fields);
+							$l_fields = $this->trans_table['contact.status.status_name'];
+							if (!$l_fields or !$contact[$l_fields[0]][0])
+							{
+								unset($contact_data['status']);
+								continue;
+							}
+
+							$contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]);
+							break;
+
+							case 'photo':
+							unset($l_fields);
+							$l_fields = $this->trans_table['contact.photo'];
+							if (!$l_fields or !$contact[$l_fields[0]][0])
+							{
+								unset($contact_data['photo']);
+								continue;
+							}
+
+							$contact_data['photo'] = $contact[$l_fields[0]][0];
+							break;
+
+						default:
+							unset($l_fields);
+							$l_fields = $this->trans_table['contact.'.$field];
+							if (!$l_fields or !$contact[$l_fields[0]][0])
+							{
+								unset($contact_data[$field]);
+								continue;
+							}
+
+							if(count($contact[$l_fields[0]]) > 1)
+							{
+								$tmp = array();
+								foreach ($contact[$l_fields[0]] as $i => $j)
+								{
+									$tmp["$i"] = utf8_decode($j);
+								}
+								//$contact_data[$field] = $contact[$l_fields[0]];
+								$contact_data[$field] = $tmp;
+							}
+							else
+								$contact_data[$field] = utf8_decode($contact[$l_fields[0]][0]);
+
+							break;
+
+					}
+				}
+
+				if (is_array($contact_data))
+				{
+					$contacts[ldap_get_dn($ldap, $entry)] = $contact_data;
+				}
+
+			}
+
+			return $contacts;
+		}
+
 		function get_multiple_entries ( $id_contacts, $fields, $other_data = false )
 		{
 			if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data)))
 			{
-				if (is_object($GLOBALS['phpgw']->log)) 
+				if (is_object($GLOBALS['phpgw']->log))
 				{
 					$GLOBALS['phpgw']->log->message(array(
@@ -826,5 +1192,5 @@
 						'line' => __LINE__,
 						'file' => __FILE__));
-					
+
 					$GLOBALS['phpgw']->log->commit();
 				}
@@ -833,18 +1199,56 @@
 				}
 			}
-			
+
 			$contacts = array();
-	
+
 			if ($other_data)
 			{
 				//TODO
 			}
-	
-			foreach ($id_contacts as $id)
-			{
-				$contacts[$id] = $this->get_single_entry($id,$fields);
-			}
-			
-			return $contacts;
+
+			$filter = $this->generate_filter($id_contacts);
+
+			//$teste = $this->get_all_entries($filter, $fields);
+
+			return $this->get_all_entries($filter, $fields);
+		}
+
+		function generate_filter($id_contacts)
+		{
+			if (($size = count($id_contacts)))
+			{
+				$filter = '(&(objectClass='.$this->src_info['obj'] .  ')(|';
+				for ($i = 0; $i < $size; $i++)
+				{
+
+					/*
+					 * Não utiliza mais a função ldap_explode, usa a expressão regular a seguir para pegar o primeiro
+					 * componente da dn
+					 */
+					preg_match('/^(\w*=[^,]*),.*$/', $id_contacts[$i], $cn);
+
+    				/*
+    				 * Adicionados os str_replace para adicionar caracteres de escape em frente aos caracteres '(' e ')',
+    				 * posteriormente poderá ser necessário substituir por uma expressão regular mais genérica.
+    				 */
+					if ($cn[1])
+					{
+						/*
+						 * Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada
+						 * pela função ldap_explode_dn(). Talvez seja necessário utilizar esta tradução em outros lugares,
+						 * neste caso é mais apropriado colocar dentro de uma função.
+						 */
+						//foreach($cn as $key=>$value){
+	          			//	$cn[$key]=preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value);
+	    				//}
+
+						$filter .= '(' . str_replace(')', '\)', str_replace('(','\(',$cn[1])) . ')';
+					}
+				}
+				$filter .= '))';
+			}
+
+			return $filter;
+
 		}
 
@@ -876,60 +1280,60 @@
 			return null;
 		}
-		
+
 		function get_relations ($id_contact,$extra=false)
 		{
 		}
-		
+
 		function get_addresses ( $id_contact,$extra=false )
 		{
 		}
-		
+
 		function get_connections ( $id_contact,$extra=false )
 		{
 		}
-		
+
 		function get_companies ( $id_contact, $extra=false )
 		{
 		}
-		
+
 		function get_all_prefixes (  )
 		{
 		}
-		
+
 		function get_all_suffixes (  )
 		{
 		}
-		
+
 		function get_all_status (  )
 		{
 		}
-		
+
 		function get_all_relations_types (  )
 		{
 		}
-		
+
 		function get_all_addresses_types (  )
 		{
 		}
-		
+
 		function get_all_connections_types (  )
 		{
 		}
-		
+
 		function get_vcard ( $id_contact )
 		{
 		}
-		
-		
-		
-		
+
+
+
+
 		function get_global_tree ( $root )
 		{
 		}
-	
+
 		function get_actual_brach (  )
 		{
 		}
-	
+
 		function set_actual_branch ( $branch )
 		{
Index: /trunk/contactcenter/inc/class.ThreadInstance.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.ThreadInstance.inc.php	(revision 284)
+++ /trunk/contactcenter/inc/class.ThreadInstance.inc.php	(revision 284)
@@ -0,0 +1,55 @@
+<?php
+	/***********************************************************************************\
+	* eGroupWare - Contacts Center                                              		*
+	* http://www.egroupware.org                                                 		*
+	* Written by:                                                               		*
+	*  - Brian W. Bosh from	Multi-threading strategies in PHP at						*
+	* http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html	*
+	* Adapted by:																		*
+	*  - Mário César Kolling <mario.kolling@serpro.gov.br>								*
+	* ----------------------------------------------------------------------------------*
+	*  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.                                               		*
+	\***********************************************************************************/
+
+	set_time_limit (0);
+	require 'ThreadUtility.inc.php';
+
+	/*
+	 * A class that is extended by the new php process and deals with communication at the new php process side
+	 */
+
+	class ThreadInstance {
+		var $stdin;
+		var $stdout;
+
+		function setup() {
+			$this->stdin = fopen ("php://stdin", "r");
+			$this->stderr = fopen ("php://stderr", "w");
+			stream_set_blocking ($this->stdin, false);
+		}
+		function getCommand() {
+				return $this->getLine(true);
+		}
+		function response ($status, $data) {
+			response ($status, $data);
+		}
+		function getLine ($wait = false) {
+			if ($wait) {
+				$buffer = "";
+				while (!strlen($buffer)) {
+					$buffer .= fgets ($this->stdin, 1024);
+				}
+			} else {
+				$buffer = fgets ($this->stdin, 1024);
+			}
+			return trim($buffer);
+		}
+		function debug ($text) {
+			fwrite ($this->stderr, $text);
+		}
+	}
+
+?>
Index: /trunk/contactcenter/inc/class.so_contact.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.so_contact.inc.php	(revision 203)
+++ /trunk/contactcenter/inc/class.so_contact.inc.php	(revision 284)
@@ -110,14 +110,4 @@
 				'is_global'		=> array(
 					'name'		=> 'is_global',
-					'type'		=> false,
-					'state'		=> 'empty',
-					'value'		=> false),
-				'last_status'		=> array(
-					'name'		=> 'last_status',
-					'type'		=> false,
-					'state'		=> 'empty',
-					'value'		=> false),
-				'last_update'		=> array(
-					'name'		=> 'last_update',
 					'type'		=> false,
 					'state'		=> 'empty',
Index: /trunk/contactcenter/inc/class.bo_people_catalog.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_people_catalog.inc.php	(revision 203)
+++ /trunk/contactcenter/inc/class.bo_people_catalog.inc.php	(revision 284)
@@ -1417,6 +1417,4 @@
 			if ($altered)
 			{
-				$contact->set_field("last_status", 'U');
-				$contact->set_field("last_update",time()."000");
 				return $contact->commit();
 			}
Index: /trunk/contactcenter/inc/class.ui_api.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.ui_api.inc.php	(revision 203)
+++ /trunk/contactcenter/inc/class.ui_api.inc.php	(revision 284)
@@ -18,14 +18,14 @@
 	 *
 	 */
-  
+
 	class ui_api
 	{
 		var $commons;
 		var $commons_loaded = false;
-		
+
 		function ui_api()
 		{
 			$preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
-			
+
 			if (!is_array($preferences))
 			{
@@ -33,17 +33,15 @@
 				//$preferences['personCardPhone'] = 2;
 			}
-			
-			//$template_dir = PHPGW_SERVER_ROOT . '/contactcenter/templates/default/';
-			//$template = CreateObject('phpgwapi.Template',$template_dir);
-			$template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
+
+			$template_dir = PHPGW_SERVER_ROOT . '/contactcenter/templates/default/';
+			$template = CreateObject('phpgwapi.Template',$template_dir);
 
 			$template->set_file(array('api' => 'api_common.tpl'));
-			
+
 			$template->set_var('cc_email_id_type', $preferences['personCardEmail']);
-			
-			
+
 			/* Messages */
 			$template->set_var('cc_msg_err_invalid_catalog',lang('Unavailable or empty Catalog'));
-			$template->set_var('cc_msg_err_contacting_server',lang('Couldn\'t contact server or server response is invalid. Contact Admin.'));
+			$template->set_var('cc_msg_err_contacting_server',lang('Couldn\'t contact server or server response is invalid.'));
 			$template->set_var('cc_msg_err_timeout',lang('Operation Timed Out.'));
 			$template->set_var('cc_msg_err_serialize_data_unknown',lang('Data to be serialized is of unknown type!'));
@@ -77,5 +75,5 @@
 			$template->set_var('cc_js_djswin', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/js/dJSWin/dJSWin.js');
 			$template->set_var('cc_js_catalog_tree', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_tree.js');
-			
+
 			$template->parse('out','api');
 
@@ -83,5 +81,5 @@
 			$this->commons_loaded = false;
 		}
-		
+
 		/* DEPRECTED! Use get_email_win() instead */
 		function ui_get_email_win()
@@ -93,10 +91,10 @@
 		{
 			//$search = $this->ui_get_search_win();
-			
+
 			$template_dir = PHPGW_SERVER_ROOT . '/contactcenter/templates/default/';
 			$template = CreateObject('phpgwapi.Template', $template_dir);
 
 			$template->set_file(array('email_win' => 'email_win.tpl'));
-			
+
 			if (!$this->commons_loaded)
 			{
@@ -108,17 +106,17 @@
 				$template->set_var('cc_api', '');
 			}
-			
+
 			//$template->set_var('cc_search_win', $search);
 			$template->set_var('cc_js_search', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_search.js');
-			
+
 			$template->set_var('cc_email_id_type', $search);
-			
+
 			$template->set_var('cc_email_win_title',lang('Contact Center').' - '.lang('Catalog Entries Emails'));
 			$template->set_var('cc_email_status',lang('Status').':');
 			$template->set_var('cc_email_search_text',lang('Search').'...');
-			
+
 			$template->set_var('cc_choose_catalogue',lang('Choose a catalogue').'...');
 			$template->set_var('cc_choose_ordinance',lang('Choose a ordinance').'...');
-			
+
 			$template->set_var('cc_btn_to_add',lang('To').' >>');
 			$template->set_var('cc_btn_to_del','<< '.lang('To'));
@@ -132,5 +130,5 @@
 			$template->set_var('cc_btn_ok',lang('Ok'));
 			$template->set_var('cc_btn_cancel',lang('Cancel'));
-			
+
 			$template->set_var('cc_label_to',lang('To').':');
 			$template->set_var('cc_label_cc',lang('Cc').':');
@@ -140,9 +138,9 @@
 			$template->set_var('cc_label_catalogue_type',lang('Type Of Catalogue').':');
 			$template->set_var('cc_label_ordinance_type',lang('Type Of Ordinace').':');
-			
+
 			$template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images');
-			
+
 			$template->set_var('cc_js_email_win', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_email_win.js');
-			
+
 			$template->parse('out','email_win');
 
@@ -161,5 +159,5 @@
 
 			$template->set_file(array('search' => 'search_win.tpl'));
-			
+
 			if (!$this->commons_loaded)
 			{
@@ -171,5 +169,5 @@
 				$template->set_var('cc_api', '');
 			}
-			
+
 			$template->set_var('cc_search_title',lang('Contact Center - Search for Catalog Entries'));
 			$template->set_var('cc_search_minimize',lang('Minimize'));
@@ -180,9 +178,9 @@
 			$template->set_var('cc_search_go',lang('Go'));
 			$template->set_var('cc_search_cancel',lang('Cancel'));
-			
+
 			$template->set_var('cc_js_search_win', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_search_win.js');
-			
+
 			$template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images');
-			
+
 			$template->parse('out','search');
 
@@ -205,5 +203,5 @@
 
 			$template->set_file(array('full_add' => 'full_add.tpl'));
-			
+
 			if (!$this->commons_loaded)
 			{
@@ -215,5 +213,5 @@
 				$template->set_var('cc_api', '');
 			}
-			
+
 			$template->set_var('cc_contact_title',lang('Contact Center').' - '.lang('Contacts'));
 
@@ -223,5 +221,5 @@
 			$template->set_var('cc_msg_type_city',lang('Type new city here').'...');
 			/* End Messages */
-			
+
 			/* Contact */
 			$template->set_var('cc_contact_save',lang('Save'));
@@ -232,12 +230,9 @@
 			$template->set_var('cc_contact_addrs',lang('Addresses'));
 			$template->set_var('cc_contact_conns',lang('Connections'));
-			$template->set_var('emails_telephones', lang("E-Mails and Telephones"));
-			$template->set_var('cc_default', lang("Default"));
-
 			/* End Contact */
-			
+
 			/* Contact - Personal Data */
 			$dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-		
+
 			$j = 0;
 			for ($i = 0; $i < 5; $i+=2)
@@ -262,9 +257,9 @@
 				$j++;
 			}
-			
+
 			$template->set_var('cc_pd_birth_size_0', "{$date[0]['size']}");
 			$template->set_var('cc_pd_birth_size_1', "{$date[1]['size']}");
 			$template->set_var('cc_pd_birth_size_2', "{$date[2]['size']}");
-			
+
 			$template->set_var('cc_pd_birthdate_0', "{$date[0]['name']}");
 			$template->set_var('cc_pd_birthdate_1', "{$date[1]['name']}");
@@ -273,5 +268,5 @@
 			$template->set_var('cc_pd_select_photo_b', lang('Browse').'...');
 			$template->set_var('cc_form_photo_src', 'photo_form.html');
-			
+
 			$template->set_var('cc_pd_select_photo',lang('Select Photo'));
 			$template->set_var('cc_pd_alias',lang('Alias'));
@@ -291,5 +286,5 @@
 			$template->set_var('cc_pd_female',lang('Female'));
 			/* End Contact - Personal Data */
-			
+
 			/* Contact - Addresses */
 			$template->set_var('cc_addr_types',lang('Type of Address'));
@@ -315,20 +310,15 @@
 			$template->set_var('cc_available',lang('Available'));
 			/* End Contact - Addresses */
-			
-			
+
 			/* Contact - Connections */
 			$template->set_var('cc_conn_type',lang('Type of Connection'));
 			$template->set_var('cc_conn_name',lang('Connection Name'));
 			$template->set_var('cc_conn_value',lang('Connection Value'));
-			
+
 			$template->set_var('cc_new_same_type',lang('New from the same Type').'...');
-			
+
 			$template->set_var('cc_conn_type_none',lang('Choose Type of Connection').'...');
 			/* End Contact - Connections */
 
-			$template->set_var('email', lang("E-Mail"));
-			$template->set_var('telephone', lang("Telephone"));
-			$template->set_var('choose_email_telephone', lang("Choose 'E-Mail' or 'Telephone'"));
-
 			$template->parse('out_full', 'full_add');
 
@@ -342,5 +332,5 @@
 
 			$template->set_file(array('quickAdd' => 'quickAddPlugin.tpl'));
-			
+
 			if (!$this->commons_loaded)
 			{
@@ -352,5 +342,5 @@
 				$template->set_var('cc_api', '');
 			}
-			
+
 			$template->set_var('ccQAPluginFile', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/ccQuickAdd-plugin.js');
 
@@ -360,13 +350,13 @@
 			$nFields = 5;
 			$fields = array(
-				lang('Alias'), 
-				lang('Given Names'), 
-				lang('Family Names'), 
+				lang('Alias'),
+				lang('Given Names'),
+				lang('Family Names'),
 				lang('Phone'),
 				lang('Email')
 			);
-			
+
 			$template->set_var('ccQAnFields', $nFields);
-			
+
 			$fieldsHTML = '';
 			$fieldsTop = 10;
@@ -375,5 +365,13 @@
 			{
 				$fieldsHTML .= '<span id="ccQuickAddT'.$i.'" style="position: absolute; top: '.($fieldsTop+$i*$fieldsSpace).'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">'.$fields[$i].':</span>'."\n";
-				$fieldsHTML .= '<input id="ccQuickAddI'.$i.'" type="text" value="" maxlength="50" style="position: absolute; top: '.($fieldsTop+$i*$fieldsSpace).'px; left: 110px; width: 135px;">'."\n";
+				if ($i == 0){
+					$fieldsHTML .= '<input id="ccQuickAddI'.$i.'" type="text" value="" maxlength="30" style="position: absolute; top: '.($fieldsTop+$i*$fieldsSpace).'px; left: 110px; width: 135px;">'."\n";
+				}
+				else if ($i == 4){
+					$fieldsHTML .= '<input id="ccQuickAddI'.$i.'" type="text" value="" maxlength="100" style="position: absolute; top: '.($fieldsTop+$i*$fieldsSpace).'px; left: 110px; width: 135px;">'."\n";
+				}
+				else {
+					$fieldsHTML .= '<input id="ccQuickAddI'.$i.'" type="text" value="" maxlength="50" style="position: absolute; top: '.($fieldsTop+$i*$fieldsSpace).'px; left: 110px; width: 135px;">'."\n";
+				}
 			}
 
@@ -381,8 +379,8 @@
 			$template->set_var('ccQAWinHeight', ($i+1)*$fieldsSpace+$fieldsTop);
 			$template->set_var('ccQAFunctionsTop', ($fieldsTop+$i*$fieldsSpace).'px');
-			
+
 			/* Images Dir */
 			$template->set_var('ccQACardImgRoot', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/');
-			
+
 			/* Texts */
 			$template->set_var('ccQATitle', lang('Contact Center').' - '.lang('Quick Add'));
@@ -390,10 +388,10 @@
 			$template->set_var('ccQAClear', lang('Reset'));
 			$template->set_var('ccQACancel', lang('Cancel'));
-			
+
 			$template->parse('out_QA', 'quickAdd');
 
 			return $template->get_var('out_QA');
 		}
-		
+
 		function get_add_group()
 		{
@@ -402,5 +400,5 @@
 
 			$template->set_file(array('addGroup' => 'addGroup.tpl'));
-			
+
 			if (!$this->commons_loaded)
 			{
@@ -410,15 +408,15 @@
 			else
 			{
-				
+
 				$template->set_var('cc_api', '');
 			}
-			
-			$template->set_var('ccAGFile', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/ccAddGroup.js');			
-			$template->set_var('ccAGWinHeightIE', '285');			
+
+			$template->set_var('ccAGFile', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/ccAddGroup.js');
+			$template->set_var('ccAGWinHeightIE', '285');
 			$template->set_var('ccAGWinHeightMO', '335');
-			
+
 			/* Images Dir */
 			$template->set_var('ccAGCardImgRoot', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/');
-			
+
 			/* Texts */
 			$template->set_var('ccAGTitle', lang('Contact Center').' - '.lang('Group Add'));
@@ -426,20 +424,20 @@
 			$template->set_var('ccAGClear', lang('Reset'));
 			$template->set_var('ccAGCancel', lang('Cancel'));
-			$title = '<input type="text" id="title" name="title" value="'.$group['title'].'" size="50" maxlength="50"/>';			
-				
-			$template->set_var('title', $title);												
+			$title = '<input type="text" id="title" name="title" value="'.$group['title'].'" size="50" maxlength="50"/>';
+
+			$template->set_var('title', $title);
 			// set content and label variables.
 			$template->set_var(array(
-						'msg_text' 	=> lang($status),						
-						'txt_title' 	=> lang('Contact Group List'),						
+						'msg_text' 	=> lang($status),
+						'txt_title' 	=> lang('Contact Group List'),
 						'txt_cancel'=> lang('cancel'),
-						'txt_add'=> lang('Add'),						
+						'txt_add'=> lang('Add'),
 						'txt_rem'=> lang('Remove'),
 						'txt_personal_contacts' => lang('Personal Contacts'),
 						'txt_contacts_in_list' => lang("Participants"),
 						'txt_name'	=> lang('Full Name')));
-						
+
 			$template->parse('out_AG', 'addGroup');
-			
+
 			return $template->get_var('out_AG');
 		}
Index: /trunk/contactcenter/inc/class.ui_data.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.ui_data.inc.php	(revision 276)
+++ /trunk/contactcenter/inc/class.ui_data.inc.php	(revision 284)
@@ -14,5 +14,5 @@
   \***************************************************************************/
 
-	
+
 	class ui_data
 	{
@@ -20,8 +20,8 @@
 			'data_manager' => true,
 		);
-		
+
 		var $bo;
 		var $typeContact;
-		
+
 		var $page_info = array(
 			'n_cards'          => 20,
@@ -34,12 +34,12 @@
 			'actual_catalog'   => false
 		);
-		
+
 		/*!
-		
+
 			@function ui_data
 			@abstract The constructor. Sets the initial parameters and loads
 				the data saved in the session
 			@author Raphael Derosso Pereira
-			
+
 		*/
 		function ui_data()
@@ -47,7 +47,11 @@
 			$temp = $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter');
 			$temp2 = $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter');
-			
+
+			//TODO: Achar um modo de descarregar este array da sessï¿œo quando o usuï¿œrio sair da tela do contactcenter.
+			//TODO: Descarregar este array da memï¿œria toda vez que uma nova consulta por letras ou mudanï¿œa de catï¿œlogo for feita.
+			$temp3 = $GLOBALS['phpgw']->session->appsession('ui_data.last_search_ids','contactcenter');
+
 			$this->bo = CreateObject('contactcenter.bo_contactcenter');
-			
+
 			if ($temp)
 			{
@@ -59,5 +63,10 @@
 				$this->all_entries = $temp2;
 			}
-			
+
+			if ($temp3)
+			{
+				$this->last_search_ids = $temp3;
+			}
+
 			if (!$this->page_info['actual_catalog'])
 			{
@@ -65,7 +74,7 @@
 				$this->page_info['actual_catalog'] = $catalogs[0];
 			}
-			
-			$this->page_info['actual_catalog'] =& $this->bo->set_catalog($this->page_info['actual_catalog']);			
-			
+
+			$this->page_info['actual_catalog'] =& $this->bo->set_catalog($this->page_info['actual_catalog']);
+
 			if($this->page_info['actual_catalog']['class'] == 'bo_group_manager')
 				$this -> typeContact = 'groups';
@@ -75,13 +84,13 @@
 
 		/*!
-		
+
 			@function index
 			@abstract Builds the Main Page
 			@author Raphael Derosso Pereira
 			@author Jonas Goes
-			
-		*/		
+
+		*/
 		function index()
-		{	
+		{
 			if(!@is_object($GLOBALS['phpgw']->js))
 			{
@@ -92,11 +101,11 @@
 			$GLOBALS['phpgw']->js->validate_file('venus','jsStructUtil');
 			$GLOBALS['phpgw']->js->validate_file('venus','cssUtil');
-			
+
 //			$GLOBALS['phpgw']->js->set_onload('setTimeout(\'updateCards()\',1000)');
 			$GLOBALS['phpgw']->common->phpgw_header();
-			
+
 			$GLOBALS['phpgw']->template->set_file(array('index' => 'index.tpl'));
 			$GLOBALS['phpgw']->template->set_var('cc_root_dir', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/');
-			
+
 			/* Quick Add */
 			$GLOBALS['phpgw']->template->set_var('cc_qa_alias',lang('Alias').':');
@@ -107,7 +116,6 @@
 			$GLOBALS['phpgw']->template->set_var('cc_qa_save',lang('Save'));
 			$GLOBALS['phpgw']->template->set_var('cc_qa_clear',lang('Clear'));
-			$GLOBALS['phpgw']->template->set_var('cc_qa_close',lang('Close'));
 			/* End Quick Add */
-			
+
 			$cc_css_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/styles/cc.css';
 			$cc_card_image_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/card.png';
@@ -115,10 +123,10 @@
 			$GLOBALS['phpgw']->template->set_var('cc_dtree_css', $cc_dtree_file);
 			$GLOBALS['phpgw']->template->set_var('cc_card_image',$cc_card_image_file);
-			
+
 			$GLOBALS['phpgw']->template->set_var('cc_personal',lang('Personal'));
-			
+
 			$GLOBALS['phpgw']->template->set_var('cc_full_add',lang('Full Add'));
 			$GLOBALS['phpgw']->template->set_var('cc_reset',lang('Reset'));
-			
+
 			$GLOBALS['phpgw']->template->set_var('cc_personal_data',lang('Personal Data'));
 			$GLOBALS['phpgw']->template->set_var('cc_addresses',lang('Addresses'));
@@ -129,5 +137,5 @@
 			$GLOBALS['phpgw']->template->set_var('cc_catalogs',lang('Catalogues'));
 			$GLOBALS['phpgw']->template->set_var('cc_group_add',lang('Group Add'));
-			
+
 			/* Panel */
 			$GLOBALS['phpgw']->template->set_var('cc_panel_new',lang('New').'...');
@@ -135,7 +143,5 @@
 			$GLOBALS['phpgw']->template->set_var('cc_panel_table',lang('Table View'));
 			$GLOBALS['phpgw']->template->set_var('cc_panel_cards',lang('Cards View'));
-			$GLOBALS['phpgw']->template->set_var('cc_btn_import_export', lang('Import/Export'));
-			$GLOBALS['phpgw']->template->set_var('cc_btn_new', lang("New..."));
-			
+
 			$GLOBALS['phpgw']->template->set_var('cc_panel_search_found',lang('Showing found entries'));
 			$GLOBALS['phpgw']->template->set_var('cc_panel_first_page',lang('First Page'));
@@ -145,5 +151,5 @@
 			$GLOBALS['phpgw']->template->set_var('cc_all',lang('all'));
 			/* End Panel */
-			
+
 			/* Messages */
 			$GLOBALS['phpgw']->template->set_var('cc_msg_no_cards',lang('No Cards'));
@@ -160,11 +166,10 @@
 			$GLOBALS['phpgw']->template->set_var('cc_empty',lang('Empty'));
 			/* End Messages */
-			
+
 			$GLOBALS['phpgw']->template->set_var('cc_results',lang('Results'));
 			$GLOBALS['phpgw']->template->set_var('cc_is_my',lang('Is My'));
-			$GLOBALS['phpgw']->template->set_var('cc_ie_personal',lang('Import/Export pesonal contacts'));
 			$GLOBALS['phpgw']->template->set_var('cc_btn_search',lang('Search'));
 			$GLOBALS['phpgw']->template->set_var('cc_add_relation',lang('Add Relation'));
-			$GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations'));			
+			$GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations'));
 			$GLOBALS['phpgw']->template->set_var('cc_msg_group',lang('Group'));
 			$GLOBALS['phpgw']->template->set_var('cc_msg_contact_full',lang('Contact [Full]'));
@@ -174,55 +179,6 @@
 			$GLOBALS['phpgw']->template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images');
 
-			$GLOBALS['phpgw']->template->set_var('cc_msg_import_contacts', lang('Import Contacts'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_export_contacts', lang('Export Contacts'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_expresso_info_csv', lang('The Expresso supports the contacts importation in the CSV file format.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_choose_file_type', lang('Select the file type'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express', lang('Outlook Express'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_outlook2k', lang('Outlook 2000'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_choose_contacts_file', lang('Select the file that contains the contacts to be imported:'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_close_win', lang('Close'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_import_finished', lang('The importation has finished.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_new', lang(' new'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_failure', lang(' failed'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_exists', lang(' were existent'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_show_more_info', lang('show more info'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_clean', lang('Clean'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_invalid_csv', lang('Select a valid CSV file to import your contacts'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_export_csv', lang('Select the format type that you want to export your contacts'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_automatic', lang('Automatic'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_main', lang('Main'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_alternative', lang('Alternative'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_select_email', lang('Select E-Mail'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_new_phone', lang('New Telephone'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_home', lang('Home'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_cellphone', lang('Cellphone'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_work', lang('Work'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_fax', lang('Fax'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_pager', lang('Pager'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_choose_phone', lang('Select the telephone'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_warn_firefox', lang('Warning: Too old version of Firefox'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half1', lang('For this application work correctly</u>'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half2', lang('it\'s necessary to update your Firefox Browser for a new version (version > 1.5) Install now clicking in the link bellow, or if you want to update it later'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_click_close', lang('click Close'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_install_now', lang('Install Now'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_install_new_firefox', lang('Install a new Firefox version'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_moz_thunderbird', lang('Export as Mozilla Thunderbird CSV.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_pt', lang('Export as Outlook Express (Portuguese) CSV.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_en', lang('Export as Outlook Express (English) CSV.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_pt', lang('Export as Outlook 2000 (Portuguese) CSV.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_en', lang('Export as Outlook 2000 (English) CSV.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default_csv', lang('Export as Expresso (Default) CSV.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_copy_to_catalog', lang('Copy to personal catalog.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_add_contact_to_group', lang('You did not add any contact for this group.'));
-			$GLOBALS['phpgw']->template->set_var('cc_msg_fill_field_name', lang('Fill the field Full Name'));
-			
 			$GLOBALS['phpgw']->template->parse('out','index');
-			
+
 			$api = CreateObject('contactcenter.ui_api');
 			$main = $api->get_full_add();
@@ -235,12 +191,12 @@
 		}
 
-		
+
 		/*!
-		
+
 			@function data_manager
-			@abstract Calls the right method and passes to it the right 
+			@abstract Calls the right method and passes to it the right
 				parameters
 			@author Raphael Derosso Pereira
-		
+
 		*/
 		function data_manager()
@@ -251,7 +207,19 @@
 				case 'set_n_cards':
 					return $this->set_n_cards((int)$_GET['ncards']);
-					
+
 				case 'get_cards_data':
-					return $this->get_cards_data($_POST['letter'], $_POST['page'], unserialize(str_replace('\\"','"',$_POST['ids'])));
+
+					$ids = false;
+					// To support ldap catalogs using accentuation
+					if ($_POST['letter'] == 'search' && isset($_POST['data']))
+					{
+						//$ids = utf8_decode($this->search($_POST['data']));
+						$ids = $this->search($_POST['data']);
+					}
+
+					//return $this->get_cards_data($_POST['letter'], $_POST['page'], unserialize(str_replace('\\"','"',$ids)));
+					return $this->get_cards_data($_POST['letter'], $_POST['page'], $ids);
+					//return $this->get_cards_data($_POST['letter'], $_POST['page'], unserialize(str_replace('\\"','"',$_POST['ids'])));
+
 				case 'get_cards_data_get':
 					return $this->get_cards_data($_GET['letter'], $_GET['page'], unserialize(str_replace('\\"','"',$_GET['ids'])));
@@ -261,9 +229,9 @@
 					return $this->get_photo($_GET['id']);
 
-					
+
 				/* Catalog Methods */
 				case 'set_catalog':
 					return $this->set_catalog($_GET['catalog']);
-					
+
 				case 'get_catalog_tree':
 					echo serialize($this->get_catalog_tree($_GET['level']));
@@ -279,14 +247,15 @@
 
 				case 'get_catalog_add_contact':
-					echo serialize($this->get_catalog_add_contact($_POST['id']));
+					// To support ldap catalogs with accentuation
+					echo serialize($this->get_catalog_add_contact(utf8_decode($_POST['id'])));
 					return;
-					
+
 				/* Full Add Methods */
 				case 'get_full_data':
 					return $this->get_full_data($_GET['id']);
-				
+
 				case 'get_group':
 					return $this->get_group_data($_GET['id']);
-					
+
 				case 'get_contact_full_add_const':
 					return $this->get_contact_full_add_const();
@@ -300,25 +269,25 @@
 				case 'get_states':
 					return $this->get_states($_GET['country']);
-					
+
 				case 'get_cities':
 					return $this->get_cities($_GET['country'], $_GET['state'] ? $_GET['state'] : null);
-					
-					
+
+
 				/* Other Methods */
-				case 'quick_add':															
+				case 'quick_add':
 					return $this->quick_add($_POST['add']);
-				
-				case 'add_group':															
+
+				case 'add_group':
 					return $this->add_group($_POST['add']);
-									
+
 				case 'remove_entry':
 					return $this->remove_entry((int)$_GET['remove']);
-				
+
 				case 'remove_all_entries':
 					return $this->remove_all_entries();
 
 				case 'remove_group':
-					 					
-					return $this->remove_group((int)$_GET['remove']);					
+
+					return $this->remove_group((int)$_GET['remove']);
 
 				case 'search':
@@ -357,11 +326,11 @@
 
 		/*!
-		
+
 			@function set_n_cards
 			@abstract Informs the class the number of cards the page can show
 			@author Raphael Derosso Pereira
-			
+
 			@param integer $n_cards The number of cards
-			
+
 		*/
 		function set_n_cards($n_cards)
@@ -372,17 +341,17 @@
 				echo 1;
 			}
-			
+
 			$this->save_session();
 		}
-				
+
 		/*!
-		
+
 			@function set_catalog
 			@abstract Sets the current catalog selected by the user
 			@author Raphael Derosso Pereira
-			
+
 			@param string $id_catalog The sequence of IDs to reach the catalog
 				separated by commas
-		
+
 		*/
 		function set_catalog($id_catalog)
@@ -390,5 +359,5 @@
 			$id_catalog = str_replace('\\"', '"', $id_catalog);
 			$temp =& $this->bo->set_catalog($id_catalog);
-			
+
 			if ($temp)
 			{
@@ -397,7 +366,7 @@
 				$this->page_info['actual_catalog'] =& $temp;
 				$this->save_session();
-				
+
 				$catalog_info = $this->bo->get_branch_by_level($this->bo->catalog_level[0]);
-				
+
 				if ($catalog_info['class'] === 'bo_global_ldap_catalog' ||
 				    $catalog_info['class'] === 'bo_catalog_group_catalog')
@@ -409,5 +378,5 @@
 					$perms = 15;
 				}
-				
+
 				echo serialize(array(
 					'status' => 'ok',
@@ -417,5 +386,5 @@
 				return;
 			}
-			
+
 			echo serialize(array(
 				'status' => 'ok',
@@ -423,15 +392,16 @@
 			));
 		}
-		
-		
+
+
 		/*!
-		
+
 			@function get_catalog_tree
 			@abstract Returns the JS serialized array to used as the tree
 				level
 			@author Raphael Derosso Pereira
-			
-			@param (string) $level The level to be taken 
-		
+			@author Mï¿œrio Cï¿œsar Kolling (error messages and timeout)
+
+			@param (string) $level The level to be taken
+
 		*/
 		function get_catalog_tree($level)
@@ -442,5 +412,5 @@
 
 				$parent = '0';
-				
+
 				if (!($tree = $this->bo->get_catalog_tree($level)))
 				{
@@ -456,5 +426,5 @@
 				$parent = substr($level, 0, $last_dot);
 				$child = substr($level, $last_dot+1, strlen($level));
-			
+
 				if (!($tree[$child] = $this->bo->get_catalog_tree($level)))
 				{
@@ -464,18 +434,48 @@
 					);
 				}
-			}
-			
+				// Deals with timeout and returns the generated message to the browser
+				else if (!empty($tree[$child]['timeout']) && !empty($tree[$child]['msg']))
+				{
+					$tmp = array(
+						'msg'    => $tree[$child]['msg'],
+						'status' => 'fatal'
+					);
+					unset($tree[$child]);
+					return $tmp;
+				}
+			}
+
 			$folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png');
 			$folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png'));
-			
+
+			// Deals with error messages from the server and returns them to the browser
+			if ($tree['msg'])
+			{
+				$msg = $tree['msg'];
+				unset($tree['msg']);
+			}
+
 			$tree_js = $this->convert_tree($tree, $folderImageDir, $parent);
-			
-			return array(
-				'data' => $tree_js,
-				'msg'  => lang('Catalog Tree Successfully taken!'),
-				'status' => 'ok'
-			);
-		}
-		
+
+			// Return status = ok, or else return generated message to the browser
+			if (!$msg)
+			{
+				return array(
+					'data' => $tree_js,
+					'msg'  => lang('Catalog Tree Successfully taken!'),
+					'status' => 'ok'
+				);
+			}
+			else
+			{
+				return array(
+					'data' => $tree_js,
+					'msg'  => $msg,
+					'status' => 'error'
+				);
+
+			}
+		}
+
 /*		function get_catalog_tree($level, $name = 'tree')
 		{
@@ -487,5 +487,5 @@
 				$parent = '0';
 				$child  = '0';
-				
+
 				if (!($tree = $this->bo->get_catalog_tree($level)))
 				{
@@ -498,7 +498,7 @@
 				$parent = substr($level, 0, $last_dot);
 				$child = substr($level, $last_dot+1, strlen($level));
-			
+
 				$tree_js = '';
-				
+
 				if (!($tree[$child] = $this->bo->get_catalog_tree($level)))
 				{
@@ -506,16 +506,16 @@
 				}
 			}
-			
+
 			$folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png');
 			$folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png'));
-			
+
 			$tree_js .= $this->convert_tree($tree, $name, $folderImageDir, $parent);
-			
+
 			return $tree_js;
 		}
-*/		
-		
+*/
+
 		/*!
-		
+
 			@function get_actual_catalog
 			@abstract Returns the actual selected Catalog
@@ -524,7 +524,7 @@
 		*/
 		function get_actual_catalog()
-		{			
+		{
 			$level = $this->bo->get_level_by_branch($this->bo->get_actual_catalog(), $this->bo->tree['branches'], '0');
-			
+
 			if ($level)
 			{
@@ -540,13 +540,13 @@
 			);
 		}
-		
+
 		/*!
-		
+
 			@function get_cards_data
 			@abstract Returns the information that is placed on the cards
 			@author Raphael Derosso Pereira
-			
+
 			@param string $letter The first letter to be searched
-			@param (int)  $page The page to be taken 
+			@param (int)  $page The page to be taken
 			@param (str)  $ids The ids to be taken in case of search
 
@@ -556,12 +556,16 @@
 		function get_cards_data($letter, $page, $ids)
 		{
+
+			// It's an external catalog?
+			$external = $this->bo->is_external($this->page_info['actual_catalog']);
+
 			//echo $page."\n";
 			if ($letter !== 'search' and ($letter != $this->page_info['actual_letter'] or
-			    ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or 
+			    ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or
 			    $this->page_info['changed']))
 			{
 				unset($ids);
 				$this->page_info['changed'] = false;
-				 
+
 				switch ($this->page_info['actual_catalog']['class'])
 				{
@@ -650,7 +654,7 @@
 							);
 						}
-						
+
 						$find_field[0] = array('contact.id_contact','contact.names_ordered');
-						
+
 						$find_other[0] = array(
 							//'offset' => (($page-1)*$this->page_info['n_cards']),
@@ -658,7 +662,11 @@
 							'order'  => 'contact.names_ordered'
 						);
-						
+
 						break;
-					
+
+					//case 'bo_external_ldap_catalog':
+
+					//	break;
+
 					case 'bo_global_ldap_catalog':
 						$field_name = 'id_contact';
@@ -671,32 +679,86 @@
 									'type'  => 'iLIKE',
 									'value' => $letter !== 'all' ? $letter.'%' : '%'
-								)
+								),
+								/*
+								 * Restrict the returned contacts in a "first letter" search
+								 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
+								 * phpgwAccountVisible != -1 and objectClass = inetOrgPerson
+								 */
+								1 => array(
+									'field' => 'contact.object_class',
+									'type'  => '=',
+									'value' => 'phpgwAccount'
+								),
+								2 => array(
+									'field' => 'contact.account_status',
+									'type'  => 'iLIKE',
+									'value' => '%'
+								),
+								3 => array(
+									'field' => 'contact.account_visible',
+									'type'  => '!=',
+									'value' => '-1'
+								),
+								4 => array(
+									'field' => 'contact.object_class',
+									'type'  => '=',
+									'value' => 'inetOrgPerson'
+								),
 							);
-							$find_restric[0][1] =  array(
-									'type'  => 'branch',
-									'value' => 'OR',
-									'sub_branch' => array(
-										0 => array(
-										'field' => 'contact.account_type',
-										'type'  => '=',
-										'value' => 'u'
-										),
-										/*1 => array(
-										'field' => 'contact.account_type',
-										'type'  => '=',
-										'value' => 'g'
-										),*/
-										2 => array(
-										'field' => 'contact.account_type',
-										'type'  => '=',
-										'value' => 'l'
+							// If not external catalog get only phpgwAccountType = u ou l
+							if (!$external)
+							{
+								$find_restric[0][5] =  array(
+										'type'  => 'branch',
+										'value' => 'OR',
+										'sub_branch' => array(
+											0 => array(
+											'field' => 'contact.account_type',
+											'type'  => '=',
+											'value' => 'u'
+											),
+											/*1 => array(
+											'field' => 'contact.account_type',
+											'type'  => '=',
+											'value' => 'g'
+											),*/
+											2 => array(
+											'field' => 'contact.account_type',
+											'type'  => '=',
+											'value' => 'l'
+											)
 										)
-									)
-							);
+								);
+							}
 						}
 						else
 						{
 							$find_restric[0] = array(
+								/*
+								 * Restrict the returned contacts in a "first number" search
+								 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
+								 * phpgwAccountVisible != -1 and objectClass = inetOrgPerson
+								 */
 								0 => array(
+									'field' => 'contact.object_class',
+									'type'  => '=',
+									'value' => 'phpgwAccount'
+								),
+								1 => array(
+									'field' => 'contact.account_status',
+									'type'  => 'iLIKE',
+									'value' => '%'
+								),
+								2 => array(
+									'field' => 'contact.account_visible',
+									'type'  => '!=',
+									'value' => '-1'
+								),
+								3 => array(
+									'field' => 'contact.object_class',
+									'type'  => '=',
+									'value' => 'inetOrgPerson'
+								),
+								4 => array(
 									'type'  => 'branch',
 									'value' => 'OR',
@@ -755,29 +817,46 @@
 								),
 							);
-							$find_restric[0][1] =  array(
-								'type'  => 'branch',
-								'value' => 'OR',
-								'sub_branch' => array(
-									0 => array(
-									'field' => 'contact.account_type',
-									'type'  => '=',
-									'value' => 'u'
-									),
-									/*1 => array(
-									'field' => 'contact.account_type',
-									'type'  => '=',
-									'value' => 'g'
-									),*/
-									2 => array(
-									'field' => 'contact.account_type',
-									'type'  => '=',
-									'value' => 'l'
+							// If not external catalog get only phpgwAccountType = u ou l
+							if (!$external)
+							{
+								$find_restric[0][5] =  array(
+									'type'  => 'branch',
+									'value' => 'OR',
+									'sub_branch' => array(
+										0 => array(
+										'field' => 'contact.account_type',
+										'type'  => '=',
+										'value' => 'u'
+										),
+										/*1 => array(
+										'field' => 'contact.account_type',
+										'type'  => '=',
+										'value' => 'g'
+										),*/
+										2 => array(
+										'field' => 'contact.account_type',
+										'type'  => '=',
+										'value' => 'l'
+										)
 									)
-								)
-							);
+								);
+							}
+
 						}
-						
-						$find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type');
-						
+
+						if (!$external)
+						{
+							// Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
+							// for non-external catalogs, used to restrict the attributes used in filters
+							$find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type',
+								'contact.object_class','contact.account_status','contact.account_visible');
+						}
+						else
+						{
+							// Get only this attributes: dn, cn for external catalogs,
+							// used to restrict the attributes used in filters
+							$find_field[0] = array('contact.id_contact','contact.names_ordered');
+						}
+
 						$find_other[0] = array(
 							//'offset' => (($page-1)*$this->page_info['n_cards']),
@@ -785,12 +864,12 @@
 							'order'  => 'contact.names_ordered'
 						);
-						
+
 						break;
-					
+
 					case 'bo_company_manager':
 						$field_name = 'id_company';
-	
+
 						$find_field[0] = array('company.id_company','company.company_name');
-						
+
 						$find_other[0] = array(
 							//'offset' => (($page-1)*$this->page_info['n_cards']),
@@ -798,5 +877,5 @@
 							'order'  => 'company.company_name'
 						);
-	
+
 						$find_restric[0] = array(
 							0 => array(
@@ -806,13 +885,13 @@
 							)
 						);
-							
+
 						break;
 
 					case 'bo_group_manager':
-					
+
 						$field_name = 'id_group';
-						
+
 						if ($letter !== 'number')	{
-							
+
 							$find_restric[0] = array(
 								0 => array(
@@ -824,45 +903,45 @@
 						}
 						 else {
-							
+
 							$find_restric[0] = array(
 								0 => array(
 											'field' => 'group.title',
 											'type'  => 'LIKE',
-											'value' => '0%'										
+											'value' => '0%'
 								)
-							);						
+							);
 						}
-						
+
 						array_push($find_restric[0],  array(
 											'field' => 'group.owner',
 											'type'  => '=',
-											'value' => $GLOBALS['phpgw_info']['user']['account_id']										
+											'value' => $GLOBALS['phpgw_info']['user']['account_id']
 								)
 						);
-						
-						$find_field[0] = array('group.id_group','group.title','group.short_name');						
+
+						$find_field[0] = array('group.id_group','group.title','group.short_name');
 						$find_other[0] = array(
 							'order'  => 'group.title'
 						);
-						
+
 						break;
-						
+
 					case 'bo_catalog_group_catalog':
 						$this->page_info['actual_entries'] = false;
-						
+
 						$this->page_info['actual_letter'] = $letter;
 						$this->page_info['actual_page'] = 0;
-						
+
 						$this->save_session();
 						$final[0] = 0;
 						$final[1] = $this -> typeContact;
-						echo serialize($final);						
+						echo serialize($final);
 						return;
 
 				}
-				
+
 				$result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0]);
 				$n_entries = count($result);
-				
+
 				if ($n_entries)
 				{
@@ -878,12 +957,12 @@
 				{
 					$this->page_info['actual_entries'] = false;
-					
+
 					$this->page_info['actual_letter'] = $letter;
 					$this->page_info['actual_page'] = 0;
-					
-					$this->save_session();				
+
+					$this->save_session();
 					$final[0] = 0;
 					$final[1] = $this -> typeContact;
-					echo serialize($final);											
+					echo serialize($final);
 					return;
 				}
@@ -894,25 +973,53 @@
 					{
 						$this->page_info['actual_entries'][] = $value[$field_name];
-					} 
-					//print_r($this->page_info['actual_entries']);
-				}
-			}
+					}
+				}
+			}
+//*************************************************************************
 			else if ($letter === 'search')
 			{
-				if (!$ids and $this->page_info['actual_letter'] !== 'search')
-				{
+				//if (!$ids and $this->page_info['actual_letter'] !== 'search')
+				if (!$ids && !$this->last_search_ids)
+				{
+					error_log('!$ids e $this->page_info[\'actual_letter\'] != search');
 					$this->page_info['actual_entries'] = false;
-					
+
 					$this->page_info['actual_letter'] = $letter;
 					$this->page_info['actual_page'] = 0;
-					
+
 					$this->save_session();
 					$final[0] = 0;
 					$final[1] = $this -> typeContact;
-					echo serialize($final);					
+					echo serialize($final);
 					return;
 				}
-				else if ($ids)
-				{				
+				else if ($ids['error'])
+				{
+					$this->page_info['actual_entries'] = false;
+					$this->page_info['actual_letter'] = $letter;
+					$this->page_info['actual_page'] = 0;
+
+					$this->save_session();
+					$final[0] = 0;
+					$final[1] = $this -> typeContact;
+					$final['error'] = $ids['error'];
+					echo serialize($final);
+					return;
+				}
+				else if ($ids || $this->last_search_ids)
+				{
+
+					if ($ids)
+					{
+
+						$this->last_search_ids = $ids;
+
+					}
+					else {
+
+						$ids = $this->last_search_ids;
+
+					}
+
 					$this->page_info['actual_letter']  = $letter;
 					$this->page_info['actual_entries'] = $ids;
@@ -931,5 +1038,5 @@
 					$page = $this->page_info['n_pages'];
 				}
-				
+
 				$final = array(
 					0 => (int)$this->page_info['n_pages'],
@@ -943,28 +1050,30 @@
 						5 => 'cc_alias',
 						6 => 'cc_id',
-						7 => 'cc_forwarding_address'
+						7 => 'cc_forwarding_address',
+						8 => 'cc_empNumber',
+						9 => 'cc_department'
 					)
 				);
-				
+
 				//echo 'Page: '.$page.'<br>';
 				$id_i = (($page-1)*$this->page_info['n_cards']);
 				$id_f = $id_i + $this->page_info['n_cards'];
 				$n_entries = count($this->page_info['actual_entries']);
-				
+
 				//echo 'ID_I: '.$id_i.'<br>';
 				//echo 'ID_F: '.$id_f.'<br>';
-				///---------------- Correção Temporária PHP5 -----------------------///
+				///---------------- Correï¿œï¿œo Temporï¿œria PHP5 -----------------------///
 				$ids = array();
-				$array_temp = array();			
-								
+				$array_temp = array();
+
 				foreach($this->page_info['actual_entries'] as $key=>$tmp){
-					$array_temp[] = $tmp;				
-				}	
-				
+					$array_temp[] = $tmp;
+				}
+
 				for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
 				{
 					$ids[] = $array_temp[$i];
 				}
-				
+
 				/// Original
 				//for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
@@ -973,5 +1082,5 @@
 				//}
 				///
-				
+
 				$fields = $this->bo->catalog->get_fields(false);
 
@@ -985,36 +1094,36 @@
 							2 => 'cc_id',
 							3 => 'cc_contacts'
-						)						
-					);					
-					
+						)
+					);
+
 					$groups =& $this->bo->catalog->get_multiple_entries($ids,$fields);
-					
+
 					$i = 0;
 					// contatos do grupo
-					$boGroups = CreateObject('contactcenter.bo_group');					
+					$boGroups = CreateObject('contactcenter.bo_group');
 					$contacts = array();
 					foreach($groups as $group)		{
-										
+
 						$final[3][$i][0] = $group['title'] ? $group['title'] : 'none';
-						$final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none';						
+						$final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none';
 						$final[3][$i][2] = $group['id_group'] ? $group['id_group'] : 'none';
 						$contacts = $boGroups -> get_contacts_by_group($group['id_group']);
 						$final[3][$i][3] = $contacts;
-						$i++;							
+						$i++;
 					}
-					
+
 					$this->page_info['actual_letter'] = $letter;
-					$this->page_info['actual_page'] = $page;					
-					
-					
+					$this->page_info['actual_page'] = $page;
+
+
 					$lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
-					
+
 					$final[5] = '<span class="link"  onclick="'.$lnk_compose;
-					$final[10] = 'groups';																												
-					$this->save_session();					
+					$final[10] = 'groups';
+					$this->save_session();
 					echo serialize($final);
-					return;					
-				}
-				
+					return;
+				}
+
 				$fields['photo'] = true;
 				$fields['names_ordered'] = true;
@@ -1023,7 +1132,8 @@
 				$fields['companies'] = 'default';
 				$fields['connections'] = 'default';
+
+				// ?aqui alterar a chamada desse mï¿œtodo para receber o base dn?
 				$contacts =& $this->bo->catalog->get_multiple_entries($ids,$fields);
-				
-				
+
 				if (!is_array($contacts) or !count($contacts))
 				{
@@ -1033,95 +1143,117 @@
 					return;
 				}
-				
+
 				$i = 0;
-				foreach($contacts as $contact)
-				{
-					$final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none';
-					$final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none';
-					$final[3][$i][2] = $contact['companies']['company1']['title']?$contact['companies']['company1']['title']:'none';
-
-					/* Select the correct Email and Telephone to be shown */
-					$preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
-					if (!is_array($preferences))
-					{
-						$preferences['personCardEmail'] = 1;
-						$preferences['personCardPhone'] = 2;
-					}
-					if ($contact['connections'])
-					{
-						$default_email_found = false;
-						$default_phone_found = false;
-						foreach($contact['connections'] as $conn_info)
+				foreach($contacts as $index => $contact)
+				{
+					/*
+					 * TODO: Os timeouts de conexï¿œo foram retirados, ver se serï¿œ necessï¿œrio retornar essa funcionalidade, e,
+					 * neste caso, terminar a implementaï¿œï¿œo das mensagens de retorno.
+					 */
+					if ($index !== 'error'){
+						$final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none';
+						$final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none';
+						$final[3][$i][2] = $contact['companies']['company1']['title']?$contact['companies']['company1']['title']:'none';
+
+						//Para exibir a matricula do empregado
+						$final[3][$i][8] = $contact['companies']['company1']['empNumber']?$contact['companies']['company1']['empNumber']:'none';
+						//Para exibir o setor/lotaï¿œï¿œo do empregado
+						$final[3][$i][9] = $contact['companies']['company1']['department']?$contact['companies']['company1']['department']:'none';
+
+						/* Select the correct Email and Telephone to be shown */
+						$preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
+						if (!is_array($preferences))
 						{
-							if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found)
+							$preferences['personCardEmail'] = 1;
+							$preferences['personCardPhone'] = 2;
+						}
+						if ($contact['connections'])
+						{
+							$default_email_found = false;
+							$default_phone_found = false;
+							foreach($contact['connections'] as $conn_info)
 							{
-								if ($conn_info['connection_is_default'])
+								if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found)
 								{
-									$default_email_found = true;
+									if ($conn_info['connection_is_default'])
+									{
+										$default_email_found = true;
+									}
+									$final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
 								}
-								$final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
-							}
-							else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found)
-							{
-								if ($conn_info['connection_is_default'])
+								else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found)
 								{
-									$default_phone_found = true;
+									if ($conn_info['connection_is_default'])
+									{
+										$default_phone_found = true;
+									}
+									
+									if (!($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['telephone_number'] == $conn_info['connection_value']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] && $conn_info['connection_value'] && preg_match('/^\([0-9]{2}\)[0-9]{4}\-[0-9]{4}$/',$conn_info['connection_value'])==1 && !$external) {
+										$conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>";
 								}
-								$final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
+									
+									$final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
+								}
 							}
 						}
+
+						if (!$final[3][$i][3])
+						{
+							$final[3][$i][3] = 'none';
+						}
+
+						if (!$final[3][$i][4])
+						{
+							$final[3][$i][4] = 'none';
+						}
+
+						$final[3][$i][5] = $contact['alias']?$contact['alias']:'none';
+						$final[3][$i][6] = $ids[$i];
+
+					//	If contact is a public list, then load the forwarding addresses.
+						if($contact['account_type'][0] == 'l')
+							$final[3][$i][7] = array();
+
+						$final[4][$i] = $contact['photo'] ? 1  : 0;
+						$i++;
+
 					}
-					
-					if (!$final[3][$i][3])
+					else
 					{
-						$final[3][$i][3] = 'none';
+						// coloca mensagem de erro no vetor que retorna para o browser
 					}
-					
-					if (!$final[3][$i][4])
-					{
-						$final[3][$i][4] = 'none';
-					}
-
-					$final[3][$i][5] = $contact['alias']?$contact['alias']:'none';
-					$final[3][$i][6] = $ids[$i];
-
-				//	If contact is a public list, then load the forwarding addresses.
-					if($contact['account_type'][0] == 'l')
-						$final[3][$i][7] = array();
-
-					$final[4][$i] = $contact['photo'] ? 1  : 0;
-					$i++;
-				}
-				$lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";				
+				}
+				$lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
 				$final[5] = '<span class="link" onclick="'.$lnk_compose;
-				
-				
+
+
 				$this->page_info['actual_letter'] = $letter;
 				$this->page_info['actual_page'] = $page;
-				
-				$this->save_session();				
+
+				$this->save_session();
+
 				echo serialize($final);
 				return;
 			}
-			
+
 			$this->page_info['actual_letter'] = $letter;
 			$this->page_info['actual_page'] = $page;
-			
+
 			$this->save_session();
-			
+
 			$final[0] = 0;
 			$final[1] = $this -> typeContact;
 			echo serialize($final);
 		}
-		
+
 		/*!
-		
+
 			@function get_group_data
 			@abstract Returns all the information of a given Group
 			@author Nilton Emilio Buhrer Neto
-			
+
 			@param (integer) $id The id to get information
-		
-		*/		
+
+		*/
 		function get_group_data($id)
 		{
@@ -1129,38 +1261,31 @@
 			$fields = $this->bo->catalog->get_fields(true);
 			$data = $this->bo->catalog->get_single_entry($id,$fields);
-			
-			if($id) {			
+
+			if($id) {
 				// get All Contacts by group.
-				$data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id);								
-			}
-			
+				$data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id);
+			}
+
 			$boGroup = CreateObject('contactcenter.bo_group');
-						
-			$all_contacts = $boGroup->get_all_contacts();
-			
-			$contact_options = "";
-			if(count($all_contacts)) {					
-				foreach($all_contacts as $idx => $contact) {				
-					$contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered']." (".$contact['connection_value'].")</OPTION>";
-				}
-			}
-			$data['contact_list'] = $contact_options;
-			$data['result'] = 'ok';								
-			echo serialize($data);			
-		}		
-		
+
+			$data['contact_list'] = $boGroup->get_all_contacts();
+
+			$data['result'] = 'ok';
+			echo serialize($data);
+		}
+
 		/*!
-		
+
 			@function get_full_data
 			@abstract Returns all the information of a given Entry
 			@author Raphael Derosso Pereira
-			
+
 			@param (integer) $id The id to get information
-		
+
 		*/
 		function get_full_data($id)
 		{
 			$dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-			$this->bo->catalog = CreateObject('contactcenter.bo_people_catalog');		
+			$this->bo->catalog = CreateObject('contactcenter.bo_people_catalog');
 			$fields = $this->bo->catalog->get_fields(true);
 			$fields['photo'] = false;
@@ -1195,5 +1320,5 @@
 			}
 			$datecount = 0;
-			
+
 			$data['result'] = 'ok';
 			$data['cc_full_add_contact_id'] = $id;
@@ -1237,5 +1362,5 @@
 
 			/* Relations */
-			
+
 			echo serialize($data);
 		}
@@ -1274,26 +1399,26 @@
 				return;
 			}
-			
+
 			echo 0;
 		}
-		
+
 		/*!
-		
+
 			@function quick_add
 			@abstract Adds a new Contact using the Quick Add interface
 			@author Raphael Derosso Pereira
-			
+
 			@param string $sdata Serialized data
 		*/
 		function quick_add($sdata)
 		{
-			
+
 			$sdata = str_replace('\\"', '"', $sdata);
 			$new_array = unserialize($sdata);
 			$tdata = array();
-			
+
 			foreach($new_array as $tmp)
 				$tdata[] = $tmp;
-			
+
 			if (!$tdata)
 			{
@@ -1302,22 +1427,22 @@
 					'status' => 'abort'
 				));
-				
+
 				return;
 			}
-			
-			// verifica se email já existe!
+
+			// verifica se email jï¿œ existe!
 			$boGroup = CreateObject('contactcenter.bo_group');
 			$contact = $boGroup->verify_contact($tdata[4]);
-												
+
 			if($contact)
-			{							
+			{
 				$str_contact = "\r\n - ".implode("\r\n - ",$contact);
-				
+
 				echo serialize(array(
 					'msg'    => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact),
 					'status' => 'alreadyExists'
 				));
-				
-				return;			
+
+				return;
 			}
 
@@ -1335,7 +1460,7 @@
 
 			if ($boPeople ->quick_add($data))
-			{				
+			{
 				$this->page_info['changed'] = true;
-				
+
 				echo serialize(array(
 					'msg'    => lang('Entry added with success!'),
@@ -1351,14 +1476,14 @@
 			}
 
-			$this->save_session();	
-			
+			$this->save_session();
+
 		}
 
 		/*!
-		
+
 			@function add_group
 			@abstract Adds a new Group using the Add Group interface
 			@author Nilton Emilio Buhrer Neto
-			
+
 			@param string $sdata Serialized data
 		*/
@@ -1368,5 +1493,5 @@
 			$tdata = unserialize($sdata);
 			$new_tdata = array();
-			
+
 			if (!$tdata)
 			{
@@ -1375,22 +1500,22 @@
 					'status' => 'abort'
 				));
-				
+
 				return;
 			}
-			
+
 			foreach($tdata as $tmp)
 				$new_tdata[] = $tmp;
-			
-			$data['title'] = $new_tdata[0];			
+
+			$data['title'] = $new_tdata[0];
 			$data['contact_in_list'] = $new_tdata[1];
 			$data['id_group'] = $new_tdata[2];
-						
+
 			$boGroup = CreateObject('contactcenter.bo_group_manager');
 			$id = $boGroup -> add_group($data);
-			
+
 			if ($id)
 			{
 				$this->page_info['changed'] = true;
-				
+
 				echo serialize(array(
 					'msg'    => lang('Entry added with success!'),
@@ -1410,14 +1535,14 @@
 
 		/*!
-		
+
 			@function remove_group
 			@abstract Removes a group if the user has the right to do it
-			@author Nilton Emilio Buhrer Neto			
+			@author Nilton Emilio Buhrer Neto
 			@param (integer) $id The id to be removed
-				
+
 		*/
 		function remove_group($id)
-		{				
-				$soGroup = CreateObject('contactcenter.so_group');				
+		{
+				$soGroup = CreateObject('contactcenter.so_group');
 				$data = array ('id_group' => $id);
 				if($soGroup -> delete($data)) {
@@ -1425,5 +1550,5 @@
 						'msg'    => lang('Removed Entry ID '.$id.'!'),
 						'status' => 'ok'
-					));							
+					));
 				}
 				else {
@@ -1434,10 +1559,10 @@
 				}
 
-			$this->save_session();				
+			$this->save_session();
 		}
 
 
 		function remove_all_entries (){
-		
+
 			$error = false;
 			$this->all_entries = $this->bo->catalog->get_all_entries_ids();
@@ -1447,5 +1572,5 @@
 				if(!$result) {
 					$error = true;
-					break;		
+					break;
 				}
 			}
@@ -1456,5 +1581,5 @@
 					'status' => 'ok'
 				));
-			} 
+			}
 			else {
 				echo serialize(array(
@@ -1468,11 +1593,11 @@
 
 		/*!
-		
+
 			@function remove_entry
 			@abstract Removes an entry if the user has the right to do it
 			@author Raphael Derosso Pereira
-			
+
 			@param (integer) $id The id to be removed
-				
+
 		*/
 		function remove_entry ($id)
@@ -1483,8 +1608,8 @@
 				return;
 			}
-			
+
 			$this->page_info['changed'] = true;
 			$result = $this->bo->catalog->remove_single_entry($id);
-			
+
 			if ($result)
 			{
@@ -1493,5 +1618,5 @@
 					unset($this->page_info['actual_entries'][$pos]);
 				}
-				
+
 				$temp = false;
 				reset($this->page_info['actual_entries']);
@@ -1500,5 +1625,5 @@
 					$temp[] = $t;
 				}
-				
+
 				$this->page_info['actual_entries'] = $temp;
 
@@ -1515,11 +1640,11 @@
 				));
 			}
-			
+
 			$this->save_session();
 		}
 
-		
+
 		/*!
-		
+
 			@function post_full_add
 			@abstract Saves all the information altered/entered in the Full Add
@@ -1530,9 +1655,8 @@
 		function post_full_add()
 		{
-			$data =  $_POST['data'];
-			// Exceptions!!! utf8 special chars. 
-			$data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data);
-			$data = unserialize(str_replace('\\"', '"', $data));
+			$data = unserialize(str_replace('\\"', '"', $_POST['data']));
 			$this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog');
+
+//			echo str_replace('\\"', '"', $_POST['data']);
 
 			if (!is_array($data))
@@ -1558,5 +1682,5 @@
 					'status' => 'fatal'
 				));
-				
+
 				return;
 			}
@@ -1572,7 +1696,7 @@
 				$id_photo = '_new_';
 			}
-			
-			/* 
-			 * Process Photo, if available 
+
+			/*
+			 * Process Photo, if available
 			 */
 			$sleep_count = 0;
@@ -1591,5 +1715,5 @@
 			}
 			$GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n'));
-			
+
 			if (isset($this->page_info['photos'][$id_photo]))
 			{
@@ -1608,11 +1732,11 @@
 				$this->save_session();
 			}
-			
+
 			/*
 			 * Arrange Date so it gets inserted correctly
 			 */
-			 
+
 			$dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-		
+
 			$j = 0;
 			for ($i = 0; $i < 5; $i+=2)
@@ -1647,5 +1771,5 @@
 					continue;
 				}
-				
+
 				switch($field)
 				{
@@ -1659,5 +1783,5 @@
 						/* Do Nothing. This is just to make sure no invalid field is passed */
 						break;
-					
+
 					case 'id_status':
 					case 'id_prefix':
@@ -1668,9 +1792,9 @@
 						}
 						break;
-					
+
 					case 'birthdate_0':
 					case 'birthdate_1':
 					case 'birthdate_2':
-					
+
 						switch($date[$datecount]['digit'])
 						{
@@ -1694,5 +1818,5 @@
 							break;
 						}
-						
+
 						if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2]))
 						{
@@ -1703,5 +1827,5 @@
 							return;
 						}
-						
+
 						$data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1];
 						break;
@@ -1726,5 +1850,5 @@
 							{
 								$index = 'address'.$type;
-								
+
 								$id_state = $this->bo->catalog->add_state($state_info);
 								$data['addresses'][$index]['id_state'] = $id_state;
@@ -1744,5 +1868,5 @@
 							{
 								$index = 'address'.$type;
-								
+
 								$id_city = $this->bo->catalog->add_city($city_info);
 								$data['addresses'][$index]['id_city'] = $id_city;
@@ -1785,5 +1909,5 @@
 				);
 			}
-			
+
 			eval($code);
 
@@ -1801,5 +1925,5 @@
 
 		/*!
-		
+
 			@function post_photo
 			@abstract Wrapper to post a photo without reload a page.
@@ -1811,10 +1935,10 @@
 			//print_r($_FILES);
 			$GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y'));
-			
+
 			if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo']))
 			{
 				$this->page_info['photos'][$id]['status'] = 'no_upload';
 				$this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.');
-				
+
 				$this->save_session();
 				$GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
@@ -1826,5 +1950,5 @@
 				$this->page_info['photos'][$id]['status'] = 'no_GD_lib';
 				$this->page_info['photos'][$id]['msg'] = lang('Cannot manipulate Image. No Image added. Please, if you want to use images, ask the Administrator to install GD library.');
-				
+
 				$this->save_session();
 				$GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
@@ -1852,5 +1976,5 @@
 				return;
 			}
-			
+
 			switch($_FILES['cc_pd_photo']['type'])
 			{
@@ -1882,5 +2006,5 @@
 
 				default:
-					
+
 					$this->page_info['photos'][$id]['status'] = 'invalid_image';
 					$this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.');
@@ -1895,23 +2019,23 @@
 					$this->page_info['photos'][$id]['status'] = 'invalid_file';
 					$this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
-					
+
 					$this->save_session();
 					$GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
 					return;
 			}
-			
+
 			$img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']);
 			$dst_img = imagecreatetruecolor(60, 80);
-			
+
 			if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1]))
 			{
 				$this->page_info['photos'][$id]['status'] = 'invalid_file';
 				$this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
-				
+
 				$this->save_session();
 				$GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
 				return;
 			}
-			
+
 			ob_start();
 			imagepng($dst_img);
@@ -1923,5 +2047,5 @@
 
 			$this->save_session();
-		
+
 			$GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
 
@@ -1944,5 +2068,5 @@
 			$fields = $this->bo->catalog->get_fields(false);
 			$fields['photo'] = true;
-			
+
 			$contact = $this->bo->catalog->get_single_entry($id, $fields);
 
@@ -1953,5 +2077,5 @@
 				return;
 			}
-			
+
 			header('Content-type: image/jpeg');
 			$photo = imagecreatefromstring ($contact['photo']);
@@ -1965,7 +2089,7 @@
 			return;
 		}
-		
+
 		/*!
-		
+
 			@function get_states
 			@abstract Echos a serialized array containing all the states for the given country
@@ -1989,10 +2113,10 @@
 				return;
 			}
-			
+
 			$result = array(
 				'msg'    => lang('States Successfully retrieved!'),
 				'status' => 'ok'
 			);
-			
+
 			foreach ($states as $state_info)
 			{
@@ -2033,15 +2157,15 @@
 				return;
 			}
-			
+
 			$result = array(
 				'msg'    => lang('Cities Successfully retrieved!'),
 				'status' => 'ok'
 			);
-			
+
 			foreach ($cities as $city_info)
 			{
 				$result['data'][$city_info['id_city']] = $city_info['name'];
 			}
-			
+
 			echo serialize($result);
 		}
@@ -2049,9 +2173,10 @@
 
 		/*!
-		
+
 			@function search
 			@abstract Echos a serialized array containing the IDs
 				of the entries that matches the search argument
 			@author Raphael Derosso Pereira
+			@author Mï¿œrio Cï¿œsar Kolling (external catalogs)
 
 			@param string $str_data A serialized array with two informations:
@@ -2065,13 +2190,26 @@
 		{
 			$data = unserialize($str_data);
+			// It's an external catalog?
+			$external = $this->bo->is_external($this->page_info['actual_catalog']);
 
 			if (!is_array($data) || !$data['search_for'] || !is_array($data['fields']))
 			{
-				echo serialize(array(
-					'msg'    => lang('Invalid parameters'),
-					'status' => 'abort'
-				));
-
-				return;
+				//echo serialize(array(
+				//	'msg'    => lang('Invalid parameters'),
+				//	'status' => 'abort'
+				//));
+
+				return array('error' => lang('Invalid parameters'));
+			}
+
+			/*
+			 * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly
+			 */
+			// Support search parameters with accentuation
+			if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
+				$this->page_info['actual_catalog']['class'] != 'bo_group_manager')
+			{
+
+				$data['search_for'] = utf8_encode($data['search_for']);
 			}
 
@@ -2094,12 +2232,44 @@
 				if (!is_array($names))
 				{
-					echo serialize(array(
-						'msg'    => lang('Invalid Search Parameter'),
-						'status' => 'abort'
-					));
-					
-					return;
-				}
-				
+					//echo serialize(array(
+					//	'msg'    => lang('Invalid Search Parameter'),
+					//	'status' => 'abort'
+					//));
+
+					return array('error' => lang('Invalid Search Parameter'));
+				}
+
+				if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
+					$this->page_info['actual_catalog']['class'] != 'bo_group_manager')
+				{
+					/*
+					 * Restrict the returned contacts search to objectClass = phpgwAccount,
+					 * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1 and
+					 * objectClass = inetOrgPerson
+					 */
+					$rules = array(
+						0 => array(
+							'field' => 'contact.object_class',
+							'type'  => '=',
+							'value' => 'phpgwAccount'
+						),
+						1 => array(
+							'field' => 'contact.account_status',
+							'type'  => 'iLIKE',
+							'value' => '%'
+						),
+						2 => array(
+							'field' => 'contact.account_visible',
+							'type'  => '!=',
+							'value' => '-1'
+						),
+						3 => array(
+							'field' => 'contact.object_class',
+							'type'  => '=',
+							'value' => 'inetOrgPerson'
+						)
+					);
+				}
+
 				foreach ($names as $name)
 				{
@@ -2114,28 +2284,35 @@
 				}
 			}
-			
-			/*
-			$catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]);
-			
-			if ($catalog['class'] === 'bo_people_catalog')
-			{
-				array_push($rules, array(
-					'field' => 'contact.id_owner',
-					'type'  => '=',
-					'value' => $GLOBALS['phpgw_info']['user']['account_id']
-				));
-			}
-			*/
-			
-			$ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
+
+			if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' ||
+				$this->page_info['actual_catalog']['class'] == 'bo_group_manager')
+			{
+				// Get only this attributes: dn, cn for external catalogs,
+				// used to restrict the attributes used in filters
+				$ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
+			}
+			else
+			{
+				// Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
+				// for non-external catalogs, used to restrict the attributes used in filters
+				$ids = $this->bo->find(array(
+					$data['fields']['id'],
+					$data['fields']['search'],
+					'contact.object_class',
+					'contact.account_status',
+					'contact.account_visible'
+					), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
+			}
 
 			if (!is_array($ids) || !count($ids))
 			{
-				echo serialize(array(
-					'msg'    => lang('No Entries Found!'),
-					'status' => 'empty'
-				));
-
-				return;
+				//echo serialize(array(
+				//	'msg'    => lang('No Entries Found!'),
+				//	'status' => 'empty'
+				//));
+
+				$this->last_search_ids = null;
+				$this->save_session();
+				return null;
 			}
 
@@ -2145,12 +2322,18 @@
 			foreach ($ids as $e_info)
 			{
+				//$ids_f[] = "base64::" . base64_encode($e_info[$id_field]);
 				$ids_f[] = $e_info[$id_field];
 			}
-			
-			echo serialize(array(
-				'data'   => $ids_f,
-				'msg'    => lang('Found %1 Entries', count($ids)),
-				'status' => 'ok'
-			));
+
+			//error_log("ids_f serializados: " . serialize($ids_f) . "\n", 3, '/var/www/teste.log');
+
+			//return serialize($ids_f);
+			return $ids_f;
+
+			//echo serialize(array(
+			//	'data'   => $ids_f,
+			//	'msg'    => lang('Found %1 Entries', count($ids)),
+			//	'status' => 'ok'
+			//));
 		}
 
@@ -2162,5 +2345,5 @@
 			@author Raphael Derosso Pereira
 
-			@param array str_data A serialized array containing the ID's of the entries 
+			@param array str_data A serialized array containing the ID's of the entries
 				to be taken, the fields to be taken and the rules to be used on the
 				retrieval:
@@ -2175,5 +2358,5 @@
 		{
 			$data = unserialize($str_data);
-			
+
 			if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids']))
 			{
@@ -2185,5 +2368,5 @@
 
 			$entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']);
-			
+
 			if (!is_array($entries) or !count($entries))
 			{
@@ -2204,9 +2387,9 @@
 
 			@function get_all_entries
-			@abstract Returns the specified fields for all catalog's entries 
+			@abstract Returns the specified fields for all catalog's entries
 				in the default CC UI format
 			@author Raphael Derosso Pereira
 
-			@params array str_data A serialized array containing the fields to 
+			@params array str_data A serialized array containing the fields to
 				be grabbed, the maximum number of entries to be returned and a
 				boolean specifying if the calls refers to a new grab or to an
@@ -2217,8 +2400,8 @@
 		{
 			$data = unserialize($str_data);
-			
-			if (!is_array($data) or 
-			    !count($data) or 
-				!count($data['fields']) or 
+
+			if (!is_array($data) or
+			    !count($data) or
+				!count($data['fields']) or
 				!$data['maxlength'] or
 				(!$data['new'] and !$data['offset']))
@@ -2246,5 +2429,5 @@
 				$data['offset'] = 0;
 			}
-			
+
 			if ($data['maxlength'] != -1)
 			{
@@ -2257,5 +2440,5 @@
 
 			$prefs = ExecMethod('contactcenter.ui_preferences.get_preferences');
-			
+
 			$jsCode = array();
 			$count = 0;
@@ -2267,21 +2450,21 @@
 				}
 
-				if($this-> typeContact == 'groups') {				
-					
+				if($this-> typeContact == 'groups') {
+
 					foreach ($each as $field => $value)	{
-										
+
 						if ($field === 'title')	{
 							$optionName = '\\"'.$value.'\\"';
-							 
+
 						}
 						else if ($field === 'short_name')	{
-							
+
 							$jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");';
-							$count++;																					
-						}					
+							$count++;
+						}
 					}
 				}
-				
-				else  {	
+
+				else  {
 					foreach ($each as $field => $value)	{
 						if ($field === 'names_ordered')	{
@@ -2291,5 +2474,5 @@
 						}
 						else if ($field === 'connections')	{
-							
+
 							foreach ($value as $connection)		{
 								if ($connection['id_type'] == $prefs['personCardEmail'])	{
@@ -2304,7 +2487,7 @@
 
 			$jsCodeFinal = implode("\n", $jsCode);
-			
+
 			$nEntries = count($result);
-			
+
 			if (!$nEntries)
 			{
@@ -2324,5 +2507,5 @@
 			);
 		}
-		
+
 		/*********************************************************************\
 		 *                      Auxiliar Methods                             *
@@ -2330,9 +2513,9 @@
 
 		/*!
-		
+
 			@function save_session
 			@abstract Saves the data on the session
 			@author Raphael Derosso Pereira
-		
+
 		*/
 		function save_session()
@@ -2340,13 +2523,14 @@
 			$GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info);
 			$GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries);
+			$GLOBALS['phpgw']->session->appsession('ui_data.last_search_ids','contactcenter',$this->last_search_ids);
 		}
 
 		/*!
-		
+
 			@function convert_tree
 			@abstract Converts the tree array in the BO format to a JS tree array compatible
 				with the one available in eGW
 			@author Raphael Derosso Pereira
-		
+
 			@param (array)  $tree    The tree in the BO format
 			@param (string) $name    The tree name
@@ -2382,5 +2566,5 @@
 					'caption' => $value['name']
 				);
-				
+
 				switch($value['type'])
 				{
@@ -2405,12 +2589,12 @@
 				$this->bo->catalog->src_info = $ldap->srcs[1];
 			}
-			
-			$ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);				
+
+			$ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
 			$dn=$this->bo->catalog->src_info['dn'];
 			$justThese = array("givenname","givenname","sn","telephonenumber","mail");
-			$sr = ldap_read($ds,$id, "objectClass=*",$justThese);							
-			$info = ldap_get_entries($ds, $sr);							
+			$sr = ldap_read($ds,$id, "objectClass=*",$justThese);
+			$info = ldap_get_entries($ds, $sr);
 			for($z = 0; $z < 5; $z++) {
-				$participant = $info[0][$justThese[$z]];													
+				$participant = $info[0][$justThese[$z]];
 				array_push($array_participants, $participant);
 			}
@@ -2418,59 +2602,59 @@
 			ldap_close($ds);
 			echo serialize($array_participants);
-		}	
-		
-		function get_catalog_participants_list($id) 
+		}
+
+		function get_catalog_participants_list($id)
 		{
-			
-			$fields = $this->bo->catalog->get_fields(false);			
+
+			$fields = $this->bo->catalog->get_fields(false);
 			$fields['names_ordered'] = true;
-			$fields['mail_forwarding_address'] = true;			
-			$contact = $this->bo->catalog->get_single_entry($id,$fields);			
-			
+			$fields['mail_forwarding_address'] = true;
+			$contact = $this->bo->catalog->get_single_entry($id,$fields);
+
 			$array_participants = array();
 			$array_emails = array();
-			
+
 			$filter = null;
-			for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) {			
+			for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) {
 					if(strstr($contact['mail_forwarding_address'][$z],'@')) {
 						$filter.="(mail=".$contact['mail_forwarding_address'][$z].")";
 						$array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>";
-					}																
-					else 
+					}
+					else
 						$array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>";
-			}					
-			
+			}
+
 			if($filter) {
-				$filter = "(|".$filter.")";							
+				$filter = "(|".$filter.")";
 				if(!$this->bo->catalog->src_info) {
 					$ldap = CreateObject('contactcenter.bo_ldap_manager');
 					$this->bo->catalog->src_info = $ldap->srcs[1];
 				}
-				$ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);				
+				$ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
 				$dn=$this->bo->catalog->src_info['dn'];
 				$justThese = array("cn","mail");
-				$sr = ldap_search($ds,$dn, $filter,$justThese);								
-				$info = ldap_get_entries($ds, $sr);							
+				$sr = ldap_search($ds,$dn, $filter,$justThese);
+				$info = ldap_get_entries($ds, $sr);
 				for($z = 0; $z < $info['count']; $z++) {
 					$participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>';
-					$array_emails[$info[$z]['mail'][0]] = null; 								
-					array_push($array_participants, $participant);					
-				}
-				
+					$array_emails[$info[$z]['mail'][0]] = null;
+					array_push($array_participants, $participant);
+				}
+
 				foreach($array_emails as $index => $email)
-					if($email) 
-						array_push($array_participants, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$email."<br>");				
-												
+					if($email)
+						array_push($array_participants, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$email."<br>");
+
 				ldap_close($ds);
 			}
 			sort($array_participants);
-			$innerHTML = '';			
+			$innerHTML = '';
 			foreach($array_participants as $index => $participant){
 				$innerHTML .= $participant;
 			}
-			$return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);			 
+			$return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);
 			echo serialize($return);
-		}	
-		
+		}
+
 		function export_contacts($typeExport){
 
@@ -2483,5 +2667,5 @@
 
 
-			// Essa iteração transforma uma esturuta com contatos redundantes e separados por email ou tel.
+			// Essa iteraï¿œï¿œo transforma uma esturuta com contatos redundantes e separados por email ou tel.
 			// em outra com apenas 1 elemento pra cada contato
 			$i=0;
@@ -2494,45 +2678,45 @@
 					$all_contacts[$i]['phone']=$object['connection_value'];
 			}
-			
+
 			switch($typeExport) {
 
 				case 'outlook_en':
 					$streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;".
-							"Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n";							
+							"Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n";
 					foreach($all_contacts as $index => $object){
 						$streamBuffer.= $object['name'].";".$object['email'].";;;;;;".$object['phone'].";;;\r\n";
 					}
 				break;
-				
+
 				case 'outlook_pt-BR':
-					$streamBuffer = "Nome;End. de email;Endereço residencial;".
-					"Cidade do endereço residencial;CEP do endereço residencial;".
-					"Estado;País/região do endereço residencial;Telefone residencial;".
-					"Rua do endereço comercial;Cidade do endereço comercial;".
-					"CEP do endereço comercial;Estado do endereço comercial;".
-					"País/região do endereço comercial;Telefone comercial;Empresa;Cargo\r\n";							
+					$streamBuffer = "Nome;End. de email;Endereï¿œo residencial;".
+					"Cidade do endereï¿œo residencial;CEP do endereï¿œo residencial;".
+					"Estado;Paï¿œs/regiï¿œo do endereï¿œo residencial;Telefone residencial;".
+					"Rua do endereï¿œo comercial;Cidade do endereï¿œo comercial;".
+					"CEP do endereï¿œo comercial;Estado do endereï¿œo comercial;".
+					"Paï¿œs/regiï¿œo do endereï¿œo comercial;Telefone comercial;Empresa;Cargo\r\n";
 					foreach($all_contacts as $index => $object){
 						$streamBuffer.= $object['name'].";".$object['email'].";;;;;;".$object['phone'].";;;;;;;;\r\n";
 					}
 				break;
-				
+
 				case 'outlook2000_pt-BR':
 					$streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",".
-					"\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",".
-					"\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",".
-					"\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",".
-					"\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",".
-					"\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",".
+					"\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereï¿œo comercial\",\"Rua do endereï¿œo comercial 2\",".
+					"\"Rua do endereï¿œo comercial 3\",\"Cidade do endereï¿œo comercial\",\"Estado do endereï¿œo comercial\",".
+					"\"CEP do endereï¿œo comercial\",\"Paï¿œs do endereï¿œo comercial\",\"Endereï¿œo residencial\",\"Rua residencial 2\",".
+					"\"Rua residencial 3\",\"Cidade do endereï¿œo residencial\",\"Estado\",\"CEP do endereï¿œo residencial\",\"Paï¿œs do endereï¿œo residencial\",".
+					"\"Outro endereï¿œo\",\"Outro endereï¿œo 2\",\"Outro endereï¿œo 3\",\"Cidade\",\"Estado\",\"CEP\",\"Paï¿œs\",".
 					"\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",".
 					"\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",".
 					"\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",".
-					"\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",".
-					"\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",".
-					"\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",".
-					"\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",".
-					"\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",".
-					"\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",".
-					"\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",".
-					"\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",".
+					"\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversï¿œrio\",\"Anotaï¿œï¿œes\",\"Caixa postal\",\"Categorias\",".
+					"\"Cï¿œdigo da empresa\",\"Cï¿œdigo do governo\",\"Cï¿œnjuge\",\"Conta\",\"Endereï¿œo de correio eletrï¿œnico\",".
+					"\"Nome de exibiï¿œï¿œo do correio eletr.\",\"Endereï¿œo de correio eletrï¿œnico 2\",".
+					"\"Nome de exibiï¿œï¿œo do correio eletr.2\",\"Endereï¿œo de correio eletrï¿œnico 3\",".
+					"\"Nome de exibiï¿œï¿œo do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",".
+					"\"Filhos\",\"Hobby\",\"Idioma\",\"Indicaï¿œï¿œo\",\"Informaï¿œï¿œes para cobranï¿œa\",\"Iniciais\",\"Local\",".
+					"\"Nome do assistente\",\"Nome do gerenciador\",\"Pï¿œgina da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",".
+					"\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissï¿œo\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretï¿œrio\",".
 					"\"Sexo\"\r\n";
 					foreach($all_contacts as $index => $object){
@@ -2540,5 +2724,5 @@
 					}
 				break;
-				
+
 				case 'outlook2000_en':
 					$streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,".
@@ -2556,13 +2740,13 @@
 					}
 				break;
-					
+
 				case 'thunderbird':
-					$streamBuffer = "\n";							
+					$streamBuffer = "\n";
 					foreach($all_contacts as $index => $object){
 						$streamBuffer.= ",,".$object['name'].",,".$object['email'].",,".$object['phone'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n";
 					}
 				break;
-				
-				case 'expresso':
+
+				default:
 					$streamBuffer = "Nome,Email,Telefone\r\n";
 					foreach($all_contacts as $index => $object){
@@ -2570,5 +2754,5 @@
 					}
 				break;
-				
+
 			}
 
@@ -2578,5 +2762,5 @@
 			if(!$f)
 				echo null;
-		
+
 			fputs($f,$streamBuffer);
 			fclose($f);
@@ -2585,56 +2769,15 @@
 		}
 
-		// Get the csv field and put into array, from php.net
-		function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') {
-  			$text = trim($input_text);
-  			  if(is_string($delimiter) && is_string($text_qualifier)) {
-       			 $re_d = '\x' . dechex(ord($delimiter));            //format for regexp
-        		$re_tq = '\x' . dechex(ord($text_qualifier));    //format for regexp
-        		
-        		$fields = array();
-        		$field_num = 0;
-        		while(strlen($text) > 0) {
-            		if($text{0} == $text_qualifier) {
-                		preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches);
-		               
-        		        $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]);
-             			$text = trim($matches[2]);
-               
-                		$fields[$field_num++] = $value;
-            		} else {
-                		preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches);
-		               
-        		        $value = $matches[1];
-               			$text = trim($matches[2]);
-               
-              		  	$fields[$field_num++] = $value;
-            	}
-        	}
-        		return $fields;
-		    } else
-       			return false;
-		}
 
 		function import_contacts($typeImport){
 
-			if($file = $_SESSION['contactcenter']['importCSV']) {				
-				unset($_SESSION['contactcenter']['importCSV']);				
+			$delim 		= ($typeImport == 'outlook' ? ';' : ',');
+
+			if($file = $_SESSION['contactcenter']['importCSV']) {
+				unset($_SESSION['contactcenter']['importCSV']);
 				$len = filesize($file);
 				$count = 0;
 				$return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0);
    				$handle = @fopen($file, "r") or die(serialize($return['error'] = true));
-   				
-				$input_header = fgets($handle);
-				if ($typeImport == 'outlook')
-					$delim = ';';
-				else if ($typeImport == 'auto')
-				$delim = strstr($input_header,',') ? ',' : ';';
-				else  
-					$delim = ',';
-				$csv_header = $this->parse_line($input_header,$delim);
-				$firstContact = fgets($handle);
-				preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv
-   				rewind($handle);	   			
-
    				$header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true));
    				if(count($header)  < 2 || count($header) > 100) {
@@ -2644,10 +2787,8 @@
    					return;
    				}
-   				
-   				if ($matches[0][strlen($matches[0])-1] == ';')
-					$delim = ';';
-   				
-			$boGroup = CreateObject('contactcenter.bo_group');
-			$boPeople = CreateObject('contactcenter.bo_people_catalog');
+
+				$boGroup = CreateObject('contactcenter.bo_group');
+				$boPeople = CreateObject('contactcenter.bo_people_catalog');
+
 				switch($typeImport){
 					case 'outlook2000':
@@ -2666,42 +2807,15 @@
 						$phone_pos=7;
 						break;
-					case 'expresso':
+					default:
 						$name_pos=0;
 						$email_pos=1;
 						$phone_pos=2;
-						break;
-					default:
-						foreach($csv_header as $index => $fieldName)
-						{
-							switch($fieldName){
-							case 'Name':
-							case 'Nome':
-							case 'First Name':
-								$name_pos = $index;
-								break;
-							case 'E-mail':
-							case 'Email':
-							case 'E-mail Address':
-							case 'Endereço de correio eletrônico':
-							case 'End. de email':
-								$email_pos = $index;
-								break;
-							case 'Home Phone':
-							case 'Phone':
-							case 'Telefone':
-							case 'Telefone principal':
-							case 'Telefone comercial':
-								$phone_pos = $index;
-								break;
-							}
-						}	
-						break;
-				}
-				
+				}
 
 				while (($data = fgetcsv($handle, $len, $delim))) {
+
        				foreach ($header as $key=>$heading)
                			$row[$heading]=(isset($data[$key])) ? $data[$key] : '';
-       				
+
 					$sdata = array();
 					$full_name  = trim($row[$header[$name_pos]]);
@@ -2717,23 +2831,20 @@
 					$sdata['connections']['default_phone']['connection_name'] = lang('Main');
 					$sdata['connections']['default_phone']['connection_value'] = $phone;
-					
-					// 	verifica se email já existe!
+
+					// 	verifica se email jï¿œ existe!
 					$contact = $boGroup->verify_contact($email);
 
-					$line_iteration = $return['_failure'] + $return['_existing'] + $return['_new']; 
 					if($contact){
 						$return['_existing']++;
-					}														
+					}
 					else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
 						$return['_failure']++;
-						$return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>";
 					}
-					else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){						
-						$return['_failure']++;							
-						$return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>";
+					else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){
+						$return['_failure']++;
 					}
 					else
 						$return['_new']++;
-       			}       			
+       			}
    				fclose($handle);
 				unlink($file);
@@ -2749,5 +2860,5 @@
 			$new = null;
 			$code = null;
-			
+
 			if ($parent === '0')
 			{
@@ -2755,5 +2866,5 @@
 				$code .= $name.".add(new dNode({id:'0', caption: '".lang('Catalogues')."'}),'none');\n";
 			}
-			
+
 			foreach ($tree as $id => $value)
 			{
@@ -2761,11 +2872,11 @@
 
 				switch ($value['type'])
-				{					
+				{
 					case 'unknown':
-						$code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption:'{$value['name']}', onFirstOpen: 'getCatalogTree(\\'{$parent}.{$id}\\');', onClick: 'getCatalogTree(\\'{$parent}.{$id}\\'); waitForTree(\\'{$parent}.{$id}\\', 0)'}),'$parent');\n"; 
+						$code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption:'{$value['name']}', onFirstOpen: 'getCatalogTree(\\'{$parent}.{$id}\\');', onClick: 'getCatalogTree(\\'{$parent}.{$id}\\'); waitForTree(\\'{$parent}.{$id}\\', 0)'}),'$parent');\n";
 						break;
-					
+
 					case 'catalog_group':
-						$code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}'}),'$parent');\n"; 
+						$code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}'}),'$parent');\n";
 						$code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id);
 						break;
@@ -2776,11 +2887,11 @@
 						$code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id);
 						break;
-					
+
 					case 'catalog':
 						$code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n";
-						
-				}
-			}
-			
+
+				}
+			}
+
 			return $code;
 		}
Index: /trunk/contactcenter/inc/class.Thread.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.Thread.inc.php	(revision 284)
+++ /trunk/contactcenter/inc/class.Thread.inc.php	(revision 284)
@@ -0,0 +1,102 @@
+<?php
+	/***********************************************************************************\
+	* eGroupWare - Contacts Center                                              		*
+	* http://www.egroupware.org                                                 		*
+	* Written by:                                                               		*
+	*  - Brian W. Bosh from	Multi-threading strategies in PHP at						*
+	* http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html	*
+	* Adapted by:																		*
+	*  - Mário César Kolling <mario.kolling@serpro.gov.br>								*
+	* ----------------------------------------------------------------------------------*
+	*  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.                                               		*
+	\***********************************************************************************/
+
+	require 'ThreadUtility.inc.php';
+
+	/*
+	 * This is the class that abstracts the details of process management
+	 */
+
+	class Thread {
+		var $pref ;
+		var $pipes;
+		var $pid;
+		var $stdout;
+		//var $timeout;
+
+		function Thread() {
+			$this->pref = 0;
+			$this->stdout = "";
+			$this->pipes = (array)NULL;
+			//$this->timeout = 30000;
+		}
+
+		function Create ($url, $env) {
+			$t = new Thread;
+			$descriptor = array (0 => array ("pipe", "r"), 1 => array ("pipe", "w"), 2 => array ("pipe", "w"));
+			$t->pref = proc_open ("php -q ". "/var/www/expresso/contactcenter/inc/" . $url, $descriptor, $t->pipes, NULL, $env);
+			stream_set_blocking ($t->pipes[1], 0);
+			stream_set_blocking ($t->pipes[2], 0);
+			//usleep ($this->timeout);
+			return $t;
+		}
+
+		function isActive () {
+			$status = proc_get_status($this->pref);
+			return $status['running'];
+		}
+
+		function close () {
+			$r = proc_terminate($this->pref);
+			$this->pref = NULL;
+			return $r;
+		}
+
+		function tell ($thought, $params = NULL) {
+		    fwrite ($this->pipes[0], $thought . "\n");
+			if (is_array ($params)) {
+				foreach ($params as $param) {
+					fwrite ($this->pipes[0], $param . "\n");
+				}
+			}
+		}
+
+		function readResponse()
+		{
+			$response = NULL;
+			$read = array($this->pipes[1]);
+			$write = NULL;
+			$exception = NULL;
+
+			if (stream_select($read, $write, $exception, 0) > 0){
+				$response = $this->listen();
+				return processresponse($response);
+			}
+			else
+			{
+				return $response;
+			}
+		}
+
+		function listen () {
+			$buffer = $this->stdout;
+			$this->stdout = "";
+			while ($r = fgets ($this->pipes[1], 1024)) {
+				$buffer .= $r;
+			}
+			return $buffer;
+		}
+
+		function getError () {
+			$buffer = "";
+			while ($r = fgets ($this->pipes[2], 1024)) {
+				$buffer .= $r;
+			}
+			return $buffer;
+		}
+	}
+
+?>
Index: /trunk/contactcenter/inc/class.bo_contactcenter.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_contactcenter.inc.php	(revision 2)
+++ /trunk/contactcenter/inc/class.bo_contactcenter.inc.php	(revision 284)
@@ -5,5 +5,5 @@
   * Written by:                                                               *
   *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
-  *  sponsored by Thyamad - http://www.thyamad.com
+  *  sponsored by Thyamad - http://www.thyamad.com                            *
   * ------------------------------------------------------------------------- *
   *  This program is free software; you can redistribute it and/or modify it  *
@@ -25,10 +25,10 @@
 		*/
 		var $catalog;
-		
+
 		/*!
 			The Security Manager
 		*/
 		var $security;
-		
+
 
 		function bo_contactcenter($catalog=false)
@@ -37,5 +37,5 @@
 			$this->catalog_level = $GLOBALS['phpgw']->session->appsession('bo_contactcenter.catalog_level','contactcenter');
 			$this->security = CreateObject('contactcenter.bo_security_manager');
-			
+
 			if ($catalog)
 			{
@@ -56,12 +56,62 @@
 			}
 		}
-		
-		/*!
-		
+
+		/*
+		 *
+		 * @function is_external
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 * @abstract Verify if a catalog is external
+		 * @param (mixed) an catalog array or a catalog tree level, a string in the form 0.sublevel.subsublevel
+		 * @return (boolean) true if it is an external catalog false otherwise
+		 *
+		 */
+
+		function is_external($catalog)
+		{
+			if (is_array($catalog))
+			{
+				$level = $this->get_level_by_branch($catalog, $this->tree['branches']);
+			}
+			else
+			{
+				$level = $catalog;
+			}
+
+			$lvl_vector = explode('.', $level);
+			$id = $lvl_vector[1];
+
+			if ($this->tree['branches'][$id]['external'])
+			{
+				return true;
+			}
+
+			return false;
+
+		}
+
+		/*
+		 function get_letters_filter($catalog)
+		{
+
+		}
+
+		function get_numbers_filter($catalog)
+		{
+
+		}
+
+		function get_search_filter($catalog)
+		{
+
+		}
+		*/
+
+		/*!
+
 			@function find
 			@abstract Performs a search in the DB based on the parameters
 			@author Raphael Derosso Pereira (algorithm and code)
 			@author Vinicius Cubas Brand (algorithm)
-			
+
 			@param array $what The list of fields to be returned. The format is:
 				$what = array(
@@ -69,16 +119,16 @@
 					'contact.names_ordered'
 				);
-			
+
 			@param array $rules The restrictions.
-			
+
 			The restrictions format is quite complicated, but is very complete.
 			As defined here, there is the possibility to do almost any type of
 			search (tell me if you can't do any). For example, imagine the
 			following search:
-					
+
 						and(a,or(d,e,and(f,g)))
-			
+
 			That is represented by the folloowing tree:
-				
+
                                    and
                                     |
@@ -98,5 +148,5 @@
 			The rules that should be passed to the find function for this tree
 			is:
-				
+
 	 			$rules = array(
  					0 => array(
@@ -139,10 +189,10 @@
 	 			);
 
-  
-			The restriction type can be: =, !=, <=, <, >, >=, NULL, IN, LIKE, 
+
+			The restriction type can be: =, !=, <=, <, >, >=, NULL, IN, LIKE,
 			NOT NULL, NOT IN, NOT LIKE
 			Value of branch can be AND, OR, NOT
-			
-			@param array $other Other parameter to the search 
+
+			@param array $other Other parameter to the search
 				$other = array(
 					'offset'          => (int),
@@ -154,5 +204,5 @@
 
 			@return array $array[<field_name>][<row_number>]
-				
+
 		*/
 		function find($what, $rules=false, $other=false)
@@ -160,7 +210,7 @@
 			return $this->catalog->find($what, $rules, $other);
 		}
-		
-		/*!
-		
+
+		/*!
+
 			@function get_catalog_tree
 			@abstract Returns an array describing the available
@@ -168,9 +218,10 @@
 				values and types
 			@author Raphael Derosso Pereira
+			@author Mário César Kolling (external catalogs and optimizations)
 
 			@param (string)  $level The level to be taken
 			@param (boolean) $recursive Retrive the whole tree from
 				the level specified until the leaves
-			
+
 			@return The format of the return is:
 				$return = array(
@@ -195,7 +246,7 @@
 					1  => array(...),...
 				);
-				
+
 				<branch_type> can be 'catalog_group', 'catalog' or 'view';
-				<branch_class> is the name of the class that is capable of 
+				<branch_class> is the name of the class that is capable of
 					handling the information for this catalog/view
 				<branch_class_args> is an array that holds the arguments to
@@ -203,8 +254,8 @@
 				<brach_find_args> is the string that should precede the search
 					string
-						
-				If the branch is actually a leaf, than 'sub_branch' is false; 
-		
-		
+
+				If the branch is actually a leaf, than 'sub_branch' is false;
+
+
 			TODO: This method is hard-coded, but it should grab the tree
 			from the DB using the View Manager...
@@ -218,8 +269,11 @@
 					return $this->tree['branches'];
 				}
-				
+
+				$lvl_vector = explode('.', $level);
+				$id = $lvl_vector[1];
+
 				$branch =& $this->get_branch_by_level($level);
 				$info = $this->get_info_by_level($level);
-				
+
 				if ($branch['type'] === 'unknown')
 				{
@@ -227,9 +281,28 @@
 					{
 						$ldap = CreateObject('contactcenter.bo_ldap_manager');
-						$new_branch = $ldap->get_ldap_tree($info['src'], $branch['value'], $recursive);
-						
+
+						if ($this->tree['branches'][$id]['external'])
+						{
+							// if it's an external catalog
+							$new_branch = $ldap->get_external_ldap_tree($info['src'], $branch['value'], $recursive);
+						}
+						else
+						{
+							// if it's not an external catalog
+							$new_branch = $ldap->get_ldap_tree($info['src'], $branch['value'], $recursive);
+						}
+
 						if ($new_branch)
 						{
+							if (!empty($new_branch['timeout']) && !empty($new_branch['msg']))
+							{
+								return $new_branch;
+							}
+
+							// Necessary for the new way the catalog tree is built at initialization
+							$new_branch['name'] = $branch['name'];
+							$new_branch['external'] = $branch['external'];
 							$branch = $new_branch;
+
 						}
 						else
@@ -239,5 +312,4 @@
 					}
 					$GLOBALS['phpgw']->session->appsession('bo_contactcenter.tree','contactcenter',$this->tree);
-					
 					return $branch;
 				}
@@ -246,13 +318,13 @@
 					return $branch;
 				}
-				
+
 				return false;
 			}
-			
+
 			if ($level !== '0')
 			{
 				return false;
 			}
-			
+
 			$this->tree = array(
 				0 => array(
@@ -275,5 +347,5 @@
 						'sub_branch' => false
 					),*/
-					
+
 					1  => array(
 						'name'       => lang('Groups'),
@@ -281,12 +353,12 @@
 						'class'      => 'bo_group_manager',
 						'icon'       => 'people-mini.png',
-						'sub_branch' => False   
+						'sub_branch' => False
 					)
 				)
 			);
-			
+
 			$ldap = CreateObject('contactcenter.bo_ldap_manager');
 			$ldap_srcs = $ldap->get_all_ldap_sources();
-			
+
 			if ($ldap_srcs)
 			{
@@ -297,25 +369,93 @@
 					if (($tree = $ldap->get_ldap_tree($id, $ldap_srcs[$id]['dn'], $recursive)))
 					{
+						// It isn't used anymore, but does no harm!
+						// It may be usefull later for use with search timeouts, or another ldap error
+						if (array_key_exists('error_msg', $tree))
+						{
+							if (isset($this->tree['branches']['msg']))
+							{
+								$this->tree['branches']['msg'] .= "\n" . lang('Catalog %1 not showed due to error: ' .
+													 $tree['error_msg'], $ldap_srcs[$id]['name']);
+							}
+							else
+							{
+								$this->tree['branches']['msg'] = lang('Catalog %1 not showed due to error: ' .
+													 $tree['error_msg'], $ldap_srcs[$id]['name']);
+							}
+						}
+						else
+						{
+							$tree['name'] = $ldap_srcs[$id]['name'];
+							$tree['external'] = false;
+							array_push($this->tree['branches'], $tree);
+							$this->tree[$i]['type'] = 'ldap';
+							$this->tree[$i]['src'] = $id;
+						}
+
+					}
+					$i++;
+				}
+			}
+
+			// external LDAP sources
+			$ldap_srcs = $ldap->get_external_ldap_sources();
+
+			if ($ldap_srcs)
+			{
+				$i = count($this->tree);
+
+				reset($ldap_srcs);
+
+				while (list($id,) = each($ldap_srcs))
+				{
+					// External catalogs are now identified as type unknown during initialization. An optimization change.
+
+					/*
+					if (($tree = $ldap->get_external_ldap_tree($id, $ldap_srcs[$id]['dn'], $recursive)))
+					{
+						if (array_key_exists('error_msg', $tree))
+						{
+							if (isset($this->tree['branches']['msg']))
+							{
+								$this->tree['branches']['msg'] .= "\n" . lang('Catalog %1 not showed due to error: ' .
+													 $tree['error_msg'], $ldap_srcs[$id]['name']);
+							}
+							else
+							{
+								$this->tree['branches']['msg'] = lang('Catalog %1 not showed due to error: ' .
+													 $tree['error_msg'], $ldap_srcs[$id]['name']);
+							}
+						}
+
+						else
+						{
+						*/
 						$tree['name'] = $ldap_srcs[$id]['name'];
+						$tree['type'] = 'unknown';
+						$tree['value'] = $ldap_srcs[$id]['dn'];
+						$tree['external'] = true;
+						//$tree['sub_branch'] = false;
 						array_push($this->tree['branches'], $tree);
 						$this->tree[$i]['type'] = 'ldap';
 						$this->tree[$i]['src'] = $id;
-					}
+					//	}
+					//}
 					$i++;
 				}
 			}
-			
+
 			$GLOBALS['phpgw']->session->appsession('bo_contactcenter.tree','contactcenter',$this->tree);
 			return $this->tree['branches'];
-		}
-
-		/*!
-			
+			//return null;
+		}
+
+		/*!
+
 			@function get_branch_by_level
 			@abstract Returns the branch and it's informations given the level
 			@author Raphael Derosso Pereira
-			
+
 			@param (string) $level The level to be used
-			
+
 		*/
 		function & get_branch_by_level($level)
@@ -323,10 +463,10 @@
 			$path = @explode('.',$level);
 			$n_ways = count($path);
-			
+
 			if ($n_ways <= 1)
 			{
 				return false;
 			}
-			
+
 			$code = '$branch =& $this->tree[\'branches\']';
 			for ($i = 1; $i < $n_ways-1; $i++)
@@ -338,10 +478,10 @@
 			//echo 'Codigo: '.$code.'<br>';
 			eval($code);
-			
+
 			return $branch;
 		}
 
 		/*!
-		 
+
 		 @function get_info_by_level
 		 @abstract Returns the information about the catalog, given the level
@@ -355,12 +495,12 @@
 			$path = @explode('.',$level);
 			$n_ways = count($path);
-			
+
 			if ($n_ways <= 1)
 			{
 				return false;
 			}
-			
+
 			$info = $this->tree[$path[1]];
-			
+
 			return $info;
 		}
@@ -413,5 +553,5 @@
 
 					$search = $this->get_level_by_branch($catalog, $bcatalog['sub_branch'], (string) $level);
-					
+
 					if ($search !== false)
 					{
@@ -427,13 +567,13 @@
 			return false;
 		}
-		
-		/*!
-		
+
+		/*!
+
 			@function get_actual_catalog
-			@abstract Returns the information about the Catalog that is 
+			@abstract Returns the information about the Catalog that is
 				instantiated
 
 			@author Raphael Derosso Pereira
-		
+
 		*/
 		function get_actual_catalog()
@@ -442,14 +582,14 @@
 			return $catalog;
 		}
-		
-		/*!
-		
+
+		/*!
+
 			@function set_catalog
 			@abstract Sets the actual catalog
 			@author Raphael Derosso Pereira
-			
+
 			@param array $to_catalog The catalog in the format returned by
 				get_available_tree or the level
-		
+
 		*/
 		function set_catalog(& $to_catalog )
@@ -477,5 +617,8 @@
 				$level = $this->get_level_by_branch($to_catalog, $this->tree['branches']);
 			}
-			
+
+			$lvl_vector = explode('.', $level);
+			$id = $lvl_vector[1];
+
 			switch($catalog['type'])
 			{
@@ -499,18 +642,18 @@
 						$call .= ','.implode(',',$args);
 					}
-					
+
 					$call .= ');';
-					
+
 //					print_r($catalog);
 //					echo '<br><br><b>Setando Catalogo '.$catalog['name'].': </b>'.$call.'<br>';
 
 					eval($call);
-								
+
 					return $catalog;
-					
+
 				default: return false;
 			}
 		}
-		
+
 
 
@@ -518,7 +661,7 @@
 		 *                Methods to set general fields                      *
 		\*********************************************************************/
-		
-		/*!
-		
+
+		/*!
+
 			@function add_vcard
 			@abstract Insert a VCard to the squema
@@ -526,5 +669,5 @@
 			@param string $uploaded_file The path to the file that were
 				uploaded.
-		
+
 		*/
 		function add_vcard ( $uploaded_file )
@@ -533,9 +676,9 @@
 
 
-		
+
 		/*********************************************************************\
 		 *                Methods to get general data                        *
 		\*********************************************************************/
-		
+
 	}
 ?>
Index: /trunk/contactcenter/js/cc_tree.js
===================================================================
--- /trunk/contactcenter/js/cc_tree.js	(revision 56)
+++ /trunk/contactcenter/js/cc_tree.js	(revision 284)
@@ -20,5 +20,5 @@
 		throw('dFTree lib must be loaded!');
 	}
-	
+
 	function ccCatalogTree(params)
 	{
@@ -29,5 +29,5 @@
 
 		var _tree = this;
-		
+
 		/* This is the property that holds the Tree Object */
 		this.name = params['name'];
@@ -39,5 +39,5 @@
 		this.Connector = params['connector'];
 
-		/* Build the Inicial Tree */ 
+		/* Build the Inicial Tree */
 		//this._getActualLevel();
 		setTimeout(function(){ _tree._updateTree('0', true);}, 100);
@@ -57,5 +57,5 @@
 				return;
 			}
-			
+
 			if (data['status'] != 'ok')
 			{
@@ -66,5 +66,5 @@
 
 			_this.catalog_perms = parseInt(data['perms']);
-			
+
 			if (_this.afterSetCatalog)
 			{
@@ -75,7 +75,7 @@
 		Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler);
 	}
-	
+
 	ccCatalogTree.prototype.setCatalogSearch = function (catalog) {
-	
+
 		var _this = this;
 		var handler = function (responseText)
@@ -89,5 +89,5 @@
 				return;
 			}
-			
+
 			if (data['status'] != 'ok')
 			{
@@ -100,17 +100,17 @@
 
 			this.afterSetCatalog = ccEmailWin.search.go();
-			
+
 		};
 
 		Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler);
 	}
-		
-	
+
+
 	ccCatalogTree.prototype.select = function(level, search)
 	{
-		if (!search) { 
+		if (!search) {
 			this.tree.openTo(level);
 			this.tree.getNodeById(level)._select();
-		
+
 			if (level != this.actualLevel)
 			{
@@ -129,5 +129,5 @@
 	 *                    Methods For Internal Use                           *
 	\*************************************************************************/
-	
+
 	ccCatalogTree.prototype._waitForTree = function(level, rlevel)
 	{
@@ -142,5 +142,5 @@
 			return;
 		}
-		
+
 		setTimeout(this.name+'._waitForTree(\''+level+'\', '+rlevel+')', 100);
 	}
@@ -176,31 +176,10 @@
 				_this.tree.getNodeById(_this.actualLevel)._select();
 				_this.setCatalog(_this.actualLevel);
-				_this.expandTree();
-
-			}
-		};
-		
+			}
+		};
+
 		Connector.newRequest(this.name+'actual', CC_url+'get_actual_catalog', 'GET', handler);
 	}
 
-	ccCatalogTree.prototype.expandTree = function() {
-		for (i=0; i < this.tree._aNodes.length; i++)
-			this._expandSubTree(this.tree._aNodes[i]);
-	}
-
-	ccCatalogTree.prototype._expandSubTree = function(node) {
-		if ( node._children == '' ) {
-			return;
-		}
-		if (node._children != '') {
-			for (i = 0; i <= node._children.length; i++) {
-				if ( node._io == false )
-					node.changeState();
-				this._expandSubTree(node._children[i]);
-			}
-		}
-	}
-
-
 	ccCatalogTree.prototype._updateTree = function(level, open)
 	{
@@ -222,9 +201,12 @@
 			{
 				showMessage(data['msg']);
-				return;
+				if (data['status'] != 'error')
+				{
+					return;
+				}
 			}
 
 			treeData = data['data'];
-			
+
 			var timeout = 10;
 			var limit = 0;
@@ -261,5 +243,5 @@
 				timeout += 5;
 			}
-			
+
 			_this.treeAvailable = true;
 
@@ -271,4 +253,5 @@
 			}
 		};
+
 		Connector.newRequest(this.name+'update', CC_url+'get_catalog_tree&level='+level, 'GET', handler);
 	}
Index: /trunk/contactcenter/js/ccQuickAddContact.js
===================================================================
--- /trunk/contactcenter/js/ccQuickAddContact.js	(revision 118)
+++ /trunk/contactcenter/js/ccQuickAddContact.js	(revision 284)
@@ -6,12 +6,12 @@
 	}
 
-	
+
 	cQuickAddContact.prototype.showList = function(id){
 		_this = this;
 		var handler = function (responseText) {
 			var contacts = unserialize(responseText);
-			var title = contacts['names_ordered'];			
-			el = document.createElement("DIV");									
-			el.style.visibility = "hidden";									
+			var title = contacts['names_ordered'];
+			el = document.createElement("DIV");
+			el.style.visibility = "hidden";
 			el.style.position = "absolute";
 			el.style.left = "0px";
@@ -21,29 +21,40 @@
 			el.style.height = wHeight + 'px';
 			el.className = "div_cc_rectQuickAddContact";
-			el.id = id+':cc_rectQuickAddContact';																							
-			document.body.appendChild(el);																
-			el.innerHTML = "";								
+			el.id = id+':cc_rectQuickAddContact';
+			document.body.appendChild(el);
+			el.innerHTML = "";
 
 			var fieldsTop = 10;
 			var fieldsSpace = 30;
 			fields = new Array(Element('cc_qa_alias').value, Element('cc_qa_given_names').value, Element('cc_qa_family_names').value, Element('cc_qa_phone').value, Element('cc_qa_email').value);
-			
+
 			for (i=0; i<fields.length; i++) {
 				var contact = contacts[i] != null ? contacts[i] : '';
 				el.innerHTML += '<span id="ccQuickAddCT' + i + id + '" style="position: absolute; top: ' +  (fieldsTop+i*fieldsSpace) + 'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">' + fields[i] + '</span>';
-				el.innerHTML += '<input id="ccQuickAddCI' + i + id + '" type="text" value="' + contact + '" maxlength="50" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">';
+				if (i == 0)
+				{
+					el.innerHTML += '<input id="ccQuickAddCI' + i + id + '" type="text" value="' + contact + '" maxlength="30" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">';
+				}
+				else if (i == 4)
+				{
+					el.innerHTML += '<input id="ccQuickAddCI' + i + id + '" type="text" value="' + contact + '" maxlength="100" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">';
+				}
+				else
+				{
+					el.innerHTML += '<input id="ccQuickAddCI' + i + id + '" type="text" value="' + contact + '" maxlength="50" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">';
+				}
 			}
-			
+
 			el.innerHTML +='<div id="ccQAFuncitons" style="border: 0px solid black; width: 220px; height: 20px">' +
-				'<input title="' + Element('cc_qa_save').value + '"  type="button" onclick="ccQuickAddContact.send(\'' + id + '\');" value="' + Element('cc_qa_save').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 75px; width: 60px" />' +
-				'<input title="' + Element('cc_qa_close').value + '" type="button" onclick="ccQuickAddContact.fechar(\'' + id + '\');" value="' + Element('cc_qa_close').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 140px; width: 60px" />' +
+				'<input title="ccQASave" type="button" onclick="ccQuickAddContact.send(\'' + id + '\');" value="' + Element('cc_qa_save').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 75px; width: 60px" />' +
+				'<input title="ccQAClear" type="button" onclick="ccQuickAddContact.fechar(\'' + id + '\');" value="' + Element('cc_qa_clear').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 140px; width: 60px" />' +
 				'</div>';
 			el.innerHTML +=	"<br>";
-								
+
 			_this.showWindow(el);
 		}
-		
+
 		div = document.getElementById(id+':cc_rectQuickAddContact');
-				
+
 		if(div)
 			this.showWindow(div);
@@ -52,10 +63,10 @@
 		}
 	}
-	
+
 	cQuickAddContact.prototype.showWindow = function (div)
-	{						
+	{
 		if(! this.arrayWin[div.id]) {
 
-			win = new dJSWin({			
+			win = new dJSWin({
 				id: 'ccQuickAddContact_'+div.id,
 				content_id: div.id,
@@ -64,18 +75,18 @@
 				title_color: '#3978d6',
 				bg_color: '#eee',
-				title: Element('ccQATitle').value,						
+				title: Element('ccQATitle').value,
 				title_text_color: 'white',
 				button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif',
 				border: true });
-			
+
 			this.arrayWin[div.id] = win;
-			win.draw();			
+			win.draw();
 		}
 		else {
 			win = this.arrayWin[div.id];
-		}			
+		}
 		win.open();
 	}
-	
+
 	cQuickAddContact.prototype.send = function (id)
 	{
@@ -104,5 +115,5 @@
 				return;
 			}
-			
+
 			win.close();
 
@@ -121,11 +132,11 @@
 			}
 		}
-	
+
 		var sdata = new Array();
-		
+
 		for (var f = 0; f < 5; f++){
 			sdata[f] = document.getElementById('ccQuickAddCI' + f + id).value;
 		}
-		
+
 		//Utiliza expressão regular para validar email
 		var reEmail = /^[A-Za-z\d_-]+(\.[A-Za-z\d_-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
@@ -136,27 +147,27 @@
 			return false;
 		}
-		
+
 		//Utiliza expressão regular para validar telefone
 		var rePhone = /^[0-9|(-)| |-]{0,15}$/;
-		
+
 		if (!rePhone.test(sdata[3])){
 			alert("O número de telefone '" + sdata[3] + "' não é valido! Utilize apenas números.\n" +
 			"Parenteses, traços ou espaços em branco podem ser usados como carácter separador.");
 			return false;
-		} 
-		
+		}
+
 		var sdata = 'add='+escape(serialize(sdata));
 
 		Connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata);
 	}
-	
+
 	cQuickAddContact.prototype.fechar = function(id) {
-	
+
 		div = document.getElementById(id+':cc_rectQuickAddContact');
 		win = this.arrayWin[div.id];
 		win.close();
 	}
-	
-	
+
+
 /* Build the Object */
 	var ccQuickAddContact ;
@@ -164,10 +175,10 @@
 
 	if (is_ie)
-	{ 
-		document.body.onload = function (e) 
-		{ 
+	{
+		document.body.onload = function (e)
+		{
 			cQuickAddContact_pre_load();
 			ccQuickAddContact = new cQuickAddContact();
-			
+
 		};
 	}
Index: /trunk/contactcenter/js/cc_search.js
===================================================================
--- /trunk/contactcenter/js/cc_search.js	(revision 2)
+++ /trunk/contactcenter/js/cc_search.js	(revision 284)
@@ -60,5 +60,5 @@
 		this.DOMinput.value = params['value'] ? params['value'] : '';
 		this.DOMinput.style.width = params['input_width'] ? params['input_width'] : '200px';
-		this.DOMinput.onkeypress = function (e) { 
+		this.DOMinput.onkeypress = function (e) {
 				if (is_ie)
 				{
@@ -86,5 +86,5 @@
 		if (params['progress_color'])
 			this.DOMprogHold.style.color = params['progress_color'];
-		
+
 		this.DOMresult.style.position = 'absolute';
 		this.DOMresult.style.top = params['progress_top'] ? params['progress_top'] : '0px';
@@ -96,5 +96,5 @@
 			this.DOMresult.style.color = params['progress_color'];
 
-		this.DOMholder.appendChild(this.DOMdiv);	
+		this.DOMholder.appendChild(this.DOMdiv);
 		this.DOMdiv.appendChild(this.DOMfields);
 		this.DOMdiv.appendChild(this.DOMinput);
@@ -104,36 +104,136 @@
 		this.DOMdiv.appendChild(this.DOMresult);
 	}
-	
+
 	ccSearchClass.prototype.go = function()
 	{
 		var data = new Array();
-		
+
 		this.DOMresult.innerHTML = '';
 
 		//TODO: Make Generic!
 		var type = Element('cc_type_contact').value;
-		
+
 		data['fields']           = new Array();
-		
+
 		if (type == 'groups') {
-			data['fields']['id']     = 'group.id_group';			
+			data['fields']['id']     = 'group.id_group';
 			data['fields']['search'] = 'group.title';
-		}		
-		else {			
-			data['fields']['id']     = 'contact.id_contact';		
-			data['fields']['search'] = 'contact.names_ordered';					
-		}
-		
+		}
+		else {
+			data['fields']['id']     = 'contact.id_contact';
+			data['fields']['search'] = 'contact.names_ordered';
+		}
+
 		data['search_for']       = this.DOMinput.value;
 		//data['recursive']        = this.recursive.checked ? true : false;
-		
+		// Exige que a consulta por nome seja feita com no mínimo 4 caracteres
+		var search_for = data['search_for'].split(' ');
+		var greaterThan4 = false;
+
+		for (i = 0; i < search_for.length; i++)
+		{
+			if (search_for[i].length >= 4)
+			{
+				greaterThan4 = true;
+			}
+		}
+
+		if (!greaterThan4){
+			alert("Favor fazer a consulta com pelo menos 4 caracteres!");
+			return;
+		}
+
 		var _this = this;
 
+	var handler = function (responseText)
+	{
+		var data = new Array();
+		data = unserialize(responseText);
+
+		ccSearchUpdate();
+
+		letter = 'search';
+
+		if ( letter != CC_actual_letter )
+		{
+			CC_actual_page = '1';
+		}
+		else
+		{
+			CC_actual_page = parseInt(data[1]);
+		}
+
+		CC_actual_letter = letter;
+
+		if (CC_max_cards[0] == 0)
+		{
+
+			if(CC_visual == 'cards')
+				drawCards(0);
+			else if(CC_visual == 'table')
+				drawTable(0);
+
+			setPages(0,0);
+			return;
+		}
+
+		if (data[0] == '0')
+		{
+			Element('cc_type_contact').value = data[1];
+			CC_npages = 0;
+			CC_actual_page = 1;
+			if(CC_visual == 'cards')
+				drawCards(0);
+			else if(CC_visual == 'table')
+				drawTable(0);
+			setPages(0,0);
+			return;
+		}
+		else
+		{
+			Element('cc_type_contact').value = data[10];
+		}
+
+//		Element('cc_debug').innerHTML = responseText;
+
+		if (typeof(data) != 'object')
+		{
+			showMessage(Element('cc_msg_err_contacting_server').value);
+			return;
+		}
+
+		if (typeof(data[3]) == 'object')
+		{
+			CC_npages = parseInt(data[0]);
+			CC_actual_page = parseInt(data[1]);
+			if(CC_visual == 'cards')
+				drawCards(data[3].length, data[10]);
+			else if(CC_visual == 'table')
+				drawTable(data[3].length, data[10]);
+			resizeWindow();
+			populateCards(data, data[10]);
+			setPages(data[0], data[1]);
+		}
+		else if (data['error'])
+		{
+			showMessage(data['error']);
+		}
+		else
+		{
+			showMessage(Element('cc_msg_err_contacting_server').value);
+			return;
+		}
+
+
+	};
+
+
+/*
 		var handler = function (responseText)
 		{
 			Element('cc_debug').innerHTML = responseText;
-			
+
 			var data = unserialize(responseText);
-			
+
 			if (!data || !data['status'])
 			{
@@ -147,5 +247,5 @@
 				_this.DOMresult.innerHTML = data['msg'];
 				setTimeout(function(){_this.DOMresult.innerHTML = '';}, 1000);
-				
+
 				if (_this.onSearchFinish)
 				{
@@ -163,5 +263,13 @@
 			}
 
-			//showMessage(data['msg']);
+			// Mostra a mensagem se a busca retornar mais de 300 resultados.
+			if (data['data'].length > 300)
+			{
+
+				TODO: Usar o esquema de tradução do expresso para este alert
+
+				alert("Mais de 300 resultados foram retornados!\n" +
+					"Favor refinar sua busca.");
+			}
 
 			if (_this.onSearchFinish)
@@ -170,5 +278,6 @@
 			}
 		};
-		
-		this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
+*/
+		var info = "letter="+'search'+"&page="+'1'+"&data="+serialize(data);
+		this.Connector.newRequest('get_cards_data', CC_url+'get_cards_data', 'POST', handler, info);
 	}
Index: /trunk/contactcenter/js/ccAddGroup.js
===================================================================
--- /trunk/contactcenter/js/ccAddGroup.js	(revision 118)
+++ /trunk/contactcenter/js/ccAddGroup.js	(revision 284)
@@ -158,5 +158,5 @@
 		
 		if(!this.title.value) {
-			alert(Element('cc_msg_fill_field_name').value);
+			alert('Preencha o campo obrigatório "Nome Completo"');
 			this.title.focus();
 			return false;
@@ -164,5 +164,5 @@
 				
 		if(! contacts.length) {
-			alert(Element('cc_msg_add_contact_to_group').value);
+			alert('Você não adicionou nenhum contato para esse grupo');
 			return false;
 		}
Index: /trunk/contactcenter/js/cc.js
===================================================================
--- /trunk/contactcenter/js/cc.js	(revision 258)
+++ /trunk/contactcenter/js/cc.js	(revision 284)
@@ -57,5 +57,5 @@
 var CC_full_add_const = false;
 var CC_full_add_photo = false;
-	
+
 var CC_last_height = window.innerHeight;
 var CC_last_width = window.innerWidth;
@@ -90,5 +90,5 @@
 		 photo_input = photo_frame.contentDocument.createElement('input');
 	}
-	
+
 	photo_frame.id = 'cc_photo_frame';
 	photo_frame.style.position = 'absolute';
@@ -96,12 +96,12 @@
 	photo_frame.style.top = '600px';
 	photo_frame.style.left = '0px';
-	
+
 	photo_form.id = 'cc_photo_form';
 	photo_form.method = 'POST';
 	photo_form.enctype = 'multipart/form-data';
-	
+
 	photo_input.id = 'cc_photo_input';
 	photo_input.type = 'file';
-	
+
 	if (is_ie)
 	{
@@ -113,5 +113,5 @@
 	}
 	photo_form.appendChild(photo_input);
-	
+
 }
 
@@ -121,5 +121,5 @@
 	var obj = Element(id);
 	var max = obj.options.length;
-	
+
 	if (option == undefined)
 	{
@@ -161,5 +161,5 @@
 function openFullAdd(){
 	// Build the FullAdd Window.
-	if(!fullAddWin && !is_ie) 
+	if(!fullAddWin && !is_ie)
 		__f();
 
@@ -168,5 +168,5 @@
 	fullAddWin.open();
 	tabs._showTab('cc_contact_tab_0');
-	Element("cc_conn_type_1").checked = false;	
+	Element("cc_conn_type_1").checked = false;
 	Element("cc_conn_type_2").checked = false;
 	Element("cc_conn_type_sel").disabled = true;
@@ -189,5 +189,5 @@
 function editGroup(id){
 	populateEditGroup(id);
-	ccAddGroup.window.open();			
+	ccAddGroup.window.open();
 }
 /*
@@ -199,5 +199,5 @@
 {
 	CC_full_add_const = false;
-	
+
 	setTimeout('populateFullAddConstAsync()', 10);
 }
@@ -207,9 +207,9 @@
 	var handler = function(responseText)
 	{
-		//Element('cc_debug').innerHTML = responseText;		
+		//Element('cc_debug').innerHTML = responseText;
 		var data = unserialize(responseText);
 		var i = 1;
 		var j;
-		
+
 		if (typeof(data) != 'object')
 		{
@@ -217,5 +217,5 @@
 			return;
 		}
-		
+
 		/* Populate Prefixes */
 		for (j in data[0])
@@ -224,5 +224,5 @@
 			i++;
 		}
-		
+
 		/* Populate Suffixes */
 		i = 1;
@@ -246,13 +246,13 @@
 		{
 			Element('cc_addr_countries').options[i] = new Option(data[3][j], j);
-			
+
 			if (j == 'BR' || j == 'br')
 			{
 				CC_br_index = i;
 			}
-			
+
 			i++;
 		}
-		
+
 		/* Populate Connection Types */
 		i = 1;
@@ -262,5 +262,5 @@
 			i++;
 		}
-		
+
 		/* Populate Relations Types */
 		i = 0;
@@ -270,5 +270,5 @@
 			i++;
 		}
-		
+
 		CC_full_add_const = true;
 
@@ -305,26 +305,31 @@
 {
 	var handler = function(responseText)
-	{			
-		var data = unserialize(responseText);			
-		Element('group_id').value = data['id_group'];								
-		var options_contact_list = Element('contact_list');
-		if(data['contact_list']) {					
-			options_contact_list.innerHTML = data['contact_list'];
+	{
+		var data = unserialize(responseText);
+		Element('group_id').value = data['id_group'];
+
+		if(data['contact_list']) {
+			for(i = 0; i < data['contact_list'].length; i++) {
+				option = document.createElement('option');
+				option.value = data['contact_list'][i]['id_connection'];
+				option.text = data['contact_list'][i]['names_ordered']+' ('+data['contact_list'][i]['connection_value']+')';
+				Element('contact_list').options[Element('contact_list').options.length] = option;
+			}
 		}
 
 		if(data['id_group']) {
-		
-			if(data['contact_in_list']) {					
-				for(i = 0; i < data['contact_in_list'].length; i++) {				
+
+			if(data['contact_in_list']) {
+				for(i = 0; i < data['contact_in_list'].length; i++) {
 					option = document.createElement('option');
 					option.value = data['contact_in_list'][i]['id_connection'];
-					option.text = data['contact_in_list'][i]['names_ordered']+' ('+data['contact_in_list'][i]['connection_value']+')';				
+					option.text = data['contact_in_list'][i]['names_ordered']+' ('+data['contact_in_list'][i]['connection_value']+')';
 					Element('contact_in_list').options[Element('contact_in_list').options.length] = option;
 				}
-			}		
-			
+			}
+
 			Element('title').value =  data['title'];
 		}
-				
+
 		if (typeof(data) != 'object' || data['result'] != 'ok')
 		{
@@ -333,8 +338,8 @@
 		}
 	};
-		
+
 	id = typeof(id) == 'undefined' ? id = 0 :  id;
-	
-	ccAddGroup.clear(true);			
+
+	ccAddGroup.clear(true);
 	Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id, 'GET', handler);
 }
@@ -371,5 +376,5 @@
 		return false;
 	}
-	
+
 	/* First thing: Send Photo */
 	if (Element('cc_pd_select_photo').value != '' && !is_ie)
@@ -389,5 +394,5 @@
 			frame = old_frame;
 		}
-		
+
 		frame.id = 'cc_photo_frame';
 		frame.style.visibility = 'hidden';
@@ -398,5 +403,5 @@
 
 		form = frame.contentDocument.createElement('form');
-		
+
 		var id_contact = Element('cc_full_add_contact_id').value;
 		form.id = 'cc_form_photo';
@@ -404,8 +409,8 @@
 		form.enctype = 'multipart/form-data';
 		form.action = 'http://'+ document.domain + Element('cc_root_dir').value+'../index.php?menuaction=contactcenter.ui_data.data_manager&method=post_photo&id='+(id_contact != '' && id_contact != 'null' ? id_contact : '');
-		
+
 		var input_clone = Element('cc_pd_select_photo').cloneNode(false);
 		form.appendChild(input_clone);
-		
+
 		frame.contentDocument.body.appendChild(form);
 		form.submit();
@@ -461,7 +466,7 @@
 	var empty = true;
 	var replacer = '__##AND##__';
-	
+
 	data['commercialAnd'] = replacer;
-	
+
 	if (Element('cc_full_add_contact_id').value != '' && Element('cc_full_add_contact_id').value != 'null')
 	{
@@ -472,5 +477,5 @@
 	/* Status: Full Added */
 	data['id_status'] = CC_STATUS_FULL_ADD;
-	
+
 	/* Personal Data */
 	data['alias']         = replaceComAnd(Element('cc_pd_alias').value, replacer);
@@ -510,5 +515,5 @@
 				data['connections'] = new Array();
 			}
-			
+
 			for (var i in CC_contact_full_info['connections'][type])
 			{
@@ -522,5 +527,5 @@
 					data['connections']['connection'+connNumber] = new Array(5);
 				}
-				
+
 				data['connections']['connection'+connNumber]['id_connection'] = CC_contact_full_info['connections'][type][i]['id'];
 				data['connections']['connection'+connNumber]['id_typeof_connection'] = type;
@@ -531,10 +536,10 @@
 						data['connections']['connection'+connNumber]['connection_is_default']  = 'TRUE';
 					}
-					else 
+					else
 						data['connections']['connection'+connNumber]['connection_is_default']  = 'FALSE';
 				}
 
 //				data['connections']['connection'+connNumber].length = 5;
-				
+
 				empty = false;
 				connNumber++;
@@ -543,5 +548,5 @@
 
 		}
-		
+
 		if (!empty)
 		{
@@ -550,9 +555,9 @@
 		}
 	}
-	
+
 	if (CC_contact_full_info['removed_conns'])
 	{
 		empty = false;
-		
+
 		if (typeof(data['connections']) != 'object')
 		{
@@ -589,6 +594,6 @@
 			for (var i in CC_contact_full_info['connections'][type]){
 				if((CC_contact_full_info['connections'][type][i]['value'].length < 4) ||
-					(!comp.test(CC_contact_full_info['connections'][type][i]['value']))){ 
-					showMessage('Endereço para conexão de ' + CC_contact_full_info['connections'][type][i]['name'] + ', não é válido');
+					(!comp.test(CC_contact_full_info['connections'][type][i]['value']))){
+					showMessage('Endereï¿œo para conexï¿œo de ' + CC_contact_full_info['connections'][type][i]['name'] + ', nï¿œo ï¿œ vï¿œlido');
 					return false;
 				}
@@ -596,9 +601,9 @@
 			var _options_default = Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default");
 			if(_options_default.value == '-1') {
-				alert("É necessário escolher um "+ (type == 1 ? 'E-mail' : 'Telefone')+" como padrão!");
+				alert("ï¿œ necessï¿œrio escolher um "+ (type == 1 ? 'E-mail' : 'Telefone')+" como padrï¿œo!");
 				return false;
 			}
 		}
-		
+
 	}
 
@@ -609,5 +614,5 @@
 
 /********* Personal Data Functions *********/
-/* 
+/*
  * data[0] => cc_pd_select_photo
  * data[1] => cc_pd_alias
@@ -657,8 +662,8 @@
 {
 	Element('cc_addr_types').selectedIndex = 0;
-	
+
 	Element('cc_addr_countries').selectedIndex = 0;
 	Element('cc_addr_countries').disabled = true;
-	
+
 	Element('cc_addr_states').selectedIndex = 0;
 	Element('cc_addr_states').disabled = true;
@@ -711,7 +716,7 @@
 	var type = Element('cc_addr_types');
 	var oldSelected = type.value;
-	
+
 	saveAddressFields();
-	
+
 	if (oldSelected == '_NONE_')
 	{
@@ -719,13 +724,13 @@
 		return true;
 	}
-	
+
 	CC_addr_last_selected = type.selectedIndex;
-	
+
 	Element('cc_addr_countries').disabled = false;
-	
+
 	var data = CC_contact_full_info['addresses'];
 	var addrIndex  = 'address'+Element('cc_addr_types').value;
-	
-	if (typeof(data) != 'object' || typeof(data[addrIndex]) != 'object') 
+
+	if (typeof(data) != 'object' || typeof(data[addrIndex]) != 'object')
 	{
 		resetAddressFields();
@@ -736,9 +741,9 @@
 		return true;
 	}
-	
+
 	var addrTypeID = Element('cc_addr_types').value;
-	
+
 	data = CC_contact_full_info['addresses'][addrIndex];
-	
+
 	Element('cc_addr_id').value          			 = data['id_address']		? data['id_address']			: '';
 	Element('cc_addr_1').value            			= data['address1']			? data['address1']				: '';
@@ -762,5 +767,5 @@
 		states.selectedIndex = 0;
 		clearSelectBox(states, 4);
-		updateAddrCities();	
+		updateAddrCities();
 		return;
 	}
@@ -777,11 +782,11 @@
 	{
 		var data = unserialize(responseText);
-		
+
 		clearSelectBox(states, 1);
-			
+
 		if (typeof(data) != 'object')
 		{
 			showMessage(Element('cc_msg_err_contacting_server').value);
-	
+
 			return;
 		}
@@ -790,5 +795,5 @@
 		{
 			states.disabled = true;
-			cities.disabled = true;			
+			cities.disabled = true;
 			states.selectedIndex = 0;
 			cities.selectedIndex = 0;
@@ -830,5 +835,5 @@
 		}
 	};
-	
+
 	Connector.newRequest('populateStates', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_states&country='+Element('cc_addr_countries').value, 'GET', handler);
 }
@@ -858,5 +863,5 @@
 			newState.disabled = false;
 			updateAddrNewStateOnMouseOut();
-			
+
 			cities.disabled = false;
 			clearSelectBox(cities, 3);
@@ -869,11 +874,11 @@
 		case '_NOSTATE_':
 			clearSelectBox(cities, 3);
-			
+
 			cities.disabled = false;
 			cities.selectedIndex = 0;
-			
+
 			requestStr = 'country='+Element('cc_addr_countries').value;
 			break;
-		
+
 		default:
 			requestStr = 'country='+Element('cc_addr_countries').value+'&state='+states.value;
@@ -890,15 +895,15 @@
 {
 	var cities = Element('cc_addr_cities');
-	
+
 	var handler = function (responseText)
 	{
 		var data = unserialize(responseText);
-		
+
 		clearSelectBox(cities, 1);
-		
+
 		if (typeof(data) != 'object')
 		{
 			showMessage(Element('cc_msg_err_contacting_server').value);
-			
+
 			return;
 		}
@@ -945,5 +950,5 @@
 		}
 	};
-	
+
 	Connector.newRequest('populateCities', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_cities&'+requestStr, 'GET', handler);
 }
@@ -951,5 +956,5 @@
 function updateAddrNewStateOnMouseOver ()
 {
-	if (Element('cc_addr_states_new').value == Element('cc_msg_type_state').value && Element('cc_addr_states').selectedIndex == 1) 
+	if (Element('cc_addr_states_new').value == Element('cc_msg_type_state').value && Element('cc_addr_states').selectedIndex == 1)
 	{
 		Element('cc_addr_states_new').value = '';
@@ -959,5 +964,5 @@
 function updateAddrNewStateOnMouseOut ()
 {
-	if (Element('cc_addr_states_new').value.length == 0 && Element('cc_addr_states').selectedIndex == 1) 
+	if (Element('cc_addr_states_new').value.length == 0 && Element('cc_addr_states').selectedIndex == 1)
 	{
 		Element('cc_addr_states_new').value = Element('cc_msg_type_state').value;
@@ -979,5 +984,5 @@
 		return;
 	}
-	
+
 	Element('cc_addr_1').readonly = false;
 	Element('cc_addr_1').disabled = false;
@@ -1009,5 +1014,5 @@
 
 			//resetAddrFillingFields();
-			
+
 			return;
 
@@ -1017,5 +1022,5 @@
 			newCity.disabled = false;
 			updateAddrNewCityOnMouseOut();
-			
+
 			break;
 
@@ -1031,5 +1036,5 @@
 function updateAddrNewCityOnMouseOver ()
 {
-	if (Element('cc_addr_cities_new').value == Element('cc_msg_type_city').value && Element('cc_addr_cities').selectedIndex == 1) 
+	if (Element('cc_addr_cities_new').value == Element('cc_msg_type_city').value && Element('cc_addr_cities').selectedIndex == 1)
 	{
 		Element('cc_addr_cities_new').value = '';
@@ -1039,5 +1044,5 @@
 function updateAddrNewCityOnMouseOut ()
 {
-	if (Element('cc_addr_cities_new').value.length == 0 && Element('cc_addr_cities').selectedIndex == 1) 
+	if (Element('cc_addr_cities_new').value.length == 0 && Element('cc_addr_cities').selectedIndex == 1)
 	{
 		Element('cc_addr_cities_new').value = Element('cc_msg_type_city').value;
@@ -1053,10 +1058,10 @@
 		return true;
 	}
-	
-	var addrFields = new Array('cc_addr_1', 
-	                           'cc_addr_2', 
-							   'cc_addr_complement', 
+
+	var addrFields = new Array('cc_addr_1',
+	                           'cc_addr_2',
+							   'cc_addr_complement',
 							   'cc_addr_other',
-							   'cc_addr_postal_code', 
+							   'cc_addr_postal_code',
 							   'cc_addr_po_box',
 							   'cc_addr_countries',
@@ -1065,5 +1070,5 @@
 
 	var empty = true;
-	
+
 	for (var i = 0; i < 8; i++)
 	{
@@ -1074,5 +1079,5 @@
 		}
 	}
-				
+
 	if (empty)
 	{
@@ -1103,5 +1108,5 @@
 		default:
 			addrInfo['id_country'] = Element('cc_addr_countries').value;
-		
+
 	}
 
@@ -1117,5 +1122,5 @@
 		default:
 			addrInfo['id_state'] = Element('cc_addr_states').value;
-		
+
 	}
 
@@ -1130,6 +1135,6 @@
 		default:
 			addrInfo['id_city'] = Element('cc_addr_cities').value;
-		
-	}	
+
+	}
 
 	addrInfo['id_typeof_address']  = Element('cc_addr_types').options[lastIndex].value;
@@ -1144,15 +1149,15 @@
 	CC_contact_full_info['addresses']['address'+Element('cc_addr_types').options[lastIndex].value] = addrInfo;
 
-	if (Element('cc_addr_cities').value == '_NEW_' && 
+	if (Element('cc_addr_cities').value == '_NEW_' &&
 	    Element('cc_msg_type_city').value !=  Element('cc_addr_cities_new').value &&
 		Element('cc_addr_cities_new').value != '')
 	{
 		var addrRootInfo = CC_contact_full_info['addresses']['new_cities'];
-		
+
 		if (!addrRootInfo)
 		{
 			addrRootInfo = new Array();
 		}
-		
+
 		var i = addrRootInfo.length;
 		addrRootInfo[addrInfo['id_typeof_address']] = new Array();
@@ -1163,15 +1168,15 @@
 	}
 
-	if (Element('cc_addr_states').value == '_NEW_' && 
-	    Element('cc_msg_type_state').value !=  Element('cc_addr_states_new').value && 
+	if (Element('cc_addr_states').value == '_NEW_' &&
+	    Element('cc_msg_type_state').value !=  Element('cc_addr_states_new').value &&
 		Element('cc_addr_states_new').value != '')
 	{
 		var addrRootInfo = CC_contact_full_info['addresses']['new_states'];
-		
+
 		if (!addrRootInfo)
 		{
 			addrRootInfo = new Array();
 		}
-		
+
 		var i = addrRootInfo.length;
 		addrRootInfo[addrInfo['id_typeof_address']] = new Array();
@@ -1203,16 +1208,27 @@
 	for(idx_conn; idx_conn < cc_conn_default.options.length; idx_conn++)
 		if(cc_conn_default.options[idx_conn].value == _label)
-			break;	
-	
+			break;
+
 	if(idx_conn == cc_conn_default.options.length)
 		cc_conn_default.options[idx_conn] = new Option (_label,_label, false,false);
-			
+
 	if (!document.all)
 	{
-		return '<td style="position: absolute; left: 0; top: 0; z-index: -1; visibility: hidden"><input id="cc_conn_id_' + CC_conn_count + '" type="hidden" value="_NEW_"><input id="cc_conn_is_default_' + CC_conn_count + '" type="hidden" value="false"></td>'+
-		//'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
-		'<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px;" align="right"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+'</span></td>' +
-		'<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px;" type="text">&nbsp;' +
-		'<img align="top" alt="X" src="templates/default/images/x.png" style="width:18px; height:18px" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"></td>';
+		if (Element("cc_conn_type_1").checked)
+		{
+			return '<td style="position: absolute; left: 0; top: 0; z-index: -1; visibility: hidden"><input id="cc_conn_id_' + CC_conn_count + '" type="hidden" value="_NEW_"><input id="cc_conn_is_default_' + CC_conn_count + '" type="hidden" value="false"></td>'+
+			//'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
+			'<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px;" align="right"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+'</span></td>' +
+			'<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px;" maxlength="100" type="text">&nbsp;' +
+			'<img align="top" alt="X" src="templates/default/images/x.png" style="width:18px; height:18px" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"></td>';
+		}
+		else if (Element("cc_conn_type_2").checked)
+		{
+			return '<td style="position: absolute; left: 0; top: 0; z-index: -1; visibility: hidden"><input id="cc_conn_id_' + CC_conn_count + '" type="hidden" value="_NEW_"><input id="cc_conn_is_default_' + CC_conn_count + '" type="hidden" value="false"></td>'+
+			//'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
+			'<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px;" align="right"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+'</span></td>' +
+			'<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px;" maxlength="50" type="text">&nbsp;' +
+			'<img align="top" alt="X" src="templates/default/images/x.png" style="width:18px; height:18px" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"></td>';
+		}
 	}
 	else
@@ -1238,5 +1254,5 @@
 		img.align = 'top';
 		img.onclick = function(e){ removeConnField(remove_id);};
-		
+
 		for (var i = 0; i < 3; i++)
 		{
@@ -1249,5 +1265,5 @@
 
 		inputs[1].id = 'cc_conn_name_'+CC_conn_count;
-		inputs[1].type = 'hidden';		
+		inputs[1].type = 'hidden';
 
 		inputs[2].id = 'cc_conn_value_'+CC_conn_count;
@@ -1278,19 +1294,19 @@
 		|| typeof(CC_contact_full_info['connections'][CC_conn_last_selected]) == 'undefined'
 		|| typeof(CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]) == 'undefined');
-	
-	if(_emptyLine) {	
-		
+
+	if(_emptyLine) {
+
 		if(Element("cc_conn_type_sel").value == '-1'){
-				return false;	
-		}
-		
+				return false;
+		}
+
 		for(k = 0; k < CC_conn_count; k++) {
 			if(Element("cc_conn_name_"+k) && Element("cc_conn_name_"+k).value != "" && Element("cc_conn_name_"+k).value == Element("cc_conn_type_sel").value) {
-				alert('Você já possui uma entrada para o tipo "'+Element("cc_conn_type_sel").value+'"!');
-				Element("cc_conn_type_sel").options.selectedIndex = 0;				
+				alert('Vocï¿œ jï¿œ possui uma entrada para o tipo "'+Element("cc_conn_type_sel").value+'"!');
+				Element("cc_conn_type_sel").options.selectedIndex = 0;
 				return false;
 			}
 		}
-	}	
+	}
 	if (!document.all)
 	{
@@ -1319,5 +1335,5 @@
 
 function connRemoveLine(id)
-{	
+{
 	var p = Element(id).parentNode;
 	var cc_conn_default = Element("cc_phone_default").style.display == '' ? Element("cc_phone_default") : Element("cc_email_default");
@@ -1358,5 +1374,5 @@
 		}
 	}
-	
+
 	CC_conn_count = 0;
 }
@@ -1380,5 +1396,5 @@
 function updateConnFields()
 {
-	
+
 	var connID;
 	var i;
@@ -1389,18 +1405,15 @@
 	var cc_conn_is_default = '';
 	var selected_index = '';
-	
+
 	cc_conn_type_sel.disabled = false;
 	div_cc_conn_is_default.style.display = "";
-	
+
 	for(var i = 0;i < cc_conn_type_sel.options.length; i++)
-		cc_conn_type_sel.options[i--] = null;	
-		
+		cc_conn_type_sel.options[i--] = null;
+
 	if(Element('cc_conn_type_1').checked) {
-	    var lang_new_email = Element('cc_msg_new_email').value;
-	    var lang_main = Element('cc_msg_main').value;
-	    var lang_alternative = Element('cc_msg_alternative').value;	
-	    cc_conn_type_sel[0] = new Option(lang_new_email,'-1');	
-	    cc_conn_type_sel[1] = new Option(lang_main,lang_main);
-	    cc_conn_type_sel[2] = new Option(lang_alternative,lang_alternative);	
+		cc_conn_type_sel[0] = new Option('Novo Email...','-1');
+		cc_conn_type_sel[1] = new Option('Principal','Principal');
+		cc_conn_type_sel[2] = new Option('Alternativo','Alternativo');
 		connID = 1;
 		selected_index = cc_email_default.options.selectedIndex;
@@ -1409,24 +1422,17 @@
 		}
 
-		var lang_select_email = Element('cc_msg_select_email').value;
-		cc_email_default.options[0] = new Option(lang_select_email,'-1');		
+		cc_email_default.options[0] = new Option('Selecionar Email...','-1');
+
 		cc_phone_default.style.display = 'none';
-		cc_email_default.style.display = '';			
+		cc_email_default.style.display = '';
 		cc_conn_is_default = cc_email_default;
 	}
 	else if(Element('cc_conn_type_2').checked) {
-	    var lang_new_telephone = Element('cc_msg_new_phone').value;
-	    var lang_home = Element('cc_msg_home').value;
-	    var lang_cellphone = Element('cc_msg_cellphone').value;
-	    var lang_work = Element('cc_msg_work').value;
-	    var lang_fax = Element('cc_msg_fax').value;
-	    var lang_pager = Element('cc_msg_pager').value;
-	    cc_conn_type_sel[0] = new Option(lang_new_telephone,'-1');	
-	    cc_conn_type_sel[1] = new Option(lang_home,lang_home);
-	    cc_conn_type_sel[2] = new Option(lang_cellphone,lang_cellphone);	
-	    cc_conn_type_sel[3] = new Option(lang_work,lang_work);
-	    cc_conn_type_sel[4] = new Option(lang_fax,lang_fax);
-	    cc_conn_type_sel[5] = new Option(lang_pager,lang_pager);
-
+		cc_conn_type_sel[0] = new Option('Novo Telefone...','-1');
+		cc_conn_type_sel[1] = new Option('Residencial','Residencial');
+		cc_conn_type_sel[2] = new Option('Celular','Celular');
+		cc_conn_type_sel[3] = new Option('Comercial','Comercial');
+		cc_conn_type_sel[4] = new Option('Fax','Fax');
+		cc_conn_type_sel[5] = new Option('Pager','Pager');
 		connID = 2;
 		selected_index = cc_phone_default.options.selectedIndex;
@@ -1435,11 +1441,10 @@
 		}
 
-		var lang_choose_phone = Element('cc_msg_choose_phone').value;		
-		cc_phone_default.options[0] = new Option(lang_choose_phone,'-1');
+		cc_phone_default.options[0] = new Option('Selecionar Telefone...','-1');
 		cc_email_default.style.display = 'none';
 		cc_phone_default.style.display = '';
 		cc_conn_is_default = cc_phone_default;
 	}
-			
+
 	Element("cc_conn_type_sel").options.selectedIndex = 0;
 	/* First save the data */
@@ -1447,12 +1452,12 @@
 
 	CC_conn_last_selected = connID;
-	
+
 	clearConn();
-	
+
 	if (connID == '_NONE_')
 	{	cc_conn_is_default.disabled = true;
 		return;
 	}
-	
+
 	/* If no data already available, return */
 	if (!CC_contact_full_info['connections'])
@@ -1478,5 +1483,5 @@
 			}
 		}
-	}	
+	}
 	if(cc_conn_is_default.options.length > selected_index)
 		cc_conn_is_default.options.selectedIndex = (selected_index == "-1" ? 0 : selected_index);
@@ -1499,5 +1504,5 @@
 			CC_contact_full_info['connections'][CC_conn_last_selected] = new Array();
 		}
-		else 
+		else
 		{
 			delete CC_contact_full_info['connections'][CC_conn_last_selected];
@@ -1511,8 +1516,8 @@
 				var subNodes = nodes[i].childNodes;
 				var found = false;
-				
+
 				for (var j = 0; j < subNodes.length; j++)
 				{
-					if (subNodes[j].childNodes.length > 0 && 
+					if (subNodes[j].childNodes.length > 0 &&
 					    subNodes[j].childNodes[0].id)
 					{
@@ -1522,5 +1527,5 @@
 							CC_contact_full_info['connections'][CC_conn_last_selected][k] = new Array();
 						}
-						
+
 					    if (subNodes[j].childNodes[0].id.indexOf('cc_conn_name') != -1)
 						{
@@ -1542,5 +1547,5 @@
 							else
 							{
-								CC_contact_full_info['connections'][CC_conn_last_selected][k]['value'] = ''; 
+								CC_contact_full_info['connections'][CC_conn_last_selected][k]['value'] = '';
 							}
 						}
@@ -1553,5 +1558,5 @@
 					}
 				}
-				
+
 				if (found)
 				{
@@ -1570,5 +1575,5 @@
 			delete CC_contact_full_info['connections'][CC_conn_last_selected];
 		}
-		
+
 	}
 
@@ -1596,9 +1601,9 @@
 	var number = randomString().toLowerCase();
 	var result = '';
-	
+
 	if(!is_ie)
-		result = prompt("Essa operação removerá TODOS os seus \ncontatos pessoais,  e  NÃO  PODERÁ  ser \ndesfeita. Digite o código abaixo:\n\tCódigo de confirmação: "+number);
+		result = prompt("Essa operaï¿œï¿œo removerï¿œ TODOS os seus \ncontatos pessoais,  e  Nï¿œO  PODERï¿œ  ser \ndesfeita. Digite o cï¿œdigo abaixo:\n\tCï¿œdigo de confirmaï¿œï¿œo: "+number);
 	else
-		result = prompt("Essa operação removerá TODOS os seus contatos pessoais,  e  NÃO  PODERÁ  ser desfeita. Digite o seguinte código de confirmação: "+number,"");
+		result = prompt("Essa operaï¿œï¿œo removerï¿œ TODOS os seus contatos pessoais,  e  Nï¿œO  PODERï¿œ  ser desfeita. Digite o seguinte cï¿œdigo de confirmaï¿œï¿œo: "+number,"");
 
 	if(result) {
@@ -1606,6 +1611,6 @@
 			Connector.newRequest('removeAllEntries', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=remove_all_entries', 'GET', handler);
 		else
-			alert('Código Incorreto');
-	}	
+			alert('Cï¿œdigo Incorreto');
+	}
 }
 
@@ -1618,5 +1623,5 @@
 		return;
 	}
-	
+
 	var handler = function (responseText)
 	{
@@ -1628,5 +1633,5 @@
 			return;
 		}
-		
+
 		if (data['status'] != 'ok')
 		{
@@ -1634,10 +1639,10 @@
 			return;
 		}
-		
+
 		setTimeout('updateCards()',80);;
 	};
-		
+
 	typeArg = (type == 'groups' ? 'group' : 'entry');
-		
+
 	Connector.newRequest('removeEntry', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=remove_'+typeArg+'&remove=' + id, 'GET', handler);
 }
@@ -1662,5 +1667,5 @@
 	var w_height = 0;
 	var w_extra = 200;
-	
+
 	if (document.body.clientHeight)
 	{
@@ -1691,4 +1696,12 @@
 			Element('cc_letter_' + i).className = 'letter_box';
 		}
+	}
+}
+
+function clearLetterSelection()
+{
+	for (var i = 0; i < 28; i++)
+	{
+		Element('cc_letter_' + i).className = 'letter_box';
 	}
 }
@@ -1758,10 +1771,10 @@
 				final_page = 1;
 			}
-			
+
 			html_pages += '<a href="javascript:setPages('+npages+', '+ actual_page +', '+ final_page +')">...</a> ';
 
 			page = showing_page ? showing_page : actual_page;
 		}
-		
+
 		for (; page <= npages; page++)
 		{
@@ -1823,5 +1836,5 @@
 		Element('cc_panel_arrow_last').style.cursor = 'hand';
 	}
-	
+
 	Element('cc_panel_pages').innerHTML = html_pages;
 }
@@ -1829,19 +1842,11 @@
 function populateCards(data, type)
 {
-	if (data[3].length >= 100 )
-	{
-		alert("Critério de pesquisa muito abrangente, achados " + data[3].length + " resultados");
-		for (i = 0; i < (Math.sqrt(data[3].length)-1); i++)
-			for (j = 0; j < 3; j++)
-				document.getElementById("cc_card:"+j+":"+i).innerHTML = '';
-		return false;
-	}
-	
+
 	if(type == 'groups')
 		return populateGroupsInCards(data);
-	
+
 	var pos = 0;
 	var ncards = data[3].length;
-	
+
 	if (typeof(data[3]) == 'object' && ncards > 0)
 	{
@@ -1851,5 +1856,5 @@
 			{
 				id = 'cc_card:'+j+':'+i;
-			
+
 				for (var k = 0; k < data[2].length; k++)
 				{
@@ -1858,6 +1863,6 @@
 						Element(id).style.display = 'none';
 						continue;
-					}					
-				
+					}
+
 					if(data[3][pos][k] != 'none')
 					{
@@ -1875,7 +1880,6 @@
 								}
 								break;
-							
+
 							case 'cc_mail':
-								
 								if (data[3][pos][k].length > (CC_visual == 'table'  ? 50 : 20))
 								{
@@ -1885,8 +1889,8 @@
 								else
 								{
-									Element(id+':'+data[2][k]).innerHTML = data[5] + data[3][pos][k] + '\')">'+ data[3][pos][k]+'</span>';									
+									Element(id+':'+data[2][k]).innerHTML = data[5] + data[3][pos][k] + '\')">'+ data[3][pos][k]+'</span>';
 								}
 								break;
-							
+
 							case 'cc_phone':
 								if (data[3][pos][k].length > 20)
@@ -1919,14 +1923,41 @@
 								Element(id+':cc_photo').src = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo' + (data[4][pos] != 0 ? '&id='+data[3][pos][k] : '');
 								if(ccTree.catalog_perms == 1)
-									Element(id+':cc_icon_data').innerHTML =  '<span title="'+Element('cc_msg_copy_to_catalog').value+'" id="' + id + ':ccQuickAdd" onmouseout="window.status=\'\';" onclick="ccQuickAddContact.showList(\''+ Element(id+':cc_id').value + '\');return true;" style="cursor: pointer; cursor: hand; z-index: 1"><img src="templates/default/images/address-conduit-16.png" align="center"></span>';
+									Element(id+':cc_icon_data').innerHTML =  '<span title="Copiar para o Catï¿œlogo Pessoal" id="' + id + ':ccQuickAdd" onmouseout="window.status=\'\';" onclick="ccQuickAddContact.showList(\''+ Element(id+':cc_id').value + '\');return true;" style="cursor: pointer; cursor: hand; z-index: 1"><img src="templates/default/images/address-conduit-16.png" align="center"></span>';
 								break;
 
 							case 'cc_forwarding_address':
 								var contacts = data[3][pos][k];
-																
+
 								if( !contacts)
 									break;
-																																								
+
 								Element(id+':cc_icon_group').innerHTML =  '<span title="'+Element('cc_participants').value+'"  onmouseout="window.status=\'\';" onclick="ccListParticipants.showList(\''+ Element(id+':cc_id').value + '\');return true;" style="cursor: pointer; cursor: hand; z-index: 1"><img src="templates/default/images/people-mini.png" align="center">&nbsp;&nbsp;</span>';
+								break;
+
+							case 'cc_empNumber':
+								if (data[3][pos][k].length > 20)
+								{
+									Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
+									Element(id+':'+data[2][k]).title = data[3][pos][k];
+								}
+								else
+								{
+									Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
+								}
+								Element(id+':cc_empNumber').innerHTML = data[3][pos][k];
+								break;
+
+							//Para tratar tamanho do campo "departamento" do empregado
+							case 'cc_department':
+								if (data[3][pos][k].length > 15)
+								{
+									Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 15);
+									Element(id+':'+data[2][k]).title = data[3][pos][k];
+								}
+								else
+								{
+									Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 15);
+								}
+								Element(id+':cc_department').innerHTML = data[3][pos][k];
 								break;
 
@@ -1939,4 +1970,5 @@
 								else
 								{
+									if (Element(id+':'+data[2][k]) == null) alert('ï¿œ nulovgdfv');
 									Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
 								}
@@ -1944,5 +1976,5 @@
 					}
 				}
-	
+
 				if (--ncards == 0)
 				{
@@ -1950,5 +1982,5 @@
 					i = CC_max_cards[1];
 				}
-	
+
 				pos++;
 			}
@@ -1958,9 +1990,9 @@
 
 function populateGroupsInCards(data)
-{	
+{
 	var pos = 0;
-	var contacts = data[5];		
+	var contacts = data[5];
 	var ncards = data[3].length;
-	
+
 	if (typeof(data[3]) == 'object' && ncards > 0)
 	{
@@ -1970,13 +2002,13 @@
 			{
 				id = 'cc_card:'+j+':'+i;
-			
+
 				for (var k = 0; k < data[2].length; k++)
 				{
-				
+
 					if(data[3][pos][k] != 'none')
-					{	
-											
+					{
+
 						switch (data[2][k])
-						{							
+						{
 							case 'cc_title':
 								if (data[3][pos][k].length > 50)
@@ -1990,5 +2022,5 @@
 								}
 								break;
-							
+
 							case 'cc_short_name':
 								if (data[3][pos][k].length > (CC_visual == 'table'  ? 50 : 20))
@@ -2002,5 +2034,5 @@
 								}
 								break;
-							
+
 							case 'cc_contacts':
 
@@ -2011,23 +2043,23 @@
 								var email = "";
 
-								for (var d = 0; d < contacts.length; d++) {																																					
+								for (var d = 0; d < contacts.length; d++) {
 									contact += contacts[d]['names_ordered']+ ",";
 									email += contacts[d]['connection_value']+",";
 								}
-								
+
 								Element(id+':cc_participantes').innerHTML = '<span title="Ver Participantes" id="' + id + ':ccQuickAdd" onmouseout="window.status=\'\';" onclick="ccListParticipants.showList(\''+ Element(id+':cc_id').value+'value\', \''+contact+'\', \''+email+'\', \''+title+'\', \''+id_group+'\');return true;" style="cursor: pointer; cursor: hand; z-index: 1"><img title="Ver participantes" align="center" src="templates/default/images/people-mini.png">&nbsp;&nbsp</span>';
-																					
+
 								break;
-							
+
 							case 'cc_id':
 								var id_contact = data[3][pos][k];
 								Element(id+':'+data[2][k]).value = data[3][pos][k];
-								 							
+
 								break;
-								
+
 						}
 					}
 				}
-	
+
 				if (--ncards == 0)
 				{
@@ -2035,5 +2067,5 @@
 					i = CC_max_cards[1];
 				}
-	
+
 				pos++;
 			}
@@ -2064,5 +2096,5 @@
 	};
 
-	Connector.newRequest('setMaxCards', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=set_n_cards&ncards=' + ncards, 'GET'); 
+	Connector.newRequest('setMaxCards', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=set_n_cards&ncards=' + ncards, 'GET');
 }
 
@@ -2070,5 +2102,5 @@
 {
 	var coord = new Array();
-	
+
 	//Element('cc_card_space').innerHTML = '';
 	//return;
@@ -2077,5 +2109,5 @@
 	//card_space_width = parseInt(is_ie ? document.body.offsetWidth : window.innerWidth) - parseInt(Element('cc_left').offsetWidth) - parseInt(CC_card_extra) - 40;
 	card_space_height = parseInt(Element('cc_card_space').offsetHeight) - parseInt(CC_card_extra);
-	
+
 	card_width = CC_card_image_width + CC_card_extra;
 	card_height = CC_card_image_height + CC_card_extra;
@@ -2083,5 +2115,5 @@
 	ncols = parseInt(card_space_width / card_width);
 	nlines = parseInt(card_space_height / card_height);
-	
+
 	coord[0] = ncols;
 	//coord[1] = nlines;
@@ -2097,8 +2129,8 @@
 {
 		if(type != 'groups') {
-		
+
 			html_card = '<td id="' + id + '" style="width: ' + CC_card_image_width + 'px; height: ' + CC_card_image_height + '">' +
 				'<div style="border: 0px solid #999; position: relative;">' +
-					'<img src="templates/default/images/card.png" border="0" width="' + CC_card_image_width +'" height="' + CC_card_image_height + '"i ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' + 
+					'<img src="templates/default/images/card.png" border="0" width="' + CC_card_image_width +'" height="' + CC_card_image_height + '"i ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' +
 						( ccTree.catalog_perms == 1 ?
 						'<span id="' + id + ':cc_icon_data" style="position: absolute; top: 35px; left: 222px; width: 18px; height: 18px; cursor: pointer; cursor: hand; z-index: 1"></span>':'') +
@@ -2106,21 +2138,25 @@
 						'<img title="'+Element('cc_msg_card_edit').value+'" id="' + id + ':cc_card_edit" style="position: absolute; top: 35px; left: 222px; width: 18px; height: 18px; cursor: pointer; cursor: hand; z-index: 1" onclick="editContact(Element(\'' + id + ':cc_id\').value);" onmouseover="resizeIcon(\''+id+':cc_card_edit\',0)" onmouseout="resizeIcon(\''+id+':cc_card_edit\',1)" src="templates/default/images/cc_card_edit.png">' +
 						'<img title="'+Element('cc_msg_card_remove').value+'" id="' + id + ':cc_card_remove" style="position: absolute; top: 78px; left: 223px; width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value);" onmouseover="resizeIcon(\''+id+':cc_card_remove\',0)" onmouseout="resizeIcon(\''+id+':cc_card_remove\',1)" src="templates/default/images/cc_x.png">' : '') +
-						'<img id="' + id + ':cc_photo" style="position: absolute; top: 15px; left: 7px;" src="" border="0" ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' + 
+						'<img id="' + id + ':cc_photo" style="position: absolute; top: 15px; left: 7px;" src="" border="0" ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' +
 						'<span id="' + id + ':cc_company" style="position: absolute; top: 5px; left: 75px; width: 135px; border: 0px solid #999; font-weight: bold; font-size: 14px; text-align: center; height: 10px;" onmouseover="//Element(\''+id+':cc_company_full\').style.visibility=\'visible\'" onmouseout="//Element(\''+id+':cc_company_full\').style.visibility=\'hidden\'"></span>' +
-						'<span style="cursor: pointer; cursor: hand; z-index: 1;position: absolute; top: 100px; left: 35px"  valign="bottom" id="' + id + ':cc_icon_group">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'+ 
-						'<span id="' + id + ':cc_name" style="position: absolute; top: 30px; left: 75px; width: 135px; border: 0px solid #999; font-weight: bold; font-size: 10px; text-align: center; height: 10px;" onmouseover="//Element(\''+id+':cc_name_full\').style.visibility=\'visible\'" onmouseout="//Element(\''+id+':cc_name_full\').style.visibility=\'hidden\'"></span>' + 
-						'<span id="' + id + ':cc_title" style="position: absolute; top: 60px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 12px; text-align: center; height: 10px;"></span>' + 
-						'<span id="' + id + ':cc_phone" style="position: absolute; top: 90px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' + 
-						'<span id="' + id + ':cc_mail" style="position: absolute; top: 105px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' + 
-						'<span id="' + id + ':cc_alias" style="position: absolute; top: 95px; left: 10px; width: 60px; border: 0px solid #999; font-weight: normal; font-size: 9px; text-align: center; height: 10px;"></span>' + 
+						'<span style="cursor: pointer; cursor: hand; z-index: 1;position: absolute; top: 100px; left: 35px"  valign="bottom" id="' + id + ':cc_icon_group">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'+
+						//Para exibir a matricula do empregado nos cartoes
+						'<span id="' + id + ':cc_empNumber" style="position: absolute; top: 15px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 9px; text-align: center; height: 10px;"></span>' +
+						'<span id="' + id + ':cc_name" style="position: absolute; top: 30px; left: 75px; width: 135px; border: 0px solid #999; font-weight: bold; font-size: 10px; text-align: center; height: 10px;" onmouseover="//Element(\''+id+':cc_name_full\').style.visibility=\'visible\'" onmouseout="//Element(\''+id+':cc_name_full\').style.visibility=\'hidden\'"></span>' +
+						'<span id="' + id + ':cc_title" style="position: absolute; top: 60px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 12px; text-align: center; height: 10px;"></span>' +
+						//Para exibir o setor/lotacao do empregado nos cartoes
+						'<span id="' + id + ':cc_department" style="position: absolute; top: 70px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
+						'<span id="' + id + ':cc_phone" style="position: absolute; top: 90px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
+						'<span id="' + id + ':cc_mail" style="position: absolute; top: 105px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
+						'<span id="' + id + ':cc_alias" style="position: absolute; top: 95px; left: 10px; width: 60px; border: 0px solid #999; font-weight: normal; font-size: 9px; text-align: center; height: 10px;"></span>' +
 					'<input id="' + id + ':cc_id" type="hidden">' +
 				'</div>' + '</td>';
-		
+
 		} else {
 			html_card = '<td id="' + id + '" style="width: ' + CC_card_image_width + 'px; height: ' + CC_card_image_height + '">' +
-            '<div style="border: 0px solid #999; position: relative;">' + 
+            '<div style="border: 0px solid #999; position: relative;">' +
 				'<img src="templates/default/images/card.png" border="0" width="' + CC_card_image_width +'" height="' + CC_card_image_height + '"i ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' +
 				'<img title="'+Element('cc_msg_group_edit').value+'" id="' + id + ':cc_card_edit" style="position: absolute; top: 35px; left: 222px; width: 18px; height: 18px; cursor: pointer; cursor: hand; z-index: 1" onclick="editGroup(Element(\'' + id + ':cc_id\').value);" onmouseover="resizeIcon(\''+id+':cc_card_edit\',0)" onmouseout="resizeIcon(\''+id+':cc_card_edit\',1)" src="templates/default/images/cc_card_edit.png">' +
-				'<img title="'+Element('cc_msg_group_remove').value+'" id="' + id + ':cc_card_remove" style="position: absolute; top: 78px; left: 223px; width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value,\'groups\');" onmouseover="resizeIcon(\''+id+':cc_card_remove\',0)" onmouseout="resizeIcon(\''+id+':cc_card_remove\',1)" src="templates/default/images/cc_x.png">' + 
+				'<img title="'+Element('cc_msg_group_remove').value+'" id="' + id + ':cc_card_remove" style="position: absolute; top: 78px; left: 223px; width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value,\'groups\');" onmouseover="resizeIcon(\''+id+':cc_card_remove\',0)" onmouseout="resizeIcon(\''+id+':cc_card_remove\',1)" src="templates/default/images/cc_x.png">' +
 				'<span id="' + id + ':cc_title" style="position: absolute; top: 30px; left: 75px; width: 135px; border: 0px solid #999; font-weight: bold; font-size: 10px; text-align: center; height: 10px;" onmouseover="//Element(\''+id+':cc_name_full\').style.visibility=\'visible\'" onmouseout="//Element(\''+id+':cc_name_full\').style.visibility=\'hidden\'"></span>' +
 				'<span id="' + id + ':cc_participantes" style="cursor: pointer; cursor: hand; z-index: 1;position: absolute; top: 15px; left: 15px"></span>' +
@@ -2129,5 +2165,5 @@
 			'</div>' + '</td>';
 		}
-	
+
 
 	return html_card;
@@ -2141,11 +2177,17 @@
 			else
 				bg = "this.style.background=\'#EEEEEE\'";
-						
+
 			if(type != 'groups') {
-			
-				html_card = '<tr  style="height:20px" id="' + id + '" onmouseout="'+bg+'" onmouseover="this.style.background=\'LIGHTYELLOW\'" bgcolor="EEEEEE"><td width="auto" style="font-weight: normal; font-size: 10px; text-align: left; height: 10px;">' +					
-					'<span valign="bottom" id="' + id + ':cc_icon_group">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="' + id + ':cc_name"></span></td>' +
+
+				html_card = '<tr  style="height:20px" id="' + id + '" onmouseout="'+bg+'" onmouseover="this.style.background=\'LIGHTYELLOW\'" bgcolor="EEEEEE">' +
+					//Para exibir a matricula do empregado na tabela
+					'<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_empNumber"></span></td>' +
+					'<td width="auto" style="font-weight: normal; font-size: 10px; text-align: left; height: 10px;"><span valign="bottom" id="' + id + ':cc_icon_group">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="' + id + ':cc_name"></span></td>' +
 					'<td style="solid #999; font-weight: normal; font-size: 10px; text-align: left; height: 10px"><span onMouseOver="this.title = \''+Element('cc_send_mail').value+' => '+'\'+document.getElementById(\''+id + ':cc_name\').innerHTML" id="' + id + ':cc_mail"></span></td>' +
-					'<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_phone"></span></td>' +		
+					'<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_phone"></span></td>' +
+					//Para exibir o setor/lotacao do empregado na tabela
+					'<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_department"></span></td>' +
+//					'<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_mobile"></span></td>' +
+					'<td style="solid #999; font-weight: normal; font-size: 10px; text-align: left; height: 10px"><span onMouseOver="this.title = \''+Element('cc_send_mail').value+' => '+'\'+document.getElementById(\''+id + ':cc_name\').innerHTML" id="' + id + ':cc_mail"></span></td>' +
 					( ccTree.catalog_perms == 1 ?
 					'<td align="left"><span valign="bottom" id="' + id + ':cc_icon_data"></span></td>':'') +
@@ -2156,7 +2198,9 @@
 					'<img title="'+Element('cc_msg_card_remove').value+'" id="' + id + ':cc_card_remove" style="width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value);" src="templates/default/images/cc_x.png">' : '') +
 					'<input id="' + id + ':cc_id" type="hidden">'+
-					'<input type="hidden" id="' + id + ':cc_photo">' + 
-					'<span id="' + id + ':cc_title" style="display:none"></span>' + 
-					'<span id="' + id + ':cc_alias" style="display:none"></span>' + 
+					'<input type="hidden" id="' + id + ':cc_photo">' +
+					'<span id="' + id + ':cc_title" style="display:none"></span>' +
+					'<span id="' + id + ':cc_alias" style="display:none"></span>' +
+					// Esse campo ï¿œ necessï¿œrio se o contato possui dados no campo cc_company
+					'<span id="' + id + ':cc_company" style="display:none"></span>' +
 					'</td></tr>';
 			}
@@ -2170,5 +2214,5 @@
 					'&nbsp;&nbsp;|&nbsp;&nbsp;'+
 					'<img  title="'+Element('cc_msg_group_remove').value+'" id="' + id + ':cc_card_remove" style="width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value,\'groups\');" src="templates/default/images/cc_x.png">'  +
-					'<input id="' + id + ':cc_id" type="hidden">'+										
+					'<input id="' + id + ':cc_id" type="hidden">'+
 					'</td></tr>';
 			}
@@ -2180,7 +2224,7 @@
 {
 	var pos;
-	
+
 	html_cards = '<div id="divScrollMain" style="overflow:auto;z-index:1"><table width="100%" border="0" cellpadding="0" cellspacing="3">';
-	
+
 	if (ncards > 0)
 	{
@@ -2202,5 +2246,5 @@
 		if((ccTree.catalog_perms & 2) && type != 'groups')
 			html_cards += '<tr><td colspan=4 align="right"><button id="cc_button_tools" value="" type="button" onclick="javascript:removeAllEntries()">Remover Todos</button></td></tr>';
-	}	
+	}
 	else if (CC_max_cards != 0)
 	{
@@ -2222,5 +2266,5 @@
 	html_cards = '<div id="divScrollMain" style="overflow:auto;z-index:1">';
 	html_cards += '<table  border="0" cellpadding="0" cellspacing="' + CC_card_extra + '">';
-	
+
 	if (ncards > 0)
 	{
@@ -2241,5 +2285,5 @@
 		if((ccTree.catalog_perms & 2) && type != 'groups')
 			html_cards += '<tr><td colspan=3 align="right"><button id="cc_button_tools" value="" type="button" onclick="javascript:removeAllEntries()">Remover Todos</button></td></tr>';
-	}	
+	}
 	else if (CC_max_cards != 0)
 	{
@@ -2278,5 +2322,5 @@
 		else if(CC_visual == 'table')
 			drawTable(0);
-			
+
 		setPages(0,0);
 		return;
@@ -2288,6 +2332,6 @@
 		data = unserialize(responseText);
 		if (data[0] == '0')
-		{				
-			Element('cc_type_contact').value = data[1];			
+		{
+			Element('cc_type_contact').value = data[1];
 			CC_npages = 0;
 			CC_actual_page = 1;
@@ -2301,7 +2345,7 @@
 		else
 		Element('cc_type_contact').value = data[10];
-		
-//		Element('cc_debug').innerHTML = responseText;						
-		
+
+//		Element('cc_debug').innerHTML = responseText;
+
 		if (typeof(data) != 'object')
 		{
@@ -2309,9 +2353,9 @@
 			return;
 		}
-		
+
 		if (typeof(data[3]) == 'object')
 		{
 			CC_npages = parseInt(data[0]);
-			CC_actual_page = parseInt(data[1]);			
+			CC_actual_page = parseInt(data[1]);
 			if(CC_visual == 'cards')
 				drawCards(data[3].length, data[10]);
@@ -2321,5 +2365,9 @@
 			populateCards(data, data[10]);
 			setPages(data[0], data[1]);
-			
+
+		}
+		else if (data['error'])
+		{
+			showMessage(data['error']);
 		}
 		else
@@ -2332,4 +2380,20 @@
 	var info = "letter="+letter+"&page="+CC_actual_page+"&ids="+ids;
 	Connector.newRequest('showCards', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_cards_data', 'POST', handler, info);
+}
+
+
+function clearCards()
+{
+	clearLetterSelection();
+	setHeightSpace();
+	setMaxCards(getMaxCards());
+
+	if(CC_visual == 'cards')
+		drawCards(0);
+	else if(CC_visual == 'table')
+		drawTable(0);
+
+	setPages(0,0);
+	return;
 }
 
@@ -2342,5 +2406,5 @@
 	var table_h = Element('cc_panel_table');
 	var cards_h = Element('cc_panel_cards');
-	
+
 	switch (type)
 	{
@@ -2355,14 +2419,14 @@
 			break;
 	}
-	
+
 	CC_visual = type;
 	showCards(getActualLetter(), getActualPage());
 }
 
-function ccSearchUpdate(ids)
+/*function ccSearchUpdate(ids)
 {
 	Element('cc_panel_letters').style.display = 'none';
 	Element('cc_panel_search').style.display  = 'inline';
-	
+
 	if(CC_visual == 'cards')
 		drawCards(0);
@@ -2375,5 +2439,5 @@
 		return;
 	}
-	
+
 	var sIds = serialize(ids);
 
@@ -2383,4 +2447,22 @@
 	}
 	showCards('search', '1', sIds);
+}
+*/
+
+function ccSearchUpdate()
+{
+	Element('cc_panel_letters').style.display = 'none';
+	Element('cc_panel_search').style.display  = 'inline';
+
+	if(CC_visual == 'cards')
+		drawCards(0);
+	else if(CC_visual == 'table')
+		drawTable(0);
+
+	if (CC_actual_letter != 'search')
+	{
+		CC_last_letter = CC_actual_letter;
+	}
+	//showCards('search', '1', sIds);
 }
 
@@ -2399,5 +2481,6 @@
 	Element('cc_panel_search').style.display  = 'none';
 	Element('cc_panel_letters').style.display = 'inline';
-	showCards(CC_last_letter, '1');
+	clearCards();
+	//showCards(CC_last_letter, '1');
 }
 
@@ -2424,26 +2507,40 @@
 	data[3] = Element('cc_qa_phone').value;
 	data[4] = Element('cc_qa_email').value;
+
+	return data;
+}
+
+function sendQuickAdd ()
+{
+	var data = getQuickAdd();
+
+	var str = serialize(data);
+
+	if (!str)
+	{
+		return false;
+	}
+
+	var handler = function (responseText)
+	{
+		setTimeout('updateCards()',100);;
+	}
+
+	resetQuickAdd();
+
+	Connector.newRequest('quickAdd', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=quick_add', 'POST', handler, 'add='+escape(str));
+}
+
 	
-	return data;
-}
-
-function sendQuickAdd ()
-{
-	var data = getQuickAdd();
-	
-	var str = serialize(data);
-
-	if (!str)
-	{
-		return false;
-	}
-
-	var handler = function (responseText)
-	{
-		setTimeout('updateCards()',100);;
-	}
-
-	resetQuickAdd();
-
-	Connector.newRequest('quickAdd', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=quick_add', 'POST', handler, 'add='+escape(str));
-}
+function connectVoip (phoneUser, typePhone){
+	var handler_voip = function (responseText){
+		if(!responseText) {
+			alert("Erro conectando servidor VoIP.");
+		}
+		else{
+			data = unserialize(responseText);
+			alert("Requisitando chamada para o ramal: "+data);
+		}
+	}
+	Connector.newRequest('voip', "../../expressoMail1_2/controller.php?action=expressoMail1_2.functions.callVoipconnect&to="+phoneUser+"&typePhone="+typePhone, 'POST', handler_voip);
+	}
Index: /trunk/contactcenter/js/ccMain.js
===================================================================
--- /trunk/contactcenter/js/ccMain.js	(revision 119)
+++ /trunk/contactcenter/js/ccMain.js	(revision 284)
@@ -1,21 +1,21 @@
-var last_id = 0;	
-
-function openwindow(url){ 	
-	var window_features = 	"scrollbars=yes,resizable=yes,location=no,menubar=no," + 
-						"personalbar=no,status=no,titlebar=no,toolbar=no," + 
-						"screenX=0,screenY=0,top=0,left=0,width=" + 
-						screen.width + ",height=" + screen.height/5*3; 
-			
-	window.open(url,'', window_features); 
+var last_id = 0;
+
+function openwindow(url){
+	var window_features = 	"scrollbars=yes,resizable=yes,location=no,menubar=no," +
+						"personalbar=no,status=no,titlebar=no,toolbar=no," +
+						"screenX=0,screenY=0,top=0,left=0,width=" +
+						screen.width + ",height=" + screen.height/5*3;
+
+	window.open(url,'', window_features);
 }
 
 var Main_pre_load = document.body.onload;
 var ccSearch, ccTree;
-var Main_load = function () 
-	{ 	
+var Main_load = function ()
+	{
 		Connector.setProgressBox(Element('cc_loading'), true);
-		Connector.setProgressHolder(Element('cc_loading_inner'));		
+		Connector.setProgressHolder(Element('cc_loading_inner'));
 		/* Associate the Quick Add Button with the Plugin */
-					
+
 
 		/* Create the Search Object */
@@ -37,10 +37,11 @@
 		ccSearch.DOMresult.style.visibility = 'hidden';
 		ccSearch.onSearchFinish = ccSearchUpdate;
-			
+
 		Connector.setProgressBox(Element('cc_loading'), true);
 		Connector.setProgressHolder(Element('cc_loading_inner'));
-			
+
 		/* Create the Tree Object */
-		ccTree = new ccCatalogTree({name: 'ccTree', id_destination: 'cc_tree', afterSetCatalog: 'ccSearchHidePanel(); updateCards()'});
+		//ccTree = new ccCatalogTree({name: 'ccTree', id_destination: 'cc_tree', afterSetCatalog: 'ccSearchHidePanel(); updateCards()'});
+		ccTree = new ccCatalogTree({name: 'ccTree', id_destination: 'cc_tree', afterSetCatalog: 'ccSearchHidePanel(); clearCards();'});
 
 		ccTree.Connector = Connector;
@@ -64,62 +65,62 @@
 	var _timeout = '';
 	var menu = function () {
-		 
+
 	 if(! this.menuStarted)
 		this.menuStarted = true;
-		
+
 		submenu = [];
 		textmenu = [];
-			
+
 		textmenu[0] = ["cc_msg_contact_qa","cc_msg_contact_full","cc_msg_group"]
-		textmenu[1] = ["cc_quick_add", "cc_full_add", "cc_add_group"];		
+		textmenu[1] = ["cc_quick_add", "cc_full_add", "cc_add_group"];
 		function show(){
 			clearTimeout(_timeout);
 			button = document.getElementById("cc_button_new");
-				
-			this.style.top = 19 + findPosY(button) + "px"; 
-			this.style.visibility='visible'; 
+
+			this.style.top = 19 + findPosY(button) + "px";
+			this.style.visibility='visible';
 		}
 		function hide(){ _timeout = setTimeout("menu.style.visibility='hidden';",200); };
-			
+
 		if(document.getElementById) {
 			menu = document.getElementById("Layer1");
-				
+
 			for (i=0; i< textmenu[0].length; i++) {
 				textmenu[0][i] = "<span onclick= 'menu.onmouseout();'>" + document.getElementById(textmenu[0][i]).value + "</span><br>";
-				submenu[i] = document.createElement("DIV");				
+				submenu[i] = document.createElement("DIV");
 				submenu[i].innerHTML = textmenu[0][i];
 				submenu[i].id = textmenu[1][i];
 				submenu[i].onmouseover = function () {this.style.backgroundColor = 'LIGHTYELLOW';this.style.color = 'DARKBLUE';};
-				submenu[i].onmouseout   = function () {  this.style.backgroundColor = '#DCDCDC'; this.style.color = '#006699';};					
+				submenu[i].onmouseout   = function () {  this.style.backgroundColor = '#DCDCDC'; this.style.color = '#006699';};
 				submenu[i].setAttribute("className", "special");
 				submenu[i].setAttribute("class", "special");
-				submenu[i].style.padding = "5px";					  
+				submenu[i].style.padding = "5px";
 				menu.appendChild(submenu[i]);
-			}			
-				
+			}
+
 			menu.onmouseover = show;
 			menu.onmouseout = hide;
 		}
-	 		
+
 		ccQuickAdd.associateAsButton(Element('cc_quick_add'));
 		ccAddGroup.associateAsButton(Element('cc_add_group'));
 		document.getElementById("cc_full_add").onclick= newContact;
-			 
-			
+
+
 		ccQuickAdd.afterSave = function ()
 		{
 			updateCards();
-		}			
-			
-		ccAddGroup.load = function () 
-		{				
-			editGroup();			
-		}
-			
+		}
+
+		ccAddGroup.load = function ()
+		{
+			editGroup();
+		}
+
 		ccAddGroup.afterSave = function ()
 		{
 			updateCards();
 		}
-			
+
 		return true;
 	}
@@ -127,17 +128,17 @@
 	if (is_ie)
 	{
-			
+
 		document.body.onload = function (e)
-		{ 			
-			Main_pre_load();								
-			Main_load();					
-								
+		{
+			Main_pre_load();
+			Main_load();
+
 		}
 	}
 	else
-	{		
-		Main_load();	
-			
-	}	
+	{
+		Main_load();
+
+	}
 
 // BEGIN: FUNCTION RESIZE WINDOW
@@ -156,19 +157,19 @@
 showBar = __showBar;
 hideBar = __hideBar;
-	
+
 var _onResize	= window.onresize;
 window.onresize = resizeWindow;
 var defaultHeight = 0;
 function setDefaultHeight(){
-	
+
 	var bar = Element("toolbar");
 	var offset = 0;
-	if(bar.style.visibility != 'hidden') 
-		offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);	
+	if(bar.style.visibility != 'hidden')
+		offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);
 
 	var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
-	defaultHeight = screenHeight - offset;	
-	Element("cc_tree").style.height 		= defaultHeight - 68;	
-	Element("cc_left_main").style.height 	= defaultHeight - 68;	
+	defaultHeight = screenHeight - offset;
+	Element("cc_tree").style.height 		= defaultHeight - 68;
+	Element("cc_left_main").style.height 	= defaultHeight - 68;
 }
 
@@ -176,5 +177,5 @@
 	setDefaultHeight();
 	if(Element("divScrollMain"))
-		Element("divScrollMain").style.height 	= defaultHeight - 108;	
+		Element("divScrollMain").style.height 	= defaultHeight - 108;
 	if (!is_ie)
 		Element('tableDivAppbox').width = '100%';
@@ -184,10 +185,4 @@
 setDefaultHeight();
 Element('cc_main').style.height = defaultHeight;
-var lang_warn_firefox = Element('cc_msg_warn_firefox');
-var lang_firefox_msg1 = Element('cc_msg_firefox_half1');
-var lang_firefox_msg2 = Element('cc_msg_firefox_half2');
-var lang_install_now = Element('cc_msg_install_now');
-var lang_install_new_firefox = Element('cc_msg_install_new_firefox');
-var lang_close = Element('cc_msg_close');
 function buildWarningMsg(_version) {
 	var screenWidth = document.body.clientWidth ? document.body.clientWidth: document.body.offsetWidth;
@@ -196,11 +191,11 @@
 	"border:1px solid black;left:"+(screenWidth - 330)+";top:10px;width:300px;padding:10px;"+
 	(document.body.clientWidth ? "-moz-border-radius: 9px 9px 9px 9px;'>" : "")+
-	    "<font color='RED' size='2'>"+lang_warn_firefox +  "("+_version+")</font><BR>"+
-	    "<font color='black' size='2'><p style='text-align:justify'>&nbsp;"+lang_firefox_msg1+
-	    lang_firefox_msg2 + ".</p></font><div style='width:100%' align='center'>"+
-	    "<a title='"+lang_install_now+"' href='http://br.mozdev.org/firefox/download.html' target='_blank'>"+lang_install_new_firefox+ "</a>"+	
+	"<font color='RED' size='2'>Aviso: Versão muito antiga do Firefox ("+_version+")</font><BR>"+
+	"<font color='black' size='2'><p style='text-align:justify'>&nbsp;Para que essa aplicação funcione <u>corretamente</u> "+
+	"é necessário atualizar o seu navegador Firefox para uma versão mais nova (versão > 1.5). "+
+	"Instale agora clicando no link abaixo ou caso queira atualizar mais tarde (não recomendável), clique em Fechar.</p></font><div style='width:100%' align='center'>"+
+	"<a title='Instalar agora' href='http://br.mozdev.org/firefox/download.html' target='_blank'>Instalar nova versão do Firefox</a>"+
 	"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
-	    "<a title='"+lang_close+"' href='javascript:void(0)' onclick='javascript:myOpacity.toggle()'>"+lang_close+"</a></div>"+
-
+	"<a title='Fechar' href='javascript:void(0)' onclick='javascript:myOpacity.toggle()'>Fechar</a></div>"+
 	"</DIV>";
 
@@ -208,5 +203,5 @@
 
 	myOpacity = new fx.Opacity('warning_msg', {duration: 600});
-	document.getElementById("warning_msg").style.visibility = 'hidden';		
+	document.getElementById("warning_msg").style.visibility = 'hidden';
 	myOpacity.now = 0;
 	setTimeout("myOpacity.toggle()",3000);
Index: /trunk/contactcenter/js/ccIEContacts.js
===================================================================
--- /trunk/contactcenter/js/ccIEContacts.js	(revision 270)
+++ /trunk/contactcenter/js/ccIEContacts.js	(revision 284)
@@ -3,5 +3,5 @@
 		this.el;		
 		this.wWidth = 395;
-		this.wHeight = 255;
+		this.wHeight = 240;
 	}
 	
@@ -16,25 +16,4 @@
 		}	
 	}
-	
-	cIEContacts.prototype.showFailures = function(data){
-		if (data == 'undefined')
-			return;
-		if (data){
-			var lang_clean = Element('cc_msg_clean').value;
-			var info_box = document.getElementById('s_info2');
-			info_box.innerHTML = data;
-			info_box.style.visibility = '';
-			var cleanButton = document.createElement('input');
-			cleanButton.type='button';
-			cleanButton.value=lang_clean;
-			cleanButton.onclick= function() { ccIEContacts.cleanInfo() };
-			info_box.appendChild(cleanButton);
-			}
-	}
-
-	cIEContacts.prototype.cleanInfo = function(){
-	var info_box = document.getElementById('s_info2');
-	info_box.innerHTML = '';
-	}	
 	
 	cIEContacts.prototype.showList = function(){
@@ -58,70 +37,52 @@
 			this.el.id = 'cc_rectIEContacts';
 			document.body.appendChild(this.el);
-
-			var lang_import_contacts = Element('cc_msg_import_contacts').value;
-            var lang_close_win = Element('cc_msg_close_win').value
-            var lang_export_contacts = Element('cc_msg_export_contacts').value;
-            var lang_expresso_info_csv = Element('cc_msg_expresso_info_csv').value;
-            var lang_expresso_default = Element('cc_msg_expresso_default').value;
-            var lang_choose_contacts_file	= Element('cc_msg_choose_contacts_file').value;
-            var lang_msg_choose_type		= Element('cc_msg_choose_file_type').value;
-			var lang_msg_expresso_info_csv	= Element('cc_msg_expresso_info_csv').value;
-			var lang_msg_export_csv			= Element('cc_msg_export_csv').value;;
-            var lang_msg_automatic = Element('cc_msg_automatic').value;
-			var lang_moz_tb = Element('cc_msg_moz_thunderbird').value;
-			var lang_outl_pt = Element('cc_msg_outlook_express_pt').value;
-			var lang_outl_en = Element('cc_msg_outlook_express_en').value;
-			var lang_outl2k_pt = Element('cc_msg_outlook_2k_pt').value;
-			var lang_outl2k_en = Element('cc_msg_outlook_2k_en').value;
-			var lang_expresso_default_csv = Element('cc_msg_expresso_default_csv').value;
-
-		
 			this.el.innerHTML = 
 			'<div align="left" id="divAppbox"><table width="100%" border=0>'+
-			'<tr><td style="border-bottom:1px solid black"><input onclick="javascript:ccIEContacts.changeOptions(this.value)" id="type" type="radio" name="type" value="i" style="border:0" checked>'+lang_import_contacts+
-			'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input onclick="javascript:ccIEContacts.changeOptions(this.value)" id="type" type="radio" name="type" style="border:0" value="e"/>'+lang_export_contacts+' <br></td></tr>'+
+			'<tr><td style="border-bottom:1px solid black"><input onclick="javascript:ccIEContacts.changeOptions(this.value)" id="type" type="radio" name="type" value="i" style="border:0" checked>Importar Contatos'+
+			'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input onclick="javascript:ccIEContacts.changeOptions(this.value)" id="type" type="radio" name="type" style="border:0" value="e"/>Exportar Contatos<br></td></tr>'+
 			'</table>'+
 			'<table border=0 height="208px"  width="100%" id="import_span">'+
 			'<tr><td>'+
-			'<font color="DARKBLUE" size="2">'+lang_expresso_info_csv+'</font></td></tr>'+
+			'<font color="DARKBLUE" size="2">O Expresso suporta a importação de contatos no formato de arquivo CSV.</font></td></tr>'+
 			'<tr><td height="75px" valign="top">'+
-			'<form name="formCSV" method="POST" enctype="multipart/form-data">'+ lang_msg_choose_type +
-			':&nbsp;<select id="typeImport"><option value="auto" selected>'+lang_msg_automatic+'</option>'+
-			'<option value="outlook">'+("Outlook Express")+'</option>'+
-			'<option value="outlook2000">'+("Outlook 2000")+'</option>'+
-			'<option value="thunderbird">'+("Mozilla Thunderbird")+'</option>'+
-			'<option value="expresso">'+lang_expresso_default+'</option></select><br>'+
-			'<br>'+lang_choose_contacts_file+'<br><br>'+			
+			'<form name="formCSV" method="POST" enctype="multipart/form-data">'+										
+			'Selecione o tipo do arquivo:&nbsp;<select id="typeImport">'+
+			'<option value="outlook">Outlook Express</option>'+
+			'<option value="outlook2000">Outlook 2000</option>'+
+			'<option value="thunderbird">Mozilla Thunderbird</option>'+
+			'<option value="expresso" selected>Expresso (padrão)</option></select><br>'+
+			'<br>Selecione o arquivo que contém os contatos a serem importados:<br><br>'+			
 			'<input id="import_file" type="file" name="import_file">'+
 			'</form></td></tr>'+
 			'<tr><td height="10px" align="center" nowrap><span style="visibility:hidden" id="s_info"></span></td></tr>'+
 			'<tr><td height="10px" align="center"></td></tr>'+
-			'<tr><td nowrap><center><input id="import_button" type="button" value='+lang_import_contacts+' onClick="javascript:ccIEContacts.importCSV(this)">&nbsp;&nbsp;&nbsp;&nbsp;'+
-			'<input type="button" value='+lang_close_win+' onClick="javascript:ccIEContacts.close()"></center></td></tr>'+
-			'<tr><td height="10px" align="center" nowrap><span style="visibility:hidden" id="s_info2"></span></td></tr></table>'+
+			'<tr><td nowrap><center><input id="import_button" type="button" value="Importar Contatos" onClick="javascript:ccIEContacts.importCSV(this)">&nbsp;&nbsp;&nbsp;&nbsp;'+
+			'<input type="button" value="Fechar" onClick="javascript:ccIEContacts.close()"></center></td></tr>'+
+			'</table>'+
 			'<table border=0  height="208px"  width="100%" style="display:none" id="export_span">'+
 			'<tr><td>'+						
-			'<font color="DARKBLUE" size="2">'+ lang_msg_expresso_info_csv+'</font></td></tr>'+
-			'<tr><td height="85px" valign="top">'+lang_msg_export_csv+'<br><br>'+
-			'<input style="border:0" id="typeExport_0" name="radio" type="radio" value="expresso" checked/>'+lang_expresso_default_csv+'<br>'+
-			'<input style="border:0" id="typeExport_1" name="radio" type="radio" value="outlook_pt-BR">'+lang_outl_pt+ '<br>'+
-			'<input style="border:0" id="typeExport_2" name="radio" type="radio" value="outlook_en">'+lang_outl_en+ '<br>'+
-			'<input style="border:0" id="typeExport_3" name="radio" type="radio" value="outlook2000_pt-BR">'+lang_outl2k_pt + '<br>'+
-			'<input style="border:0" id="typeExport_4" name="radio" type="radio" value="outlook2000_en">'+lang_outl2k_en + '<br>'+
-			'<input style="border:0" id="typeExport_5" name="radio" type="radio" value="thunderbird">'+lang_moz_tb + '<br>'+
+			'<font color="DARKBLUE" size="2">O Expresso suporta a exportação de contatos no formato de arquivo CSV.</font></td></tr>'+
+			'<tr><td height="85px" valign="top">'+						
+			'Selecione o tipo do formato que deseja exportar seus contatos:<br><br>'+
+			'<input style="border:0" id="typeExport_0" name="radio" type="radio" value="expresso" checked/>Exportar como CSV do Expresso (padrão)<br>'+
+			'<input style="border:0" id="typeExport_1" name="radio" type="radio" value="outlook_pt-BR">Exportar como CSV do Outlook Express (Português)<br>'+
+			'<input style="border:0" id="typeExport_2" name="radio" type="radio" value="outlook_en">Exportar como CSV do Outlook Express (Inglês)<br>'+
+			'<input style="border:0" id="typeExport_3" name="radio" type="radio" value="outlook2000_pt-BR">Exportar como CSV do Outlook 2000 (Português)<br>'+
+			'<input style="border:0" id="typeExport_4" name="radio" type="radio" value="outlook2000_en">Exportar como CSV do Outlook 2000 (Inglês)<br>'+
+			'<input style="border:0" id="typeExport_5" name="radio" type="radio" value="thunderbird">Exportar como CSV do Mozilla Thunderbird<br>'+
 			'</td></tr>'+
 			'<tr><td align="center">&nbsp;</td></tr>'+
-			'<tr><td nowrap><center><input id="export_button" type="button" value='+lang_export_contacts+ ' onClick="javascript:ccIEContacts.exportCSV(this)">&nbsp;&nbsp;&nbsp;&nbsp;'+
-			'<input type="button" value='+lang_close_win+ ' onClick="javascript:ccIEContacts.close()"></center></td></tr>'+
+			'<tr><td nowrap><center><input id="export_button" type="button" value="Exportar Contatos" onClick="javascript:ccIEContacts.exportCSV(this)">&nbsp;&nbsp;&nbsp;&nbsp;'+
+			'<input type="button" value="Fechar" onClick="javascript:ccIEContacts.close()"></center></td></tr>'+
 			'</table></div>';
 		}		
 		this.showWindow();
 	}
-	
+		
 	cIEContacts.prototype.showWindow = function ()
 	{						
 		if(!this.win) {
-	
-				this.win = new dJSWin({			
+
+			this.win = new dJSWin({			
 				id: 'ccIEContacts',
 				content_id: this.el.id,
@@ -130,5 +91,5 @@
 				title_color: '#3978d6',
 				bg_color: '#eee',
-				title: Element('cc_msg_ie_personal').value, 
+				title: "Importar / Exportar Contatos Pessoais",						
 				title_text_color: 'white',
 				button_x_img: '../phpgwapi/images/winclose.gif',
@@ -151,25 +112,16 @@
 		var status = '';
 
-		var lang_import_fail = Element('cc_msg_import_fail').value;
-		var lang_importing = Element('cc_msg_importing_contacts').value;
-		var lang_import_finish = Element('cc_msg_import_finished').value;
-		var lang_new = Element('cc_msg_new').value;
-		var lang_failure = Element('cc_msg_failure').value;
-		var lang_exists = Element('cc_msg_exists').value;
-		var lang_show_more_info = Element('cc_msg_show_more_info').value;
-
-		var l_1		= '<font face="Verdana" size="1" color="GREEN">['+args[1]+lang_new+']</font>';
-		var l_2 	= '<font face="Verdana" size="1" color="RED">['+args[2]+lang_failure+']</font>';
-		var l_3		= '<font face="Verdana" size="1" color="DARKBLUE">['+args[3]+lang_exists+']</font>';
-		var l_4 	= '<br><a font face="Verdana" size="1" href="javascript:ccIEContacts.showFailures(\''+args[4]+'\')">'+lang_show_more_info+'</a>';
-		var l_error	= '<span style="height:15px;background:#cc4444">&nbsp;&nbsp;<font face="Verdana" size="1" color="WHITE">'+lang_import_fail+ '&nbsp;</font></span>';
-		var l_importing = '<span style="height:15px;background:rgb(250, 209, 99)">&nbsp;&nbsp;<font face="Verdana" size="1" color="DARKBLUE">'+lang_importing + '&nbsp;</font></span>';
+		var l_1		= '<font face="Verdana" size="1" color="GREEN">['+args[1]+' novos]</font>';
+		var l_2 	= '<font face="Verdana" size="1" color="RED">['+args[2]+' falharam]</font>';
+		var l_3		= '<font face="Verdana" size="1" color="DARKBLUE">['+args[3]+' já existiam]</font>';
+		var l_error	= '<span style="height:15px;background:#cc4444">&nbsp;&nbsp;<font face="Verdana" size="1" color="WHITE">A importação falhou. Verifique o formato do arquivo.&nbsp;</font></span>';
+		var l_importing = '<span style="height:15px;background:rgb(250, 209, 99)">&nbsp;&nbsp;<font face="Verdana" size="1" color="DARKBLUE">Importando contatos ....&nbsp;</font></span>';
 
 		if(args[0] == 'success') {
 
-			for(i = 1; i < 5; i++) {
+			for(i = 1; i < 4; i++) {
 				status += "&nbsp;"+eval('l_'+i);
 			}
-			Element('s_info').innerHTML = '&nbsp;&nbsp;<font face="Verdana" size="1" color="BLACK"><b>'+lang_import_finish+'</b></font><br>&nbsp;'+status;
+			Element('s_info').innerHTML = '&nbsp;&nbsp;<font face="Verdana" size="1" color="BLACK"><b>A importação foi concluída.</b></font><br>&nbsp;'+status;
 		}
 		else 
@@ -196,9 +148,9 @@
 	cIEContacts.prototype.importCSV = function ()
 	{		
-		var lang_msg_invalid_csv = Element('cc_msg_invalid_csv').value;
 		var form = document.formCSV;
+		
 		if ((form.import_file.value.length < 10) || 
-		(form.import_file.value.substring(form.import_file.value.length - 4, form.import_file.value.length).toLowerCase() != ".csv")){
-			alert(lang_msg_invalid_csv);
+		(form.import_file.value.substring(form.import_file.value.length - 4, form.import_file.value.length) != ".csv")){
+			alert('Selecione um arquivo CSV válido para importar seus contatos.');
 			return;
 		}
@@ -218,6 +170,4 @@
 				args[2] = data._failure ? data._failure : 0;
 				args[3] = data._existing ? data._existing : 0;
-				args[4] = data._failure_status
-
 			}
 			_this.importWriteStatus(args);
@@ -258,8 +208,8 @@
 	
 	cIEContacts.prototype.exportCSV = function() {
-		var lang_export_error = Element('cc_msg_export_error');
+
 		var handler_export = function(data) {
 			if(!data){
-				alert(lang_export_error	);
+				alert("Ocorreu um erro durante a exportação.");
 				return;
 			}				
Index: /trunk/contactcenter/index.php
===================================================================
--- /trunk/contactcenter/index.php	(revision 2)
+++ /trunk/contactcenter/index.php	(revision 284)
@@ -22,7 +22,10 @@
 	);
 	include('../header.inc.php');
+	$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['telephone_number'] = $GLOBALS['phpgw_info']['user']['telephonenumber'];
+    	$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] = true;
 
 	$obj = CreateObject('contactcenter.ui_data');
 	$obj->index();
+	
 
 	$GLOBALS['phpgw']->common->phpgw_footer();
Index: /trunk/contactcenter/templates/default/index.tpl
===================================================================
--- /trunk/contactcenter/templates/default/index.tpl	(revision 270)
+++ /trunk/contactcenter/templates/default/index.tpl	(revision 284)
@@ -1,11 +1,11 @@
 <link rel="stylesheet" type="text/css" href="{cc_css}">
-<style>	
+<style>
 	.special{
 		cursor:pointer;
 		cursor:hand;
-		position:relative; 
-		top:0px; 
+		position:relative;
+		top:0px;
 		left:0px;
-		color: #006699; 
+		color: #006699;
 		background-color:#DCDCDC;
 	}
@@ -15,4 +15,5 @@
 <input id="cc_msg_no_cards" type="hidden" value="{cc_msg_no_cards}">
 <input id="cc_msg_err_no_room" type="hidden" value="{cc_msg_err_no_room}">
+
 <input id="cc_root_dir" type="hidden" value="{cc_root_dir}">
 <input id="cc_msg_card_new" type="hidden" value="{cc_msg_card_new}">
@@ -24,64 +25,12 @@
 <input id="cc_msg_card_remove_confirm" type="hidden" value="{cc_msg_card_remove_confirm}">
 <input id="cc_send_mail" type="hidden" value="{cc_send_mail}">
-<input id="cc_msg_group_edit" type="hidden" value="{cc_msg_group_edit}">	
+<input id="cc_msg_group_edit" type="hidden" value="{cc_msg_group_edit}">
 <input id="cc_msg_group_remove" type="hidden" value="{cc_msg_group_remove}">
 <input id="cc_msg_group_remove_confirm" type="hidden" value="{cc_msg_group_remove_confirm}">
 <input id="cc_panel_search_text" type="hidden" value="{cc_panel_search}" style="cursor: pointer; cursor: hand;" onclick="javascript:ccSearch()" />
-<input id="cc_msg_close_win" type="hidden" value="{cc_msg_close_win}">
-<input id="cc_msg_import_contacts" type="hidden" value="{cc_msg_import_contacts}">
-<input id="cc_msg_export_contacts" type="hidden" value="{cc_msg_export_contacts}">
-<input id="cc_msg_expresso_info_csv" type="hidden" value="{cc_msg_expresso_info_csv}">
-<input id="cc_msg_choose_file_type" type="hidden" value="{cc_msg_choose_file_type}">
-<input id="cc_msg_outlook_express" type="hidden" value="{cc_msg_outlook_express}">
-<input id="cc_msg_outlook2k" type="hidden" value="{cc_msg_outlook2k}">
-<input id="cc_msg_expresso_default" type="hidden" value="{cc_msg_expresso_default}">
-<input id="cc_msg_choose_contacts_file" type="hidden" value="{cc_msg_choose_contacts_file}">
-<input id="cc_msg_close" type="hidden" value="{cc_msg_close}">
-<input id="cc_msg_ie_personal" type="hidden" value="{cc_msg_ie_personal}">
-<input id="cc_msg_import_fail" type="hidden" value="{cc_msg_import_fail}">
-<input id="cc_msg_export_csv" type="hidden" value="{cc_msg_export_csv}">		   
-<input id="cc_msg_automatic" type="hidden" value="{cc_msg_automatic}">
-<input id="cc_msg_importing_contacts" type="hidden" value="{cc_msg_importing_contacts}">
-<input id="cc_msg_import_finished" type="hidden" value="{cc_msg_import_finished}">
-<input id="cc_msg_invalid_csv" type="hidden" value="{cc_msg_invalid_csv}">
-<input id="cc_msg_new" type="hidden" value="{cc_msg_new}">
-<input id="cc_msg_failure" type="hidden" value="{cc_msg_failure}">
-<input id="cc_msg_exists" type="hidden" value="{cc_msg_exists}">
-<input id="cc_msg_show_more_info" type="hidden" value="{cc_msg_show_more_info}">
-<input id="cc_msg_clean" type="hidden" value="{cc_msg_clean}">
-<input id="cc_msg_choose_valid_csv" type="hidden" value="{cc_msg_choose_valid_csv}">
-<input id="cc_msg_export_error" type="hidden" value="{cc_msg_export_error}">
-<input id="cc_msg_new_email" type="hidden" value="{cc_msg_new_email}">
-<input id="cc_msg_main" type="hidden" value="{cc_msg_main}">
-<input id="cc_msg_alternative" type="hidden" value="{cc_msg_alternative}">
-<input id="cc_msg_select_email" type="hidden" value="{cc_msg_select_email}">
-<input id="cc_msg_new_phone" type="hidden" value="{cc_msg_new_phone}">
-<input id="cc_msg_home" type="hidden" value="{cc_msg_home}">
-<input id="cc_msg_cellphone" type="hidden" value="{cc_msg_cellphone}">
-<input id="cc_msg_work" type="hidden" value="{cc_msg_work}">
-<input id="cc_msg_fax" type="hidden" value="{cc_msg_fax}">
-<input id="cc_msg_pager" type="hidden" value="{cc_msg_pager}">
-<input id="cc_msg_choose_phone" type="hidden" value="{cc_msg_choose_phone}">
-<input id="cc_msg_warn_firefox" type="hidden" value="{cc_msg_warn_firefox}">
-<input id="cc_msg_firefox_half1" type="hidden" value="{cc_msg_firefox_half1}">
-<input id="cc_msg_firefox_half2" type="hidden" value="{cc_msg_firefox_half2}">
-<input id="cc_msg_click_close" type="hidden" value="{cc_msg_click_close}">
-<input id="cc_msg_install_now" type="hidden" value="{cc_msg_install_now}">
-<input id="cc_msg_install_new_firefox" type="hidden" value="{cc_msg_install_new_firefox}">
-<input id="cc_msg_outlook_express_pt" type="hidden" value="{cc_msg_outlook_express_pt}">
-<input id="cc_msg_outlook_express_en" type="hidden" value="{cc_msg_outlook_express_en}">
-<input id="cc_msg_outlook_2k_pt" type="hidden" value="{cc_msg_outlook_2k_pt}">
-<input id="cc_msg_outlook_2k_en" type="hidden" value="{cc_msg_outlook_2k_en}">
-<input id="cc_msg_moz_thunderbird" type="hidden" value="{cc_msg_moz_thunderbird}">
-<input id="cc_msg_expresso_default_csv" type="hidden" value="{cc_msg_expresso_default_csv}">
-<input id="cc_msg_copy_to_catalog" type="hidden" value="{cc_msg_copy_to_catalog}">
-<input id="cc_msg_fill_field_name" type="hidden" value="{cc_msg_fill_field_name}">
-<input id="cc_msg_add_contact_to_group" type="hidden" value="{cc_msg_add_contact_to_group}">
-
-
  <!-- END JS MESSAGES -->
  <input id="cc_type_contact" 	type="hidden">
  <input id="cc_participants" 	type="hidden"  value="{cc_participants}">
- 
+
  <input id="cc_qa_alias" 		type="hidden" value="{cc_qa_alias}">
  <input id="cc_qa_given_names" 	type="hidden" value="{cc_qa_given_names}">
@@ -89,8 +38,8 @@
  <input id="cc_qa_phone" 		type="hidden" value="{cc_qa_phone}">
  <input id="cc_qa_email"		type="hidden" value="{cc_qa_email}">
- 
+
  <input id="cc_qa_save" 		type="hidden" value="{cc_qa_save}">
- <input id="cc_qa_close"		type="hidden" value="{cc_qa_close}">
- 
+ <input id="cc_qa_clear"		type="hidden" value="{cc_qa_clear}">
+
  <input id="cc_empty" 			type="hidden"  value="{cc_empty}">
   <!-- VIEW CARDS -->
@@ -104,5 +53,5 @@
 				</tr>
 				<tr>
-					<td width="150px" height="100%" align="left" valign="top"> 
+					<td width="150px" height="100%" align="left" valign="top">
 						<div id="cc_tree" style="overflow:auto;position:relative; width: 150px;border: 0px solid #999;"></div>
 					</td>
@@ -126,6 +75,6 @@
 				</tr>-->
 				<tr align="left">
-					<td align="left">															
-					<input id="cc_button_new" onMouseOver="if(!menuStarted) menu();menu.onmouseover()" onMouseOut="menu.onmouseout()"  value="{cc_btn_new}" type="button">					
+					<td align="left">
+					<input id="cc_button_new" onMouseOver="if(!menuStarted) menu();menu.onmouseover()" onMouseOut="menu.onmouseout()"  value="Novo ..." type="button">
 					<div id="cc_panel_search_call" style="display: inline"></div>
 					<div id="cc_panel_table" style="display: none; text-align: right">
@@ -133,9 +82,9 @@
 					</div>
 					<div id="cc_panel_cards" style="display: inline; text-align: right">
-					<input type="button" value="{cc_panel_cards}" class="tab_box" style="cursor: pointer; cursor: hand;" onclick="javascript: ccChangeVisualization('cards')" />					
+					<input type="button" value="{cc_panel_cards}" class="tab_box" style="cursor: pointer; cursor: hand;" onclick="javascript: ccChangeVisualization('cards')" />
 					</div>
 					</td>
 					<td align="right">
-					<input id="cc_button_tools" value="{cc_btn_import_export}" type="button" onclick="javascript:ccIEContacts.showList()">
+					<input id="cc_button_tools" value="Importar | Exportar" type="button" onclick="javascript:ccIEContacts.showList()">
 					</td>
 				</tr>
@@ -223,5 +172,5 @@
 											<td align="left" valign="middle"><span id="cc_panel_arrow_last"><img src="templates/default/images/last-grey.png" border="0" alt="{cc_panel_last_page}" hspace="2" /></span></td>
 										</tr>
-									</table>			
+									</table>
 								</td>
 							</tr>
@@ -230,8 +179,8 @@
 				</tr>
 				<!-- ___END PANEL -->
-				<!-- __CARDS -->				
+				<!-- __CARDS -->
 				<tr>
 					<td style="border: 0px solid #666;" id="cc_card_space" width="100%" height="auto" valign="top" align="center" colspan="4"></td>
-				</tr>												
+				</tr>
 				<!-- __END CARDS -->
 			</table>
@@ -248,3 +197,3 @@
 <script type="text/javascript" src="js/ccIEContacts.js"></script>
 <script type="text/javascript" src="js/ccMain.js"></script>
-<!-- END BOTTOM DETAILS-->						
+<!-- END BOTTOM DETAILS-->
Index: /trunk/contactcenter/templates/default/full_add.tpl
===================================================================
--- /trunk/contactcenter/templates/default/full_add.tpl	(revision 118)
+++ /trunk/contactcenter/templates/default/full_add.tpl	(revision 284)
@@ -13,5 +13,5 @@
 <input id="cc_contact_personal" type="hidden" value="{cc_contact_personal}">
 <input id="cc_contact_addrs" type="hidden" value="{cc_contact_addrs}">
-<input id="cc_contact_conns" type="hidden" value="{emails_telephones}">
+<input id="cc_contact_conns" type="hidden" value="E-mails e Telefones">
 <input id="cc_pd_full_name" name="{cc_pd_full_name}" type="hidden">
 <input id="cc_pd_sex" name="{cc_pd_sex}" type="hidden">
@@ -36,5 +36,5 @@
 		<tr class="row_on">
 			<td align="right">{cc_pd_alias}:</td>
-			<td align="left" colspan="2"><input id="cc_pd_alias" name="{cc_pd_alias}" type="text" style="width:175px;z-index:-1" value="" maxlength=""></td>
+			<td align="left" colspan="2"><input id="cc_pd_alias" name="{cc_pd_alias}" type="text" style="width:175px;z-index:-1" value="" maxlength="30"></td>
 		</tr>
 		<tr style="display:none" class="row_off">
@@ -139,14 +139,14 @@
 	<tbody>
 		<tr class="th" width="100%" align="center" height="10px">
-			<td width="60px" noWrap><input type="radio"  name="cc_conn_type" id="cc_conn_type_1" value="Email" onclick="javascript:updateConnFields();">{email}</td>
-			<td width="60px" noWrap><input type="radio" name="cc_conn_type" id="cc_conn_type_2" value="Telefone" onclick="javascript:updateConnFields();">{telephone}</td>
-			<td width="*" align="left"><select style="width:160px" id="cc_conn_type_sel" onchange="javascript:connAddNewLine();"><option value="-1">{choose_email_telephone}</option></select></td>
-		</tr>
-		<tr class="row_off">			
+			<td width="60px" noWrap><input type="radio"  name="cc_conn_type" id="cc_conn_type_1" value="Email" onclick="javascript:updateConnFields();">E-mail</td>
+			<td width="60px" noWrap><input type="radio" name="cc_conn_type" id="cc_conn_type_2" value="Telefone" onclick="javascript:updateConnFields();">Telefone</td>
+			<td width="*" align="left"><select style="width:160px" id="cc_conn_type_sel" onchange="javascript:connAddNewLine();"><option value="-1">Escolha 'Email' ou 'Telefone'</option></select></td>
+		</tr>
+		<tr class="row_off">
 			<td valign="top" colspan="4" width="100%" style="border: 0px solid black" cellpadding="0" cellspacing="0">
 				<table align="left" width="100%" style="border: 0px solid black">
 				<tbody id="cc_conn">&nbsp;
 					<!-- Code inside here is inserted dynamically -->
-				</tbody>				
+				</tbody>
 				</table>
 			</td>
@@ -159,8 +159,8 @@
 	</tbody>
 	</table>
-	<div style="z-index:10000;position: absolute;display:none; top: 170px; left: 78px;" id="div_cc_conn_is_default"> {cc_default} &nbsp;<select id="cc_email_default" name="cc_email_default" disabled style="display:none"></select><select id="cc_phone_default" name="cc_phone_default" disabled style="display:none"></select></div>
+	<div style="z-index:10000;position: absolute;display:none; top: 170px; left: 78px;" id="div_cc_conn_is_default">É padrão:&nbsp;<select id="cc_email_default" name="cc_email_default" disabled style="display:none"></select><select id="cc_phone_default" name="cc_phone_default" disabled style="display:none"></select></div>
 </div>
 <!-- _BOTTOM BUTTONS -->
-<div align="center" id="cc_contact_tab_buttons" style="position: absolute; visibility: hidden; top: 250px; left: 0px; width: 498px; height: 32px; border: 0px solid black">	
+<div align="center" id="cc_contact_tab_buttons" style="position: absolute; visibility: hidden; top: 250px; left: 0px; width: 498px; height: 32px; border: 0px solid black">
 	<table class="row_off" align="center" width="498px" cellpadding="2" cellspacing="0" border="0">
 		<tr>
@@ -177,9 +177,9 @@
 <!--
 //	Overloading some methods for fix cursor problem in Firefox.
-	if(!is_ie) { 
-		dJSWin.prototype.close = function() {		
+	if(!is_ie) {
+		dJSWin.prototype.close = function() {
 			dJSWin.state = 0;
 			dd.elements[this.title.id].hide();
-			Element("divScrollMain").style.overflow = 'auto';	
+			Element("divScrollMain").style.overflow = 'auto';
 		}
 		dJSWin.prototype.open = function() {
@@ -190,30 +190,30 @@
 			Element("divScrollMain").style.overflow = 'hidden';
 		}
-	}	
-		
+	}
+
 	var fullAdd_onload = document.body.onload;
 	var tabs;
 	var fullAddWin;
-	var photo_frame, photo_form, photo_input;	
+	var photo_frame, photo_form, photo_input;
 
 	__f = function(e)
 	{
-		
+
 		tabs = new dTabsManager({'id': 'cc_contact_tab', 'width': '500px'});
-		
-		tabs.addTab({'id': 'cc_contact_tab_0', 
-					 'name': Element('cc_contact_personal').value, 
-					 'selectedClass': 'tab_box_active', 
+
+		tabs.addTab({'id': 'cc_contact_tab_0',
+					 'name': Element('cc_contact_personal').value,
+					 'selectedClass': 'tab_box_active',
 					 'unselectedClass': 'tab_box'});
-					 
-		tabs.addTab({'id': 'cc_contact_tab_2', 
-					 'name': Element('cc_contact_conns').value, 
-					 'selectedClass': 'tab_box_active', 
+
+		tabs.addTab({'id': 'cc_contact_tab_2',
+					 'name': Element('cc_contact_conns').value,
+					 'selectedClass': 'tab_box_active',
 					 'unselectedClass': 'tab_box'});
 
-		tabs.addTab({'id': 'cc_contact_tab_1', 
-					 'name': Element('cc_contact_addrs').value, 
-					 'selectedClass': 'tab_box_active', 
-					 'unselectedClass': 'tab_box'});					 
+		tabs.addTab({'id': 'cc_contact_tab_1',
+					 'name': Element('cc_contact_addrs').value,
+					 'selectedClass': 'tab_box_active',
+					 'unselectedClass': 'tab_box'});
 
 		fullAddWin = new dJSWin({'id': 'cc_full_add',
@@ -229,6 +229,6 @@
 					 'border': true});
 
-		fullAddWin.draw();		
-		 				
+		fullAddWin.draw();
+
 		if (is_ie)
 		{
@@ -242,12 +242,12 @@
 		{
 			Element('cc_pd_select_photo_t').style.display='none';
-			Element('cc_pd_select_photo_b').style.display='none';			
-		}
-		
+			Element('cc_pd_select_photo_b').style.display='none';
+		}
+
 	};
 
 	if (is_ie) // || is_moz1_6)
 	{
-			
+
 		document.body.onload = function(e) { setTimeout('__f()', 10); fullAdd_onload ? setTimeout('fullAdd_onload()'): false;};
 	}
@@ -270,5 +270,5 @@
 
 
-<!-- RELATIONS 
+<!-- RELATIONS
 <div id="cc_contact_tab_3" class="row_off div_cc_contact_tab">
 	<table align="center" width="500px" height="100%" cellpadding="2" cellspacing="0" border="0">
