Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 13.3 Code uiteindelijk product
- 13.3.1 Index.php
- <?php
- require 'connect.php';
- session_start();
- function fetchProducts($products)
- {
- if (mysqli_num_rows($products) >= 1) {
- foreach ($products as $product) {
- echo '<div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">';
- echo '<div class="productTile">';
- echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>';
- echo '<h4 class="productH4">€' . $product['price'] . ',- ' . $product['title'] . '</h4>';
- echo '<p style="background-color: white; padding: 10px;">';
- echo '<form action="/projects/itsm2/product.php?productid='.$product['ID'].'" method="post">';
- // echo '<form action="/projects/itsm2/product.php?productID=' . $product['ID'] . '">';
- echo '<button class="btn btn-primary" type="submit">Bekijken</button>';
- echo '<button class="btn btn-primary" style="float: right;">Toevoegen aan winkelwagen</button>';
- echo '</form>';
- echo '</p>';
- echo '</div>';
- echo '</div>';
- return $product;
- }
- } else {
- echo 'geen producten gevonden!';
- }
- }
- $query = "SELECT * FROM `products` WHERE id=4";
- $result = $link->query($query)->fetch_assoc();
- $query2 = "SELECT * FROM `products` WHERE id=13";
- $result2 = $link->query($query2)->fetch_assoc();
- ?>
- <html>
- <?php
- $currentpagename = 'Webshop';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'index';
- include_once('navbar.php')
- ?>
- <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
- <div class="carousel-inner" role="listbox" style="height: 400px">
- <div class="carousel-item active">
- <img class="carouselImage" src="https://www.w3schools.com/bootstrap/la.jpg" alt="First slide">
- </div>
- <div class="carousel-item">
- <img class="carouselImage" src="https://www.w3schools.com/bootstrap/ny.jpg" alt="Second slide">
- </div>
- <div class="carousel-item">
- <img class="carouselImage" src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Third slide">
- </div>
- </div>
- <a class="carousel-control-prev" href="#carouselExampleSlidesOnly" role="button" data-slide="prev">
- <span class="carousel-control-prev-icon" aria-hidden="true"></span>
- <span class="sr-only">Previous</span>
- </a>
- <a class="carousel-control-next" href="#carouselExampleSlidesOnly" role="button" data-slide="next">
- <span class="carousel-control-next-icon" aria-hidden="true"></span>
- <span class="sr-only">Next</span>
- </a>
- </div>
- <div class="featuredProductsView container">
- <div class="row">
- <div class="col-sm-6 col-sm-offset-1">
- <?php echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $result['image'] . ');"></p>';?>
- <a style="color: black;" href="product.php?productid=4"><h2>€<?php echo $result['price'] . ",-" . $result['title'] ?></h2></a>
- </div>
- <div class="col-sm-6 col-sm-offset-1">
- <?php echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $result2['image'] . ');"></p>';?>
- <a style="color: black;" href="product.php?productid=13"><h2><?php echo $result2['price'] . ", " . $result2['title'] ?></h2></a>
- </div>
- </div>
- </div>
- </body>
- </html>
- 13.3.2 Products.php
- <?php
- require('connect.php');
- $formal = 1;
- $sneakers = 1;
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- if ($_POST['inputFormal'] == 1) {
- $formal = 1;
- } else {
- $formal = 0;
- }
- if ($_POST['inputSneakers'] == 1) {
- $sneakers = 1;
- } else {
- $sneakers = 0;
- }
- }
- session_start();
- // order formal & sneakers both set
- if ($formal == 1 && $sneakers == 1) {
- $products = mysqli_query($link, 'select * from products order by rand()');
- } else if ($formal == 0 && $sneakers == 1) {
- $products = mysqli_query($link, 'select * from products WHERE formeel = 0 order by rand()');
- } else if ($formal == 1 && $sneakers == 0) {
- $products = mysqli_query($link, 'select * from products WHERE formeel = 1 order by rand()');
- } else {
- $products = mysqli_query($link, 'select * from products order by rand()');
- }
- function fetchProducts($products)
- {
- if (mysqli_num_rows($products) >= 1) {
- foreach ($products as $product) {
- echo '<div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">';
- echo '<div class="productTile">';
- echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>';
- echo '<h4 class="productH4">€' . $product['price'] . ',- ' . $product['title'] . '</h4>';
- echo '<p style="background-color: white; padding: 10px;">';
- echo '<form action="/projects/itsm2/product.php?productid='.$product['ID'].'" method="post">';
- // echo '<form action="/projects/itsm2/product.php?productID=' . $product['ID'] . '">';
- echo '<button class="btn btn-primary" type="submit">Bekijken</button>';
- echo '</form>';
- echo '</p>';
- echo '</div>';
- echo '</div>';
- }
- } else {
- echo 'geen producten gevonden!';
- }
- }
- ?>
- <html>
- <?php
- $currentpagename = 'Producten';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'products';
- include_once('navbar.php')
- ?>
- <div class="featuredProductsView container">
- <form method="post" action="">
- <div class="form-row">
- <label for="inputFormal">Formeel</label>
- <input type="hidden" name="inputFormal" value="0" />
- <input type="checkbox" class="form-control form-check-input" name="inputFormal" value="1">
- </div>
- <div class="form-row">
- <label for="inputSneakers">Sneakers</label>
- <input type="hidden" name="inputSneakers" value="0" />
- <input type="checkbox" class="form-control form-check-input" name="inputSneakers" value="1">
- </div>
- <div class="form-row">
- <input type="submit" class="btn btn-warning" value="Filteren" />
- </div>
- </form>
- <div class="row">
- <?php
- fetchProducts($products);
- ?>
- </div>
- </div>
- </html>
- 13.3.3 Product.php
- <?php
- require 'connect.php';
- session_start();
- $productID = $_GET['productid'];
- $result = "select * from products where id=$productID";
- $product = $link->query($result)->fetch_assoc();
- $inserted = false;
- if(isset($_POST['productid']) && isset($_POST['quantity'])) {
- // Check if shopping cart exists
- if(!isset($_SESSION['shopping_cart']) && empty($_SESSION['shopping_cart'])) {
- // Create new shopping cart array, insert product
- $_SESSION['shopping_cart'] = array(
- array('productid' => $_POST['productid'], 'quantity' => $_POST['quantity'])
- );
- // Shopping cart exists
- } else {
- $found = false;
- // Loop through products
- foreach ($_SESSION['shopping_cart'] as $arr => $prod) {
- // Check if product is already included
- if ($prod['productid'] == $_POST['productid']) {
- // Product already exists
- $found = true;
- // Add posted quantity to previously set quantity
- $counted = $prod['quantity'] + $_POST['quantity'];
- // Update quantity
- $_SESSION['shopping_cart'][$arr]['quantity'] = +$counted;
- } else {
- // Product doesn't exist yet
- $found = false;
- }
- }
- // If product doesn't exist yet
- if (!$found) {
- // Insert new product into already existing shopping cart array
- array_push($_SESSION['shopping_cart'], array('productid' => $_POST['productid'], 'quantity' => $_POST['quantity']));
- }
- }
- $inserted = true;
- }
- ?>
- <html>
- <?php
- $currentpagename = 'Product';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'product';
- include_once('navbar.php')
- ?>
- <div class="detailedProductView container">
- <?php
- if($inserted === true) {
- echo '<div class="alert alert-success">';
- echo '<strong>Succes!</strong> Product toegevoegd aan winkelwagen.';
- echo '</div>';
- }
- ?>
- <div class="row">
- <div class="col-sm-6 col-sm-offset-1">
- <?php echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>'; ?>
- </div>
- <div class="col-sm-6 col-sm-offset-1">
- <form method="post" action="">
- <p class="detailedProductDescription"><?php echo $product['description']; ?></p>
- <h2 class="detailedProductDetails"><?php echo $product['title']; ?></h2>
- <input type="hidden" name="productid" id="hiddenField" value="<?php echo $productID ?>" />
- <div class="detailedProductOptions">
- <p>Prijs: €<?php echo $product['price'] ?></p>
- <p>Aantal: <input type="text" name="quantity" value="1" size="2" /><input type="submit" style="margin-left: 5px;" class="btn btn-primary" value="In winkelwagen" /></p>
- </div>
- </form>
- </div>
- </div>
- </div>
- </html>
- 13.3.4 Addproduct.php
- <?php
- require 'connect.php';
- session_start();
- $inserted = false;
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- // Define variables
- $title = $_POST["inputTitle"];
- $description = $_POST['inputDescription'];
- $image = 'images/' . $_POST['inputImage'];
- $price = $_POST['inputPrice'];
- if($_POST['inputFormal'] == 1) {
- $formal = 1;
- } else {
- $formal = 0;
- }
- // Check if product exists
- $result = mysqli_query($link, 'select * from products where title= "$title"');
- if(mysqli_num_rows($result) == 0) {
- // Add product
- $insert = mysqli_query($link, "insert into products (title, description, image, price, formeel) VALUES ('$title', '$description', '$image', '$price', '$formal')");
- if($insert)
- {
- $inserted = true;
- } else {
- $inserted = false;
- }
- } else {
- echo 'Product bestaat al!';
- }
- }
- ?>
- <html>
- <?php
- $currentpagename = 'Product toevoegen';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'addproduct';
- include_once('navbar.php')
- ?>
- <div class="container">
- <div class="row">
- <div class="col-md-4"></div>
- <form class="col-md-4 registerContainer" method="post" action="addproduct.php">
- <?php
- if($inserted === true) {
- echo '<div class="alert alert-success">';
- echo '<strong>Succes!</strong> Product toegevoegd.';
- echo '</div>';
- }
- ?>
- <div class="form-row">
- <div class="form-group col-md-8">
- <label for="inputTitle">Productnaam</label>
- <input type="text" class="form-control" name="inputTitle" required>
- </div>
- <div class="form-group col-md-4">
- <label for="inputDescription">Beschrijving</label>
- <input type="text" class="form-control" name="inputDescription">
- </div>
- </div>
- <div class="form-group">
- <label for="inputImage">Afbeelding</label>
- <input type="text" class="form-control" name="inputImage" placeholder="Bestandsnaam.extensie">
- </div>
- <div class="form-row">
- <div class="form-group col-md-9">
- <label for="inputPrice">Prijs</label>
- <input type="text" class="form-control" name="inputPrice" required>
- </div>
- <div class="form-group col-md-3">
- <label class="form-check-label" for="inputFormal">Formeel</label>
- <input type="hidden" name="inputFormal" value="0" />
- <input type="checkbox" class="form-control form-check-input" name="inputFormal" value="1">
- </div>
- </div>
- <input type="submit" class="btn btn-primary" value="Toevoegen" />
- </form>
- </div>
- </div>
- </html>
- 13.3.5 Sale.php
- <?php
- require('connect.php');
- session_start();
- $products = mysqli_query($link, 'select * from products WHERE aanbieding = 1');
- function fetchProducts($products)
- {
- if (mysqli_num_rows($products) >= 1) {
- foreach ($products as $product) {
- echo '<div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">';
- echo '<div class="productTile">';
- echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>';
- echo '<h4 class="productH4">€' . $product['price'] . ',- ' . $product['title'] . '</h4>';
- echo '<p style="background-color: white; padding: 10px;">';
- echo '<form action="/projects/itsm2/product.php?productid='.$product['ID'].'" method="post">';
- echo '<button class="btn btn-primary" type="submit">Bekijken</button>';
- echo '</form>';
- echo '</p>';
- echo '</div>';
- echo '</div>';
- }
- } else {
- echo 'geen producten gevonden!';
- }
- }
- ?>
- <html>
- <?php
- $currentpagename = 'Aanbiedingen';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'sale';
- include_once('navbar.php')
- ?>
- <div class="featuredProductsView container">
- <div class="row">
- <?php
- fetchProducts($products);
- ?>
- </div>
- </div>
- </html>
- 13.3.6 Contact.php
- <?php
- require('connect.php');
- session_start();
- ?>
- <html>
- <?php
- $currentpagename = 'Contact';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'contact';
- include_once('navbar.php');
- ?>
- <div class="container featuredProductsView">
- <div class="row">
- <div class="col-md-3"></div>
- <div class="col-md-6">
- <h1>Contact opnemen</h1>
- </div>
- </div>
- <div class="row">
- <div class="col-md-3"></div>
- <div class="col-md-6 registerContainer">
- <p>E-mail: onzeemail@webmail.com</p>
- <p>Telefoon: 05437268362</p>
- <p>Adres: Vuurhoutstraat 34, Enschede, Overijssel, Nederland</p>
- </div>
- </div>
- </div>
- </body>
- </html>
- 13.3.7 Login.php
- <?php
- require 'connect.php';
- if(isset($_SESSION['login_id'])) {
- // Do nothing
- } else {
- session_start();
- }
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- // Define variables
- $email = $_POST['inputEmail'];
- $password = $_POST['inputPassword'];
- // Fetch user
- $result = mysqli_query($link, "SELECT * FROM `users` where email = 'wesseloblink@hotmail.com' && password = 'Winterswijkdebeste33'");
- // Check if user exists
- if(mysqli_num_rows($result) == 1) {
- // Define user
- $user = $result->fetch_assoc();
- // Maak sessie aan
- if(!isset($_SESSION)) {
- session_start();
- }
- // Vul sessie
- $_SESSION['login_id'] = $user['ID'];
- $_SESSION['login_name'] = $user['first_name'];
- } else {
- echo 'Gebruiker bestaat niet!';
- }
- }
- ?>
- <html>
- <?php
- $currentpagename = 'Inloggen';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'login';
- include_once('navbar.php')
- ?>
- <div class="container">
- <div class="row">
- <div class="col-md-4"></div>
- <form class="col-md-4 registerContainer" method="post" action="login.php">
- <?php
- if(isset($_SESSION['login_id'])) {
- echo '<div class="alert alert-success">';
- echo '<strong>Succes!</strong> Je bent ingelogd.';
- echo '</div>';
- }
- ?>
- <div class="form-group">
- <label for="inputEmail">Emailaddres</label>
- <input type="email" class="form-control" name="inputEmail" required>
- </div>
- <div class="form-group">
- <label for="inputPassword">Wachtwoord</label>
- <input type="password" class="form-control" name="inputPassword" required>
- </div>
- <input type="submit" class="btn btn-primary" value="Inloggen" />
- <a type="button" class="btn" href="register.php" style="float: right;">Registreren</a>
- </form>
- </div>
- </div>
- </html>
- 13.3.8 Register.php
- <?php
- require 'connect.php';
- session_start();
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- // Define variables
- $firstName = $_POST["inputFirstname"];
- $middleName = $_POST['inputMiddlename'];
- $lastName = $_POST['inputFirstname'];
- $street = $_POST['inputFirstname'];
- $house = $_POST['inputFirstname'];
- $address = $street . " " . $house;
- $phone = $_POST['inputFirstname'];
- $mobile = $_POST['inputFirstname'];
- $city = $_POST['inputFirstname'];
- $zipcode = $_POST['inputFirstname'];
- $province = $_POST['inputFirstname'];
- $email = $_POST['inputFirstname'];
- $password = $_POST['inputFirstname'];
- // Check if user exists
- $result = mysqli_query($link, 'select * from users where email= "$email"');
- if(mysqli_num_rows($result) == 0) {
- // Register user
- $insert = mysqli_query($link, "insert into users (first_name, middle_name, last_name, address, phone, mobile, zipcode, city, province, password, email) VALUES ('$firstName', '$middleName', '$lastName', '$address', '$phone', '$mobile', '$zipcode', '$city', '$province', '$password', '$email')");
- if($insert)
- {
- echo 'Toegevoegd!';
- } else {
- echo 'Mislukt!';
- }
- } else {
- echo 'Email al gebruikt!';
- }
- }
- ?>
- <html>
- <?php
- $currentpagename = 'Registreren';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'register';
- include_once('navbar.php')
- ?>
- <div class="container">
- <div class="row">
- <div class="col-md-4"></div>
- <form class="col-md-4 registerContainer" method="post" action="register.php">
- <div class="form-row">
- <div class="form-group col-md-8">
- <label for="inputFirstname">Voornaam *</label>
- <input type="text" class="form-control" name="inputFirstname" placeholder="Voornaam" required>
- </div>
- <div class="form-group col-md-4">
- <label for="inputMiddlename">Tussenvoegsel</label>
- <input type="text" class="form-control" name="inputMiddlename" placeholder="">
- </div>
- </div>
- <div class="form-group">
- <label for="inputLastname">Achternaam *</label>
- <input type="text" class="form-control" name="inputLastname" placeholder="Achternaam" required>
- </div>
- <div class="form-row">
- <div class="form-group col-md-9">
- <label for="inputStreet">Straat</label>
- <input type="text" class="form-control" name="inputStreet" placeholder="Straat" required>
- </div>
- <div class="form-group col-md-3">
- <label for="inputHouse">Huisnummer</label>
- <input type="text" class="form-control" name="inputHouse" placeholder="Huisnr" required>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-6">
- <label for="inputPhone">Huistelefoonnummer *</label>
- <input type="text" class="form-control" name="inputPhone" placeholder="Huistelefoonnr">
- </div>
- <div class="form-group col-md-6">
- <label for="inputMobile">Mobieletelefoonnummer</label>
- <input type="text" class="form-control" name="inputMobile" placeholder="06- nummer">
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-8">
- <label for="inputCity">Woonplaats *</label>
- <input type="text" class="form-control" name="inputZipcode" placeholder="Woonplaats">
- </div>
- <div class="form-group col-md-4">
- <label for="inputZipcode">Postcode *</label>
- <input type="text" class="form-control" name="inputZipcode" placeholder="Postcode">
- </div>
- </div>
- <div class="form-group">
- <label for="inputProvince">Provincie *</label>
- <input type="text" class="form-control" name="inputProvince" placeholder="Provincie">
- </div>
- <div class="form-group">
- <label for="inputEmail">Emailaddres *</label>
- <input type="email" class="form-control" name="inputEmail" aria-describedby="emailHelp" placeholder="Bijvoorbeeld henk@jans.nl" required>
- </div>
- <div class="form-group">
- <label for="inputPassword">Wachtwoord *</label>
- <input type="password" class="form-control" name="inputPassword" placeholder="Password" required>
- </div>
- <input type="submit" class="btn btn-primary" value="Registreren" />
- </form>
- </div>
- </div>
- </html>
- 13.3.9 Logout.php
- <?php
- session_start();
- unset($_SESSION['login_id']);
- header('Location: index.php');
- 13.3.10 Connect.php
- <?php
- ini_set('display_errors', 1);
- error_reporting(E_ALL);
- $link = mysqli_connect("localhost", "root", "", "webshop");
- 13.3.11 Basket.php
- <?php
- require 'connect.php';
- session_start();
- require_once 'basketHandling.php';
- if(!isset($_SESSION['login_id'])) {
- header('Location: login.php');
- }
- // TODO: get products in basket
- ?>
- <html>
- <?php
- $currentpagename = 'Winkelmand';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'basket';
- include_once('navbar.php')
- ?>
- <div class="container">
- <div class="row">
- <div class="col-md-3"></div>
- <?php
- if(!isset($_SESSION['shopping_cart'])) {
- // Basket is not set or empty
- echo '<form class="col-md-6 registerContainer" action="">';
- echo '<p>Je winkelmand is leeg!</p>';
- echo '</form>';
- } else {
- echo '<form class="col-md-6 registerContainer" action="">';
- // Basket is set
- foreach ($_SESSION['shopping_cart'] as $arr => $prod) {
- // print_r($_SESSION['shopping_cart']);
- // Fetch products based on ID
- $productID = $prod['productid'];
- $result = "select * from products where id=$productID";
- $product = $link->query($result)->fetch_assoc();
- $products[] = array('id' => $prod['productid'], 'quantity' => $prod['quantity']);
- echo '<div class="form-row">';
- echo '<div class="form-group col-md-8">';
- echo '<label>Product</label>';
- echo '<input type="text" class="form-control" name="inputProduct" value="' . $product["title"] . '" readonly />';
- echo '</div>';
- echo '</div>';
- echo '<div class="form-row">';
- echo '<div class="form-group col-md-4">';
- echo '<label>Prijs</label>';
- echo '<input type="text" class="form-control" name="inputPrice" value="€' . $product["price"] . '" readonly />';
- echo '</div>';
- echo '</div>';
- echo '<div class="form-row">';
- echo '<div class="form-group col-md-4">';
- echo '<label>Aantal</label>';
- echo '<input type="text" class="form-control" name="inputQuantity" value="' . $prod["quantity"] . '" readonly />';
- echo '</div>';
- echo '</div>';
- echo '<hr>';
- }
- echo '<a class="btn btn-primary" href="basket.php?order=true">Bestellen</a>';
- echo '<a class="btn btn-danger" href="basket.php?empty=true" style="margin-left: 10px;">Winkelmand legen</a>';
- if (isset($_GET['empty'])) {
- unset($_SESSION['shopping_cart']);
- header('Location: basket.php');
- die();
- }
- if (isset($_GET['order'])) {
- // Generate order ID
- $orderid = abs(crc32(uniqid()));
- echo 'unique id: ' . $orderid;
- // Insert order
- $query = mysqli_query($link, "insert into orders (id, notes) values ('$orderid', 'Testorder')");
- var_dump($query);
- if ($query) {
- echo 'order inserted!';
- } else {
- echo 'order not inserted.';
- }
- // Link user
- $query2 = mysqli_query($link, "insert into users_orders (orders_id, users_id) values ('$orderid', '" . $_SESSION['login_id'] . "')");
- if ($query2) {
- echo 'user order inserted!';
- } else {
- echo 'user order not inserted.';
- }
- foreach ($products as $producc) {
- // Get product ID
- echo 'ProductID = ' . $producc['id'];
- // Get product quantity
- echo 'ProductQuantity = ' . $producc['quantity'];
- // Insert product
- $query3 = mysqli_query($link, "insert into orders_products (products_id, orders_id, quantity) values ('" . $producc['id'] . "', '$orderid', '" . $producc['quantity'] . "')");
- if ($query3) {
- echo 'order products inserted!';
- } else {
- echo 'order products not inserted.';
- }
- }
- unset($_SESSION['shopping_cart']);
- header('Location: orders.php');
- die();
- }
- echo '</form>';
- }
- ?>
- </div>
- </div>
- </html>
- 13.3.12 Navbar.php
- <?php
- // Get current user
- if(isset($_SESSION['login_id'])) {
- $query = mysqli_query($link, "select * from users where id='" . $_SESSION['login_id'] . "'");
- $user = $query->fetch_assoc();
- }
- ?>
- <nav class="navbar navbar-expand-lg navbar-light bg-light">
- <a class="navbar-brand" href="index.php">Webshop</a>
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
- aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="collapse navbar-collapse" id="navbarText">
- <ul class="navbar-nav mr-auto">
- <li class="nav-item <?php if($currentpage === 'index') { echo 'active';} ?>">
- <a class="nav-link" href="index.php">Home</a>
- </li>
- <li class="nav-item <?php if($currentpage === 'products') { echo 'active';} ?>">
- <a class="nav-link" href="products.php">Producten</a>
- </li>
- <li class="nav-item <?php if($currentpage === 'sale') { echo 'active';} ?>">
- <a class="nav-link" href="sale.php">Aanbiedingen</a>
- </li>
- <li class="nav-item <?php if($currentpage === 'contact') { echo 'active';} ?>">
- <a class="nav-link" href="contact.php">Contact</a>
- </li>
- <?php
- if($currentpage != 'index' && $currentpage != 'products' && $currentpage != 'sale' && $currentpage != 'contact' ) {
- ?>
- <li class="nav-item active">
- <?php echo '<a class="nav-link" href="' . $currentpage . '.php">' . $currentpagename . '</a>'; ?>
- </li>
- <?php
- }
- ?>
- </ul>
- <ul class="navbar-nav navbar-right">
- <li class="nav-item">
- <?php
- if(isset($_SESSION['login_id'])) {
- echo '<a class="nav-link dropdown" data-toggle="dropdown" href="#">Hallo, ' . $_SESSION['login_name'] . '.</a>';
- echo '<ul class="dropdown-menu dropdown-menu-right">';
- if($user['type'] == 2) {
- echo '<li><a href="addproduct.php">Product toevoegen</a></li>';
- }
- if(isset($_SESSION['shopping_cart'])) {
- echo '<li><a href="basket.php">Winkelmand</a></li>';
- }
- echo '<li><a href="orders.php">Mijn orders</a></li>';
- echo '<li><a href="logout.php">Uitloggen</a></li>';
- echo '</ul>';
- } else {
- echo '<a class="nav-link" href="login.php">Log in</a>';
- }
- ?>
- </li>
- </ul>
- </div>
- </nav>
- 13.3.13 Orders.php
- <?php
- require('connect.php');
- // TODO: Get user ID from session
- session_start();
- include 'orderHandling.php';
- if (!isset($_SESSION['login_id'])) {
- header('Location: login.php');
- } else {
- $userID = $_SESSION['login_id'];
- ?>
- <html>
- <?php
- $currentpagename = 'Orders';
- include_once('header.php');
- ?>
- <body>
- <?php
- // Include Navbar
- $currentpage = 'orders';
- include_once('navbar.php')
- ?>
- <?php
- // TODO: Fetch orders from db
- $orderids = getOrdersFromDB($link, $userID);
- // TODO: Output order data
- for ($i = 0; $i < count($orderids); $i++) {
- $orderid = $orderids[$i]['id'];
- $order_query = mysqli_query($link, "select * from orders where id='$orderid'");
- $order = $order_query->fetch_assoc();
- }
- // TODO: Output products per order
- // Define products array
- for ($i = 0; $i < count($orderids); $i++) {
- $orderid = $orderids[$i]['id'];
- $order_query = mysqli_query($link, "select * from orders where id='$orderid'");
- $order = $order_query->fetch_assoc();
- $orders_products_query = mysqli_query($link, "select * from orders_products where orders_id='$orderid'");
- if (mysqli_num_rows($orders_products_query) > 0) {
- // Print order info
- echo '<div class="container featuredProductsView orderContainer">';
- echo '<h1>Producten voor order ' . $orderid . ' </h1>';
- echo '<div class="row">';
- while ($row = mysqli_fetch_assoc($orders_products_query)) {
- // Get products
- $products_query = mysqli_query($link, "select * from products where id='" . $row['products_id'] . "'");
- // While products
- while ($productrow = mysqli_fetch_assoc($products_query)) {
- ?>
- <div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">
- <div class="productTile">
- <p>Ordernummer: <?php echo $row['orders_id'] ?></p>
- <p>Productnaam: <?php echo $productrow["title"] ?></p>
- <p>Aantal: <?php echo $row["quantity"] ?></p>
- <p class="productTileParagraphSmall productImage"
- style="background-image: <?php echo 'url(' . $productrow["image"] . ')' ?>"></p>
- </div>
- </div>
- <?php
- }
- }
- echo '</div>';
- echo '</div>';
- }
- }
- }
- ?>
- </body>
- </html>
- 13.3.14 OrderHandling.php
- <?php
- require_once 'connect.php';
- function getOrdersFromDB($link, $userID) {
- $orderids = array();
- $orders_query = mysqli_query($link, "select orders_id from users_orders where users_id='$userID'");
- if(mysqli_num_rows($orders_query) > 0) {
- while($row = mysqli_fetch_assoc($orders_query)) {
- $responses[] = array(
- 'id' => $row['orders_id']
- );
- }
- $orderids = $responses;
- return $orderids;
- }
- return null;
- }
- 13.3.15 Header.php
- <head>
- <?php
- if(isset($currentpagename)) {
- echo '<title>'.$currentpagename.'</title>';
- } else {
- echo '<title>Webshop</title>';
- }
- ?>
- <!--Stylesheet-->
- <link rel="stylesheet" type="text/css" href="style.css">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"
- integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
- <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
- integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
- crossorigin="anonymous"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
- integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
- crossorigin="anonymous"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js"
- integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4"
- crossorigin="anonymous"></script>
- </head>
- 13.3.16 Style.css
- body {
- background-color: #f2f2f2 !important;
- }
- .carouselImage {
- width: 100%;
- height: 400px;
- }
- .productTile {
- padding: 10px;
- background-color: white;
- }
- .productH4 {
- margin-bottom: 0;
- background-color: white;
- }
- .productTileParagraphLarge {
- background-color: #f8f8f8;
- height: 400px;
- }
- .productTileParagraphSmall {
- background-color: lightgrey;
- height: 400px;
- }
- .featuredProductsView {
- margin-top: 15px;
- margin-bottom: 50px;
- }
- .col-offset-square {
- padding-top: 15px;
- padding-bottom: 15px;
- }
- .productImage {
- background-size: 100% 100%;
- margin: 0px;
- }
- .detailedProductView {
- margin-top: 50px;
- }
- .detailedProductDescription {
- background-color: white;
- padding: 5px;
- }
- .detailedProductDetails {
- margin-top: 20px;
- background-color: white;
- padding: 5px;
- }
- .detailedProductOptions {
- margin-top: 10px;
- background-color: white;
- padding: 5px;
- }
- .registerContainer {
- background-color: white;
- border: white 2px solid;
- border-radius: 5px;
- margin-top: 20px;
- padding: 5px;
- }
- .orderContainer {
- background-color: #f8f8f8;
- border: #f8f8f8 2px solid;
- border-radius: 5px;
- margin-top: 20px;
- padding: 5px;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement