Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/membership/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/membership/bulk_delete.php

<?php
require_once '../../config/config.php';
checkLogin();

$db = Database::getInstance()->getConnection();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: index.php');
    exit;
}

$memberIds = isset($_POST['member_ids']) && is_array($_POST['member_ids']) ? array_filter($_POST['member_ids'], 'is_numeric') : [];

if (empty($memberIds)) {
    header('Location: index.php');
    exit;
}

try {
    $db->beginTransaction();

    // Build IN clause placeholders
    $placeholders = implode(',', array_fill(0, count($memberIds), '?'));

    // Delete related member accounts
    $stmt = $db->prepare("DELETE FROM member_accounts WHERE member_id IN ($placeholders)");
    $stmt->execute($memberIds);

    // Delete related membership cards
    try {
        $stmt = $db->prepare("DELETE FROM membership_cards WHERE member_id IN ($placeholders)");
        $stmt->execute($memberIds);
    } catch (PDOException $e) {
        // Table may not exist or not have member_id; ignore
    }

    // Delete related memberuser codes
    try {
        $stmt = $db->prepare("DELETE FROM memberuser_codes WHERE member_id IN ($placeholders)");
        $stmt->execute($memberIds);
    } catch (PDOException $e) {
        // Table may not exist; ignore
    }

    // Finally delete members
    $stmt = $db->prepare("DELETE FROM members WHERE id IN ($placeholders)");
    $stmt->execute($memberIds);

    $db->commit();
} catch (Exception $e) {
    if ($db->inTransaction()) {
        $db->rollBack();
    }
}

header('Location: index.php');
exit;

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists