Merge branch 'andreas'

This commit is contained in:
Andreas Zweili 2017-02-20 22:08:40 +01:00
commit 58eb99d7b0
8 changed files with 125 additions and 44 deletions

62
add_demand.php Normal file
View File

@ -0,0 +1,62 @@
<?php
include 'functions.php';
date_default_timezone_set('Europe/Amsterdam');
?>
<!DOCTYPE html>
<html>
<head>
<!-- enable utf-8 encoding for umlauts etc.-->
<meta charset="utf-8">
<!-- Description of what this dose -->
<meta name ="viewport" content="width=device-width, initial-scale=1">
<!-- link to the default css file -->
<link rel="stylesheet" href="css/stylesheet.css"/>
</head>
<body>
<div>
<div>
<header>
<!-- The title begins here -->
<h1>Board</h1>
<!--The Title ends here -->
<!-- The sidebar naviagtion begins here -->
<nav>
<?php
include 'navigation.php';
?>
</nav>
<!-- The sidebar naviagtion ends here -->
</header>
</div>
<!-- The Post function begins here -->
<div>
<h2>New entry</h2>
<?php
echo "<form class= 'post-box p' method='POST' action='".post_demand($con)."'>
Title<br>
<input type='text' name='title' required><br>
Quality<br>
<select name='quality'>
<option selected='selected' value='1'>New</option>
<option value='2'>Used</option>
</select><br>
<br>
Maximum<br>
<input type='number' name='piecesMax' value='' required><br>
<br>
Minimum<br>
<input type='number' name='piecesMin' value='' required><br>
<br>
Description<br>
<textarea rows='6' cols='40' name='text' required></textarea><br>
<button type='submit' name='submit'>SUBMIT</button>
</form>
";
?>
</div>
</body>
</html>

View File

@ -32,24 +32,10 @@ date_default_timezone_set('Europe/Amsterdam');
</div>
<!-- The Post function begins here -->
<div>
<h2>Neuer Eintrag</h2>
<h2>Open Demands</h2>
<?php
echo
"<form class= 'post-box p' method='POST' action='".pbinsert($con)."'> <br /> Maximum<br/>
<input type='hidden' name='userId' value=''>
<input type='number' name='piecesMax' value='' > <br /> Minimum<br/>
<input type='number' name='piecesMin' value='' > <br />
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<br /> Produktbeschreibung<br/>
<textarea rows='6' cols='40' name='text'></textarea><br />
<button type='submit' name='submit'>SUBMIT</button>
</form>";
pbget($con);
get_demand_titles($con);
?>
</div>
</body>
</html>

View File

@ -94,3 +94,6 @@ li {
.delete-form button:hover{
opacity: 1;
}
*.warning {
color:red;
}

View File

@ -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
"<form method='POST' action='".editpost($con)."'>
"<form method='POST' action='".edit_demand($con)."'>
<input type='text' name='title' value='".$title."'><br>
<input type='hidden' name='userId' value='".$userId."'>
<input type='hidden' name='demandId' value='".$demandId."'><br /> Maximum<br/>
<input type='number' name='piecesMax' value='".$piecesMax."'> <br /> Minimum<br/>
<input type='number' name='piecesMin' value='".$piecesMin."'>
<input type='hidden' name='date' value='".$date."'>
<br /> Produktbeschreibung<br/>
<textarea name='text'>".$text."</textarea><br />
<button type='submit' name='edit'>Edit</button>

View File

@ -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 "<strong class='warning'>
The Maximum must be bigger than the Minimum!
</strong>";
} 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 "<div class='post-box'><p>";
echo "<strong>" . $row['demandTitle'] . "</strong>" . "<br>";
echo $row['date'] . "<br>";
echo $row['text'] ."<br>" , "<br /> Maximum<br/>";
echo $row['piecesMax'] ."<br /> Minimum<br/>";
echo $row['piecesMin'];
echo "</p>
<form class= 'delete-form' method= 'POST' action='".deletepost($con)."'>
<form class= 'delete-form' method= 'POST'
action='".delete_demand($con)."'>
<input type='hidden' name='demandId' value='".$row['demandId']."'>
<button type='submit' name= 'deletepost'> Delete</button>
</form>
<form class= 'edit-form' method= 'POST' action='editboard.php'>
<form class= 'edit-form' method= 'POST' action='edit_demand.php'>
<input type='hidden' name='userId' value='".$row['userId']."'>
<input type='hidden' name='demandId' value='".$row['demandId']."'>
<input type='hidden' name='piecesMax' value='".$row['piecesMax']."'>
<input type='hidden' name='piecesMin' value='".$row['piecesMin']."'>
<input type='hidden' name='date' value='".$row['date']."'>
<input type='hidden' name='text' value='".$row['text']."'>
<input type='hidden' name='title' value='".$row['demandTitle']."'>
<input type='hidden' name='text' value='".$row['demandText']."'>
<button>Edit</button>
</form>
</div>";
@ -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 "<strong class='warning'>
The Maximum must be bigger than the Minimum!
</strong>";
} 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');
}
}
?>
?>

View File

@ -2,6 +2,7 @@
echo '<ul>
<li><a href="index.php">Logout</a></li>
<li><a href="board.php">Board</a></li>
<li><a href="add_demand.php">New Demand</a></li>
<li><a class="active" href="home.php">Home</a></li>
</ul>'
?>

View File

@ -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');

View File

@ -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;