commit
2b0f20ae20
37
layout.php
37
layout.php
|
|
@ -1,3 +1,13 @@
|
|||
<?php
|
||||
session_start();
|
||||
if (isset($_SESSION['loggedin'])) {
|
||||
$logButton = 'href="account/logout.php">Logout';
|
||||
}
|
||||
else {
|
||||
$logButton = 'href="account/login.php">Login';
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -6,29 +16,36 @@
|
|||
echo $pageTitle
|
||||
?>
|
||||
</title>
|
||||
<link rel="stylesheet" href="assets/ibuy.css" />
|
||||
<link rel="stylesheet" href="../assets/ibuy.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="index.php"><span class="i">i</span><span class="b">b</span><span class="u">u</span><span class="y">y</span></a></h1>
|
||||
<h1><a href="../index.php"><span class="i">i</span><span class="b">b</span><span class="u">u</span><span class="y">y</span></a></h1>
|
||||
|
||||
<form action="#">
|
||||
<input type="text" name="search" placeholder="Search for anything" />
|
||||
<input type="submit" name="submit" value="Search" />
|
||||
</form>
|
||||
|
||||
</header>
|
||||
|
||||
<nav> <!--TODO: Populate this list from the categories defined by the admins-->
|
||||
<ul>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Home+%26+Garden">Home & Garden</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Electronics">Electronics</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Fashion">Fashion</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Sport">Sport</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Health">Health</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Toys">Toys</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Motors">Motors</a></li>
|
||||
<li><a class="categoryLink" href="categories.php">More</a></li>
|
||||
<?php
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
$stmt = $pdo->prepare('SELECT * FROM categories');
|
||||
$stmt->execute();
|
||||
$cats = $stmt->fetchAll();
|
||||
foreach ($cats as &$cat) {
|
||||
echo '<li><a class="categoryLink" href="../index.php?pageHeading='. urlencode($cat['category_name']) .'">'. $cat['category_name'] .'</a></li>';
|
||||
}
|
||||
?>
|
||||
<li><a class="categoryLink" <?php echo $logButton?></a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<img src="../assets/banners/1.jpg" alt="Banner" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
$pageTitle = 'iBuy - Login';
|
||||
$pageContent = '<p>Don\'t have an account?<a href=\'register.php\'>Click here to register</a></p>
|
||||
<h1>Login</h1>
|
||||
<form action="login.php" method="POST">
|
||||
<label>Email</label> <input name="email" type="text" />
|
||||
<label>Password</label> <input name="password" type="text" />
|
||||
<input name="submit" type="submit" value="Submit" />
|
||||
</form>';
|
||||
$stylesheet = '../assets/ibuy.css';
|
||||
require '../../layout.php';
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
if (isset($_POST['submit'])) {
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
|
||||
$values = [
|
||||
'email' => $_POST['email']
|
||||
];
|
||||
$stmt->execute($values);
|
||||
$user = $stmt->fetch();
|
||||
if (password_verify($_POST['password'], $user['password'])) {
|
||||
$_SESSION['loggedin'] = $user['user_id'];
|
||||
echo'<script>window.location.href = "../index.php";</script>';
|
||||
if ($user['admin'] === 'y') {
|
||||
$_SESSION['loggedin'] = 'y';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo '<p>Unsuccessful Login</p>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
session_start();
|
||||
unset($_SESSION['loggedin']);
|
||||
header('Location: ../index.php');
|
||||
echo '<p>Logged Out</p>';
|
||||
?>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
function addUser() {
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
|
||||
$stmt = $pdo->prepare('INSERT INTO users (first_name, last_name, email, password, admin)
|
||||
VALUES (:first_name, :last_name, :email, :password, :admin)');
|
||||
$values = [
|
||||
'first_name' => $_POST['first_name'],
|
||||
'last_name' => $_POST['last_name'],
|
||||
'email' => $_POST['email'],
|
||||
'admin' => 'n',
|
||||
'password' => password_hash($_POST['password'], PASSWORD_DEFAULT)
|
||||
];
|
||||
$stmt->execute($values);
|
||||
}
|
||||
|
||||
$pageTitle = 'iBuy - Register';
|
||||
$pageContent = '<p>Already have an account?<a href=\'login.php\'>Click here to Login</a></p>
|
||||
<h1>Register</h1>
|
||||
<form action="register.php" method="POST">
|
||||
<label>First Name</label> <input name="first_name" type="text" />
|
||||
<label>Last Name</label> <input name="last_name" type="text" />
|
||||
<label>Email</label> <input name="email" type="text" />
|
||||
<label>Password</label> <input name="password" type="text" />
|
||||
<input name="submit" type="submit" value="Submit" />
|
||||
</form>';
|
||||
require '../../layout.php';
|
||||
|
||||
if (isset($_POST['submit'])) {
|
||||
addUser();
|
||||
echo '<p>Successful account creation</p>';
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
//Listing display page. Display the 10 auctions finishing soonest
|
||||
//Can be used for index, search page, and category listing
|
||||
|
||||
$pageTitle = 'iBuy - Home';
|
||||
|
||||
if (isset($_GET['pageHeading'])) {
|
||||
|
|
@ -12,23 +11,53 @@ else {
|
|||
}
|
||||
|
||||
$pageContent = '<h1>'.$pageHeading.'</h1>
|
||||
<ul class="productList">'.populateList().'</ul>';
|
||||
<ul class="productList">'.populateList($pageHeading).'</ul>';
|
||||
require '../layout.php';
|
||||
|
||||
function populateList() { //TODO: This will need to be updated to populate from the database
|
||||
|
||||
function populateList($category) { //TODO: This will need to be updated to populate from the database
|
||||
$output = '';
|
||||
for ($i = 0; $i <= 10; $i++) {
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
|
||||
if ($category === 'Latest Listings') {
|
||||
$stmt = $pdo->prepare('SELECT * FROM listings WHERE listing_deadline > "'. date("Y-m-d H:i:s"). '" ORDER BY listing_deadline DESC');
|
||||
$stmt->execute();
|
||||
$listings = $stmt->fetchAll();
|
||||
}
|
||||
else {
|
||||
$stmt = $pdo->prepare('SELECT * FROM listings WHERE listing_category = (SELECT category_id FROM categories WHERE category_name = :listing_category)');
|
||||
$values = [
|
||||
'listing_category' => $category
|
||||
];
|
||||
$stmt->execute($values);
|
||||
$listings = $stmt->fetchAll();
|
||||
}
|
||||
|
||||
foreach ($listings as &$listing) {
|
||||
$stmt = $pdo->prepare('SELECT MAX(amount) FROM bids WHERE listing_id = :listing_id');
|
||||
$values = [
|
||||
'listing_id' => $listing['listing_id']
|
||||
];
|
||||
$stmt->execute($values);
|
||||
|
||||
$output .= '<li>
|
||||
<img src="assets/product.png" alt="product name">
|
||||
<article>
|
||||
<h2>Product name</h2>
|
||||
<h3>Product category</h3>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sodales ornare purus, non laoreet dolor sagittis id. Vestibulum lobortis laoreet nibh, eu luctus purus volutpat sit amet. Proin nec iaculis nulla. Vivamus nec tempus quam, sed dapibus massa. Etiam metus nunc, cursus vitae ex nec, scelerisque dapibus eros. Donec ac diam a ipsum accumsan aliquet non quis orci. Etiam in sapien non erat dapibus rhoncus porta at lorem. Suspendisse est urna, egestas ut purus quis, facilisis porta tellus. Pellentesque luctus dolor ut quam luctus, nec porttitor risus dictum. Aliquam sed arcu vehicula, tempor velit consectetur, feugiat mauris. Sed non pellentesque quam. Integer in tempus enim.</p>
|
||||
<p class="price">Current bid: £123.45</p>
|
||||
<a href="listing.php" class="more auctionLink">More >></a>
|
||||
<h2>'. $listing['listing_name'] .'</h2>
|
||||
<h3>'. $listing['listing_category'] .'</h3>
|
||||
<p>'. $listing['listing_description'] .'</p>
|
||||
<p class="price">Current bid:'. $stmt->fetch()['MAX(amount)'] .'</p>
|
||||
<a href="listing.php?listing_id='. $listing['listing_id'] .'" class="more auctionLink">More >></a>
|
||||
</article>
|
||||
</li>';
|
||||
</li>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
?>
|
||||
|
|
@ -2,42 +2,81 @@
|
|||
$pageTitle = 'iBuy - Product Listing';
|
||||
//TODO: have page populate information based on listing in the database
|
||||
$pageContent = '<h1>Product Page</h1>
|
||||
<article class="product">
|
||||
<article class="product">'. populateContent() .'</article>';
|
||||
|
||||
<img src="product.png" alt="product name">
|
||||
<section class="details">
|
||||
<h2>Product name</h2>
|
||||
<h3>Product category</h3>
|
||||
<p>Auction created by <a href="#">User.Name</a></p>
|
||||
<p class="price">Current bid: £123.45</p>
|
||||
<time>Time left: 8 hours 3 minutes</time>
|
||||
<form action="#" class="bid">
|
||||
<input type="text" name="bid" placeholder="Enter bid amount" />
|
||||
<input type="submit" value="Place bid" />
|
||||
</form>
|
||||
</section>
|
||||
<section class="description">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sodales ornare purus, non laoreet dolor sagittis id. Vestibulum lobortis laoreet nibh, eu luctus purus volutpat sit amet. Proin nec iaculis nulla. Vivamus nec tempus quam, sed dapibus massa. Etiam metus nunc, cursus vitae ex nec, scelerisque dapibus eros. Donec ac diam a ipsum accumsan aliquet non quis orci. Etiam in sapien non erat dapibus rhoncus porta at lorem. Suspendisse est urna, egestas ut purus quis, facilisis porta tellus. Pellentesque luctus dolor ut quam luctus, nec porttitor risus dictum. Aliquam sed arcu vehicula, tempor velit consectetur, feugiat mauris. Sed non pellentesque quam. Integer in tempus enim.</p>
|
||||
require '../layout.php';
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
<section class="reviews">
|
||||
<h2>Reviews of User.Name </h2>
|
||||
<ul>
|
||||
<li><strong>Ali said </strong> great ibuyer! Product as advertised and delivery was quick <em>29/09/2019</em></li>
|
||||
<li><strong>Dave said </strong> disappointing, product was slightly damaged and arrived slowly.<em>22/07/2019</em></li>
|
||||
<li><strong>Susan said </strong> great value but the delivery was slow <em>22/07/2019</em></li>
|
||||
function populateContent() {
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
|
||||
$stmt = $pdo->prepare('SELECT * FROM listings WHERE listing_id= :listing_id');
|
||||
$values = [
|
||||
'listing_id' => $_GET['listing_id']
|
||||
];
|
||||
$stmt->execute($values);
|
||||
$listing = $stmt->fetch();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT * FROM categories WHERE category_id = :category_id');
|
||||
$values = [
|
||||
'category_id' => $listing['listing_category']
|
||||
];
|
||||
$stmt->execute($values);
|
||||
$category = $stmt->fetch();
|
||||
|
||||
</ul>
|
||||
$stmt = $pdo->prepare('SELECT MAX(amount) FROM bids WHERE listing_id = :listing_id');
|
||||
$values = [
|
||||
'listing_id' => $listing['listing_id']
|
||||
];
|
||||
$stmt->execute($values);
|
||||
$bid = $stmt->fetch();
|
||||
|
||||
<form>
|
||||
<label>Add your review</label> <textarea name="reviewtext"></textarea>
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
|
||||
$values = [
|
||||
'email' => $listing['listing_email']
|
||||
];
|
||||
$stmt->execute($values);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
<input type="submit" name="submit" value="Add Review" />
|
||||
</form>
|
||||
</section>
|
||||
</article>';
|
||||
require '../layout.php'
|
||||
$output = ' <img src="product.png" alt="product name">
|
||||
<section class="details">
|
||||
<h2>'. $listing['listing_name'] .'</h2>
|
||||
<h3>'. $category['category_name'] .'</h3>
|
||||
<p>Auction created by <a href="#">'. $user['first_name'].$user['last_name'] .'</a></p>
|
||||
<p class="price">Current bid: '. $bid['MAX(amount)'] .'</p>
|
||||
<time>Time left:'. round((strtotime($listing['listing_deadline']) - strtotime(date('Y-m-d H:i:s')))/60,1 ) .' Minutes</time>
|
||||
<form action="#" class="bid">
|
||||
<input type="text" name="bid" placeholder="Enter bid amount" />
|
||||
<input type="submit" value="Place bid" />
|
||||
</form>
|
||||
</section>
|
||||
<section class="description">
|
||||
<p>'. $listing['listing_description'] .'</p>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
<section class="reviews">
|
||||
<h2>Reviews of User.Name </h2>
|
||||
<ul>
|
||||
<li><strong>Ali said </strong> great ibuyer! Product as advertised and delivery was quick <em>29/09/2019</em></li>
|
||||
<li><strong>Dave said </strong> disappointing, product was slightly damaged and arrived slowly.<em>22/07/2019</em></li>
|
||||
<li><strong>Susan said </strong> great value but the delivery was slow <em>22/07/2019</em></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<form>
|
||||
<label>Add your review</label> <textarea name="reviewtext"></textarea>
|
||||
|
||||
<input type="submit" name="submit" value="Add Review" />
|
||||
</form>
|
||||
</section>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue