<?php

	// Cache
	require_once('dis_cache.php');

	if(!isset($_REQUEST['ordner_id']) || !isset($_REQUEST['page'])){
		header('Location: /');
		die();
	}

	$ordner_id = $_REQUEST['ordner_id'];
	$id = $_REQUEST['page'];
	
	if(substr($id, -1) == 'w'){
		$werbung = true;
		$id = substr($id, 0, -1);
	}else{
		$werbung = false;
	}
	
	if(($p = strpos($id, '.')) !== false){
		$page = substr($id, $p+1);
		$id = substr($id, 0, $p);
	}else{
		$page = 0;
	}

	if(file_exists('../foto/'.substr($id, -2).'/'.substr($id, -4, 2).'/'.$id.'/foto.dat')){
		// foto!
		$FOTO = @unserialize(@file_get_contents('../foto/'.substr($id, -2).'/'.substr($id, -4, 2).'/'.$id.'/foto.dat'));
		$strecke_id = $FOTO['strecke_id'];
		$dst = $id.($werbung ? 'w' : '').'.html';
	}else if(file_exists('../data/strecke/'.substr($id, -2).'/'.substr($id, -4, 2).'/'.$id.'.dat')){
		$strecke_id = $id;
		$dst = $id.'s'.($page > 0 ? $page+1 : '').'.html';
	}else{
		$ERROR404 = 'id not found';
		require_once('dis_404.php');
	}
	
	$STRECKE = @unserialize(@file_get_contents('../data/strecke/'.substr($strecke_id, -2).'/'.substr($strecke_id, -4, 2).'/'.$strecke_id.'.dat'));

	if(!is_array($STRECKE)){
		$ERROR404 = 'no strecke';
		require_once('dis_404.php');
	}

	header('HTTP/1.1 301 Moved Permanently');
	header('Location: '.$STRECKE['url_base'].$dst);

?>