diff --git a/public/listing.php b/public/listing.php
index c4ed9cf..2dddf7e 100644
--- a/public/listing.php
+++ b/public/listing.php
@@ -2,16 +2,49 @@
session_start();
require_once '../functions.php';
$pageTitle = 'iBuy - Product Listing';
+
+$listing = getListing();
+
+$pdo = startDB();
+if (isset($_POST['bidSubmit'])) {
+ $stmt = $pdo->prepare('INSERT INTO bids(amount, user_id, listing_id)
+ VALUES(:amount, :user_id, :listing_id)');
+ $values = [
+ 'amount' => $_POST['bid'],
+ 'user_id' => $_SESSION['loggedin'],
+ 'listing_id' => $listing['listing_id']
+ ];
+ $stmt->execute($values);
+}
+else if (isset($_POST['reviewSubmit'])) {
+ $stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
+ $values = [
+ 'email' => $listing['email']
+ ];
+ $stmt->execute($values);
+ $user = $stmt->fetch();
+
+ $stmt = $pdo->prepare('INSERT INTO review (review_user, review_date, review_contents, user_id)
+ VALUES (:review_user, :review_date, :review_contents, :user_id)');
+ $values = [
+ 'review_user' => $_SESSION['loggedin'],
+ 'review_date' => date('Y-m-d'),
+ 'review_contents' => $_POST['reviewtext'],
+ 'user_id' => $user['user_id']
+ ];
+ $stmt->execute($values);
+}
+
$pageContent = '
Product Page
-'. populateContent() .'';
+'. populateContent($listing) .'';
require '../layout.php';
checkListing();
-function populateContent() {
+
+function populateContent($listing) {
$pdo = startDB();
- $listing = getListing();
$stmt = $pdo->prepare('SELECT * FROM category WHERE category_id = :category_id');
$values = [
@@ -41,40 +74,58 @@ function populateContent() {
Auction created by '. $user['first_name'].$user['last_name'] .'
Current bid: '. $bid['MAX(amount)'] .'
-
'. $listing['description'] .'
-
+ ';
-
- Reviews of User.Name
-
- - Ali said great ibuyer! Product as advertised and delivery was quick 29/09/2019
- - Dave said disappointing, product was slightly damaged and arrived slowly.22/07/2019
- - Susan said great value but the delivery was slow 22/07/2019
+ $output .= '
+ Reviews of '. $user['first_name'].$user['last_name'].'
+ '. getReviews($user['user_id']) .'
-
-
-
';
+
+
if($user['user_id'] === $_SESSION['loggedin']) {
$output .= 'edit';
}
return $output;
}
+
+function getReviews($user_id) {
+ $pdo = startDB();
+ $output = '';
+ $stmt = $pdo->prepare('SELECT * FROM review WHERE user_id = :user_id');
+ $values = [
+ 'user_id' => $user_id
+ ];
+ $stmt->execute($values);
+ $reviews = $stmt->fetchAll();
+
+
+
+ foreach ($reviews as &$review) {
+ $stmt = $pdo->prepare('SELECT * FROM users WHERE user_id = :user_id');
+ $values = [
+ 'user_id' => $review['review_user']
+ ];
+ $stmt->execute($values);
+ $user = $stmt->fetch();
+ $output .= ''.$user['first_name'].$user['last_name'].' said '.$review['review_content'].' '. $review['review_date'] .'';
+ }
+}
+
?>
-//TODO: add functionality for bid form
-//TODO: add functionality for review form
//TODO: add bid history
\ No newline at end of file