Index: branches/2.2/contactcenter/inc/class.so_group.inc.php
===================================================================
--- branches/2.2/contactcenter/inc/class.so_group.inc.php	(revision 1280)
+++ branches/2.2/contactcenter/inc/class.so_group.inc.php	(revision 3215)
@@ -110,9 +110,33 @@
 		function selectAllContacts( $field = false ,$shared_from=null)
 		{
-			if($shared_from==null) {		
-				$query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'.
-				'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
-				'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '.
-				'A.id_owner ='.$this->owner.' and C.connection_is_default = true ';
+			if ( $shared_from == NULL )
+			{
+				$query = "select"
+						. " phpgw_cc_connections.id_connection,"
+						. " phpgw_cc_contact.id_contact,"
+						. " phpgw_cc_contact.names_ordered,"
+						. " phpgw_cc_contact.alias,"
+						. " phpgw_cc_connections.connection_value ,"
+						. " phpgw_cc_contact_conns.id_typeof_contact_connection,"
+						. " phpgw_cc_addresses.address1,"
+						. " phpgw_cc_addresses.complement,"
+						. " phpgw_cc_addresses.postal_code,"
+						. " phpgw_cc_city.city_name,"
+						. " phpgw_cc_state.state_name,"
+						. " phpgw_cc_addresses.id_country";
+
+				$query .= " from"
+						. " phpgw_cc_contact"
+						. " inner join phpgw_cc_contact_conns on ( phpgw_cc_contact.id_contact = phpgw_cc_contact_conns.id_contact )"
+						. " inner join phpgw_cc_connections on ( phpgw_cc_contact_conns.id_connection = phpgw_cc_connections.id_connection )"
+						. " left join phpgw_cc_contact_addrs on ( phpgw_cc_contact.id_contact = phpgw_cc_contact_addrs.id_contact )"
+						. " left join phpgw_cc_addresses on ( phpgw_cc_contact_addrs.id_address = phpgw_cc_addresses.id_address )"
+						. " left join phpgw_cc_city on ( phpgw_cc_addresses.id_city = phpgw_cc_city.id_city )"
+						. " left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)";
+
+				$query .= " where"
+						. " phpgw_cc_contact.id_owner = {$this->owner}"
+						. " and phpgw_cc_connections.connection_is_default = true";
+
 			}
 			else {
@@ -121,5 +145,5 @@
 							  B.acl_appname = \'contactcenter\' and B.acl_rights & 1 <> 0 
 							  and A.id_typeof_contact_relation=1 and A.id_contact = '.$shared_from.' and A.id_related='.$this->owner;
-				
+
 				$query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'.
 				'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
@@ -130,44 +154,50 @@
 
 			if ( $field == 'only_email' )
-				$query .= 'and B.id_typeof_contact_connection = 1 ';
-
-			$query .= ' order by A.names_ordered,C.connection_value';
-
-					
-			if (!$this->db->query($query))
-			{
-				exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
-			}
-			 
+				$query .= 'and phpgw_cc_contact_conns.id_typeof_contact_connection = 1 ';
+
+			$query .= ' order by phpgw_cc_contact.names_ordered, phpgw_cc_connections.connection_value';
+
+			if (!$this->db->query($query))
+			{
+				exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
+			}
+
 			$return = array();
-			
+
 			while($this->db->next_record())
 			{
 				$return[] = $this->db->row(); 
 			}
-			
-			if(!count($return))
-				return $return;				
-			// Essa iteração transforma uma esturuta com contatos redundantes e separados por email ou tel.
-			// em outra com apenas 1 elemento pra cada contato
-			foreach($return as $i => $object){
-				if ($object['id_typeof_contact_connection'] == 1){
-					$all_contacts[$object['id_contact']]['connection_value'] = $object['connection_value'];
-                    $all_contacts[$object['id_contact']]['names_ordered'] = $object['names_ordered'];
-                    $all_contacts[$object['id_contact']]['id_contact'] = $object['id_contact'];
-                    $all_contacts[$object['id_contact']]['id_connection'] = $object['id_connection'];
+
+			if( ! count( $return ) )
+				return $return;
+
+			foreach( $return as $i => $object )
+			{
+				switch( $object[ 'id_typeof_contact_connection' ] )
+				{
+					case 1 :
+						$all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ];
+						break;
+					case 2 :
+						$all_contacts[ $object[ 'id_contact' ] ][ 'phone' ] = $object[ 'connection_value' ];
+						break;
 				}
-				else 
-					if ($object['id_typeof_contact_connection'] == 2){
-						$all_contacts[$object['id_contact']]['phone'] = $object['connection_value'];
-						$all_contacts[$object['id_contact']]['names_ordered'] = $object['names_ordered'];
-						$all_contacts[$object['id_contact']]['id_contact'] = $object['id_contact'];
-						$all_contacts[$object['id_contact']]['id_connection'] = $object['id_connection'];
-					}
-			}
-			
+
+				$all_contacts[ $object[ 'id_contact' ] ][ 'names_ordered' ] = $object[ 'names_ordered' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'id_contact' ]    = $object[ 'id_contact' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'id_connection' ] = $object[ 'id_connection' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'alias' ]         = $object[ 'alias' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'address1' ]      = $object[ 'address1' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'complement' ]    = $object[ 'complement' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'postal_code' ]   = $object[ 'postal_code' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'city_name' ]     = $object[ 'city_name' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'state_name' ]    = $object[ 'state_name' ];
+				$all_contacts[ $object[ 'id_contact' ] ][ 'id_country' ]    = $object[ 'id_country' ];
+			}
+
 			return array_values($all_contacts);
-		}		
-		
+		}
+
 		function verifyContact($email)
 		{
