<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

eval ("\$title_clanwars_details = \"".gettemplate("title_clanwars_details")."\";");
echo $title_clanwars_details;

echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=clanwars\');return document.MM_returnValue" value="Show Clanwars"> 
	 <input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=clanwars&action=stats\');return document.MM_returnValue" value="Statistics"><br><br>';

if(!isset($_GET['action'])) {
  $cwID = $_GET['cwID'];
  $ds=mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."clanwars WHERE cwID='$cwID'"));
	$date=date("d.m.Y", $ds[date]);
	$opponent='<a href="'.$ds[opphp].'" target="_blank"><b>'.$ds[opptag].' / '.$ds[opponent].'</></a>';
	$league='<a href="'.$ds[leaguehp].'" target="_blank">'.$ds[league].'</a>';
	$game='<img src="images/games/'.$ds[game].'.gif" width="13" height="13" border="0">';
	
	// v1.0
	$homescr=array_sum(explode("||", $ds[homescore]));
	$oppscr =array_sum(explode("||", $ds[oppscore]));
	$theMaps=explode("||", $ds[maps]);
	if(is_array($theMaps)) {
		$n=1;
		foreach($theMaps as $map) {
			if($n == 1) {
				$maps.=$map;
			} else {
				if($map=='') {
					$maps='no maps';
				} else {
					$maps.=', '.$map;
				}
			}
			$n++;
		}
	}	
	
	if($homescr>$oppscr) $results='<font color="'.$wincolor.'">'.$homescr.':'.$oppscr.'</font>';
	elseif($homescr<$oppscr) $results='<font color="'.$loosecolor.'">'.$homescr.':'.$oppscr.'</font>';
	else $results='<font color="'.$drawcolor.'">'.$homescr.':'.$oppscr.'</font>';

	if(isclanwaradmin($userID)) 
	    $adminaction='<input type="button" class="button" onClick="MM_openBrWindow(\'upload.php?cwID='.$cwID.'\',\'Clanwars\',\'toolbar=no,status=no,scrollbars=yes,width=800,height=600\')" value="upload screens"> 
					  <input type="button" class="button" onClick="MM_openBrWindow(\'clanwars.php?action=edit&cwID='.$ds[cwID].'\',\'Clanwars\',\'toolbar=no,status=no,scrollbars=yes,width=800,height=600\')" value="edit">
					  <input type="button" class="button" onClick="MM_confirm(\'delete clanwar?\',\'clanwars.php?action=delete&cwID='.$ds[cwID].'\')" value="delete">';
	
	$report=cleartext($ds[report]);
	$report = toggle($report, $ds[cwID]);
	if($report=="") $report="n/a";
	
	$squad='<a href="index.php?site=clanwars&action=showonly&only=squad&id='.$ds[squad].'"><b>'.getsquadname($ds[squad]).'</b></a>';
	
	$opptag=$ds[opptag];
	$oppteam=$ds[oppteam];
	$server=$ds[server];
	$hltv=$ds[hltv];
	$opptag=$ds[opptag];
	
	if(!empty($ds[hometeam])) {
		$array=explode("|", $ds[hometeam]);
		$n=1;
		foreach($array as $id) {
			if(!empty($id)) {
				if($n>1) $hometeam.=', <a href="index.php?site=profile&id='.$id.'">'.getnickname($id).'</a>';
				else $hometeam.='<a href="index.php?site=profile&id='.$id.'">'.getnickname($id).'</a>';
				$n++;
			}
		}
	}
	
	if(!empty($ds[screens])) $screens=explode("|", $ds[screens]);
	if(is_array($screens)) {
		$n=1;
		foreach($screens as $screen) {
			if(!empty($screen)) {
				$screenshots.='<a href="images/clanwar-screens/'.$screen.'" target="_blank"><img src="images/clanwar-screens/'.$screen.'" width="150" height="100" border="0" style="padding-top:3px; padding-right:3px;"></a>';
				  if($nbr==2) {
            $nbr=1;
            $screenshots.='<br>';
          } else {	
					  $nbr=2;
          }
        $n++;
        }
      }
  }
	
	if(!(strlen(trim($screenshots)))) $screenshots='no Screenshots available';
	
	$bg1=BG_1;
	$bg2=BG_2;
	$bg3=BG_3;
	$bg4=BG_4;
	
	$linkpage=cleartext($ds[linkpage]);
	$linkpage=str_replace('http://','',$ds[linkpage]);
	if($linkpage=="") $linkpage="#";
	
	// -- v1.0, extended results -- //
	
	$scoreHome=explode("||", $ds[homescore]);
	$scoreOpp=explode("||", $ds[oppscore]);
	$homescr=array_sum($scoreHome);
	$oppscr=array_sum($scoreOpp);
		
	if($homescr>$oppscr) {
		$result_map='[color='.$wincolor.'][b]'.$homescr.':'.$oppscr.'[/b][/color]';
		$result_map2='won';
	}
	elseif($homescr<$oppscr) {
		$result_map='[color='.$loosecolor.'][b]'.$homescr.':'.$oppscr.'[/b][/color]';
		$result_map2='lost';
	}
	else {
		$result_map='[color='.$drawcolor.'][b]'.$homescr.':'.$oppscr.'[/b][/color]';
		$result_map2='draw';
	}
		
	if(is_array($theMaps)) {
		$d=0;
		foreach($theMaps as $map) {
			if(($d+1)%2) { $bgone=BG_1; $bgtwo=BG_2; } else { $bgone=BG_3; $bgtwo=BG_4; }
			if($scoreHome[$d] > $scoreOpp[$d]) $score.='<font color="'.$wincolor.'"><b>'.$scoreHome[$d].'</b></font> : <font color="'.$loosecolor.'"><b>'.$scoreOpp[$d].'</b></font>';
			elseif($scoreHome[$d] < $scoreOpp[$d]) $score.='<font color="'.$loosecolor.'"><b>'.$scoreHome[$d].'</b></font> : <font color="'.$wincolor.'"><b>'.$scoreOpp[$d].'</b></font>';
			else $score.='<font color="'.$drawcolor.'"><b>'.$scoreHome[$d].'</b></font> : <font color="'.$drawcolor.'"><b>'.$scoreOpp[$d].'</b></font>';
			eval ("\$clanwars_details_results = \"".gettemplate("clanwars_details_results")."\";");
			$extendedresults.=$clanwars_details_results;
			unset($score);
			$d++;
		}
	} else $extendedresults='';
	
	// -- clanwar output -- //
	
	eval ("\$clanwars_details = \"".gettemplate("clanwars_details")."\";");
	echo $clanwars_details;
	
	$comments_allowed = $ds[comments];
	$parentID = $cwID;
	$type = "cw";
	$referer = "index.php?site=clanwars_details&cwID=$cwID";
		
	include("comments.php");
}

?>
