diff --git a/layout.php b/layout.php index 62fa402..d03ccfc 100644 --- a/layout.php +++ b/layout.php @@ -1,3 +1,13 @@ +Logout'; +} +else { + $logButton = 'href="account/login.php">Login'; +} +?> + @@ -6,29 +16,36 @@ echo $pageTitle ?> - +
-

ibuy

+

ibuy

+
Banner diff --git a/public/account/login.php b/public/account/login.php index e69de29..031a3b4 100644 --- a/public/account/login.php +++ b/public/account/login.php @@ -0,0 +1,35 @@ +Don\'t have an account?Click here to register

+

Login

+
+ + + +
'; +$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''; + if ($user['admin'] === 'y') { + $_SESSION['loggedin'] = 'y'; + } + } + else { + echo '

Unsuccessful Login

'; + } +} +?> \ No newline at end of file diff --git a/public/account/logout.php b/public/account/logout.php index e69de29..af49c50 100644 --- a/public/account/logout.php +++ b/public/account/logout.php @@ -0,0 +1,6 @@ +Logged Out

'; +?> \ No newline at end of file diff --git a/public/account/register.php b/public/account/register.php index e69de29..8efff36 100644 --- a/public/account/register.php +++ b/public/account/register.php @@ -0,0 +1,37 @@ +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 = '

Already have an account?Click here to Login

+

Register

+
+ + + + + +
'; +require '../../layout.php'; + +if (isset($_POST['submit'])) { + addUser(); + echo '

Successful account creation

'; +} +?> \ No newline at end of file diff --git a/public/account/settings.php b/public/account/settings.php new file mode 100644 index 0000000..e69de29 diff --git a/public/index.php b/public/index.php index aed9c78..6bdd75b 100644 --- a/public/index.php +++ b/public/index.php @@ -1,7 +1,6 @@ '.$pageHeading.' -'; +'; 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 .= '
  • product name
    -

    Product name

    -

    Product category

    -

    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.

    -

    Current bid: £123.45

    - More >> +

    '. $listing['listing_name'] .'

    +

    '. $listing['listing_category'] .'

    +

    '. $listing['listing_description'] .'

    +

    Current bid:'. $stmt->fetch()['MAX(amount)'] .'

    + More >>
    -
  • '; + '; } + + + return $output; } ?> \ No newline at end of file diff --git a/public/listing.php b/public/listing.php index 3d1c473..abf77c9 100644 --- a/public/listing.php +++ b/public/listing.php @@ -2,42 +2,81 @@ $pageTitle = 'iBuy - Product Listing'; //TODO: have page populate information based on listing in the database $pageContent = '

    Product Page

    -
    +
    '. populateContent() .'
    '; - product name -
    -

    Product name

    -

    Product category

    -

    Auction created by User.Name

    -

    Current bid: £123.45

    - -
    - - -
    -
    -
    -

    - 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.

    +require '../layout.php'; -
    -
    -

    Reviews of User.Name

    - + $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(); -
    - + $stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email'); + $values = [ + 'email' => $listing['listing_email'] + ]; + $stmt->execute($values); + $user = $stmt->fetch(); - -
    -
    -
    '; -require '../layout.php' + $output = ' product name +
    +

    '. $listing['listing_name'] .'

    +

    '. $category['category_name'] .'

    +

    Auction created by '. $user['first_name'].$user['last_name'] .'

    +

    Current bid: '. $bid['MAX(amount)'] .'

    + +
    + + +
    +
    +
    +

    '. $listing['listing_description'] .'

    + + +
    + +
    +

    Reviews of User.Name

    + + +
    + + + +
    +
    '; + + return $output; +} ?> \ No newline at end of file