69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'header.php';
|
|
|
|
// Get author ID from query string
|
|
$author_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
|
|
if (!$author_id) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch author details
|
|
// This assumes the bio is stored in the writer_applications table.
|
|
// A better approach would be to have a 'bio' column in the users table.
|
|
$stmt = $pdo->prepare("SELECT u.username, wa.bio FROM users u LEFT JOIN writer_applications wa ON u.id = wa.user_id WHERE u.id = ? AND u.role = 'writer'");
|
|
$stmt->execute([$author_id]);
|
|
$author = $stmt->fetch();
|
|
|
|
if (!$author) {
|
|
// Redirect if not a writer or doesn't exist
|
|
// You might want to show a generic "user not found" page instead
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
// Fetch author's books, assuming the user who added the book is the author
|
|
$stmt = $pdo->prepare("SELECT id, title, author_name, description FROM books WHERE added_by_user_id = ? ORDER BY created_at DESC");
|
|
$stmt->execute([$author_id]);
|
|
$books = $stmt->fetchAll();
|
|
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<div class="card mb-4">
|
|
<div class="card-body">
|
|
<h1 class="card-title"><?php echo htmlspecialchars($author['username']); ?></h1>
|
|
<p class="card-text"><?php echo nl2br(htmlspecialchars($author['bio'] ?? 'This author has not provided a bio yet.')); ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<h3>Books by <?php echo htmlspecialchars($author['username']); ?></h3>
|
|
|
|
<div class="row">
|
|
<?php if (empty($books)): ?>
|
|
<div class="col">
|
|
<p>This author has not published any books yet.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($books as $book): ?>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><a href="book.php?id=<?php echo $book['id']; ?>"><?php echo htmlspecialchars($book['title']); ?></a></h5>
|
|
<p class="card-text"><?php echo htmlspecialchars(substr($book['description'] ?? '', 0, 100)); ?>...</p>
|
|
</div>
|
|
<div class="card-footer">
|
|
<a href="book.php?id=<?php echo $book['id']; ?>" class="btn btn-primary">View Details</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'footer.php'; ?>
|