Index: sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php
===================================================================
--- sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 4538)
+++ sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 4544)
@@ -219,5 +219,10 @@
                     require_once $_SESSION['rootPath'].'/API/class.servicelocator.php';
                     $ldapService = ServiceLocator::getService('ldap');
-                    $filter =  $ldapService->getSearchFilter($find);
+
+                    if($other['customFilter'])
+                        $filter =  $ldapService->getSearchFilter( $other['CN'], false, $find, $other['exact'] );
+                    else
+                        $filter =  $ldapService->getSearchFilter( $find );
+
                     $fields = array('cn','dn');
                     $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true);
Index: sandbox/2.2.0.2/contactcenter/inc/class.abo_catalog.inc.php
===================================================================
--- sandbox/2.2.0.2/contactcenter/inc/class.abo_catalog.inc.php	(revision 4538)
+++ sandbox/2.2.0.2/contactcenter/inc/class.abo_catalog.inc.php	(revision 4544)
@@ -523,5 +523,9 @@
 							}
 							break;
-											
+						case 'customFilter':
+						case 'exact':
+						case 'CN':
+							break;
+						
 						default:
 							exit('Invalid \'other\' field passed to find in file '.__FILE__.' on line '.__LINE__);
Index: sandbox/2.2.0.2/contactcenter/inc/class.ui_data.inc.php
===================================================================
--- sandbox/2.2.0.2/contactcenter/inc/class.ui_data.inc.php	(revision 4538)
+++ sandbox/2.2.0.2/contactcenter/inc/class.ui_data.inc.php	(revision 4544)
@@ -19,4 +19,5 @@
 		var $public_functions = array(
 			'data_manager' => true,
+                        'advanced_searh_fields' => true
 		);
 
@@ -262,4 +263,53 @@
 			$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'));
+			
+			
+
+
+                            /*
+                             * Monta Contactcenter Busca Avancada
+                             */
+                            $c = CreateObject('phpgwapi.config','contactcenter');
+                            $c->read_repository();
+                            $current_config = $c->config_data;
+
+                            $arraySearch = array();
+                            foreach ($current_config as $index => $value)
+                            {
+
+                                if(substr($index, 0, 24) == 'cc_attribute_searchable_')
+                                {
+                                    if($value == 'true')
+                                    {
+                                        $v = substr($index, 24, strlen($index));
+                                        $arraySearch[] = $v;
+                                    }
+                                }
+                            }
+                            $advanceSearchArray = array();
+                            foreach ($arraySearch as $value)
+                            {
+                                foreach ($current_config as $index => $value2)
+                                {
+                                    if($value == substr($index, 22, strlen($index)) && substr($index, 0, 22) == 'cc_attribute_ldapname_')
+                                    {
+                                        foreach ($current_config as $index2 => $value3)
+                                        {
+                                            if($value == substr($index2, 18, strlen($index2)) && substr($index2, 0, 18) == 'cc_attribute_name_')
+                                                 $advanceSearchArray[$value2] =  $value3;
+                                        }
+                                    }
+
+                                }
+                            }
+
+                            $advanceSearch = array();
+                            foreach ($advanceSearchArray as $index => $value)
+                                $advanceSearch[] ='"'.$index.'":"'.$value.'"';
+
+                            $advancedFields =  "{".implode(',',$advanceSearch)."}";
+
+
+                        $GLOBALS['phpgw']->template->set_var('cc_config_advanced_search', $advancedFields);
 
 			$select_groups = '';
@@ -3194,5 +3244,5 @@
 			{
 
-				$data['search_for'] = utf8_encode($data['search_for']);
+				$data['search_for'] = ($data['search_for']);
 			}
 
@@ -3319,5 +3369,5 @@
 				// 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'), $data['search_for'] != null);
+				$ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC', 'customFilter' => $data['custom_filter'], 'CN' => $data['CN'], 'exact' => $data['exact']), $data['search_for'] != null);
 			}
 			else
@@ -3333,5 +3383,5 @@
 					'contact.connection.mail',
 					'contact.connection.phone'
-					), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'), $data['search_for_area'], $data['search_for'] != null );
+					), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC', 'customFilter' => $data['custom_filter'], 'CN' => $data['CN'], 'exact' => $data['exact']), $data['search_for_area'], $data['search_for'] != null );
 			}
 
Index: sandbox/2.2.0.2/contactcenter/js/cc_tree.js
===================================================================
--- sandbox/2.2.0.2/contactcenter/js/cc_tree.js	(revision 3970)
+++ sandbox/2.2.0.2/contactcenter/js/cc_tree.js	(revision 4544)
@@ -50,4 +50,10 @@
 		var _this = this;
                 var _catalog = catalog;
+		if( parseInt( catalog.charAt(2) ) < 2 ){
+		    document.getElementById( 'advanced' ).style.display = 'none';
+		}
+		else
+		    document.getElementById( 'advanced' ).style.display = '';
+		
 
 		var handler = function (responseText)
Index: sandbox/2.2.0.2/contactcenter/js/cc_config.js
===================================================================
--- sandbox/2.2.0.2/contactcenter/js/cc_config.js	(revision 4502)
+++ sandbox/2.2.0.2/contactcenter/js/cc_config.js	(revision 4544)
@@ -34,6 +34,6 @@
 			
 			if(inputs[0].value == "" || inputs[1].value == "") 
-			{
-				
+			{		
+				//tupla.parentNode.removeChild(tupla);
 				inputs[0].setAttribute("value", "");
 				inputs[1].setAttribute("value", "");
@@ -41,4 +41,5 @@
 				select = tupla.getElementsByTagName("select");
 				select[0].innerHTML = "<option value=\"\" selected=\"selected\"></option>";
+				select[1].innerHTML = "<option value=\"\" selected=\"selected\"></option>";
 				
 				tupla.style.visible = "hidden";
@@ -59,9 +60,4 @@
 	function cc_attribute_add()
 	{
-		var strings = document.getElementsByClassName("cc_attribute")[0].getElementsByTagName("label");
-		var stringNome = strings[0].innerHTML + " ";
-		var stringCorrespLdap = " " + strings[1].innerHTML + " ";
-		var stringTipo = " " + strings[2].innerHTML + " ";
-		
 		var stringTexto = document.getElementsByClassName("cc_attribute")[0].getElementsByTagName("select")[0].getElementsByTagName("option")[0].innerHTML;
 		var stringMultivalorado = document.getElementsByClassName("cc_attribute")[0].getElementsByTagName("select")[0].getElementsByTagName("option")[1].innerHTML
@@ -71,5 +67,5 @@
 		
 		var maior = 0;
-		for (var i=0; i<vars.length; i++) {
+		for (var i=1; i<vars.length; i++) {
 			var tupla = vars[i];
 			var linhaIndice = tupla.getElementsByTagName("input")[0];
@@ -89,5 +85,6 @@
 		var cc_attribute_name = "newsettings[cc_attribute_name_" + numeroAtributo + "]";
 		var cc_attribute_ldapname = "newsettings[cc_attribute_ldapname_" + numeroAtributo + "]";
-		var cc_attribute_type = "newsettings[cc_attribute_type_" + numeroAtributo + "]";
+		var cc_attribute_type        = "newsettings[cc_attribute_type_" + numeroAtributo + "]";
+		var cc_attribute_searchable = "newsettings[cc_attribute_searchable_" + numeroAtributo + "]";
 		
 		var pool = document.getElementById("cc_attribute_fields");
@@ -95,27 +92,23 @@
 		
 		var newDiv = document.createElement("div");
-		newDiv.setAttribute("class", "cc_attribute");
-		
-		var labelNome = document.createElement("label");
-		labelNome.appendChild(document.createTextNode(stringNome));
-		
+			newDiv.setAttribute("class", "cc_attribute");
+	
 		var formularioNome = document.createElement("input");
-		formularioNome.setAttribute("type", "text");
-		formularioNome.setAttribute("name", cc_attribute_name);
-		formularioNome.setAttribute("value", "");
-		
-		var labelCorrespondenteLdap = document.createElement("label");
-		labelCorrespondenteLdap.appendChild(document.createTextNode(stringCorrespLdap));
-		
+			formularioNome.setAttribute("type", "text");
+			formularioNome.setAttribute("name", cc_attribute_name);
+			formularioNome.setAttribute("value", "");
+			formularioNome.setAttribute("style", "width: 170px;");
+	
 		var formularioLdap = document.createElement("input");
-		formularioLdap.setAttribute("type", "text");
-		formularioLdap.setAttribute("name", cc_attribute_ldapname);
-		formularioLdap.setAttribute("value", "");
-		
-		var labelTipo = document.createElement("label");
-		labelTipo.appendChild(document.createTextNode(stringTipo));
-		
+			formularioLdap.setAttribute("type", "text");
+			formularioLdap.setAttribute("name", cc_attribute_ldapname);
+			formularioLdap.setAttribute("value", "");
+			//formularioLdap.setAttribute("style", "margin: 0px 40px;");
+			formularioLdap.setAttribute("style", "width: 170px;");
+
 		var selectTipos = document.createElement("select");
 		selectTipos.setAttribute("name", cc_attribute_type);
+		selectTipos.setAttribute("style", "width: 86px; margin: 0px 0px 0px 8px");
+		//selectTipos.setAttribute("style", "margin: 0px 0px 0px 8px");
 			var optionTexto = document.createElement("option");
 			optionTexto.setAttribute("value", "text");
@@ -130,18 +123,35 @@
 		selectTipos.appendChild(optionMultivalorado);
 				
-
+		var selectPesquisavel = document.createElement("select");
+		selectPesquisavel.setAttribute("name", cc_attribute_searchable);
+		selectPesquisavel.setAttribute("style", "margin: 0px 16px;");
+			var optionYes = document.createElement("option");
+				optionYes.setAttribute("value", "true");
+				optionYes.innerHTML = "Sim ";
+			var optionNo = 	document.createElement("option");
+				optionNo.setAttribute("value", "false");
+				optionNo.setAttribute("selected", "selected");
+				optionNo.innerHTML = "Não ";
+			
+				
+		selectPesquisavel.appendChild(optionYes);
+		selectPesquisavel.appendChild(optionNo);		
+				
+				
+				
 		var imagem = document.createElement("img");
-		imagem.setAttribute("type", "image");
-		imagem.setAttribute("src", "contactcenter/templates/default/images/cc_x.png");
-		imagem.setAttribute("alt", "Excluir Campo ");
-		imagem.setAttribute("style", "width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;");
-		imagem.setAttribute("onclick", "javascript:cc_attribute_delete(this)");
-				
-		newDiv.appendChild(labelNome);
+			imagem.setAttribute("type", "image");
+			imagem.setAttribute("src", "contactcenter/templates/default/images/cc_x.png");
+			imagem.setAttribute("alt", "Excluir Campo ");
+			imagem.setAttribute("style", "width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;");
+			imagem.setAttribute("onclick", "javascript:cc_attribute_delete(this)");
+	
 		newDiv.appendChild(formularioNome);
-		newDiv.appendChild(labelCorrespondenteLdap);
+		newDiv.appendChild(document.createTextNode(" "));
 		newDiv.appendChild(formularioLdap);
-		newDiv.appendChild(labelTipo);
+		newDiv.appendChild(document.createTextNode(" "));
 		newDiv.appendChild(selectTipos);
+		newDiv.appendChild(document.createTextNode(" "));
+		newDiv.appendChild(selectPesquisavel);
 		newDiv.appendChild(document.createTextNode(" "));
 		newDiv.appendChild(imagem);
@@ -168,4 +178,5 @@
 				var select = tupla.getElementsByTagName("select");
 				select[0].innerHTML = "<option value=\"\" selected=\"selected\"></option>";
+				select[1].innerHTML = "<option value=\"\" selected=\"selected\"></option>";		
 				
 			tupla.style.visible = "hidden";
Index: sandbox/2.2.0.2/contactcenter/js/cc_search.js
===================================================================
--- sandbox/2.2.0.2/contactcenter/js/cc_search.js	(revision 3644)
+++ sandbox/2.2.0.2/contactcenter/js/cc_search.js	(revision 4544)
@@ -130,4 +130,5 @@
 		this.DOMinput = document.createElement('input');
 		this.DOMbtn = document.createElement('input');
+		this.DOMAdv = document.createElement('input');
                 this.DOMbtn2 = document.createElement('input');
                 this.DOMbtn3 = document.createElement('input');
@@ -191,5 +192,5 @@
 		this.DOMbtn.type = 'button';
 		//this.DOMbtn.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
-		this.DOMbtn.style.width = '60px';
+// 		this.DOMbtn.style.width = '60px';
 		this.DOMbtn.value = params['button_text'];
 		this.DOMbtn.onclick = function () {_this.go();};
@@ -206,4 +207,89 @@
                 this.DOMbtn3.disabled = 'disabled';
 		this.DOMbtn3.value =  v_label + ':';
+var btn = this.DOMbtn.cloneNode(true);
+
+		var btn = this.DOMbtn.cloneNode(true);
+
+		this.DOMAdv.type = 'button';
+// 		this.DOMAdv.style.padding = '1px';
+		this.DOMAdv.value = 'Busca Avancada';
+		this.DOMAdv.id = 'advanced';
+		this.DOMAdv.onclick = function()
+		{
+		    var target = document.getElementById( 'Layer2' );
+
+		    if( !target.innerHTML )
+		    {
+			var overlay = document.createElement( 'DIV' );
+
+			var items = target.style.width = overlay.innerHTML = '';
+
+			var config = { "cn":"Nome", "uid":"Matricula" };
+
+			for( attr in config )
+			    items += "<tr><td style='padding: 3px'>"+config[attr]+"</td><td style='padding: 5px;'><input type='text' name='advanced_search' label='"+attr+"'><br></td></tr>";
+
+			for( attr in advanced_search_fields )
+			    items += "<tr><td style='padding: 3px'>"+advanced_search_fields[attr]+"</td><td style='padding: 5px;'><input type='text' name='advanced_search' label='"+attr+"'><br></td></tr>";
+			
+			var itemH = document.createElement('DIV');
+
+			itemH.innerHTML = items ? '<table>' + items + '</table>' : '';
+			target.appendChild( itemH );
+
+			target.style.left = "507px";
+
+			var holder = document.createElement('DIV');
+			holder.setAttribute('align','center');
+
+			var exact_search = document.createElement('input');
+			exact_search.type = 'checkbox';
+			exact_search.id = 'exact_search';
+			exact_search.setAttribute( "checked", "checked" );
+
+			var label_exact_search = document.createElement('label');
+			label_exact_search.setAttribute( "rel", exact_search.id );
+			label_exact_search.innerHTML = 'Busca Exata';
+
+			btn.onclick = function(){ _this.go(); };
+			var closeBtn = document.createElement('input');
+			closeBtn.value = 'Fechar';
+			closeBtn.type = 'button';
+			closeBtn.onclick = function(){ 
+			    document.getElementById('Layer2').style.visibility = 'hidden';
+			    document.getElementById('overlay').style.visibility = 'hidden';
+			};
+			
+			holder.appendChild( exact_search );
+			holder.appendChild( label_exact_search );
+			holder.appendChild( spacer.cloneNode(false) );
+			holder.appendChild( btn );
+			holder.appendChild( spacer.cloneNode(false) );
+			holder.appendChild( closeBtn );
+			holder.appendChild( spacer.cloneNode(false) );
+
+			holder.style.padding = '5px';
+			target.style.padding = '5px';
+
+			target.appendChild( holder );
+		    }
+
+		    var overlay = document.getElementById('overlay');
+
+		    overlay.style.visibility = ( overlay.style.visibility === 'hidden' ? 'visible' : 'hidden' );
+
+		    var pos = findPosY( this );
+
+		    with( target.style )
+		    {
+			if( !visibility || visibility === 'visible' )
+			    visibility = 'hidden';
+			else
+			{
+			    visibility = 'visible';
+			   top = 19 + pos + "px";
+			}
+		    }
+		};
 
 		this.DOMprogHold.style.position = 'absolute';
@@ -236,4 +322,6 @@
 		this.DOMdiv.appendChild(spacer);
 		this.DOMdiv.appendChild(this.DOMbtn);
+		this.DOMdiv.appendChild(spacer.cloneNode(false));
+		this.DOMdiv.appendChild(this.DOMAdv);
 		this.DOMdiv.appendChild(this.DOMprogHold);
 		this.DOMdiv.appendChild(this.DOMresult);
@@ -242,12 +330,4 @@
 	ccSearchClass.prototype.go = function()
 	{
-		if ( (this.DOMinput.value == '') && (this.DOMinputx.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();
 		
@@ -269,38 +349,70 @@
 		
 		data['search_for']       = this.DOMinput.value;
-                data['search_for_area']       = this.DOMinputx.value;
-		
-		var invalidChars = /[\%\?]/;
-		if(invalidChars.test(data['search_for']) || invalidChars.test(data['search_for_area'])){
-			showMessage(Element('cc_msg_err_invalid_serch').value);
-			return;
+
+//                 var customFilter = '(mail=*@mail.prognus*)(uid=*c120455*)';
+
+		var customFilterDiv = document.getElementById( 'Layer2' );
+
+                if( customFilterDiv && customFilterDiv.style.visibility !== 'hidden' )
+		{
+		    var customFilter = cn = '';
+		
+		    var values = document.getElementsByName('advanced_search');
+
+		    for( var i = 0; i < values.length; i++ )
+		    {
+			if( !values[i].value ) continue;
+			
+			if( values[i].getAttribute('label') === 'cn' )
+			{
+			    cn = values[i].value;
+			    continue;
+			}
+
+			customFilter += '(' + values[i].getAttribute('label') + '=*' + values[i].value.replace( / /g, '*' ) + '*)';
+		    }
+
+		    if( customFilter )
+		    {
+			if( document.getElementById('exact_search').checked )
+			    data['exact'] = 'true';
+
+			data['search_for'] = customFilter;
+			data['CN'] = cn;
+			data['custom_filter'] = true;
+		    }
+		    else
+			data['search_for'] = cn;
+
+		    customFilterDiv.style.visibility = 'hidden';
+		    document.getElementById('overlay').style.visibility = 'hidden';
 		}
 		
-		var search_for = data['search_for'].split(' ');
-		var greaterThan4 = false;
-                var use_length = v_min;
-
-                if (search_for.length == 1)
-                    {
-                        if(search_for[0].length == 0)
-                            {
-                                search_for[0] = "*";
-                                data['search_for'] = "*";
-                                use_length = 1;
-                            }
-                    }
-
-		for (i = 0; i < search_for.length; i++)
-		{
-			if (search_for[i].length >= use_length)
-			{
-				greaterThan4 = true;
-			}
-		}
-
-		if (!greaterThan4){
-			alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!");
-			return;
-		}
+//		var search_for = data['search_for'].split(' ');
+//		var greaterThan4 = false;
+//                var use_length = v_min;
+
+//                if (search_for.length == 1)
+//                    {
+//                        if(search_for[0].length == 0)
+//                            {
+//                                search_for[0] = "*";
+//                                data['search_for'] = "*";
+//                                use_length = 1;
+//                            }
+//                    }
+
+//		for (i = 0; i < search_for.length; i++)
+//		{
+//			if (search_for[i].length >= use_length)
+//			{
+//				greaterThan4 = true;
+//			}
+//		}
+
+//		if (!greaterThan4){
+//			alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!");
+//			return;
+//		}
 
 		var _this = this;
Index: sandbox/2.2.0.2/contactcenter/templates/default/config.tpl
===================================================================
--- sandbox/2.2.0.2/contactcenter/templates/default/config.tpl	(revision 4538)
+++ sandbox/2.2.0.2/contactcenter/templates/default/config.tpl	(revision 4544)
@@ -52,8 +52,4 @@
 		<td>{lang_Password_for_the_account_above_(if_any)}:</td>
 		<td><input name="newsettings[cc_ldap_pw0]" type="password" value="" size="40" /></td>
-	</tr>
-	<tr class="row_on">
-		<td>{lang_LDAP_max_results}:</td>
-		<td><input name="newsettings[cc_ldap_max_results]" value="{value_cc_ldap_max_results}" size="40" /></td>
 	</tr>
 	<tr class="row_off">
Index: sandbox/2.2.0.2/contactcenter/templates/default/index.tpl
===================================================================
--- sandbox/2.2.0.2/contactcenter/templates/default/index.tpl	(revision 4500)
+++ sandbox/2.2.0.2/contactcenter/templates/default/index.tpl	(revision 4544)
@@ -12,4 +12,7 @@
 </style>
 <script src="js/cc.js" type="text/javascript"></script>
+<script type="text/javascript">
+    var advanced_search_fields = {cc_config_advanced_search};
+</script>
 <!-- JS MESSAGES -->
 <input id="cc_msg_name_mandatory" type="hidden" value="{cc_msg_name_mandatory}">
@@ -256,4 +259,5 @@
 </table>
 	<div id="Layer1" style="position:absolute; top:178px; left:183px;width:auto; padding:2px; z-index:100000; background-color:#F2F3ED; border:1px solid #999999;visibility:hidden"></div>
+	<div id="Layer2" style="position:absolute; top:178px; left:183px;width:auto; padding:2px; z-index:100000; background-color:#F2F3ED; border:1px solid #999999;visibility:hidden"></div>
 	<div id="debug_layer" style="position:absolute;width:0px;height:0px;display:none"></div>
 <!-- _END VIEW CARDS -->
@@ -265,3 +269,4 @@
 <script type="text/javascript" src="js/ccMain.js"></script>
 <script type="text/javascript" src="js/cc_full_search.js"></script>
+<div id='overlay' style='background-color: #666666; opacity: .50; filter:Alpha(Opacity=50); height: 100%; width: 100%; position: absolute; top: 0; left: 0; visibility: hidden;'></div>
 <!-- END BOTTOM DETAILS-->						
