<?php
/* Idut Shop 1.0 (beta)
* (c) 2008 Idut - www.idut.co.uk
* index.php
*/
session_start();
include("config.php");
if(!$IS_CONFIG['db_already_connected']){
$link = mysql_connect($IS_CONFIG['db_host'], $IS_CONFIG['db_user'], $IS_CONFIG['db_pass']) or die('Could not connect: ' . mysql_error());
mysql_select_db($IS_CONFIG['db_database']) or die('Could not select database');
}
include("header.php");
if($_GET['c'] == "details"){
showCartOverview();
showDetails();
}elseif($_GET['c'] == "cart"){
showCart();
}elseif($_GET['c'] == "checkout"){
showCheckout();
}else{
showCartOverview();
showMain();
}
echo '<br/><br/><a href="http://www.idut.co.uk/"><img src="http://www.idut.co.uk/idutpowered.png" border=0 alt="Powered by Idut Shop"/></a>';
include("footer.php");
function showMain(){
global $IS_CONFIG;
echo $IS_CONFIG['intro_text'];
echo "<br/><br/><b>Our products:</b><br/>";
$query = 'SELECT * FROM '.$IS_CONFIG['db_table'].' ORDER BY id';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<table>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>";
echo "<td><a href=\"$IS_CONFIG[shop_url]";
if($IS_CONFIG['rewrite_urls']){
echo $line['id'].'-'.ereg_replace("[^A-Za-z0-9\-]", "", str_replace(" ","-",$line['title'])).".html";
}else{
echo "?c=details&id=$line[id]";
}
echo "\">$line[title]</a></td><td align=\"right\">$IS_CONFIG[currency_symbol]$line[price]</td>";
echo "<td width=\"110\" rowspan=2>";
if($line[thumb]) echo "<a href=\"$IS_CONFIG[shop_url]?c=details&id=$line[id]\"><img src=\"$IS_CONFIG[thumb_dir]$line[thumb]\" style=\"border:1px solid black;\"/></a>";
echo "</td>";
echo "</tr><tr><td colspan=2 valign=top>$line[description]</td>";
echo "</tr><tr><td colspan=3 align=\"center\"><hr></td>";
echo "</tr>";
}
echo "</table>";
}//showMain
function showDetails(){
global $IS_CONFIG;
$query = "SELECT * FROM $IS_CONFIG[db_table] WHERE id = '$_GET[id]'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<table>";
$line = mysql_fetch_array($result, MYSQL_ASSOC);
echo "<tr>";
echo "<td><big><b>$line[title]</b></big></td><td align=\"right\">$IS_CONFIG[currency_symbol]$line[price]</td>";
echo "<td width=\"110\" rowspan=2>";
if($line['thumb']) echo "<img src=\"$IS_CONFIG[thumb_dir]$line[thumb]\" style=\"border:1px solid black;\"/>";
echo "</td>";
echo "</tr><tr><td colspan=2 valign=top>$line[description]</td>";
echo "</tr>";
echo "</table>";
if($line['instock']){
echo "<br/><big><a href=\"$IS_CONFIG[shop_url]?c=cart&add=$line[id]\">Add to shopping $IS_CONFIG[cart]</a></big> or <a href=\"$IS_CONFIG[shop_url]\">Return to products</a>";
}else{
echo "<br/><big>This product is currently out of stock!</big> <a href=\"$IS_CONFIG[shop_url]\">Return to products</a>";
}
if($line['image']) echo "<br/><img src=\"$IS_CONFIG[image_dir]$line[image]\" style=\"border:1px solid black;\"/>";
}//showDetails
function showCart(){
global $IS_CONFIG;
if($_GET['add']){
if(isset($_SESSION['cart'][$_GET['add']])){
$_SESSION['cart'][$_GET['add']]++;
}else{
$_SESSION['cart'][$_GET['add']] = 1;
}
}elseif($_GET['remove']){
unset($_SESSION['cart'][$_GET['remove']]);
}elseif($_GET['qty'] == "down" and $_GET['id']){
$_SESSION['cart'][$_GET['id']]--;
if($_SESSION['cart'][$_GET['id']] == 0){
unset($_SESSION['cart'][$_GET['id']]);
}
}elseif($_GET['qty'] == "up" and $_GET['id']){
$_SESSION['cart'][$_GET['id']]++;
}
if(!isset($_SESSION['cart']) or count($_SESSION['cart']) == 0){
echo 'Your '.$IS_CONFIG['cart'].' is empty.<br/><br/><a href="'.$IS_CONFIG[shop_url].'">Click here to view our products</a>';
include("../footer.php");
exit;
}
$idin = null;
foreach($_SESSION['cart'] as $key => $value){
$idin[] = $key;
}
$idin = join(",",$idin);
$query = "SELECT * FROM $IS_CONFIG[db_table] WHERE id in($idin)";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<b>Your Shopping $IS_CONFIG[cart]:</b><br/>";
echo "<table width=\"100%\" cellpadding=\"5\">
<td><b>Product</b></td><td align=\"center\"><b>Quantity</b></td><td align=\"right\"><b>Price</b></td><td><b>Remove</b></td>";
$total = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>";
echo "<td><a href=\"$IS_CONFIG[shop_url]";
if($IS_CONFIG['rewrite_urls']){
echo $line['id'].'-'.ereg_replace("[^A-Za-z0-9\-]", "", str_replace(" ","-",$line['title'])).".html";
}else{
echo "?c=details&id=$line[id]";
}
echo "\">$line[title]</a></td><td align=\"center\">
<a href=\"$IS_CONFIG[shop_url]?c=cart&qty=down&id=$line[id]\">-</a> ".$_SESSION['cart'][$line['id']]." <a href=\"$IS_CONFIG[shop_url]?c=cart&qty=up&id=$line[id]\">+</a></td><td align=\"right\">$IS_CONFIG[currency_symbol]$line[price]</td><td><a href=\"$IS_CONFIG[shop_url]?c=cart&remove=$line[id]\">Remove all from $IS_CONFIG[cart]</a></td>";
echo "</tr>";
$total = $total + ($line['price'] * $_SESSION['cart'][$line['id']]);
}
echo "<td> </td><td> </td><td align=\"right\"><b>Total: $IS_CONFIG[currency_symbol]$total</b></td><td> </td>";
echo "</table>";
$_SESSION['carttotal'] = $total;
echo "<br/><big><a href=\"$IS_CONFIG[shop_url]";
if($IS_CONFIG['rewrite_urls']){
echo "checkout/";
}else{
echo "?c=checkout";
}
echo "\">Purchase here using Google Checkout</a></big> or <a href=\"$IS_CONFIG[shop_url]\">Return to products</a>";
}//showCart
function showCartOverview(){
global $IS_CONFIG;
echo '<div style="border:1px solid black;background-color:#333333;padding:4px;color:white;width:150px;float:right;margin:4px;">';
if(!isset($_SESSION['cart']) or count($_SESSION['cart']) == 0){
echo 'Your '.$IS_CONFIG['cart'].' is empty.';
}else{
if(count($_SESSION['cart']) == 1){
$s = "product";
}else{
$s = "different products";
}
echo 'You have <b>'.count($_SESSION['cart']).'</b> '.$s.' totaling <b>'.$IS_CONFIG['currency_symbol'].$_SESSION['carttotal'].'</b> in your '.$IS_CONFIG['cart'].'.';
echo '<br/><a href="'.$IS_CONFIG['shop_url'];
if($IS_CONFIG['rewrite_urls']){
echo "cart/";
}else{
echo "?c=cart";
}
echo '">Click here</a> to view your '.$IS_CONFIG['cart'].'.';
}
echo '</div>';
}//showCartOverview
function showCheckout(){
global $IS_CONFIG;
if(!isset($_SESSION['cart']) or count($_SESSION['cart']) == 0){
echo 'Your '.$IS_CONFIG['cart'].' is empty.<br/><br/><a href="$IS_CONFIG[shop_url]">Click here to view our products</a>';
exit;
}
$idin = null;
foreach($_SESSION['cart'] as $key => $value){
$idin[] = $key;
}
$idin = join(",",$idin);
$query = "SELECT * FROM $IS_CONFIG[db_table] WHERE id in($idin)";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<b>Checkout</b><br/>";
echo "<a href=\"$IS_CONFIG[shop_url]";
if($IS_CONFIG['rewrite_urls']){
echo "cart/";
}else{
echo "?c=cart";
}
echo "\">Click here to make changes to your order</a>";
if($IS_CONFIG['sandbox']){
echo '<form method="POST" action="https://sandbox.google.com/checkout/cws/v2/Merchant/'.$IS_CONFIG['sandbox_merchantid'].'/checkoutForm" accept-charset="utf-8">';
}else{
echo '<form method="POST" action="https://checkout.google.com/cws/v2/Merchant/'.$IS_CONFIG['merchantid'].'/checkoutForm" accept-charset="utf-8">';
}
echo "<table width=\"100%\" cellpadding=\"5\">
<td><b>Product</b></td><td align=\"center\"><b>Quantity</b></td><td align=\"right\"><b>Price Each</b></td><td> </td>";
$total = 0;
$count = 1;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>";
echo "<td>$line[title]</td><td align=\"center\">".$_SESSION['cart'][$line['id']]."</td><td align=\"right\">$IS_CONFIG[currency_symbol]$line[price]</td></td>";
echo '<td><input type="hidden" name="item_name_'.$count.'" value="'.$line['title'].'"/>
<input type="hidden" name="item_description_'.$count.'" value="'.$line['description'].'"/>
<input type="hidden" name="item_quantity_'.$count.'" value="'.$_SESSION['cart'][$line['id']].'"/>
<input type="hidden" name="item_price_'.$count.'" value="'.$line['price'].'"/>
<input type="hidden" name="item_currency_'.$count.'" value="'.$IS_CONFIG['currency_code'].'"/></td>';
echo "</tr>";
$total = $total + ($line['price'] * $_SESSION['cart'][$line['id']]);
$count++;
}
echo "<td> </td><td> </td><td align=\"right\"><b>Sub Total: $IS_CONFIG[currency_symbol]$total</b></td><td> </td>";
echo "</table>";
echo '<b>Available delivery options:</b><br/>';
for($i=0;$i<count($IS_CONFIG['delivery_names']);$i++){
echo '<input type="hidden" name="ship_method_name_'.($i+1).'" value="'.$IS_CONFIG['delivery_names'][$i].'"/>
<input type="hidden" name="ship_method_price_'.($i+1).'" value="'.$IS_CONFIG['delivery_prices'][$i].'"/>
<input type="hidden" name="ship_method_currency_'.($i+1).'" value="'.$IS_CONFIG['currency_code'].'"/>';
echo ' - '.$IS_CONFIG['delivery_names'][$i].'<br/>';
}
echo '<br/><br/><div align="center"><input type="image" name="Google Checkout" alt="Fast checkout through Google" src="';
if($IS_CONFIG['sandbox']){
echo 'http://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id='.$IS_CONFIG['sandbox_merchantid'].'&w=180&h=46&style=white&variant=text&loc='.$IS_CONFIG['location'];
}else{
echo 'https://checkout.google.com/buttons/checkout.gif?merchant_id='.$IS_CONFIG['merchantid'].'&w=180&h=46&style=white&variant=text&loc='.$IS_CONFIG['location'];
}
echo 'height="46" width="180"/></div>
</form>';
}//showCheckout
?>