<?php
session_start();
require_once '../Conexion/conexion.php';
require_once('../Conexion/ConexionPDO.php');
$conexion = $_SESSION['conexion'];
$con = new ConexionPDO();
$valor = $_REQUEST['valor'];

switch ($valor) {
    case 1:
        // $concepto = base64_decode($_REQUEST['concepto']);
        $concepto = $_REQUEST['concepto'];
        if($concepto == 0 || $concepto=='""'){
            echo '<option value="">Rubro Fuente</option>';
        }else{
            $result =$con->Listar("SELECT DISTINCT rb.id_unico,rb.codi_presupuesto,rb.nombre,ft.nombre,rft.id_unico
                    FROM gf_concepto_rubro cr 
                    LEFT JOIN gf_rubro_fuente rft ON cr.rubro = rft.rubro
                    LEFT JOIN gf_rubro_pptal rb ON cr.rubro = rb.id_unico
                    LEFT JOIN  gf_fuente ft ON rft.fuente = ft.id_unico
                    WHERE cr.concepto = $concepto AND rb.id_unico IS NOT NULL");
            // $result = $mysqli->query($sql);
            // while ($row = mysqli_fetch_row($result)){
            for ($row=0; $row < count($result) ; $row++) { 
                echo '<option value="'.$result[$row][4].'">'.utf8_encode(strtolower(ucwords($result[$row][1].' '.$result[$row][2].'-'.$result[$row][3]))).'</option>';
            }
        }
        break;
    case 2:
        $concepto = $_REQUEST['concepto'];
        if($concepto == 0 || $concepto=='""'){
            echo '';
        }else{
            $row = $con->Listar("SELECT DISTINCT cr.id_unico
            FROM gf_concepto_rubro cr 
            LEFT JOIN gf_rubro_fuente rft ON cr.rubro = rft.rubro
            LEFT JOIN gf_rubro_pptal rb ON rft.rubro = rb.id_unico
            LEFT JOIN  gf_fuente ft ON rft.fuente = ft.id_unico
            WHERE concepto = $concepto AND rb.id_unico IS NOT NULL");
            // $result = $mysqli->query($sql);            
            // $row = mysqli_fetch_row($result);
            echo $row[0][0];
        }
        break;
}
?>
