-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
55 lines (43 loc) · 1.48 KB
/
add.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
<?php session_start(); ?>
<?php
if(!isset($_SESSION['valid'])) {
header('Location: login.php');
}
?>
<html>
<head>
<title>Agregar un producto | Gabriel Peña & Manuel Albarran</title>
</head>
<body>
<?php
include_once("connection.php");
if(isset($_POST['Submit'])) {
$name = $_POST['name'];
$qty = $_POST['qty'];
$price = $_POST['price'];
$expiration_date = $_POST['expiration_date'];
$usersId = $_SESSION['id'];
$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, "INSERT INTO products (name, qty, price, expiration_date, expiration_status, users_id)
VALUES('$name','$qty','$price', '$expiration_date', '$expiration_status', '$usersId')");
$description = "Se agregó el producto: ".$name;
$result2 = mysqli_query($mysqli, "INSERT INTO audit_process_tracking (action, date, user_id, description)
VALUES('Add service', CURRENT_TIMESTAMP, '$usersId', '$description')");
header('Location: view.php?search=&search_selector=products.name&order_type=id&order=DESC');
}
?>
</body>
</html>