diff --git a/assets/script.js b/assets/script.js index f2ef051..b6f0baf 100644 --- a/assets/script.js +++ b/assets/script.js @@ -218,12 +218,21 @@ async function submitarticle(){ async function articleInit(){ let articleContainerElement = document.getElementById("articlecreatecontainer"); + let articleCreateOpenElement = document.getElementById("articlecreateopen"); articleContainerElement.addEventListener("keyup", function (ev) { if(ev.key === "Escape"){ togglearticlecreate(); } }) PageIntervals.push(setInterval(renderarticles, 300000)); + document.getElementById("articleprivilegeinput").setAttribute("max", UserInfo.Privileges); + if(UserInfo.Privileges < 2){ + articleContainerElement.style.display = "none"; + articleCreateOpenElement.style.display = "none"; + } + else{ + articleCreateOpenElement.style.display = "inline-block"; + } } async function onPageLoad() { diff --git a/assets/style.css b/assets/style.css index 3f65fa2..e70f766 100644 --- a/assets/style.css +++ b/assets/style.css @@ -402,6 +402,11 @@ body:has(.ye-span:hover) { backdrop-filter: blur(2px); } +div.articleinfo{ + display: flex; + flex-direction: row; +} + .hidden { display: none !important; } diff --git a/lib/config.php b/lib/config.php index e180cc2..3f8c2a6 100644 --- a/lib/config.php +++ b/lib/config.php @@ -26,6 +26,9 @@ 'default_permissions' => 255, ], + 'newsarticle' => [ + 'default_permissions' => 255, + ], 'seo' => [ 'author' => 'Tím AdlerkaTop', 'description' => 'Toto je neoficiánla študentská stránka pre Adlerku, kde môžete nájsť plno zaujímavostí.', diff --git a/lib/newsarticle.php b/lib/newsarticle.php index 65745b3..646c22b 100644 --- a/lib/newsarticle.php +++ b/lib/newsarticle.php @@ -1,5 +1,4 @@ "Fail"]; // Default Status is "Fail" $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 WHERE NewsArticles.PrivilegeLevel <= ?;"); $id = 0; $writtenAt = ""; $writtenBy = 0; @@ -17,6 +15,7 @@ function getNewsArticles() :array $filelist = 0; $writtenByName = ""; + $stmt->bind_param("i", $_SESSION["privilege_level"]); $stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName); $stmt->execute(); @@ -37,19 +36,23 @@ function getNewsArticles() :array $output["Articles"] = $articles; } - } - return $output; } -function addNewsArticle($title="Nazov", $body="Obsah") :array +function addNewsArticle($title="Nazov", $body="Obsah", $privilegeLevel=0) :array { global $mysqli; + global $routerConfig; + + + if ($privilegeLevel == 0){ + $privilegeLevel = $routerConfig['newsarticle']['default_permissions']; + } $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)); + if (isLoggedIn() && $privilegeLevel <= $_SESSION["privilege_level"]) { + $query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList, PrivilegeLevel) VALUES (?, ?, ?, 0, ?);"); + $query->bind_param("issi", $_SESSION["ID"], htmlspecialchars($title), htmlspecialchars($body), intval($privilegeLevel)); $query->execute(); if ($query->affected_rows > 0) { $output["Status"] = "Success"; diff --git a/lib/page.php b/lib/page.php index a9eaa3b..3c04f80 100644 --- a/lib/page.php +++ b/lib/page.php @@ -143,6 +143,7 @@ function getPage($site_name_in = null, $page_name_in = null): string "currentTitle" => $page_title, "defaultPage" => $routerConfig["default_page"], "defaultSite" => $routerConfig["default_site"], + "UserInfo_Privileges" => $_SESSION["privilege_level"], ]; if(isLoggedIn()){ $dynamic_script_data += [ diff --git a/templates/newsArticles.html b/templates/newsArticles.html index ea74d38..e300c85 100644 --- a/templates/newsArticles.html +++ b/templates/newsArticles.html @@ -17,6 +17,7 @@


+