Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.13 KB | None | 0 0
  1. 13.3 Code uiteindelijk product
  2. 13.3.1 Index.php
  3. <?php
  4. require 'connect.php';
  5.  
  6. session_start();
  7.  
  8. function fetchProducts($products)
  9. {
  10. if (mysqli_num_rows($products) >= 1) {
  11. foreach ($products as $product) {
  12. echo '<div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">';
  13. echo '<div class="productTile">';
  14. echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>';
  15. echo '<h4 class="productH4">&euro;' . $product['price'] . ',- ' . $product['title'] . '</h4>';
  16. echo '<p style="background-color: white; padding: 10px;">';
  17.  
  18. echo '<form action="/projects/itsm2/product.php?productid='.$product['ID'].'" method="post">';
  19. // echo '<form action="/projects/itsm2/product.php?productID=' . $product['ID'] . '">';
  20. echo '<button class="btn btn-primary" type="submit">Bekijken</button>';
  21. echo '<button class="btn btn-primary" style="float: right;">Toevoegen aan winkelwagen</button>';
  22. echo '</form>';
  23.  
  24. echo '</p>';
  25. echo '</div>';
  26. echo '</div>';
  27. return $product;
  28. }
  29. } else {
  30. echo 'geen producten gevonden!';
  31. }
  32. }
  33. $query = "SELECT * FROM `products` WHERE id=4";
  34. $result = $link->query($query)->fetch_assoc();
  35.  
  36. $query2 = "SELECT * FROM `products` WHERE id=13";
  37. $result2 = $link->query($query2)->fetch_assoc();
  38.  
  39.  
  40. ?>
  41.  
  42. <html>
  43. <?php
  44. $currentpagename = 'Webshop';
  45.  
  46. include_once('header.php');
  47. ?>
  48. <body>
  49.  
  50. <?php
  51. // Include Navbar
  52. $currentpage = 'index';
  53. include_once('navbar.php')
  54. ?>
  55.  
  56. <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
  57. <div class="carousel-inner" role="listbox" style="height: 400px">
  58. <div class="carousel-item active">
  59. <img class="carouselImage" src="https://www.w3schools.com/bootstrap/la.jpg" alt="First slide">
  60. </div>
  61. <div class="carousel-item">
  62. <img class="carouselImage" src="https://www.w3schools.com/bootstrap/ny.jpg" alt="Second slide">
  63. </div>
  64. <div class="carousel-item">
  65. <img class="carouselImage" src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Third slide">
  66. </div>
  67. </div>
  68. <a class="carousel-control-prev" href="#carouselExampleSlidesOnly" role="button" data-slide="prev">
  69. <span class="carousel-control-prev-icon" aria-hidden="true"></span>
  70. <span class="sr-only">Previous</span>
  71. </a>
  72. <a class="carousel-control-next" href="#carouselExampleSlidesOnly" role="button" data-slide="next">
  73. <span class="carousel-control-next-icon" aria-hidden="true"></span>
  74. <span class="sr-only">Next</span>
  75. </a>
  76. </div>
  77.  
  78. <div class="featuredProductsView container">
  79. <div class="row">
  80. <div class="col-sm-6 col-sm-offset-1">
  81. <?php echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $result['image'] . ');"></p>';?>
  82. <a style="color: black;" href="product.php?productid=4"><h2>&euro;<?php echo $result['price'] . ",-" . $result['title'] ?></h2></a>
  83. </div>
  84. <div class="col-sm-6 col-sm-offset-1">
  85. <?php echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $result2['image'] . ');"></p>';?>
  86. <a style="color: black;" href="product.php?productid=13"><h2><?php echo $result2['price'] . ", " . $result2['title'] ?></h2></a>
  87. </div>
  88. </div>
  89. </div>
  90.  
  91. </body>
  92. </html>
  93. 13.3.2 Products.php
  94. <?php
  95. require('connect.php');
  96.  
  97. $formal = 1;
  98. $sneakers = 1;
  99.  
  100. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  101.  
  102. if ($_POST['inputFormal'] == 1) {
  103. $formal = 1;
  104. } else {
  105. $formal = 0;
  106. }
  107.  
  108. if ($_POST['inputSneakers'] == 1) {
  109. $sneakers = 1;
  110. } else {
  111. $sneakers = 0;
  112. }
  113.  
  114. }
  115.  
  116. session_start();
  117. // order formal & sneakers both set
  118. if ($formal == 1 && $sneakers == 1) {
  119.  
  120. $products = mysqli_query($link, 'select * from products order by rand()');
  121. } else if ($formal == 0 && $sneakers == 1) {
  122.  
  123. $products = mysqli_query($link, 'select * from products WHERE formeel = 0 order by rand()');
  124. } else if ($formal == 1 && $sneakers == 0) {
  125.  
  126. $products = mysqli_query($link, 'select * from products WHERE formeel = 1 order by rand()');
  127. } else {
  128.  
  129. $products = mysqli_query($link, 'select * from products order by rand()');
  130. }
  131.  
  132. function fetchProducts($products)
  133. {
  134. if (mysqli_num_rows($products) >= 1) {
  135. foreach ($products as $product) {
  136. echo '<div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">';
  137. echo '<div class="productTile">';
  138. echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>';
  139. echo '<h4 class="productH4">&euro;' . $product['price'] . ',- ' . $product['title'] . '</h4>';
  140. echo '<p style="background-color: white; padding: 10px;">';
  141.  
  142. echo '<form action="/projects/itsm2/product.php?productid='.$product['ID'].'" method="post">';
  143. // echo '<form action="/projects/itsm2/product.php?productID=' . $product['ID'] . '">';
  144. echo '<button class="btn btn-primary" type="submit">Bekijken</button>';
  145. echo '</form>';
  146.  
  147. echo '</p>';
  148. echo '</div>';
  149. echo '</div>';
  150. }
  151. } else {
  152. echo 'geen producten gevonden!';
  153. }
  154. }
  155.  
  156. ?>
  157.  
  158. <html>
  159. <?php
  160. $currentpagename = 'Producten';
  161.  
  162. include_once('header.php');
  163. ?>
  164. <body>
  165.  
  166. <?php
  167. // Include Navbar
  168. $currentpage = 'products';
  169. include_once('navbar.php')
  170. ?>
  171.  
  172. <div class="featuredProductsView container">
  173. <form method="post" action="">
  174. <div class="form-row">
  175. <label for="inputFormal">Formeel</label>
  176. <input type="hidden" name="inputFormal" value="0" />
  177. <input type="checkbox" class="form-control form-check-input" name="inputFormal" value="1">
  178. </div>
  179. <div class="form-row">
  180. <label for="inputSneakers">Sneakers</label>
  181. <input type="hidden" name="inputSneakers" value="0" />
  182. <input type="checkbox" class="form-control form-check-input" name="inputSneakers" value="1">
  183. </div>
  184. <div class="form-row">
  185. <input type="submit" class="btn btn-warning" value="Filteren" />
  186. </div>
  187. </form>
  188. <div class="row">
  189. <?php
  190. fetchProducts($products);
  191. ?>
  192. </div>
  193. </div>
  194. </html>
  195.  
  196. 13.3.3 Product.php
  197. <?php
  198. require 'connect.php';
  199.  
  200. session_start();
  201.  
  202. $productID = $_GET['productid'];
  203. $result = "select * from products where id=$productID";
  204. $product = $link->query($result)->fetch_assoc();
  205.  
  206. $inserted = false;
  207.  
  208. if(isset($_POST['productid']) && isset($_POST['quantity'])) {
  209.  
  210. // Check if shopping cart exists
  211. if(!isset($_SESSION['shopping_cart']) && empty($_SESSION['shopping_cart'])) {
  212.  
  213. // Create new shopping cart array, insert product
  214. $_SESSION['shopping_cart'] = array(
  215. array('productid' => $_POST['productid'], 'quantity' => $_POST['quantity'])
  216. );
  217.  
  218. // Shopping cart exists
  219. } else {
  220.  
  221. $found = false;
  222.  
  223. // Loop through products
  224. foreach ($_SESSION['shopping_cart'] as $arr => $prod) {
  225.  
  226. // Check if product is already included
  227. if ($prod['productid'] == $_POST['productid']) {
  228.  
  229. // Product already exists
  230. $found = true;
  231.  
  232. // Add posted quantity to previously set quantity
  233. $counted = $prod['quantity'] + $_POST['quantity'];
  234.  
  235. // Update quantity
  236. $_SESSION['shopping_cart'][$arr]['quantity'] = +$counted;
  237. } else {
  238.  
  239. // Product doesn't exist yet
  240. $found = false;
  241. }
  242. }
  243.  
  244. // If product doesn't exist yet
  245. if (!$found) {
  246.  
  247. // Insert new product into already existing shopping cart array
  248. array_push($_SESSION['shopping_cart'], array('productid' => $_POST['productid'], 'quantity' => $_POST['quantity']));
  249. }
  250. }
  251.  
  252. $inserted = true;
  253. }
  254. ?>
  255.  
  256. <html>
  257. <?php
  258. $currentpagename = 'Product';
  259.  
  260. include_once('header.php');
  261. ?>
  262. <body>
  263. <?php
  264. // Include Navbar
  265. $currentpage = 'product';
  266. include_once('navbar.php')
  267. ?>
  268.  
  269. <div class="detailedProductView container">
  270. <?php
  271. if($inserted === true) {
  272. echo '<div class="alert alert-success">';
  273. echo '<strong>Succes!</strong> Product toegevoegd aan winkelwagen.';
  274. echo '</div>';
  275. }
  276. ?>
  277. <div class="row">
  278. <div class="col-sm-6 col-sm-offset-1">
  279. <?php echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>'; ?>
  280. </div>
  281. <div class="col-sm-6 col-sm-offset-1">
  282. <form method="post" action="">
  283. <p class="detailedProductDescription"><?php echo $product['description']; ?></p>
  284. <h2 class="detailedProductDetails"><?php echo $product['title']; ?></h2>
  285. <input type="hidden" name="productid" id="hiddenField" value="<?php echo $productID ?>" />
  286. <div class="detailedProductOptions">
  287. <p>Prijs: &euro;<?php echo $product['price'] ?></p>
  288. <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>
  289. </div>
  290. </form>
  291. </div>
  292. </div>
  293.  
  294. </div>
  295.  
  296. </html>
  297.  
  298. 13.3.4 Addproduct.php
  299. <?php
  300. require 'connect.php';
  301.  
  302. session_start();
  303.  
  304. $inserted = false;
  305.  
  306. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  307.  
  308. // Define variables
  309. $title = $_POST["inputTitle"];
  310. $description = $_POST['inputDescription'];
  311. $image = 'images/' . $_POST['inputImage'];
  312. $price = $_POST['inputPrice'];
  313. if($_POST['inputFormal'] == 1) {
  314. $formal = 1;
  315. } else {
  316. $formal = 0;
  317. }
  318.  
  319. // Check if product exists
  320. $result = mysqli_query($link, 'select * from products where title= "$title"');
  321. if(mysqli_num_rows($result) == 0) {
  322.  
  323. // Add product
  324. $insert = mysqli_query($link, "insert into products (title, description, image, price, formeel) VALUES ('$title', '$description', '$image', '$price', '$formal')");
  325. if($insert)
  326. {
  327. $inserted = true;
  328. } else {
  329. $inserted = false;
  330. }
  331. } else {
  332. echo 'Product bestaat al!';
  333. }
  334. }
  335.  
  336. ?>
  337.  
  338. <html>
  339. <?php
  340. $currentpagename = 'Product toevoegen';
  341. include_once('header.php');
  342. ?>
  343. <body>
  344. <?php
  345. // Include Navbar
  346. $currentpage = 'addproduct';
  347. include_once('navbar.php')
  348. ?>
  349.  
  350. <div class="container">
  351. <div class="row">
  352. <div class="col-md-4"></div>
  353. <form class="col-md-4 registerContainer" method="post" action="addproduct.php">
  354. <?php
  355. if($inserted === true) {
  356. echo '<div class="alert alert-success">';
  357. echo '<strong>Succes!</strong> Product toegevoegd.';
  358. echo '</div>';
  359. }
  360. ?>
  361. <div class="form-row">
  362. <div class="form-group col-md-8">
  363. <label for="inputTitle">Productnaam</label>
  364. <input type="text" class="form-control" name="inputTitle" required>
  365. </div>
  366. <div class="form-group col-md-4">
  367. <label for="inputDescription">Beschrijving</label>
  368. <input type="text" class="form-control" name="inputDescription">
  369. </div>
  370. </div>
  371. <div class="form-group">
  372. <label for="inputImage">Afbeelding</label>
  373. <input type="text" class="form-control" name="inputImage" placeholder="Bestandsnaam.extensie">
  374. </div>
  375. <div class="form-row">
  376. <div class="form-group col-md-9">
  377. <label for="inputPrice">Prijs</label>
  378. <input type="text" class="form-control" name="inputPrice" required>
  379. </div>
  380. <div class="form-group col-md-3">
  381. <label class="form-check-label" for="inputFormal">Formeel</label>
  382. <input type="hidden" name="inputFormal" value="0" />
  383. <input type="checkbox" class="form-control form-check-input" name="inputFormal" value="1">
  384. </div>
  385. </div>
  386. <input type="submit" class="btn btn-primary" value="Toevoegen" />
  387. </form>
  388. </div>
  389. </div>
  390.  
  391. </html>
  392.  
  393. 13.3.5 Sale.php
  394. <?php
  395. require('connect.php');
  396. session_start();
  397. $products = mysqli_query($link, 'select * from products WHERE aanbieding = 1');
  398. function fetchProducts($products)
  399. {
  400. if (mysqli_num_rows($products) >= 1) {
  401. foreach ($products as $product) {
  402. echo '<div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">';
  403. echo '<div class="productTile">';
  404. echo '<p class="productTileParagraphSmall productImage" style="background-image: url(' . $product['image'] . ');"></p>';
  405. echo '<h4 class="productH4">&euro;' . $product['price'] . ',- ' . $product['title'] . '</h4>';
  406. echo '<p style="background-color: white; padding: 10px;">';
  407.  
  408. echo '<form action="/projects/itsm2/product.php?productid='.$product['ID'].'" method="post">';
  409. echo '<button class="btn btn-primary" type="submit">Bekijken</button>';
  410. echo '</form>';
  411.  
  412. echo '</p>';
  413. echo '</div>';
  414. echo '</div>';
  415. }
  416. } else {
  417. echo 'geen producten gevonden!';
  418. }
  419. }
  420.  
  421. ?>
  422.  
  423. <html>
  424. <?php
  425. $currentpagename = 'Aanbiedingen';
  426.  
  427. include_once('header.php');
  428. ?>
  429. <body>
  430. <?php
  431. // Include Navbar
  432. $currentpage = 'sale';
  433. include_once('navbar.php')
  434. ?>
  435.  
  436. <div class="featuredProductsView container">
  437. <div class="row">
  438. <?php
  439. fetchProducts($products);
  440. ?>
  441. </div>
  442. </div>
  443. </html>
  444.  
  445. 13.3.6 Contact.php
  446. <?php
  447.  
  448. require('connect.php');
  449. session_start();
  450.  
  451. ?>
  452.  
  453. <html>
  454. <?php
  455. $currentpagename = 'Contact';
  456. include_once('header.php');
  457. ?>
  458. <body>
  459. <?php
  460. // Include Navbar
  461.  
  462. $currentpage = 'contact';
  463. include_once('navbar.php');
  464. ?>
  465.  
  466. <div class="container featuredProductsView">
  467. <div class="row">
  468. <div class="col-md-3"></div>
  469. <div class="col-md-6">
  470. <h1>Contact opnemen</h1>
  471. </div>
  472. </div>
  473. <div class="row">
  474. <div class="col-md-3"></div>
  475. <div class="col-md-6 registerContainer">
  476. <p>E-mail: onzeemail@webmail.com</p>
  477. <p>Telefoon: 05437268362</p>
  478. <p>Adres: Vuurhoutstraat 34, Enschede, Overijssel, Nederland</p>
  479. </div>
  480. </div>
  481.  
  482.  
  483. </div>
  484. </body>
  485. </html>
  486.  
  487. 13.3.7 Login.php
  488. <?php
  489. require 'connect.php';
  490.  
  491. if(isset($_SESSION['login_id'])) {
  492. // Do nothing
  493. } else {
  494. session_start();
  495. }
  496.  
  497. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  498.  
  499. // Define variables
  500. $email = $_POST['inputEmail'];
  501. $password = $_POST['inputPassword'];
  502.  
  503. // Fetch user
  504. $result = mysqli_query($link, "SELECT * FROM `users` where email = 'wesseloblink@hotmail.com' && password = 'Winterswijkdebeste33'");
  505.  
  506. // Check if user exists
  507. if(mysqli_num_rows($result) == 1) {
  508.  
  509. // Define user
  510. $user = $result->fetch_assoc();
  511.  
  512. // Maak sessie aan
  513. if(!isset($_SESSION)) {
  514. session_start();
  515. }
  516.  
  517. // Vul sessie
  518. $_SESSION['login_id'] = $user['ID'];
  519. $_SESSION['login_name'] = $user['first_name'];
  520.  
  521. } else {
  522. echo 'Gebruiker bestaat niet!';
  523. }
  524. }
  525.  
  526. ?>
  527.  
  528. <html>
  529. <?php
  530. $currentpagename = 'Inloggen';
  531.  
  532. include_once('header.php');
  533. ?>
  534. <body>
  535. <?php
  536. // Include Navbar
  537. $currentpage = 'login';
  538. include_once('navbar.php')
  539. ?>
  540.  
  541. <div class="container">
  542. <div class="row">
  543. <div class="col-md-4"></div>
  544. <form class="col-md-4 registerContainer" method="post" action="login.php">
  545. <?php
  546. if(isset($_SESSION['login_id'])) {
  547. echo '<div class="alert alert-success">';
  548. echo '<strong>Succes!</strong> Je bent ingelogd.';
  549. echo '</div>';
  550. }
  551. ?>
  552.  
  553. <div class="form-group">
  554. <label for="inputEmail">Emailaddres</label>
  555. <input type="email" class="form-control" name="inputEmail" required>
  556. </div>
  557. <div class="form-group">
  558. <label for="inputPassword">Wachtwoord</label>
  559. <input type="password" class="form-control" name="inputPassword" required>
  560. </div>
  561. <input type="submit" class="btn btn-primary" value="Inloggen" />
  562. <a type="button" class="btn" href="register.php" style="float: right;">Registreren</a>
  563. </form>
  564. </div>
  565. </div>
  566.  
  567. </html>
  568.  
  569. 13.3.8 Register.php
  570. <?php
  571. require 'connect.php';
  572.  
  573. session_start();
  574.  
  575. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  576.  
  577. // Define variables
  578. $firstName = $_POST["inputFirstname"];
  579. $middleName = $_POST['inputMiddlename'];
  580. $lastName = $_POST['inputFirstname'];
  581. $street = $_POST['inputFirstname'];
  582. $house = $_POST['inputFirstname'];
  583. $address = $street . " " . $house;
  584. $phone = $_POST['inputFirstname'];
  585. $mobile = $_POST['inputFirstname'];
  586. $city = $_POST['inputFirstname'];
  587. $zipcode = $_POST['inputFirstname'];
  588. $province = $_POST['inputFirstname'];
  589. $email = $_POST['inputFirstname'];
  590. $password = $_POST['inputFirstname'];
  591.  
  592. // Check if user exists
  593. $result = mysqli_query($link, 'select * from users where email= "$email"');
  594. if(mysqli_num_rows($result) == 0) {
  595.  
  596. // Register user
  597. $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')");
  598. if($insert)
  599. {
  600. echo 'Toegevoegd!';
  601. } else {
  602. echo 'Mislukt!';
  603. }
  604. } else {
  605. echo 'Email al gebruikt!';
  606. }
  607. }
  608.  
  609. ?>
  610.  
  611. <html>
  612. <?php
  613. $currentpagename = 'Registreren';
  614.  
  615. include_once('header.php');
  616. ?>
  617. <body>
  618. <?php
  619. // Include Navbar
  620. $currentpage = 'register';
  621. include_once('navbar.php')
  622. ?>
  623.  
  624. <div class="container">
  625. <div class="row">
  626. <div class="col-md-4"></div>
  627. <form class="col-md-4 registerContainer" method="post" action="register.php">
  628. <div class="form-row">
  629. <div class="form-group col-md-8">
  630. <label for="inputFirstname">Voornaam *</label>
  631. <input type="text" class="form-control" name="inputFirstname" placeholder="Voornaam" required>
  632. </div>
  633. <div class="form-group col-md-4">
  634. <label for="inputMiddlename">Tussenvoegsel</label>
  635. <input type="text" class="form-control" name="inputMiddlename" placeholder="">
  636. </div>
  637. </div>
  638. <div class="form-group">
  639. <label for="inputLastname">Achternaam *</label>
  640. <input type="text" class="form-control" name="inputLastname" placeholder="Achternaam" required>
  641. </div>
  642. <div class="form-row">
  643. <div class="form-group col-md-9">
  644. <label for="inputStreet">Straat</label>
  645. <input type="text" class="form-control" name="inputStreet" placeholder="Straat" required>
  646. </div>
  647. <div class="form-group col-md-3">
  648. <label for="inputHouse">Huisnummer</label>
  649. <input type="text" class="form-control" name="inputHouse" placeholder="Huisnr" required>
  650. </div>
  651. </div>
  652. <div class="form-row">
  653. <div class="form-group col-md-6">
  654. <label for="inputPhone">Huistelefoonnummer *</label>
  655. <input type="text" class="form-control" name="inputPhone" placeholder="Huistelefoonnr">
  656. </div>
  657. <div class="form-group col-md-6">
  658. <label for="inputMobile">Mobieletelefoonnummer</label>
  659. <input type="text" class="form-control" name="inputMobile" placeholder="06- nummer">
  660. </div>
  661. </div>
  662. <div class="form-row">
  663. <div class="form-group col-md-8">
  664. <label for="inputCity">Woonplaats *</label>
  665. <input type="text" class="form-control" name="inputZipcode" placeholder="Woonplaats">
  666. </div>
  667. <div class="form-group col-md-4">
  668. <label for="inputZipcode">Postcode *</label>
  669. <input type="text" class="form-control" name="inputZipcode" placeholder="Postcode">
  670. </div>
  671. </div>
  672. <div class="form-group">
  673. <label for="inputProvince">Provincie *</label>
  674. <input type="text" class="form-control" name="inputProvince" placeholder="Provincie">
  675. </div>
  676. <div class="form-group">
  677. <label for="inputEmail">Emailaddres *</label>
  678. <input type="email" class="form-control" name="inputEmail" aria-describedby="emailHelp" placeholder="Bijvoorbeeld henk@jans.nl" required>
  679. </div>
  680. <div class="form-group">
  681. <label for="inputPassword">Wachtwoord *</label>
  682. <input type="password" class="form-control" name="inputPassword" placeholder="Password" required>
  683. </div>
  684. <input type="submit" class="btn btn-primary" value="Registreren" />
  685. </form>
  686. </div>
  687. </div>
  688.  
  689. </html>
  690.  
  691. 13.3.9 Logout.php
  692. <?php
  693. session_start();
  694. unset($_SESSION['login_id']);
  695. header('Location: index.php');
  696.  
  697. 13.3.10 Connect.php
  698. <?php
  699. ini_set('display_errors', 1);
  700. error_reporting(E_ALL);
  701.  
  702. $link = mysqli_connect("localhost", "root", "", "webshop");
  703.  
  704. 13.3.11 Basket.php
  705. <?php
  706. require 'connect.php';
  707. session_start();
  708.  
  709. require_once 'basketHandling.php';
  710.  
  711. if(!isset($_SESSION['login_id'])) {
  712.  
  713. header('Location: login.php');
  714. }
  715.  
  716. // TODO: get products in basket
  717.  
  718.  
  719. ?>
  720.  
  721. <html>
  722. <?php
  723. $currentpagename = 'Winkelmand';
  724. include_once('header.php');
  725. ?>
  726. <body>
  727. <?php
  728. // Include Navbar
  729. $currentpage = 'basket';
  730. include_once('navbar.php')
  731. ?>
  732.  
  733. <div class="container">
  734. <div class="row">
  735. <div class="col-md-3"></div>
  736. <?php
  737. if(!isset($_SESSION['shopping_cart'])) {
  738.  
  739. // Basket is not set or empty
  740. echo '<form class="col-md-6 registerContainer" action="">';
  741. echo '<p>Je winkelmand is leeg!</p>';
  742. echo '</form>';
  743.  
  744. } else {
  745.  
  746. echo '<form class="col-md-6 registerContainer" action="">';
  747.  
  748. // Basket is set
  749. foreach ($_SESSION['shopping_cart'] as $arr => $prod) {
  750. // print_r($_SESSION['shopping_cart']);
  751.  
  752. // Fetch products based on ID
  753. $productID = $prod['productid'];
  754. $result = "select * from products where id=$productID";
  755. $product = $link->query($result)->fetch_assoc();
  756.  
  757. $products[] = array('id' => $prod['productid'], 'quantity' => $prod['quantity']);
  758.  
  759. echo '<div class="form-row">';
  760. echo '<div class="form-group col-md-8">';
  761. echo '<label>Product</label>';
  762. echo '<input type="text" class="form-control" name="inputProduct" value="' . $product["title"] . '" readonly />';
  763. echo '</div>';
  764. echo '</div>';
  765. echo '<div class="form-row">';
  766. echo '<div class="form-group col-md-4">';
  767. echo '<label>Prijs</label>';
  768. echo '<input type="text" class="form-control" name="inputPrice" value="&euro;' . $product["price"] . '" readonly />';
  769. echo '</div>';
  770. echo '</div>';
  771. echo '<div class="form-row">';
  772. echo '<div class="form-group col-md-4">';
  773. echo '<label>Aantal</label>';
  774. echo '<input type="text" class="form-control" name="inputQuantity" value="' . $prod["quantity"] . '" readonly />';
  775. echo '</div>';
  776. echo '</div>';
  777. echo '<hr>';
  778.  
  779. }
  780. echo '<a class="btn btn-primary" href="basket.php?order=true">Bestellen</a>';
  781. echo '<a class="btn btn-danger" href="basket.php?empty=true" style="margin-left: 10px;">Winkelmand legen</a>';
  782.  
  783. if (isset($_GET['empty'])) {
  784.  
  785. unset($_SESSION['shopping_cart']);
  786. header('Location: basket.php');
  787. die();
  788. }
  789.  
  790. if (isset($_GET['order'])) {
  791.  
  792. // Generate order ID
  793. $orderid = abs(crc32(uniqid()));
  794. echo 'unique id: ' . $orderid;
  795.  
  796. // Insert order
  797. $query = mysqli_query($link, "insert into orders (id, notes) values ('$orderid', 'Testorder')");
  798. var_dump($query);
  799. if ($query) {
  800. echo 'order inserted!';
  801. } else {
  802. echo 'order not inserted.';
  803. }
  804.  
  805. // Link user
  806. $query2 = mysqli_query($link, "insert into users_orders (orders_id, users_id) values ('$orderid', '" . $_SESSION['login_id'] . "')");
  807. if ($query2) {
  808. echo 'user order inserted!';
  809. } else {
  810. echo 'user order not inserted.';
  811. }
  812.  
  813.  
  814. foreach ($products as $producc) {
  815.  
  816. // Get product ID
  817. echo 'ProductID = ' . $producc['id'];
  818.  
  819. // Get product quantity
  820. echo 'ProductQuantity = ' . $producc['quantity'];
  821.  
  822.  
  823. // Insert product
  824. $query3 = mysqli_query($link, "insert into orders_products (products_id, orders_id, quantity) values ('" . $producc['id'] . "', '$orderid', '" . $producc['quantity'] . "')");
  825. if ($query3) {
  826. echo 'order products inserted!';
  827. } else {
  828. echo 'order products not inserted.';
  829. }
  830.  
  831. }
  832. unset($_SESSION['shopping_cart']);
  833. header('Location: orders.php');
  834. die();
  835. }
  836.  
  837. echo '</form>';
  838. }
  839. ?>
  840. </div>
  841. </div>
  842.  
  843. </html>
  844.  
  845. 13.3.12 Navbar.php
  846. <?php
  847.  
  848. // Get current user
  849. if(isset($_SESSION['login_id'])) {
  850.  
  851. $query = mysqli_query($link, "select * from users where id='" . $_SESSION['login_id'] . "'");
  852. $user = $query->fetch_assoc();
  853. }
  854.  
  855.  
  856. ?>
  857.  
  858.  
  859. <nav class="navbar navbar-expand-lg navbar-light bg-light">
  860. <a class="navbar-brand" href="index.php">Webshop</a>
  861. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
  862. aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
  863. <span class="navbar-toggler-icon"></span>
  864. </button>
  865. <div class="collapse navbar-collapse" id="navbarText">
  866. <ul class="navbar-nav mr-auto">
  867. <li class="nav-item <?php if($currentpage === 'index') { echo 'active';} ?>">
  868. <a class="nav-link" href="index.php">Home</a>
  869. </li>
  870. <li class="nav-item <?php if($currentpage === 'products') { echo 'active';} ?>">
  871. <a class="nav-link" href="products.php">Producten</a>
  872. </li>
  873. <li class="nav-item <?php if($currentpage === 'sale') { echo 'active';} ?>">
  874. <a class="nav-link" href="sale.php">Aanbiedingen</a>
  875. </li>
  876. <li class="nav-item <?php if($currentpage === 'contact') { echo 'active';} ?>">
  877. <a class="nav-link" href="contact.php">Contact</a>
  878. </li>
  879. <?php
  880. if($currentpage != 'index' && $currentpage != 'products' && $currentpage != 'sale' && $currentpage != 'contact' ) {
  881. ?>
  882. <li class="nav-item active">
  883. <?php echo '<a class="nav-link" href="' . $currentpage . '.php">' . $currentpagename . '</a>'; ?>
  884. </li>
  885. <?php
  886. }
  887.  
  888. ?>
  889. </ul>
  890. <ul class="navbar-nav navbar-right">
  891. <li class="nav-item">
  892. <?php
  893. if(isset($_SESSION['login_id'])) {
  894. echo '<a class="nav-link dropdown" data-toggle="dropdown" href="#">Hallo, ' . $_SESSION['login_name'] . '.</a>';
  895. echo '<ul class="dropdown-menu dropdown-menu-right">';
  896. if($user['type'] == 2) {
  897. echo '<li><a href="addproduct.php">Product toevoegen</a></li>';
  898. }
  899. if(isset($_SESSION['shopping_cart'])) {
  900. echo '<li><a href="basket.php">Winkelmand</a></li>';
  901. }
  902. echo '<li><a href="orders.php">Mijn orders</a></li>';
  903. echo '<li><a href="logout.php">Uitloggen</a></li>';
  904. echo '</ul>';
  905. } else {
  906. echo '<a class="nav-link" href="login.php">Log in</a>';
  907. }
  908. ?>
  909. </li>
  910. </ul>
  911. </div>
  912. </nav>
  913.  
  914. 13.3.13 Orders.php
  915. <?php
  916.  
  917. require('connect.php');
  918.  
  919. // TODO: Get user ID from session
  920. session_start();
  921.  
  922. include 'orderHandling.php';
  923.  
  924. if (!isset($_SESSION['login_id'])) {
  925. header('Location: login.php');
  926. } else {
  927. $userID = $_SESSION['login_id'];
  928. ?>
  929.  
  930. <html>
  931. <?php
  932. $currentpagename = 'Orders';
  933.  
  934. include_once('header.php');
  935. ?>
  936. <body>
  937. <?php
  938. // Include Navbar
  939. $currentpage = 'orders';
  940. include_once('navbar.php')
  941. ?>
  942. <?php
  943.  
  944. // TODO: Fetch orders from db
  945.  
  946. $orderids = getOrdersFromDB($link, $userID);
  947.  
  948. // TODO: Output order data
  949.  
  950. for ($i = 0; $i < count($orderids); $i++) {
  951. $orderid = $orderids[$i]['id'];
  952. $order_query = mysqli_query($link, "select * from orders where id='$orderid'");
  953. $order = $order_query->fetch_assoc();
  954. }
  955.  
  956. // TODO: Output products per order
  957.  
  958.  
  959. // Define products array
  960. for ($i = 0; $i < count($orderids); $i++) {
  961. $orderid = $orderids[$i]['id'];
  962. $order_query = mysqli_query($link, "select * from orders where id='$orderid'");
  963. $order = $order_query->fetch_assoc();
  964.  
  965. $orders_products_query = mysqli_query($link, "select * from orders_products where orders_id='$orderid'");
  966. if (mysqli_num_rows($orders_products_query) > 0) {
  967.  
  968. // Print order info
  969. echo '<div class="container featuredProductsView orderContainer">';
  970. echo '<h1>Producten voor order ' . $orderid . ' </h1>';
  971. echo '<div class="row">';
  972.  
  973. while ($row = mysqli_fetch_assoc($orders_products_query)) {
  974.  
  975. // Get products
  976. $products_query = mysqli_query($link, "select * from products where id='" . $row['products_id'] . "'");
  977.  
  978. // While products
  979. while ($productrow = mysqli_fetch_assoc($products_query)) {
  980.  
  981. ?>
  982. <div class="col-sm-12 col-md-6 col-lg-6 col-offset-square">
  983. <div class="productTile">
  984. <p>Ordernummer: <?php echo $row['orders_id'] ?></p>
  985. <p>Productnaam: <?php echo $productrow["title"] ?></p>
  986. <p>Aantal: <?php echo $row["quantity"] ?></p>
  987. <p class="productTileParagraphSmall productImage"
  988. style="background-image: <?php echo 'url(' . $productrow["image"] . ')' ?>"></p>
  989. </div>
  990. </div>
  991. <?php
  992. }
  993.  
  994. }
  995. echo '</div>';
  996. echo '</div>';
  997. }
  998. }
  999. }
  1000.  
  1001. ?>
  1002. </body>
  1003. </html>
  1004.  
  1005. 13.3.14 OrderHandling.php
  1006. <?php
  1007.  
  1008. require_once 'connect.php';
  1009.  
  1010. function getOrdersFromDB($link, $userID) {
  1011.  
  1012. $orderids = array();
  1013.  
  1014. $orders_query = mysqli_query($link, "select orders_id from users_orders where users_id='$userID'");
  1015.  
  1016. if(mysqli_num_rows($orders_query) > 0) {
  1017.  
  1018. while($row = mysqli_fetch_assoc($orders_query)) {
  1019.  
  1020. $responses[] = array(
  1021. 'id' => $row['orders_id']
  1022. );
  1023. }
  1024.  
  1025. $orderids = $responses;
  1026.  
  1027. return $orderids;
  1028. }
  1029. return null;
  1030. }
  1031.  
  1032. 13.3.15 Header.php
  1033. <head>
  1034. <?php
  1035. if(isset($currentpagename)) {
  1036. echo '<title>'.$currentpagename.'</title>';
  1037. } else {
  1038. echo '<title>Webshop</title>';
  1039. }
  1040. ?>
  1041. <!--Stylesheet-->
  1042. <link rel="stylesheet" type="text/css" href="style.css">
  1043. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"
  1044. integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
  1045. <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
  1046. integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
  1047. crossorigin="anonymous"></script>
  1048. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
  1049. integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
  1050. crossorigin="anonymous"></script>
  1051. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js"
  1052. integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4"
  1053. crossorigin="anonymous"></script>
  1054. </head>
  1055.  
  1056. 13.3.16 Style.css
  1057. body {
  1058. background-color: #f2f2f2 !important;
  1059. }
  1060. .carouselImage {
  1061. width: 100%;
  1062. height: 400px;
  1063. }
  1064. .productTile {
  1065. padding: 10px;
  1066. background-color: white;
  1067. }
  1068. .productH4 {
  1069. margin-bottom: 0;
  1070. background-color: white;
  1071. }
  1072. .productTileParagraphLarge {
  1073. background-color: #f8f8f8;
  1074. height: 400px;
  1075. }
  1076. .productTileParagraphSmall {
  1077. background-color: lightgrey;
  1078. height: 400px;
  1079. }
  1080. .featuredProductsView {
  1081. margin-top: 15px;
  1082. margin-bottom: 50px;
  1083. }
  1084. .col-offset-square {
  1085. padding-top: 15px;
  1086. padding-bottom: 15px;
  1087. }
  1088. .productImage {
  1089. background-size: 100% 100%;
  1090. margin: 0px;
  1091. }
  1092. .detailedProductView {
  1093. margin-top: 50px;
  1094. }
  1095. .detailedProductDescription {
  1096. background-color: white;
  1097. padding: 5px;
  1098. }
  1099. .detailedProductDetails {
  1100. margin-top: 20px;
  1101. background-color: white;
  1102. padding: 5px;
  1103. }
  1104. .detailedProductOptions {
  1105. margin-top: 10px;
  1106. background-color: white;
  1107. padding: 5px;
  1108. }
  1109. .registerContainer {
  1110. background-color: white;
  1111. border: white 2px solid;
  1112. border-radius: 5px;
  1113. margin-top: 20px;
  1114. padding: 5px;
  1115. }
  1116. .orderContainer {
  1117. background-color: #f8f8f8;
  1118. border: #f8f8f8 2px solid;
  1119. border-radius: 5px;
  1120. margin-top: 20px;
  1121. padding: 5px;
  1122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement