34394-vm/delete-credential.php
Flatlogic Bot 3d274404c6 0004
2025-09-25 21:18:43 +00:00

43 lines
1.2 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/audit.php';
// If user is not logged in, redirect to login page
if (!isset($_SESSION['user_id'])) {
header('Location: index.php');
exit;
}
// Check if credential_id is provided
if (!isset($_GET['credential_id'])) {
header('Location: dashboard.php');
exit;
}
$pdo = db();
$credential_id = $_GET['credential_id'];
// Fetch the client_id for redirecting back
$stmt = $pdo->prepare("SELECT client_id FROM credentials WHERE credential_id = ?");
$stmt->execute([$credential_id]);
$credential = $stmt->fetch(PDO::FETCH_ASSOC);
if ($credential) {
$client_id = $credential['client_id'];
log_audit_event('credential_delete', $_SESSION['user_id'], 'credential', $credential_id);
// Delete the credential
$deleteStmt = $pdo->prepare("DELETE FROM credentials WHERE credential_id = ?");
$deleteStmt->execute([$credential_id]);
// Redirect back to the client detail page with a success message
header("Location: dashboard.php?client_id=$client_id&status=credential_deleted");
exit;
} else {
// Credential not found, just redirect
header('Location: dashboard.php');
exit;
}