38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'includes/header.php'; // Para la sesión y seguridad
|
|
|
|
// Verificar permisos
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: /auth/login.php');
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id = $_POST['id'] ?? null;
|
|
$fecha = $_POST['fecha'] ?? null;
|
|
$descripcion = trim($_POST['descripcion'] ?? '');
|
|
$monto = $_POST['monto'] ?? null;
|
|
$tipo = $_POST['tipo'] ?? null;
|
|
|
|
if (!$id || !$fecha || empty($descripcion) || !is_numeric($monto) || empty($tipo)) {
|
|
header('Location: inversiones_operativas.php?error=invalid_data');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("UPDATE inversiones SET fecha = ?, descripcion = ?, monto = ?, tipo = ? WHERE id = ?");
|
|
$stmt->execute([$fecha, $descripcion, $monto, $tipo, $id]);
|
|
|
|
header('Location: inversiones_operativas.php?success=updated#section-' . $tipo);
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
header('Location: inversiones_operativas.php?error=db_error');
|
|
exit;
|
|
}
|
|
} else {
|
|
header('Location: inversiones_operativas.php');
|
|
exit;
|
|
}
|
|
?>
|