Guest User

Untitled

a guest
Jun 11th, 2013
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function writeShoppingCart() {
  3.     $cart = $_SESSION['cart'];
  4.     if (!$cart) {
  5.         return '<p>Twoj koszyk jest pusty</p>';
  6.     } else {
  7.         // Parse the cart session variable
  8.         $items = explode(',',$cart);
  9.         $s = (count($items) > 1) ? 's':'';
  10.         return '<p>Masz <a href="cart.php">'.count($items).' produkty/uslugi w koszyku</a></p>';
  11.     }
  12. }
  13.  
  14. function showCart() {
  15.     global $db;
  16.     $cart = $_SESSION['cart'];
  17.     if ($cart) {
  18.         $items = explode(',',$cart);
  19.         $contents = array();
  20.         foreach ($items as $item) {
  21.             $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
  22.         }
  23.         $output[] = '<form action="cart.php?action=update" method="post" id="cart">';
  24.         $output[] = '<table>';
  25.         foreach ($contents as $id=>$qty) {
  26.             $sql = 'SELECT * FROM USLUGA WHERE idUSLUGA = '.$id;
  27.             $result = $db->query($sql);
  28.             $row = $result->fetch();
  29.             extract($row);
  30.             $output[] = '<tr>';
  31.             $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Usun</a></td>';
  32.             $output[] = '<td>'.$USLUGA_NAZWA_USLUGI.'   '.$USLUGA_CENA_NETTO.' PLN</td>';
  33.             $output[] = '<td>'.$USLUGA_STAWKA_USLUGI.' %</td>';
  34.             $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
  35.             $output[] = '<td>'.($USLUGA_CENA_NETTO * $qty).' PLN</td>';
  36.                         $output[] = '<td>'.(($USLUGA_CENA_NETTO * $qty)*$USLUGA_STAWKA_USLUGI*0.01).' PLN</td>';
  37.             $total += $USLUGA_CENA_NETTO * $qty;
  38.                         $totalVAT += (($USLUGA_CENA_NETTO * $qty)*$USLUGA_STAWKA_USLUGI*0.01);
  39.                         $punkty = $total*0.01;
  40.             $output[] = '</tr>';
  41.         }
  42.         $output[] = '</table>';
  43.         $output[] = '<p>Razem: <strong>'.$total.' PLN</strong></p>';
  44.                 $output[] = '<p>Razem VAT : <strong>'.$totalVAT.' PLN</strong></p>';
  45.                 $output[] = '<p>Punkty : <strong>'.$punkty.' PKT</strong></p>';
  46.         $output[] = '<div><button type="submit">Odswiez koszyk</button></div>';
  47.         $output[] = '</form>';
  48.     } else {
  49.         $output[] = '<p>Twoj koszyk jest pusty</p>';
  50.     }
  51.     return join('',$output);
  52. }
  53. ?>
RAW Paste Data