/* ── Real-time: New User Registered ─────────────────────────────────────── */ (function () { var cfg = window._rrReverb; if (!cfg || typeof Pusher === 'undefined') return; var pusher = new Pusher(cfg.key, { wsHost: cfg.wsHost, wsPort: cfg.wsPort, wssPort: cfg.wssPort, forceTLS: cfg.forceTLS, enabledTransports: cfg.enabledTransports, cluster: 'mt1', disableStats: true, }); pusher.subscribe('contact.admin').bind('user.registered', function (data) { admNewUserRegistered(data); }); })(); function escHtml(str) { if (!str) return ''; return String(str) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"'); } function admNewUserRegistered(data) { var tbody = document.querySelector('#userTable tbody'); if (!tbody) return; var name = (data.name || ((data.first_name || '') + ' ' + (data.last_name || '')).trim()) || data.username; var existingRows = tbody.querySelectorAll('tr.pgd-row'); var newIndex = existingRows.length + 1; var row = document.createElement('tr'); row.className = 'pgd-row'; row.dataset.status = '1'; row.dataset.verified = 'unverified'; row.dataset.search = (name + ' ' + (data.username || '') + ' ' + (data.email || '')).toLowerCase(); row.innerHTML = '' + newIndex + '' + '
' + '
' + '
' + '' + '
' + '
' + '' + escHtml(name) + '' + '
' + '' + escHtml(data.username) + '' + '' + escHtml(data.email) + '' + '—' + 'Active' + 'Unverified' + '' + escHtml(data.created_at || '—') + '' + ''; var noResults = document.getElementById('userNoResults'); if (noResults) tbody.insertBefore(row, noResults); else tbody.appendChild(row); var totalPill = document.querySelector('.adm-page-header .status-pill'); if (totalPill) { var cur = parseInt(totalPill.textContent, 10) || 0; totalPill.textContent = (cur + 1) + ' Total'; } if (window.PGD) { PGD.init({ id: 'usr', sel: '#userTable tbody tr.pgd-row', prevId: 'usrPrev', nextId: 'usrNext', infoId: 'usrInfo', pagesId: 'usrPages', perPage: 10, }); } } /* ── Filter ─────────────────────────────────────────────────────────────── */ function filterUserTable() { var search = ( document.getElementById("searchUser").value || "" ).toLowerCase(); var status = document.getElementById("filterUserStatus").value; var verified = document.getElementById("filterUserVerified").value; var noRes = document.getElementById("userNoResults"); var matched = []; document .querySelectorAll("#userTable tbody tr.pgd-row") .forEach(function (row) { var matchSearch = !search || (row.dataset.search || "").includes(search); var matchStatus = !status || row.dataset.status === status; var matchVerified = !verified || row.dataset.verified === verified; if (matchSearch && matchStatus && matchVerified) matched.push(row); }); if (noRes) noRes.style.display = matched.length === 0 ? "table-row" : "none"; if (window.PGD) PGD.applyFilter("usr", matched); } /* ── View User ───────────────────────────────────────────────────────────── */ function viewUser(id) { var loader = document.getElementById("userViewLoader"); var content = document.getElementById("userViewContent"); loader.style.display = "block"; content.style.display = "none"; content.innerHTML = ""; bootstrap.Modal.getOrCreateInstance( document.getElementById("userViewModal"), ).show(); fetch(window.usersRoutes.show + "/" + id, { headers: { Accept: "application/json", "X-CSRF-TOKEN": getCsrf(), }, }) .then(function (r) { return r.json(); }) .then(function (res) { if (!res.success) { showAlert("error", "Could not load user details."); return; } var u = res.user; var d = u.details || {}; var mc = u.medical_card || null; var statusHtml = u.status === "1" ? 'Active' : 'Suspended'; var html = '
'; /* ── Profile Card ── */ html += '
'; html += '
'; html += '
'; html += '
'; html += '
' + (d.first_name ? d.first_name + " " + d.last_name : u.username) + "
"; html += '
@' + u.username + "  ·  Consumer #" + (d.consumer_no || "—") + "
"; html += '
' + statusHtml; if (d.email_verified_at) { html += 'Email Verified'; } else { html += 'Unverified'; } html += "
"; html += '
Joined
' + (u.created_at || "—") + '
' + u.total_messages + " message(s)
"; html += "
"; /* ── Personal Info ── */ html += detailSection("Personal Information", "fa-address-card", [ [ "Full Name", d.first_name ? d.first_name + " " + d.last_name : "—", ], ["Email", d.email || "—"], ["Phone", d.phone || "—"], ["Date of Birth", d.date_of_birth || "—"], ["Address", d.address || "—"], ]); /* ── Account Info ── */ html += detailSection("Account Info", "fa-circle-info", [ ["Username", u.username], ["Consumer No.", d.consumer_no || "—"], ["Email Verified", d.email_verified_at || "Not verified"], ["Account Status", u.status === "1" ? "Active" : "Suspended"], ["Registered On", u.created_at || "—"], ]); /* ── Medical Card ── */ if (mc) { html += '
'; html += '
Medical Card
'; html += '
'; [ ["Blood Type", mc.blood_type || "—"], ["Medical History", mc.medical_history || "—"], ["Allergies", mc.allergies || "—"], ["Medications", mc.medications || "—"], ["Emergency Contact", mc.contact_name || "—"], ["Relation", mc.relation || "—"], ["Contact Phone", mc.contact_phone || "—"], ].forEach(function (item) { html += '
' + item[0] + "
"; html += '
' + item[1] + "
"; }); html += "
"; } else { html += '
'; html += ''; html += 'No medical card on file.
'; } html += "
"; loader.style.display = "none"; content.innerHTML = html; content.style.display = "block"; }) .catch(function () { showAlert("error", "Server error. Please try again."); loader.style.display = "none"; }); } function detailSection(title, icon, rows) { var html = '
'; html += '
' + title + "
"; html += '
'; rows.forEach(function (row) { html += '
'; html += '' + row[0] + ""; html += '' + row[1] + ""; html += "
"; }); html += "
"; return html; }