<?php
/*-----------------------------------------------------------
|   Countdown Panel for zWar Clan-Infusion				|
|															|
|	Copyright (C) 2006-2008 Christoph Schreck				|
|	zezoar@gmx.net											|
|	http://www.zoffclan.de/zoffdev/							|
|															|
|   This program is free software; 							|
|	you can redistribute it and/or modify it under 			|
|	the terms of the GNU General Public License 			|
|	as published by the Free Software Foundation; 			|
|	either version 3 of the License, 						|
|	or (at your option) any later version.					|
|															|
|   This program is distributed in the hope that 			|
|	it will be useful, but WITHOUT ANY WARRANTY; 			|
|	without even the implied warranty of MERCHANTABILITY 	|
|	or FITNESS FOR A PARTICULAR PURPOSE. 					|
|	See the GNU General Public License for more details.	|
|															|
|   You should have received a copy of the 					|
|	GNU General Public License along with this program; 	|
|	if not, see <http://www.gnu.org/licenses/>.				|
-----------------------------------------------------------*/
if (!defined("IN_FUSION")) { die("Access Denied"); }

if (file_exists(INFUSIONS."zwar_countdown_panel/locale/".$settings['locale'].".php")) {
	include_once INFUSIONS."zwar_countdown_panel/locale/".$settings['locale'].".php";
} else {
	include_once INFUSIONS."zwar_countdown_panel/locale/English.php";
}

if (file_exists(INFUSIONS."zwar_warscript/zwar_functions.php") && dbcount("(inf_id)", DB_INFUSIONS, "inf_folder='zwar_warscript'")) {
	require_once INFUSIONS."zwar_warscript/zwar_functions.php";
		
	openside($p_data['panel_name'], true, "on");
	$result = dbquery("SELECT * FROM ".DB_ZWAR_WARS." AS zw LEFT JOIN ".DB_ZWAR_OPPONENTS." AS zop ON zw.war_opp_id=zop.opp_id WHERE war_date>'".(time()+($settings['timeoffset']*3600))."' ORDER BY war_date ASC LIMIT 1");
	if (dbrows($result)) {
		$data = dbarray($result);
		echo "<div style='text-align:center;'>
		<div style='text-align:center; font-size:15px; font-weight:bold;' id='zw_countdown_dcont'></div>
		<div style='text-align:center; font-size:12px; margin-bottom:5px;' id='zw_countdown_tcont'></div>
		".$locale['zwar_cdp01']."<br/>
		<a href='".BASEDIR."zwar.php?page=war_details&warid=".$data['war_id']."'>".$data['opp_name']."</a><br/>
		".display_zwar_games($data['war_game_id'], true, false)."
		</div>";
		echo "<script type=\"text/javascript\">
		function zw_countdown() {
			var datenow = new Date();
			var ct = Math.floor(".$data['war_date']."-datenow.getTime()/1000);
			var d = Math.floor(ct/(24*3600));
			var h = Math.floor((ct-d*(24*3600))/3600);
			var m = Math.floor((ct-(d*24+h)*3600)/60);
			var s = (ct-((d*24+h)*60+m)*60);
			var p1  = ((h < 10) ? '0' : '');
			var p2  = ((m < 10) ? ':0' : ':');
			var p3  = ((s < 10) ? ':0' : ':');
			var ctime=p1+h+p2+m+p3+s;
			document.getElementById('zw_countdown_tcont').innerHTML=ctime;
			document.getElementById('zw_countdown_dcont').innerHTML=d+' ".$locale['zwar_cdp02']."';
			window.setTimeout(\"zw_countdown()\", 1000);
		}
		zw_countdown();
		</script>";
	} else {
		echo "<div style='text-align:center;' class='zwarpanel'>".$locale['zwar_cdp03']."</div>\n";
	}
	closeside();
}
?>