<?php

// No error reporting :
// error_reporting(E_ALL);
error_reporting(0);

// Required libraries :
require_once 'php/WebVS.php';
require_once 'php/Session.php';
require_once 'php/config.inc';

// Required to set up site parameters :
$webvs = new WebVS($sitename, $domain, $language, $dbserver, $dbuser, $dbpass, $dbname);

// Session Handling :
$session = new Session();

// Get previous response :
if( isset($_POST['win']) && isset($_POST['action']) ) {
	$winV = $_POST['win'];
	$action = $_POST['action'];

	// Get Votes from Session Token :
	if($winV == 'A') {
		$win = $session->get('voteA');
		$lose = $session->get('voteB');
	} else {
		$win = $session->get('voteB');
		$lose = $session->get('voteA');
	}

	$webvs->processVote($win, $lose, $action);
} else {
	$win = "";
	$lose = "";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
	<link rel="stylesheet" href="/styles.css" type="text/css" media="screen" />
	<link rel="shortcut icon" href="favicon.ico" />
	<meta http-equiv="imagetoolbar" content="false" />
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="keywords" content="<?=$metakeywords?>" />
	<title>PuppyWar - Vote for your favorite cute puppy pictures!</title>

	<script language="JavaScript" type="text/javascript">
	<!--
		function voteA () {
			document.voteA.submit();
		}

		function voteB () {
			document.voteB.submit();
		}

		function voteD () {
			document.fDraw.submit();
		}

	//-->
	</script>
</head>

<body>

<div align="center">
<div id="banner">
	<a href="https://<?=$domain?>"><img src="/images/puppywar.jpg" border="0" height="98" width="800" alt="PuppyWar"/></a>
	<p>
	<?php echo $webvs->topMenu(); ?>
	</p>
</div>


<div id="main">
	<?php
		$previous = $webvs->getPrevious($win, $lose);
		$votefor = $webvs->getCompare($win, $lose);

		$session->set('voteA', $votefor[0][0]);
		$session->set('voteB', $votefor[1][0]);
	?>
	<table cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr>
			<td width="150" id="results" valign="top"><p>
			<?php if($previous != "") { //will break out of PHP only if results should display 
				if($action == "draw") {
					echo '<img src="/images/results.jpg" alt="results" title="results" />';
					} else {
						echo '<img src="/images/winner.jpg" alt="winner" title="winner" />';
					}
				?>
				<a href="/stats.php?id=<?=$previous[0][0]?>">
				<img src="<?=$previous[0][2]?>" alt="<?=$previous[0][1]?>" title="<?=$previous[0][1]?>" 
				width="125" height="125" border="0" /></a><br /><strong><?=$previous[0][1]?></strong>
				<em>[<?=$previous[0][3]?>%]</em>
				</p><p>
					<?php
						if($action == "draw") {
							echo "<img src=\"/images/draw.jpg\" alt=\"draw\" title=\"draw\"/>\r\n";
						} else {
							echo "<img src=\"/images/loser.jpg\" alt=\"loser\" title=\"loser\"/>\r\n";
						}
					?>
				<br />
				<a href="/stats.php?id=<?=$previous[1][0]?>">
				<img src="<?=$previous[1][2]?>" alt="<?=$previous[1][1]?>" title="<?=$previous[1][1]?>" 
				width="125" height="125" border="0" /></a><br /><strong><?=$previous[1][1]?></strong>
				<em>[<?=$previous[1][3]?>%]</em><br/><br/>
				<img src="/images/stats.jpg" alt="Click Pics for Stats" title="Click Pics for Stats" />
			<?php } //back in PHP to close "if" bracket ?>
			</p></td>
			<td width="550" id="vote" valign="top">
				<table cellpadding="0" cellspacing="0" border="0" width="550" id="votetable">
				<tr><td colspan="3"><!--<strong><font color="red">MAINTENANCE TIME</strong> - We're working on some improvements behind the scenes, so if the site behaves oddly please excuse the disruption; it should be short lived.</font><br/>--><strong>Puppy War!</strong> Pick the cutest puppy picture.<!--<br/>Moderators wanted. Click <a href="about.php">here</a> for info.--><br/>&nbsp;</td></tr>
				
				<tr>
					<td><form action="https://<?=$domain?>" name="voteA" method="post">
						<a href="JavaScript: voteA();">
						<img src="<?=$votefor[0][2]?>" alt="<?=$votefor[0][1]?>" 
						title="<?=$votefor[0][1]?>" border="0" width="250" height="250" /></a>
						<br /><strong><?=$votefor[0][1]?></strong>
						<input type="hidden" name="win" value="A" />
						<input type="hidden" name="action" value="vote" />
					</form></td>

					<td align="center"><img src="/images/vs.jpg" alt="vs" title="vs"/></td>

					<td><form action="https://<?=$domain?>" name="voteB" method="post">
						<a href="JavaScript: voteB();">
						<img src="<?=$votefor[1][2]?>" alt="<?=$votefor[1][1]?>" 
						title="<?=$votefor[1][1]?>" border="0" width="250" height="250" /></a>
						<br /><strong><?=$votefor[1][1]?></strong>
						<input type="hidden" name="win" value="B" />
						<input type="hidden" name="action" value="vote" />
					</form></td>
				</tr>
				<tr><td colspan="3">
					<form action="https://<?=$domain?>" name="fDraw" method="post">
					<p><a href="JavaScript: voteD();"><u>I can't decide! (Draw)</u></a></p>
					<input type="hidden" name="win" value="X" />
					<input type="hidden" name="action" value="draw" />
					</form>
				</td></tr>

				</table>
			</td>
			<td width="150" id="sponsor">
			<p>
				<!--<?php include('advertSideMain.php'); ?>-->
			</p>
			<!--<p align="center">
				<a href="http://www.dailypuppy.com" onClick="javascript:urchinTracker('/outgoing/dailypuppy_com');" target="_blank"><img src="http://dailypuppy.com/images/dpicon120X20.gif" border="0"/></a>
			</p>-->
			<p align="center">
				&nbsp;
			</p>
			</td>
		</tr>
	</table>
</div>

<p align="center">
<?php include('advertBase.php'); ?>
</p>

</div>
</body>
</html>
