diff --git a/add_demand.php b/add_demand.php new file mode 100644 index 0000000..bf7613f --- /dev/null +++ b/add_demand.php @@ -0,0 +1,62 @@ + + + + + + + + + + + + + +
+
+
+ +

Board

+ + + + + +
+
+ + +
+

New entry

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

Neuer Eintrag

- +

Open Demands


Maximum
- -
Minimum
-
- -
Produktbeschreibung
-
- - "; - pbget($con); + get_demand_titles($con); ?> -
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/editboard.php b/edit_demand.php similarity index 90% rename from editboard.php rename to edit_demand.php index 0673a23..10947a3 100644 --- a/editboard.php +++ b/edit_demand.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 a83db06..511bcf6 100644 --- a/functions.php +++ b/functions.php @@ -69,47 +69,55 @@ function get_userid ($con) } // A function to post a demand -function pbinsert ($con) +function post_demand ($con) { if (isset($_POST['submit'])) { global $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')"; - $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)); + } } } -// A function to insert the own posts from the database into the webside -function pbget($con) +// A function to insert the own posts from the database into the website +function get_demand_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['text'] ."
" , "
Maximum
"; - echo $row['piecesMax'] ."
Minimum
"; - echo $row['piecesMin']; echo "

- + -
+ - - + +
"; @@ -118,27 +126,35 @@ function pbget($con) // A function to edit a demand -function editpost($con) +function edit_demand ($con) { if (isset($_POST['edit'])) { global $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', - text='$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 -function deletepost($con) +function delete_demand($con) { if (isset($_POST['deletepost'])) { global $con; @@ -150,4 +166,4 @@ function deletepost($con) header('Location: board.php'); } } -?> +?> \ No newline at end of file diff --git a/navigation.php b/navigation.php index 5d09565..1e6681e 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;