<?php
    
require("data.php");
    require(
"func.php");
    require(
"class/cart_class.php");
    if(isset(
$_GET['do']) && $do=$_GET['do']){
        
$shopcart=new Cart();
        switch (
$do){
            case 
"add":
                
$id=isset($_GET['id']) ? intval($_GET['id']) : '';
                
add_shop();
            break;
            case 
"less":
                
$id=isset($_GET['id']) ? intval($_GET['id']) : '';
                
less_shop();
            break;
            case 
"clear":
                
$shopcart->clear();
            break;
            default:
        }
        unset(
$shopcart);
        
header("location:index.php");
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物车Class</title>
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
</head>

<body>
    <h3 class="title">Use The Cart Class <small>by paperen</small></h3>
    <div class="container">
<?php
    
foreach($fruits as $fid=>$each){
?>        
        <div class="cartbox" id="catbox-<?php echo $fid?>">
            <h5>Example <?php echo $fid?></h5>
            <ul>
                <li class="name"><?php echo $each['name']; ?></li>
                <li class="price">price:<?php echo $each['price']; ?></li>
                <li><a href="?do=add&id=<?php echo $fid?>" id="buy-<?php echo $fid?>" class="btn">BUY ME</a></li>
            </ul>
        </div>
<?php
    
}
?>            
        <div class="c"></div>
        <ul class="youbuy">
<?php
        $total
=0;
        if(isset(
$_COOKIE['buy'])){
            foreach(
$_COOKIE['buy'] as $fid=>$fnum){
                
$each=get_friut($fid);
                if(
$each){
?>        
            <li><?php echo $each['name']; ?>*<?php echo $fnum?>=<span class="total"><?php echo $fnum*$each['price']; ?></span> <a href="?do=less&id=<?php echo $fid?>">Less-</a> <a href="?do=add&id=<?php echo $fid?>">Add+</a></li>
<?php
                    $total
+=$fnum*$each['price'];
                }
            }
?>
            <li><a href="?do=clear">Clear all</a></li>
<?php            
        
}else{
?>    
            <li>There's empty in your bag.</li>        
<?php
        
}
?>
            <li class="lastcost">Total is <?php echo $total?></li>
        </ul>
    </div>
    <div class="seecode">
    查看源代码:
        <a href="code.php?id=0" target="_blank">data.php</a>
        <a href="code.php?id=1" target="_blank">func.php</a>
        <a href="code.php?id=2" target="_blank">cart_class.php</a>
        <a href="code.php?id=3" target="_blank">index.php</a>
    </div>
</body>
</html>