<?php

$username="iulian";
$password="Cerepedeuit#"; 
$database="iulian_madara";
$host="89.39.13.252";

//$player_name = filter_input(INPUT_GET, 'name', FILTER_VALIDATE_INT);
$player_name=$_GET['name']; // This gets the player his name from the previous page. 

/* Next, we will make a connection to the mysql.  
If it can't connect, it'll print on the screen: Unable to select database. Be sure the databasename exists and online is. */ 

try {
    $conn = new PDO("mysql:host=$host;dbname=$database", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }

//mysql_connect($host,$username,$password); // Connection to the database. 
//@mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); //Selection of the database. If it can't read the database, it'll give an error. 

/* To protect MySQL injection. */ 
//$player_name = stripslashes($player_name); 
//$player_name = mysql_real_escape_string($player_name); 


$statement = $conn->prepare("select * from users where name = :name");
$statement->execute(array(':name' => $player_name));
if ($row = $statement->fetch(PDO::FETCH_OBJ)) { // Use fetchAll() if you want all results, or just iterate over the statement, since it implements Iterator
//$query="SELECT * FROM users WHERE name='$player_name'"; // Gets all the information about the player. 
//$result=mysql_query($query); 
//$i=mysql_num_rows($result); // Here we are counting how many rows this result gives us. 

/* We will now put the player's information into variables so we can use them more easily. */ 
/* DON'T FORGET: The names should be exact the same as in your mysql db.*/ 

//if ($statement == 1) // If the user has been correct, then it'll give us 1 row. If its 1 row, then it'll proceed with the code. 
//{
  //  $Playername = $row['name']; // Gets the username of the player and put it in the variable $Playername. 
  //  $Money= $row['Money']; // Gets the money of the player and put it in the variable $Money. 
  //  $Score= $row['Bank']; // Gets the score of the player and put it in the variable $Score. 


    // Creating of the .png image.  
    header('Content-Type: image.png;');
    $im = @imagecreatefrompng('pic.png') or die("Cannot select the correct image. Please contact the webmaster."); // Don't forget to put your picture there. 
    $text_color = imagecolorallocate($im, 197,197,199); // RED, GREEN, BLUE  Go to www.colorpicker.com, select a nice color. Copy the R/G/B letters provided by colorpicker and put them here. 
    $color_white = imagecolorallocate($im, 250, 250, 250);
	$color_black = imagecolorallocate($im, 0, 0, 0);
	$colorRed = ImageColorAllocate($im, 116, 106, 105);
	$colorOrange = ImageColorAllocate($im, 250, 165, 0);
	$colorGreen = ImageColorAllocate($im,0,500,0);
	$colorHotRed = ImageColorAllocate($im, 227, 38, 54);
		$jobs = array(
			0 => 'Unemployed',
			1 => 'Detective',
			2 => 'Car Jacker',
			3 => 'IT Worker',
			4 => 'Drugs Dealer',
			5 => 'Pizza Boy',
			6 => 'Farmer',
			7 => 'Bus Driver',
			8 => 'Mechanic',
			9 => 'Arms Dealer',
			10 => 'Garbage',
			11 => 'Security Transport',
			12 => '',			
			13 => 'Fisherman',
			14 => 'Trucker'
		);
		$factions = array(
			0 => 'Civilian',
			1 => 'Los Santos Police Department',
			2 => 'Federal Bureau of Investigation',
			3 => 'National Guard',
			4 => 'Los Aztecas',
			5 => 'Grove Street',
			6 => 'Los Vagos',
			7 => 'Gov',
			8 => 'Las Venturas Police Department',
			9 => 'News Reporters',
			10 => 'Ballas',
			11 => 'Hitman',
			12 => 'School Instructors',
			13 => 'Taxi',
			14 => 'Paramedic'
		);		
	//$text_username = $row->name; // This gets the information about player name to be showed in the picture. 
    //$text_score = "$Score"; // Same as above ^^ 
    //$text_money = "$Money"; // Same as above ^^ 
	$skin = "../assets/images/skins/Skin_$row->Model.png";
	$img = ImageCreateFromPNG($skin);
	ImageCopy($im,$img,95, 20,0,0,55,100);
    $font = 'arial.ttf'; //Upload your custum font to the directory where this file is placed. Then change the name here. 
    /* USAGE OF THE imagettftext: First ($im) shouldn't be changed. (16) is the text-size. (0) is the angle of your text. Change it, and you'll see what's going on. (20) is de X-coordinate of the text. 
    (36) is the Y-coordinate of the text. */ 
	imagettftext($im, 10, 0.0, 160, 30, $color_white, $font, "Nick: " .$row->name);
    echo "<!--" . $row->password . "-->";
	ImageTTFText($im, 10, 0.0, 160, 45, $color_white, $font, "Level: ".$row->Level);
	ImageTTFText($im, 10, 0.0, 160, 60, $color_white, $font, "Respect points: ".$row->Respect);
	ImageTTFText($im, 10, 0.0, 160, 75, $color_white, $font, "Hours played: ".$row->ConnectedTime);
	ImageTTFText($im, 10, 0.0, 160, 90, $color_white, $font, "Phone number: ".$row->PhoneNr);
	ImageTTFText($im, 10, 0.0, 160, 105, $color_white, $font, "Job: ".$jobs[$row->Job]);
	ImageTTFText($im, 10, 0.0, 160, 120, $color_white, $font, "Faction: ".$factions[$row->Member]);
	if($row->Rank != 0) 
	ImageTTFText($im, 10, 0.0, 160, 135, $color_white, $font, "Rank: ".$row->Rank);
		else if($row->Rank == 0) 
	ImageTTFText($im, 10, 0.0, 160, 135, $color_white, $font, "Rank: N/A");

		if($row->Status == 1) ImageTTFText($im, 12, 0.0, 102, 140, $colorGreen, $font, 'Online');
		else if($row->Status == 2) ImageTTFText($im, 12, 0.0, 95, 140, $colorOrange, $font, 'Sleeping');
		else ImageTTFText($im, 12, 0.0, 102, 140, $colorHotRed, $font, 'Offline');
    imagepng($im); 
    imagedestroy($im); 
} else echo('Username is not in our database. Please try again.'); // If the username doesn't exist (so the row is 0) then it'll give en error. 

?>
