Merge branch 'andreas'
This commit is contained in:
commit
58eb99d7b0
|
@ -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>
|
18
board.php
18
board.php
|
@ -32,24 +32,10 @@ date_default_timezone_set('Europe/Amsterdam');
|
||||||
</div>
|
</div>
|
||||||
<!-- The Post function begins here -->
|
<!-- The Post function begins here -->
|
||||||
<div>
|
<div>
|
||||||
|
<h2>Open Demands</h2>
|
||||||
<h2>Neuer Eintrag</h2>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
get_demand_titles($con);
|
||||||
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);
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -94,3 +94,6 @@ li {
|
||||||
.delete-form button:hover{
|
.delete-form button:hover{
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
*.warning {
|
||||||
|
color:red;
|
||||||
|
}
|
||||||
|
|
|
@ -38,16 +38,16 @@ date_default_timezone_set('Europe/Amsterdam');
|
||||||
$demandId = $_POST['demandId'];
|
$demandId = $_POST['demandId'];
|
||||||
$piecesMax = $_POST['piecesMax'];
|
$piecesMax = $_POST['piecesMax'];
|
||||||
$piecesMin = $_POST['piecesMin'];
|
$piecesMin = $_POST['piecesMin'];
|
||||||
$date = $_POST['date'];
|
$title= $_POST['title'];
|
||||||
$text = $_POST['text'];
|
$text = $_POST['text'];
|
||||||
|
|
||||||
echo
|
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='userId' value='".$userId."'>
|
||||||
<input type='hidden' name='demandId' value='".$demandId."'><br /> Maximum<br/>
|
<input type='hidden' name='demandId' value='".$demandId."'><br /> Maximum<br/>
|
||||||
<input type='number' name='piecesMax' value='".$piecesMax."'> <br /> Minimum<br/>
|
<input type='number' name='piecesMax' value='".$piecesMax."'> <br /> Minimum<br/>
|
||||||
<input type='number' name='piecesMin' value='".$piecesMin."'>
|
<input type='number' name='piecesMin' value='".$piecesMin."'>
|
||||||
<input type='hidden' name='date' value='".$date."'>
|
|
||||||
<br /> Produktbeschreibung<br/>
|
<br /> Produktbeschreibung<br/>
|
||||||
<textarea name='text'>".$text."</textarea><br />
|
<textarea name='text'>".$text."</textarea><br />
|
||||||
<button type='submit' name='edit'>Edit</button>
|
<button type='submit' name='edit'>Edit</button>
|
|
@ -69,47 +69,55 @@ function get_userid ($con)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A function to post a demand
|
// A function to post a demand
|
||||||
function pbinsert ($con)
|
function post_demand ($con)
|
||||||
{
|
{
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
global $con;
|
global $con;
|
||||||
$userId = get_userid($con);
|
$userId = get_userid($con);
|
||||||
$piecesMax = $_POST['piecesMax'];
|
$piecesMax = $_POST['piecesMax'];
|
||||||
$piecesMin = $_POST['piecesMin'];
|
$piecesMin = $_POST['piecesMin'];
|
||||||
$date = $_POST['date'];
|
$qualityId = $_POST['quality'];
|
||||||
|
$title = $_POST['title'];
|
||||||
$text = $_POST['text'];
|
$text = $_POST['text'];
|
||||||
// Inserts Data into Database
|
// Inserts Data into Database
|
||||||
$sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date, userId)
|
if ($piecesMax <= $piecesMin) {
|
||||||
VALUES ('$piecesMax', '$piecesMin', '$text', '$date', '$userId')";
|
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));
|
$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)
|
function get_demand_titles ($con)
|
||||||
{
|
{
|
||||||
global $con;
|
global $con;
|
||||||
$sql = "SELECT * FROM demands";
|
$sql = "SELECT * FROM demands";
|
||||||
$result = mysqli_query($con, $sql);
|
$result = mysqli_query($con, $sql);
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
echo "<div class='post-box'><p>";
|
echo "<div class='post-box'><p>";
|
||||||
|
echo "<strong>" . $row['demandTitle'] . "</strong>" . "<br>";
|
||||||
echo $row['date'] . "<br>";
|
echo $row['date'] . "<br>";
|
||||||
echo $row['text'] ."<br>" , "<br /> Maximum<br/>";
|
|
||||||
echo $row['piecesMax'] ."<br /> Minimum<br/>";
|
|
||||||
echo $row['piecesMin'];
|
|
||||||
echo "</p>
|
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']."'>
|
<input type='hidden' name='demandId' value='".$row['demandId']."'>
|
||||||
<button type='submit' name= 'deletepost'> Delete</button>
|
<button type='submit' name= 'deletepost'> Delete</button>
|
||||||
</form>
|
</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='userId' value='".$row['userId']."'>
|
||||||
<input type='hidden' name='demandId' value='".$row['demandId']."'>
|
<input type='hidden' name='demandId' value='".$row['demandId']."'>
|
||||||
<input type='hidden' name='piecesMax' value='".$row['piecesMax']."'>
|
<input type='hidden' name='piecesMax' value='".$row['piecesMax']."'>
|
||||||
<input type='hidden' name='piecesMin' value='".$row['piecesMin']."'>
|
<input type='hidden' name='piecesMin' value='".$row['piecesMin']."'>
|
||||||
<input type='hidden' name='date' value='".$row['date']."'>
|
<input type='hidden' name='title' value='".$row['demandTitle']."'>
|
||||||
<input type='hidden' name='text' value='".$row['text']."'>
|
<input type='hidden' name='text' value='".$row['demandText']."'>
|
||||||
<button>Edit</button>
|
<button>Edit</button>
|
||||||
</form>
|
</form>
|
||||||
</div>";
|
</div>";
|
||||||
|
@ -118,27 +126,35 @@ function pbget($con)
|
||||||
|
|
||||||
|
|
||||||
// A function to edit a demand
|
// A function to edit a demand
|
||||||
function editpost($con)
|
function edit_demand ($con)
|
||||||
{
|
{
|
||||||
if (isset($_POST['edit'])) {
|
if (isset($_POST['edit'])) {
|
||||||
global $con;
|
global $con;
|
||||||
$demandId = $_POST['demandId'];
|
$demandId = $_POST['demandId'];
|
||||||
$piecesMax = $_POST['piecesMax'];
|
$piecesMax = $_POST['piecesMax'];
|
||||||
$piecesMin = $_POST['piecesMin'];
|
$piecesMin = $_POST['piecesMin'];
|
||||||
|
$title = $_POST['title'];
|
||||||
$text = $_POST['text'];
|
$text = $_POST['text'];
|
||||||
|
|
||||||
// Inserts Updates Database
|
// Inserts Updates Database
|
||||||
|
if ($piecesMax <= $piecesMin) {
|
||||||
|
echo "<strong class='warning'>
|
||||||
|
The Maximum must be bigger than the Minimum!
|
||||||
|
</strong>";
|
||||||
|
} else {
|
||||||
$sql = "UPDATE demands
|
$sql = "UPDATE demands
|
||||||
SET piecesMax='$piecesMax',
|
SET piecesMax='$piecesMax',
|
||||||
piecesMin='$piecesMin',
|
piecesMin='$piecesMin',
|
||||||
text='$text'
|
demandTitle='$title',
|
||||||
|
demandText='$text'
|
||||||
WHERE demandId='$demandId'";
|
WHERE demandId='$demandId'";
|
||||||
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
|
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
|
||||||
header("Location: board.php");
|
header("Location: board.php");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// A function to delete a post
|
// A function to delete a post
|
||||||
function deletepost($con)
|
function delete_demand($con)
|
||||||
{
|
{
|
||||||
if (isset($_POST['deletepost'])) {
|
if (isset($_POST['deletepost'])) {
|
||||||
global $con;
|
global $con;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
echo '<ul>
|
echo '<ul>
|
||||||
<li><a href="index.php">Logout</a></li>
|
<li><a href="index.php">Logout</a></li>
|
||||||
<li><a href="board.php">Board</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>
|
<li><a class="active" href="home.php">Home</a></li>
|
||||||
</ul>'
|
</ul>'
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -10,3 +10,7 @@ insert into users (userLogin, userPass, userEmail)
|
||||||
values ('demander','password','demander@example.com'),
|
values ('demander','password','demander@example.com'),
|
||||||
('provider','password','provider@example.com'),
|
('provider','password','provider@example.com'),
|
||||||
('admin','password','admin@example.com');
|
('admin','password','admin@example.com');
|
||||||
|
|
||||||
|
insert into quality (qualityName)
|
||||||
|
values ('new'),
|
||||||
|
('used');
|
||||||
|
|
|
@ -31,16 +31,25 @@ CREATE TABLE if not exists `tags` (
|
||||||
`text` varchar(50) NOT NULL
|
`text` varchar(50) NOT NULL
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) 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` (
|
CREATE TABLE if not exists `demands` (
|
||||||
`demandId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
`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,
|
`piecesMin` int(11) NOT NULL,
|
||||||
`piecesMax` int(11) DEFAULT NULL,
|
`piecesMax` int(11) DEFAULT NULL,
|
||||||
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
`qualityId` int(11) NOT NULL,
|
||||||
`userId` int(11) NOT NULL,
|
`userId` int(11) NOT NULL,
|
||||||
`tagId` int(11) NULL,
|
`tagId` int(11) NULL,
|
||||||
CONSTRAINT `fk_demands_userId`
|
CONSTRAINT `fk_demands_userId`
|
||||||
FOREIGN KEY (userId) REFERENCES users (userId),
|
FOREIGN KEY (userId) REFERENCES users (userId),
|
||||||
|
CONSTRAINT `fk_demands_qualityId`
|
||||||
|
FOREIGN KEY (qualityId) REFERENCES quality (qualityId),
|
||||||
CONSTRAINT `fk_tagId`
|
CONSTRAINT `fk_tagId`
|
||||||
FOREIGN KEY (tagId) REFERENCES tags (tagId)
|
FOREIGN KEY (tagId) REFERENCES tags (tagId)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
Loading…
Reference in New Issue