<?
/*
Autor: Lic. Carlos Alberto Vaca Coronado
Version: 3.3.0
Cambio: Se agregan las ligas request y response cuando el evento sea verificacion SAT
*/

session_name('portal_absa');session_start();if(!isset($_SESSION['usuario_p_prov_absa']) || trim($_SESSION['usuario_p_prov_absa']) == "" || trim(strtoupper($_SESSION["URL_PORTAL"]."admin.php")) != trim(strtoupper($_SERVER['HTTP_REFERER']))){?><script>window.location.href="<?=$_SESSION["URL_PORTAL"]."index.php"?>"</script><?exit;}

require "../conexion/conectar.php";

$conexion = new CONDB();
$conexion->conectar();

$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
$id = $_GET['id'];
if(!$sidx) $sidx =1;
$queryC = str_replace("\\","",$_SESSION['queryC']);
$completaQuery =" and numeroevento='$id'";
$SQL_1="select COUNT(*) as count from (".$queryC.$completaQuery.") as temp";

/*$responce->rows[0]['cell']=array($SQL_1);
echo json_encode($responce);
exit;*/


//$SQL_1="select COUNT(*) as count from (select rfcemisor,tipodocto,serie,folio from doce) as temp";

$result = mysqli_query($conexion->CONEXION,$SQL_1) or die(mysqli_num_rows($conexion->CONEXION));

$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = $row['count'];

if( $count >0 ) {
	$total_pages = ceil($count/$limit);
} else {
	$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;

$SQL = $queryC.$completaQuery." order by $sidx $sord LIMIT $start , $limit";

//$responce->rows[0]['cell']=array($SQL);

//$SQL = "select rfcemisor,tipodocto,serie,folio from doce order by $sidx $sord LIMIT $start , $limit";

$result = mysqli_query($conexion->CONEXION, $SQL ) or die(mysqli_num_rows($conexion->CONEXION));

$responce=new stdClass();
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;

//$responce->rows[0]['cell']=array($SQL);

while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){

$mystring = $row['comentario'];
$findme   = '<<SAT>>';

$pos = strpos($mystring, $findme);

	if ($pos !== false) {
		
		$row['comentario']=str_replace("<<SAT>>","",$row['comentario']);
		
		$row['comentario'].='<br/><br/><a style="color: #0D7DFC; text-decoration: underline; cursor: pointer" onClick="loadDiv(\'extras/requestSAT.php\',\'cuerpoPopup\',\''.$_GET['rfcEmisor'].'\',\''.$_GET['serie'].'\',\''.$_GET['folio'].'\',\''.$_GET['uuid'].'\',\''.$_GET['doc'].'\',\''.$_GET['id'].'\'); open_w();">Ver Request</a>';

		$row['comentario'].='&nbsp;&nbsp;&nbsp;<a style="color: #0D7DFC; text-decoration: underline; cursor: pointer" onClick="loadDiv(\'extras/responseSAT.php\',\'cuerpoPopup\',\''.$_GET['rfcEmisor'].'\',\''.$_GET['serie'].'\',\''.$_GET['folio'].'\',\''.$_GET['uuid'].'\',\''.$_GET['doc'].'\',\''.$_GET['id'].'\'); open_w();">Ver Response</a>';
		
	}
    //$responce->rows[$i]['id']=$row[$_GET['key']];
	$responce->rows[$i]['cell']=array("<div style='overflow: auto; height: 100; width: 250;'>".$row['comentario']."</div>");
	$i++;
}
echo json_encode($responce);

?>
