-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommittees.php
More file actions
315 lines (285 loc) · 17 KB
/
committees.php
File metadata and controls
315 lines (285 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
// committees.php - Manage committees for Destiny Chapel ChMS
session_start();
require_once 'db_connect.php';
if (!isset($_SESSION['admin_id'])) {
header('Location: login.php');
exit;
}
// Add Committee
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_comm'])) {
$name = trim($_POST['name']);
$description = trim($_POST['description']);
if (!empty($name)) {
$stmt = $pdo->prepare("INSERT INTO committees (name, description) VALUES (?, ?)");
$stmt->execute([$name, $description]);
header('Location: committees.php');
exit;
}
}
// Fetch Committees with Member Count
$stmt = $pdo->query("
SELECT c.*, COUNT(mc.member_id) as member_count
FROM committees c
LEFT JOIN member_committees mc ON c.id = mc.committee_id
GROUP BY c.id
ORDER BY c.name ASC
");
$committees = $stmt->fetchAll();
// Update Member Role in Committee
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['update_role'])) {
$member_id = $_POST['member_id'];
$comm_id = $_POST['comm_id'];
$new_role = $_POST['role'];
$stmt = $pdo->prepare("UPDATE member_committees SET role = ? WHERE member_id = ? AND committee_id = ?");
$stmt->execute([$new_role, $member_id, $comm_id]);
header('Location: committees.php?view='.$comm_id);
exit;
}
// Edit Committee
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit_comm'])) {
$id = $_POST['id'];
$name = trim($_POST['name']);
$description = trim($_POST['description']);
if (!empty($id) && !empty($name)) {
$stmt = $pdo->prepare("UPDATE committees SET name = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $description, $id]);
header('Location: committees.php');
exit;
}
}
// Fetch all members with their committee assignments and roles for the view modal
$comm_members = $pdo->query("
SELECT m.id as member_id, m.full_name, m.email, m.phone, mc.committee_id, mc.role, m.photo_url
FROM members m
INNER JOIN member_committees mc ON m.id = mc.member_id
ORDER BY m.full_name ASC
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Committees | Destiny Chapel ChMS</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>body { font-family: 'Inter', sans-serif; }</style>
</head>
<body class="bg-gray-50 text-slate-900 font-sans flex h-screen overflow-hidden">
<!-- Sidebar -->
<aside class="bg-slate-900 text-white w-64 flex flex-col shrink-0">
<div class="p-6 flex items-center gap-3 border-b border-slate-800">
<div class="w-8 h-8 bg-indigo-600 rounded-lg flex items-center justify-center font-bold text-xl">D</div>
<span class="font-bold text-lg tracking-tight">Destiny Chapel</span>
</div>
<nav class="flex-1 p-4 space-y-2">
<a href="dashboard.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-slate-400 hover:bg-slate-800 hover:text-white font-medium">Dashboard</a>
<a href="members.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-slate-400 hover:bg-slate-800 hover:text-white font-medium">Members</a>
<a href="finance.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-slate-400 hover:bg-slate-800 hover:text-white font-medium">Finance</a>
<a href="events.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-slate-400 hover:bg-slate-800 hover:text-white font-medium">Events</a>
<a href="departments.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-slate-400 hover:bg-slate-800 hover:text-white font-medium">Departments</a>
<a href="committees.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg bg-indigo-600 text-white font-medium">Committees</a>
<div class="pt-4 mt-4 border-t border-slate-800">
<a href="profile.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-slate-400 hover:bg-slate-800 hover:text-white font-medium">My Profile</a>
<?php if (isset($_SESSION['admin_role']) && $_SESSION['admin_role'] == 'Super Admin'): ?>
<a href="admins.php" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-slate-400 hover:bg-slate-800 hover:text-white font-medium">Administrators</a>
</div>
<?php endif; ?>
</nav>
<a href="logout.php" class="p-4 hover:bg-slate-800 border-t border-slate-800 text-center text-sm text-slate-400">Logout</a>
</aside>
<!-- Main Content -->
<main class="flex-1 flex flex-col overflow-hidden">
<header class="bg-white border-b border-gray-200 h-16 flex items-center justify-between px-8 shrink-0">
<h1 class="text-xl font-semibold">Church Committees</h1>
<div className="flex items-center gap-4">
<span class="text-sm font-medium text-slate-600"><?php echo $_SESSION['admin_name']; ?></span>
</div>
</header>
<div class="flex-1 overflow-y-auto p-8 space-y-8">
<!-- Add Committee Form -->
<div class="bg-white p-6 rounded-2xl border border-gray-200 shadow-sm">
<h3 class="font-bold text-lg mb-4 text-slate-800">Add New Committee</h3>
<form method="POST" class="grid grid-cols-1 md:grid-cols-2 gap-4">
<input type="text" name="name" placeholder="Committee Name" required class="px-4 py-2 rounded-lg border border-gray-200 outline-none focus:ring-2 focus:ring-indigo-500">
<input type="text" name="description" placeholder="Description" class="px-4 py-2 rounded-lg border border-gray-200 outline-none focus:ring-2 focus:ring-indigo-500">
<div class="md:col-span-2 flex justify-end">
<button type="submit" name="add_comm" class="px-6 py-2 bg-indigo-600 text-white rounded-lg font-bold hover:bg-indigo-700">Save Committee</button>
</div>
</form>
</div>
<!-- Committees Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<?php foreach ($committees as $comm): ?>
<div class="bg-white p-6 rounded-2xl border border-gray-200 shadow-sm hover:border-indigo-300 transition-all group">
<h3 class="text-lg font-bold mb-2 group-hover:text-indigo-600 transition-colors"><?php echo $comm['name']; ?></h3>
<p class="text-sm text-slate-500 mb-4 line-clamp-2"><?php echo $comm['description']; ?></p>
<div class="flex items-center justify-between pt-4 border-t border-gray-100">
<button
onclick='viewMembers(<?php echo $comm["id"]; ?>, "<?php echo addslashes($comm["name"]); ?>")'
class="text-xs font-bold text-indigo-600 hover:indigo-800 flex items-center gap-1"
>
View Members (<?php echo $comm['member_count']; ?>)
</button>
<button
onclick='openEditModal(<?php echo json_encode($comm); ?>)'
class="text-xs font-bold text-slate-400 hover:text-slate-900"
>
Edit Details
</button>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<!-- Static Horizontal Footer -->
<footer class="bg-white border-t border-gray-200 py-4 px-8 shrink-0 flex flex-col md:flex-row justify-between items-center text-slate-500 text-sm">
<p>© <?php echo date('Y'); ?> AWC-Destiny Chapel. All rights reserved.</p>
<p class="mt-2 md:mt-0">Made with <span class="text-red-500">❤</span> by <a href="https://kojoshaddy.pages.dev" target="_blank" class="text-indigo-600 hover:text-indigo-800 transition-colors duration-300 font-medium">Shadrack Inusah</a></p>
</footer>
</main>
<!-- Edit Committee Modal -->
<div id="editModal" class="hidden fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl w-full max-w-lg overflow-hidden">
<div class="p-6 border-b border-gray-100 flex items-center justify-between">
<h3 class="font-bold text-xl text-slate-800">Edit Committee</h3>
<button onclick="closeEditModal()" class="text-slate-400 hover:text-slate-600">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
</button>
</div>
<form method="POST" class="p-6 space-y-4">
<input type="hidden" name="id" id="edit_id">
<div class="space-y-1">
<label class="text-xs font-semibold text-slate-500 uppercase">Committee Name</label>
<input type="text" name="name" id="edit_name" required class="w-full px-4 py-2 rounded-lg border border-gray-200 outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div class="space-y-1">
<label class="text-xs font-semibold text-slate-500 uppercase">Description</label>
<textarea name="description" id="edit_description" rows="3" class="w-full px-4 py-2 rounded-lg border border-gray-200 outline-none focus:ring-2 focus:ring-indigo-500"></textarea>
</div>
<div class="flex justify-end gap-3 pt-4">
<button type="button" onclick="closeEditModal()" class="px-6 py-2 border border-gray-200 text-slate-600 rounded-lg font-bold hover:bg-gray-50 transition-colors">Cancel</button>
<button type="submit" name="edit_comm" class="px-6 py-2 bg-indigo-600 text-white rounded-lg font-bold hover:bg-indigo-700 transition-colors">Update Committee</button>
</div>
</form>
</div>
</div>
<!-- View Members Modal -->
<div id="viewMembersModal" class="hidden fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl w-full max-w-2xl overflow-hidden h-[80vh] flex flex-col">
<div class="p-6 border-b border-gray-100 flex items-center justify-between shrink-0">
<h3 class="font-bold text-xl text-slate-800" id="view_comm_title">Committee Members</h3>
<button onclick="closeViewMembersModal()" class="text-slate-400 hover:text-slate-600">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
</button>
</div>
<div class="flex-1 overflow-y-auto p-6" id="members_list_container">
<!-- Members will be injected here -->
</div>
<div class="p-4 border-t border-gray-100 text-right shrink-0">
<button onclick="closeViewMembersModal()" class="px-6 py-2 bg-slate-100 text-slate-600 rounded-lg font-bold hover:bg-slate-200 transition-colors">Close</button>
</div>
</div>
</div>
<script>
const allMembers = <?php echo json_encode($comm_members); ?>;
// Auto-open modal if comm ID is in URL
const urlParams = new URLSearchParams(window.location.search);
const autoViewId = urlParams.get('view');
if (autoViewId) {
const comm = <?php echo json_encode($committees); ?>.find(c => c.id == autoViewId);
if (comm) viewMembers(comm.id, comm.name);
}
function openEditModal(comm) {
document.getElementById('edit_id').value = comm.id;
document.getElementById('edit_name').value = comm.name;
document.getElementById('edit_description').value = comm.description;
document.getElementById('editModal').classList.remove('hidden');
}
function closeEditModal() {
document.getElementById('editModal').classList.add('hidden');
}
function getRoleStyle(role) {
switch(role) {
case 'Chairman':
case 'President':
case 'Head': return 'bg-amber-100 text-amber-700 border-amber-200';
case 'Vice president':
case 'Assistant':
case 'Assist. Organiser':
case 'Assist. Secretary':
case 'Assist. Financial Secretary': return 'bg-emerald-100 text-emerald-700 border-emerald-200';
case 'Secretary': return 'bg-indigo-100 text-indigo-700 border-indigo-200';
case 'Organiser': return 'bg-rose-100 text-rose-700 border-rose-200';
case 'Financial secretary': return 'bg-cyan-100 text-cyan-700 border-cyan-200';
default: return 'bg-slate-100 text-slate-500 border-slate-200';
}
}
function toggleRole(memberId, commId, currentRole) {
const roles = [
'Member', 'Chairman', 'President', 'Head', 'Vice president', 'Assistant',
'Secretary', 'Assist. Secretary', 'Organiser',
'Assist. Organiser', 'Financial secretary', 'Assist. Financial Secretary'
];
const nextRole = roles[(roles.indexOf(currentRole) + 1) % roles.length];
const form = document.createElement('form');
form.method = 'POST';
form.innerHTML = `
<input type="hidden" name="update_role" value="1">
<input type="hidden" name="member_id" value="${memberId}">
<input type="hidden" name="comm_id" value="${commId}">
<input type="hidden" name="role" value="${nextRole}">
`;
document.body.appendChild(form);
form.submit();
}
function viewMembers(commId, commName) {
const container = document.getElementById('members_list_container');
document.getElementById('view_comm_title').innerText = `${commName} Members`;
const filteredMembers = allMembers.filter(m => m.committee_id == commId);
if (filteredMembers.length === 0) {
container.innerHTML = `<div class="text-center py-10 text-slate-400">No members assigned to this committee yet.</div>`;
} else {
let html = `<div class="space-y-4">`;
filteredMembers.forEach(m => {
html += `
<div class="flex items-center justify-between p-4 bg-gray-50 rounded-xl hover:bg-gray-100 transition-colors">
<div class="flex items-center gap-4">
<div class="w-10 h-10 bg-indigo-100 text-indigo-700 rounded-full flex items-center justify-center text-xs font-bold overflow-hidden shrink-0 border-2 border-white shadow-sm">
${m.photo_url ? `<img src="${m.photo_url}" class="w-full h-full object-cover">` : m.full_name.charAt(0)}
</div>
<div>
<div class="font-bold text-slate-900 flex items-center gap-2">
${m.full_name}
<button
onclick='toggleRole(${m.member_id}, ${commId}, "${m.role}")'
class="text-[10px] uppercase font-bold px-2 py-0.5 rounded-full border ${getRoleStyle(m.role)}"
>
${m.role}
</button>
</div>
<div class="text-sm text-slate-500">${m.email || 'No email'}</div>
</div>
</div>
<div class="text-sm font-medium text-slate-600">${m.phone || 'No phone'}</div>
</div>
`;
});
html += `</div>`;
container.innerHTML = html;
}
document.getElementById('viewMembersModal').classList.remove('hidden');
}
function closeViewMembersModal() {
document.getElementById('viewMembersModal').classList.add('hidden');
}
window.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
closeEditModal();
closeViewMembersModal();
}
});
</script>
</body>
</html>