Guest User

Untitled

a guest
Jun 11th, 2013
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Include MySQL class
  3. require_once('mysql.class.php');
  4. // Include database connection
  5. require_once('global.inc.php');
  6. // Include functions
  7. require_once('functions.inc.php');
  8. // Start the session
  9. session_start();
  10. // Process actions
  11. $cart = $_SESSION['cart'];
  12. $action = $_GET['action'];
  13.  
  14. switch ($action) {
  15.     case 'add':
  16.         if ($cart) {
  17.             $cart .= ','.$_GET['id'];
  18.         } else {
  19.             $cart = $_GET['id'];
  20.         }
  21.         break;
  22.     case 'delete':
  23.         if ($cart) {
  24.             $items = explode(',',$cart);
  25.             $newcart = '';
  26.             foreach ($items as $item) {
  27.                 if ($_GET['id'] != $item) {
  28.                     if ($newcart != '') {
  29.                         $newcart .= ','.$item;
  30.                     } else {
  31.                         $newcart = $item;
  32.                     }
  33.                 }
  34.             }
  35.             $cart = $newcart;
  36.         }
  37.         break;
  38.     case 'update':
  39.     if ($cart) {
  40.         $newcart = '';
  41.         foreach ($_POST as $key=>$value) {
  42.             if (stristr($key,'qty')) {
  43.                 $id = str_replace('qty','',$key);
  44.                 $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
  45.                 $newcart = '';
  46.                 foreach ($items as $item) {
  47.                     if ($id != $item) {
  48.                         if ($newcart != '') {
  49.                             $newcart .= ','.$item;
  50.                         } else {
  51.                             $newcart = $item;
  52.                         }
  53.                     }
  54.                 }
  55.                 for ($i=1;$i<=$value;$i++) {
  56.                     if ($newcart != '') {
  57.                         $newcart .= ','.$id;
  58.                     } else {
  59.                         $newcart = $id;
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.     }
  65.     $cart = $newcart;
  66.     break;
  67. }
  68. $_SESSION['cart'] = $cart;
  69. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  70.    
  71. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  72. <head>
  73.     <title>PHP Shopping Cart Demo &#0183; Cart</title>
  74.     <link rel="stylesheet" href="css/styles.css" />
  75. </head>
  76.  
  77. <body>
  78.  
  79. <div id="shoppingcart">
  80.  
  81. <h1>Twoj koszyk</h1>
  82.  
  83. <?php
  84. echo writeShoppingCart();
  85. ?>
  86.  
  87. </div>
  88.  
  89. <div id="contents">
  90.  
  91. <h1>Prosze o sprawdzenie zamowienia</h1>
  92.  
  93.  
  94. <p><a href="index.php">Wroc do produktow/uslug</a></p>
  95.  
  96. <form name="submit1" method="post" action="wyslij.php">
  97. <input type="hidden" name="total" value="<?php echo $total ?>/>
  98. <input type="hidden" name="totalVAT" value="<?php echo $totalVAT ?>/>
  99. <input type="hidden" name="punkty" value="<?php echo $punkty ?>"/>
  100. <input type="submit" value="wyslij" />
  101. </form>
  102.  
  103.  
  104. <?php
  105. echo showCart();
  106. ?>
  107.  
  108.  
  109. </div>
  110.  
  111. </body>
  112. </html>
RAW Paste Data