// uwaga na istniejące katalogi
include("inc.sqlconnect.php");
$debug=0;
$uri_page_parts = split("/",$_REQUEST[page]);
if ($uri_page_parts[0]=='') header("Location: /");
// sprawdz czy jest taki adres
$request = mysql_query("SELECT id FROM `menu` WHERE addr='".$_REQUEST[page]."'");
if ($stu = @mysql_fetch_object($request))
{
$id=$stu->id;
}
if ($debug==1) echo "1=$id id_location=$id_location
";
// sprawdz czy jest taki adres z / na koncu
if ($id=='')
{
$request = mysql_query("SELECT id FROM `menu` WHERE addr='".$_REQUEST[page]."/'");
if ($stu = @mysql_fetch_object($request))
{
$id_location=$stu->id;
}
}
if ($debug==1) echo "2=$id id_location=$id_location
";
// sprawdz czy jest id na końcu
if ($id=='')
{
if ($uri_page_parts[count($uri_page_parts)-1]=='') $id=$uri_page_parts[count($uri_page_parts)-2];
else $id=$uri_page_parts[count($uri_page_parts)-1];
if (!is_numeric($id)) $id='';
//sprawdź czy jest już nowy adres
if ($id)
{
$request = mysql_query("SELECT id FROM `menu` WHERE addr!='".$_REQUEST[page]."' AND id='$id' AND active=1");
if ($stu = @mysql_fetch_object($request))
{
$id_location=$stu->id;
}
// sprawdź czy znalezione id istnieje
if ($id)
{
$request = mysql_query("SELECT count(*) FROM `menu` WHERE id='$id'");
$stu = @mysql_fetch_object($request);
if ($stu->ile!=1) $id='';
}
}
}
if ($debug==1) echo "3=$id id_location=$id_location
";
// sprawdz czy jest id dla faq
if ($id=='')
{
if($uri_page_parts[0]=='faq')
{
$uri_page_parts_faq_id = split("_",$uri_page_parts[1]);
$faq_id=$uri_page_parts_faq_id[0];
}
}
if ($debug==1) echo "4=$id id_location=$id_location
";
//sprawdzic czy nie zmienił sie adres dla pytania
if ($id=='' && $faq_id)
{
$request = mysql_query("SELECT count(*) as ile FROM faq WHERE id='".$faq_id."' AND addr='".eregi_replace('\.html$','',eregi_replace('^faq/','',$_REQUEST[page]))."'");
$stu = @mysql_fetch_object($request);
if ($stu->ile==0)
{
$id_location_faq=$faq_id;
}
}
if ($debug==1) echo "5=$id id_location=$id_location
";
// sprawdz czy był kiedys taki adres
if ($id=='' && $faq_id=='')
{
$request = mysql_query("SELECT * FROM uri_history WHERE uri='".$_REQUEST[page]."'");
if ($stu = @mysql_fetch_object($request))
{
if ($stu->contents_id)$id_location=$stu->contents_id;
if ($stu->faq_id) $id_location_faq=$stu->faq_id;
}
}
if ($debug==1) echo "6=$id id_location=$id_location
";
//sprawdzam w dół po strukturze katalogowej
if (!$id && !$faq_id && !$id_location && !$id_location_faq)
{
for($i=count($uri_page_parts)-1;$i>0;$i--)
{
$test_uri='';
for($j=0;$j<$i;$j++)
{
$test_uri.=$uri_page_parts[$j]."/";
}
$request = mysql_query("SELECT id FROM `menu` WHERE addr='".$test_uri."' AND active=1");
if ($stu = @mysql_fetch_object($request))
{
$id_location=$stu->id;
break;
}
}
}
if ($debug==1) echo "7=$id id_location=$id_location
";
// sprawdz czy ma być przekierowanie
if ($id_location)
{
$request = mysql_query("SELECT addr FROM `menu` WHERE id='".$id_location."'");
$stu = @mysql_fetch_object($request);
header("HTTP/1.1 301 Moved Permanently");
header("Location: /".$stu->addr."");
die;
}
if ($id_location_faq)
{
$request = mysql_query("SELECT addr FROM faq WHERE id='".$id_location_faq."'");
$stu = @mysql_fetch_object($request);
header("HTTP/1.1 301 Moved Permanently");
header("Location: /faq/".$stu->addr.".html");
die;
}
if ($debug==1) echo "8=$id id_location=$id_location
";
if (!$id && !$faq_id && !$id_location && !$id_location_faq)
{
header("HTTP/1.0 404 Not Found");
// echo "Przekierowanie na stronę główną lub stronę błędu
";
echo "
404 Plik nie istnieje
| |
Przepraszamy, ale plik, który próbujesz wy¶wietlić, nie istnieje.
Zapraszamy na nasz± stronę www.dianthus.pl
|
";
die;
}
if ($debug==1) echo "9=$id id_location=$id_location
";
if ($id) include("inc.template.php");
?>