<?php
require('../cfg/res.php');
mysql_query("SET NAMES 'utf8'");
//$sql_updr='update enti0 set enti_drtr="1" where enti_codigo in (select drtr from vtas1)';
//echo $sql_updr;
//mysql_query($sql_updr,$link_vcrx);
//$sql_dire='select *from drgd0 where enti_referidox="'.$_SESSION['user_vcrx_id'].'" order by enti_descri, enti_codigo  ';

$sql_dire='select * from drgd0 where (enti_referidox="'.$_SESSION['user_vcrx_id'].'" or drtr="'.$_SESSION['user_vcrx_id'].'") and enti_codigo not in (select enti_codigo from enti0 where enti_referidox!="'.$_SESSION['user_vcrx_id'].'" and enti_referidox>"" and enti_referidox is not null ) order by enti_descri, enti_codigo  ';

//$sql_dire='select *from drgd0 where (enti_referidox="1102433271" or drtr="1102433271" ) and enti_codigo not in (select enti_codigo from enti0 where enti_referidox!="1102433271")order by enti_descri, enti_codigo ';
//echo $sql_dire;
$res_dire=mysql_query($sql_dire,$link_vcrx);

?>
<div align="left">

<?php
if (mysql_num_rows($res_dire)!=0)
{
?>
<div align="center">  Empresarios Registrados </div>
<hr />

<table width="90%" cellpadding="2" cellspacing="0" style="font-size:12px; border-collapse:collapse; border:solid 1px #000;">
<tr align="center" style="border:1px solid #000;">
<th>CI</th>

<th style="">NOMBRES</th>
<th style="">PROVINCIA /CIUDAD</th>

<th>Clave</th>
<th>Datos</th>

</tr>
<?php
$fila_t=1;
$borde_t='border-bottom:dotted 1px #000;';
while($_dire=mysql_fetch_assoc($res_dire))
{
?>
<tr  style=" <?php if($fila_t==5){echo $borde_t; $fila_t=1;}else{$fila_t++;}?> ">

	<td><?php echo $_dire['enti_codigo'];?></td>

	<td><?php echo $_dire['enti_descri'];?></td>
	<td><?php echo $_dire['prvc_descri'].' /'.$_dire['cdad_descri'];?></td>


	<td align="center">
        <?php
	if(empty($_dire['user_cedula']))
	{echo 'No';}
	else
	{echo 'Si';
	}
	?>
	</td>

	<td align="center">
        <?php
	if(empty($_dire['enti_referidox']))
	{echo '-';}
	else
	{echo 'Ok';
	}
	?>
	</td>


</tr>
<?php	
}
?>
</table>

<?php
}
else
{
?>

<div align="center"> No Tiene Empresarios Registrados </div>

<?php
}
?>


</div>
<script type="text/javascript">
function updrtr(ci,tipo,idx)
{
	var res = idx.substring(1, idx.length);
        

	
	$.ajax({
		url:'../lib/updrtr1.php',
		type:'POST',
		data:{ci:ci,tipo:tipo},
		success: function(dato)
		{
			console.log(dato);
			if(dato=='0')
			{
				alert('Atualizado Correctamente.');
				//window.location.reload();
                                document.getElementById(tipo+res).style.display='block';
	                       if(tipo=='1')
                               {
		                   tipo='0';
	                       }
 	                       else
	                       {
		                   tipo='1';
	                       }
	                       document.getElementById(tipo+res).style.display='none';
			}
			else
			{
				alert('Error de Conexion.');
			}
		},
		error:function(objeto)
		{
			console.log(objeto);
		}
	});
}
</script>