-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvintages.php
More file actions
463 lines (420 loc) · 22.3 KB
/
Copy pathvintages.php
File metadata and controls
463 lines (420 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
<?php
// Define a constant to protect included files from direct access
define('INCLUDED_VIA_APP', true);
// Include the initialization file (handles sessions and database connection)
require_once __DIR__ . '/includes/init.php';
// Accessible if user has view_tnotes privilege
if (!hasPrivilege($conn, 'view_tnotes')) {
header("Location: login.php?redirect=" . urlencode($_SERVER['REQUEST_URI']));
exit();
}
global $mysqli, $conn;
// Determine view mode
$selected_vintage = null;
$vintage_error = null;
$vintage_summary = null;
if (isset($_GET['vintage']) && trim($_GET['vintage']) !== '') {
$raw_vintage = trim($_GET['vintage']);
$validated_vintage = filter_var($raw_vintage, FILTER_VALIDATE_INT);
if ($validated_vintage === false || $validated_vintage < 1750 || $validated_vintage > 2100) {
$vintage_error = "Invalid vintage year provided: '" . htmlspecialchars($raw_vintage, ENT_QUOTES, 'UTF-8') . "'. Please choose a valid vintage year from the chart.";
} else {
$selected_vintage = $validated_vintage;
$vintage_summary = getVintageSummary($conn, $selected_vintage);
if (!$vintage_summary || (int)$vintage_summary['total_notes'] === 0) {
$vintage_error = "No tasting notes or vintage data found for vintage " . htmlspecialchars((string)$selected_vintage, ENT_QUOTES, 'UTF-8') . ".";
}
}
}
// Set Page Title
if ($selected_vintage && !$vintage_error) {
$page_title = getSiteTitle() . " - Vintage Report " . $selected_vintage;
} else {
$page_title = getSiteTitle() . " - Vintage Chart & Reports";
}
require_once 'includes/header.php';
?>
<div class="row">
<?php if ($selected_vintage && !$vintage_error): ?>
<?php
// Single Vintage Report
$active_scale = getRatingScale();
$max_score = getRatingScaleMax($active_scale);
$threshold = getTopWineScoreThreshold($active_scale);
$region_stats = getVintageRegionStats($conn, $selected_vintage);
$country_stats = getVintageCountryStats($conn, $selected_vintage);
$top_wines = getVintageTopWines($conn, $selected_vintage);
$adjacent = getAdjacentVintages($conn, $selected_vintage);
$all_vintages_list = getAllVintagesSummary($conn);
$avg_display = $vintage_summary['avg_score'] ?? $vintage_summary['avg_dmpts'] ?? null;
$max_display = $vintage_summary['max_score'] ?? $vintage_summary['max_dmpts'] ?? null;
?>
<!-- Top Centre Back Button -->
<div class="vintage-nav-center">
<a href="/vintages.php" class="btn-action" style="padding: 8px 18px; font-size: 14px; display: inline-block;">← Back to all vintages</a>
</div>
<!-- Main Content Area -->
<div class="column main">
<!-- Vintage Header Card -->
<div class="card">
<h3 style="margin-top:0; margin-bottom: 5px;">Vintage report: <?php echo $selected_vintage; ?></h3>
<p style="margin-top:0; color: #64748b;"><small>Detailed analysis of published tasting notes for the <?php echo $selected_vintage; ?> vintage.</small></p>
<div class="vintage-stats-grid">
<div class="vintage-stat-box">
<div class="stat-val"><?php echo '<span title="Total number of tasting notes (including flawed wines and notes without a rating">'.(int)$vintage_summary['total_notes'].'</span>'; ?></div>
<div class="stat-lbl">Tasting Notes</div>
</div>
<div class="vintage-stat-box">
<div class="stat-val"><?php echo ($avg_display !== null) ? $avg_display : '<span title="Not enough tasting notes to calculate an average">n/a</span>'; ?></div>
<div class="stat-lbl">Avg Rating</div>
</div>
<div class="vintage-stat-box">
<div class="stat-val"><?php echo ($max_display !== null) ? $max_display : 'n/a'; ?></div>
<div class="stat-lbl">Top Rating</div>
</div>
<div class="vintage-stat-box">
<div class="stat-val"><?php echo (int)$vintage_summary['country_count']; ?></div>
<div class="stat-lbl">Countries</div>
</div>
<div class="vintage-stat-box">
<div class="stat-val"><?php echo (int)$vintage_summary['region_count']; ?></div>
<div class="stat-lbl">Regions</div>
</div>
</div>
<?php if ($avg_display === null): ?>
<p style="margin-top: 15px; margin-bottom: 0; color: #64748b; font-size: 13px;">
<em>Not enough tasting notes to calculate an average rating (at least 5 <b>rated</b> tasting notes required<?php echo ((int)$vintage_summary['rated_notes_count'] > 0) ? ', currently ' . (int)$vintage_summary['rated_notes_count'] : ''; ?>).</em>
</p>
<?php endif; ?>
</div>
<!-- Regional Averages & Expandable Descriptions -->
<div class="card">
<h3 style="margin-top:0;">Average ratings by country & region</h3>
<p style="margin-top:0; margin-bottom:15px;"><small>Average points (out of <?php echo $max_score; ?>, to one decimal place). Click on an entry to reveal vintage descriptions where available.</small></p>
<?php if (empty($region_stats)): ?>
<p><i>No regional statistics available for this vintage.</i></p>
<?php else: ?>
<?php foreach ($region_stats as $r): ?>
<?php
$label = htmlspecialchars($r['country_region_colour'], ENT_QUOTES, 'UTF-8');
$score_val = $r['avg_score'] ?? $r['avg_dmpts'] ?? null;
$avg = ($score_val !== null) ? number_format((float)$score_val, 1) : 'NR';
$count_label = $r['note_count'] . ' note' . ($r['note_count'] > 1 ? 's' : '');
$has_desc = !empty($r['vintage_desc']);
?>
<div class="vintage-region-item">
<?php if ($has_desc): ?>
<details class="vintage-region-detail">
<summary>
<div>
<strong><?php echo $label; ?></strong>
<small style="color: #64748b; margin-left: 6px;">(<?php echo $count_label; ?>)</small>
<span style="font-size: 11px; color: indianred; margin-left: 6px;">📖 details</span>
</div>
<div class="vintage-score-badge"><?php echo $avg; ?> / <?php echo $max_score; ?></div>
</summary>
<div class="vintage-desc-box">
<?php echo $r['vintage_desc']; ?>
</div>
</details>
<?php else: ?>
<div class="vintage-region-plain">
<div>
<strong><?php echo $label; ?></strong>
<small style="color: #64748b; margin-left: 6px;">(<?php echo $count_label; ?>)</small>
</div>
<div class="vintage-score-badge"><?php echo $avg; ?> / <?php echo $max_score; ?></div>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Top Wines of Vintage -->
<div class="card">
<h3 style="margin-top:0;">Top wines of the <?php echo $selected_vintage; ?> vintage</h3>
<p style="margin-top:0; margin-bottom:15px;"><small>Ranked from best to worst. Showing wines rated <?php echo $threshold; ?> and higher.</small></p>
<?php if (empty($top_wines)): ?>
<p><i>No wines rated <?php echo $threshold; ?> or higher for this vintage.</i></p>
<?php else: ?>
<ul style="list-style-type:none; padding:0; margin:0;">
<?php foreach ($top_wines as $wine): ?>
<?php
// Format wine name
$wine_name = getWineName($wine['nameconvention'] ?? 'vintage_producer_name', $wine['vintage'] ?? 'NV', $wine['name'] ?? '', $wine['producer'] ?? '', $wine['grape'] ?? '', $wine['vineyard'] ?? '');
$score_text = formatNoteRatingBadge($wine, $active_scale, true);
$fav_icon = ($wine['favourite'] === 'yes') ? "<span style='color:#e25555; margin-left:4px;'>❤️</span>" : "";
$t_dt = !empty($wine['tasting_date']) ? date_create($wine['tasting_date']) : false;
$tasted_date = ($t_dt !== false) ? date_format($t_dt, "d M Y") : '';
?>
<li class="vintage-top-wine-card">
<div>
<a href="/tnotes.php?id=<?php echo (int)$wine['note_id']; ?>" style="font-weight: bold;">
<?php echo htmlspecialchars($wine_name, ENT_QUOTES, 'UTF-8'); ?>
</a>
<?php echo $fav_icon; ?>
<div style="font-size: 12px; color: #64748b; margin-top: 3px;">
<?php echo htmlspecialchars($wine['region'] . ', ' . $wine['country'], ENT_QUOTES, 'UTF-8'); ?>
<?php if (!empty($wine['grape'])): ?> • <?php echo htmlspecialchars($wine['grape'], ENT_QUOTES, 'UTF-8'); ?><?php endif; ?>
<?php if (!empty($tasted_date)): ?> • <small>Tasted <?php echo $tasted_date; ?></small><?php endif; ?>
</div>
</div>
<div style="text-align: right; min-width: 90px;">
<span class="vintage-score-badge"><?php echo $score_text; ?></span>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
<!-- Side Column -->
<div class="column side">
<!-- % of Notes per Country -->
<div class="card">
<h3 style="margin-top:0;">Tasting notes by country</h3>
<p style="margin-top:0; margin-bottom:10px;"><small>Distribution of published notes across countries for <?php echo $selected_vintage; ?>.</small></p>
<?php if (empty($country_stats)): ?>
<p><i>No country data available.</i></p>
<?php else: ?>
<table class="vintage-country-table">
<?php foreach ($country_stats as $c): ?>
<tr>
<td style="width: 35%; font-weight: bold;">
<?php echo htmlspecialchars($c['country'], ENT_QUOTES, 'UTF-8'); ?>
</td>
<td style="width: 45%;">
<div class="vintage-bar-wrapper">
<div class="vintage-bar-fill" style="width: <?php echo min(100, max(5, (float)$c['country_percentage'])); ?>%;"></div>
</div>
</td>
<td style="width: 20%; text-align: right; font-size: 12px; color: #475569;">
<strong><?php echo number_format((float)$c['country_percentage'], 1); ?>%</strong>
<br><small style="color: #94a3b8;"><?php echo $c['country_notes_count']; ?> note<?php echo $c['country_notes_count'] > 1 ? 's' : ''; ?></small>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
<!-- Adjacent Vintages Switcher -->
<div class="card">
<h3 style="margin-top:0;">Switch vintage</h3>
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 15px;">
<?php if (!empty($adjacent['prev_vintage'])): ?>
<a class="filter-nav" href="/vintages.php?vintage=<?php echo (int)$adjacent['prev_vintage']; ?>">← <?php echo (int)$adjacent['prev_vintage']; ?></a>
<?php else: ?>
<span style="color:#94a3b8; font-size:small;">← Older</span>
<?php endif; ?>
<span style="font-weight:bold; font-size: 16px;"><?php echo $selected_vintage; ?></span>
<?php if (!empty($adjacent['next_vintage'])): ?>
<a class="filter-nav" href="/vintages.php?vintage=<?php echo (int)$adjacent['next_vintage']; ?>"><?php echo (int)$adjacent['next_vintage']; ?> →</a>
<?php else: ?>
<span style="color:#94a3b8; font-size:small;">Newer →</span>
<?php endif; ?>
</div>
<div style="margin-top: 10px;">
<label for="vintageSelect" style="font-size: small; display:block; margin-bottom: 5px;">Jump to vintage:</label>
<select id="vintageSelect" onchange="if(this.value) window.location.href='/vintages.php?vintage=' + this.value;" style="width: 100%; padding: 5px; font-family: Georgia, serif;">
<option value="">-- Select a vintage --</option>
<?php foreach ($all_vintages_list as $v_item): ?>
<?php $v_item_avg = $v_item['avg_score'] ?? $v_item['avg_dmpts'] ?? null; ?>
<option value="<?php echo (int)$v_item['vintage']; ?>" <?php echo ((int)$v_item['vintage'] === $selected_vintage) ? 'selected' : ''; ?>>
<?php echo (int)$v_item['vintage']; ?> (<?php echo $v_item['note_count']; ?> note<?php echo (int)$v_item['note_count'] === 1 ? '' : 's'; ?><?php echo ($v_item_avg !== null) ? ', avg ' . $v_item_avg : ', avg n/a'; ?>)
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Rating Scale Info -->
<div class="card">
<h3 style="margin-top:0;">My rating scale</h3>
<?php if ($active_scale === '100-point'): ?>
<p style="font-size: small; line-height: 1.4;">
Wines are evaluated using the 100-point scale:
</p>
<ul style="font-size: small; padding-left: 18px; margin: 0;">
<li><b>98-100</b>: extraordinary / classic</li>
<li><b>95-97</b>: extraordinary</li>
<li><b>90-94</b>: outstanding</li>
<li><b>85-89</b>: very good</li>
<li><b>80-84</b>: good</li>
<li><b>75-79</b>: acceptable / mediocre</li>
<li><b>70-74</b>: below average</li>
<li><b>< 70</b>: poor / faulty</li>
</ul>
<?php else: ?>
<p style="font-size: small; line-height: 1.4;">
Wines are evaluated using the 20-point scale:
</p>
<ul style="font-size: small; padding-left: 18px; margin: 0;">
<li><b>20</b>: one-of-a-kind</li>
<li><b>17-19</b>: grand vin</li>
<li><b>13-16</b>: excellent</li>
<li><b>9-12</b>: very good</li>
<li><b>5-8</b>: good</li>
<li><b>3-4</b>: passable</li>
<li><b>1-2</b>: subpar</li>
<li><b>0</b>: poor</li>
</ul>
<?php endif; ?>
<p style="margin-top:10px;"><small><a href="/blog.php">Explore tasting notes & stories →</a></small></p>
</div>
</div>
<!-- Bottom Centre Back Button -->
<div class="vintage-nav-center bottom">
<a href="/vintages.php" class="btn-action" style="padding: 8px 18px; font-size: 14px; display: inline-block;">← Back to all vintages</a>
</div>
<?php elseif ($vintage_error): ?>
<!-- Error State for Invalid Vintage -->
<div class="column main" style="width: 100%;">
<div class="vintage-nav-center">
<a href="/vintages.php" class="btn-action" style="padding: 8px 18px; font-size: 14px; display: inline-block;">← Back to all vintages</a>
</div>
<div class="card" style="text-align:center; padding: 40px 20px;">
<h3 style="color: darkred; margin-top:0;">Vintage Not Found</h3>
<p><?php echo htmlspecialchars($vintage_error, ENT_QUOTES, 'UTF-8'); ?></p>
<p><small>Please select an available vintage from the chart overview.</small></p>
<div style="margin-top: 20px;">
<a href="/vintages.php" class="btn-action" style="padding: 8px 18px; font-size: 14px; display: inline-block;">View Vintage Chart</a>
</div>
</div>
<div class="vintage-nav-center bottom">
<a href="/vintages.php" class="btn-action" style="padding: 8px 18px; font-size: 14px; display: inline-block;">← Back to all vintages</a>
</div>
</div>
<?php else: ?>
<?php
// All Vintages Chart Overview
$active_scale = getRatingScale();
$max_score = getRatingScaleMax($active_scale);
$all_vintages = getAllVintagesSummary($conn);
// Group vintages by decade
$decades = [];
$total_all_notes = 0;
$weighted_score_sum = 0;
$weighted_notes_count = 0;
$highest_vintage = null;
$highest_vintage_score = 0;
foreach ($all_vintages as $v_data) {
$v_num = (int)$v_data['vintage'];
$n_count = (int)$v_data['note_count'];
$total_all_notes += $n_count;
$v_score_val = $v_data['avg_score'] ?? $v_data['avg_dmpts'] ?? null;
if ($v_score_val !== null) {
$avg_val = (float)$v_score_val;
$weighted_score_sum += ($avg_val * $n_count);
$weighted_notes_count += $n_count;
if ($avg_val > $highest_vintage_score && $n_count >= 5) {
$highest_vintage_score = $avg_val;
$highest_vintage = $v_num;
}
}
$decade_key = floor($v_num / 10) * 10;
if ($decade_key >= 1970) {
$decade_label = $decade_key . "s";
} else {
$decade_label = "1960s & Older";
$decade_key = 1960;
}
if (!isset($decades[$decade_label])) {
$decades[$decade_label] = [];
}
$decades[$decade_label][] = $v_data;
}
$overall_avg = ($weighted_notes_count > 0) ? round($weighted_score_sum / $weighted_notes_count, 1) : null;
?>
<!-- Main Column: Vintage Chart -->
<div class="column main">
<div class="card">
<h3 style="margin-top:0; margin-bottom:5px;">Vintage chart & reports</h3>
<p style="margin-top:0; color:#475569;"><small>Explore wines by vintage year. Click any vintage to view regional performance, top rated wines, and country breakdowns.</small></p>
</div>
<?php if (empty($all_vintages)): ?>
<div class="card" style="text-align:center; padding:30px;">
<p>No published tasting notes with vintage information are available yet.</p>
</div>
<?php else: ?>
<div class="card">
<?php foreach ($decades as $decade_title => $vintages_in_decade): ?>
<div class="vintage-grid-decade">
<div class="vintage-decade-heading"><?php echo htmlspecialchars($decade_title, ENT_QUOTES, 'UTF-8'); ?></div>
<div class="vintage-chart-grid">
<?php foreach ($vintages_in_decade as $v): ?>
<?php
$v_year = (int)$v['vintage'];
$v_count = (int)$v['note_count'];
$v_score_val = $v['avg_score'] ?? $v['avg_dmpts'] ?? null;
$v_avg = ($v_score_val !== null) ? number_format((float)$v_score_val, 1) : null;
?>
<!-- Link to vintages.php?vintage=NNNN -->
<a href="/vintages.php?vintage=<?php echo $v_year; ?>" class="vintage-tile" title="<?php echo ($v_avg !== null) ? 'View ' . $v_year . ' vintage report (avg ' . $v_avg . ')' : 'View ' . $v_year . ' vintage report (not enough tasting notes to calculate an average)'; ?>">
<span class="vintage-year"><?php echo $v_year; ?></span>
<span class="vintage-meta">
<small><?php echo $v_count; ?> note<?php echo $v_count > 1 ? 's' : ''; ?></small>
<?php if ($v_avg !== null): ?>
<span class="vintage-score-pill"><?php echo $v_avg; ?></span>
<?php else: ?>
<span class="vintage-score-pill vintage-score-pill-na" title="Not enough tasting notes to calculate an average">n/a</span>
<?php endif; ?>
</span>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- Side Column: Summary & Quick Search -->
<div class="column side">
<div class="card">
<h3 style="margin-top:0;">Overview</h3>
<p>This vintage chart compiles tasting notes from my personal notebook across all recorded vintages.</p>
<div class="vintage-stats-grid">
<div class="vintage-stat-box">
<div class="stat-val"><?php echo count($all_vintages); ?></div>
<div class="stat-lbl">Vintages</div>
</div>
<div class="vintage-stat-box">
<div class="stat-val"><?php echo $total_all_notes; ?></div>
<div class="stat-lbl">Total Notes</div>
</div>
<div class="vintage-stat-box">
<div class="stat-val"><?php echo ($overall_avg !== null) ? $overall_avg : 'n/a'; ?></div>
<div class="stat-lbl">Overall Avg</div>
</div>
</div>
<?php if ($highest_vintage): ?>
<p style="font-size:small; margin-top:15px;">
Top performing vintage (min. 5 notes): <a href="/vintages.php?vintage=<?php echo $highest_vintage; ?>"><b><?php echo $highest_vintage; ?></b></a> (avg <?php echo number_format($highest_vintage_score, 1); ?> / <?php echo $max_score; ?>).
</p>
<?php endif; ?>
</div>
<div class="card">
<h3 style="margin-top:0;">Direct vintage lookup</h3>
<p style="font-size:small;">Select a vintage to jump directly to its report:</p>
<select onchange="if(this.value) window.location.href='/vintages.php?vintage=' + this.value;" style="width: 100%; padding: 6px; font-family: Georgia, serif;">
<option value="">-- Choose a vintage --</option>
<?php foreach ($all_vintages as $v_item): ?>
<?php $v_item_avg = $v_item['avg_score'] ?? $v_item['avg_dmpts'] ?? null; ?>
<option value="<?php echo (int)$v_item['vintage']; ?>">
<?php echo (int)$v_item['vintage']; ?> (<?php echo $v_item['note_count']; ?> note<?php echo (int)$v_item['note_count'] === 1 ? '' : 's'; ?><?php echo ($v_item_avg !== null) ? ', avg ' . $v_item_avg : ', avg n/a'; ?>)
</option>
<?php endforeach; ?>
</select>
</div>
<div class="card">
<aside>
<?php
echo getStaticPageContent(
'vintages_sidebar',
'<h3 style="margin-top:0;">About vintage reports</h3><p style="font-size:small; line-height:1.4;">Vintage scores reflect my personal tasting notes on the wines reviewed. They are updated dynamically as new tasting notes are posted.</p><p style="font-size:small;"><a href="/tnotes.php">Browse all tasting notes →</a></p>'
);
?>
</aside>
</div>
</div>
<?php endif; ?>
</div>
<?php require_once 'includes/footer.php'; ?>