38458-vm/api/delete_officer.php
2026-02-15 20:43:30 +00:00

27 lines
913 B
PHP

<?php
require_once '../auth_helper.php';
require_login();
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['id']) && isset($_GET['election_id'])) {
$userId = $_GET['id'];
$electionId = $_GET['election_id'];
$pdo = db();
try {
// Remove the assignment for this election
$stmt = $pdo->prepare("DELETE FROM election_assignments WHERE user_id = ? AND election_id = ? AND role_in_election != 'Voter'");
$stmt->execute([$userId, $electionId]);
$currentUser = get_user();
audit_log('officer_removed', 'users', $userId, null, null, "Removed officer ID $userId from election $electionId");
header("Location: ../officers_management.php?success=officer_deleted");
exit;
} catch (PDOException $e) {
die("Error deleting officer: " . $e->getMessage());
}
} else {
header("Location: ../officers_management.php");
exit;
}