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(){
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() {

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

@ -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í.',

@ -1,5 +1,4 @@
<?php
function getNewsArticles() :array
{
global $mysqli;
@ -7,8 +6,7 @@ function getNewsArticles() :array
$output = ["Status" => "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";

@ -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 += [

@ -17,6 +17,7 @@
<div id="articlecreate">
<input type="text" placeholder="Article Title" id="articletitleinput"><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>
</div>
</div>