DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/viewLog.js
rodude123 95b11f3496 Created the log functionality
Signed-off-by: rodude123 <rodude123@gmail.com>
2022-12-16 12:19:38 +00:00

37 lines
1.0 KiB
JavaScript

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;
}
}));
});