public function grabar() { $sql = ""; $count = 0; if (!$this->_existe) { $this->cve_actividad = UtilDB::getSiguienteNumero("actividades", "cve_actividad"); $sql = "INSERT INTO actividades VALUES({$this->cve_actividad}," . $this->cve_tipo->getCve_tipo() . ",'{$this->nombre}','{$this->descripcion}',{$this->activo})"; $count = UtilDB::ejecutaSQL($sql); if ($count > 0) { $this->_existe = true; } } else { $sql = "UPDATE actividades SET "; $sql .= "cve_tipo = " . $this->cve_tipo->getCve_tipo() . ","; $sql .= "nombre = '{$this->nombre}',"; $sql .= "descripcion = '{$this->descripcion}',"; $sql .= "activo=" . ($this->activo ? "1" : "0"); $sql .= " WHERE cve_actividad = {$this->cve_actividad}"; $count = UtilDB::ejecutaSQL($sql); } return $count; }
$ta = new TipoActividad(); $count = 0; $xAccion = ""; $txtCveTipo = 0; $txtCveUnidadNegocio = 0; $txtNombre = ""; $cbxActivo = 0; $msg = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $xAccion = test_input($_POST["xAccion"]); $txtCveTipo = (int) test_input($_POST["txtCveTipo"]); $txtCveUnidadNegocio = (int) test_input($_POST["txtCveUnidadNegocio"]); $txtNombre = test_input($_POST["txtNombre"]); $cbxActivo = isset($_POST["cbxActivo"]) ? 1 : 0; if ($txtCveTipo != 0) { $ta = new TipoActividad($txtCveTipo); } if ($xAccion == 'grabar') { $ta->setCve_unidad_negocio(new UnidadNegocio($txtCveUnidadNegocio)); $ta->setNombre($txtNombre); $ta->setActivo($cbxActivo); $count = $ta->grabar(); if ($count > 0) { $msg = "Los datos han sido guardados."; } else { $msg = "Ha ocurrido un imprevisto al guardar los datos"; } } elseif ($xAccion == 'eliminar') { $count = $ta->borrar(); if ($count > 0) { $msg = "El registro ha sido borrado con éxito";