Index: trunk/contactcenter/inc/class.bo_ldap_manager.inc.php
===================================================================
--- trunk/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 284)
+++ trunk/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 285)
@@ -12,5 +12,5 @@
   \***************************************************************************/
 
-
+	
 	/*
 		This class is responsible for the LDAP control/generic functions and for
@@ -19,17 +19,17 @@
 	include_once('class.Thread.inc.php');
 
-	class bo_ldap_manager
+	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')
 				{
@@ -37,5 +37,5 @@
 					return;
 				}
-
+				
 				$this->srcs = array(
 					1 => array(
@@ -46,7 +46,7 @@
 						'pw'     => $data['cc_ldap_pw0'],
 						'obj'    => 'inetOrgPerson',
-						'branch' => strtolower('ou')
+						'branch' => strtolower('ou'),
+						'visible' => $data['cc_ldap_query_automatic']
 					)
-
 				);
 			}
@@ -56,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(
@@ -69,9 +69,9 @@
 						'dn'   => (string),
 						'acc'  => (string),
-						'pw'   => (string)
+						'pw'   => (string)   
 					),
 					...
 				)
-
+				
 			TODO: Return multiple sources...
 		*/
@@ -80,5 +80,5 @@
 			return $this->srcs;
 		}
-
+		
 		/*
 		* @function get_external_ldap_sources
@@ -102,5 +102,5 @@
 		function get_ldap_fields_association ( $id_source )
 		{
-
+			
 			$op_iop = array(
 				'contact.id_contact'               => array('dn'),
@@ -111,5 +111,4 @@
 				'contact.family_names'             => array('sn'),
 				'contact.names_ordered'            => array('cn'),//,'displayName'),
-
 				'contact.suffixes.suffix'          => false,
 				'contact.birthdate'                => false,
@@ -117,15 +116,14 @@
 				'contact.pgp_key'                  => false,
 				'contact.notes'                    => false,
-				'contact.mail_forwarding_address'  => array('mailForwardingAddress'),
-				'contact.account_type'             => array('phpgwAccountType'),
-				'contact.account_status'           => array('phpgwAccountStatus'),
-				'contact.account_visible'          => array('phpgwAccountVisible'),
+				'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'), // Setor do empregado...
-				'contact.business_info.empNumber'  => array('employeeNumber'), // Matricula do empregado
+				'contact.business_info.department' => array('ou'),
 				'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(
@@ -133,30 +131,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 (
@@ -169,7 +167,6 @@
 				),
 			);
-
+			
 			return $op_iop;
-
 		}
 
@@ -232,18 +229,18 @@
 
 		/*!
-
+		
 			@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])
@@ -251,5 +248,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)
@@ -257,5 +254,5 @@
 				return false;
 			}
-
+			
 			if ($recursive)
 			{
@@ -265,7 +262,8 @@
 				return $tree;
 			}
-
-			return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch'], 0);
-		}
+			
+			return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']);
+		}
+		// SERPRO
 
 		/*!
@@ -336,5 +334,5 @@
 				return null;
 			}
-
+			
 			$count = ldap_count_entries($resource,$result_res);
 			if ( $count == 0 )
@@ -353,16 +351,14 @@
 				}
 			}
-
+			
 			$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];
@@ -381,5 +377,5 @@
 						'sub_branch' => false
 					);
-				}
+				} 
 			}
 
@@ -393,17 +389,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);
@@ -412,29 +408,30 @@
 				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 translate_accentuation($text)
@@ -464,5 +461,4 @@
 			//$filter = '(!(objectClass='.$objectClass.'))';
 			// Don't show OU's whith phpgwAccountVisible equal to '-1'
-
 			if ($external)
 			{
@@ -483,8 +479,4 @@
 			if ($result_res === false)
 			{
-				if (ldap_errno($resource) === 3)
-				{
-					return array('error_msg' => ldap_error($resource));
-				}
 				return null;
 			}
@@ -591,4 +583,5 @@
 				$tree['ldap']       = array('id_source' => $id_source, 'context' => $context);
 			}
+			
 			usort($tree['sub_branch'], array($this, "compareTreeNodes"));
 			return $tree;
@@ -596,7 +589,7 @@
 
 		function compareTreeNodes($a, $b)	{
-
+						
 			return strnatcasecmp($a['name'], $b['name']);
-		}
+		}	
 
 	}
