File: D:/HostingSpaces/SBogers10/spire.komma-mediadesign.nl/wwwroot/forwards/old_product_fwd.php
<?php
/**
* c_old_id.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 6/24/13
*/
require_once 'config/config_db.php';
require_once 'kms/app/models/m_dbHandler.php';
if(isset($_GET['ProdID']))
{
$oldId = $_GET['ProdID'];
$data = array();
$tables = array('cpucoolers','pccases','mobileaccessories','pcaccessories','powersupply','systemcooling','tabletpc');
$found = false;
foreach($tables as $table)
{
if( ! $found)
{
$Dbh = new DatabaseHandler();
$Dbh->setTableName('page_' . $table . '_items');
$Dbh->setData(array('catId'=>'','title'=>'','productCode'=>''));
$Dbh->addRule('oldSiteId',$oldId);
$Dbh->setScope(0,1);
if($data = $Dbh->select())
{
$found = true;
}
}
}
if($found)
{
$Dbh = new DatabaseHandler();
$Dbh->setTableName('page_categorieen_items');
$Dbh->setData(array('title'=>''));
$Dbh->addRule('id',$data['catId']);
$Dbh->setOrder('id','ASC');
$cat = $Dbh->select();
$linkCat = encodeUrl($cat['title']);
$linkTitle = encodeUrl($data['title']) . '-' . encodeUrl($data['productCode']);
// redirect to default page
header ('HTTP/1.1 301 Moved Permanently');
header("Location: /" . $linkCat . "/" . $linkTitle . "/");
exit;
}
else
{
header("HTTP/1.0 404 Not Found");
header('location:'.LANG_ROOT.'404');
exit;
}
}
else
{
header("HTTP/1.0 404 Not Found");
header('location:'.LANG_ROOT.'404');
exit;
}
function encodeUrl($input)
{
$output = trim($input);
$output = str_replace(' ','-',$output);
//remove these characters
$forbidden = array("'", '"', '\\', '/', ';', ';', '|', '>', '<', '[', ']', '!','?', '@', '#', '$', '%', '^', '&', '*', '(', ')','+','=','{','}','`', '~', '.', ',');
foreach($forbidden as $key => $value){
$output = str_replace($value, '', $output);
}
$output = strtolower($output);
$output = str_replace('--','',$output);
$output = str_replace('---','',$output);
return $output;
}