-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
389 lines (346 loc) · 17.1 KB
/
index.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
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
<?php
require 'BackEnd/conecta.php';
session_start();
$isLoggedIn = isset($_SESSION['username']);
if($isLoggedIn){
$con = conecta();
$usuario = $_SESSION['username'];
$sql = "SELECT * FROM pedidos WHERE status = 1 AND client_id = '$usuario'";
$res = $con->query($sql);
$numFilas = 0;
$total = 0;
$numFilas=$res->num_rows;
}else{
$numFilas = 0;
$total = 0;
}
if ($isLoggedIn && isset($_POST['logout'])) {
session_destroy();
header('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FlipArt</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/flatly/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap">
<style>
body {
font-family: 'Ubuntu', sans-serif;
}
</style>
<link rel="stylesheet" href="Styles/footer.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="index.php">FlipART</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="products.php">Productos</a>
</li>
<?php
if ($isLoggedIn) {
$con = conecta();
$usuario = $_SESSION['username'];
$sql = "SELECT * FROM pedidos WHERE status = 1 AND client_id = '$usuario'";
$res = $con->query($sql);
echo '
<li class="nav-item">
<a class="nav-link" href="#" data-toggle="modal" data-target="#cartModal">
<i class="fas fa-shopping-cart"></i> Carrito
<span class="badge badge-pill badge-danger">';echo $res->num_rows; echo '</span>
</a>
</li>
';
}
else{
echo '
<li class="nav-item">
<a class="nav-link" href="#" data-toggle="modal" data-target="#cartModal">
<i class="fas fa-shopping-cart"></i> Carrito
<span class="badge badge-pill badge-danger"> 0 </span>
</a>
</li>
';
}
?>
<li class="nav-item">
<a class="nav-link" href="contact.php">Contactanos</a>
</li>
<?php
if ($isLoggedIn) {
echo '<li class="nav-item"><a class="nav-link" href="profile.php">' . $_SESSION['username'] . '</a></li>';
echo '<form method="post" class="nav-item"><button type="submit" name="logout" class="btn btn-link nav-link">Logout</button></form>';
} else {
echo '<li class="nav-item"><a class="nav-link" href="login.php">Login/Sign-up</a></li>';
}
?>
</ul>
</div>
</nav>
<div class="container my-5">
<h1>BIENVENIDO A FlipArt</h1>
<br>
<h3>LA TIENDA ONLINE #1 DE IMPRESION 3D</h3>
<br>
<div id="carouselExample" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src='imgs/4.png' class="d-block w-100" alt="Card image" style="width: 100%;height: 100% ; max-width: 1000px;max-height: 475px;object-fit: fill;">
<div class="carousel-caption d-none d-md-block">
<h5>OFERTA</h5>
<p>PRODUCTO ON SALE</p>
</div>
</div>
<div class="carousel-item">
<img src='imgs/1.jpg' class="d-block w-100" alt="Card image" style="width: 100%;height: 100% ; max-width: 1000px;max-height: 475px;object-fit: fill;">
<div class="carousel-caption d-none d-md-block">
</div>
</div> <div class="carousel-item">
<img src='imgs/3.jpg' class="d-block w-100" alt="Card image" style="width: 100%;height: 100% ; max-width: 1000px;max-height: 475px;object-fit: fill;">
<div class="carousel-caption d-none d-md-block">
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExample" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExample" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<br>
<h3></h3>
</div>
<div class="container my-5">
<h1>Productos en PROMOCION</h1>
<br>
<p>Envios gratis a todo mexico!</p>
<div class="row">
<?php
$con = conecta();
$sql = "SELECT * FROM Offers
WHERE status = 1 AND deleted = 0";
$res = $con->query($sql);
while ($row = $res->fetch_array()) {
$id = $row["id"];
$productName = $row["product_name"];
$productCode = $row["product_code"];
$productDescription = $row["product_description"];
$productCost = $row["product_cost"];
$productStock = $row["product_stock"];
$file = $row["archivo"];
$finalFile = substr($file, 3);
?>
<div class="card" style="width: 18rem; margin: 1%" >
<img class="card-img-top" src="<?php echo $finalFile?>" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><?php echo $productName ?></h5>
<p class="card-text"><?php echo $productDescription?></p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item"><strong>Precio:</strong> $<?php echo $productCost?>.00</li>
<li class="list-group-item"> <strong>Disponibilidad:</strong> <?php echo $productStock?></li>
<li class="list-group-item"> <strong>Codigo:</strong> <?php echo $productCode?></li>
</ul>
<div class="card-body">
<label for="botonespia_<?php echo $id; ?>" class="labelfor"><a class="card-link">Agregar al Carrito!</a></label>
<button onclick="addToCard('<?php echo $id; ?>')" class="hidebotton" id="botonespia_<?php echo $id; ?>"></button>
<div class="form-group">
<select class="form-control" id="cantidad_<?php echo $id; ?>">
<?php for($i = 1 ; $i <= $productStock ; $i++){ ?>
<option><?php echo $i;?> Unidad</option>
<?php } ?>
</select>
</div>
</div>
</div>
<?php }?>
</div>
</div>
<div class="modal fade" id="cartModal" tabindex="-1" role="dialog" aria-labelledby="cartModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="cartModalLabel">Carrito de Compras</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php
if($isLoggedIn){
$con = conecta();
$usuario = $_SESSION['username'];
$sql = "SELECT * FROM pedidos WHERE status = 1 AND client_id = '$usuario'";
$res = $con->query($sql);
$total = 0;
$numFilas=$res->num_rows;
if ($numFilas=='0'){
echo'
<div class="modal-body">
<div class="media">
<div class="media-body">
<h5 class="mt-0">Acualmente no tienes productos en el carrito</h5>
<div id="productDescription">Empieza a agregar productos aqui <strong>HOY MISMO</strong>!</div>
</div>
</div>
<hr>
</div>
';
}else{
while($row = $res->fetch_array()) {
$userOrderId = $row["id"];
$productoQuery = "SELECT * FROM items_orders WHERE order_id = '$userOrderId'";
$productoANS = $con->query($productoQuery);
while($productrow = $productoANS->fetch_array()) {
$invoiceNumber = $productrow['id'];
$productID = $productrow['product_id'];
$productAmount = $productrow['amount'];
$productPrice = $productrow['price'];
//Obten Detalles del Producto
$tablaDeProductos = "SELECT * FROM Products WHERE id = '$productID' AND deleted = 0";
$tablaDeProductosANS = $con->query($tablaDeProductos);
while($tablaDeProductosROW = $tablaDeProductosANS->fetch_array()) {
$itemName = $tablaDeProductosROW['product_name'];
$itemCode = $tablaDeProductosROW['product_code'];
$itemDescr = $tablaDeProductosROW['product_description'];
$itemStock = $tablaDeProductosROW['product_stock'];
$file = $tablaDeProductosROW["archivo"];
$finalFile = substr($file, 3);
$total += ($productPrice * $productAmount);
echo '
<div class="modal-body">
<div class="media">
<img src="';echo $finalFile; echo '" style="max-width: 64px;height: 64px;object-fit: cover;" class="mr-3" alt="Producto">
<div class="media-body">
<h5 class="mt-0">';echo $itemName; echo '</h5>
<div id="productDescription">';echo $itemDescr; echo'</div>
<div id="productPrice"><strong>Precio:</strong> $';echo $productPrice;echo '.00 Unidad</div>
<div class="input-group mt-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary " type="button" id="subtractQuantity">-</button>
</div>
<input type="text" class="form-control text-center" value=" ';echo $productAmount;echo ' " id="quantity" readonly>
<div class="input-group-append">
<button class="btn btn-outline-secondary " type="button" id="addQuantity">+</button>
</div>
</div>
<label for="botoneliminar" style="cursor: grab">Eliminar producto</label>
<button id="botoneliminar" class="botoneliminar" style="display: none ; " onclick="deleteThisproduct(';echo $userOrderId;echo ' )"></button>
</div>
</div>
<hr>
</div>
';}}}} }
else{
echo '
<div class="modal-body">
<div class="media">
<div class="media-body">
<h5 class="mt-0"><strong>Deberas Iniciar Sesion para continuar</strong></h5>
<div id="productDescription">Si no te registras hermano o te loggeas no puedes hacer pedidos</div>
<div id="productPrice"><strong>Precio:</strong> $00.00 Unidad</div>
<div class="input-group mt-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary subtractQuantity" type="button" id="subtractQuantity">-</button>
</div>
<input type="text" class="form-control text-center" value="0" id="quantity" readonly>
<div class="input-group-append">
<button class="btn btn-outline-secondary addQuantity" type="button" id="addQuantity">+</button>
</div>
</div>
</div>
</div>
<hr>
</div>';
}
?>
<div>
<strong>Total:</strong>
<span id="totalPrice">$<?php if($isLoggedIn) echo $total; else echo 00?>.00</span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
<button type="button" class="btn btn-primary" onclick="sale();return false">Realizar Compra</button>
</div>
</div>
</div>
</div>
<footer class="bg-dark text-white text-center py-3">
<div class="container">
<p>© 2023 FlipArt Todos los derechos reservados.</p>
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="Js/carrito.js"></script>
<script src="Js/logIn.js"></script>
<script>
function sale(){
if(<?php echo $numFilas?> != 0){
window.location.href='pago.php';
}
}
$(document).ready(function() {
$("#addQuantity").click(function() {
var currentQuantity = parseInt($("#quantity").val());
$("#quantity").val(currentQuantity + 1);
});
$("#subtractQuantity").click(function() {
var currentQuantity = parseInt($("#quantity").val());
if (currentQuantity > 1) {
$("#quantity").val(currentQuantity - 1);
}
});
});
function changeInfo() {
var name = $('#fullname').val();
var email = $('#email').val();
var phone = $('#phone').val();
if (name == '' || email == "" || phone == "") {
$('#emailWrong').show();
$('#emailWrong').html('Faltan Campos por llenar.');
setTimeout("$('#emailWrong').hide(); $('#emailWrong').html('')", 5000);
} else {
$.ajax({
url: "UpdateInfo.php",
type: "POST",
data: 'name=' + name + '&email=' + email + "&phone=" + phone,
success: function (res) {
location.reload();
},
error: function () {
alert('Archivo no encontrado.');
}
});
}
}
function deleteThisproduct(order){
$.ajax({
url:"deleteProductCar.php",
type:"POST",
data:'order='+order,
success:function (res){
console.log(res);
location.reload();
},
error:function (){
alert('Archivo no encontrado.');
}
});
}
</script>
</body>
</html>