function handleSubmit(event) { event.preventDefault(); const formData = new FormData(event.target); console.log('Adding Book:', Object.fromEntries(formData)); } function editUser(userId) { const modal = document.getElementById('editModal'); modal.innerHTML = ` `; modal.style.display = 'block'; } function closeModal() { document.getElementById('editModal').style.display = 'none'; } function updateUserStatus(event, userId) { event.preventDefault(); const status = event.target.status.value; fetch('../Admin Actions/UpdateUserStatus.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: `userId=${userId}&status=${status}` }) .then(response => response.text()) // Get the raw response as text .then(data => { console.log(data); // Log the raw response for debugging try { const jsonResponse = JSON.parse(data); if (jsonResponse.success) { location.reload(); // Refresh to show updated status } } catch (error) { console.error('Failed to parse response as JSON:', error); } }) .catch(error => { console.error('Error during fetch:', error); }); closeModal(); } function searchUsers() { const searchInput = document.querySelector('.search-input').value.toLowerCase(); const tableRows = document.querySelectorAll('#usersTableBody tr'); tableRows.forEach(row => { const userid = row.cells[0].textContent.toLowerCase(); const username = row.cells[1].textContent.toLowerCase(); const email = row.cells[2].textContent.toLowerCase(); if (userid.includes(searchInput) || username.includes(searchInput) || email.includes(searchInput)) { row.style.display = ''; } else { row.style.display = 'none'; } }); document.querySelector('.search-input').addEventListener('keyup', searchUsers); }