DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/viewLog.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

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 += `<th>${header}</th>`;
}
let body = "";
for (const row of json.logs)
{
body += "<tr>";
for (const key of Object.keys(row))
{
body += `<td>${row[key]}</td>`;
}
body += "</tr>";
}
document.querySelector("#logTable tbody").innerHTML = body;
}
}));
});