Location: PHPKode > scripts > Faucart > faucart/faucart_demo2.php
<?
################################################
#
# Faucart Demo 2
#
# by Fausto Iannuzzi - 2005 - free to use
#
################################################

session_start();
require_once "faucart.lib.php";

$cart_object->addItem(new faucartelement("LCD Monitor","12 ms",240.12));
$cart_object->addItem(new faucartelement("Hard Disk","250 GB - 1000rpm",45));
$cart_object->addItem(new faucartelement("DSL Router/Modem","DSL router/modem with 4 10/100mbits ports",80));
$cart_object->addItem(new faucartelement("Inkjet printer","1200x1200 dpi - Windows + Mac drivers included",150));

$action = $_GET["action"];

switch ($action) {
case "empty":
  $cart_object->emptyCart();
  break;
case "add":
   $cart_object->addItem(new faucartelement($_GET["name"],$_GET["description"],$_GET["price"]));
   break;
case "del":
   $cart_object->delItemByObjectID($_GET["id"]);
   break;
}

$cart_object->total();
$total = $cart_object->_total;
$cart_items = $cart_object->getItems();
?>
<head>
<title>Your e-commerce cart with faucart</title>
<style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style2 {font-size: 12px}
.style11 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }
.style12 {
	color: #FF0000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style14 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FF0000; }
.style16 {
	font-size: 10px;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<script>
function checkCart(action) {
 top.location.href = 'faucart_demo2.php?action='+action;
}

function addProduct() {
 var params="";
 params = '&name='+document.cart.name.value;
 params += '&description='+document.cart.description.value;
 params += '&price='+document.cart.price.value;
 top.location.href = 'faucart_demo2.php?action=add'+params;
}
</script>
<form name=cart action='faucart_demo2.php' method='get'>
<table width="60%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="5"><div align="center" class="style2 style1"><strong>Your e-commerce cart</strong></div></td>
  </tr>
  <tr>
    <td><span class="style2"></span></td>
    <td><span class="style2"></span></td>
    <td><span class="style2"></span></td>
    <td><span class="style2"></span></td>
    <td><span class="style2"></span></td>
  </tr>
  <tr>
    <td><span class="style11">Name</span></td>
    <td><span class="style11">Description</span></td>
    <td><span class="style11">Quantity</span></td>
    <td><span class="style11">Price</span></td>
    <td><span class="style11">[actions]</span></td>
  </tr>
<?
  foreach ($cart_items as $cart_item) {
    echo "<tr>";
    echo " <td><span class='style2'>".$cart_item->name."</span></td>";
    echo " <td><span class='style2'>".$cart_item->description."</span></td>";
    echo " <td><span class='style2'>".$cart_item->quantity."</span></td>";
    echo " <td><span class='style2'>".$cart_item->price." €</span></td>";
    echo " <td><span class='style4'><a href='faucart_demo2.php?action=del&id=".$cart_item->object_id."'>[del]</a></span></td>";
    echo "</tr>";
  }
?>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><span class="style14">Total</span></td>
    <td> <span class="style12"><? echo $total; ?> &euro; </span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="5"><div align="center"><span class="style2 style1"><strong>Add a new product </strong></span></div></td>
    </tr>
  <tr>
    <td><div align="center">
      <input name="name" type="text" id="name" size="15" maxlength="30">
    </div></td>
    <td><div align="center">
      <input name="description" type="text" id="description" size="20" maxlength="50">
    </div></td>
    <td></td>
    <td><div align="center">
      <input name="price" type="text" id="price" size="5" maxlength="5">
    </div></td>
    <td><div align="center">
      <input type="button" name="add" value="Add" onClick="addProduct();">
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="5"><div align="center">
      <input type="button" name="Submit" value="Empty cart" onClick="checkCart('empty');">
      &nbsp;
      <input type="submit" name="Submit" value="Reload">
    </div></td>
  </tr>
  <tr>
    <td colspan="5">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="5"><div align="center" class="style1 style16">copyright 2005 by Fausto Iannuzzi - free to use - <a href="http://ecommerce-cart.nuz.it">http://ecommerce-cart.nuz.it</a> </div></td>
  </tr>
</table>
</form>
</body>
</html>
<? toSession(); ?>
Return current item: Faucart