1.1.1.1.2

This commit is contained in:
Flatlogic Bot 2025-12-11 09:14:46 +00:00
parent c56a30b688
commit 51894f9e94
6 changed files with 172 additions and 43 deletions

View File

@ -1,24 +1,8 @@
<!DOCTYPE html> <?php
<html lang="en"> // Admin PHP logic here (e.g., session check, database operations, etc.)
<head> $pageTitle = "Admin Dashboard";
<meta charset="UTF-8"> include 'includes/header.php';
<meta name="viewport" content="width=device-width, initial-scale=1.0"> ?>
<title>Admin Dashboard</title>
<link rel="stylesheet" href="assets/css/styles.css?v=<?php echo time(); ?>">
</head>
<body>
<header class="main-header">
<div class="container">
<a href="/" class="logo">AppCo</a>
<nav class="main-nav">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/admin.php" class="active">Admin Panel</a></li>
</ul>
</nav>
</div>
</header>
<main class="container"> <main class="container">
<div class="dashboard-header"> <div class="dashboard-header">

View File

@ -337,3 +337,83 @@ tbody tr:hover {
background-color: #d4edda; background-color: #d4edda;
border-color: #c3e6cb; border-color: #c3e6cb;
} }
/* Post Section Styles */
.post-creation-section, .feed-section {
background-color: #fff;
padding: 2rem;
border-radius: 0.5rem;
box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,.075);
margin-bottom: 2rem;
}
.post-creation-section h2, .feed-section h2 {
margin-top: 0;
margin-bottom: 1.5rem;
font-size: 1.75rem;
color: #343a40;
}
.post-card {
border: 1px solid #e9ecef;
border-radius: 0.5rem;
padding: 1.5rem;
margin-bottom: 1rem;
background-color: #fefefe;
}
.post-card:last-child {
margin-bottom: 0;
}
.post-author {
font-size: 1rem;
color: #495057;
margin-bottom: 0.5rem;
}
.post-author strong {
color: #007bff;
}
.post-date {
font-size: 0.85rem;
color: #6c757d;
float: right;
}
.post-content {
font-size: 1.1rem;
line-height: 1.6;
color: #212529;
white-space: pre-wrap; /* Preserve whitespace and line breaks */
}
textarea#post_content {
width: 100%;
padding: 0.75rem;
border: 1px solid #ced4da;
border-radius: 0.25rem;
resize: vertical; /* Allow vertical resizing */
font-family: inherit; /* Inherit font from body */
}
button[name="new_post"] {
margin-top: 1rem;
width: auto;
padding: 0.75rem 2rem;
border-radius: 0.25rem;
background-color: #28a745; /* A green color for post button */
}
button[name="new_post"]:hover {
background-color: #218838;
}
.button-secondary {
background-color: #6c757d;
}
.button-secondary:hover {
background-color: #5a6268;
}

View File

@ -1,31 +1,89 @@
<?php <?php
session_start(); session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
header('Location: login.php'); header('Location: login.php');
exit; exit;
} }
$user_id = $_SESSION['user_id'];
$username = $_SESSION['username'];
$post_message = '';
$error_message = '';
// Handle new post submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_post'])) {
$post_content = trim($_POST['post_content']);
if (empty($post_content)) {
$error_message = 'Post content cannot be empty.';
} else {
try {
$db = db();
$stmt = $db->prepare("INSERT INTO posts (user_id, content) VALUES (:user_id, :content)");
$stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$stmt->bindParam(':content', $post_content, PDO::PARAM_STR);
$stmt->execute();
$post_message = 'Your post has been shared!';
// Clear the post content after successful submission
$_POST['post_content'] = '';
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
// Fetch all posts
$posts = [];
try {
$db = db();
$stmt = $db->prepare("SELECT p.content, p.created_at, u.username FROM posts p JOIN users u ON p.user_id = u.id ORDER BY p.created_at DESC");
$stmt->execute();
$posts = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$error_message = 'Failed to load posts: ' . $e->getMessage();
}
$pageTitle = "User Dashboard - Flatlogic";
include 'includes/header.php';
?> ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Dashboard - Flatlogic</title>
<link rel="stylesheet" href="assets/css/styles.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="container"> <div class="container">
<header> <header>
<h1>Welcome to your Dashboard</h1> <h1>Welcome, <?php echo htmlspecialchars($username); ?>!</h1>
</header> </header>
<main> <main>
<p>This is your protected dashboard area.</p> <?php if ($post_message): ?>
<a href="logout.php" class="button">Logout</a> <div class="message success"><?php echo $post_message; ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="message error"><?php echo $error_message; ?></div>
<?php endif; ?>
<section class="post-creation-section">
<h2>Share something new</h2>
<form action="dashboard.php" method="post" class="form-card">
<div class="form-group">
<textarea id="post_content" name="post_content" rows="4" placeholder="What's on your mind?" required><?php echo htmlspecialchars($_POST['post_content'] ?? ''); ?></textarea>
</div>
<button type="submit" name="new_post" class="button">Post</button>
</form>
</section>
<section class="feed-section">
<h2>Recent Posts</h2>
<?php if (empty($posts)): ?>
<p>No posts yet. Be the first to share something!</p>
<?php else: ?>
<?php foreach ($posts as $post): ?>
<div class="post-card">
<p class="post-author"><strong><?php echo htmlspecialchars($post['username']); ?></strong> <span class="post-date"><?php echo date('F j, Y, g:i a', strtotime($post['created_at'])); ?></span></p>
<p class="post-content"><?php echo nl2br(htmlspecialchars($post['content'])); ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
</section>
<a href="logout.php" class="button button-secondary">Logout</a>
</main> </main>
<footer> <?php include 'includes/footer.php'; ?>
<p>&copy; <?php echo date("Y"); ?> Flatlogic. All rights reserved.</p>
</footer>
</div>
</body>
</html>

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS posts (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);

View File

@ -13,15 +13,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} else { } else {
try { try {
$db = db(); $db = db();
$stmt = $db->prepare("SELECT id, username, password FROM users WHERE email = :email"); $stmt = $db->prepare("SELECT id, username, password_hash FROM users WHERE email = :email");
$stmt->bindParam(':email', $email); $stmt->bindParam(':email', $email);
$stmt->execute(); $stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC); $user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password'])) { if ($user && password_verify($password, $user['password_hash'])) {
$_SESSION['user_id'] = $user['id']; $_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username']; // Store username for display $_SESSION['username'] = $user['username']; // Store username for display
header('Location: home.php'); // Redirect to home.php header('Location: dashboard.php'); // Redirect to dashboard.php
exit; exit;
} else { } else {
$error_message = 'Invalid email or password.'; $error_message = 'Invalid email or password.';

View File

@ -27,7 +27,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} else { } else {
$password_hash = password_hash($password, PASSWORD_DEFAULT); $password_hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $db->prepare("INSERT INTO users (username, email, password) VALUES (:username, :email, :password)"); $stmt = $db->prepare("INSERT INTO users (username, email, password_hash) VALUES (:username, :email, :password)");
$stmt->bindParam(':username', $username); $stmt->bindParam(':username', $username);
$stmt->bindParam(':email', $email); $stmt->bindParam(':email', $email);
$stmt->bindParam(':password', $password_hash); $stmt->bindParam(':password', $password_hash);