<?php
	// Created by Marcus Tillmanns 23. Aug. 2003
	// All rights reserved :) Use as you like, but don't say you wrote it. That pretty sucks :)
	
	// Purpose: Insert some foreign Homepage into a Side Modul. We use it to display a Train plan
	// You know, to query the time your train arives.
	// This Version of the Script loads the Transport Provider of my Home town, Bremen in Germany.
	// But you can simply insert your own Urls and replacements. We for example replaced all urls
	// so they point to the corrent Website. Thats pretty simple with Str_replace. But read the comments.
	
	
	// Vars:
	$source_url 	= "http://www.bsag.de"; // /index.html but we don't need it. 
	
	$start_Pattern	= "<form class=\"fahrplanauskunft-home\"";
	$end_Pattern	= "</form>";
	
	// Initialization
	require_once('tiki-setup.php');
	include_once('lib/wiki/wikilib.php');

	// Features whats that ? If you like, implement	one. Furtermore, all the Setup, 
	// could be done in Wiki too. But I didn't had the time too. This is my forth script in 3 days :)
	// Tiki roxx :)
	
	if($feature_wiki != 'y') {
	  die;  
	}

	// Open the Source URL, to acquire all Data.
	$fp = fopen($source_url, "r");
	
	$readBuf = "";
	// Read all Data into readBuf.
	// I thought about Letting the script search for the start and later the end tag
	// while loading, but didn't knew if that would weight the performance.
	
	while(!feof($fp))
	{
		$readBuf .= fread($fp, 1);
	}
	// Close the Source.
	fclose($fp);
	// Search for start and end Pattern to extract the "box" that we wan't
	$start = strpos($readBuf, $start_Pattern);
	$end = strpos($readBuf, $end_Pattern, $start);
	$box = substr($readBuf, $start, $end - $start + strlen($end_Pattern));
	
	// replace the hrefs etc.
	$box = replaceSpecifics($box);
	
	// Well, just for the look :)
	$content = $box;
	
	// Set the "data" Var for smarty so he can insert it into the TPL
	$smarty->assign_by_ref('data',$content);
	// This loads the Bsag_boxstat Cookie into the template to decide wether it should be open or not.
	$smarty->assign_by_ref('bsag_boxstate',$bsagBoxCook);
	

	// Replaces all Location specific links etc. 
	function replaceSpecifics($box)
	{
		$box = Str_replace("action=\"", "action=\"http://www.bsag.de", $box);
		$box = Str_replace("src=\"", "src=\"http://www.bsag.de", $box);
		
		$box = Str_replace("onMouseover=\"simpleOver(this, '/px/navigation/button_suche-aktiv.gif')\"", "", $box);
		$box = Str_replace("onMouseout=\"simpleOut(this, '/px/navigation/button_suche-passiv.gif')\"", "", $box);
	
		$box = Str_replace("onMouseover=\"simpleOver(this, '/px/navigation/button_erweitert-aktiv.gif')\"", "", $box);
		$box = Str_replace("onMouseout=\"simpleOut(this, '/px/navigation/button_erweitert-passiv.gif')\"", "", $box);
		$box = Str_replace("<fieldset >", "<fieldset width=1>", $box);
		
		return $box;
	}


?>