-
Notifications
You must be signed in to change notification settings - Fork 0
/
item-details.php
130 lines (124 loc) · 4.7 KB
/
item-details.php
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style_itemdetails.css">
<title>AutoIUT - Détails du véhicule</title>
</head>
<body id="vehicle-detail-page">
<div class="vehicle-details-container">
<?php
include 'config/db_connector.php';
include 'basket-function.php';
if (isset($_GET['id'])) {
$vehicle_id = $_GET['id'];
$query = "SELECT * FROM items WHERE id = $vehicle_id";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$directory = "data/ads_imgs/" . $row['id'];
$images = is_dir($directory) ? glob($directory . "/*.{jpg,jpeg,png,gif}", GLOB_BRACE) : [];
echo "<div class='vehicle-card'>";
if (!empty($images)) {
echo "<img src='" . $images[0] . "' class='main-image' id='displayedImage'>";
echo "<button class='navigation-button prev' onclick='changeImage(-1)'>❮</button>";
echo "<button class='navigation-button next' onclick='changeImage(1)'>❯</button>";
echo "<div class='thumbnails'>";
foreach ($images as $index => $image) {
echo "<img src='" . $image . "' class='thumbnail" . ($index == 0 ? " active" : "") . "' onclick='setActiveImage($index)'>";
}
echo "</div>";
}
echo "<div class='vehicle-details'>";
echo "<div class='make-model'>" . $row['make'] . " " . $row['model'] . "</div>";
echo "<div class='price'>" . $row['price'] . "€</div>";
echo "<div class='date-mileage'>" . $row['year'] . " - " . $row['mileage'] . " km</div>";
echo "<div class='description'>" . $row['description'] . "</div>";
echo "<div class='condition'>Etat: ";
$condition = intval($row['condition']);
switch ($condition) {
case 1:
echo "Très mauvais état";
break;
case 2:
echo "Mauvais état";
break;
case 3:
echo "Etat moyen";
break;
case 4:
echo "Bon état";
break;
case 5:
echo "Très bon état";
break;
default:
echo "Inconnu";
break;
}
echo "<br>";
echo "</div>";
echo "<div class='energy'>Energie: ";
$energy = intval($row['energy']);
switch ($energy) {
case 1:
echo "Diesel";
break;
case 2:
echo "Essence";
break;
case 3:
echo "Electrique";
break;
case 4:
echo "Gaz";
break;
case 5:
echo "Ethanol";
break;
default:
echo "Inconnu";
break;
}
echo "</div>";
echo "</div>";
echo "<form method='post' action='https://projetr209.nekocorp.fr/index.php?page=basket'>";
echo "<input type='hidden' name='itemID' value='" . $row['id'] . "'>";
echo "<input type='submit' name='addItem' value='Ajouter au panier'>";
echo "</div>";
echo "</div>";
} else {
echo "<p>Aucun véhicule trouvé avec l'ID spécifié.</p>";
}
} else {
echo "<p>L'ID du véhicule n'est pas spécifié dans l'URL.</p>";
}
mysqli_close($conn);
?>
</div>
<script>
var images = <?php echo json_encode($images); ?>;
var currentIndex = 0;
function changeImage(direction) {
currentIndex += direction;
if (currentIndex >= images.length) {
currentIndex = 0;
} else if (currentIndex < 0) {
currentIndex = images.length - 1;
}
setActiveImage(currentIndex);
}
function setActiveImage(index) {
currentIndex = index;
document.getElementById('displayedImage').src = images[currentIndex];
document.querySelectorAll('.thumbnail').forEach((thumb, idx) => {
if (idx === currentIndex) {
thumb.classList.add('active');
} else {
thumb.classList.remove('active');
}
});
}
</script>
</body>
</html>