HTML OUTPUT:


John & Juliet present

the Chocolat! Shop

Main Navigation

home
view cart
Admin

See Categories of our Famous Chocolat!

Chocolate most commonly comes in dark, milk, and white varieties, with cocoa solids contributing to the brown coloration.chocolate!

cart image

Your Current Chocolat! Shopping Cart



Please Select a Shipping Method:




chocolate cake!Dark chocolate is produced by adding fat and sugar to the cacao mixture. The U.S. Government calls this "sweet chocolate", and requires a 15% concentration of chocolate liquor. European rules specify a minimum of 35% cocoa solids. Dark chocolate, with its high cocoa content, is a rich source of the flavonoids epicatechin and gallic acid, which are thought to possess cardioprotective properties. Dark chocolate has also been said to reduce the possibility of a heart attack when consumed regularly in small amounts. Semisweet chocolate is a dark chocolate with a low sugar content. Bittersweet chocolate is chocolate liquor to which some sugar (typically a third), more cocoa butter, vanilla and sometimes lecithin have been added. It has less sugar and more liquor than semisweet chocolate, but the two are interchangeable in baking. Unsweetened chocolate is pure chocolate liquor, also known as bitter or baking chocolate. It is unadulterated chocolate: the pure, ground, roasted chocolate beans impart a strong, deep chocolate flavor.

While chocolate is regularly eaten for pleasure, there are potential beneficial health effects of eating chocolate. Cocoa or dark chocolate benefits the circulatory system. Other beneficial effects suggested include anticancer, brain stimulator, cough preventor and antidiarrhoeal effects. An aphrodisiac effect is yet unproven.



SOURCE CODE:


<?php     // load connection info and functions  including session_start()

  
require_once("../administration.inc.php"); ?>
  
  <style type="text/css">
<!--
div#cartTitle img {
    float: left;
    padding-right: 5px;
    padding-left: 5px;
}
div#cartTitle br {
    clear: right;
}
div#cartTitle {
    height: 75px;
}
p.grand {
    font-size: 100%;
    font-weight: bold;
    text-align: right;
    margin-right: 40px;
}
#cartTable th {
    font: bold 75% "Lucida Grande CE";
}
#cartTable td {
    font: normal 75% "Lucida Grande CE";
}
-->
  </style> 

  
<?php 
  
  
/* echo "<br /><br /><hr><br /><br />";  */


/* User clicks "add to cart" on Category5.php, then goes here (to cartAdd.php) --  
we can access productid from url and set it to local variable: */

 
$productid $_GET['id'];

/* add items to cart with new switch statement, using 'add' value and value of productid 
 that is attached to url on Category page */
  // start array
        
$_SESSION['cartArray'];
        
// use shorter name
        
$cart $_SESSION['cartArray'];
        
/*  set action variable to cover simple add, and then delete and update -- 
        I thought this might be more compact but it looks like it gets out of hand a bit */
        
$action $_GET['action'];
            
// add action is easiest, just add #id if none exists, or append another instance if one is already there
            
switch ($action) {
                case 
'add':
                    if (
$cart) {
                        
$cart .= ','.$productid;
                 } else {
                         
$cart $productid;
             }
                 break;
                
                
/* delete action, take stuff out of array comma-delimited, put into new empty variable, 
                check the current state of product quantities and reconstruct the temp variable excluding items deleted, 
                set that value back to cart array */
                
case 'delete':
                    if (
$cart) {
                        
$items explode(',',$cart);
                        
$newcart '';
                     foreach (
$items as $item) {
                            if (
$productid!= $item) {
                                if (
$newcart != '') {
                                    
$newcart .= ','.$item;
                            } else {
                                
$newcart $item;
                             }
                         }
                     }
                         
$cart $newcart;
                 }
                         break;
             
/*  update action, check to see what's in the $_POST array (which holds all our quantity values for each product, 
            as those text input boxes are part of the form element that encases the whole cart table) 
            and extract the relevant id and value pairs. For each product, we then delete all the existing instances of it, 
            and set back the new quantities */
              
case 'update':
                 if (
$cart) {
                     
$newcart '';
                     
                    foreach (
$_POST as $key=>$value) {
                        if (
stristr($key,'qty')) {
                             
$id str_replace('qty','',$key);
                             
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
                             
$newcart '';
                                 
                                foreach (
$items as $item) {
                                     if (
$id != $item) {
                                         if (
$newcart != '') {
                                         
$newcart .= ','.$item;
                                     } else {
                                         
$newcart $item;
                                                 }
                                             }
                                         }
                                         
                                        for (
$i=1;$i<=$value;$i++) {
                                         if (
$newcart != '') {
                                         
$newcart .= ','.$id;
                                         } else {
                                         
$newcart $id;
                                            }
                                         }
                                     }
                                     }
                                   }
                                     
$cart $newcart;
                                     break;
                            }
              
              
              
$_SESSION['cartArray'] = $cart;
              
              
    
// show the source code, show the html header and top part of page
$showsource "cartAdd.php";
include(
"chocolatHeader.inc.php");
// show main navigation 
require_once("nav.inc.php");

// title cart area 
echo "<div id = 'cartTitle'>";
echo 
'<p><img src="images/cart.gif" alt="cart image" width="60" height="64" /></p>';
echo 
"<h3>";
echo 
"Your Current Chocolat! Shopping Cart";
echo 
'<br />';
echo 
"</h3>";
echo 
"</div>";

// get everything out of array and put it into $contents
 
$cart $_SESSION['cartArray'];
    if (
$cart) {
        
$items explode(',',$cart);
        
$contents = array();
        foreach (
$items as $item) {
            
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1;
        }
    
//then set up cart table structure and form with action set to update    
        
        
echo '<form action="cartAdd.php?action=update" method="post" id="cart">';
        echo 
'<table id="cartTable" border ="1" cellpadding ="3">';
        
            echo 
'<tr>';
            echo 
'<th>Delete</th>';
            echo  
'<th>Product</th>';
            echo  
'<th>Price</th>';
            echo  
'<th>kg</th>';
            echo  
'<th>Quantity</th>';
            echo  
'<th>Amount</th>';
            echo  
'<th>Total kg</th>';
            echo 
'</tr>';
    
// run through $contents and pull down db info for each product ordered, pop all that into the table        
            
        
foreach ($contents as $id=>$qty) {
            
             
$qProdInfo 'SELECT * FROM Products WHERE productid = ' $id
             
             
$reProdInfo mysql_query($qProdInfo) or die ("Error in query: $query. " mysql_error());
             
              
$row=mysql_fetch_array($reProdInfo,MYSQL_ASSOC);
              
extract($row);
            
            echo 
'<tr>';
            echo 
'<td><a href="cartAdd.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
            echo  
'<td>'.$productname.'</td>';
            echo  
'<td>$'.$productprice'</td>';
            echo  
'<td>'.$productweight' kg</td>';
            echo  
'<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
            echo  
'<td>$'.($productprice $qty).'</td>';
            echo  
'<td>'.($productweight $qty).' kg</td>';
            
            
$total += $productprice $qty;
            
$totalW += $productweight $qty;
            
$totalQty += $qty;
            echo 
'</tr>';
        }
        echo 
'</table>';
        echo 
'<p class = "grand">Merchandise total: <strong>$'.$total.'.00</strong></p>';
        echo 
'<p class = "grand">Total Weight: <strong>'.$totalW.' kg</strong></p>';
        echo 
'<div><button type="submit">Update cart</button></div>';
        echo
'</form>';
}

    echo 
'<br />';
    echo 
'<br />';  
    
    
             
$qShipM 'SELECT * FROM Shipmethods';                                                                 
             
             
$reShipM mysql_query($qShipM) or die ("Error in query: $query. " mysql_error());
    
    
/*     $aShipM = mysql_fetch_array($reShipM);
           
           if ($aShipM)  {
                 print_r($aShipM);
                 }  else  {
                 echo 'No info in $aShipM!';
                 } */
    
    //set up form to go to checkout page
    
    
echo '<form action="updateCO.php?action=update" method="post" id="udCO">';
    
    
// set up form element to choose shipping method
    
    
$selected 'Please Select a Shipping Method:';
            echo 
"<h4> $selected </h4>";
            echo 
"<select name='ship'>";
            
// echo '<option value=' . $selected. 'selected=' .$selected. '>' . $selected . '</option>';
    
            
         
do  {
            
            echo 
'<option value=' $shipRow['shipmethodid'] . '>' $shipRow['shipmethoddesc'] . '</option>';
            
             
$shipRow mysql_fetch_array($reShipM,MYSQL_ASSOC);
           }  while (!
$shipRow ==0);  /**/
           
         
           
           
        /*    
           while ($aShipM = mysql_fetch_array($reShipM))   {
           
              echo "option value =\"$aShipM[0]\">$aShipM[1]\n";
              } */
              
              
              
              
              
              
         
            
            
echo '</select>';
            echo 
'<br />';
            echo 
'<br />';            
echo 
'<div><button type="submit">Checkout</button></div>';            
echo
'</form>';

// add footer stuff
require_once("footer.inc.php"); 
?>