<?php session_start();?>

<?php

$pnumcntn=strtoupper(str_replace('-','',$_POST['pnumero']));

$url='http://www.shippingline.org/track/?container='.$pnumcntn;
$page = file_get_contents($url);
// echo $url;

$page2=$page;
$page2=substr($page2,strpos($page2,"iframe src="),500);
$page2=substr($page2,strpos($page2,'/'),500);
$page2=substr($page2,0,strpos($page2,'"'));
$url='http://www.shippingline.org'.$page2;
// /track_frame/?container=TRIU8403427&key=2549874&type=container

$page = file_get_contents($url);


if(mb_stristr($page,$pnumcntn) && !mb_stristr($page,'not found') && 1==1)
{
  require('../cfg/cfg.php');
  require('../cfg/res.php');
//   echo $page;

	$sql_cntn='insert into cntn0(cntn_codigo,cntn_descri,cntn_status,cntn_idate,cntn_iuser)';
	$sql_cntn.='value("'.$pnumcntn.'","NUEVO CONTENEDOR","-",now(),"'.$_SESSION['user_vcrx_id'].'")';
	$res_cntn=mysql_query($sql_cntn,$link_vcrx);
// 	echo $sql_cntn;
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"</h4>"),10000);
  $page2=substr($page2,strpos($page2,"<h4>"),10000);
  $page2=substr($page2,strpos($page2,"</span>")+7,10000);
  $page2=substr($page2,strpos($page2,"</span>")+7,10000);
  $xdescri=strtoupper(trim(substr($page2,0,strpos($page2,"</h4>"))));
	
	if ($xdescri=="")
	{
 	$sql_cntn='update cntn0 set cntn_descri="'.substr($pnumcntn,0,4).'-'.substr($pnumcntn,4,7).'" where cntn_codigo like "'.$pnumcntn.'"';
	$res_cntn=mysql_query($sql_cntn,$link_vcrx);
	}
	else
	{	
 	$sql_cntn='update cntn0 set cntn_descri="'.$xdescri.'" where cntn_codigo like "'.$pnumcntn.'"';
	$res_cntn=mysql_query($sql_cntn,$link_vcrx);
	}


	
}



?>

