snuffler-web/index.php
2024-09-28 19:42:37 +03:00

89 lines
2 KiB
PHP
Executable file

<?php
require_once "inc/database.php";
$database = new DataBase();
if(!$database) {
die($database->lastErrorMsg());
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Snuffler</title>
</head>
<body>
<div id="flexout">
<div id="lpanel" class="flexpanel">
<ul>
<li>Kotisivu</li>
<li>Viestit</li>
<li>Kalavaleet</li>
<li>Takasivu</li>
</ul>
</div>
<div id="rpanel" class="flexpanel">
<ul>
<li>Mikko Mällikäs<br /><small>@mmallikas</small></li>
<li>Jarkko Toivanen<br /><small>@jt</small></li>
</ul>
</div>
<div id="centerbox">
<div id="titlebox"><img src="favicon.ico" />Snuffler</div>
<?php
if (!$database->getAuthedUserId()) {
?>
<form id="loginform" method="post" action="login.php">
<input type="text" name="name" placeholder="username" />
<input type="password" name="pass" placeholder="password" />
<input type="submit" name="submit" value="Log in" />
</form>
<?php
} else {
?>
<a href="logout.php">LOG OUT</a>
<form id="postform">
<textarea id="postformtextarea" name="text" rows="5" placeholder="Whatcha snuffin' about?"></textarea><br />
<div id="postformactionrow">
<select id="user" name="user">
<option value=0>SYSTEM</option>
<option value=1>User</option>
</select>
<input type="submit" id="submit" name="submit" value="Snuff!" />
</div>
</form>
<?php
}
?>
<?php
//$database->addPost("Test post", 0);
$posts = array_reverse($database->getPosts());
//var_dump($posts);
foreach($posts as $post) {
echo '<div class="post">';
echo '<strong>' . $post["user.name"] . '</strong>';
echo '<br><small>@' . $post["user.handle"] . '</small>';
echo '<p>' . $post["post.text"] . '</p>';
echo '<hr><small>' . date("D j.n.Y \@ G:i", $post["post.time"]) . '</small>';
echo '<span class="postactions">👍5 👎0 💬2</span>';
echo "</div>";
}
$database->close();
?>
</div>
</div>
</body>
</html>