-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducers.php
More file actions
140 lines (126 loc) · 4.93 KB
/
Copy pathproducers.php
File metadata and controls
140 lines (126 loc) · 4.93 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
<?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';
// Check if a producer ID parameter is provided; if not, redirect to wines.php?sort=producer
if (!isset($_GET['id']) || trim($_GET['id']) === '') {
header("Location: /wines.php?sort=producer");
exit;
}
// Get producer ID
$producerID = $_GET['id'];
// Fetch the producer and ensure it exists before proceeding
getProducer($producerID);
if (empty($producer)) {
header("Location: /wines.php?sort=producer");
exit;
}
// Associated producer data for richer SEO keywords & schema
$associated_data = getProducerAssociatedData($conn, $producerID);
// Page title and SEO metadata
$page_title = getSiteTitle() . " - " . $producer["producer"];
$meta_keywords = generateProducerKeywords($producer, $associated_data);
$meta_desc = generateProducerDescription($producer);
$canonical_url = getAbsoluteUrl('/producers.php?id=' . $producerID);
$og_type = 'profile';
$json_ld = generateProducerJsonLd($producer, $canonical_url);
require_once 'includes/header.php';
?>
<div class="row">
<div class="column main">
<div class="card">
<h3><?php echo $producer["producer"];?></h3>
</div>
<div class="card">
<section>
<h3>Description</h3>
<p>Based in <?php echo $producer["region"].", ".$producer["country"]."."; ?></p>
<?php
if($producer["producer_desc"]!=null) {
echo $producer["producer_desc"];
}
?>
</section>
</div>
<div class="card">
<h3>Wines I've tasted</h3>
<p>
<ul style="list-style-type:none;padding:0;margin:0;">
<?php
if (hasPrivilege($conn, 'view_tnotes')) {
latestNotes($producer["producer_id"]);
} else {
echo "<p>Please <a href='/login.php?redirect=" . urlencode($_SERVER['REQUEST_URI']) . "'>log in</a> to see my tasting notes.</p>";
}
?>
</ul>
</p>
</div>
</div>
<div class="column side">
<div class="card">
<h3>Address</h3>
<address>
<p>
<?php
if($producer["address"]!=null) {
echo $producer["address"];
} else {
echo "Not available.";
}
?>
</p>
</address>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>
<?php function getProducer($producerID)
{
global $mysqli, $conn;
// Perform query
$stmt = $mysqli->prepare("select * from producers
left join regions on producers.region_id=regions.region_id
where producer_id=?");
$stmt->bind_param("i", $producerID);
$stmt->execute();
$result = $stmt->get_result();
if ($result)
{
$GLOBALS['producer'] = $result -> fetch_assoc();
// Free result set
$result -> free_result();
}
$stmt->close();
} ?>
<?php function latestNotes($id)
{
global $mysqli, $conn;
// Perform query
$stmt = $mysqli->prepare("select * from tnotes
left join users on tnotes.user_id=users.user_id
left join wines on tnotes.wine_id=wines.wine_id
left join wines_master on wines.master_id=wines_master.master_id
left join producers on wines_master.producer_id=producers.producer_id
left join vineyards on wines_master.vineyard_id=vineyards.vineyard_id
left join regions on wines_master.region_id=regions.region_id
left join countries on regions.country=countries.country
left join subregions on wines_master.subregion_id=subregions.subregion_id
left join appellations on wines_master.appellation_id=appellations.appellation_id
where status='published' and producers.producer_id=?
order by tasting_date desc, note_id desc");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$scale = getRatingScale();
while ($tasting_note = $result->fetch_assoc()) {
$wine_name = getWineName($tasting_note["nameconvention"], $tasting_note["vintage"], $tasting_note["name"], $tasting_note["producer"], $tasting_note["grape"], $tasting_note["vineyard"]);
$rating_badge = formatNoteRatingBadge($tasting_note, $scale, true);
// Output
echo "<li>".date_format(date_create($tasting_note["tasting_date"]),"d M Y").": <a href='/tnotes.php?id=".$tasting_note['note_id']."'>".$wine_name."</a> (".$rating_badge.")</li>";
}
if (mysqli_num_rows($result)==0) { echo "<li>I haven't tasted any of this producer's wines, yet.</li>"; }
$stmt->close();
$result -> free_result();
} ?>