book_details.php 7.06 KB
Newer Older
1
2
3
4
5
<?php include 'session_manager.php';
include 'book_data.php';
include 'comments.php';
?>

6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Book Details</title>
    <script src="https://cdn.tailwindcss.com"></script>
14
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
15
16
17
18
19
20
21
22
    <link href="style.css" rel="stylesheet">
</head>

<body class="flex flex-col min-h-screen">
    <!-- Sticky Navbar -->
    <nav class="bg-gray-800 text-white p-4 sticky top-0 z-50">
        <div class="container mx-auto flex justify-between items-center">
            <!-- Logo -->
23
            <a href="index.php" class="transition-transform duration-500 transform hover:scale-125 hover:rotate-180">
24
                <img src="./images/Logo.png" alt="Logo" class="h-8">
25
            </a>
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
            <!-- Login/Logout Button -->
            <div>
                <?php if (isset($_SESSION['userid'])) : ?>
                    <span>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></span>
                    <a href="logout.php" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">Logout</a>
                <?php else : ?>
                    <a href="signup.php" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Login</a>
                <?php endif; ?>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <div class="flex-grow container mx-auto p-4 bg-gray-100">
        <?php if ($book) : ?>
            <div class="flex flex-wrap">
                <!-- Book Image -->
                <div class="w-full md:w-1/3 p-4">
44
                    <img src="<?php echo htmlspecialchars($book['image_url']); ?>" class="w-full h-auto object-cover">
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
                </div>

                <!-- Book Details and Comments -->
                <div class="w-full md:w-2/3 p-4">
                    <h2 class="text-2xl font-bold"><?php echo htmlspecialchars($book['title']); ?></h2>
                    <p><strong>Author:</strong> <?php echo htmlspecialchars($book['author_name']); ?></p>
                    <p><strong>Year Published:</strong> <?php echo htmlspecialchars($book['year_published']); ?></p>
                    <p><strong>Pages:</strong> <?php echo htmlspecialchars($book['pages']); ?></p>
                    <p><strong>Category:</strong> <?php echo htmlspecialchars($book['category_title']); ?></p>
                    <p><strong>Author Bio:</strong> <?php echo htmlspecialchars($book['bio']); ?></p>

                    <div class="my-8"></div>

                    <!-- Comments Section -->
60
61
62
63
64
65
66
67
68
                    <div class="mt-8">
                        <h3 class="text-2xl font-bold text-gray-800 mb-4">Comments</h3>
                        <div class="space-y-4">
                            <?php foreach ($commentsResult as $comment) : ?>
                                <div class="bg-white shadow rounded-lg p-4">
                                    <h5 class="font-semibold text-gray-800 mb-2"><?php echo htmlspecialchars($comment['username']); ?></h5>
                                    <p class="text-gray-600"><?php echo htmlspecialchars($comment['comment']); ?></p>
                                </div>
                            <?php endforeach; ?>
69
70
                        </div>

71
72
73
74
75
76
                        <?php if (isset($_SESSION['comment_message'])) : ?>
                            <div class="bg-green-500 text-white text-sm p-4 rounded-lg mt-4">
                                <?php echo htmlspecialchars($_SESSION['comment_message']); ?>
                            </div>
                            <?php unset($_SESSION['comment_message']); ?>
                        <?php endif; ?>
77

78
                        <?php if (isset($_SESSION['username']) && (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin')) : ?>
79
80
81
82
83
84
                            <!-- Comment Submission Form -->
                            <form action="comments.php" method="post" class="mt-8">
                                <textarea name="comment" class="w-full p-4 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="Leave a comment..." required></textarea>
                                <input type="hidden" name="book_id" value="<?php echo $bookId; ?>">
                                <button type="submit" class="mt-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-lg transition duration-300 ease-in-out animate-bounce">Submit</button>
                            </form>
85
                        <?php elseif (!isset($_SESSION['username'])) : ?>
86
87
88
89
90
91
                            <p class="mt-8 text-lg font-semibold animate-bounce">
                                To leave comments, please <a href="signup.php" class="text-blue-500 hover:text-blue-700 transition duration-300 ease-in-out">Log in</a>.
                            </p>
                        <?php endif; ?>
                    </div>
                </div>
92
93
94
                <div class="my-8"></div>

                <!-- Private Notes -->
95
                <?php if (isset($_SESSION['username']) && (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin')) : ?>
96
                    <div class="mt-8">
97
98
99
100
                        <h3 class="text-xl font-bold mb-2 text-gray-800">Private Notes</h3>
                        <div class="bg-white shadow-sm rounded-lg p-4">
                            <form id="privateNotesForm" class="space-y-4">
                                <textarea name="note" class="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:shadow-outline" rows="4" placeholder="Your private note here"></textarea>
101
                                <input type="hidden" name="book_id" value="<?php echo $bookId; ?>">
102
                                <button type="button" id="saveNoteButton" class="w-full text-white bg-blue-500 hover:bg-blue-600 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center">Save Note</button>
103
104
105
                            </form>
                        </div>
                        <!-- Notes List -->
106
107
                        <div id="notesList" class="mt-4 space-y-2">
                            <!-- JavaScript goes here -->
108
109
                        </div>
                    </div>
110
                <?php elseif (!isset($_SESSION['username'])) : ?>
111
                    <p class="text-lg font-semibold">To add private notes, please <a href="signup.php" class="text-blue-500">Log in</a>.</p>
112
113
114
115
116
117
118
119
120
121
122
123
124
                <?php endif; ?>
            </div>
        <?php else : ?>
            <p>Book details not found.</p>
        <?php endif; ?>
    </div>
    <!-- Sticky Footer -->
    <footer class="bg-gray-800 text-white p-4 sticky bottom-0 z-50">
        <div class="container mx-auto text-center">
            <p id="quote"></p>
        </div>
    </footer>
    <script src="footer.js"></script>
125
    <script src="notes_ajax.js"></script>
126
</body>
127

128
</html>