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
}
function run()
{
    //htmlDatos, arreglo que contiene todas las substituciones
    // que se darán en la plantilla.
    $htmlDatos = array();
    $htmlDatos["categoryTitle"] = "";
    $htmlDatos["categoryMode"] = "";
    $htmlDatos["ctgid"] = "";
    $htmlDatos["ctgdsc"] = "";
    $htmlDatos["ctgest"] = "";
    $htmlDatos["actSelected"] = "selected";
    $htmlDatos["inaSelected"] = "";
    $htmlDatos["disabled"] = "";
    if (isset($_GET["acc"])) {
        switch ($_GET["acc"]) {
            //Manejando si es un insert
            case "ins":
                $htmlDatos["categoryTitle"] = "Ingreso de Nueva Categoría";
                $htmlDatos["categoryMode"] = "ins";
                //se determina si es una acción del formulario
                if (isset($_POST["btnacc"])) {
                    $lastID = insertarCategoria($_POST);
                    if ($lastID) {
                        redirectWithMessage("¡Categoría Ingresada!", "index.php?page=category&acc=upd&ctgid=" . $lastID);
                    } else {
                        //Se obtiene los datos que estaban en el post
                        $htmlDatos["ctgid"] = $_POST["ctgid"];
                        $htmlDatos["ctgdsc"] = $_POST["ctgdsc"];
                        $htmlDatos["ctgest"] = $_POST["ctgest"];
                        $htmlDatos["actSelected"] = $_POST["ctgest"] == "ACT" ? "selected" : "";
                        $htmlDatos["inaSelected"] = $_POST["ctgest"] == "INA" ? "selected" : "";
                    }
                }
                //si no es una acción del post se muestra los datos
                renderizar("category", $htmlDatos);
                break;
                //Manejando si es un Update
            //Manejando si es un Update
            case "upd":
                if (isset($_POST["btnacc"])) {
                    //implementar logica de guardado
                    if (actualizarCategoria($_POST)) {
                        //forzando a que se actualice con los datos de la db
                        redirectWithMessage("¡Categoría Actualizada!", "index.php?page=category&acc=upd&ctgid=" . $_POST["ctgid"]);
                    }
                }
                if (isset($_GET["ctgid"])) {
                    $categoria = obtenerCategoria($_GET["ctgid"]);
                    if ($categoria) {
                        $htmlDatos["categoryTitle"] = "Actualizar " . $categoria["ctgdsc"];
                        $htmlDatos["categoryMode"] = "upd";
                        $htmlDatos["ctgid"] = $categoria["ctgid"];
                        $htmlDatos["ctgdsc"] = $categoria["ctgdsc"];
                        $htmlDatos["ctgest"] = $categoria["ctgest"];
                        $htmlDatos["actSelected"] = $categoria["ctgest"] == "ACT" ? "selected" : "";
                        $htmlDatos["inaSelected"] = $categoria["ctgest"] == "INA" ? "selected" : "";
                        renderizar("category", $htmlDatos);
                    } else {
                        redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                    }
                } else {
                    redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                }
                break;
                //Manejando un delete
            //Manejando un delete
            case "dlt":
                if (isset($_POST["btnacc"])) {
                    //implementar logica de guardado
                    if (borrarCategoria($_POST["ctgid"])) {
                        //forzando a que se actualice con los datos de la db
                        redirectWithMessage("¡Categoría Borrada!", "index.php?page=categorias");
                    }
                }
                if (isset($_GET["ctgid"])) {
                    $categoria = obtenerCategoria($_GET["ctgid"]);
                    if ($categoria) {
                        $htmlDatos["categoryTitle"] = "¿Desea borrar " . $categoria["ctgdsc"] . "?";
                        $htmlDatos["categoryMode"] = "dlt";
                        $htmlDatos["ctgid"] = $categoria["ctgid"];
                        $htmlDatos["ctgdsc"] = $categoria["ctgdsc"];
                        $htmlDatos["ctgest"] = $categoria["ctgest"];
                        $htmlDatos["actSelected"] = $categoria["ctgest"] == "ACT" ? "selected" : "";
                        $htmlDatos["inaSelected"] = $categoria["ctgest"] == "INA" ? "selected" : "";
                        $htmlDatos["disabled"] = 'disabled="disabled"';
                        renderizar("category", $htmlDatos);
                    } else {
                        redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                    }
                } else {
                    redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                }
                break;
                defualt:
                redirectWithMessage("¡Acción no permitida!", "index.php?page=categorias");
                break;
        }
    }
}
Exemplo n.º 3
0
function run()
{
    $DatosCategoria = array();
    $DatosCategoria["categoryTitle"] = "";
    $DatosCategoria["categoryMode"] = "";
    $DatosCategoria["ctgid"] = "";
    $DatosCategoria["ctgdsc"] = "";
    $DatosCategoria["ctgest"] = "";
    $DatosCategoria["actSelected"] = "selected";
    $DatosCategoria["inaSelected"] = "";
    $DatosCategoria["disabled"] = "";
    if (isset($_GET["acc"])) {
        switch ($_GET["acc"]) {
            case "ins":
                $DatosCategoria["categoryTitle"] = "Ingreso de Nueva Categoría";
                $DatosCategoria["categoryMode"] = "ins";
                if (isset($_POST["btnacc"])) {
                    $lastID = insertarCategoria($_POST);
                    if ($lastID) {
                        redirectWithMessage("¡Categoría Ingresada!", "index.php?page=category&acc=upd&ctgid=" . $lastID);
                    } else {
                        $DatosCategoria["ctgid"] = $_POST["ctgid"];
                        $DatosCategoria["ctgdsc"] = $_POST["ctgdsc"];
                        $DatosCategoria["ctgest"] = $_POST["ctgest"];
                        $DatosCategoria["actSelected"] = $_POST["ctgest"] == "ACT" ? "selected" : "";
                        $DatosCategoria["inaSelected"] = $_POST["ctgest"] == "INA" ? "selected" : "";
                    }
                }
                renderizar("category", $DatosCategoria);
                break;
            case "upd":
                if (isset($_POST["btnacc"])) {
                    if (actualizarCategoria($_POST)) {
                        redirectWithMessage("¡Categoría Actualizada!", "index.php?page=category&acc=upd&ctgid=" . $_POST["ctgid"]);
                    }
                }
                if (isset($_GET["ctgid"])) {
                    $categoria = obtenerCategoria($_GET["ctgid"]);
                    if ($categoria) {
                        $DatosCategoria["categoryTitle"] = "Actualizar " . $categoria["ctgdsc"];
                        $DatosCategoria["categoryMode"] = "upd";
                        $DatosCategoria["ctgid"] = $categoria["ctgid"];
                        $DatosCategoria["ctgdsc"] = $categoria["ctgdsc"];
                        $DatosCategoria["ctgest"] = $categoria["ctgest"];
                        $DatosCategoria["actSelected"] = $categoria["ctgest"] == "ACT" ? "selected" : "";
                        $DatosCategoria["inaSelected"] = $categoria["ctgest"] == "INA" ? "selected" : "";
                        renderizar("category", $DatosCategoria);
                    } else {
                        redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                    }
                } else {
                    redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                }
                break;
            case "dlt":
                if (isset($_POST["btnacc"])) {
                    if (borrarCategoria($_POST["ctgid"])) {
                        redirectWithMessage("¡Categoría Borrada!", "index.php?page=categorias");
                    }
                }
                if (isset($_GET["ctgid"])) {
                    $categoria = obtenerCategoria($_GET["ctgid"]);
                    if ($categoria) {
                        $DatosCategoria["categoryTitle"] = "¿Desea borrar " . $categoria["ctgdsc"] . "?";
                        $DatosCategoria["categoryMode"] = "dlt";
                        $DatosCategoria["ctgid"] = $categoria["ctgid"];
                        $DatosCategoria["ctgdsc"] = $categoria["ctgdsc"];
                        $DatosCategoria["ctgest"] = $categoria["ctgest"];
                        $DatosCategoria["actSelected"] = $categoria["ctgest"] == "ACT" ? "selected" : "";
                        $DatosCategoria["inaSelected"] = $categoria["ctgest"] == "INA" ? "selected" : "";
                        $DatosCategoria["disabled"] = 'disabled="disabled"';
                        renderizar("category", $DatosCategoria);
                    } else {
                        redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                    }
                } else {
                    redirectWithMessage("¡Categoría No Encontrada!", "index.php?page=categorias");
                }
                break;
                defualt:
                redirectWithMessage("¡Acción no permitida!", "index.php?page=categorias");
                break;
        }
    }
}