Index: branches/2.2/contactcenter/setup/tables_current.inc.php
===================================================================
--- branches/2.2/contactcenter/setup/tables_current.inc.php	(revision 2)
+++ branches/2.2/contactcenter/setup/tables_current.inc.php	(revision 3282)
@@ -287,5 +287,6 @@
 				'pgp_key'		=> array( 'type' => 'text' ),
 				'notes'			=> array( 'type' => 'text' ),
-				'is_global'		=> array( 'type' => 'bool' )
+				'is_global'		=> array( 'type' => 'bool' ),
+				'corporate_name'=> array( 'type' => 'varchar', 'precision' => 100)
 			),
 			'pk' => array('id_contact'),
Index: branches/2.2/contactcenter/inc/class.bo_ldap_manager.inc.php
===================================================================
--- branches/2.2/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 3262)
+++ branches/2.2/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 3282)
@@ -181,4 +181,6 @@
 					'telex'  => array('telexNumber')
 				),
+				'contact.connection.mail'				   => array('mail'),
+				'contact.connection.phone'				   => array('telephoneNumber')
 			);
 			
Index: branches/2.2/contactcenter/inc/class.ui_data.inc.php
===================================================================
--- branches/2.2/contactcenter/inc/class.ui_data.inc.php	(revision 3247)
+++ branches/2.2/contactcenter/inc/class.ui_data.inc.php	(revision 3282)
@@ -116,4 +116,14 @@
 			$GLOBALS['phpgw']->template->set_var('cc_qa_close',lang('Close'));
 			/* End Quick Add */
+
+			/* Advanced Search */
+			
+			$GLOBALS['phpgw']->template->set_var('cc_corporate',lang('Corporate'));
+			$GLOBALS['phpgw']->template->set_var('cc_cs_title',lang('Advanced Search'));
+			$GLOBALS['phpgw']->template->set_var('cc_catalogues',lang('Catalogues'));
+			
+			
+			
+			/* End of Advanced Search*/
 
 			$cc_css_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/styles/cc.css';
@@ -470,4 +480,6 @@
 				echo serialize(array(
 					'status' => 'ok',
+					'catalog' => $catalog_info['class'],
+					'external' => $catalog_info['external']?true:false,
 					'perms'  => $perms
 				));
@@ -2753,4 +2765,30 @@
 		}
 
+		//Traduz o campo na busca completa por entradas no catálogo do usuário.
+		function aux_full_search ($field,$isldap) {
+			$retorno = '';
+			if($isldap) {
+				switch($field) {
+					case 'mail':
+						$retorno = 'contact.connection.mail';
+						break;
+					case 'phone':
+						$retorno = 'contact.connection.phone';
+						break;
+				}
+			}
+			else {
+				switch($field) {
+					case 'corporate':
+						$retorno = 'contact.corporate_name';
+						break;
+					case 'mail':
+					case 'phone':
+						$retorno = 'contact.contact_connection.connection.connection_value';
+						break;
+				}
+			}
+			return $retorno;
+		}
 
 		/*!
@@ -2775,6 +2813,7 @@
 			// 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']))
+			$full_search = isset($data['full_search'])?$data['full_search']:false;
+			
+			if (!is_array($data) || (!$data['search_for'] && !$full_search) || !is_array($data['fields']))
 			{
 				echo serialize(array(
@@ -2821,8 +2860,13 @@
 				if (!is_array($names))
 				{
-					echo serialize(array(
-						'msg'    => lang('Invalid Search Parameter'),
-						'status' => 'abort'
-					));
+					if(!$full_search) {
+						echo serialize(array(
+							'msg'    => lang('Invalid Search Parameter'),
+							'status' => 'abort'
+						));
+						exit;
+					}
+					else 
+						$names = array();
 
 				}
@@ -2840,4 +2884,5 @@
 					 * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1
 					 */
+					
 					$rules = array(
 						0 => array(
@@ -2868,4 +2913,26 @@
 						),
 					);
+
+					foreach($full_search as $field => $value) {
+						if(trim($value)!='')
+							array_push($rules,array(
+											'field' => $this->aux_full_search($field,true),
+											'type' => 'LIKE',
+											'value' => '*'.$value.'*'
+											));
+					}
+
+				}
+				else if(!$external) {
+					
+					foreach($full_search as $field => $value) {
+						if(trim($value)!='')
+							array_push($rules,array(
+											'field' => $this->aux_full_search($field,false),
+											'type' => 'iLIKE',
+											'value' => '%'.$value.'%'
+											));
+					}
+				
 				}
 
@@ -2906,5 +2973,7 @@
 					'contact.object_class',
 					//'contact.account_status',
-					'contact.account_visible'
+					'contact.account_visible',
+					'contact.connection.mail',
+					'contact.connection.phone'
 					), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'), $data['search_for_area'], $data['search_for'] != null );
 			}
Index: branches/2.2/contactcenter/inc/class.bo_contactcenter.inc.php
===================================================================
--- branches/2.2/contactcenter/inc/class.bo_contactcenter.inc.php	(revision 3211)
+++ branches/2.2/contactcenter/inc/class.bo_contactcenter.inc.php	(revision 3282)
@@ -300,5 +300,5 @@
 							// Necessary for the new way the catalog tree is built at initialization
 							$new_branch['name'] = $branch['name'];
-							$new_branch['external'] = $branch['external'];
+							$new_branch['external'] = $this->tree['branches'][$id]['external'];
 							$branch = $new_branch;
 						}
Index: branches/2.2/contactcenter/js/cc_tree.js
===================================================================
--- branches/2.2/contactcenter/js/cc_tree.js	(revision 3180)
+++ branches/2.2/contactcenter/js/cc_tree.js	(revision 3282)
@@ -34,4 +34,6 @@
 		this.tree = new dFTree({'name': params['name']+'_tree'});
 		this.actualLevel = null;
+		this.actualCatalog = null;
+		this.actualCatalogIsExternal = null;
 		this.treeAvailable = false;
 		this.afterSetCatalog = params['afterSetCatalog'];
@@ -57,5 +59,6 @@
 				return;
 			}
-			
+			_this.actualCatalog = data['catalog'];//Atribuir o catalogo atual...
+			_this.actualCatalogIsExternal = data['external'];
 			if (data['status'] != 'ok')
 			{
Index: branches/2.2/contactcenter/js/cc_search.js
===================================================================
--- branches/2.2/contactcenter/js/cc_search.js	(revision 1690)
+++ branches/2.2/contactcenter/js/cc_search.js	(revision 3282)
@@ -22,4 +22,102 @@
 			return false;
 		}
+
+		this.mount_handler = function (responseText)
+		{
+			var data = new Array();
+			data = unserialize(responseText);
+			
+			if( !data )
+				return false;
+
+			if( data[0] == 0 )
+			{
+				if (_this.onSearchFinish)
+					_this.onSearchFinish(null);
+				return false;
+			}
+			
+			if (data[3].length > 300)
+			{
+				alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca.");
+
+				if (_this.onSearchFinish)
+					_this.onSearchFinish(null);
+
+				return false;
+			}
+			
+			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];
+			}
+	
+			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;
+			}
+		};
+
 
 		/* Attributes */
@@ -141,4 +239,12 @@
 	ccSearchClass.prototype.go = function()
 	{
+		if (this.DOMinput.value == '') {
+			if ((ccTree.actualCatalog != 'bo_group_manager') && 
+					(ccTree.actualCatalog != 'bo_shared_group_manager') && 
+					(!ccTree.actualCatalogIsExternal)) { //Busca avanÃ§ada para pessoal e catÃ¡logo geral
+				ccFullSearchVar.showForm();
+				return;
+			}
+		}
 		var data = new Array();
 		
@@ -197,101 +303,5 @@
 		var _this = this;
 		
-		var handler = function (responseText)
-		{
-			var data = new Array();
-			data = unserialize(responseText);
-			
-			if( !data )
-				return false;
-
-			if( data[0] == 0 )
-			{
-				if (_this.onSearchFinish)
-					_this.onSearchFinish(null);
-				return false;
-			}
-			
-			if (data[3].length > 300)
-			{
-				alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca.");
-
-				if (_this.onSearchFinish)
-					_this.onSearchFinish(null);
-
-				return false;
-			}
-			
-			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];
-			}
-	
-			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;
-			}
-		};
-
-                this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
+		var handler = this.mount_handler;
+        this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
 	}
Index: branches/2.2/contactcenter/js/cc_full_search.js
===================================================================
--- branches/2.2/contactcenter/js/cc_full_search.js	(revision 3282)
+++ branches/2.2/contactcenter/js/cc_full_search.js	(revision 3282)
@@ -0,0 +1,113 @@
+/**
+ * @author diogenes
+ */
+function ccFullSearch() {
+	var win;
+	var fields = null;
+}
+	
+ccFullSearch.prototype.showForm = function() {
+	div = document.getElementById('cc_searchDiv');
+	if(this.fields==null)
+		this.fields = new Array(Element('cc_qa_given_names').value, Element('cc_corporate').value+":", Element('cc_qa_email').value, Element('cc_qa_phone').value);
+	if(div)
+		this.showWindow(div);
+	else {
+		
+		var el = document.createElement("DIV");									
+		el.style.visibility = "hidden";									
+		el.style.position = "absolute";
+		el.style.left = "0px";
+		el.style.top = "0px";
+		el.style.width = "0px";
+		wHeight = Element('ccQAWinHeight').value;
+		el.style.height = wHeight + 'px';
+		el.className = "div_cc_rectQuickAddContact";
+		el.id = 'cc_searchDiv';
+		document.body.appendChild(el);																
+		el.innerHTML = "";								
+
+		var fieldsTop = 10;
+		var fieldsSpace = 30;
+		for (i=0; i<this.fields.length; i++) {
+			el.innerHTML += '<span id="ccSearchSpan' + i + '" style="position: absolute; top: ' +  (fieldsTop+i*fieldsSpace) + 'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">' + this.fields[i] + '</span>';			
+			el.innerHTML += '<input id="ccSearchInp' + i + '" type="text" maxlength="30" style="position: absolute; top: ' + (fieldsTop + i * fieldsSpace) + 'px; left: 110px; width: 135px;">';
+		}
+		el.innerHTML +='<div id="ccSearchFunctions" style="border: 0px solid black; width: 220px; height: 20px">' +
+			'<input title="' + Element('cc_panel_search_text').value + '"  type="button" onclick="ccFullSearchVar.go();" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 35px; width: 60px" value="'+Element('cc_panel_search_text').value+'"/>' +
+			'<input title="' + Element('cc_msg_clean').value + '" type="button" onclick="ccFullSearchVar.clean();" value="' + Element('cc_msg_clean').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 100px; width: 60px" />' +
+			'<input title="' + Element('cc_qa_close').value + '" type="button" onclick="ccFullSearchVar.close();" value="' + Element('cc_qa_close').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 165px; width: 60px" />' +
+			'</div>';
+		el.innerHTML +=	"<br>";
+
+		this.showWindow(el);
+	}
+		
+}
+
+ccFullSearch.prototype.showWindow = function (div)
+{		
+	if(! this.win) {
+		win = new dJSWin({			
+			id: 'ccSearch_'+div.id,
+			content_id: div.id,
+			width: '255px',
+			height: wHeight+'px',
+			title_color: '#3978d6',
+			bg_color: '#eee',
+			title: Element('cc_cs_title').value,						
+			title_text_color: 'white',
+			button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif',
+			border: true });
+		
+		this.win = win;
+		win.draw();			
+	}
+	if((ccTree.actualCatalog=='bo_people_catalog') ||
+		(ccTree.actualCatalog=='bo_shared_people_manager')) //Habilita empresa apenas para catálogos que não sejam do ldap.
+		Element('ccSearchInp1').disabled = false;
+	else
+		Element('ccSearchInp1').disabled = true;
+	this.win.open();
+}
+
+ccFullSearch.prototype.go = function () {
+
+	var _this = this;
+	var data = new Array();
+	var type = Element('cc_type_contact').value;
+	
+	data['fields'] = new Array();
+	
+	if (type=='groups') {
+		data['fields']['id']     = 'group.id_group';			
+		data['fields']['search'] = 'group.title';
+	}		
+	else {			
+		data['fields']['id']     = 'contact.id_contact';		
+		data['fields']['search'] = 'contact.names_ordered';					
+	}
+	data['search_for'] = Element('ccSearchInp0').value;
+	data['full_search'] = new Array();
+	
+	data['full_search']['corporate'] = Element('ccSearchInp1').disabled?'':Element('ccSearchInp1').value;
+	data['full_search']['mail'] = Element('ccSearchInp2').value ;
+	data['full_search']['phone'] = Element('ccSearchInp3').value ;
+	var handler = function(responseText) {
+		ccSearch.mount_handler(responseText);
+		_this.close();		
+	} 
+	Connector.newRequest('fullSearch',CC_url+'search&data='+serialize(data), 'GET',handler);
+}
+
+ccFullSearch.prototype.close = function() {
+		this.win.close();
+}
+
+ccFullSearch.prototype.clean = function() {
+	for (i=0; i<this.fields.length; i++) {
+		Element('ccSearchInp'+i).value = '';
+	}
+}
+
+var ccFullSearchVar = new ccFullSearch();
Index: branches/2.2/contactcenter/templates/default/index.tpl
===================================================================
--- branches/2.2/contactcenter/templates/default/index.tpl	(revision 1690)
+++ branches/2.2/contactcenter/templates/default/index.tpl	(revision 3282)
@@ -89,5 +89,9 @@
 <input id="cc_msg_add_contact_to_group" type="hidden" value="{cc_msg_add_contact_to_group}">
 <input id="cc_contact_type" type="hidden" value="{cc_contact_type}">
+<input id="cc_select_groups" type="hidden" value="{cc_select_groups}">
 
+<input id="cc_corporate" type="hidden" value="{cc_corporate}">
+<input id="cc_catalogues" type="hidden" value="{cc_catalogues}">
+<input id="cc_cs_title" type="hidden" value="{cc_cs_title}">
 
  <!-- END JS MESSAGES -->
@@ -259,3 +263,5 @@
 <script type="text/javascript" src="js/ccIEContacts.js"></script>
 <script type="text/javascript" src="js/ccMain.js"></script>
+<script type="text/javascript" src="js/ccMain.js"></script>
+<script type="text/javascript" src="js/cc_full_search.js"></script>
 <!-- END BOTTOM DETAILS-->						
