<?php
class User {
// Contributed by qzip! remove if noob.

    private $con, $sqlData;

    public function __construct($con, $id) {
	 $query = $con->prepare('SELECT * FROM users WHERE id=:id');
	 $query->bindParam(':id', $id);
     $query->execute();	
     $this->sqlData = $query->fetch(PDO::FETCH_ASSOC);
    }

    public static function isLoggedIn() {
        return isset($_SESSION["user"]);
    }
	
	public function getMoney($short) {
	    if ($short == "true") {
        $money = $this->$query->sqlData["money"];
		
		if ($money < 1000000) {
         // Anything less than a million
         return number_format($money);
        } else if ($money < 1000000000) {
         // Anything less than a billion
         return number_format($money / 1000000, 1) . 'M';
        } else {
         // At least a billion
         return number_format($money / 1000000000, 1) . 'B';
        
		}
		} else {
		return $this->$query->sqlData["money"];
		}
    }
	
	public function getID($con, $username) {
	    $query = $con->prepare('SELECT id FROM users WHERE username=:username');
	    $query->bindParam(':username', $username);
        $query->execute();	
        $id = $query->fetch(PDO::FETCH_ASSOC);
		if(isset($id['id'])) {
		return $id['id'];
		} else {
		return null;
		}
	}
	
	public function getUsername() {
		return $this->sqlData["username"];
	}
	
	public function getPassword() {
		return $this->sqlData["password"];
	}
	
}