2024-02-22 09:42:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function getNewsArticles() :array
|
|
|
|
{
|
|
|
|
global $mysqli;
|
|
|
|
|
|
|
|
$articles = [];
|
|
|
|
if (isLoggedIn()) {
|
2024-02-22 10:05:09 +01:00
|
|
|
$result = $mysqli->query("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; ");
|
2024-02-22 09:42:37 +01:00
|
|
|
|
|
|
|
// Check if the query executed Successfully
|
|
|
|
if ($result) {
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
$articles[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $articles;
|
2024-02-22 10:05:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function addNewsArticle($title="Nazov", $body="Obsah") :array
|
|
|
|
{
|
|
|
|
global $mysqli;
|
|
|
|
|
|
|
|
$output = ["Status" => "Fail"]; // Default Status is "Fail"
|
|
|
|
if (isLoggedIn()) {
|
|
|
|
$query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList) VALUES (?, ?, ?, ?);");
|
2024-02-22 12:24:09 +01:00
|
|
|
$query->bind_param("issi", $_SESSION["id"], htmlspecialchars($title), htmlspecialchars($body), 0);
|
2024-02-22 10:05:09 +01:00
|
|
|
$query->execute();
|
|
|
|
if ($query->affected_rows > 0) {
|
|
|
|
$output["Status"] = "Success";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$query->close();
|
|
|
|
return $output;
|
2024-02-22 09:42:37 +01:00
|
|
|
}
|