<?php
header('Content-type: text/html; charset=utf-8');

    $roundinfo[0]['name'] = str_replace("_", " ", $roundinfo[0]['name']);
    $roundinfo[0]['origname'] = $roundinfo[0]['name'];
	$roundinfo[0]['name'] = preg_replace("/v(\d) (\d+)/i", "", $roundinfo[0]['name']);
	$roundinfo[0]['name'] = preg_replace("/(\d) (\d+)/i", "", $roundinfo[0]['name']);
	$roundinfo[0]['name'] = trim ($roundinfo[0]['name']);
	$roundinfo[0]['name'] = ucwords(strtolower($roundinfo[0]['name']));

if ($roundinfo[0]['tickets1'] > $roundinfo[0]['tickets2']) {$roundinfo[0]['tickets1'] = "<b>".$roundinfo[0]['tickets1']."</b>";}
if ($roundinfo[0]['tickets2'] > $roundinfo[0]['tickets1']) {$roundinfo[0]['tickets2'] = "<b>".$roundinfo[0]['tickets2']."</b>";}
    $roundinfo[0]['sum']  = $roundinfo[0]['pids1'] + $roundinfo[0]['pids2'];
    $roundinfo[0]['sum_end']  = $roundinfo[0]['pids1_end'] + $roundinfo[0]['pids2_end'];
    $roundinfo[0]['mapsize'] = "32";
    if ($roundinfo[0]['sum'] < 17 ) {$roundinfo[0]['mapsize'] = "16";}
    if ($roundinfo[0]['sum'] > 38 ) {$roundinfo[0]['mapsize'] = "64";}
    if ($roundinfo[0]['team1'] > 12) {$roundinfo[0]['team1'] = 404;}
    if ($roundinfo[0]['team2'] > 12) {$roundinfo[0]['team2'] = 404;}
$medals[0] = $proundinfo[0]['id'];
$medals[1] = $proundinfo[1]['id'];
$medals[2] = $proundinfo[2]['id'];

$template = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" class="inner">
<head>

<title>'.$PRETITLE.' - '.Lastbattle.'</title>

<link rel="icon" href="'.$ROOT.'favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="'.$ROOT.'favicon.ico" type="image/x-icon">

<link rel="stylesheet" type="text/css" media="screen" href="'.$ROOT.'css/two-tiers.css">
<link rel="stylesheet" type="text/css" media="screen" href="'.$ROOT.'css/nt.css">
<link rel="stylesheet" type="text/css" media="print" href="'.$ROOT.'css/print.css">
<link rel="stylesheet" type="text/css" media="screen" href="'.$ROOT.'css/default.css">

<script type="text/javascript">/* no frames */ if(top.location != self.location) top.location.replace(self.location);</script>
<script type="text/javascript" src="'.$ROOT.'js/nt2.js"></script></head><body class="inner">

<div id="page-1">
	<div id="page-2">

	<h1 id="page-title">'.$roundinfo[0]['name'].' <small>'.date("Y-m-d H:i",$roundinfo[0]['timestamp']).'</small></h1>

	<div id="page-3">

		<ul id="navitems">
			<li>|<a href="'.$ROOT.'">'.$lang_main.'</a>|</li>
            <li><a href="'.$ROOT.'/forum">'.$lang_forum.'</a>|</li>
            <li><a href="'.$ROOT.'?go=stats">'.$lang_top.'</a>|</li>
            <li><a href="'.$ROOT.'?go=currentranking">'.$lang_currentranking.'</a>|</li>
            <li><a href="'.$ROOT.'?go=lastrounds">'.$lang_lastrounds.'</a>|</li>
            <li><a href="'.$ROOT.'?go=banlist">'.$lang_banlist.'</a>|</li>
            <li><a href="'.$ROOT.'monitor.php">'.$lang_monetor.'</a>|</li>
			<li><a href="'.$ROOT.'?go=faq">'.$lang_faq.'</a>|</li>
            <li><a href="'.$ROOT.'?go=ubar">'.$lang_UBAR.'</a>|</li>
			<li><a href="http://wiki.bf2s.com/">'.$lang_Wiki.'</a>|</li>
		</ul>
	
		<form action="'.$ROOT.'?go=search" method="post" id="getstats">
			<label for="pid">'.$lang_search.':</label>
			<input type="text" name="searchvalue" id="pid" value="" />
			<input type="submit" class="btn" value="Go" />
		</form>
        
<br />';

	$template .= '
<table align=center width="98%" cellpadding="0" cellspacing="0" border="0" class="stat">
  <tr>';

	$check_image = @GetImageSize("maps/".$roundinfo[0]['name'].".jpg");
	if ($check_image) {

$template .= '<td valign=top width=130><IMG SRC="maps/'.$roundinfo[0]['name'].'.jpg" width=130 height=100 border=0 alt="'.$roundinfo[0]['name'].' '.$roundinfo[0]['mapsize'].'"></td>';

	} else {
$template .= '<td align="center" valign=top width=130><IMG SRC="maps/default.gif" width=130 height=100 border=0></td>';
	}




$template .= '<td valign=top>

<table width=98% border="0" cellpadding="0" cellspacing="0" class="stat">
				<tr>
					<td>'.$lang_lastserv.'</td>
					<td>'.$sservername.'</td>
				</tr>
				<tr>
					<td>'.$lang_Map.'</td>
					<td>'.$roundinfo[0]['name'].' ('.$roundinfo[0]['mapsize'].')</td>
				</tr>
				<tr>
					<td>'.$lang_lastduration.'</td>
					<td>'.intToTime($roundinfo[0]['time']).'</td>
				</tr>

				<tr>
					<td>'.$lang_lastEnd.'</td>
					<td>'.$roundinfo[0]['sum'].'/'.$roundinfo[0]['sum_end'].'</td>
				</tr>

				</table>

    </td>
<td valign=center align=center width=400><span class=px24><img src="'.$ROOT.'game-images/armies/'.$roundinfo[0]['team1'].'.png" style="border: 0pt none ;"> '.getArmyByID($roundinfo[0]['team1']).'&nbsp;&nbsp;&nbsp;<span class=score>'.$roundinfo[0]['tickets1'].' : '.$roundinfo[0]['tickets2'].'</span>&nbsp;&nbsp;&nbsp;'.getArmyByID($roundinfo[0]['team2']).' <img src="'.$ROOT.'game-images/armies/'.$roundinfo[0]['team2'].'.png" style="border: 0pt none ;"></span></td>
  </tr>
</table>

<table width=99% align="center" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td valign=top>

		<table width=98% id="roundinfo" class="stat" border="0" cellpadding="0" cellspacing="0">
			<tbody><tr><th colspan=6><img src="'.$ROOT.'game-images/armies/'.$roundinfo[0]['team1'].'.png" alt="'.armyname($roundinfo[0]['team1']).'" style="border: 0pt none ;"> <b>'.armyname($roundinfo[0]['team1']).'</b> ('.$roundinfo[0]['pids1'].')</th></tr>
        </tbody></table>

		<table width=98% id="roundinfo" class="stat sortable" border="0" cellpadding="0" cellspacing="0">
			<tbody><tr>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Name.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_lastScore.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Scores.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">K<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">D<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Time.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
			</tr>
    ';

$totalscore_team1=0;
$totaldeaths_team1=0;
$totalping_team1=0;
$totalplayers_team1=0;
$totalkills_team1=0;

foreach ($proundinfo as $key => $row) {


	if ($row['army'] == $roundinfo[0]['team1'])
	{
    $row['name'] = preg_replace("/>/","&gt;",$row['name']);
    $row['name'] = preg_replace("/</","&lt;",$row['name']);

        $medal=""; $m = "";
		if($row['id'] == $medals[0]) {$m = "<span class=mgold>&nbsp;</span>"; $medal=" <img src=\"".$ROOT."game-images/stars/star_gold.gif\">";}
		if($row['id'] == $medals[1]) {$m = "<span class=msil>&nbsp;</span>"; $medal=" <img src=\"".$ROOT."game-images/stars/star_silver.gif\">";}
		if($row['id'] == $medals[2]) {$m = "<span class=mbron>&nbsp;</span>"; $medal=" <img src=\"".$ROOT."game-images/stars/star_bronze.gif\">";}
		$namecolor = "";
		if($row['ping'] > $lagger) $namecolor=$laggercolor;
		if($row['deaths'] < 0 || $row['score'] < 0) $namecolor=$teamkillercolor;
		if(stristr($row['name'], $serveradmintag)) $namecolor=$admincolor;
		if($row['name'] == $serveradmin) $namecolor=$admincolor;
		if(!$namecolor) $namecolor=$fontcolor;

		if($row['cmdscore'] > 0) {$fav=" class=\"favorite\""; $row['score'] .= " (".$row['cmdscore'].")";}
		else {$fav="";}
$template .= '
<tr'.$fav.'>
<td>'.$m.'<img src="'.$ROOT.'game-images/ranks/icon/rank_'.$row['rank'].'.gif"><a target=_blank href="?pid='.$row['id'].'">'.$row['name'].'</a></td>
<td>'.$row['score'].'</td>
<td>'.$row['teamscore'].'</td>
<td>'.$row['kills'].'</td>
<td>'.$row['deaths'].'</td>
<td>'.intToTime($row['time']).'</td>
</tr>
';

	$totalscore_team1=($totalscore_team1+$row['score']);
	$totaldeaths_team1=($totaldeaths_team1+$row['deaths']);
	$totalping_team1=($totalping_team1+$row['ping']);
	$totalplayers_team1=($totalplayers_team1+1);
	$totalkills_team1=($totalkills_team1+$row['kills']);

	}
}

$template .= '    </table></td>
    <td valign=top>


		<table width=98% id="roundinfo" class="stat" border="0" cellpadding="0" cellspacing="0">
			<tbody><tr><th colspan=6><img src="'.$ROOT.'game-images/armies/'.$roundinfo[0]['team2'].'.png" alt="'.armyname($roundinfo[0]['team2']).'" style="border: 0pt none ;"> <b>'.armyname($roundinfo[0]['team2']).'</b> ('.$roundinfo[0]['pids2'].')</th></tr>
        </tbody></table>

		<table width=98% id="roundinfo" class="stat sortable" border="0" cellpadding="0" cellspacing="0">
			<tbody><tr>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Name.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_lastScore.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Scores.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Kills.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Deaths.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
				<th><a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'.$lang_Time.'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a></th>
			</tr>
    ';

$totalscore_team1=0;
$totaldeaths_team1=0;
$totalping_team1=0;
$totalplayers_team1=0;
$totalkills_team1=0;

foreach ($proundinfo as $key => $row) {

	if ($row['army'] == $roundinfo[0]['team2'])
	{
    $row['name'] = preg_replace("/>/","&gt;",$row['name']);
    $row['name'] = preg_replace("/</","&lt;",$row['name']);
        
        $medal=""; $m = "";
		if($row['id'] == $medals[0]) {$m = "<span class=mgold>&nbsp;</span>"; $medal=" <img src=\"".$ROOT."game-images/stars/star_gold.gif\">";}
		if($row['id'] == $medals[1]) {$m = "<span class=msil>&nbsp;</span>"; $medal=" <img src=\"".$ROOT."game-images/stars/star_silver.gif\">";}
		if($row['id'] == $medals[2]) {$m = "<span class=mbron>&nbsp;</span>"; $medal=" <img src=\"".$ROOT."game-images/stars/star_bronze.gif\">";}
		$namecolor = "";
		if($row['ping'] > $lagger) $namecolor=$laggercolor;
		if($row['deaths'] < 0 || $row['score'] < 0) $namecolor=$teamkillercolor;
		if(stristr($row['name'], $serveradmintag)) $namecolor=$admincolor;
		if($row['name'] == $serveradmin) $namecolor=$admincolor;
		if(!$namecolor) $namecolor=$fontcolor;
//print current($row);
		if($row['cmdscore'] > 0) {$fav=" class=\"favorite\""; $row['score'] .= " (".$row['cmdscore'].")";}
		else {$fav="";}
$template .= '
<tr'.$fav.'>
<td>'.$m.'<img src="'.$ROOT.'game-images/ranks/icon/rank_'.$row['rank'].'.gif"><a target=_blank href="?pid='.$row['id'].'">'.$row['name'].'</a></td>
<td>'.$row['score'].'</td>
<td>'.$row['teamscore'].'</td>
<td>'.$row['kills'].'</td>
<td>'.$row['deaths'].'</td>
<td>'.intToTime($row['time']).'</td>
</tr>
';

	$totalscore_team1=($totalscore_team1+$row['score']);
	$totaldeaths_team1=($totaldeaths_team1+$row['deaths']);
	$totalping_team1=($totalping_team1+$row['ping']);
	$totalplayers_team1=($totalplayers_team1+1);
	$totalkills_team1=($totalkills_team1+$row['kills']);

	}
}

$template .= '    </table>

    </td>

  </tr>
</table>
	<!-- end content == footer below -->

	<hr class="clear">
    
    <div><!-- Language -->
        <form method="post" id="content">
            <select name="lang">
            <option value="ru">Russian</option>
            <option value="en">English</option>
            <option value="jp">Japanese</option>
            </select>
            <input type="submit" value="'.$lang_select.'" />
        </form>
    </div><!-- / Language -->
    
<div id="footer">'.$lang_footerLASTUPDATE.'. '.$lang_footerNEXTUPDATE.'.<br>
	'.$lang_footerPROCESSED.'.<br>
    '.$lang_copyrightProject.'<br/>
    <!-- Уважайте мою работу - не трогайте нижнюю строчку... (^ω^)/ -->
    '.$lang_copyrightBF2REW.'<br/>
    '.$lang_copyrightShark.'<br/></div>

            
	</div>

</div>';
$template .= '	</body></html>';
?>