36806-vm/update_activity.php
Flatlogic Bot 5366b4681b CRM-V1
2025-12-11 07:55:09 +00:00

45 lines
1.1 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/db/config.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: index.php');
exit();
}
// Basic validation
$activity_id = $_POST['activity_id'] ?? null;
$activity_type = trim($_POST['activity_type'] ?? '');
$status = trim($_POST['status'] ?? '');
$due_date = $_POST['due_date'] ?? null;
$notes = trim($_POST['notes'] ?? '');
if (empty($activity_id) || empty($activity_type) || empty($status)) {
$_SESSION['error_message'] = 'Required fields are missing.';
header('Location: index.php');
exit();
}
try {
$pdo = db();
$stmt = $pdo->prepare(
'UPDATE activities SET ActivityType = ?, Status = ?, DueDate = ?, Notes = ? WHERE ActivityID = ?'
);
$stmt->execute([
$activity_type,
$status,
$due_date,
$notes,
$activity_id
]);
$_SESSION['success_message'] = 'Activity updated successfully!';
} catch (PDOException $e) {
// In a real app, log this error.
$_SESSION['error_message'] = 'Failed to update activity. Please try again.';
}
header('Location: index.php');
exit();