From f2a79e6506b9e902ea7e62c460c9a616192ecb42 Mon Sep 17 00:00:00 2001 From: Joshua Perry <45966243+jpez-development@users.noreply.github.com> Date: Sun, 20 Nov 2022 15:38:33 +0000 Subject: [PATCH] added reviews and bids --- public/listing.php | 91 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 20 deletions(-) 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

- - -
+ - - +
'; + + 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