Exemplo n.º 1
0
<?php

require_once __DIR__ . '/../../Clases/ControladorSucursal.php';
//Creación de un arreglo con los datos obtenidos
$sucursal = array();
$sucursal["Calle"] = $_REQUEST['calle'];
$sucursal["NoEdificio"] = $_REQUEST['edificio'];
$sucursal["Colonia"] = $_REQUEST['colonia'];
$posCiudad = $_REQUEST['ciudad'];
$ciudad = ControladorSucursal::obtenerCiudades()[$posCiudad];
$sucursal["Ciudad"] = $ciudad->getAbreviatura();
//Creación de un objeto del tipo sucursal
$obj = ControladorSucursal::array_Sucursal($sucursal);
if ($_REQUEST["tipoAccion"] == 'Agregar') {
    $posible = ControladorSucursal::insertarSucursal($obj);
    if ($posible) {
        echo 'OK';
    } else {
        echo 'KO';
    }
} else {
    if ($_REQUEST["tipoAccion"] == 'Modificar') {
        $id = $_REQUEST["id_modificacion"];
        ControladorSucursal::actualizarSucursal($id, $obj);
        echo 'OK';
    }
}
$ciudadString = $ciudadString . '<select id="aCiudad">';
foreach ($ciudades as $key => $value) {
    $ciudadString = $ciudadString . "<option id=calidad{$key}>" . $value->getNombre() . "</option>";
}
$ciudadString = $ciudadString . "</select>";
$plantilla = str_replace('|ciudades|', $ciudadString, $plantilla);
echo $plantilla;
$url = ControladorBaseDatos::getRestoURL();
if ($url != '') {
    $url = substr($url, 4);
    if (is_numeric($url)) {
        $id = intval($url);
        $Sucursal = ControladorSucursal::obtenerSucursalID($id);
        if ($Sucursal != NULL) {
            $calle = $Sucursal->getCalle();
            $colonia = $Sucursal->getColonia();
            $edificio = $Sucursal->getNoEdificio();
            //Establece datos de objetos dentro de objetos
            echo "<script>\n\t\t\t\t\t    document.getElementById('aCalle').value = '{$calle}';\n\t\t\t\t\t    document.getElementById('aNoEdificio').value = '{$edificio}';\n\t\t\t\t\t    document.getElementById('aColonia').value = '{$colonia}';";
            $ciudades = ControladorSucursal::obtenerCiudades();
            $selector = 0;
            foreach ($ciudades as $key => $value) {
                if ($value->getAbreviatura() == $Sucursal->getCiudad()->getAbreviatura()) {
                    $selector = $key;
                    break;
                }
            }
            echo "document.getElementById('aCiudad').options.selectedIndex = {$selector}; //es un select\n\t\t\t \t\t </script>";
        }
    }
}