function run()
{
    if (mw_estaLogueado()) {
        $datosARenderizar = array();
        if (isset($_GET["catecod"])) {
            $datosARenderizar["productos"] = obtenerProductosXCategoria($_GET["catecod"]);
        } else {
            $datosARenderizar["productos"] = obtenerProductos();
        }
        renderizar("productos", $datosARenderizar);
    } else {
        mw_redirectToLogin("page=productos");
    }
}
Ejemplo n.º 2
0
function renderizar($vista, $datos)
{
    if (!is_array($datos)) {
        http_response_code(404);
        die("Error de renderizador: datos no es un arreglo");
    }
    //union de los dos arreglos
    global $global_context;
    $datos = array_merge($global_context, $datos);
    $viewsPath = "views/";
    $fileTemplate = $vista . ".view.tpl";
    $layoutFile = "layout.view.tpl";
    $htmlContent = "";
    if (file_exists($viewsPath . $layoutFile)) {
        $htmlContent = file_get_contents($viewsPath . $layoutFile);
        if (file_exists($viewsPath . $fileTemplate)) {
            $tmphtml = file_get_contents($viewsPath . $fileTemplate);
            $htmlContent = str_replace("{{{page_content}}}", $tmphtml, $htmlContent);
            if (mw_estaLogueado()) {
                $VistaLogin = file_get_contents($viewsPath . "logiado.view.tpl");
                $htmlContent = str_replace("{{{NoestaLogiado}}}", $VistaLogin, $htmlContent);
            } else {
                $VistaLogin = file_get_contents($viewsPath . "login.view.tpl");
                $htmlContent = str_replace("{{{NoestaLogiado}}}", $VistaLogin, $htmlContent);
            }
            //Limpiar Saltos de Pagina
            $htmlContent = str_replace("\n", "", $htmlContent);
            $htmlContent = str_replace("\r", "", $htmlContent);
            $htmlContent = str_replace("\t", "", $htmlContent);
            $htmlContent = str_replace("  ", "", $htmlContent);
            //obtiene un arreglo separando lo distintos tipos de nodos
            $template_code = parseTemplate($htmlContent);
            $htmlResult = renderTemplate($template_code, $datos);
            echo $htmlResult;
        }
    }
}
Ejemplo n.º 3
0
<?php

session_start();
require_once "libs/utilities.php";
$pageRequest = "home";
if (isset($_GET["page"])) {
    $pageRequest = $_GET["page"];
}
//Incorporando los midlewares son codigos que se deben ejecutar
//Siempre
require_once "controllers/verificar.mw.php";
require_once "controllers/site.mw.php";
if (isset($_SESSION["userRol"])) {
    mw_estaLogueado($_SESSION["userRol"]);
} else {
    mw_estaLogueado("");
}
//Este switch se encarga de todo el enrutamiento
switch ($pageRequest) {
    case "home":
        //llamar al controlador
        require_once "controllers/home.control.php";
        break;
    case "about":
        require_once "controllers/about.control.php";
        break;
    case "services":
        require_once "controllers/services.control.php";
        break;
    case "gallery":
        require_once "controllers/gallery.control.php";
function run()
{
    $htmlData = array();
    $htmlData["errores"] = array();
    $htmlData["Cuenta"] = "";
    if (mw_estaLogueado()) {
        if (isset($_SESSION["userName"])) {
            $htmlData["Cuenta"] = $_SESSION["userName"];
        }
        $htmlData["CrtTotal"] = 0;
        $htmlData["carretilla"] = obtenerCarretilla($_SESSION["userCodigo"]);
        $contador = 0;
        if (isset($_POST["btnAgregar"])) {
            $activar = '1';
            if (isset($htmlData["carretilla"][0]["PrtId"])) {
                foreach ($htmlData["carretilla"] as $precios) {
                    if ($precios["PrtId"] == $_POST["Codigo"]) {
                        $activar = '0';
                    }
                }
            }
            if (verificar_Numero($_POST["txtCantidad"])) {
                if ($activar) {
                    $Usuario = $_SESSION["userCodigo"];
                    $Cantidad = $_POST["txtCantidad"];
                    $precio = $_POST["Txtprecio"];
                    $Producto = $_POST["Codigo"];
                    $lstchk = time();
                    $Codigo["CrtEstado"] = "DES";
                    $Codigo = Carretilla($Usuario);
                    if ($Codigo["CrtEstado"] == "DES" or $Codigo["CrtEstado"] == "") {
                        DatosCarretilla($Usuario, $lstchk);
                    }
                    $CarretillaID = DetallesCarretilla($Usuario, $Producto, $Cantidad, $precio);
                } else {
                    $htmlData["errores"][] = array("errmsg" => "El producto ya estaba en la carretilla");
                }
            } else {
                $htmlData["errores"][] = array("errmsg" => "El campo debia ser numerico");
            }
        }
        $htmlData["carretilla"] = obtenerCarretilla($_SESSION["userCodigo"]);
        foreach ($htmlData["carretilla"] as $precios) {
            $htmlData["CrtTotal"] += $precios["CrtDtlCantidad"] * $precios["CrtDtlPrecio"];
            $contador += 1;
        }
        for ($i = 0; $i < $contador; $i++) {
            $htmlData["carretilla"][$i]["total"] = $htmlData["carretilla"][$i]["CrtDtlCantidad"] * $htmlData["carretilla"][$i]["CrtDtlPrecio"];
        }
        if (isset($_POST["btnComprar"])) {
            $Usuario = $_SESSION["userCodigo"];
            $lstchk = time();
            CrearPedido($Usuario, $lstchk, $htmlData);
            mw_redirect();
        }
        //die(print_r($htmlData));
        renderizar("carretilla", $htmlData);
    } else {
        mw_redirect();
    }
}