source: CaseViews.php

main
Last change on this file was 75f74d9, checked in by Vlado 222039 <vlado.popovski@…>, 6 weeks ago

Initial commit: Adding Book Tracker code

  • Property mode set to 100644
File size: 9.0 KB
Line 
1<?php require_once 'connect.php'; ?>
2<!DOCTYPE html>
3<html lang="en">
4<head>
5 <meta charset="UTF-8">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <title>Library Reports - BookTracker</title>
8 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
9 <style>
10 body {
11 background-color: #f8f9fa;
12 font-family: 'Libre Baskerville', serif;
13 }
14 .report-section {
15 background: white;
16 border-radius: 8px;
17 margin: 2rem 0;
18 padding: 2rem;
19 box-shadow: 0 2px 4px rgba(0,0,0,0.1);
20 }
21 h1, h2 {
22 color: #2C4A52;
23 border-bottom: 2px solid #D4AA7D;
24 padding-bottom: 0.5rem;
25 margin-bottom: 1.5rem;
26 }
27 .table-hover tbody tr:hover {
28 background-color: #f5f5f5;
29 }
30 .table thead th {
31 background-color: #2C4A52;
32 color: white;
33 }
34 .stat-number {
35 font-weight: 600;
36 color: #D4AA7D;
37 }
38 .nav {
39 display: flex;
40 gap: 15px;
41 margin-bottom: 20px;
42 }
43 .nav a {
44 color: #2C4A52;
45 text-decoration: none;
46 padding: 10px 15px;
47 border: 1px solid #2C4A52;
48 border-radius: 5px;
49 }
50 .nav a:hover {
51 background-color: #2C4A52;
52 color: white;
53 }
54 </style>
55</head>
56<body>
57 <div class="container-fluid py-4">
58 <header class="mb-5 text-center">
59 <h1 class="display-4" style="color: #2C4A52;">BookTracker Analytics</h1>
60 <div class="nav justify-content-center">
61 <a href="#member-stats">Member Statistics</a>
62 <a href="#book-stats">Book Statistics</a>
63 <a href="#genre-trends">Genre Trends</a>
64 </div>
65 </header>
66
67 <!-- Member Statistics Section -->
68 <div class="report-section" id="member-stats">
69 <h2>Member Loan Statistics (<?php echo date('Y'); ?>)</h2>
70 <div class="table-responsive">
71 <table class="table table-striped table-hover">
72 <thead>
73 <tr>
74 <th>Member</th>
75 <th>Status</th>
76 <th>Month</th>
77 <th>Total Loans</th>
78 <th>Current Loans</th>
79 <th>Total Fines</th>
80 <th>Fines Amount</th>
81 <th>Paid Amount</th>
82 </tr>
83 </thead>
84 <tbody>
85 <?php
86 try {
87 $stmt = $conn->query("SELECT * FROM get_member_history()");
88 $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
89
90 if(count($results) > 0) {
91 foreach($results as $row) {
92 $startDate = new DateTime($row['startdate']);
93 $formattedDate = $startDate->format('F');
94 echo "<tr>
95 <td>{$row['membername']}</td>
96 <td>{$row['membershipstatus']}</td>
97 <td>{$formattedDate}</td>
98 <td class='stat-number'>{$row['totalloans']}</td>
99 <td class='stat-number'>{$row['currentloans']}</td>
100 <td class='stat-number'>{$row['totalfines']}</td>
101 <td class='stat-number'>$".number_format($row['totalfineamount'], 2)."</td>
102 <td class='stat-number'>$".number_format($row['totalpayments'], 2)."</td>
103 </tr>";
104 }
105 } else {
106 echo "<tr><td colspan='8'>No member statistics available for " . date('Y') . ".</td></tr>";
107 }
108 } catch(PDOException $e) {
109 echo "<tr><td colspan='8'>Error loading member statistics: " . $e->getMessage() . "</td></tr>";
110 }
111 ?>
112 </tbody>
113 </table>
114 </div>
115 </div>
116
117 <!-- Book Statistics Section -->
118 <div class="report-section" id="book-stats">
119 <h2>Book Loan Statistics</h2>
120 <div class="table-responsive">
121 <table class="table table-striped table-hover">
122 <thead>
123 <tr>
124 <th>Title</th>
125 <th>Avg Days</th>
126 <th>Min Days</th>
127 <th>Max Days</th>
128 <th>Total Loans</th>
129 <th>Loans with Fines</th>
130 </tr>
131 </thead>
132 <tbody>
133 <?php
134 try {
135 $stmt = $conn->query("SELECT * FROM get_book_loan_stats()");
136 $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
137
138 if(count($results) > 0) {
139 foreach($results as $row) {
140 echo "<tr>
141 <td>{$row['title']}</td>
142 <td class='stat-number'>".number_format($row['avgdaystoreturn'], 1)."</td>
143 <td class='stat-number'>{$row['mindaystoreturn']}</td>
144 <td class='stat-number'>{$row['maxdaystoreturn']}</td>
145 <td class='stat-number'>{$row['totalloans']}</td>
146 <td class='stat-number'>{$row['loanswithfines']}</td>
147 </tr>";
148 }
149 } else {
150 echo "<tr><td colspan='6'>No book statistics found.</td></tr>";
151 }
152 } catch(PDOException $e) {
153 echo "<tr><td colspan='6'>Error loading book statistics: " . $e->getMessage() . "</td></tr>";
154 }
155 ?>
156 </tbody>
157 </table>
158 </div>
159 </div>
160
161 <!-- Genre Trends Section -->
162 <div class="report-section" id="genre-trends">
163 <h2>Genre Trends Analysis - Last 3 Quarters</h2>
164 <div class="table-responsive">
165 <table class="table table-striped table-hover">
166 <thead>
167 <tr>
168 <th>Genre</th>
169 <th>Quarter</th>
170 <th>Loans</th>
171 <th>Average</th>
172 </tr>
173 </thead>
174 <tbody>
175 <?php
176 try {
177 $stmt = $conn->query("SELECT * FROM get_genre_loan_stats()");
178 $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
179
180 if(count($results) > 0) {
181 foreach($results as $row) {
182 $period = new DateTime($row['period']);
183 $formattedPeriod = 'Q' . ceil($period->format('n')/3) . ' ' . $period->format('Y');
184 echo "<tr>
185 <td>{$row['genre']}</td>
186 <td>{$formattedPeriod}</td>
187 <td class='stat-number'>{$row['loancount']}</td>
188 <td class='stat-number'>".number_format($row['movingaverage'], 2)."</td>
189 </tr>";
190 }
191 } else {
192 echo "<tr><td colspan='4'>No genre trends data available for the last 3 quarters.</td></tr>";
193 }
194 } catch(PDOException $e) {
195 echo "<tr><td colspan='4'>Error loading genre trends: " . $e->getMessage() . "</td></tr>";
196 }
197 ?>
198 </tbody>
199 </table>
200 </div>
201 </div>
202 </div>
203
204 <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
205</body>
206</html>
Note: See TracBrowser for help on using the repository browser.