 <?php

    require_once($path["page"] . "Page.php");


    /**
     * User profile page.
     */
    class Profile_Page extends Page{

        public $name;
        public $mail;
        public $api_key;

        /**
         * Constructor.
         *
         * Retrieves the data and initializes the variables.
         *
         * @param SQLite3 $db Connection to the database.
         */
        public function __construct($db){
            global $path;
            global $root;
            global $UID;
            parent::__construct($db);
            $this->view = $path["view"] . "profile.php";
            $s = "
              SELECT
                name,
                mail,
                api_key
              FROM player
              WHERE uid = '$UID';
            ";
            $q = $this->db->query($s);
            if ($r = $q->fetchArray(SQLITE3_ASSOC)){
                $this->name = $r["name"];
                $this->mail = $r["mail"];
                $this->api_key = $r["api_key"];
            }
            $this->title = $this->name ." - SWDB";
            $this->description = $this->name . " user profile";
            $this->canonical = $root . "profile/";
        }

    }
?>
