<?php
 
if(session_id()=="") 
	session_start();
$com="AS";	
require_once("DMMYSQLG.php");
$tipRequest=$_REQUEST['typeRequest'];

/*Si Tipo de respuesta es distinta de AutoCompletar Se imprime Ventana de Busqueda*/
if(trim($tipRequest)=="" || !isset($tipRequest)){
	require_once("DFJQUERY.inc");
	?>
	<html>
	<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
	<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
	
	
	<body id="bodyVENTESP">
	 <form name="formbascps" id="formbascps" method="post" action="">
	   <img src="logos/mover.gif" width="30" height="30" /><img src="logos/cerrar.gif" alt="cerrar" width="30" height="30" onClick="<?php
echo "cloLayAndCpy({idLayer:'".$_POST['layerToLoad']."'},{})";?>"/>
		<input type="hidden", name="layerToLoad" id="layerToLoad" value="<?php
echo trim($_POST['layerToLoad']);?>">
		<input type="hidden", name="idRetObj" id="idRetObj" value="<?php
echo trim($_POST['idRetObj']);?>">
		<input type="hidden", name="nomRetObj" id="nomRetObj" value="<?php
echo trim($_POST['nomRetObj']);?>">
		
		<input type="hidden" name="refOnClose" id="refOnClose" value="<?php
echo trim($_POST['refOnClose']);?>">
		<input type="hidden" name="idForm" id="idForm" value="<?php
echo trim($_POST['idForm']);?>">
		<input type="hidden" name="actForm" id="actForm" value="<?php
echo trim($_POST['actForm']);?>">
		<input type="hidden" name="tarForm" id="tarForm" value="<?php
echo trim($_POST['tarForm']);?>">		
	<table width="430"  border="0" align="center">
		  <tr> 
			<td colspan="4" style="#CCCCCC"><div align="center" id="titleTableEsp" class="Estilo2">CATALOGO DE CLIENTES </div></td>
		  </tr>
		  <tr> 
			<td width="138"  style="#3399FF">
			  
			  <div align="center">
				<input name="tipBusCat" type="radio" value="nom" onClick=" 	
				loadOnLayer(
				{
					action:'DYCLICATCLI.php',
					idLayer:document.getElementById('layerToLoad').value
				},			
				{	
					textBus:document.getElementById('textBus').value,
					idRetObj:document.getElementById('idRetObj').value,
					nomRetObj:document.getElementById('nomRetObj').value,
					tipBusCat:getValRadChe('tipBusCat')
				});"  />
				Nombre</div></td>
			<td width="118" style="#3399FF"><input name="tipBusCat" type="radio" value="rfc" onClick=" 	
				loadOnLayer(
				{
					action:'DYCLICATCLI.php',
					idLayer:document.getElementById('layerToLoad').value
				},			
				{	
					textBus:document.getElementById('textBus').value,
					idRetObj:document.getElementById('idRetObj').value,
					nomRetObj:document.getElementById('nomRetObj').value,
					tipBusCat:getValRadChe('tipBusCat')
				});" />
			  R.F.C.</td>
			<td width="118" style="#3399FF"><input name="tipBusCat" type="radio"  value="id" onClick=" 	
				loadOnLayer(
				{
					action:'DYCLICATCLI.php',
					idLayer:document.getElementById('layerToLoad').value
				},			
				{	
					textBus:document.getElementById('textBus').value,
					idRetObj:document.getElementById('idRetObj').value,
					nomRetObj:document.getElementById('nomRetObj').value,
					tipBusCat:getValRadChe('tipBusCat')
				});" />
	Clave </td>
			<td width="38"  style="#3399FF"><input type="button" name="agregarLayerEsp" id="agregarLayerEsp" value="Agregar" 
			onClick="
				openWindow({action:'DX40000_AG.php',name:'AGREGA_CLIENTE',resize:true,width:1000,height:400},{tipAgr:'C',retAct:'close'});
			" class="clase3" /></td>
		  </tr>
		  <tr>
			<td colspan="5" style="#3399FF"><div align="center">
			  <input name="textBus" id="textBus" type="text" size="50"  value="<?php
echo trim($_POST['textBus']);?>"  maxlength="255" onKeyPress="return  loadOnLayerByKey(
				{
					action:'DYCLICATCLI.php',
					idLayer:document.getElementById('layerToLoad').value,
					accKey:13
				}
				,			
				{	
					textBus:document.getElementById('textBus').value,
					idRetObj:document.getElementById('idRetObj').value,
					nomRetObj:document.getElementById('nomRetObj').value,
					tipBusCat:'rfc'
				});"/>
			</div></td>
		  </tr>
	   </table>
		<table align = "center">
		  <tr>
			<td nowrap style="#CCCCCC"><div align="center" class="Estilo2">Sel. </div></td>
			<td nowrap style="#CCCCCC"><div align="center" class="Estilo2">Con/Mod </div></td>
			<td nowrap style="#CCCCCC"><div align="center" class="Estilo2">Nombre/Empresa </div></td>
			<td nowrap style="#CCCCCC"><div align="center" class="Estilo2">Apellido Paterno </div></td>
			<td nowrap style="#CCCCCC"><div align="center" class="Estilo2">Apellido Materno </div></td>
			<td nowrap style="#CCCCCC"><div align="center" class="Estilo2">RFC</div></td>
			 <td nowrap style="#CCCCCC"><div align="center" class="Estilo2">Sucursal</div></td>
		  </tr>
		  <?php
 
		  $textBus=utf8_decode(trim($_REQUEST['textBus']));
	if($textBus!=''){
		
		if($_REQUEST['tipBusCat']=="id"){
			@$sql = mysqli_query($con ,"SELECT 
									dgcatcli.*,
									dxbascps.nom_suc 
								FROM 
									dgcatcli
								LEFT JOIN dxbascps ON(dxbascps.codigo=dgcatcli.codigo) 
								WHERE 
									dgcatcli.cod_cli like '$textBus%' 
								ORDER BY 
									dgcatcli.nom_cli,dgcatcli.ap_pat_cli,dgcatcli.ap_mat_cli");
		}elseif($_REQUEST['tipBusCat']=="nom"){
			$sq_retrieve = "SELECT 
								dgcatcli.*,
								dxbascps.nom_suc 
							FROM 
								dgcatcli
							LEFT JOIN dxbascps ON(dxbascps.codigo=dgcatcli.codigo) 	 
							WHERE  
								 TRIM(CONCAT(dgcatcli.nom_cli,' ',dgcatcli.ap_pat_cli,' ',dgcatcli.ap_mat_cli)) like '$textBus%'
								OR TRIM(CONCAT(dgcatcli.ap_pat_cli,' ',dgcatcli.ap_mat_cli,' ',dgcatcli.nom_cli)) like '$textBus%'
								OR dgcatcli.nom_cli like '$textBus%'
							ORDER BY 
								dgcatcli.nom_cli,dgcatcli.ap_pat_cli,dgcatcli.ap_mat_cli";
			@$sql = mysqli_query($con ,$sq_retrieve);
		}
		elseif($_REQUEST['tipBusCat']=="rfc"){
			$sq_retrieve = "SELECT 
								dgcatcli.*,
								dxbascps.nom_suc  
							FROM 
								dgcatcli
							LEFT JOIN dxbascps ON(dxbascps.codigo=dgcatcli.codigo) 	 
							WHERE  
								 dgcatcli.rfc_cli like'$textBus%'
							ORDER BY 
								 dgcatcli.nom_cli,dgcatcli.ap_pat_cli,dgcatcli.ap_mat_cli";
			@$sql = mysqli_query($con ,$sq_retrieve);
		}
	
	$arrStyles=array("styTabEspA","styTabEspB");
	$i=0;
		while(@$reg = mysqli_fetch_array($sql)){
			echo '<tr class="'.$arrStyles[($i%2)].'">';
			echo "<td>
					<input type=\"button\" name=\"boton\" value=\"$reg['cod_cli']\" class=\"clase3\" onclick=\"
						cloLayAndCpy(
							{
								idLayer:'".$_POST['layerToLoad']."',
								refOnClose:'".$_POST['refOnClose']."',
								idForm:'".$_POST['idForm']."',
								actForm:'".$_POST['actForm']."',
								tarForm:'".$_POST['tarForm']."'							
							},
							{
								$_POST['idRetObj']: '".$reg['cod_cli']."',
								$_POST['nomRetObj']: '$reg['ap_pat_cli'] $reg['ap_mat_cli'] $reg['nom_cli']'
							}
						);
					\">
				</td>";
			 echo "<td>
					<input type=\"button\" name=\"boton\" value=\"CON/MOD\" class=\"clase3\" onclick=\"
			openWindow({
						action:'DX40000_MO.php',
						name:'MODIFICA_CLIENTE',
						resize:true,
						width:1000,
						height:400
					  },
					  {
						bot:'".$reg['codigo']."',
						botCat:'".$reg['cod_cli']."', 
						tipAgr:'C',
						retAct:'close'
					  });
					\">
			</td>";	
			echo '<td> <div align="left">' . utf8_encode($reg['nom_cli']) . '&nbsp;</div></td>';
			echo '<td> <div align="left">' . utf8_encode($reg['ap_pat_cli']) . '&nbsp;</div></td>';
			echo '<td> <div align="left">' . utf8_encode($reg['ap_mat_cli']) . '&nbsp;</div></td>';
			echo '<td> <div align="left">' . utf8_encode($reg['rfc_cli']) . '&nbsp;</div></td>';
			echo '<td> <div align="left">' . utf8_encode($reg['nom_suc']) . '&nbsp;</div></td>';
			echo '</tr>';
			$i++;
		}
	}
	?>
		</table>
	 </form>
	</body>
	</html>
<?php

}
/*TERMINA si Tipo de respuesta es distinta de AutoCompletar (abrir ventana de busqueda en layer)*/
elseif($tipRequest=='ac'){
	$textBus=utf8_decode(mysqli_real_escape_string($con,$_REQUEST['q']));
	if(trim($textBus)!=''){
		
		if($_REQUEST['tipBusCat']=="id"){
			@$sql = mysqli_query($con ,"SELECT 
									dgcatcli.*,
									dxbascps.calle,
									dxbascps.no_ext,
									dxbascps.no_int,
									geoyos_jc.dxestado.des_estado,
									geoyos_jc.dxdelmun.des_delmun,
									geoyos_jc.dxcoloni.des_colonia,
									geoyos_jc.dxpaises.des_pais,
									dxbascps.nom_suc,
									dxbascps.no_suc 
								FROM 
									dgcatcli
								LEFT JOIN dxbascps ON(dxbascps.codigo=dgcatcli.codigo)
								LEFT JOIN geoyos_jc.dxpaises ON(geoyos_jc.dxpaises.cve_pais=dxbascps.cve_pais)
								LEFT JOIN geoyos_jc.dxestado ON(geoyos_jc.dxestado.cve_estado=dxbascps.cve_estado)
								LEFT JOIN geoyos_jc.dxdelmun ON(geoyos_jc.dxdelmun.cve_delmun=dxbascps.cve_delmun)
								LEFT JOIN geoyos_jc.dxcoloni ON(geoyos_jc.dxcoloni.cve_col=dxbascps.des_colonia)										
								WHERE 
									dgcatcli.cod_cli like '$textBus%' 
								ORDER BY
									dgcatcli.cod_cli");
		}elseif($_REQUEST['tipBusCat']=="nom"){
			$sq_retrieve = "SELECT 
								dgcatcli.*,
								dxbascps.calle,
								dxbascps.no_ext,
								dxbascps.no_int,
								geoyos_jc.dxestado.des_estado,
								geoyos_jc.dxdelmun.des_delmun,
								geoyos_jc.dxcoloni.des_colonia,
								geoyos_jc.dxpaises.des_pais,
								dxbascps.nom_suc,
								dxbascps.no_suc 
							FROM 
								dgcatcli
							LEFT JOIN dxbascps ON(dxbascps.codigo=dgcatcli.codigo)
							LEFT JOIN geoyos_jc.dxpaises ON(geoyos_jc.dxpaises.cve_pais=dxbascps.cve_pais)
							LEFT JOIN geoyos_jc.dxestado ON(geoyos_jc.dxestado.cve_estado=dxbascps.cve_estado)
							LEFT JOIN geoyos_jc.dxdelmun ON(geoyos_jc.dxdelmun.cve_delmun=dxbascps.cve_delmun)
							LEFT JOIN geoyos_jc.dxcoloni ON(geoyos_jc.dxcoloni.cve_col=dxbascps.des_colonia)														 	 
							WHERE  
								 TRIM(CONCAT(dgcatcli.nom_cli,' ',dgcatcli.ap_pat_cli,' ',dgcatcli.ap_mat_cli)) like '$textBus%'
								OR TRIM(CONCAT(dgcatcli.ap_pat_cli,' ',dgcatcli.ap_mat_cli,' ',dgcatcli.nom_cli)) like '$textBus%'
								OR dgcatcli.nom_cli like '$textBus%'
							ORDER BY 
								dgcatcli.nom_cli,dgcatcli.ap_pat_cli,dgcatcli.ap_mat_cli";
			@$sql = mysqli_query($con ,$sq_retrieve);
		}
		elseif($_REQUEST['tipBusCat']=="rfc"){
			$sq_retrieve = "SELECT 
								dgcatcli.*,
								dxbascps.calle,
								dxbascps.no_ext,
								dxbascps.no_int,
								geoyos_jc.dxestado.des_estado,
								geoyos_jc.dxdelmun.des_delmun,
								geoyos_jc.dxcoloni.des_colonia,
								geoyos_jc.dxpaises.des_pais,
								dxbascps.nom_suc,
								dxbascps.no_suc 
							FROM 
								dgcatcli
							LEFT JOIN dxbascps ON(dxbascps.codigo=dgcatcli.codigo) 	 
							WHERE  
								 dgcatcli.rfc_cli like'$textBus%'
							ORDER BY 
								 dgcatcli.nom_cli,dgcatcli.ap_pat_cli,dgcatcli.ap_mat_cli";
			@$sql = mysqli_query($con ,$sq_retrieve);
		}
		echo mysqli_error($con);
		while(@$reg = mysqli_fetch_array($sql)){
			echo utf8_encode("$reg['ap_pat_cli'] $reg['ap_mat_cli'] $reg['nom_cli']")."|$reg['cod_cli']|$reg['rfc_cli']|$reg['nom_suc']|$reg['calle']|$reg['no_ext']|$reg['no_int']|$reg['des_colonia']|$reg['des_delmun']|$reg['des_estado']|$reg['des_pais']|$reg['no_suc']\n";
		}
	}	
}
?>