· 8 years ago · Dec 20, 2017, 12:20 PM
1<!--
2 index.php
3-->
4
5<?php
6 require_once 'database_connection.php';
7
8 require_once 'login_include.php';
9?>
10
11<!DOCTYPE html>
12<html>
13 <head>
14 <meta charset="utf-8">
15 <title>Tools4Ever</title>
16 </head>
17 <body>
18 <a href="locations.php">Locations</a><br>
19 <a href="products.php">Producten</a><br>
20 <a href="factories.php">Factories</a><br>
21 <a href="availabilty.php">Beschikbaarheid</a><br>
22
23 <br>
24 <a href="logout.php">Log uit!</a>
25 </body>
26</html>
27
28
29<!--
30 END index.php END
31-->
32
33
34<!--
35 products_add.php
36-->
37
38<?php
39
40require_once 'database_connection.php';
41require_once 'login_include.php';
42
43$product_name = strtoupper($_POST['name']);
44$product_price = $_POST['price'];
45$factory = $_POST['factory'];
46
47$sql = "SELECT * FROM products WHERE name = '$product_name' AND factory = $factory";
48$match = $db->query($sql);
49
50if($match->num_rows > 0) {
51
52 header("Location: products.php");
53
54} else {
55
56 $sql = "INSERT INTO products(name, price, factory) VALUES('$product_name', '$product_price', '$factory')";
57 $db->query($sql);
58
59}
60
61
62header("Location: products.php");
63
64?>
65
66<!--
67 END products_add.php END
68-->
69
70<!--
71 products_move.php
72-->
73
74<?php
75
76require_once 'database_connection.php';
77require_once 'login_include.php';
78
79if ($_POST) {
80 $product_id = $_POST['product_id'];
81 $location_id = $_POST['location_id'];
82 $new_location_id = $_POST['new_location_id'];
83 $quantity = $_POST['quantity'];
84
85 $sql = "SELECT * FROM product_locations
86 WHERE location_id = $location_id
87 AND product_id = $product_id";
88 $record_quantity = $db->query($sql)->fetch_assoc();
89 $record_quantity = $record_quantity['quantity'];
90
91 $delete_old_record = false;
92 if ($quantity >= $record_quantity) {
93 $quantity = $record_quantity;
94
95 $delete_old_record = true;
96 }
97
98 $sql = "SELECT * FROM product_locations
99 WHERE location_id = $new_location_id
100 AND product_id = $product_id";
101 $match = $db->query($sql);
102
103 if ($match->num_rows == 1) {
104 $sql = "UPDATE product_locations
105 SET quantity=quantity+$quantity
106 WHERE location_id = $new_location_id
107 AND product_id = $product_id";
108 $db->query($sql);
109
110 if ($delete_old_record) {
111 $sql = "DELETE FROM product_locations
112 WHERE location_id = $location_id
113 AND product_id = $product_id";
114 $db->query($sql);
115 } else {
116 $sql = "UPDATE product_locations
117 SET quantity=quantity-$quantity
118 WHERE location_id = $location_id
119 AND product_id = $product_id";
120 $db->query($sql);
121 }
122 } else {
123 if ($delete_old_record) {
124 $sql = "UPDATE product_locations
125 SET location_id=$new_location_id
126 WHERE location_id = $location_id
127 AND product_id = $product_id";
128 $db->query($sql);
129 } else {
130 $sql = "INSERT INTO product_locations(product_id, location_id, quantity)
131 VALUES($product_id, $new_location_id, $quantity)";
132 $db->query($sql);
133
134 $sql = "UPDATE product_locations
135 SET quantity=quantity-$quantity
136 WHERE location_id = $location_id
137 AND product_id = $product_id";
138 $db->query($sql);
139 }
140 }
141
142 header('Location: products.php');
143}
144
145if (!empty($_GET['product_id']) && !empty($_GET['location_id'])) {
146
147
148 $product_id = $_GET['product_id'];
149 $location_id = $_GET['location_id'];
150
151 $sql = "SELECT * FROM locations WHERE id != $location_id";
152 $other_locations = $db->query($sql);
153
154 $sql = "
155 SELECT p_l.quantity AS quantity,
156 p.id AS product_id,
157 p.name AS product_name,
158 p.price AS price,
159 l.name AS location_name,
160 l.id AS location_id
161 FROM product_locations AS p_l
162 LEFT JOIN products AS p ON p.id = p_l.product_id
163 LEFT JOIN locations AS l ON l.id = p_l.location_id
164 WHERE p_l.product_id = $product_id AND p_l.location_id = $location_id";
165
166 $record = $db->query($sql);
167
168 if($record->num_rows == 1 && $other_locations->num_rows > 0) {
169 $record = $record->fetch_assoc();
170 } else {
171 header('Location: products.php');
172 }
173?>
174
175Waar wilt u <?php echo $record['quantity'] . 'x ' . $record['product_name'] . ' van ' . $record['location_name']; ?> heen verplaatsen?
176<br>
177<br>
178 <form action="products_move.php" method="POST">
179 <select name="new_location_id" required>
180 <option value="">Selecteer een locatie</option>
181 <?php
182 if($other_locations->num_rows > 0) {
183 while($row = $other_locations->fetch_assoc()) {
184 echo "<option value='". $row['id'] ."'>".$row['name']."</option>";
185 }
186 }
187 ?>
188 </select><br><br>
189 <input type="number" name="quantity" placeholder="Hoeveel?" required>
190 <input type="hidden" name="location_id" value="<?php echo $location_id; ?>">
191 <input type="hidden" name="product_id" value="<?php echo $product_id; ?>">
192
193 <button type="submit">Verplaats product</button>
194 </form>
195
196<?php } ?>
197
198
199
200<!--
201 END products_move.php END
202-->
203
204<!--
205 products.php
206-->
207
208<?php
209require_once 'database_connection.php';
210
211require_once 'login_include.php';
212
213
214$sql = "SELECT * FROM locations ORDER BY `name` ASC";
215$locations = $db->query($sql);
216
217$sql = "SELECT * FROM factories ORDER BY `name` ASC";
218$factories = $db->query($sql);
219
220$sql = "SELECT
221 p.id AS product_id,
222 p.name AS product_name,
223 p.price AS price,
224 f.id AS factory_id,
225 f.name AS factory_name
226 FROM products AS p
227 LEFT JOIN factories AS f ON f.id = p.factory
228 ORDER BY p.name ASC";
229$products = $db->query($sql);
230
231$sql = "SELECT
232 p.id AS product_id,
233 p.name AS product_name,
234 p.price AS price,
235 f.id AS factory_id,
236 f.name AS factory_name
237 FROM products AS p
238 LEFT JOIN factories AS f ON f.id = p.factory
239 ORDER BY p.name ASC";
240$products2 = $db->query($sql);
241?>
242
243<!DOCTYPE html>
244<html>
245<head>
246 <meta charset="utf-8">
247 <title>Tools4Ever</title>
248</head>
249<body>
250<a href="index.php">Home</a><br>
251<br>
252<table>
253 <tr>
254 <td>
255 <form action="products_add_stock.php" method="POST">
256 <select name="product" required>
257 <option value="">Selecteer een product</option>
258 <?php
259 if($products->num_rows > 0) {
260 while($row = $products->fetch_assoc()) {
261 echo "<option value='". $row['product_id'] ."'>".$row['product_name']. " fabriek: " . $row['factory_name']."</option>";
262 }
263 }
264 ?>
265 </select><br>
266 <input type="number" name="quantity" placeholder="Quantity" required><br>
267
268 <select name="location" required>
269 <option value="">Selecteer een locatie</option>
270 <?php
271 if($locations->num_rows > 0) {
272 while($row = $locations->fetch_assoc()) {
273 echo "<option value='". $row['id'] ."'>".$row['name']."</option>";
274 }
275 }
276 ?>
277 </select><br><br>
278
279 <button type="submit">Voeg voorraad toe</button>
280 </form>
281 </td>
282 <td>
283 <form action="products_add.php" method="POST">
284 <input type="text" name="name" placeholder="Naam" required><br>
285 <input type="number" step="0.01" name="price" placeholder="Prijs" required><br>
286
287 <select name="factory" required>
288 <option value="">Selecteer een fabriek</option>
289 <?php
290 if($factories->num_rows > 0) {
291 while($row = $factories->fetch_assoc()) {
292 echo "<option value='". $row['id'] ."'>".$row['name']."</option>";
293 }
294 }
295 ?>
296 </select><br><br>
297
298 <button type="submit">Voeg product toe</button>
299 </form>
300 </td>
301 </tr>
302</table>
303<br>
304<table style="text-align: left">
305 <thead>
306 <th>id</th>
307 <th>naam</th>
308 <th>prijs</th>
309 <th>fabriek</th>
310 </thead>
311 <tbody>
312 <?php
313 if($products2->num_rows > 0) {
314 while($row = $products2->fetch_assoc()) {
315 ?>
316 <tr>
317 <td><?php echo $row['product_id']; ?></td>
318 <td><?php echo $row['product_name']; ?></td>
319 <td>€<?php echo number_format($row['price'],2, ',', '.');?></td>
320 <td><a href="factories_show.php?id=<?php echo $row['factory_id'] ?>"><?php echo $row['factory_name'] ?></a></td>
321 </tr>
322 <?php
323 }
324 }
325 ?>
326 </tbody>
327</table>
328
329</body>
330</html>
331
332<!--
333 END products.php END
334-->
335
336<!--
337 products_add_stock.php
338-->
339
340<?php
341
342require_once 'database_connection.php';
343require_once 'login_include.php';
344
345$product_id = $_POST['product'];
346$product_quantity = $_POST['quantity'];
347$location_id = $_POST['location'];
348
349$sql = "SELECT * FROM products WHERE name = '$product_name'";
350$match = $db->query($sql);
351
352if($match->num_rows > 0) {
353
354 $product = $match->fetch_assoc();
355
356 $sql = "SELECT * FROM product_locations WHERE product_id = ". $product['id'] ." AND location_id = ". $location_id;
357 $match = $db->query($sql);
358
359 if($match->num_rows > 0) {
360
361 $sql = "UPDATE product_locations SET quantity = quantity + $product_quantity WHERE product_id = ". $product['id'] ." AND location_id = ". $location_id ;
362 $db->query($sql);
363
364 } else {
365
366 $sql = "INSERT INTO product_locations(product_id, location_id, quantity) VALUES(".$product['id'].", $location_id, $product_quantity)";
367 $db->query($sql);
368
369 }
370
371} else {
372
373 header("Location: products.php");
374
375}
376
377
378header("Location: products.php");
379
380?>
381
382<!--
383 END products_add_stock.php END
384-->
385
386<!--
387 factories.php
388-->
389
390<?php
391require_once 'database_connection.php';
392require_once 'login_include.php';
393
394$sql = "SELECT * FROM locations ORDER BY `name` ASC";
395$locations = $db->query($sql);
396
397$sql = "
398 SELECT
399 f.id AS factory_id,
400 f.name AS factory_name,
401 l.id AS location_id,
402 l.name AS location_name
403 FROM factories AS f
404 LEFT JOIN locations AS l ON l.id = f.location
405 ";
406
407$factories = $db->query($sql);
408?>
409
410<!DOCTYPE html>
411<html>
412<head>
413 <meta charset="utf-8">
414 <title>Tools4Ever</title>
415</head>
416<body>
417<a href="index.php">Home</a><br>
418<br>
419<form action="factories_add.php" method="POST">
420 <input type="text" name="name" placeholder="Naam" required><br>
421 <select name="location" required>
422 <option value="">Selecteer een locatie</option>
423 <?php
424 if($locations->num_rows > 0) {
425 while($row = $locations->fetch_assoc()) {
426 echo "<option value='". $row['id'] ."'>".$row['name']."</option>";
427 }
428 }
429 ?>
430 </select><br><br>
431
432 <button type="submit">Voeg fabriek toe</button>
433</form>
434<br>
435<table style="text-align: left">
436 <thead>
437 <th>id</th>
438 <th>naam</th>
439 <th>locatie</th>
440 </thead>
441 <tbody>
442 <?php
443
444 if ($factories->num_rows > 0) {
445 while ($row = $factories->fetch_assoc()) {
446 ?>
447 <tr>
448 <td><?php echo $row['factory_id']; ?></td>
449 <td><a href="factories_show.php?id=<?php echo $row['factory_id']; ?>"><?php echo $row['factory_name']; ?></a></td>
450 <td><?php echo $row['location_name'];?></td>
451 </tr>
452 <?php
453 }
454 }
455 ?>
456 </tbody>
457</table>
458
459</body>
460</html>
461
462
463<!--
464 END factories.php END
465-->
466
467<!--
468 factories_add.php
469-->
470
471<?php
472
473require_once 'database_connection.php';
474require_once 'login_include.php';
475
476$factory_name = strtoupper($_POST['name']);
477$location_id = $_POST['location'];
478
479$sql = "INSERT INTO factories(name, location) VALUES('$factory_name','$location_id')";
480$db->query($sql);
481
482header('Location: factories.php');
483?>
484
485<!--
486 END factories_add.php END
487-->
488
489<!--
490 factories_show.php
491-->
492
493<?php
494require_once 'database_connection.php';
495require_once 'login_include.php';
496
497if ($_GET['id']) {
498 $total_worth = 0;
499
500 $factory_id = $_GET['id'];
501
502 $sql = "SELECT * FROM factories WHERE id = $factory_id";
503
504 $factory = $db->query($sql)->fetch_assoc();
505
506 $sql = "SELECT * FROM products WHERE factory = $factory_id";
507
508 $products = $db->query($sql);
509?>
510<a href="factories.php">Terug</a><br><br>
511Fabriek: <?php echo $factory['name']; ?>
512<br>
513<?php
514if ($products->num_rows > 0) {
515?>
516<br><br>
517<b>Producten:</b>
518<br>
519<table>
520 <thead>
521 <tr>
522 <th>id</th>
523 <th>naam</th>
524 <th>prijs</th>
525 </tr>
526 </thead>
527 <tbody>
528 <?php
529
530 while ($row = $products->fetch_assoc()) {
531 ?>
532 <tr>
533 <td><?php echo $row['id']; ?></td>
534 <td><?php echo $row['name']; ?></td>
535 <td>€<?php echo number_format($row['price'],2,',','.'); ?></td>
536 </tr>
537 <?php
538 }
539 }
540}
541?>
542</tbody>
543</table>
544
545
546<!--
547 END factories_show.php END
548-->
549
550<!--
551 toolsforever.sql
552-->
553
554-- --------------------------------------------------------
555-- Host: 127.0.0.1
556-- Server versie: 10.1.21-MariaDB - mariadb.org binary distribution
557-- Server OS: Win32
558-- HeidiSQL Versie: 9.3.0.4984
559-- --------------------------------------------------------
560
561/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
562/*!40101 SET NAMES utf8mb4 */;
563/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
564/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
565
566-- Databasestructuur van toolsforever wordt geschreven
567CREATE DATABASE IF NOT EXISTS `toolsforever` /*!40100 DEFAULT CHARACTER SET latin1 */;
568USE `toolsforever`;
569
570
571-- Structuur van tabel toolsforever.factories wordt geschreven
572CREATE TABLE IF NOT EXISTS `factories` (
573 `id` int(11) NOT NULL AUTO_INCREMENT,
574 `name` varchar(50) DEFAULT NULL,
575 `location` int(11) DEFAULT NULL,
576 PRIMARY KEY (`id`),
577 KEY `location_ibfk_1` (`location`),
578 CONSTRAINT `location_ibfk_1` FOREIGN KEY (`location`) REFERENCES `locations` (`id`)
579) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
580
581-- Dumpen data van tabel toolsforever.factories: ~0 rows (ongeveer)
582DELETE FROM `factories`;
583/*!40000 ALTER TABLE `factories` DISABLE KEYS */;
584/*!40000 ALTER TABLE `factories` ENABLE KEYS */;
585
586
587-- Structuur van tabel toolsforever.locations wordt geschreven
588CREATE TABLE IF NOT EXISTS `locations` (
589 `id` int(11) NOT NULL AUTO_INCREMENT,
590 `name` varchar(50) DEFAULT NULL,
591 PRIMARY KEY (`id`)
592) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
593
594-- Dumpen data van tabel toolsforever.locations: ~0 rows (ongeveer)
595DELETE FROM `locations`;
596/*!40000 ALTER TABLE `locations` DISABLE KEYS */;
597/*!40000 ALTER TABLE `locations` ENABLE KEYS */;
598
599
600-- Structuur van tabel toolsforever.products wordt geschreven
601CREATE TABLE IF NOT EXISTS `products` (
602 `id` int(11) NOT NULL AUTO_INCREMENT,
603 `name` varchar(50) DEFAULT NULL,
604 `price` double DEFAULT NULL,
605 `factory` int(11) DEFAULT NULL,
606 PRIMARY KEY (`id`),
607 KEY `products_factories_ibfk_1` (`factory`),
608 CONSTRAINT `products_factories_ibfk_1` FOREIGN KEY (`factory`) REFERENCES `factories` (`id`)
609) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
610
611-- Dumpen data van tabel toolsforever.products: ~0 rows (ongeveer)
612DELETE FROM `products`;
613/*!40000 ALTER TABLE `products` DISABLE KEYS */;
614/*!40000 ALTER TABLE `products` ENABLE KEYS */;
615
616
617-- Structuur van tabel toolsforever.product_locations wordt geschreven
618CREATE TABLE IF NOT EXISTS `product_locations` (
619 `product_id` int(11) NOT NULL,
620 `location_id` int(11) NOT NULL,
621 `quantity` int(11) DEFAULT NULL,
622 KEY `product_id` (`product_id`),
623 KEY `location_id` (`location_id`),
624 CONSTRAINT `product_locations_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
625 CONSTRAINT `product_locations_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `locations` (`id`)
626) ENGINE=InnoDB DEFAULT CHARSET=latin1;
627
628-- Dumpen data van tabel toolsforever.product_locations: ~0 rows (ongeveer)
629DELETE FROM `product_locations`;
630/*!40000 ALTER TABLE `product_locations` DISABLE KEYS */;
631/*!40000 ALTER TABLE `product_locations` ENABLE KEYS */;
632
633
634-- Structuur van tabel toolsforever.users wordt geschreven
635CREATE TABLE IF NOT EXISTS `users` (
636 `id` int(11) NOT NULL AUTO_INCREMENT,
637 `username` varchar(50) DEFAULT NULL,
638 `password` varchar(50) DEFAULT NULL,
639 PRIMARY KEY (`id`)
640) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
641
642-- Dumpen data van tabel toolsforever.users: ~0 rows (ongeveer)
643DELETE FROM `users`;
644/*!40000 ALTER TABLE `users` DISABLE KEYS */;
645INSERT INTO `users` (`id`, `username`, `password`) VALUES
646 (1, 'admin', '21232f297a57a5a743894a0e4a801fc3');
647/*!40000 ALTER TABLE `users` ENABLE KEYS */;
648/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
649/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
650/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
651
652
653<!--
654 END toolsforever.sql END
655-->