<?php
$s = settings('shop_page');
if($url['pid'] == $s['shop_page'])
{
$notFound = true;
//if $_GET['junk'] is not set, show the shop categories
if(!isset($_GET['junk']))
{
$notFound = false;
$parent = 0;
include(fileInclude('inc/shop/cats.php'));
}
else//$_GET['junk'] is set
{
$junk = $form->clean_fields($_GET['junk']);
//is it a category?
$query = $mysql->query("ID", "fs_shop_cats", "url_key = '$junk' LIMIT 1");
//check the url log to make sure the product was not renamed at some point
$logQuery = $mysql->query("new_url", "fs_url_log", "type = 'category' AND old_url = '$junk' ORDER BY ID DESC LIMIT 1");
if($mysql->num_rows($logQuery) == 1)
{
$log = $mysql->get_array($logQuery);
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: /{$_GET['pid']}/{$_GET['page']}/{$log['new_url']}");
exit;
}
$check = $mysql->num_rows($query);
if($check == 1)
{
//see if the category has any subs
$cat = $mysql->get_array($query);
$check = $mysql->num_rows($mysql->query("ID", "fs_shop_cats", "sub = {$cat['ID']} ORDER BY ID DESC LIMIT 1"));
if($check == 0)//doesnt have subs, show products in the category
{
include(fileInclude('inc/shop/products_in_cat.php'));
$notFound = false;
}
else//has subs
{
$parent = $cat['ID'];
include(fileInclude('inc/shop/cats.php'));
$notFound = false;
}
}
//is it a product?
if($check == 0)
{
$check = $mysql->num_rows($mysql->query("ID", "fs_shop_products", "url_key = '$junk' LIMIT 1"));
//check the url log to make sure the product was not renamed at some point
$logQuery = $mysql->query("new_url", "fs_url_log", "type = 'product' AND old_url = '$junk' ORDER BY ID DESC LIMIT 1");
if($mysql->num_rows($logQuery) == 1)
{
$log = $mysql->get_array($logQuery);
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: /{$_GET['pid']}/{$_GET['page']}/{$log['new_url']}");
exit;
}
//
if($check == 1)
{
include(fileInclude('inc/shop/product.php'));
$notFound = false;
}
}
//is it the basket page?
if($_GET['junk'] == 'Basket')
{
include(fileInclude('inc/shop/Basket.php'));
$notFound = false;
}
//is it the best sellers page?
if($_GET['junk'] == 'Best-Sellers')
{
include(fileInclude('inc/shop/BestSellers.php'));
$notFound = false;
}
//is it new arriaslvs page?
if($_GET['junk'] == 'New-Arrivals')
{
include(fileInclude('inc/shop/NewArrivals.php'));
$notFound = false;
}
//is it view all products page?
if($_GET['junk'] == 'AllProducts')
{
include(fileInclude('inc/shop/AllProducts.php'));
$notFound = false;
}
//is it search page?
if($_GET['junk'] == 'Search')
{
include(fileInclude('inc/shop/Search.php'));
$notFound = false;
}
//is the checkout page?
if($_GET['junk'] == 'Checkout')
{
include(fileInclude('inc/shop/Checkout.php'));
$notFound = false;
}
//is the payment page?
if($_GET['junk'] == 'Payment')
{
include(fileInclude('inc/shop/Payment.php'));
$notFound = false;
}
//is the shipping error page?
if($_GET['junk'] == 'Shipping_Error')
{
include(fileInclude('inc/shop/shipping/shipping_error.php'));
$notFound = false;
}
//is the bank/cash on dec processing page page?
if($_GET['junk'] == 'Bank')
{
include(fileInclude('inc/shop/Bank.php'));
$notFound = false;
}
//is the thank you page?
if($_GET['junk'] == 'Thankyou')
{
include(fileInclude('inc/shop/thankyou.php'));
$notFound = false;
}
//if error is set to true, redirect to 404
if($notFound == true)
{
header("Location: /2/Error");
exit;
}
//
}
}
?>