Fix user list

This commit is contained in:
Bruno Rybársky 2024-02-22 17:52:20 +01:00
parent 69b02ea332
commit d5bc8931eb
4 changed files with 5 additions and 10 deletions

@ -193,7 +193,7 @@ async function renderarticles(){
); );
let articleout = ""; let articleout = "";
for (const article of articles) { for (const article of articles.Articles) {
articleout += template.replace("__TEMPLATE_ARTICLE_TITLE__", article.Title).replace("__TEMPLATE_ARTICLE_AUTHOR__", article.WrittenByName).replace("__TEMPLATE_ARTICLE_DATE__", article.WrittenAt).replace("__TEMPLATE_ARTICLE_BODY__", article.Body) articleout += template.replace("__TEMPLATE_ARTICLE_TITLE__", article.Title).replace("__TEMPLATE_ARTICLE_AUTHOR__", article.WrittenByName).replace("__TEMPLATE_ARTICLE_DATE__", article.WrittenAt).replace("__TEMPLATE_ARTICLE_BODY__", article.Body)
} }
document.getElementById("articleslist").innerHTML = articleout; document.getElementById("articleslist").innerHTML = articleout;

@ -89,11 +89,10 @@ function verifyPassword($userID, $password): bool
function UpdateSession(): void function UpdateSession(): void
{ {
global $mysqli; global $mysqli;
$stmt = $mysqli->prepare("SELECT ID, FirstName, LastName, Nickname, Email, MinecraftNick, PrivilegeLevel, LastLoginAt, LoginCount, ClassID, FavoriteColor FROM Users WHERE ID = ? AND isActivated = 1"); $stmt = $mysqli->prepare("SELECT FirstName, LastName, Nickname, Email, MinecraftNick, PrivilegeLevel, LastLoginAt, LoginCount, ClassID, FavoriteColor FROM Users WHERE ID = ? AND isActivated = 1");
$stmt->bind_param("i", $_SESSION["ID"]); $stmt->bind_param("i", $_SESSION["ID"]);
$stmt->execute(); $stmt->execute();
$id = 0;
$first_name = ""; $first_name = "";
$last_name = ""; $last_name = "";
$nickname = ""; $nickname = "";
@ -104,11 +103,9 @@ function UpdateSession(): void
$favorite_color = 0; $favorite_color = 0;
$lastLoginAt = null; $lastLoginAt = null;
$loginCount = 0; $loginCount = 0;
$stmt->bind_result($id, $first_name, $last_name, $nickname, $email, $minecraft_nickname, $privilege_level, $lastLoginAt, $loginCount, $class_id, $favorite_color); $stmt->bind_result($first_name, $last_name, $nickname, $email, $minecraft_nickname, $privilege_level, $lastLoginAt, $loginCount, $class_id, $favorite_color);
$stmt->fetch(); $stmt->fetch();
$stmt->close(); $stmt->close();
$_SESSION["id"] = $id;
$_SESSION["first_name"] = $first_name; $_SESSION["first_name"] = $first_name;
$_SESSION["last_name"] = $last_name; $_SESSION["last_name"] = $last_name;
$_SESSION["nickname"] = $nickname; $_SESSION["nickname"] = $nickname;

@ -9,7 +9,6 @@ function getNewsArticles() :array
$articles = []; $articles = [];
if (isLoggedIn()) { if (isLoggedIn()) {
$stmt = $mysqli->prepare("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList, Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID;"); $stmt = $mysqli->prepare("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList, Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID;");
$id = 0; $id = 0;
$writtenAt = ""; $writtenAt = "";
$writtenBy = 0; $writtenBy = 0;
@ -50,7 +49,7 @@ function addNewsArticle($title="Nazov", $body="Obsah") :array
$output = ["Status" => "Fail"]; // Default Status is "Fail" $output = ["Status" => "Fail"]; // Default Status is "Fail"
if (isLoggedIn()) { if (isLoggedIn()) {
$query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList) VALUES (?, ?, ?, 0);"); $query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList) VALUES (?, ?, ?, 0);");
$query->bind_param("iss", $_SESSION["id"], htmlspecialchars($title), htmlspecialchars($body)); $query->bind_param("iss", $_SESSION["ID"], htmlspecialchars($title), htmlspecialchars($body));
$query->execute(); $query->execute();
if ($query->affected_rows > 0) { if ($query->affected_rows > 0) {
$output["Status"] = "Success"; $output["Status"] = "Success";

@ -1,6 +1,5 @@
<article> <article>
<h2 class='newstitle'>__TEMPLATE_ARTICLE_TITLE__</h2> <h2 class='newstitle'>__TEMPLATE_ARTICLE_TITLE__</h2>
<br>
<p class='newsauthor'>__TEMPLATE_ARTICLE_AUTHOR__</p> <p class='newsauthor'>__TEMPLATE_ARTICLE_AUTHOR__</p>
<p class='newsdate'>__TEMPLATE_ARTICLE_DATE__</p> <p class='newsdate'>__TEMPLATE_ARTICLE_DATE__</p>
<hr> <hr>