From 4871de62d3477a023b80e5d66b662a28922a0eb2 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 20:56:02 +0100 Subject: [PATCH 1/7] Create a seperate page for adding demands In addition I've added a new field for quality. --- add_request.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++ board.php | 16 +----------- functions.php | 17 +++++++------ navigation.php | 1 + sql/add_data.sql | 4 +++ sql/create_db.sql | 11 ++++++++- 6 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 add_request.php diff --git a/add_request.php b/add_request.php new file mode 100644 index 0000000..113fa6f --- /dev/null +++ b/add_request.php @@ -0,0 +1,62 @@ + + + + + + + + + + + + + +
+
+
+ +

Board

+ + + + + +
+
+ + +
+

New entry

+ + + Title
+
+ Quality
+
+
+ Maximum
+
+
+ Minimum
+
+
+ Description
+
+ + + "; + ?> +
+ + diff --git a/board.php b/board.php index a58a0d7..e9e166c 100644 --- a/board.php +++ b/board.php @@ -32,24 +32,10 @@ date_default_timezone_set('Europe/Amsterdam');
- -

Neuer Eintrag

- +

Open Requests


Maximum
- -
Minimum
-
- -
Produktbeschreibung
-
- - "; pbget($con); ?> -
diff --git a/functions.php b/functions.php index a83db06..103f8f5 100644 --- a/functions.php +++ b/functions.php @@ -76,16 +76,19 @@ function pbinsert ($con) $userId = get_userid($con); $piecesMax = $_POST['piecesMax']; $piecesMin = $_POST['piecesMin']; - $date = $_POST['date']; + $qualityId = $_POST['quality']; + $title = $_POST['title']; $text = $_POST['text']; // Inserts Data into Database - $sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date, userId) - VALUES ('$piecesMax', '$piecesMin', '$text', '$date', '$userId')"; + $sql = "INSERT INTO demands (piecesMax, piecesMin, demandText, + demandTitle, userId, qualityId) + VALUES ('$piecesMax', '$piecesMin', '$text', '$title', + '$userId', '$qualityId')"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); } } -// A function to insert the own posts from the database into the webside +// A function to insert the own posts from the database into the website function pbget($con) { global $con; @@ -94,7 +97,7 @@ function pbget($con) while ($row = $result->fetch_assoc()) { echo "

"; echo $row['date'] . "
"; - echo $row['text'] ."
" , "
Maximum
"; + echo $row['demandText'] ."
" , "
Maximum
"; echo $row['piecesMax'] ."
Minimum
"; echo $row['piecesMin']; echo "

@@ -109,7 +112,7 @@ function pbget($con) - +
"; @@ -131,7 +134,7 @@ function editpost($con) $sql = "UPDATE demands SET piecesMax='$piecesMax', piecesMin='$piecesMin', - text='$text' + demandText='$text' WHERE demandId='$demandId'"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); header("Location: board.php"); diff --git a/navigation.php b/navigation.php index 5d09565..b2313c7 100644 --- a/navigation.php +++ b/navigation.php @@ -2,6 +2,7 @@ echo '' ?> diff --git a/sql/add_data.sql b/sql/add_data.sql index 538c241..397a7ee 100644 --- a/sql/add_data.sql +++ b/sql/add_data.sql @@ -10,3 +10,7 @@ insert into users (userLogin, userPass, userEmail) values ('demander','password','demander@example.com'), ('provider','password','provider@example.com'), ('admin','password','admin@example.com'); + +insert into quality (qualityName) + values ('new'), + ('used'); diff --git a/sql/create_db.sql b/sql/create_db.sql index 7c25d06..019c145 100644 --- a/sql/create_db.sql +++ b/sql/create_db.sql @@ -31,16 +31,25 @@ CREATE TABLE if not exists `tags` ( `text` varchar(50) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE if not exists `quality` ( + `qualityId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `qualityName` varchar(20) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE if not exists `demands` ( `demandId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, - `text` text, + `demandTitle` varchar(50) NOT NULL, + `demandText` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `piecesMin` int(11) NOT NULL, `piecesMax` int(11) DEFAULT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `qualityId` int(11) NOT NULL, `userId` int(11) NOT NULL, `tagId` int(11) NULL, CONSTRAINT `fk_demands_userId` FOREIGN KEY (userId) REFERENCES users (userId), + CONSTRAINT `fk_demands_qualityId` + FOREIGN KEY (qualityId) REFERENCES quality (qualityId), CONSTRAINT `fk_tagId` FOREIGN KEY (tagId) REFERENCES tags (tagId) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From c407495893e0d4448950f78e800f310bf5adcc95 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 21:12:41 +0100 Subject: [PATCH 2/7] Remove the amounts and text fields from the board view. The board view should provide an overview over the available requests for further selection. --- board.php | 2 +- editboard.php | 4 ++-- functions.php | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/board.php b/board.php index e9e166c..5b7790d 100644 --- a/board.php +++ b/board.php @@ -34,7 +34,7 @@ date_default_timezone_set('Europe/Amsterdam');

Open Requests

diff --git a/editboard.php b/editboard.php index 0673a23..c6530cc 100644 --- a/editboard.php +++ b/editboard.php @@ -38,16 +38,16 @@ date_default_timezone_set('Europe/Amsterdam'); $demandId = $_POST['demandId']; $piecesMax = $_POST['piecesMax']; $piecesMin = $_POST['piecesMin']; - $date = $_POST['date']; + $title= $_POST['title']; $text = $_POST['text']; echo "
+

Maximum

Minimum
-
Produktbeschreibung

diff --git a/functions.php b/functions.php index 103f8f5..b30e7a0 100644 --- a/functions.php +++ b/functions.php @@ -89,17 +89,15 @@ function pbinsert ($con) } // A function to insert the own posts from the database into the website -function pbget($con) +function get_post_titles($con) { global $con; $sql = "SELECT * FROM demands"; $result = mysqli_query($con, $sql); while ($row = $result->fetch_assoc()) { echo "

"; + echo "" . $row['demandTitle'] . "" . "
"; echo $row['date'] . "
"; - echo $row['demandText'] ."
" , "
Maximum
"; - echo $row['piecesMax'] ."
Minimum
"; - echo $row['piecesMin']; echo "

@@ -111,7 +109,7 @@ function pbget($con) - + @@ -128,12 +126,14 @@ function editpost($con) $demandId = $_POST['demandId']; $piecesMax = $_POST['piecesMax']; $piecesMin = $_POST['piecesMin']; + $title = $_POST['title']; $text = $_POST['text']; // Inserts Updates Database $sql = "UPDATE demands SET piecesMax='$piecesMax', piecesMin='$piecesMin', + demandTitle='$title', demandText='$text' WHERE demandId='$demandId'"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); From bcd41be9a89fb69dd84cd5ca119743756966d160 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 21:24:47 +0100 Subject: [PATCH 3/7] rename function names --- editboard.php | 2 +- functions.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/editboard.php b/editboard.php index c6530cc..18e4965 100644 --- a/editboard.php +++ b/editboard.php @@ -42,7 +42,7 @@ date_default_timezone_set('Europe/Amsterdam'); $text = $_POST['text']; echo - "
+ "

Maximum
diff --git a/functions.php b/functions.php index b30e7a0..96a3603 100644 --- a/functions.php +++ b/functions.php @@ -99,7 +99,8 @@ function get_post_titles($con) echo "" . $row['demandTitle'] . "" . "
"; echo $row['date'] . "
"; echo "

- +
@@ -119,7 +120,7 @@ function get_post_titles($con) // A function to edit a demand -function editpost($con) +function edit_post($con) { if (isset($_POST['edit'])) { global $con; @@ -141,7 +142,7 @@ function editpost($con) } } // A function to delete a post -function deletepost($con) +function delete_post($con) { if (isset($_POST['deletepost'])) { global $con; From 5efaae8bb3c077a25d3192dbd4d21f705a6df88e Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 21:34:28 +0100 Subject: [PATCH 4/7] rename various files and functions to add consistency --- add_request.php => add_demand.php | 2 +- board.php | 2 +- edit_demand.php | 58 +++++++++++++++++++++++++++++++ functions.php | 12 +++---- navigation.php | 2 +- editboard.php => show_demand.php | 0 6 files changed, 67 insertions(+), 9 deletions(-) rename add_request.php => add_demand.php (94%) create mode 100644 edit_demand.php rename editboard.php => show_demand.php (100%) diff --git a/add_request.php b/add_demand.php similarity index 94% rename from add_request.php rename to add_demand.php index 113fa6f..7c07602 100644 --- a/add_request.php +++ b/add_demand.php @@ -36,7 +36,7 @@ date_default_timezone_set('Europe/Amsterdam');

New entry

+ echo "
Title

Quality
diff --git a/board.php b/board.php index 5b7790d..bd076d1 100644 --- a/board.php +++ b/board.php @@ -34,7 +34,7 @@ date_default_timezone_set('Europe/Amsterdam');

Open Requests

diff --git a/edit_demand.php b/edit_demand.php new file mode 100644 index 0000000..10947a3 --- /dev/null +++ b/edit_demand.php @@ -0,0 +1,58 @@ + + + + + + + + + + + + + +
+
+
+ +

Edit

+ + + + + +
+
+ +

Edit Board

+ + +
+ +
Maximum
+
Minimum
+ +
Produktbeschreibung
+
+ + "; + ?> +
+ + diff --git a/functions.php b/functions.php index 96a3603..775f8c3 100644 --- a/functions.php +++ b/functions.php @@ -69,7 +69,7 @@ function get_userid ($con) } // A function to post a demand -function pbinsert ($con) +function post_demand ($con) { if (isset($_POST['submit'])) { global $con; @@ -89,7 +89,7 @@ function pbinsert ($con) } // A function to insert the own posts from the database into the website -function get_post_titles($con) +function get_demand_titles ($con) { global $con; $sql = "SELECT * FROM demands"; @@ -105,7 +105,7 @@ function get_post_titles($con) -
+ @@ -120,7 +120,7 @@ function get_post_titles($con) // A function to edit a demand -function edit_post($con) +function edit_demand ($con) { if (isset($_POST['edit'])) { global $con; @@ -142,7 +142,7 @@ function edit_post($con) } } // A function to delete a post -function delete_post($con) +function delete_demand($con) { if (isset($_POST['deletepost'])) { global $con; @@ -154,4 +154,4 @@ function delete_post($con) header('Location: board.php'); } } -?> +?> \ No newline at end of file diff --git a/navigation.php b/navigation.php index b2313c7..1e6681e 100644 --- a/navigation.php +++ b/navigation.php @@ -2,7 +2,7 @@ echo '' ?> diff --git a/editboard.php b/show_demand.php similarity index 100% rename from editboard.php rename to show_demand.php From 935e4f9e95415dd7ba026659c42d5e04a6fa323e Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 21:35:49 +0100 Subject: [PATCH 5/7] change title --- board.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board.php b/board.php index bd076d1..f46e32a 100644 --- a/board.php +++ b/board.php @@ -32,7 +32,7 @@ date_default_timezone_set('Europe/Amsterdam');
-

Open Requests

+

Open Demands

From 27ee918b636e49d5c7b8f7d780c5c02890c13266 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 21:37:02 +0100 Subject: [PATCH 6/7] rename a function call --- functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 775f8c3..1eda332 100644 --- a/functions.php +++ b/functions.php @@ -100,7 +100,7 @@ function get_demand_titles ($con) echo $row['date'] . "
"; echo "

+ action='".delete_demand($con)."'> From b4f3db4208c761c4c0a44fe90d35ec85b5015a7a Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 22:05:30 +0100 Subject: [PATCH 7/7] check if the maximumPieces is bigger than the minimumPieces --- add_demand.php | 2 +- css/stylesheet.css | 3 +++ functions.php | 38 +++++++++++++++++++----------- show_demand.php | 58 ---------------------------------------------- 4 files changed, 29 insertions(+), 72 deletions(-) delete mode 100644 show_demand.php diff --git a/add_demand.php b/add_demand.php index 7c07602..bf7613f 100644 --- a/add_demand.php +++ b/add_demand.php @@ -46,7 +46,7 @@ date_default_timezone_set('Europe/Amsterdam');

Maximum
-
+

Minimum

diff --git a/css/stylesheet.css b/css/stylesheet.css index 2bbdcf5..7016cb0 100644 --- a/css/stylesheet.css +++ b/css/stylesheet.css @@ -94,3 +94,6 @@ li { .delete-form button:hover{ opacity: 1; } +*.warning { + color:red; +} diff --git a/functions.php b/functions.php index 1eda332..511bcf6 100644 --- a/functions.php +++ b/functions.php @@ -80,11 +80,17 @@ function post_demand ($con) $title = $_POST['title']; $text = $_POST['text']; // Inserts Data into Database - $sql = "INSERT INTO demands (piecesMax, piecesMin, demandText, - demandTitle, userId, qualityId) - VALUES ('$piecesMax', '$piecesMin', '$text', '$title', - '$userId', '$qualityId')"; - $result = mysqli_query($con, $sql) or die(mysqli_error($con)); + if ($piecesMax <= $piecesMin) { + echo " + The Maximum must be bigger than the Minimum! + "; + } else { + $sql = "INSERT INTO demands (piecesMax, piecesMin, demandText, + demandTitle, userId, qualityId) + VALUES ('$piecesMax', '$piecesMin', '$text', '$title', + '$userId', '$qualityId')"; + $result = mysqli_query($con, $sql) or die(mysqli_error($con)); + } } } @@ -131,14 +137,20 @@ function edit_demand ($con) $text = $_POST['text']; // Inserts Updates Database - $sql = "UPDATE demands - SET piecesMax='$piecesMax', - piecesMin='$piecesMin', - demandTitle='$title', - demandText='$text' - WHERE demandId='$demandId'"; - $result = mysqli_query($con, $sql) or die(mysqli_error($con)); - header("Location: board.php"); + if ($piecesMax <= $piecesMin) { + echo " + The Maximum must be bigger than the Minimum! + "; + } else { + $sql = "UPDATE demands + SET piecesMax='$piecesMax', + piecesMin='$piecesMin', + demandTitle='$title', + demandText='$text' + WHERE demandId='$demandId'"; + $result = mysqli_query($con, $sql) or die(mysqli_error($con)); + header("Location: board.php"); + } } } // A function to delete a post diff --git a/show_demand.php b/show_demand.php deleted file mode 100644 index 18e4965..0000000 --- a/show_demand.php +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - -
-
-
- -

Edit

- - - - - -
-
- -

Edit Board

- - -
- -
Maximum
-
Minimum
- -
Produktbeschreibung
-
- - "; - ?> -
- -