<?php session_start();?>

<?php


$pnumced=substr($_POST['pnumero'],0,10).'';
$url = 'http://karview.kradac.com:8080/registrocivil/webresources/servicios/consultar/ced='.$pnumced;





$page = file_get_contents($url);
echo $url;

if(mb_stristr($page,$pnumced))
{
  require('../cfg/cfg.php');
  require('../cfg/res.php');
//   echo $page;
	
	$sql_ruc1='insert into enti0(enti_codigo,enti_descri,enti_status,enti_idate)value('.$pnumced.',"NUEVO RUC","-",now())';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

  $page2=$page;
  $page2=substr($page2,strpos($page2,"apellidosNombres"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xrazsoc=strtoupper(substr($page2,0,strpos($page2,'"')));
	$xrazsoc=str_replace('"','-',$xrazsoc);
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"apellidos"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
	$xape12=strtoupper(substr($page2,0,strpos($page2,'"')));
	$xape1=substr($xape12,0,strpos($xape12,' '));
	$xape2=substr($xape12,strpos($xape12,' ')+1,100);
		
  $page2=$page;
  $page2=substr($page2,strpos($page2,"nombres"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xnom12=strtoupper(substr($page2,0,strpos($page2,'"')));
	$xnom1=substr($xnom12,0,strpos($xnom12,' '));
	$xnom2=substr($xnom12,strpos($xnom12,' ')+1,100);
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"direccion"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xdireccion=strtoupper(substr($page2,0,strpos($page2,'"')));
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"numeroCasa"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xnumcasa=strtoupper(substr($page2,0,strpos($page2,'"')));
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"parroquia"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xparroquia=strtoupper(substr($page2,0,strpos($page2,'"')));
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"fechaNacimiento"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xfecnac=strtoupper(substr($page2,0,strpos($page2,'"')));
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"genero"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xsexo=strtoupper(substr($page2,0,strpos($page2,'"')));
	if(mb_stristr($xsexo,'M')){$xsexo='1';}else{$xsexo='2';}

	$page2=$page;
  $page2=substr($page2,strpos($page2,"huellasDigitales"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xhuellas=strtoupper(substr($page2,0,strpos($page2,'"')));
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"estadoCivil"),250);
  $page2=substr($page2,strpos($page2,':')+2,250);
  $xstcivil=strtoupper(substr($page2,0,strpos($page2,'"')));
	

	
	
	if(strlen($xape1)>1)
	{
 	$sql_ruc1='update enti0 set enti_razsoc="'.$xrazsoc.'" where enti_codigo like "'.substr($pnumced,0,10).'"';
// 	$sql_ruc1.=' and (enti_razsoc="" or enti_razsoc is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_descri="'.$xrazsoc.'" where enti_codigo like "'.substr($pnumced,0,10).'"';
// 	$sql_ruc1.=' and (enti_descri="" or enti_descri is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_ape1="'.$xape1.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_ape1="" or enti_ape1 is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_ape2="'.$xape2.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_ape2="" or enti_ape2 is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_nom1="'.$xnom1.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_nom1="" or enti_nom1 is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_nom2="'.$xnom2.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_nom2="" or enti_nom2 is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_matriz="'.$xdireccion.'/'.$xnumcasa.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_matriz="" or enti_matriz is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);
// 		echo $sql_ruc1;

	$sql_ruc1='update enti0 set enti_direccion="'.$xdireccion.'/'.$xnumcasa.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_direccion="" or enti_direccion is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_sexo="'.$xsexo.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_sexo="" or enti_sexo is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_fechanac="'.$xfecnac.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_fechanac="" or enti_fechanac is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_huellas="'.$xhuellas.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_huellas="" or enti_huellas is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

	$sql_ruc1='update enti0 set enti_stcivil="'.$xstcivil.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
	$sql_ruc1.=' and (enti_stcivil="" or enti_stcivil is null)';
	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);

// 	$sql_ruc1='update enti0 set enti_nomcom="'.$xnomcom.'" where enti_codigo like "'.substr($pnumced,0,10).'%"';
// 	$res_ruc1=mysql_query($sql_ruc1,$link_vcrx);
	}
  
}



?>

