-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstpage.php
186 lines (168 loc) · 7.79 KB
/
firstpage.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
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Sensidia";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed ".$conn->connect_error);
} else {
echo "";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sensidia - The Best shop You Ever had </title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,600;1,100;1,400;1,500;1,600&display=swap" rel="stylesheet">
<link rel="stylesheet"href="./src/index.css">
</head>
<body>
<header>
<h1>Sensidia - The Hottest Products on Sale!</h1>
</header>
<main>
<section>
<div class = "buttons">
<h2>
Product List
</h2>
<a href="./Addproduct.php">
<button id="#add-product-btn">
Add
</button>
</a>
<button id="delete-product-btn" type="submit">
Mass Delete
</button>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
window.onload = function() {
const deleteBtn = document.getElementById('delete-product-btn');
deleteBtn.addEventListener('click', function() {
var checkboxes = document.getElementsByName("product[]");
var selectedProducts = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
selectedProducts.push(checkboxes[i].value);
}
}
if (selectedProducts.length === 0) {
alert("Please select at least one product to delete.");
return;
}
if (confirm("Are you sure you want to delete the selected products?")) {
var form = document.createElement("form");
form.method = "POST";
form.action = "./src/mass_delete.php";
for (var i = 0; i < selectedProducts.length; i++) {
var input = document.createElement("input");
input.type = "hidden";
input.name = "product[]";
input.value = selectedProducts[i];
form.appendChild(input);
}
document.body.appendChild(form);
fetch('./src/mass_delete.php', {
method: 'POST',
body:new FormData(form)
})
.then(response => response.json())
.then(data => {
alert(data.message);
if (data.sucess) {
location.reload();
}
location.reload()
})
.catch(error => {
location.reload();
})
}
});
};
</script>
</div>
<div class="ProductsList" id="ProductsList">
<!--Where the products will be shown-->
<?php
$sql = "SELECT
products.id,
products.product_type,
products.image,
products.name,
products.description,
products.price,
products.SKU,
book.weight,
dvd.size,
dimensions.height,
dimensions.width,
dimensions.length
FROM products
LEFT JOIN dvd ON products.id = dvd.product_id
LEFT JOIN furniture ON products.id = furniture.product_id
LEFT JOIN dimensions ON furniture.id = dimensions.furniture_id
LEFT JOIN book ON products.id = book.product_id";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) {
while ($row = $result ->fetch_assoc()) {
$productId = $row['id'];
echo '<div class= "product">';
echo '<img src="'. $row["image"]. '"alt ="'.$row["name"] .'"><br>';
echo "<label><input type='checkbox' name='product[]' value='$productId'></label>";
echo "SKU: ".$row["SKU"]."<br>";
echo "<h3 class= 'ProductName'> ". $row["name"] . "</h3><br>";
echo "<p class = 'price'>$" . $row["price"] . "</p><br>";
echo "<div class= 'statsProducts'>";
if (!empty($row["weight"])) {
echo "<p>Weight: ".$row["weight"]."g</p>";
}if ($row["product_type"] === "dvd" && isset($row["size"])) {
echo "<p>Size: ".$row["size"]."MB</p>";
}if (!empty($row["height"]) && !empty($row["width"]) && !empty($row["length"])) {
echo "<p>Dimensions: ".$row["height"]."x".$row["width"]."x".$row["length"]."</p>";
}if (empty($row["weight"]) && empty($row["length"]) && empty($row["height"]) && empty($row["width"]) && empty($row["size"])) {
echo "<p>Information not available</p>";
}
echo "</div>";
echo '</div>';
}
} else {
echo "0 results";
}
$conn->close();
?>
</div>
</section>
</main>
<footer id="footer">
<p>© 2023 - Scandiweb Test Assigment</p>
<script>
var footer = document.getElementById('footer');
var lastScrollPosition = 0;
window.addEventListener('scroll', function() {
var currentScrollPosition = window.scrollY || document.documentElement.scrollTop;
if (currentScrollPosition > lastScrollPosition) {
// Scroll para baixo
if (currentScrollPosition + window.innerHeight >= document.documentElement.scrollHeight) {
// Chegou ao final da página, mostra o footer
footer.style.bottom = '0';
}
} else {
// Scroll para cima
if (currentScrollPosition + window.innerHeight < document.documentElement.scrollHeight - footer.clientHeight) {
// Ainda não chegou ao final da página, esconde o footer
footer.style.bottom = '-100px';
}
}
lastScrollPosition = currentScrollPosition;
});
</script>
</footer>
</body>
</html>