-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profile.php
327 lines (297 loc) · 13.7 KB
/
Profile.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
<?php
require "BackEnd/conecta.php";
$con = conecta();
session_start();
$currentUsername = $_SESSION['username'];
$isLoggedIn = isset($_SESSION['username']);
$fullName = '';
$email = '';
$phoneNumber = '';
$birthday = '';
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">
<link rel="stylesheet" href="Styles/footer.css">
<style>
body {
font-family: 'Ubuntu', sans-serif;
}
</style>
<link rel="stylesheet" href="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>
<?php
$User = "SELECT * FROM Users WHERE userName = '$currentUsername' AND status = 1 AND deleted = 0";
$res = $con->query($User);
while($row = $res->fetch_array()) {
$fullName = $row['fullName'];
$email = $row['email'];
$phoneNumber = $row['phone'];
$birthday = $row['birthday'];
?>
<div class="container mt-5">
<div class="row">
<div class="col-md-4">
<!-- Foto de perfil con clase rounded para bordes redondeados -->
<img src="imgs/alexis.jpeg" alt="Foto de perfil" class="img-fluid rounded">
</div>
<div class="col-md-8">
<!-- Formulario de edición del perfil -->
<h2 class="mb-4">Perfil de <?php echo $currentUsername; ?></h2>
<form method="post">
<div class="form-group">
<label for="fullname">Nombre completo:</label>
<input type="text" class="form-control" id="fullname" name="fullname" value="<?php echo $fullName; ?>" >
</div>
<div class="form-group">
<label for="email">Correo:</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo $email; ?>" >
</div>
<div class="form-group">
<label for="phone">Teléfono:</label>
<input type="tel" class="form-control" id="phone" name="phone" value="<?php echo $phoneNumber; ?>" >
</div>
<div class="alert alert-dismissible alert-danger emailWrong" id="emailWrong" style="display: none"></div>
<button type="submit" name="edit_profile" onclick="changeInfo();return false;" class="btn btn-primary">Editar Perfil</button>
</form>
</div>
</div>
</div>
<?php }?>
<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>