function run()
{
    //Agregar codigo aqui
    $categorias = array();
    if (isset($_POST["btnIngresar"])) {
        $ctgdsc = $_POST["txtCtgDsc"];
        $ctgest = $_POST["cmbCtgEst"];
        ingresarCategoria($ctgdsc, $ctgest);
    } elseif (isset($_POST["btnActualizar"])) {
        $ctgdsc = $_POST["txtCtgDsc"];
        $ctgest = $_POST["cmbCtgEst"];
        $ctgcod = $_GET["cod"];
        actualizarCategoria($ctgcod, $ctgdsc, $ctgest);
    } elseif (isset($_POST["btnEliminar"])) {
        $ctgcod = $_GET["cod"];
        eliminarCategoria($ctgcod);
    }
    if (isset($_GET["modo"])) {
        $modo = $_GET["modo"];
        switch ($modo) {
            case 'ACT':
                $categoria = obtenerCategoria($_GET["cod"]);
                $datos = array("actualizar" => 'ACT', "ctgcod" => $categoria["ctgcod"], "ctgdsc" => $categoria["ctgdsc"], "ctgest" => $categoria["ctgest"] == "INA" ? "ACT" : NULL);
                break;
            case 'INS':
                $datos = array("ingresar" => 'INS');
                break;
            case 'ELI':
                $categoria = obtenerCategoria($_GET["cod"]);
                $datos = array("eliminar" => 'ELI', "ctgcod" => $categoria["ctgcod"], "ctgdsc" => $categoria["ctgdsc"], "ctgest" => $categoria["ctgest"] == "INA" ? "ACT" : NULL);
                break;
        }
        renderizar("formularioCategorias", $datos);
    } else {
        $categorias = obtenerCategorias();
        renderizar("categorias", array("categorias" => $categorias));
    }
    //areglo de arreglos
    //debe existir un archivo en vistas
}
Ejemplo n.º 2
0
function run()
{
    /*Agregar código aquí*/
    $categorias = array();
    $categorias = obtenerCategorias();
    /*$categorias[] = array(
          "catcod" => 1,
          "catdsc" => "Categoria",
          "catest" => "ACT"
      );
      $categorias[] = array(
          "catcod" => 2,
          "catdsc" => "Categoria 2",
          "catest" => "ACT"
      );
      $categorias[] = array(
          "catcod" => 3,
          "catdsc" => "Categoria 3",
          "catest" => "INA"
      );*/
    /*====================*/
    renderizar("categorias", array("categorias" => $categorias));
}
function run()
{
    $categorias = array();
    $categorias = obtenerCategorias();
    renderizar("categorias", array("categorias" => $categorias));
}
<?php

/*****************************/
/***DESARROLLO HIDROCALIDO****/
/*****************************/
require 'connector.php';
// TOMAMOS NUESTRO JSON RECIBIDO DESDE LA PETICION DE ANGULAR JS Y LO LEEMOS
$JSON = file_get_contents("php://input");
$request = json_decode($JSON);
$metodo = $request->metodo;
if ($metodo == 'obtenerCategorias') {
    obtenerCategorias();
} else {
    if ($metodo == 'obtenerPistos') {
        $idCategoria = $request->idCategoria;
        obtenerPistos($idCategoria);
    }
}
function obtenerPistos($idCategoria)
{
    $sql = "SELECT * FROM categorias AS CA INNER JOIN pistos AS PI ON CA.idCategoria = PI.idCategoria WHERE PI.idCategoria = '{$idCategoria}' ";
    try {
        $db = getConnection();
        $stmt = $db->query($sql);
        $detalle = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo '{"pistos": ' . json_encode($detalle) . '}';
    } catch (PDOException $e) {
        echo '{"error":{"text":' . $e->getMessage() . '}}';
    }
}