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 = "";
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)
}
document.getElementById("articleslist").innerHTML = articleout;

@ -89,11 +89,10 @@ function verifyPassword($userID, $password): bool
function UpdateSession(): void
{
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->execute();
$id = 0;
$first_name = "";
$last_name = "";
$nickname = "";
@ -104,11 +103,9 @@ function UpdateSession(): void
$favorite_color = 0;
$lastLoginAt = null;
$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->close();
$_SESSION["id"] = $id;
$_SESSION["first_name"] = $first_name;
$_SESSION["last_name"] = $last_name;
$_SESSION["nickname"] = $nickname;

@ -8,8 +8,7 @@ function getNewsArticles() :array
$articles = [];
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;
$writtenAt = "";
$writtenBy = 0;
@ -50,7 +49,7 @@ function addNewsArticle($title="Nazov", $body="Obsah") :array
$output = ["Status" => "Fail"]; // Default Status is "Fail"
if (isLoggedIn()) {
$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();
if ($query->affected_rows > 0) {
$output["Status"] = "Success";

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