예제 #1
0
$xAccion = "";
$txtCveUnidadNegocio = 0;
$txtNombre = "";
$cbxActivo = 0;
$msg = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $xAccion = test_input($_POST["xAccion"]);
    $txtCveUnidadNegocio = (int) test_input($_POST["txtCveUnidadNegocio"]);
    $txtNombre = test_input($_POST["txtNombre"]);
    $cbxActivo = isset($_POST["cbxActivo"]) ? 1 : 0;
    if ($txtCveUnidadNegocio != 0) {
        $un = new UnidadNegocio($txtCveUnidadNegocio);
    }
    if ($xAccion == 'grabar') {
        $un->setNombre($txtNombre);
        $un->setActivo($cbxActivo);
        $count = $un->grabar();
        if ($count > 0) {
            $msg = "Los datos han sido guardados.";
        } else {
            $msg = "Ha ocurrido un imprevisto al guardar los datos";
        }
    } elseif ($xAccion == 'eliminar') {
        $count = $un->borrar();
        if ($count > 0) {
            $msg = "El registro ha sido borrado con éxito";
            $un = NULL;
        } else {
            $msg = "Ha ocurrido un imprevisto al borrar el registro";
            $un = NULL;
        }