<?php

//Modelo
require "usuarioModel.php";
//--Declaraciones:
$mensaje = array();
//--
$data = json_decode(file_get_contents("php://input"));
$post = helper_userdata($data);
//-- Recibe el parametro accion por post, segun la acción desarrollará una operación....
if ($post) {
    switch ($post["accion"]) {
        case 'guardar':
            $recordset = insertar_usuario($post);
            if ($recordset == "error") {
                $mensaje["mensaje"] = "Error #01: No se realizó la operación";
            } else {
                if ($recordset[0][0] == '-1') {
                    $mensaje["mensaje"] = "Error #02: YA existe un usuario con esa cédula";
                } else {
                    $mensaje["mensaje"] = "Registro Exitoso";
                    $mensaje["id"] = $recordset[0][0];
                }
            }
            //$mensaje[0] = $recordset[0][0];
            die(json_encode($mensaje));
            break;
        case 'consultar':
            $recordset = consultar_usuario($post);
            die(json_encode($recordset));
            break;
//View
require "usuarioView.php";
//Modelo
require "usuarioModel.php";
$mensaje = array();
$mensaje[0] = "Prueba";
//--Recibe el parametro accion por post, segun la acción desarrollará una operación
if (array_key_exists("accion", $_POST)) {
    //--
    $arreglo_datos = helper_userdata();
    //--
    switch ($_POST["accion"]) {
        //--Para insertar
        case "insertar":
            $recordset = insertar_usuario($arreglo_datos);
            if ($recordset != false) {
                $mensaje[0] = "Registro";
            } else {
                $mensaje[0] = "no_registro";
            }
            die(json_encode($mensaje));
            break;
        case "actualizar":
            $recordset = actualizar_usuario($arreglo_datos);
            if ($recordset != false) {
                $mensaje[0] = "Actualizo";
            } else {
                $mensaje[0] = "no_actualizo";
            }
            die(json_encode($mensaje));