<?php
include_once (ROOT . FOLDER_CORE .'/auth.php'); 
if ($auth == 1) {
    define('ALIAS_EXPEDIENTE', 'VENTA_%');
    $base = consultaTiposExpedientes($bd_conn, ALIAS_EXPEDIENTE);
    $data = array();
    $array_count = 0;
    while ($row = $base->fetch_object()){
        //CARGO EL ARRAY DE CONEXIONES
        $data[$array_count] = array ( 
            "codigo_expediente" => $row->CODIGO,
            "nombre_expediente" => mb_strtoupper($row->DESCRIPCION, 'UTF-8')
        );
        $array_count ++;
    }
    mysqli_close($bd_conn);
    header("Content-type: application/json; charset=utf-8");
    //DEVUELVO EL JSON
    echo json_encode($data);
}elseif ($auth == 0) {
    $data = array();
    $data[] = array ( 
        "status" => "unauthorized_client",
        "message" => "Invalid authorization token"
    );
    header("Content-type: application/json; charset=utf-8");
    echo json_encode($data);
}
//FUNCIONES=============================================
function consultaTiposExpedientes($bd, $alias_exp)
{
    $sql =  "   SELECT T.CODIGO, T.DESCRIPCION
                FROM EXPEDIENTES_TIPOS T
                WHERE T.ALIAS LIKE ?";
    $base = $bd->prepare($sql);
    $alias_exp = mysqli_real_escape_string($bd, $alias_exp);
    $base->bind_param('s', $alias_exp);
    $base->execute();
    $result = $base->get_result();
    $base->close();
    return $result;
}  
?>