document.addEventListener("DOMContentLoaded", () => { fetch("isAdmin.php").then(res => res.json().then(json => { if (json.message !== "ok") { window.location.href = "./search.html"; } })); fetch("viewLog.php").then(res => res.json().then(json => { if (json.message === "ok") { for (const key of Object.keys(json.logs[0])) { let header = key.substring(key.indexOf("_") + 1) header = header.charAt(0).toUpperCase() + header.slice(1); document.querySelector("#logTable thead tr").innerHTML += `${header}`; } let body = ""; for (const row of json.logs) { body += ""; for (const key of Object.keys(row)) { body += `${row[key]}`; } body += ""; } document.querySelector("#logTable tbody").innerHTML = body; } })); });