<?php
// app/api/additional/economicacts

    header("Content-Type:application/json");
    include("../dbconn.php");
    include("../utils.php");
    
    // parametros obligatorios
    $parmsob = array("sessionid");
    if (!parametrosValidos($_GET, $parmsob)){
        badEnd("400", array("msg"=>"Parametros obligatorios " . implode(",", $parmsob)));
    }
    
    //Definicion de variables y almacenamiento de valores enviados por GET
    $out = new stdClass;
    $sessionid = $_GET["sessionid"];
    
    //Validamos la session
    isSessionValid($db, $sessionid);
    
    //Consultamos el total de registros
    $sql = "SELECT count(id) AS qty ".
    "       FROM economicactivities";
    if (!$rs=$db->query($sql))
        badEnd("500", array("msg"=>$db->error));
        
    $row = $rs->fetch_assoc();
    //Guardamos el total de registros
    $out->numofrecords = (int)$row["qty"];
    
    //Consultamos todos los registros
    $sql = "SELECT * FROM economicactivities ".
    "       ORDER BY dsc ASC";
    if (!$rs=$db->query($sql))
        badEnd("500", array("msg"=>$db->error));
    
    //Ordenamos los valores
    while($row = $rs->fetch_assoc()){
        $record = new stdClass();
        $record->id = (int)$row["id"];
        $record->dsc = $row["dsc"];
        
        $records [] = $record;
    }
    
    //Retornamos todos los registros
    $out->records = $records;
    
    header("HTTP/1.1 200");
    echo (json_encode($out));
    die();
?>