<?php


set_time_limit (3600 );


define('SF_ROOT_DIR', "/home/sinergiaperu/public_html/sinergia");
//define('SF_ROOT_DIR', "C://wamp/www/sinergia");
define('SF_APP',      'sys');
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."functions".DIRECTORY_SEPARATOR."HelperHelper.php");
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config_core_compile.php');
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'config_autoload.php');


////////////////////////////////////////////////////////////////////////////////////////
//clases incluidas del sistema



$con = Conexion::getConexion();
$a_param = Conexion::getParamDbByAlias($apps);

if (!mysql_select_db($a_param['db'], $con)) {
    echo 'Could not select database';
    exit;
}




$sql = "SELECT idbusqueda, documento
		FROM `cr_busqueda`
		WHERE 	`idcliente` is null 
				and tipobusqueda = 'SENTINEL' ";
echo $sql;
echo "<br><br><br>";	
$result = mysql_query($sql,$con);

$num_rows = mysql_num_rows($result);
    


if($num_rows > 0){
  while ($o_valor = mysql_fetch_object($result)) {
  	
  	  $documento = $o_valor->documento;	
  	  $idbusqueda = $o_valor->idbusqueda;	
  	
  	  $sql = "SELECT idcliente
       		  FROM cr_cliente
       		  WHERE dni = '".$documento."'
       		  ORDER BY idcliente desc
       		  LIMIT 0,1";
      
      //echo $sql;
	  //echo "<br><br><br>";	
      $result_J = mysql_db_query(Conexion::getNameDb(), $sql, $con);
      
      $num_rows_J = mysql_num_rows($result_J);
      echo $num_rows_J;
      if($num_rows_J > 0){
        while ($o_valor_J = mysql_fetch_object($result_J)) {
  	
        	$idcliente 		= $o_valor_J->idcliente;
        	
  						
  			  			
			$sql = "UPDATE 
						cr_busqueda
					SET 
						idcliente= '".$idcliente."'
						
					WHERE
						idbusqueda= '".$idbusqueda."'";
			echo $sql;
			echo "<br><br><br>";
			$result_p = mysql_query($sql,$con);
			
	  	
        }
      }
  	
  }
}





exit;

