<?php
include '../comunes_php/cors.php';
include '../rdb/conn.php';
    $myfile = fopen("logFileGet.txt", "a") or die("Unable to open file!");
    $parametros = print_r($_REQUEST,TRUE);
    fwrite($myfile, "\n");
    fwrite($myfile, "---------------------------". date("Y-m-d H:i:s") ."--------------------------------------------------------");
    fwrite($myfile, "\n");    
    fwrite($myfile, "----------------------------nuevo registro log-------------------------------------------------------");
    fwrite($myfile, "\n");    
    fwrite($myfile, "-----------------------------------------------------------------------------------------------------");
    
    fwrite($myfile, "\n");
    
    fwrite($myfile, $parametros);
    fclose($myfile);

    


    
   
    $id= isset($_REQUEST['id']) ? $_REQUEST['id'] : '';


    
    $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $offset = ($page-1)*$rows;
    $result = array();


$sql = "select "
    . "count(*) "
    . "from"
    . " reclamos_contrato where 1 ";
$sql.= $where ;
    
 
    
    $rs = mysqli_query( $conn,$sql);
    $row = mysqli_fetch_row($rs);
    $result["total"] = $row[0];
    if ($result["total"] === 0) {exit;}  
    
$sql = "SELECT r.id".
" ,contrato_id ".
" ,tr.nombre as tipo_reclamo".
" ,inicio_fecha".
" ,u1.nombre as inicio_responsable".
" ,inicio_observaciones".
" ,fin_fecha".
" ,u2.nombre as fin_responsable".
" ,fin_observaciones FROM ".
" reclamos_contrato r ".
" left join usuarios u1 on r.inicio_responsable_id=u1.id  ".
" left join usuarios u2 on r.fin_responsable_id=u2.id  ".
" left join tipo_reclamos tr on r.tipo_reclamo_id=tr.id ".
" where r.contrato_id =$id".
 " order by id desc"; //limit $offset,$rows ";	
	$rs = mysqli_query( $conn,$sql);
 		    $myfile = fopen("logFileGet.txt", "a") or die("Unable to open file!");

      		    fwrite($myfile, date("Y-m-d H:i:s")."*****************MODIFICACION*****************");
		        fwrite($myfile, "\n");      		    
        	    fwrite($myfile, $sql);
        	    fwrite($myfile, "\n");
        	    fclose($myfile);	    
    $items = array();
    while($row = mysqli_fetch_object($rs)){
        array_push($items, $row);
    }
    $result["rows"] = $items;
    $result["sql"] = $sql;


    echo json_encode($result);
    
  
    
?>