-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_edit.php
166 lines (132 loc) · 7.38 KB
/
product_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
158
159
160
161
162
163
164
165
166
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<title>Modifica Prodotto:</title>
</head>
<body>
<div class="container mt-5">
<?php
include('config/db.php');
if (isset($_POST['update']) && $_SERVER['REQUEST_METHOD'] == "POST") {
/*//Magazzino (Prodotti)
create table products(
ID INT PRIMARY KEY,
Legal BOOL,
THCLevel INT,
Price DECIMAL(7,2) NOT NULL,
AvailableQuantity INT NOT NULL,
ShopID INT REFERENCES shop(ID) ON DELETE CASCADE ON UPDATE CASCADE,
imagepath varchar(255),
ProductName varchar(255)); */
$quantitàRimanente = $connection->query("SELECT SUM(AvailableQuantity) as available FROM products p INNER JOIN shop ON (ShopID=shop.ID) WHERE p.ID={$_POST['ID']}");
$quantitàPrecedente = $connection->query("SELECT AvailableQuantity as previous FROM products p WHERE p.ID={$_POST['ID']}");
$quantitàMassima = $connection->query("SELECT MaxNumProducts as maxNum FROM products p INNER JOIN shop ON (ShopID=shop.ID) WHERE p.ID={$_POST['ID']}");
$quantitàRimanente = (mysqli_fetch_array($quantitàRimanente)['available']);
$quantitàPrecedente = (mysqli_fetch_array($quantitàPrecedente)['previous']);
$quantitàMassima = (mysqli_fetch_array($quantitàMassima)['maxNum']);
if (($quantitàRimanente - $quantitàPrecedente + (int)$_POST['AvailableQuantity']) > (int)$quantitàMassima) {
echo "<div class='alert alert-warning email_alert'>
Valori non aggiornati, non puoi acquistare più prodotti rispetto alla quantità massima del magazzino (Quantità massima: {$quantitàMassima});
</div>";
} else {
if (!$risultatoQuery = $connection->query("UPDATE products P SET P.LightHard='{$_POST['LightHard']}',P.Price={$_POST['Price']},P.AvailableQuantity={$_POST['AvailableQuantity']} WHERE P.ID={$_POST['ID']}")) {
echo "<div class='alert alert-danger email_alert'>
Impossibile eseguire l'aggiornamento : {$connection->error}.
</div>";
} else {
if ($connection->affected_rows == 0) {
echo "<div class='alert alert-warning email_alert'>
Valori non aggiornati.
</div>";
} else {
echo "<div class='alert alert-success email_alert'>
Valori aggiornati.
</div>";
}
}
}
header("Refresh:2 url=./dashboardProdotti.php");
exit(0);
}
?>
<?php
if (isset($_POST['edit'])) {
$IDDaModificare = mysqli_real_escape_string($connection, $_POST['edit']);
$query = "SELECT P.ID,LightHard,Price,AvailableQuantity,ProductName,S.Address,S.ID AS ShopID FROM products P INNER JOIN shop S ON (P.ShopID=S.ID) WHERE P.ID=$IDDaModificare";
$query_run = mysqli_query($connection, $query);
/*create table products(
ID INT PRIMARY KEY,
Legal BOOL,
THCLevel INT,
Price DECIMAL(7,2) NOT NULL,
AvailableQuantity INT NOT NULL,
ShopID INT REFERENCES shop(ID) ON DELETE CASCADE ON UPDATE CASCADE,
imagepath varchar(255),
ProductName varchar(255));*/
if (mysqli_num_rows($query_run) > 0) {
$product = mysqli_fetch_array($query_run);
?>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4>Modifica Prodotto "
<?= $product['ProductName']; ?>":
</h4>
</div>
<div class="card-body">
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
ID:<br>
<input type="text" readonly name="ID" value="<?= $product['ID']; ?>" class="form-control">
<div class="mb-3">
<br>
<label>Light / Hard</label>
<br><br>
<select name="LightHard" class="form-select">
<option value="light" selected>Light</option>
<option value="hard">Hard</option>
</select>
</div>
<div class="mb-3">
<label>Prezzo</label>
<input type="text" name="Price" value="<?= $product['Price']; ?>"
pattern="[0-9]{1,5}[.]{0,1}[0-9]{0,2}" class="form-control" required>
</div>
<div class="mb-3">
<label>Quantità disponibile:</label>
<input type="number" name="AvailableQuantity"
value="<?= $product['AvailableQuantity']; ?>" class="form-control" required>
</div>
<div class="mb-3">
<label>Sede Magazzino:</label>
<input type="text" name="ShopID" value="<?= $product['ShopID']; ?>" class="form-control"
required readonly>
</div>
<div class="mb-3">
<button type="submit" name="update" class="btn btn-primary">
Aggiorna prodotto:
</button>
<a href="./dashboardDipendente.php" class="btn btn-primary">Torna alla dashboard:</a>
</div>
</form>
<?php
} else {
echo "<h4>ID Non trovato.</h4>";
}
}
?>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>