Facebook
From Stained Peafowl, 4 Years ago, written in HTML5.
Embed
Download Paste or View Raw
Hits: 137
  1. <?php
  2. session_start();
  3. require_once('connection.php');
  4.  
  5.  
  6. //dodawanie do koszyka
  7. if(isset($_POST["add_to_cart"]))
  8. {
  9.         if(isset($_SESSION["shopping_cart"]))
  10.         {
  11.                 $item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
  12.                 if(!in_array($_GET["id"], $item_array_id))
  13.                 {
  14.                         $count = count($_SESSION["shopping_cart"]);
  15.                         $item_array = array(
  16.                                 'item_id'                       =>      $_GET["id"],
  17.                                 'item_name'                     =>      $_POST["hidden_name"],
  18.                                 'item_price'            =>      $_POST["hidden_price"],
  19.                                 'item_quantity'         =>      $_POST["quantity"]
  20.                         );
  21.                         $_SESSION["shopping_cart"][$count] = $item_array;
  22.                 }
  23.                 else
  24.                 {
  25.                         //echo '<script>alert("Danie już dodane.")</script>';
  26.                 }
  27.         }
  28.         else
  29.         {
  30.                 $item_array = array(
  31.                         'item_id'                       =>      $_GET["id"],
  32.                         'item_name'                     =>      $_POST["hidden_name"],
  33.                         'item_price'            =>      $_POST["hidden_price"],
  34.                         'item_quantity'         =>      $_POST["quantity"]
  35.                 );
  36.                 $_SESSION["shopping_cart"][0] = $item_array;
  37.         }
  38. }
  39.  
  40. //usuwanie z koszyka
  41. if(isset($_GET["action"]))
  42. {
  43.         if($_GET["action"] == "delete")
  44.         {
  45.                 foreach($_SESSION["shopping_cart"] as $keys => $values)
  46.                 {
  47.                         if($values["item_id"] == $_GET["id"])
  48.                         {
  49.                                 unset($_SESSION["shopping_cart"][$keys]);
  50.                                 //echo '<script>alert("Danie usunięte.")</script>';
  51.                                 echo '<script>window.location="cusisineTurkish.php"</script>';
  52.                         }
  53.                 }
  54.         }
  55. }
  56.  
  57. ?>
  58. <!DOCTYPE html>
  59.         <head>
  60.                 <title>MENU</title>
  61.                 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  62.                 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  63.         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  64.                 <link
  65.        href="https://fonts.googleapis.com/css?family=Saira+Extra+Condensed:300,700|Saira:300,400&display=swap&subset=latin-ext"
  66.        rel="stylesheet">
  67.     <link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap&subset=latin-ext" rel="stylesheet">
  68.                  <!--   do używania ikon z FontAwesome   -->
  69.     <link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">
  70.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  71.         </head>
  72.         <body>
  73.  
  74. <div style="display: flex;">
  75.  
  76. <p class="title" style=" margin-top: 50px; margin-left: 50px; width: 50%; color: black; font-size: 45px; font-family: 'Saira Extra Condensed', sans-serif;">Mniam</p>
  77.  
  78. <section style=" width: 50%;">
  79.  
  80.                 </section>
  81.                 </div>
  82.  
  83.             <!-- przycisk - powrót do strony głównej -->
  84.                  <!-- <a style=" color: white; height: 53px; width: 53px;  border: none; font-size: 12px; line-height: 18px;
  85.    outline: none; background-color: #F5585C; position: fixed; bottom: 20px; right: 20px; text-align: center; padding: 8px 3px; text-decoration: none; border-radius: 10px; " class="backToHome" href="index.php">Strona </br>główna</a>  -->
  86.                 <br />
  87.                 <div class="container">
  88.                         <h1 align="center">MENU - kuchnia turecka</h1><br />
  89.                         <br /><br />
  90.             <?php
  91.            // wyciągam dania z bazy danych
  92.                                 $query = "SELECT * FROM m_dania WHERE id_lokalu = 2";
  93.                                
  94.                                 $result = mysqli_query($connection, $query);
  95.                                 if (mysqli_num_rows($result) > 0)
  96.                                 {
  97.                                         while($row = mysqli_fetch_array($result))
  98.                                         {
  99.                                 ?>
  100.                                 <!-- karty z daniami  -->
  101.                         <div style="margin-bottom: 50px;" class="col-md-6">
  102.                 <form method="post" action="cusisineTurkish.php?action=add&id=<?php echo $row["id_dania"]; ?>">
  103.                
  104.                         <div style="background-color: #FACE58; border-radius: 5px; padding: 16px; text-align: center; width: 100%;">
  105.                                                
  106.                                                 <h4 style="color: black;" class="text-info"><?php echo $row["nazwa"]; ?></h4>
  107.  
  108.                         <h4 style="color: white;" class="text-danger"> <?php echo $row["cena"]; ?></h4>
  109.                        
  110.                         <h4 style="color: black;" class="text-danger"> <?php echo $row["opis"]; ?></h4>
  111.  
  112.                         <input type="text" name="quantity" value="1" class="form-control" />
  113.  
  114.                         <input type="hidden" name="hidden_name" value="<?php echo $row["nazwa"]; ?>" />
  115.  
  116.                                                 <input type="hidden" name="hidden_price" value="<?php echo $row["cena"]; ?>" />
  117.  
  118.                                                 <input style="background-color: #F5585C; border: none; margin-top: 10px;" type="submit" name="add_to_cart" style="margin-top:5px;" class="btn btn-success" value="Dodaj do koszyka" />
  119.  
  120.                                         </div>
  121.                                 </form>
  122.                        
  123.                         </div>
  124.                         <?php
  125.                                         }
  126.                                 }
  127.                         ?>
  128.                        
  129.                        
  130.                         <h3 style="text-align: left;">Szczegóły zamówienia</h3>
  131.                         <div class="table-responsive" >
  132.                 <!-- szczegóły zamówienia -->
  133.                                 <table class="table table-bordered">
  134.                                         <tr>
  135.                                                 <th width="40%">Nazwa dania</th>
  136.                                                 <th width="10%">Ilość</th>
  137.                                                 <th width="20%">Cena jednostkowa</th>
  138.                                                 <th width="15%">Cena całkowita</th>
  139.                                                 <th width="5%">Koszyk</th>
  140.                                         </tr>
  141.                                         <?php
  142.                                         if(!empty($_SESSION["shopping_cart"]))
  143.                                         {
  144.                                                 $total = 0;
  145.                                                 foreach($_SESSION["shopping_cart"] as $keys => $values)
  146.                                                 {
  147.                                         ?>
  148.                                         <!-- szczegóły zamówienia - poszczególne elementy -->
  149.                                         <tr>
  150.                                                 <td name="danie" required><?php echo $values["item_name"]; ?></td>
  151.                                                 <td><?php echo $values["item_quantity"]; ?></td>
  152.                                                 <td><?php echo $values["item_price"]; ?></td>
  153.                                                 <td><?php echo number_format($values["item_quantity"] * $values["item_price"], 2);?></td>
  154.                                                 <td><a style="text-decoration: none;" href="cusisineTurkish.php?action=delete&id=<?php echo $values["item_id"]; ?>"><span class="text-danger">Usuń</span></a></td>
  155.                                         </tr>
  156.                                         <?php
  157.                                                     //   obliczenie całkowitej ceny zamówienia
  158.                                                          $total = $total + ($values["item_quantity"] * $values["item_price"]);
  159.                                                 }
  160.                                         ?>
  161.                                         <tr>
  162.                                                              <!-- całkowitej cena zamówienia -->
  163.                                                 <td colspan="3" align="right" style="font-weight: bold;">Całkowita cena zamówienia</td>
  164.                                                 <td align="right"> <?php echo number_format($total, 2); ?></td>
  165.                                                 <td></td>
  166.                                         </tr>
  167.                                         <?php
  168.                                         }
  169.                                         ?>
  170.                                                
  171.                                 </table>
  172.                         </div>
  173.                 </div>
  174.         </div>
  175.  
  176.         <a href="submitOrder.php">Przejdź do finalizacji zamówienia</a>
  177.         </body>
  178. </html>
  179.