<?php

header('Content-type: application/json; charset=UTF-8');

include 'conexion.php';
$start = $_GET['start'];
$all = $_GET['all'];
$search = $_GET['search'];

if(empty($search)){
    $search = "WHERE 1+1";
}else{
    $search = "WHERE papelera.id_activo like '%".$search."%' or papelera.descripcion like '%".$search."%'";
}

$consulta = "SELECT
                `id_activo` AS NUM_INV_,
                `categoria` AS CATEGORY_,
                `descripcion` AS DESCRIPTION_,
                `estado` AS STATE_,
                `fecha_compra` AS DATE_,
                `valor` AS PRICE_,
                `func_respon` AS RESPONSIBLE_,
                `ubicacion` AS LOCATION_,
                `sede` AS CAMPUS_,
                `compra` AS PURCHASE_,
                 (
            SELECT
                COUNT(id_activo)
            FROM
                papelera $search
                ) AS SIZE_
            FROM
                papelera $search    
            LIMIT $start, $all";
                  
$result = $conexion->query($consulta);
                    
if(!$result){
    echo "Hay un error en la consulta";
}

while($fila = $result -> fetch_array()){
    $response[] = $fila;
}

echo json_encode($response, JSON_UNESCAPED_UNICODE);

$result -> close();

?>