Fix articles

This commit is contained in:
Bruno Rybársky 2024-02-24 09:01:13 +01:00
parent cb0c400f81
commit d508231265
6 changed files with 31 additions and 9 deletions

@ -218,12 +218,21 @@ async function submitarticle(){
async function articleInit(){ async function articleInit(){
let articleContainerElement = document.getElementById("articlecreatecontainer"); let articleContainerElement = document.getElementById("articlecreatecontainer");
let articleCreateOpenElement = document.getElementById("articlecreateopen");
articleContainerElement.addEventListener("keyup", function (ev) { articleContainerElement.addEventListener("keyup", function (ev) {
if(ev.key === "Escape"){ if(ev.key === "Escape"){
togglearticlecreate(); togglearticlecreate();
} }
}) })
PageIntervals.push(setInterval(renderarticles, 300000)); 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() { async function onPageLoad() {

@ -402,6 +402,11 @@ body:has(.ye-span:hover) {
backdrop-filter: blur(2px); backdrop-filter: blur(2px);
} }
div.articleinfo{
display: flex;
flex-direction: row;
}
.hidden { .hidden {
display: none !important; display: none !important;
} }

@ -26,6 +26,9 @@
'default_permissions' => 255, 'default_permissions' => 255,
], ],
'newsarticle' => [
'default_permissions' => 255,
],
'seo' => [ 'seo' => [
'author' => 'Tím AdlerkaTop', 'author' => 'Tím AdlerkaTop',
'description' => 'Toto je neoficiánla študentská stránka pre Adlerku, kde môžete nájsť plno zaujímavostí.', 'description' => 'Toto je neoficiánla študentská stránka pre Adlerku, kde môžete nájsť plno zaujímavostí.',

@ -1,5 +1,4 @@
<?php <?php
function getNewsArticles() :array function getNewsArticles() :array
{ {
global $mysqli; global $mysqli;
@ -7,8 +6,7 @@ function getNewsArticles() :array
$output = ["Status" => "Fail"]; // Default Status is "Fail" $output = ["Status" => "Fail"]; // Default Status is "Fail"
$articles = []; $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 WHERE NewsArticles.PrivilegeLevel <= ?;");
$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;
@ -17,6 +15,7 @@ function getNewsArticles() :array
$filelist = 0; $filelist = 0;
$writtenByName = ""; $writtenByName = "";
$stmt->bind_param("i", $_SESSION["privilege_level"]);
$stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName); $stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName);
$stmt->execute(); $stmt->execute();
@ -37,19 +36,23 @@ function getNewsArticles() :array
$output["Articles"] = $articles; $output["Articles"] = $articles;
} }
}
return $output; return $output;
} }
function addNewsArticle($title="Nazov", $body="Obsah") :array function addNewsArticle($title="Nazov", $body="Obsah", $privilegeLevel=0) :array
{ {
global $mysqli; global $mysqli;
global $routerConfig;
if ($privilegeLevel == 0){
$privilegeLevel = $routerConfig['newsarticle']['default_permissions'];
}
$output = ["Status" => "Fail"]; // Default Status is "Fail" $output = ["Status" => "Fail"]; // Default Status is "Fail"
if (isLoggedIn()) { if (isLoggedIn() && $privilegeLevel <= $_SESSION["privilege_level"]) {
$query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList) VALUES (?, ?, ?, 0);"); $query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList, PrivilegeLevel) VALUES (?, ?, ?, 0, ?);");
$query->bind_param("iss", $_SESSION["ID"], htmlspecialchars($title), htmlspecialchars($body)); $query->bind_param("issi", $_SESSION["ID"], htmlspecialchars($title), htmlspecialchars($body), intval($privilegeLevel));
$query->execute(); $query->execute();
if ($query->affected_rows > 0) { if ($query->affected_rows > 0) {
$output["Status"] = "Success"; $output["Status"] = "Success";

@ -143,6 +143,7 @@ function getPage($site_name_in = null, $page_name_in = null): string
"currentTitle" => $page_title, "currentTitle" => $page_title,
"defaultPage" => $routerConfig["default_page"], "defaultPage" => $routerConfig["default_page"],
"defaultSite" => $routerConfig["default_site"], "defaultSite" => $routerConfig["default_site"],
"UserInfo_Privileges" => $_SESSION["privilege_level"],
]; ];
if(isLoggedIn()){ if(isLoggedIn()){
$dynamic_script_data += [ $dynamic_script_data += [

@ -17,6 +17,7 @@
<div id="articlecreate"> <div id="articlecreate">
<input type="text" placeholder="Article Title" id="articletitleinput"><br> <input type="text" placeholder="Article Title" id="articletitleinput"><br>
<textarea id="articlebodyinput" placeholder="Article Body" rows="20" cols="80"></textarea><br> <textarea id="articlebodyinput" placeholder="Article Body" rows="20" cols="80"></textarea><br>
<input type="number" id="articleprivilegeinput" min="1" value="1" step="1"><br>
<button id="articlesubmit" onclick="submitarticle()">Add</button> <button id="articlesubmit" onclick="submitarticle()">Add</button>
</div> </div>
</div> </div>