Sindbad~EG File Manager
<?php
require_once '../../config/config.php';
checkLogin();
$db = Database::getInstance()->getConnection();
// Load districts and assemblies for location updates
$districts = [];
$assemblies = [];
try {
$districtsStmt = $db->query("SELECT id, district_name FROM districts WHERE is_active = 1 ORDER BY district_name");
$districts = $districtsStmt->fetchAll();
} catch (PDOException $e) {
// ignore
}
try {
$assembliesStmt = $db->query("SELECT id, assembly_name, district_id FROM assemblies WHERE is_active = 1 ORDER BY assembly_name");
$assemblies = $assembliesStmt->fetchAll();
} catch (PDOException $e) {
// ignore
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['apply_bulk_edit'])) {
$memberIds = isset($_POST['member_ids']) && is_array($_POST['member_ids']) ? array_filter($_POST['member_ids'], 'is_numeric') : [];
if (!empty($memberIds)) {
$fields = [];
$params = [];
// Text and select fields: apply if not empty
if (isset($_POST['title']) && $_POST['title'] !== '') {
$fields[] = 'title = ?';
$params[] = $_POST['title'];
}
if (isset($_POST['first_name']) && $_POST['first_name'] !== '') {
$fields[] = 'first_name = ?';
$params[] = $_POST['first_name'];
}
if (isset($_POST['middle_name']) && $_POST['middle_name'] !== '') {
$fields[] = 'middle_name = ?';
$params[] = $_POST['middle_name'];
}
if (isset($_POST['last_name']) && $_POST['last_name'] !== '') {
$fields[] = 'last_name = ?';
$params[] = $_POST['last_name'];
}
if (isset($_POST['member_type']) && $_POST['member_type'] !== '') {
$fields[] = 'member_type = ?';
$params[] = $_POST['member_type'];
}
if (isset($_POST['gender']) && $_POST['gender'] !== '') {
$fields[] = 'gender = ?';
$params[] = $_POST['gender'];
}
if (isset($_POST['date_of_birth']) && $_POST['date_of_birth'] !== '') {
$fields[] = 'date_of_birth = ?';
$params[] = $_POST['date_of_birth'];
}
if (isset($_POST['place_of_birth']) && $_POST['place_of_birth'] !== '') {
$fields[] = 'place_of_birth = ?';
$params[] = $_POST['place_of_birth'];
}
if (isset($_POST['marital_status']) && $_POST['marital_status'] !== '') {
$fields[] = 'marital_status = ?';
$params[] = $_POST['marital_status'];
}
if (isset($_POST['phone']) && $_POST['phone'] !== '') {
$fields[] = 'phone = ?';
$params[] = $_POST['phone'];
}
if (isset($_POST['email']) && $_POST['email'] !== '') {
$fields[] = 'email = ?';
$params[] = $_POST['email'];
}
if (isset($_POST['occupation']) && $_POST['occupation'] !== '') {
$fields[] = 'occupation = ?';
$params[] = $_POST['occupation'];
}
if (isset($_POST['level_of_education']) && $_POST['level_of_education'] !== '') {
$fields[] = 'level_of_education = ?';
$params[] = $_POST['level_of_education'];
}
if (isset($_POST['address_line1']) && $_POST['address_line1'] !== '') {
$fields[] = 'address_line1 = ?';
$params[] = $_POST['address_line1'];
}
if (isset($_POST['gps_address']) && $_POST['gps_address'] !== '') {
$fields[] = 'gps_address = ?';
$params[] = $_POST['gps_address'];
}
if (isset($_POST['street_name']) && $_POST['street_name'] !== '') {
$fields[] = 'street_name = ?';
$params[] = $_POST['street_name'];
}
if (isset($_POST['city']) && $_POST['city'] !== '') {
$fields[] = 'city = ?';
$params[] = $_POST['city'];
}
if (isset($_POST['hometown']) && $_POST['hometown'] !== '') {
$fields[] = 'hometown = ?';
$params[] = $_POST['hometown'];
}
// District / Assembly (integer IDs)
if (isset($_POST['district_id']) && $_POST['district_id'] !== '') {
$fields[] = 'district_id = ?';
$params[] = (int)$_POST['district_id'];
}
if (isset($_POST['assembly_id']) && $_POST['assembly_id'] !== '') {
$fields[] = 'assembly_id = ?';
$params[] = (int)$_POST['assembly_id'];
}
// Boolean-like fields with tri-state select (no change / yes / no)
if (isset($_POST['is_active']) && $_POST['is_active'] !== '') {
$fields[] = 'is_active = ?';
$params[] = $_POST['is_active'] === '1' ? 1 : 0;
}
if (isset($_POST['communicant']) && $_POST['communicant'] !== '') {
$fields[] = 'communicant = ?';
$params[] = $_POST['communicant'] === '1' ? 1 : 0;
}
if (isset($_POST['water_baptism']) && $_POST['water_baptism'] !== '') {
$fields[] = 'water_baptism = ?';
$params[] = $_POST['water_baptism'] === '1' ? 1 : 0;
}
if (isset($_POST['date_of_baptism']) && $_POST['date_of_baptism'] !== '') {
$fields[] = 'date_of_baptism = ?';
$params[] = $_POST['date_of_baptism'];
}
if (isset($_POST['holyghost_baptism']) && $_POST['holyghost_baptism'] !== '') {
$fields[] = 'holyghost_baptism = ?';
$params[] = $_POST['holyghost_baptism'] === '1' ? 1 : 0;
}
if (isset($_POST['date_of_holyspirit_baptism']) && $_POST['date_of_holyspirit_baptism'] !== '') {
$fields[] = 'date_of_holyspirit_baptism = ?';
$params[] = $_POST['date_of_holyspirit_baptism'];
}
if (isset($_POST['date_of_conversion']) && $_POST['date_of_conversion'] !== '') {
$fields[] = 'date_of_conversion = ?';
$params[] = $_POST['date_of_conversion'];
}
if (isset($_POST['date_of_joining']) && $_POST['date_of_joining'] !== '') {
$fields[] = 'date_of_joining = ?';
$params[] = $_POST['date_of_joining'];
}
if (isset($_POST['place_of_baptism']) && $_POST['place_of_baptism'] !== '') {
$fields[] = 'place_of_baptism = ?';
$params[] = $_POST['place_of_baptism'];
}
if (isset($_POST['officiating_minister_baptism']) && $_POST['officiating_minister_baptism'] !== '') {
$fields[] = 'officiating_minister_baptism = ?';
$params[] = $_POST['officiating_minister_baptism'];
}
if (isset($_POST['officiating_ministers_district']) && $_POST['officiating_ministers_district'] !== '') {
$fields[] = 'officiating_ministers_district = ?';
$params[] = $_POST['officiating_ministers_district'];
}
if (isset($_POST['dedicated']) && $_POST['dedicated'] !== '') {
$fields[] = 'dedicated = ?';
$params[] = $_POST['dedicated'] === '1' ? 1 : 0;
}
if (isset($_POST['dedication_date']) && $_POST['dedication_date'] !== '') {
$fields[] = 'dedication_date = ?';
$params[] = $_POST['dedication_date'];
}
if (isset($_POST['name_of_officiating_minister']) && $_POST['name_of_officiating_minister'] !== '') {
$fields[] = 'name_of_officiating_minister = ?';
$params[] = $_POST['name_of_officiating_minister'];
}
if (isset($_POST['church_where_dedication_done']) && $_POST['church_where_dedication_done'] !== '') {
$fields[] = 'church_where_dedication_done = ?';
$params[] = $_POST['church_where_dedication_done'];
}
if (isset($_POST['parent_name']) && $_POST['parent_name'] !== '') {
$fields[] = 'parent_name = ?';
$params[] = $_POST['parent_name'];
}
if (isset($_POST['parent_relationship']) && $_POST['parent_relationship'] !== '') {
$fields[] = 'parent_relationship = ?';
$params[] = $_POST['parent_relationship'];
}
if (!empty($fields)) {
$placeholders = implode(',', array_fill(0, count($memberIds), '?'));
$sql = 'UPDATE members SET ' . implode(', ', $fields) . ' WHERE id IN (' . $placeholders . ')';
$stmt = $db->prepare($sql);
$stmt->execute(array_merge($params, $memberIds));
}
}
header('Location: members_edit.php');
exit;
}
// Initial load: coming from index with selected member_ids
$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;
}
// Load selected members for display
$members = [];
try {
$placeholders = implode(',', array_fill(0, count($memberIds), '?'));
$sql = "SELECT id, title, first_name, middle_name, last_name, email, phone FROM members WHERE id IN ($placeholders) ORDER BY first_name, last_name";
$stmt = $db->prepare($sql);
$stmt->execute($memberIds);
$members = $stmt->fetchAll();
} catch (PDOException $e) {
$members = [];
}
$pageTitle = 'Bulk Edit Members - ' . APP_NAME;
include '../../includes/header.php';
include '../../includes/sidebar.php';
?>
<main class="flex-1 md:ml-64 mt-16">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<h1 class="text-2xl font-bold mb-4">Bulk Edit Members</h1>
<p class="text-gray-600 mb-6">Any values you set below will be applied to all selected members.</p>
<?php if (!empty($members)): ?>
<div class="bg-white rounded-lg shadow mb-6 p-4">
<h2 class="text-sm font-semibold text-gray-700 mb-2">Selected Members (<?php echo count($members); ?>)</h2>
<ul class="max-h-40 overflow-auto text-sm text-gray-700 list-disc pl-5">
<?php foreach ($members as $m): ?>
<li>
<?php
$name = trim(($m['title'] ?? '') . ' ' . $m['first_name'] . ' ' . $m['last_name']);
echo htmlspecialchars($name);
?>
<?php if (!empty($m['email'])): ?>
- <?php echo htmlspecialchars($m['email']); ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<form method="POST" class="bg-white rounded-lg shadow p-6 space-y-6">
<?php foreach ($memberIds as $id): ?>
<input type="hidden" name="member_ids[]" value="<?php echo htmlspecialchars($id); ?>">
<?php endforeach; ?>
<!-- Personal Information -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Title</label>
<select name="title" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Dr">Dr</option>
<option value="Rev">Rev</option>
<option value="Pastor">Pastor</option>
<option value="Deacon">Deacon</option>
<option value="Deaconess">Deaconess</option>
<option value="Elder">Elder</option>
<option value="Evangelist">Evangelist</option>
<option value="Prophet">Prophet</option>
<option value="Apostle">Apostle</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Member Type</label>
<select name="member_type" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="Full Member">Full Member</option>
<option value="Associate Member">Associate Member</option>
<option value="Youth">Youth</option>
<option value="Children">Children</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Gender</label>
<select name="gender" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">First Name</label>
<input type="text" name="first_name" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Middle Name</label>
<input type="text" name="middle_name" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Last Name</label>
<input type="text" name="last_name" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Marital Status</label>
<select name="marital_status" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Divorced">Divorced</option>
<option value="Widowed">Widowed</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Status</label>
<select name="is_active" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Communicant</label>
<select name="communicant" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
<!-- Contact & Other -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Phone</label>
<input type="text" name="phone" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" name="email" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Occupation</label>
<input type="text" name="occupation" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Level of Education</label>
<input type="text" name="level_of_education" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
</div>
<!-- Location (District / Assembly) -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">District</label>
<select name="district_id" id="bulkDistrictSelect" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<?php foreach ($districts as $dist): ?>
<option value="<?php echo $dist['id']; ?>"><?php echo htmlspecialchars($dist['district_name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Assembly</label>
<select name="assembly_id" id="bulkAssemblySelect" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<?php foreach ($assemblies as $asm): ?>
<option value="<?php echo $asm['id']; ?>" data-district-id="<?php echo $asm['district_id']; ?>">
<?php echo htmlspecialchars($asm['assembly_name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Address Information -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="md:col-span-2">
<label class="block text-sm font-medium text-gray-700 mb-1">Address Line 1</label>
<textarea name="address_line1" rows="2" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --"></textarea>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">GPS Address</label>
<input type="text" name="gps_address" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Street Name</label>
<input type="text" name="street_name" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">City</label>
<input type="text" name="city" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Hometown</label>
<input type="text" name="hometown" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
</div>
<!-- Spiritual Information -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Date of Birth</label>
<input type="date" name="date_of_birth" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Place of Birth</label>
<input type="text" name="place_of_birth" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Water Baptism</label>
<select name="water_baptism" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Date of Baptism</label>
<input type="date" name="date_of_baptism" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Holy Ghost Baptism</label>
<select name="holyghost_baptism" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Date of Holy Spirit Baptism</label>
<input type="date" name="date_of_holyspirit_baptism" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Date of Conversion</label>
<input type="date" name="date_of_conversion" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Date of Joining</label>
<input type="date" name="date_of_joining" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Place of Baptism</label>
<input type="text" name="place_of_baptism" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Officiating Minister (Baptism)</label>
<input type="text" name="officiating_minister_baptism" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Minister's District/Church</label>
<input type="text" name="officiating_ministers_district" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Dedicated</label>
<select name="dedicated" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
<option value="">-- No change --</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Dedication Date</label>
<input type="date" name="dedication_date" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Officiating Minister (Dedication)</label>
<input type="text" name="name_of_officiating_minister" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Church Where Dedication Done</label>
<input type="text" name="church_where_dedication_done" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
</div>
<!-- Parent / Guardian Info -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Parent / Guardian Name</label>
<input type="text" name="parent_name" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Relationship</label>
<input type="text" name="parent_relationship" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="-- No change --">
</div>
</div>
<div class="flex justify-end space-x-3 mt-6">
<a href="members_edit.php" class="px-4 py-2 rounded-lg bg-gray-500 text-white hover:bg-gray-600">Cancel</a>
<button type="submit" name="apply_bulk_edit" value="1" class="px-4 py-2 rounded-lg bg-blue-600 text-white hover:bg-blue-700">Apply Changes</button>
</div>
</form>
</div>
</main>
<script>
// Filter assemblies by selected district
document.addEventListener('DOMContentLoaded', function() {
var districtSelect = document.getElementById('bulkDistrictSelect');
var assemblySelect = document.getElementById('bulkAssemblySelect');
if (!districtSelect || !assemblySelect) return;
function filterAssemblies() {
var selectedDistrict = districtSelect.value;
var options = assemblySelect.querySelectorAll('option');
options.forEach(function(opt) {
if (!opt.dataset.districtId) {
// Keep the "-- No change --" option always visible
opt.style.display = '';
return;
}
if (selectedDistrict === '' || opt.dataset.districtId === selectedDistrict) {
opt.style.display = '';
} else {
opt.style.display = 'none';
}
});
// Reset assembly selection when district changes
assemblySelect.value = '';
}
districtSelect.addEventListener('change', filterAssemblies);
});
</script>
<?php include '../../includes/footer.php'; ?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists