amin007

troli - cart.php

Mar 4th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2. // Include MySQL class
  3. require_once('inc/mysql.class.php');
  4. // Include database connection
  5. require_once('inc/global.inc.php');
  6. // Include functions
  7. require_once('inc/functions.inc.php');
  8. // Start the session
  9. session_start();
  10. // Process actions
  11. $cart = $_SESSION['beli'];
  12. $action = $_GET['action'];
  13. switch ($action)
  14. {
  15.     case 'add':
  16.         if ($cart)
  17.         {
  18.             $cart .= ',' . $_GET['idkek'];
  19.         }
  20.         else
  21.         {
  22.             $cart = $_GET['idkek'];
  23.         }
  24.         break;
  25.     case 'delete':
  26.         if ($cart)
  27.         {
  28.             $items = explode(',',$cart);
  29.             $newcart = '';
  30.  
  31.             foreach ($items as $item)
  32.             {
  33.                 if ($_GET['idkek'] != $item)
  34.                 {
  35.                     if ($newcart != '')
  36.                     {
  37.                         $newcart .= ',' . $item;
  38.                     }
  39.                     else
  40.                     {
  41.                         $newcart = $item;
  42.                     }
  43.                 }
  44.             }
  45.             $cart = $newcart;
  46.         }
  47.         break;
  48.     case 'update':
  49.     if ($cart)
  50.     {
  51.         $newcart = '';
  52.  
  53.         foreach ($_POST as $key=>$value)
  54.         {
  55.             if (stristr($key,'qty'))
  56.             {
  57.                 $id = str_replace('qty','',$key);
  58.                 $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
  59.                 $newcart = '';
  60.  
  61.                 foreach ($items as $item)
  62.                 {
  63.                     if ($id != $item)
  64.                     {
  65.                         if ($newcart != '')
  66.                         {
  67.                             $newcart .= ',' . $item;
  68.                         }
  69.                         else
  70.                         {
  71.                             $newcart = $item;
  72.                         }
  73.                     }
  74.                 }
  75.                 for ($i=1;$i<=$value;$i++)
  76.                 {
  77.                     if ($newcart != '')
  78.                     {
  79.                         $newcart .= ',' . $id;
  80.                     }
  81.                     else
  82.                     {
  83.                         $newcart = $id;
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.     }
  89.     $cart = $newcart;
  90.     break;
  91. }
  92. $_SESSION['beli'] = $cart;
  93. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  94.    
  95. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  96. <head>
  97.     <title>Senarai tempahan</title>
  98.     <link rel="stylesheet" href="css/styles.css" />
  99. </head>
  100.  
  101. <body>
  102.  
  103. <div id="shoppingcart">
  104.  
  105. <h1>Senarai Tempahan | <a href="../logout.php">Keluar...</a></h1>
  106.  
  107. <?php
  108. echo writeShoppingCart();
  109. ?>
  110.  
  111. </div>
  112.  
  113. <div id="contents">
  114.  
  115. <h1>Sila semak kuantiti...</h1>
  116.  
  117. <?php
  118. echo showCart('lihat');
  119. ?>
  120.  
  121. <p><a href="./">Kembali ke menu utama...</a></p>
  122.  
  123. </div>
  124.  
  125. </body>
  126. </html>
Advertisement
Add Comment
Please, Sign In to add comment