예제 #1
0
require_once __DIR__ . '/../../Clases/ControladorCliente.php';
//Creación de un arreglo con los datos obtenidos
$cliente = array();
$cliente["Nombre"] = $_REQUEST['nombre'];
$cliente["RFC"] = $_REQUEST['rfc'];
$cliente["Calle"] = $_REQUEST['calle'];
$cliente["NoEdificio"] = $_REQUEST['edificio'];
$_REQUEST['sexo'] == 0 ? $cliente["Sexo"] = "F" : ($cliente["Sexo"] = "M");
if ($_REQUEST['regimen'] == 0) {
    $cliente["Regimen"] = "Fisica";
} else {
    $cliente["Regimen"] = "Moral";
    $cliente["Sexo"] = "";
}
$posCiudad = $_REQUEST['ciudad'];
$ciudad = ControladorCliente::obtenerCiudades()[$posCiudad];
$cliente["Ciudad"] = $ciudad->getAbreviatura();
//Creación de un objeto del tipo cliente
$obj = ControladorCliente::array_Cliente($cliente);
if ($_REQUEST["tipoAccion"] == 'Agregar') {
    $posible = ControladorCliente::insertarCliente($obj);
    if ($posible) {
        echo 'OK';
    } else {
        echo 'KO';
    }
} else {
    if ($_REQUEST["tipoAccion"] == 'Modificar') {
        $id = $_REQUEST["id_modificacion"];
        ControladorCliente::actualizarCliente($id, $obj);
        echo 'OK';
    $url = substr($url, 4);
    if (is_numeric($url)) {
        $id = intval($url);
        $Cliente = ControladorCliente::obtenerClienteID($id);
        if ($Cliente != NULL) {
            $calle = $Cliente->getCalle();
            $edificio = $Cliente->getNoEdificio();
            $rfc = $Cliente->getRFC();
            $nombre = $Cliente->getNombre();
            //Establece datos de objetos dentro de objetos
            echo "<script>\n                        document.getElementById('aRFC').value = '{$rfc}';\n                        document.getElementById('aNombre').value = '{$nombre}';\n                        document.getElementById('aCalle').value = '{$calle}';\n                        document.getElementById('aNoEdificio').value = '{$edificio}';";
            if ($Cliente->getRegimen() == 'Moral') {
                echo "document.getElementById('aRegimen').options.selectedIndex = 1;";
            } else {
                echo "document.getElementById('aRegimen').options.selectedIndex = 0;";
                if ($Cliente->getSexo() == 'M') {
                    echo "document.getElementById('aSexo').options.selectedIndex = 1;";
                }
            }
            $ciudades = ControladorCliente::obtenerCiudades();
            $selector = 0;
            foreach ($ciudades as $key => $value) {
                if ($value->getAbreviatura() == $Cliente->getCiudad()->getAbreviatura()) {
                    $selector = $key;
                    break;
                }
            }
            echo "document.getElementById('aCiudad').options.selectedIndex = {$selector};\n                      inicializarClientes();\n                </script>";
        }
    }
}