<?
#			maritime_Liste
#
#			Top_Liste 1.0
#
#			       in.php3

require("config.php3");

$TS_file_lines = file($site_log_file);
$TS_total_file_count = count($TS_file_lines);



// anti-cheat gateway
if(empty($vote) && $super_gateway == 1){

include($HEADER);


## sees what site they are voting for
for($i=0; $TS_total_file_count > $i; $i++){
$split = explode("||", $TS_file_lines[$i]);

	if($site == $split[2]){

		$site_voted_name = $split[3];
		$site_voted_link = $split[4];

		$found_site = 1;
	}
}
##

ECHO "<CENTER>$master_font_before";

if($found_site == 1){

echo "<br><br><h4>Du kommst von der Seite<br>\n";
echo "<a href=\"$site_voted_link\" target=_blank>$site_voted_name</a><br>\n";
echo "<br>Klicke auf den Button 'Abstimmen für diese Seite' von der du kommst,<br>
 um für diese Seite, <br>
in dem maritimen TOP - RING deine Stimme abzugeben.<p>\n";

echo "<form action=in.php3 method=post>\n";
echo "<input type=hidden name=site value=\"$site\">\n";
echo "<input type=submit name=vote value=\"Abstimmen für diese Seite\">\n";
echo "</form>\n";

}


echo "<a href=http://www.musterrolle.de/index.php?option=com_weblinks&catid=13&Itemid=45><br><br><br><h6>Besuche den maritimen TOP -
RING ohne für die Seite von der du kommst zu stimmen.</a></center>$master_font_after\n";

// echo "<a href=list.php3>Besuche den maritimen TOP - RING ohne für die Seite von der du kommst zu stimmen.</a></center>$master_font_after\n";

include($FOOTER);

} elseif(!empty($vote) && !eregi("$url_to_folder/in.php3",$HTTP_REFERER) && $super_gateway == 1){

header("location: $url_to_folder/list.php3");

} else {

#####
$timeout_file = file($vote_timeout_file);
$timeout_total = count($timeout_file);


for($i=0; $timeout_total > $i; $i++){
$split = explode("||", $timeout_file[$i]);

if($split[2] <= time()){

	if($edited_timeout != 1){
		$fp = fopen($vote_timeout_file, "r");
		flock($fp,1);
		$after = fread($fp, filesize($vote_timeout_file));
		fclose($fp);
	}

$after = str_replace("$timeout_file[$i]","", $after);

$edited_timeout = 1;

}


}

	// updates the file if it was edited
if($edited_timeout == 1){
		$fp = fopen($vote_timeout_file, "w");
		flock($fp,2);
		$fw = fwrite($fp, $after);
		fclose($fp);

	}

// does anti-cheating goodness
#####
$timeout_file = file($vote_timeout_file);
$timeout_total = count($timeout_file);

###

// cookie anti-cheat
if($HTTP_COOKIE_VARS["top_list_gatekeeper_$site"] != 1){
setcookie("top_list_gatekeeper_$site", "1", (time()+(3600 * $vote_timeout_hours)));
} else { $gateway = 1; }

###


for($i=0; $timeout_total > $i; $i++){
$split = explode("||", $timeout_file[$i]);

if(($split[0] == $REMOTE_ADDR) && ($split[1] == $site)){
$gateway = 1;
}

}

if($gateway != 1){

$timout_hour = time()+(3600 * $vote_timeout_hours);

$fp = fopen($vote_timeout_file, "a");
flock($fp,2);
$fw = fwrite($fp, "$REMOTE_ADDR||$site||$timout_hour||\n");
fclose($fp);
}

#####

if($gateway != 1){

for($i=0; $TS_total_file_count > $i; $i++){
$split = explode("||", $TS_file_lines[$i]);

if($split[2] == $site){

$before = "$split[0]||$split[1]||$split[2]||";
$split[1]++;
$after = "$split[0]||$split[1]||$split[2]||";

$fp = fopen($site_log_file, "r");
flock($fp,1);
$x = fread($fp, filesize($site_log_file));
fclose($fp);

$after = str_replace("$before","$after", $x);

$fp = fopen($site_log_file, "w");
flock($fp,2);
$fw = fwrite($fp, $after);
fclose($fp);

		}
	}
}

if($gateway == 1){ $cheat = "?gate=y"; }
if($gateway != 1){ $cheat = "?gate=n"; }

header("location: $url_to_folder/list.php3$cheat");

}
?>