Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function writeShoppingCart() {
- $cart = $_SESSION['cart'];
- if (!$cart) {
- return '<p>Twoj koszyk jest pusty</p>';
- } else {
- // Parse the cart session variable
- $items = explode(',',$cart);
- $s = (count($items) > 1) ? 's':'';
- return '<p>Masz <a href="cart.php">'.count($items).' produkty/uslugi w koszyku</a></p>';
- }
- }
- function showCart() {
- global $db;
- $cart = $_SESSION['cart'];
- if ($cart) {
- $items = explode(',',$cart);
- $contents = array();
- foreach ($items as $item) {
- $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
- }
- $output[] = '<form action="cart.php?action=update" method="post" id="cart">';
- $output[] = '<table>';
- foreach ($contents as $id=>$qty) {
- $sql = 'SELECT * FROM USLUGA WHERE idUSLUGA = '.$id;
- $result = $db->query($sql);
- $row = $result->fetch();
- extract($row);
- $output[] = '<tr>';
- $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Usun</a></td>';
- $output[] = '<td>'.$USLUGA_NAZWA_USLUGI.' '.$USLUGA_CENA_NETTO.' PLN</td>';
- $output[] = '<td>'.$USLUGA_STAWKA_USLUGI.' %</td>';
- $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
- $output[] = '<td>'.($USLUGA_CENA_NETTO * $qty).' PLN</td>';
- $output[] = '<td>'.(($USLUGA_CENA_NETTO * $qty)*$USLUGA_STAWKA_USLUGI*0.01).' PLN</td>';
- $total += $USLUGA_CENA_NETTO * $qty;
- $totalVAT += (($USLUGA_CENA_NETTO * $qty)*$USLUGA_STAWKA_USLUGI*0.01);
- $punkty = $total*0.01;
- $output[] = '</tr>';
- }
- $output[] = '</table>';
- $output[] = '<p>Razem: <strong>'.$total.' PLN</strong></p>';
- $output[] = '<p>Razem VAT : <strong>'.$totalVAT.' PLN</strong></p>';
- $output[] = '<p>Punkty : <strong>'.$punkty.' PKT</strong></p>';
- $output[] = '<div><button type="submit">Odswiez koszyk</button></div>';
- $output[] = '</form>';
- } else {
- $output[] = '<p>Twoj koszyk jest pusty</p>';
- }
- return join('',$output);
- }
- ?>
RAW Paste Data