<?php session_start();
require('../cfg/res.php');
require('../cfg/cfg.php');
include('php_gene1.php');
include('php_session.php');


$user_cedula=r_fiel('user',$user_codigo,'cedula');

$enti_sql='select * from enti00 where enti_codigo="'.$_POST['ci'].'"';
$ci=$_POST['ci'];
if(empty($_POST['ci'])){$ci=$_SESSION['user_vcrx_id'];}
if ( !mb_stristr('admi.sist.supe',strtolower($user_tipo))) {$ci=$user_cedula;}

// echo '*/*/';
// echo new_docu('PLA1','001001');


	$n1='';
	$n2='';
	$a1='';
	$a2='';
	$matriz='';
  $parroq='';
  $calle1='';
  $calle2='';
  $calle3='';
  $callen='';
	$telefono='';
	$email='';
	$emailce='';
	$fn='';
  $fi='';
	$nik='';
	$c1='';
	$c2='';
	$c3='';
	$c4='';
	$cn='';
	$e1='';
	$t1='';
	$t2='';
	$ref='';
	$pais='';
  $ciudad='';
  $provincia='';
	$ciu='';
	$razsoc='';
	$nomcom='';
	$struc='';
	$sexo='';
	$vndd='';
	$tpro='';
	$zsub='';
	$csub='';
	$cargo='';
  $dcto='';
  $comi='';
	$rcdd='';
	$pspt='';
	$idex='';
	$conadis='';
  $factura='';

$enti_sql='select *from enti00 where enti_codigo="'.$ci.'"';
$enti_sql='select *from enti0 where enti_codigo="'.$ci.'"';
$enti_res=mysql_query($enti_sql,$link_vcrx);

$matriz=@mysql_result($enti_res,0,'enti_matriz');
$razsoc=@mysql_result($enti_res,0,'enti_razsoc');
$parroq=@mysql_result($enti_res,0,'enti_parroq');


//   echo get_ruc8($ci);

if(strlen($razsoc)<=5 or strlen($matriz)<=5 )
{
  get_ruc0($ci);
  $enti_res=mysql_query($enti_sql,$link_vcrx);
}

if(mysql_num_rows($enti_res)!=0)
{	
  $n1=mysql_result($enti_res,0,'enti_nom1');
  $n2=mysql_result($enti_res,0,'enti_nom2');
  $a1=mysql_result($enti_res,0,'enti_ape1');
  $a2=mysql_result($enti_res,0,'enti_ape2');
  $matriz=mysql_result($enti_res,0,'enti_matriz');
  $parroq=@mysql_result($enti_res,0,'enti_parroq');
  $telefono=mysql_result($enti_res,0,'enti_telefono');
  $email=mysql_result($enti_res,0,'enti_email');
  $emailce=mysql_result($enti_res,0,'enti_emailce');
  $fn=mysql_result($enti_res,0,'enti_fechanac');
  $fi=mysql_result($enti_res,0,'enti_fechaini');
  $nik=mysql_result($enti_res,0,'enti_nickname');
  $calle1=mysql_result($enti_res,0,'enti_calle1');
  $calle2=mysql_result($enti_res,0,'enti_calle2');
  $calle3=mysql_result($enti_res,0,'enti_calle3');
  $callen=mysql_result($enti_res,0,'enti_callen');
  $c1=mysql_result($enti_res,0,'enti_calle1');
  $c2=mysql_result($enti_res,0,'enti_calle2');
  $c3=mysql_result($enti_res,0,'enti_calle3');
  $cn=mysql_result($enti_res,0,'enti_callen');
  $e1=mysql_result($enti_res,0,'enti_email');
  $t1=mysql_result($enti_res,0,'enti_telefono');
  $ref=mysql_result($enti_res,0,'enti_referidox');
  $pais=mysql_result($enti_res,0,'enti_pais');
  $ciudad=mysql_result($enti_res,0,'enti_ciudad');
  $provincia=mysql_result($enti_res,0,'enti_provincia');
  $cdad=mysql_result($enti_res,0,'enti_cdad');
  $ci=mysql_result($enti_res,0,'enti_codigo');
  $razsoc=mysql_result($enti_res,0,'enti_razsoc');
  $nomcom=mysql_result($enti_res,0,'enti_nomcom');
  $struc=mysql_result($enti_res,0,'enti_struc');
  $sexo=mysql_result($enti_res,0,'enti_sexo');
  $vndd=mysql_result($enti_res,0,'enti_vndd');
  $rcdd=mysql_result($enti_res,0,'enti_rcdd');
  $tpro=mysql_result($enti_res,0,'enti_tpro');
  $tprod=@mysql_result($enti_res,0,'tpro_descri');
  $zsub=mysql_result($enti_res,0,'enti_zsub');
  $zsubd=@mysql_result($enti_res,0,'zsub_descri');
  $csub=mysql_result($enti_res,0,'enti_csub');
  $cargo=mysql_result($enti_res,0,'enti_cargo');
  $dcto=mysql_result($enti_res,0,'enti_dcto');
  $comi=mysql_result($enti_res,0,'enti_comi');
  $pspt=mysql_result($enti_res,0,'enti_pasaporte');
  $idex=mysql_result($enti_res,0,'enti_idexterior');
  $conadis=mysql_result($enti_res,0,'enti_conadis');
  $factura=mysql_result($enti_res,0,'enti_factura');
}
	
if(!empty($ref))
{
	$ref_sql='select enti_descri from enti0 where enti_codigo="'.$ref.'"';
	$ref_res=mysql_query($ref_sql,$link_vcrx);
	if(mysql_num_rows($ref_res)!=0)	{	$ref_descri=mysql_result($ref_res,0,'enti_descri');	}
}
else
{
	$ref=$empr_ruc;
	$ref_descri=$empr_nomcom;
}
//0985834563
echo '<input type="hidden" id="hn1" value="'.$n1.'"/>';
echo '<input type="hidden" id="hn2" value="'.$n2.'"/>';
echo '<input type="hidden" id="ha1" value="'.$a1.'"/>';
echo '<input type="hidden" id="ha2"  value="'.$a2.'"/>';
echo '<input type="hidden" id="hmatriz"  value="'.$matriz.'"/>';
echo '<input type="hidden" id="hparroq"  value="'.$parroq.'"/>';
echo '<input type="hidden" id="hcalle1"  value="'.$calle1.'"/>';
echo '<input type="hidden" id="hcalle2"  value="'.$calle2.'"/>';
echo '<input type="hidden" id="hcalle3"  value="'.$calle3.'"/>';
echo '<input type="hidden" id="hcallen"  value="'.$callen.'"/>';
echo '<input type="hidden" id="htelefono"  value="'.$telefono.'"/>';
echo '<input type="hidden" id="hemail"  value="'.$email.'"/>';
echo '<input type="hidden" id="hemailce"  value="'.$emailce.'"/>';
echo '<input type="hidden" id="hfn" value="'.$fn.'"/>';
echo '<input type="hidden" id="hfi" value="'.$fi.'"/>';
echo '<input type="hidden" id="hnik"  value="'.$nik.'"/>';
echo '<input type="hidden" id="hc1"  value="'.$c1.'"/>';
echo '<input type="hidden" id="hc2"  value="'.$c2.'"/>';
echo '<input type="hidden" id="hc3"  value="'.$c3.'"/>';
echo '<input type="hidden" id="hcn"  value="'.$cn.'"/>';
echo '<input type="hidden" id="he1"  value="'.$e1.'"/>';
echo '<input type="hidden" id="ht1"  value="'.$t1.'"/>';
echo '<input type="hidden" id="href"  value="'.$ref.'"/>';
echo '<input type="hidden" id="hpais"  value="'.$pais.'"/>';
echo '<input type="hidden" id="hciudad"  value="'.$ciudad.'"/>';
echo '<input type="hidden" id="hcdad"  value="'.$cdad.'"/>';
echo '<input type="hidden" id="hprovincia"  value="'.$provincia.'"/>';
echo '<input type="hidden" id="hrazsoc"  value="'.$razsoc.'"/>';
echo '<input type="hidden" id="hnomcom"  value="'.$nomcom.'"/>';
echo '<input type="hidden" id="hstruc"  value="'.$struc.'"/>';
echo '<input type="hidden" id="hsexo"  value="'.$sexo.'"/>';
echo '<input type="hidden" id="hvndd"  value="'.$vndd.'"/>';
echo '<input type="hidden" id="hrcdd"  value="'.$rcdd.'"/>';
echo '<input type="hidden" id="htpro"  value="'.$tpro.'"/>';
echo '<input type="hidden" id="htprod"  value="'.@mysql_result($enti_res,0,'tpro_descri').'"/>';
echo '<input type="hidden" id="hzsub"  value="'.$zsub.'"/>';
echo '<input type="hidden" id="hzsubd"  value="'.@mysql_result($enti_res,0,'zsub_descri').'"/>';
echo '<input type="hidden" id="hcsub"  value="'.$csub.'"/>';
echo '<input type="hidden" id="hcargo"  value="'.$cargo.'"/>';
echo '<input type="hidden" id="hdcto"  value="'.$dcto.'"/>';
echo '<input type="hidden" id="hcomi"  value="'.$comi.'"/>';
echo '<input type="hidden" id="hpspt"  value="'.$pspt.'"/>';
echo '<input type="hidden" id="hidex"  value="'.$idex.'"/>';
echo '<input type="hidden" id="hconadis"  value="'.$conadis.'"/>';
echo '<input type="hidden" id="hfactura"  value="'.$factura.'"/>';


$sql_adrs='select *from adrs00 where adrs_enti="'.$ci.'" and adrs_status!="X" order by adrs_defa desc,adrs_codigo';
$res_adrs=mysql_query($sql_adrs,$link_vcrx);

$tadrs=mysql_num_rows($res_adrs);
if($tadrs!=0)
{
$adrsdefa=mysql_result($res_adrs,0,'adrs_codigo');

$sql_uadrsd='update adrs0 set adrs_defa=0 where adrs_enti="'.$ci.'"';
$res_uadrsd=mysql_query($sql_uadrsd,$link_vcrx);

$sql_uadrsd='update adrs0 set adrs_defa=1 where adrs_enti="'.$ci.'" and adrs_codigo="'.$adrsdefa.'"';
$res_uadrsd=mysql_query($sql_uadrsd,$link_vcrx);

$sql_uadrsd='update enti0 set enti_adrs="'.$adrsdefa.'" where enti_codigo="'.$ci.'"';
$res_uadrsd=mysql_query($sql_uadrsd,$link_vcrx);
}	

$res_adrs=mysql_query($sql_adrs,$link_vcrx);
			
?>
<br>           
<hr>
<table width="100%" border="0" cellpadding="2" cellspacing="0" class="tablitita"   style="border-collapse:collapse;font-size:14px;">
   <tr style="border-top:solid 2px;border-bottom:solid 2px;" align="center">
   <th width= "1%">_</th>
   <th >e-mail</th>
   <th>Calle1</th>
   <th>Calle2</th>
   <th>Num.</th>
   <th>Refer</th>
   <th>Telef.</th>
   <th width="60">ext.</th>
   <th>Prov/Ciudad</th>
   <th>Contacto</th>
	</tr>

 <?php while($r_adrs=mysql_fetch_assoc($res_adrs)){?>
			
<tr valign="top" id="<?php echo $r_adrs['adrs_codigo'];?>" style="border-bottom:dotted 1px #000000;" >
    <td>
 		<input type="radio" id="<?php echo 'defa'.$r_adrs['adrs_codigo'] ?>" name="adrsdefa" <?php if($r_adrs['adrs_defa']=='1'){echo 'checked';}?> onclick="_defa_adr('<?php echo $r_adrs['adrs_codigo'];?>','<?php echo $r_adrs['adrs_enti'];?>');"/><span></span> <br/>
		</td>
	
    <td><?php echo $r_adrs['adrs_email'];?></td>
    <td><?php echo $r_adrs['adrs_calle1'];?></td>
    <td><?php echo $r_adrs['adrs_calle2'];?></td>
    <td align="center"><?php echo $r_adrs['adrs_callen'];?></td>
    <td><?php echo $r_adrs['adrs_calle3'];?></td>
    <td align="center"><?php echo $r_adrs['adrs_tlfn'];?></td>
    <td align="center"><?php echo $r_adrs['adrs_ext'];?></td>
    <td align="center"><?php echo $r_adrs['prvc_descri'].'/'.$r_adrs['cdad_descri'];?></td>
    <td><?php echo $r_adrs['adrs_contacto'];?></td>
    <td width="20"><input type="image" src="http://vcrxol.com/_img/x.png" width="18" onclick="_delete_adr('<?php echo $r_adrs['adrs_codigo'];?>','<?php echo $r_adrs['adrs_enti'];?>');"  /></td>
 </tr>
<?php }?>
    <td id="ttel2"></td>
    <td id="text2"></td>
    <td id="tcontacto2" ></td>
    <td id="tc12"  ></td>
    <td id="tc22"></td>
    <td id="tc32"></td>
    <td id="tcn2"></td>
    <td id="tciudad2"></td>
    <td id="temal2" ></td>
    <td id="tico"></td>

</table>