<?php 
/*======================================================================*\
|| #################################################################### ||
|| # EoT-Clan BC2 Server Stats                                        # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernt werden                      # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # -----------------BC2 Server Stats is a free Software-------------# ||
|| #                      http://eot-clan.net                         # ||
|| #################################################################### ||
\*======================================================================*/
include_once ('inc/config.php');
include ('lang/language.php');
include_once ('lang/'.$lang_file);
include_once ('inc/rankname.php');

$_GET = security::escape($_GET);
$_POST = security::escape($_POST);

if(isset($_GET['player']) && !empty($_GET['player']) && $_GET['player'] != '') {
   $WHERE = "a.SoldierName = '{$_GET['player']}'";
 }else{
	 include_once ("error/error_players2.html");
		exit;
}

$query = "SELECT 
           a.PlayerID,
           a.SoldierName,
           a.ClanTag,
           a.CountryCode,
           b.Rank,
           c.playerScore,
           c.StatsID,
           c.playerHeadshots,
           c.playerPlaytime,
           c.playerRounds,
           c.playerKills,
           c.playerDeaths,
           c.playerKills / CASE WHEN c.playerDeaths = 0 THEN (1) ELSE c.playerDeaths END AS KD,
           c.FirstSeenOnServer,
           c.LastSeenOnServer,
           d.*,
           SUM(e.Count) AS DOGTAGS,
           f.stars_id,
           f.last_count,
           f.last_weapon,
           f.last_time
	         FROM 
	           tbl_playerdata a
           Left JOIN 
             tbl_bfbcs b ON a.PlayerID = b.bfbcsID
           Left JOIN 
             tbl_playerstats c ON a.PlayerID = c.StatsID
           Left JOIN 
             tbl_weaponstats d ON a.PlayerID = d.WeaponStatsID
           Left JOIN 
             tbl_dogtags e ON a.PlayerID = e.KillerID
           Left JOIN 
             tbl_stars f ON a.PlayerID = f.stars_id
            WHERE {$WHERE}
            GROUP BY a.PlayerID";
             
       $result = mysql_query($query);
       $num_rows = mysql_num_rows($result);
if ($num_rows === 0) {
include ("error/error_signatur.html");
exit;
}

       header('Content-Type: image/png'); 
$arial_b = 'fonts/ariblk.ttf';
$arial = 'fonts/arial.ttf';

$back = imagecreatefrompng($SignaturBack);
$oldwidth = imagesx($back);
$oldheight = imagesy($back);


while($data = mysql_fetch_assoc($result)){
   $soldiername = $data['ClanTag'].' '.$data['SoldierName'];
   if($data['Rank'] == ""){
   	$rank = 0;
  }else{
   $rank = $data['Rank'];
 }
   $Rankname = '['.$rankname[$rank].']';
   $dogtags = $data['DOGTAGS'];
   $Points = lang_sig_points.number_format($data['playerScore'], 0, ',', ' ');
   $Kills = lang_sig_kills.number_format($data['playerKills'], 0, ',', ' ');
   $Deaths = lang_sig_deaths.number_format($data['playerDeaths'], 0, ',', ' ');
   $KD = lang_sig_kd.number_format($data['KD'], 2, ',', ' ');
   $Headshots = lang_sig_headshots.number_format($data['playerHeadshots'], 0, ',', ' ');
   $Firstseen = lang_sig_firstseen.$data['FirstSeenOnServer'];
   $Lastseen = lang_sig_lastseen.$data['LastSeenOnServer'];
   $awardweapon = $data['last_weapon'];
   $country = imagecreatefrompng('img/flags/'.$data['CountryCode'].'.png');
   $c_Breite = imagesx($country);    
   $c_Hohe = imagesy($country);
include_once ('inc/weapons_array.php');
  if ($data['last_count'] == 0){
   $LastAward = lang_sig_lastaward_error;
   $star = '';
   $icon = imagecreatefrompng('img/stars/s_bron.png');
   $i_Breite = imagesx($icon);    
   $i_Hohe = imagesy($icon);
 }else{
 	if (in_array($data['last_weapon'],$aStarWeapons) or in_array($data['last_weapon'],$aGadgets)){
 	 if ($data['last_count'] == 1){
 	 	  $star = lang_awards_sig_bron;
 	 	  $title = $aWeaponsName[$data['last_weapon']];
 	 	  $icon = imagecreatefrompng('img/stars/s_bron.png');
      $i_Breite = imagesx($icon);    
      $i_Hohe = imagesy($icon); 
 	 }elseif ($data['last_count'] == 2){
 	 		$star = lang_awards_sig_silv;
 	 		$title = $aWeaponsName[$data['last_weapon']];
 	 		$icon = imagecreatefrompng('img/stars/s_silv.png');
      $i_Breite = imagesx($icon);    
      $i_Hohe = imagesy($icon); 
 	}elseif ($data['last_count'] >= 3 && $data['last_count'] <=11){
 	    $star = lang_awards_sig_gold.' ('.($data['last_count']-2).')';
 	    $title = $aWeaponsName[$data['last_weapon']];
 	    $icon = imagecreatefrompng('img/stars/s_gold.png');
      $i_Breite = imagesx($icon);    
      $i_Hohe = imagesy($icon); 
 	}elseif ($data['last_count'] >= 12){
      $star = lang_awards_sig_plat;
      $title = $aWeaponsName[$data['last_weapon']];
      $icon = imagecreatefrompng('img/stars/s_plat.png');
      $i_Breite = imagesx($icon);    
      $i_Hohe = imagesy($icon); 
    }
  }else{  
  	    $title = '';
  	    $star = constant('insignia_title_sig_'.$data['last_weapon']);
  	    $icon = imagecreatefrompng('img/sig/insignias/'.$data['last_weapon'].'.png');
        $i_Breite = imagesx($icon);    
        $i_Hohe = imagesy($icon);
  }
  
   $LastAward = $title.$star;
 }
 
 
 
  foreach($aWeapons as $weapons){
     $aWeapon =  $data[$weapons.'_kills'];
     $kills_array[$weapons] = $aWeapon;
  }
  
  foreach($aVehicles  as $vehicles){
    $avehicles =  $data[$vehicles.'_kills'];
    $vehicles_array[$vehicles] = $avehicles;
}

  foreach($aGadgets as $Gadgets){
    $agadgets =  $data[$Gadgets.'_kills'];
    $gadgets_array[$Gadgets] = $agadgets;
  }
 


asort($kills_array);
asort($vehicles_array);
asort($gadgets_array);

$iw = 0;
foreach ($kills_array as $key => $weapons){
	$FavWeapon = lang_sig_favw.$aWeaponsName[$key].'(Kills:'.$weapons.')';
if ($iw == 1) break;
}

$iv = 0;
foreach ($vehicles_array as $key => $vehicles){
	$FavVehicle = lang_sig_favv.$aWeaponsName[$key].'(Kills:'.$vehicles.')';
if ($iv == 1) break;
}

$ig = 0;
foreach ($gadgets_array as $key => $gadgets){
  $FavGadget = lang_sig_favg.$aWeaponsName[$key].'(Kills:'.$gadgets.')';
if ($ig == 1) break;
}
$rankimg = imagecreatefrompng('img/sig/rank/'.$rank.'.png');
$r_Breite = imagesx($rankimg);    
$r_Hohe = imagesy($rankimg); 

$dogimg = imagecreatefrompng('img/sig/dogt.png');
$d_Breite = imagesx($dogimg);    
$d_Hohe = imagesy($dogimg); 



//Text Color
$colorB = ImageColorAllocate($back, 0, 0, 0); //Black
$colorW = ImageColorAllocate($back, 250, 252, 254); //White
$colorO = ImageColorAllocate($back, 224, 124, 2); //Orange
$colorR = ImageColorAllocate($back, 255, 3, 21); //Red
$colorG = ImageColorAllocate($back, 0, 255, 0); //Green


imagesavealpha($back, true);

imagecopy ($back, $rankimg, 10, 40, 0, 0, $r_Breite,$r_Hohe);
imagecopy ($back, $country, 32, 99, 0, 0, $c_Breite,$c_Hohe);
ImageTTFText ($back, 9, 0, 11, 16, $colorB, $arial_b, $soldiername);
ImageTTFText ($back, 9, 0, 10, 15, $colorW, $arial_b, $soldiername);
ImageTTFText ($back, 9, 0, 12, 30, $colorB, $arial, $Rankname);
ImageTTFText ($back, 9, 0, 11, 29, $colorW, $arial, $Rankname);

imagecopy ($back, $dogimg, 467, 5, 0, 0, $d_Breite,$d_Hohe);
ImageTTFText ($back, 9, 0, 470, 32, $colorB, $arial_b, $dogtags);
ImageTTFText ($back, 9, 0, 471, 33, $colorW, $arial_b, $dogtags);

ImageTTFText ($back, 9, 0, 80, 48, $colorB, $arial, $Points);
ImageTTFText ($back, 9, 0, 81, 49, $colorW, $arial, $Points);

ImageTTFText ($back, 9, 0, 80, 62, $colorB, $arial, $Kills);
ImageTTFText ($back, 9, 0, 81, 63, $colorW, $arial, $Kills);

ImageTTFText ($back, 9, 0, 80, 76, $colorB, $arial, $Deaths);
ImageTTFText ($back, 9, 0, 81, 77, $colorW, $arial, $Deaths);

ImageTTFText ($back, 9, 0, 80, 90, $colorB, $arial, $Headshots);
ImageTTFText ($back, 9, 0, 81, 91, $colorW, $arial, $Headshots);
if ($data['KD'] >= 1){
ImageTTFText ($back, 9, 0, 80, 105, $colorG, $arial, $KD);
}else{
ImageTTFText ($back, 9, 0, 80, 105, $colorR, $arial, $KD);
}
ImageTTFText ($back, 9, 0, 250, 48, $colorB, $arial, $Firstseen);
ImageTTFText ($back, 9, 0, 251, 49, $colorW, $arial, $Firstseen);
ImageTTFText ($back, 9, 0, 250, 62, $colorB, $arial, $Lastseen);
ImageTTFText ($back, 9, 0, 251, 63, $colorW, $arial, $Lastseen);
ImageTTFText ($back, 9, 0, 250, 76, $colorB, $arial, $FavWeapon);
ImageTTFText ($back, 9, 0, 251, 77, $colorW, $arial, $FavWeapon);
ImageTTFText ($back, 9, 0, 250, 90, $colorB, $arial, $FavVehicle);
ImageTTFText ($back, 9, 0, 251, 91, $colorW, $arial, $FavVehicle);
ImageTTFText ($back, 9, 0, 250, 105, $colorB, $arial, $FavGadget);
ImageTTFText ($back, 9, 0, 251, 106, $colorW, $arial, $FavGadget);

imagecopy ($back, $icon, 250, 7, 0, 0, $i_Breite,$i_Hohe);
ImageTTFText ($back, 9, 0, 270, 19, $colorB, $arial, $LastAward);
ImageTTFText ($back, 9, 0, 271, 20, $colorW, $arial, $LastAward);


imagepng($back);

ImageDestroy($back); 

  }

?>
