-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.php
157 lines (137 loc) · 5.94 KB
/
edit.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
<?php session_start(); ?>
<?php
if(!isset($_SESSION['valid'])) {
header('Location: login.php');
}
?>
<?php
include_once("connection.php");
if(isset($_POST['update']))
{
$id = $_POST['id'];
$usersId = $_SESSION['id'];
$name = $_POST['name'];
$qty = $_POST['qty'];
$price = $_POST['price'];
$expiration_date = $_POST['expiration_date'];
if(empty($name) || empty($qty) || empty($price)) {
if(empty($name)) {
echo "<font color='red'>El campo Nombre esta vacio.</font><br/>";
}
if(empty($qty)) {
echo "<font color='red'>El campo Cantidad esta vacio</font><br/>";
}
if(empty($price)) {
echo "<font color='red'>El campo Precio esta vacio</font><br/>";
}
if(empty($expiration_date)) {
echo "<font color='red'>El campo Fecha de expiracion esta vacio</font><br/>";
}
} else {
$today = new DateTime();
$today = $today->format('Y-m-d');
$expiration_date = new DateTime($expiration_date);
$expiration_date = $expiration_date->format('Y-m-d');
$soon = new DateTime();
$soon->add(new DateInterval('P8D'));
$soon = $soon->format('Y-m-d');
if($expiration_date < $today ){
$expiration_status = 'expired';
}elseif ($expiration_date <= $soon){
$expiration_status = 'soon-expired';
}else{
$expiration_status = 'not-expired';
}
$result = mysqli_query($mysqli, "UPDATE products SET name='$name', qty='$qty', price='$price', expiration_date='$expiration_date', expiration_status='$expiration_status' WHERE id=$id");
$description = "Se editó el producto: ".$name;
$result2 = mysqli_query($mysqli, "INSERT INTO audit_process_tracking (action, date, user_id, description) VALUES('Update service', CURRENT_TIMESTAMP, '$usersId', '$description')");
header("Location: view.php?search=&search_selector=products.name&order_type=id&order=DESC");
}
}
?>
<?php
$id = $_GET['id'];
$result = mysqli_query($mysqli, "SELECT * FROM products WHERE id=$id");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Editar de productos | Gabriel Peña & Manuel Albarran</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="table-wrapper">
<div class="table-title">
<div class="row">
<div class="col-sm-6">
<h2>Lista de producto</h2>
</div>
<div class="col-sm-6">
<a href="logout.php" class="btn btn-danger">
<i class="material-icons">exit_to_app</i> <span>Salir</span>
</a>
<a href="view.php?search=&search_selector=products.name&order_type=id&order=DESC"
class="btn btn-success">
<i class="material-icons">remove_red_eye</i> <span>Ver productos</span>
</a>
<a href="index.php" class="btn btn-success">
<i class="material-icons">home</i> <span>Inicio</span>
</a>
</div>
</div>
</div>
<form name="form1" method="post" action="edit.php">
<table class="table table-striped table-hover">
<thead>
<tr>
<th id="name_header">Nombre</th>
<th id="qty_header">Cantidad</th>
<th id="price_header">Precio</th>
<th id="expiration_date_header">Fecha de vencimiento</th>
<th id="action_header">Accion</th>
</tr>
</thead>
<tbody>
<?php
while($res = mysqli_fetch_assoc($result)) {
?>
<tr>
<td>
<input type="text" class="form-control" name="name" value="<?php echo $res['name'];?>">
</td>
<td>
<input type="number" class="form-control" name="qty" value="<?php echo $res['qty'];?>">
</td>
<td>
<input type="number" class="form-control" name="price"
value="<?php echo $res['price'];?>">
</td>
<td>
<input type="text" class="form-control" name="expiration_date"
value="<?php echo $res['expiration_date'];?>">
</td>
<td>
<input type="hidden" name="id" value=<?php echo $_GET['id'];?>>
<input type="submit" name="update" value="Guardar" class="btn btn-info">
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</form>
</div>
</div>
</body>
</html>