Sixtens hemsida Uppgifter Blogg Om

Inloggningstjänst

Gå till sida

Källkod

moment04/

admin.php

functions.php

logout.php

index.php

login.php

signup.php

change_password.php

admin/

authorized.php

users/

admin.json

HogeN.json

Hej.json

sixten.json

posts/

167db73f2a604dd391f1303a25cb2443.json

wesweb01/moment04/index.php

1 lines
<?php
include("functions.php");
check_user_logged_in();

if (isset(
$_GET["delete"])) {
    if (
$_SESSION["isAdmin"])
        
delete_post($_GET["delete"]);
    
header("location: ?");
}

function 
create_post_button($jsonData$id)
{
    
$title "Card Title";
    
$content "Testtest";
    
$author "admin";
    
$date "2025-09-26";
    echo 
"<div class=\"card red accent-2\">
        <div class=\"row\">
            <div class=\"col s11 card-content white-text\">
            <span class=\"card-title\">
{$jsonData->title}</span>
                <pre>
{$jsonData->content}</pre>
                <br>
                <p>Publicerat av <b>
{$jsonData->author}</b>, {$jsonData->date}</p>
            </div>"
;
    if (
$_SESSION["isAdmin"])
        echo 
"<div class=\"col s1 valign-wrapper\">
        <a class=\"waves-effect waves-light btn\" href=\"?delete=
{$id}\">Radera</a>
        </div>"
;
    echo 
"</div>
    </div>"
;
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>m04</title>
    <link rel="stylesheet" type="text/css" href="../css/materialize.css">
    <script defer type="text/javascript" src="../js/materialize.js"></script>
</head>

<body>
    <?php print_navbar() ?>
    <div class="container">
        <?php
        
echo "<h1>Välkommen, {$_SESSION['username']}!</h1>";
        
?>
        <?php
        $postsListEmpty 
true;
        foreach (new 
DirectoryIterator("posts") as $fileInfo) {
            if (
$fileInfo->isDot())
                continue;
            
$postsListEmpty false;
            
$json json_decode(file_get_contents("posts/{$fileInfo->getFilename()}"));
            
create_post_button($jsonbasename($fileInfo->getFilename(), ".json"));
        }
        if (
$postsListEmpty)
            echo 
"<h2 class=\"center-align grey-text\">Inget att se just nu...</h2>";

        
?>
    </div>
</body>

</html>