ソースを参照

Code improvements: Staged controller. Global context. Encapsulation (in progress).

Iñigo Valentin 5 年 前
コミット
f4de505c54
85 ファイル変更1150 行追加983 行削除
  1. 2 2
      application/API/v1/profile/DELETE.php
  2. 5 5
      application/API/v1/profile/GET.php
  3. 2 2
      application/API/v1/profile/POST.php
  4. 6 7
      application/API/v1/profile/PUT.php
  5. 2 2
      application/API/v1/run/POST.php
  6. 6 7
      application/API/v1/units/GET.php
  7. 96 0
      application/Context.php
  8. 178 190
      application/Controller.php
  9. 1 3
      application/action/change_game_mode.php
  10. 2 4
      application/action/delete_team.php
  11. 4 7
      application/action/edit_profile.php
  12. 2 5
      application/action/login.php
  13. 0 2
      application/action/logout.php
  14. 3 6
      application/action/new_team.php
  15. 9 13
      application/action/optimize_get_rune_list.php
  16. 1 3
      application/action/rate_team.php
  17. 5 7
      application/action/save_run_team.php
  18. 39 29
      application/entity/Area.php
  19. 4 8
      application/entity/Artifact.php
  20. 66 41
      application/entity/Artifact_Effect.php
  21. 37 26
      application/entity/Artifact_Stat.php
  22. 1 4
      application/entity/Buildable.php
  23. 1 4
      application/entity/Building.php
  24. 1 4
      application/entity/Decoration.php
  25. 2 5
      application/entity/Decorative.php
  26. 1 4
      application/entity/Effect.php
  27. 2 5
      application/entity/Enchantment.php
  28. 2 5
      application/entity/Guild.php
  29. 1 4
      application/entity/Guild_Member.php
  30. 1 4
      application/entity/Guild_Skill.php
  31. 2 5
      application/entity/Guild_Skill_Group.php
  32. 1 3
      application/entity/Inventory.php
  33. 2 5
      application/entity/Item.php
  34. 1 4
      application/entity/Leader_Skill.php
  35. 5 19
      application/entity/Monster.php
  36. 2 7
      application/entity/Monster_Transformation.php
  37. 387 162
      application/entity/Player.php
  38. 4 7
      application/entity/Record.php
  39. 9 12
      application/entity/Run.php
  40. 6 10
      application/entity/Rune.php
  41. 1 4
      application/entity/Rune_Set.php
  42. 1 4
      application/entity/Rune_Stat.php
  43. 1 4
      application/entity/Server.php
  44. 3 6
      application/entity/Skill.php
  45. 1 4
      application/entity/Skill_Level.php
  46. 1 3
      application/entity/Source.php
  47. 3 6
      application/entity/Team.php
  48. 16 32
      application/entity/Unit.php
  49. 2 4
      application/entity/User.php
  50. 3 15
      application/page/Artifacts_Page.php
  51. 2 7
      application/page/Enchantments_Page.php
  52. 3 8
      application/page/Guild_Page.php
  53. 3 6
      application/page/Home_Page.php
  54. 4 9
      application/page/Monsters_Page.php
  55. 3 10
      application/page/Optimizer_Page.php
  56. 2 7
      application/page/Profile_Page.php
  57. 5 13
      application/page/Report_Rune_Enchantment_Page.php
  58. 5 12
      application/page/Report_Skillup_Page.php
  59. 3 11
      application/page/Runes_Page.php
  60. 2 7
      application/page/Runs_Page.php
  61. 13 18
      application/page/Stats_Page.php
  62. 4 11
      application/page/Teams_Page.php
  63. 3 8
      application/page/Units_Page.php
  64. 4 3
      application/view/artifacts.php
  65. 6 5
      application/view/catalog.php
  66. 4 3
      application/view/enchantments.php
  67. 2 1
      application/view/error.php
  68. 2 1
      application/view/guild.php
  69. 2 1
      application/view/help.php
  70. 50 47
      application/view/home.php
  71. 17 19
      application/view/inc/header.php
  72. 2 1
      application/view/monster.php
  73. 7 6
      application/view/optimizer.php
  74. 6 5
      application/view/optimizer_unit.php
  75. 2 1
      application/view/profile.php
  76. 5 3
      application/view/report.php
  77. 5 4
      application/view/report_rune_enchantment.php
  78. 5 4
      application/view/report_skillup.php
  79. 4 3
      application/view/runes.php
  80. 7 6
      application/view/runs.php
  81. 4 3
      application/view/stats.php
  82. 8 7
      application/view/teams.php
  83. 5 4
      application/view/unit.php
  84. 5 4
      application/view/units.php
  85. 13 1
      public/index.php

+ 2 - 2
application/API/v1/profile/DELETE.php

@@ -15,8 +15,6 @@
      * @category API
      * @category API
      */
      */
 
 
-    global $db;
-
     try{
     try{
 
 
         header("Content-type: application/json; charset=utf-8");
         header("Content-type: application/json; charset=utf-8");
@@ -44,6 +42,8 @@
             syslog(LOG_INFO, "[APIv1] HTTP/1.1 400 API key not received.");
             syslog(LOG_INFO, "[APIv1] HTTP/1.1 400 API key not received.");
             return 400;
             return 400;
         }
         }
+        
+        $db = get_context()->get_db();
 
 
         // Authenticate
         // Authenticate
         $statement = $db->prepare("
         $statement = $db->prepare("

+ 5 - 5
application/API/v1/profile/GET.php

@@ -15,8 +15,6 @@
      * @category API
      * @category API
      */
      */
 
 
-    global $db;
-
     try{
     try{
         header("Content-type: application/json; charset=utf-8");
         header("Content-type: application/json; charset=utf-8");
 
 
@@ -32,6 +30,8 @@
             return 403;
             return 403;
         }
         }
 
 
+        $db = get_context()->get_db();
+
         // Get player
         // Get player
         $statement = $db->prepare("
         $statement = $db->prepare("
           SELECT
           SELECT
@@ -67,9 +67,9 @@
         // Build array
         // Build array
         // TODO: Add way more data
         // TODO: Add way more data
         $player = [
         $player = [
-            "username" => $player->name,
-            "level" => $player->level,
-            "public" => $player->public
+            "username" => $player->get_name(),
+            "level" => $player->get_level(),
+            "public" => $player->is_public()
         ];
         ];
         echo(json_encode($player));
         echo(json_encode($player));
         header("HTTP/1.1 200 Success.");
         header("HTTP/1.1 200 Success.");

+ 2 - 2
application/API/v1/profile/POST.php

@@ -17,8 +17,6 @@
      * @category API
      * @category API
      */
      */
 
 
-    global $db;
-
     try{
     try{
 
 
         header("Content-type: application/json; charset=utf-8");
         header("Content-type: application/json; charset=utf-8");
@@ -68,6 +66,8 @@
             $public = 0;
             $public = 0;
         }
         }
 
 
+        $db = get_context()->get_db();
+
         // Check if player exists
         // Check if player exists
         $statement = $db->prepare("SELECT COUNT(id) AS c FROM data.player WHERE id = :id;");
         $statement = $db->prepare("SELECT COUNT(id) AS c FROM data.player WHERE id = :id;");
         $statement->bindValue(":id", $id, SQLITE3_INTEGER);
         $statement->bindValue(":id", $id, SQLITE3_INTEGER);

+ 6 - 7
application/API/v1/profile/PUT.php

@@ -13,9 +13,6 @@
      * @category API
      * @category API
      */
      */
 
 
-    global $db;
-
-
     /**
     /**
      * Parses an artifact and saves it to the database.
      * Parses an artifact and saves it to the database.
      *
      *
@@ -23,7 +20,7 @@
      * @param JSON artifact JSON fragment of the artifact.
      * @param JSON artifact JSON fragment of the artifact.
      */
      */
     function parse_artifact($player_id, $artifact){
     function parse_artifact($player_id, $artifact){
-        global $db;
+        $db = get_context()->get_db();
         $statement = $db->prepare("
         $statement = $db->prepare("
           INSERT INTO artifact (
           INSERT INTO artifact (
             player,
             player,
@@ -190,7 +187,7 @@
         }
         }
 
 
         // Instantiate and calculate efficiency:
         // Instantiate and calculate efficiency:
-        $instance = new Artifact($artifact->{"rid"});
+        new Artifact($artifact->{"rid"});
 
 
         // Assigned?
         // Assigned?
         if (intval($artifact->{"occupied_id"}) != 0){
         if (intval($artifact->{"occupied_id"}) != 0){
@@ -213,7 +210,7 @@
      * @param JSON rune JSON fragment of the rune.
      * @param JSON rune JSON fragment of the rune.
      */
      */
     function parse_rune($player_id, $rune, $lock_list){
     function parse_rune($player_id, $rune, $lock_list){
-        global $db;
+        $db = get_context()->get_db();
         $statement = $db->prepare("
         $statement = $db->prepare("
           INSERT INTO rune (
           INSERT INTO rune (
             player,
             player,
@@ -371,7 +368,7 @@
         }
         }
 
 
         // Instantiate and calculate efficiency:
         // Instantiate and calculate efficiency:
-        $instance = new Rune($rune->{"rune_id"});
+        new Rune($rune->{"rune_id"});
 
 
         // Assigned?
         // Assigned?
         if (intval($rune->{"occupied_id"}) != 0){
         if (intval($rune->{"occupied_id"}) != 0){
@@ -1467,6 +1464,8 @@
             return 405;
             return 405;
         }
         }
 
 
+        $db = get_context()->get_db();
+
         // Get user info and Authenticate
         // Get user info and Authenticate
         switch ($command){
         switch ($command){
             case "HubUserLogin":
             case "HubUserLogin":

+ 2 - 2
application/API/v1/run/POST.php

@@ -1304,8 +1304,6 @@
         return "201 Created.";
         return "201 Created.";
     }
     }
 
 
-    global $db;
-
     try{
     try{
 
 
         header("Content-type: application/json; charset=utf-8");
         header("Content-type: application/json; charset=utf-8");
@@ -1378,6 +1376,8 @@
         $player_id = $json["result_res"]->{"wizard_info"}->{"wizard_id"};
         $player_id = $json["result_res"]->{"wizard_info"}->{"wizard_id"};
         $command = $json["result_res"]->{"command"};
         $command = $json["result_res"]->{"command"};
 
 
+        $db = get_context()->get_db();
+
         // Authenticate
         // Authenticate
         $statement = $db->prepare("
         $statement = $db->prepare("
           SELECT COUNT(player.id) AS c 
           SELECT COUNT(player.id) AS c 

+ 6 - 7
application/API/v1/units/GET.php

@@ -10,8 +10,6 @@
      * @category API
      * @category API
      */
      */
 
 
-    global $db;
-
     /**
     /**
      * Gets info on a unit.
      * Gets info on a unit.
      *
      *
@@ -19,12 +17,13 @@
      * @param int $id Unit identifier
      * @param int $id Unit identifier
      * @return mixed[] Content.
      * @return mixed[] Content.
      */
      */
-    function get_unit($db, $id){
+    function get_unit($id){
         $result = [
         $result = [
             "status" => 404,
             "status" => 404,
             "message" => "Unit not found",
             "message" => "Unit not found",
             "content" => ""
             "content" => ""
         ];
         ];
+        $db = get_context()->get_db();
         $statement = $db->prepare("
         $statement = $db->prepare("
           SELECT
           SELECT
             monster.id AS id,
             monster.id AS id,
@@ -288,10 +287,10 @@
     /**
     /**
      * Gets a list of units, paginated.
      * Gets a list of units, paginated.
      *
      *
-     * @param resource $db Database connection.
      * @return mixed[] Content.
      * @return mixed[] Content.
      */
      */
-    function get_unit_list($db){
+    function get_unit_list(){
+        $db = get_context()->get_db();
         $result = [
         $result = [
             "status" => 200,
             "status" => 200,
             "message" => "Success.",
             "message" => "Success.",
@@ -438,10 +437,10 @@
         /** @var mixed $query Request parameters, from API_CONTROLLER*/
         /** @var mixed $query Request parameters, from API_CONTROLLER*/
         if (strlen($query[0]) > 0){
         if (strlen($query[0]) > 0){
             $id = $query[0];
             $id = $query[0];
-            $result = get_unit($db, $id);
+            $result = get_unit($id);
         }
         }
         else{
         else{
-            $result = get_unit_list($db);
+            $result = get_unit_list();
         }
         }
         header("HTTP/1.1 " . $result["status"] . " " . $result["message"]);
         header("HTTP/1.1 " . $result["status"] . " " . $result["message"]);
         echo(json_encode($result["content"]));
         echo(json_encode($result["content"]));

+ 96 - 0
application/Context.php

@@ -0,0 +1,96 @@
+<?php
+    /**
+     * Context file.
+     *
+     * Provides a class to retrieve a context.
+     *
+     * @category Context
+     */
+
+    /**
+     * Application context.
+     *
+     * Stores usefull data to be retrieved anywhere in the app.
+     *
+     * @category Context
+     */
+    class Context {
+
+        private $user;
+        private $player;
+        private $db;
+        private $game_mode;
+
+        /**
+         * Retrieves the selected user.
+         *
+         * @return User The selected user, null if no specified.
+         */
+        public function get_user(){
+            return $this->user;
+        }
+
+        /**
+         * Retrieves the logged in player.
+         *
+         * @return Player The current player, null if not logged in.
+         */
+        public function get_player(){
+            return $this->player;
+        }
+
+        /**
+         * Retrieves the database connection.
+         *
+         * @return SQLITE3 The database connection.
+         */
+        public function get_db(){
+            return $this->db;
+        }
+
+        /**
+         * Retrieves the current game mode.
+         *
+         * @return int Game mode.
+         */
+        public function get_game_mode(){
+            return $this->game_mode;
+        }
+
+        /**
+         * Sets the current user.
+         *
+         * @param The current user.s
+         */
+        protected function set_user($user){
+            $this->user = $user;
+        }
+
+        /**
+         * Sets the currently logged-in player.
+         *
+         * @param Player Logged-in player.
+         */
+        protected function set_player($player){
+            $this->player = $player;
+        }
+
+        /**
+         * Sets the database connection
+         *
+         * @param SQLITE3 Database connection.
+         */
+        protected function set_db($db){
+            $this->db = $db;
+        }
+
+        /**
+         * Sets the game mode.
+         *
+         * @param int Game mode.
+         */
+        protected function set_game_mode($game_mode){
+            $this->game_mode = $game_mode;
+        }
+    }
+?>

+ 178 - 190
application/Controller.php

@@ -20,26 +20,7 @@
     require_once(PATH::ENTITY . "User.php");
     require_once(PATH::ENTITY . "User.php");
     require_once(PATH::ENTITY . "Player.php");
     require_once(PATH::ENTITY . "Player.php");
     require_once(__DIR__ . "/Constant.php");
     require_once(__DIR__ . "/Constant.php");
-
-    /**
-     * @global User $USER.
-     */
-    $USER = -1;
-
-    /**
-     * @global Player $PLAYER.
-     */
-    $PLAYER = -1;
-
-    /**
-     * @global int $MODE.
-     */
-    $MODE = GAME_MODE_ID::NORMAL;
-
-    /**
-     * @global resource $DB.
-     */
-    $db = null;
+    require_once(__DIR__ . "/Context.php");
 
 
     /**
     /**
      * Application controller.
      * Application controller.
@@ -49,61 +30,34 @@
      *
      *
      * @category Controller
      * @category Controller
      */
      */
-    class Controller {
-
-        /**
-         * Constructor.
-         *
-         * Handles every request, creating the required models and selecting the
-         * view.
-         *
-         * @param mixed[] $params POST parameters of the request.
-         * @return int HTTP status codes 200 or 404;
-         * @global int User ID.
-         * @global resource Databse connection.
-         */
-        public function __construct($params){
-
-            global $USER;
-            global $PLAYER;
-            global $MODE;
-            global $db;
-
-            $page = null;
-
-            session_start();
-            $db = DB::start();
+    class Controller extends Context{
 
 
-            // Parse parameters, get lang and build the route.
-            $pars = [];
-            foreach($params as $p){
-                if (strlen($p) > 0){
-                    array_push($pars, $p);
-                }
-            }
+        private $player;
+        private $user;
+        private $mode;
+        private $page;
+        private $db;
+        private $component; // web, api, action
+        private $command;
+        private $source;
+        private $params = [];
+        private $context;
 
 
+        public function action(){
             // API call: Use API controller
             // API call: Use API controller
-            if (count($pars) > 0 && strtoupper($pars[0]) == "API"){
-                if (count($pars) == 1){
+            if (count($this->params) > 0 && strtoupper($this->params[0]) == "API"){
+                if (count($this->params) == 1){
                     // TODO: API MAIN PAGE
                     // TODO: API MAIN PAGE
                 }
                 }
                 else{
                 else{
-                    $version = strtolower($pars[1]);
-                    $api_params = $pars;
+                    $version = strtolower($this->params[1]);
+                    $api_params = $this->params;
                     array_shift($api_params);
                     array_shift($api_params);
                     array_shift($api_params);
                     array_shift($api_params);
                     switch ($version){
                     switch ($version){
                         case "v1":
                         case "v1":
                             require_once(__DIR__ . "/API/v1/API_Controller.php");
                             require_once(__DIR__ . "/API/v1/API_Controller.php");
-                            new API_Controller($params);
-                            break;
-                        case "v2":
-                            require_once(__DIR__ . "/API/v2/API_Controller.php");
-                            new API_Controller($params);
-                            break;
-                        case "v3":
-                            require_once(__DIR__ . "/API/v3/API_Controller.php");
-                            new API_Controller($params);
+                            new API_Controller($this->params);
                             break;
                             break;
                     }
                     }
                 }
                 }
@@ -112,8 +66,8 @@
             // Special case: Actions.
             // Special case: Actions.
             // Not redirecting to page, just execute a function
             // Not redirecting to page, just execute a function
             // TODO: Secure actions
             // TODO: Secure actions
-            elseif (count($pars) > 1 && strtoupper($pars[0]) == "ACTION"){
-                switch (strtoupper($pars[1])){
+            elseif (count($this->params) > 1 && strtoupper($this->params[0]) == "ACTION"){
+                switch (strtoupper($this->params[1])){
                     case "CHANGE_GAME_MODE":
                     case "CHANGE_GAME_MODE":
                         require_once(PATH::ACTION . "change_game_mode.php");
                         require_once(PATH::ACTION . "change_game_mode.php");
                         action();
                         action();
@@ -188,13 +142,146 @@
                         http_response_code(404);
                         http_response_code(404);
                 }
                 }
             }
             }
+        
+            // Select the model to load.
+            array_shift($this->params); // Remove first one, should be player_id
+            if (sizeof($this->params) == 0){
+                require_once(PATH::PAGE . "Home_Page.php");
+                $page = new Home_Page();
+            }
+            else{
+                if (strtoupper($this->params[0]) == "RUNES"){
+                    require_once(PATH::PAGE . "Runes_Page.php");
+                    $page = new Runes_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "ENCHANTMENTS"){
+                    require_once(PATH::PAGE . "Enchantments_Page.php");
+                    $page = new Enchantments_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "ARTIFACTS"){
+                    require_once(PATH::PAGE . "Artifacts_Page.php");
+                    $page = new Artifacts_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "GUILD"){
+                    require_once(PATH::PAGE . "Guild_Page.php");
+                    $page = new Guild_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "RUNS"){
+                    require_once(PATH::PAGE . "Runs_Page.php");
+                    $page = new Runs_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "STATS"){
+                    require_once(PATH::PAGE . "Stats_Page.php");
+                    $page = new Stats_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "TEAMS"){
+                    require_once(PATH::PAGE . "Teams_Page.php");
+                    $page = new Teams_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "PROFILE"){
+                    require_once(PATH::PAGE . "Profile_Page.php");
+                    $page = new Profile_Page();
+                }
+                elseif (strtoupper($this->params[0]) == "UNITS"){
+                    if (count($this->params) == 1){
+                        require_once(PATH::PAGE . "Units_Page.php");
+                        $page = new Units_Page();
+                    }
+                    else{
+                        require_once(PATH::PAGE . "Unit_Page.php");
+                        $page = new Unit_Page($this->params[1]);
+                    }
+                }
+                elseif (strtoupper($this->params[0]) == "CATALOG"){
+                    if (count($this->params) == 1){
+                        require_once(PATH::PAGE . "Monsters_Page.php");
+                        $page = new Monsters_Page();
+                    }
+                    else{
+                        require_once(PATH::PAGE . "Monster_Page.php");
+                        $page = new Monster_Page($this->params[1]);
+                    }
+                }
+                elseif (strtoupper($this->params[0]) == "REPORT"){
+                    if (count($this->params) == 1){
+                        require_once(PATH::PAGE . "Report_Page.php");
+                        $page = new Report_Page();
+                    }
+                    elseif (strtoupper($this->params[1]) == "SKILLUP"){
+                        require_once(PATH::PAGE . "Report_Skillup_Page.php");
+                        $page = new Report_Skillup_Page($this->params[1]);
+                    }
+                    elseif (strtoupper($this->params[1]) == "RUNE_ENCHANTMENT"){
+                        require_once(PATH::PAGE . "Report_Rune_Enchantment_Page.php");
+                        $page = new Report_Rune_Enchantment_Page($this->params[1]);
+                    }
+                }
+                elseif (strtoupper($this->params[0]) == "OPTIMIZER"){
+                    if (count($this->params) == 1){
+                        require_once(PATH::PAGE . "Optimizer_Page.php");
+                        $page = new Optimizer_Page();
+                    }
+                    else{
+                        require_once(PATH::PAGE . "Optimizer_Unit_Page.php");
+                        $page = new Optimizer_Unit_Page($this->params[1]);
+                    }
+                }
+            }
 
 
-            // Authentication
-            $USER = null;
+            // Load the view, or set an error code.
+            if (isset($page)){
+                require_once($page->view);
+                return 200;
+            }
+            else{
+                require_once(PATH::PAGE . "Error_Page.php");
+                $page = new Error_Page(404);
+                http_response_code(404);
+                return 404;
+            }
+        }
+
+        public function get_context(){
+            return $this->context;
+        }
+
+        /**
+         * Constructor.
+         *
+         * Handles every request, creating the required models and selecting the
+         * view.
+         *
+         * @param mixed[] $params POST parameters of the request.
+         * @return int HTTP status codes 200 or 404;
+         */
+        public function __construct(){
+            $this->context = new Context();
+            session_start();
+            $this->db = DB::start();
+            $this->context->set_db($this->db);
+        }
+
+        /**
+         * Constructor.
+         *
+         * Receives the request params and gets itself ready.
+         *
+         * @param mixed[] $params POST parameters of the request.
+         * @return int HTTP status codes 200 or 404;
+         */
+        public function prepare($params){
+
+            // Parse parameters.
+            foreach($params as $p){
+                if (strlen($p) > 0){
+                    array_push($this->params, $p);
+                }
+            }
 
 
+            // Authentication
             if (array_key_exists("user_token", $_COOKIE) && array_key_exists("user_id", $_COOKIE)){
             if (array_key_exists("user_token", $_COOKIE) && array_key_exists("user_id", $_COOKIE)){
                 // Authenticated user, check token.
                 // Authenticated user, check token.
-                $statement = $db->prepare("
+                $statement = $this->db->prepare("
                   SELECT count(token) AS c
                   SELECT count(token) AS c
                   FROM token
                   FROM token
                   WHERE
                   WHERE
@@ -215,7 +302,8 @@
                     // Token is valid, renew session, and assign user.
                     // Token is valid, renew session, and assign user.
                     $_SESSION["user_id"] = $_COOKIE["user_id"];
                     $_SESSION["user_id"] = $_COOKIE["user_id"];
                     $_SESSION["session"] = true;
                     $_SESSION["session"] = true;
-                    $USER = new User($_COOKIE["user_id"]);
+                    $this->user = new User($_COOKIE["user_id"]);
+                    $this->context->set_user($this->user);
                 }
                 }
 
 
             }
             }
@@ -225,11 +313,10 @@
 
 
 
 
             // Validate URL (check if it has the player ID).
             // Validate URL (check if it has the player ID).
-            $PLAYER = null;
-            if (sizeof($pars) > 0 && preg_match("/^[0-9]{6,12}$/", $pars[0]) == 1){
-error_log("PLAYER IN URL: " . $pars[0]);
+            $this->player = null;
+            if (sizeof($this->params) > 0 && preg_match("/^[0-9]{6,12}$/", $this->params[0]) == 1){
                 // Player ID passed in URL. Check it in database
                 // Player ID passed in URL. Check it in database
-                $statement = $db->prepare("
+                $statement = $this->db->prepare("
                   SELECT
                   SELECT
                     id,
                     id,
                     user,
                     user,
@@ -237,20 +324,21 @@ error_log("PLAYER IN URL: " . $pars[0]);
                   FROM player
                   FROM player
                   WHERE id = :id
                   WHERE id = :id
                 ");
                 ");
-                $statement->bindValue(":id", $pars[0], SQLITE3_TEXT);
+                $statement->bindValue(":id", $this->params[0], SQLITE3_TEXT);
                 $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
                 $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
                 if ($r){
                 if ($r){
                     // The player exists...
                     // The player exists...
-                    if (null != $USER && $r["user"] == $USER->id){
+                    if (null != $this->user && $r["user"] == $this->user->id){
                         // ... and it belongs to the user. Proceed.
                         // ... and it belongs to the user. Proceed.
-                        $PLAYER = new Player($r["id"]);
-error_log("PLAYER SET: " . $PLAYER->id);
+                        $this->player = new Player($r["id"]);
+                        $this->context->set_player($this->player);
                     }
                     }
-                    elseif (null == $USER || $r["user"] != $USER->id){
+                    elseif (null == $this->user || $r["user"] != $this->user->id){
                         // ... and it doesn't belong to the user...
                         // ... and it doesn't belong to the user...
                         if ($r["public"] == 1){
                         if ($r["public"] == 1){
                             // ... and it belongs to a public profile. Proceed.
                             // ... and it belongs to a public profile. Proceed.
-                            $PLAYER = new Player($r[$id]);
+                            $this->player = new Player($r["id"]);
+                            $this->context->set_player($this->player);
                         }
                         }
                         else{
                         else{
                             // ... and it belongs to a private profile. Deny access.
                             // ... and it belongs to a private profile. Deny access.
@@ -260,10 +348,8 @@ error_log("PLAYER SET: " . $PLAYER->id);
                 }
                 }
             }
             }
             else{
             else{
-error_log("PLAYER NOT IN URL: ");
                 // Player ID is not passed as URL...
                 // Player ID is not passed as URL...
-                if (null == $USER){
-error_log("    USER NOT LOGGED IN: ");
+                if (null == $this->user){
                     // ... and no user logged in. Go to the landing page.
                     // ... and no user logged in. Go to the landing page.
                     require_once(PATH::PAGE . "Landing_Page.php");
                     require_once(PATH::PAGE . "Landing_Page.php");
                     $page = new Landing_Page();
                     $page = new Landing_Page();
@@ -271,15 +357,14 @@ error_log("    USER NOT LOGGED IN: ");
                     return;
                     return;
                 }
                 }
                 else{
                 else{
-error_log("    USER LOGGED IN: " . $USER->id);
                     // ... and the user is logged in. Get last accessed account.
                     // ... and the user is logged in. Get last accessed account.
-                    $statement = $db->prepare("
+                    $statement = $this->db->prepare("
                       SELECT id
                       SELECT id
                       FROM player
                       FROM player
                       WHERE user = :user
                       WHERE user = :user
                       ORDER BY last_access DESC
                       ORDER BY last_access DESC
                     ");
                     ");
-                    $statement->bindValue(":user", $USER->id, SQLITE3_INTEGER);
+                    $statement->bindValue(":user", $this->user->id, SQLITE3_INTEGER);
                     $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
                     $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
                     if ($r){
                     if ($r){
                         header("Location: /" . $r["id"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH));
                         header("Location: /" . $r["id"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH));
@@ -295,115 +380,18 @@ error_log("    USER LOGGED IN: " . $USER->id);
             }
             }
 
 
             // Get game mode
             // Get game mode
-            $statement = $db->prepare("SELECT mode FROM player WHERE id = :id;");
-            $statement->bindValue(":id", $PLAYER->id, SQLITE3_INTEGER);
+            $statement = $this->db->prepare("SELECT mode FROM player WHERE id = :id;");
+            $statement->bindValue(":id", $this->player->get_id(), SQLITE3_INTEGER);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             if ($r && $r["mode"] == GAME_MODE_ID::RTA){
             if ($r && $r["mode"] == GAME_MODE_ID::RTA){
-                $MODE = GAME_MODE_ID::RTA;
-            }
-            else{
-                $MODE = GAME_MODE_ID::NORMAL;
-            }
-
-            // Select the model to load.
-            array_shift($pars); // Remove first one, should be player_id
-            if (sizeof($pars) == 0){
-                require_once(PATH::PAGE . "Home_Page.php");
-                $page = new Home_Page();
-            }
-            else{
-                if (strtoupper($pars[0]) == "FUSION"){
-                    require_once(PATH::PAGE . "Fusion_Page.php");
-                    $page = new Fusion_Page();
-                }
-                elseif (strtoupper($pars[0]) == "RUNES"){
-                    require_once(PATH::PAGE . "Runes_Page.php");
-                    $page = new Runes_Page();
-                }
-                elseif (strtoupper($pars[0]) == "ENCHANTMENTS"){
-                    require_once(PATH::PAGE . "Enchantments_Page.php");
-                    $page = new Enchantments_Page();
-                }
-                elseif (strtoupper($pars[0]) == "ARTIFACTS"){
-                    require_once(PATH::PAGE . "Artifacts_Page.php");
-                    $page = new Artifacts_Page();
-                }
-                elseif (strtoupper($pars[0]) == "GUILD"){
-                    require_once(PATH::PAGE . "Guild_Page.php");
-                    $page = new Guild_Page();
-                }
-                elseif (strtoupper($pars[0]) == "RUNS"){
-                    require_once(PATH::PAGE . "Runs_Page.php");
-                    $page = new Runs_Page();
-                }
-                elseif (strtoupper($pars[0]) == "STATS"){
-                    require_once(PATH::PAGE . "Stats_Page.php");
-                    $page = new Stats_Page();
-                }
-                elseif (strtoupper($pars[0]) == "TEAMS"){
-                    require_once(PATH::PAGE . "Teams_Page.php");
-                    $page = new Teams_Page();
-                }
-                elseif (strtoupper($pars[0]) == "PROFILE"){
-                    require_once(PATH::PAGE . "Profile_Page.php");
-                    $page = new Profile_Page();
-                }
-                elseif (strtoupper($pars[0]) == "UNITS"){
-                    if (count($pars) == 1){
-                        require_once(PATH::PAGE . "Units_Page.php");
-                        $page = new Units_Page();
-                    }
-                    else{
-                        require_once(PATH::PAGE . "Unit_Page.php");
-                        $page = new Unit_Page($pars[1]);
-                    }
-                }
-                elseif (strtoupper($pars[0]) == "CATALOG"){
-                    if (count($pars) == 1){
-                        require_once(PATH::PAGE . "Catalog_Page.php");
-                        $page = new Catalog_Page();
-                    }
-                    else{
-                        require_once(PATH::PAGE . "Monster_Page.php");
-                        $page = new Monster_Page($pars[1]);
-                    }
-                }
-                elseif (strtoupper($pars[0]) == "REPORT"){
-                    if (count($pars) == 1){
-                        require_once(PATH::PAGE . "Report_Page.php");
-                        $page = new Report_Page();
-                    }
-                    elseif (strtoupper($pars[1]) == "SKILLUP"){
-                        require_once(PATH::PAGE . "Report_Skillup_Page.php");
-                        $page = new Report_Skillup_Page($pars[1]);
-                    }
-                    elseif (strtoupper($pars[1]) == "RUNE_ENCHANTMENT"){
-                        require_once(PATH::PAGE . "Report_Rune_Enchantment_Page.php");
-                        $page = new Report_Rune_Enchantment_Page($pars[1]);
-                    }
-                }
-                elseif (strtoupper($pars[0]) == "OPTIMIZER"){
-                    if (count($pars) == 1){
-                        require_once(PATH::PAGE . "Optimizer_Page.php");
-                        $page = new Optimizer_Page();
-                    }
-                    else{
-                        require_once(PATH::PAGE . "Optimizer_Unit_Page.php");
-                        $page = new Optimizer_Unit_Page($pars[1]);
-                    }
-                }
-            }
-            // Load the view, or set an error code.
-            if (isset($page)){
-                require_once($page->view);
-                return 200;
+                $this->mode = GAME_MODE_ID::RTA;
             }
             }
             else{
             else{
-                require_once(PATH::PAGE . "Error_Page.php");
-                $page = new Error_Page(404);
-                http_response_code(404);
-                return 404;
+                $this->mode = GAME_MODE_ID::NORMAL;
             }
             }
+            $this->context->set_game_mode($this->mode);
+            
+            
         }
         }
     }
     }
 ?>
 ?>

+ 1 - 3
application/action/change_game_mode.php

@@ -19,16 +19,14 @@
      *
      *
      * @return int 0 on success, negative values on error.
      * @return int 0 on success, negative values on error.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
-        global $db;
         $player = filter_input(INPUT_GET, "player");
         $player = filter_input(INPUT_GET, "player");
         $mode = filter_input(INPUT_GET, "mode");
         $mode = filter_input(INPUT_GET, "mode");
         if (mode != GAME_MODE_ID::NORMAL && mode != GAME_MODE_ID::RTA){
         if (mode != GAME_MODE_ID::NORMAL && mode != GAME_MODE_ID::RTA){
             return 400;
             return 400;
         }
         }
-        $statement = $db->prepare("
+        $statement = get_context()->get_db()->prepare("
           UPDATE player
           UPDATE player
           SET mode = :mode
           SET mode = :mode
           WHERE id = :id;
           WHERE id = :id;

+ 2 - 4
application/action/delete_team.php

@@ -17,18 +17,16 @@
      * 
      * 
      * @return int 0 on success, negative values on error.
      * @return int 0 on success, negative values on error.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
 
 
-        global $db;
         $player = filter_input(INPUT_POST, 'player');
         $player = filter_input(INPUT_POST, 'player');
         $id = filter_input(INPUT_POST, 'id');
         $id = filter_input(INPUT_POST, 'id');
-        $statement = $db->prepare('DELETE FROM team WHERE player = :player AND id = :id;');
+        $statement = get_context()->get_db()->prepare('DELETE FROM team WHERE player = :player AND id = :id;');
         $statement->bindValue(':player', $player, SQLITE3_TEXT);
         $statement->bindValue(':player', $player, SQLITE3_TEXT);
         $statement->bindValue(':id', $id, SQLITE3_TEXT);
         $statement->bindValue(':id', $id, SQLITE3_TEXT);
         $statement->execute();
         $statement->execute();
-        $statement = $db->prepare('DELETE FROM team_unit WHERE team = :id;');
+        $statement = get_context()->get_db()->prepare('DELETE FROM team_unit WHERE team = :id;');
         $statement->bindValue(':id', $id, SQLITE3_TEXT);
         $statement->bindValue(':id', $id, SQLITE3_TEXT);
         $statement->execute();
         $statement->execute();
         return 0;
         return 0;

+ 4 - 7
application/action/edit_profile.php

@@ -21,12 +21,9 @@
      * @return int|string 0 on success, negative values on error. If the API
      * @return int|string 0 on success, negative values on error. If the API
      * key has been updated, the new key.
      * key has been updated, the new key.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
 
 
-        global $db;
-
         $response = null;
         $response = null;
 
 
         // TODO: Dont pass user as argument, use currently logged in one.
         // TODO: Dont pass user as argument, use currently logged in one.
@@ -37,7 +34,7 @@
             if (!filter_var($mail, FILTER_VALIDATE_EMAIL)){
             if (!filter_var($mail, FILTER_VALIDATE_EMAIL)){
                 return -1;
                 return -1;
             }
             }
-            $s = $db->prepare('UPDATE user SET mail = :mail WHERE id = :user;');
+            $s = get_context()->get_db()->prepare('UPDATE user SET mail = :mail WHERE id = :user;');
             $s->bindValue(':user', $user, SQLITE3_TEXT);
             $s->bindValue(':user', $user, SQLITE3_TEXT);
             $s->bindValue(':mail', $mail, SQLITE3_TEXT);
             $s->bindValue(':mail', $mail, SQLITE3_TEXT);
             if(!$s->execute()){
             if(!$s->execute()){
@@ -48,7 +45,7 @@
         if (filter_input(INPUT_POST, "pass")){
         if (filter_input(INPUT_POST, "pass")){
             $pass = sha1(filter_input(INPUT_POST, 'pass'));
             $pass = sha1(filter_input(INPUT_POST, 'pass'));
             $currentPass = sha1(filter_input(INPUT_POST, 'currentPass'));
             $currentPass = sha1(filter_input(INPUT_POST, 'currentPass'));
-            $s = $db->prepare('SELECT COUNT(id) AS count FROM user WHERE id = :id AND password = :currentPass;');
+            $s = get_context()->get_db()->prepare('SELECT COUNT(id) AS count FROM user WHERE id = :id AND password = :currentPass;');
             $s->bindValue(':id', $user, SQLITE3_TEXT);
             $s->bindValue(':id', $user, SQLITE3_TEXT);
             $s->bindValue(':currentPass', $currentPass, SQLITE3_TEXT);
             $s->bindValue(':currentPass', $currentPass, SQLITE3_TEXT);
             $q = $s->execute();
             $q = $s->execute();
@@ -56,7 +53,7 @@
             if ($r["count"] != 1){
             if ($r["count"] != 1){
                 return -3;
                 return -3;
             }
             }
-            $s = $db->prepare('UPDATE user SET password = :pass WHERE id = :id AND password = :currentPass;');
+            $s = get_context()->get_db()->prepare('UPDATE user SET password = :pass WHERE id = :id AND password = :currentPass;');
             $s->bindValue(':id', $user, SQLITE3_TEXT);
             $s->bindValue(':id', $user, SQLITE3_TEXT);
             $s->bindValue(':pass', $pass, SQLITE3_TEXT);
             $s->bindValue(':pass', $pass, SQLITE3_TEXT);
             $s->bindValue(':currentPass', $currentPass, SQLITE3_TEXT);
             $s->bindValue(':currentPass', $currentPass, SQLITE3_TEXT);
@@ -72,7 +69,7 @@
             for ($i = 0; $i < $charactersLength; $i++) {
             for ($i = 0; $i < $charactersLength; $i++) {
                 $api .= $characters[rand(0, $charactersLength - 1)];
                 $api .= $characters[rand(0, $charactersLength - 1)];
             }
             }
-            $s = $db->prepare('UPDATE user SET api_key = :api WHERE id = :id;');
+            $s = get_context()->get_db()->prepare('UPDATE user SET api_key = :api WHERE id = :id;');
             $s->bindValue(':id', $user, SQLITE3_TEXT);
             $s->bindValue(':id', $user, SQLITE3_TEXT);
             $s->bindValue(':api', $api, SQLITE3_TEXT);
             $s->bindValue(':api', $api, SQLITE3_TEXT);
             if(!$s->execute()){
             if(!$s->execute()){

+ 2 - 5
application/action/login.php

@@ -19,12 +19,9 @@
      *
      *
      * @return int 0 on success, negative values on error.
      * @return int 0 on success, negative values on error.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
 
 
-        global $db;
-
         if (!isset($_POST['uname'], $_POST['password'])){
         if (!isset($_POST['uname'], $_POST['password'])){
             header("Location: " . URL::BASE);
             header("Location: " . URL::BASE);
             exit();
             exit();
@@ -40,7 +37,7 @@
             exit();
             exit();
         }
         }
         $password = hash('sha256', $password);
         $password = hash('sha256', $password);
-        $statement = $db->prepare("
+        $statement = get_context()->get_db()->prepare("
           SELECT
           SELECT
             id,
             id,
             name
             name
@@ -69,7 +66,7 @@
         //$_COOKIE["user_token"]) && isset($COOKIE["user_id"])
         //$_COOKIE["user_token"]) && isset($COOKIE["user_id"])
         $token = bin2hex(random_bytes(32));
         $token = bin2hex(random_bytes(32));
         $expiry = time() + 5 * 24 * 60 * 60; // 5 days
         $expiry = time() + 5 * 24 * 60 * 60; // 5 days
-        $statement = $db->prepare("
+        $statement = get_context()->get_db()->prepare("
           INSERT INTO token (user, token, expiry) VALUES
           INSERT INTO token (user, token, expiry) VALUES
           (:user, :token, :expiry);
           (:user, :token, :expiry);
         ");
         ");

+ 0 - 2
application/action/logout.php

@@ -15,10 +15,8 @@
      * 
      * 
      * @return int 0.
      * @return int 0.
      * @category Action
      * @category Action
-     * @global User The logged-in user.
      */
      */
     function action(){
     function action(){
-        $USER = null;
         setcookie("user_id", null, time() - 3600);
         setcookie("user_id", null, time() - 3600);
         setcookie("user_token", null, time() - 3600);
         setcookie("user_token", null, time() - 3600);
         session_regenerate_id();
         session_regenerate_id();

+ 3 - 6
application/action/new_team.php

@@ -24,12 +24,9 @@
      * 
      * 
      * @return int 0 on success, negative values on error.
      * @return int 0 on success, negative values on error.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
 
 
-        global $db;
-
         $player = filter_input(INPUT_POST, 'player');
         $player = filter_input(INPUT_POST, 'player');
         $area_type = filter_input(INPUT_POST, 'area_type');
         $area_type = filter_input(INPUT_POST, 'area_type');
         $area = filter_input(INPUT_POST, 'area');
         $area = filter_input(INPUT_POST, 'area');
@@ -168,10 +165,10 @@
             return -4;
             return -4;
         }
         }
         $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
         $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
-        $q = $db->query($s);
+        $q = get_context()->get_db()->query($s);
         $r = $q->fetchArray(SQLITE3_ASSOC);
         $r = $q->fetchArray(SQLITE3_ASSOC);
         $team_id = $r["id"];
         $team_id = $r["id"];
-        $statement = $db->prepare("
+        $statement = get_context()->get_db()->prepare("
           INSERT INTO team (
           INSERT INTO team (
             player,
             player,
             id,
             id,
@@ -218,7 +215,7 @@
             if ($j < $total_front){
             if ($j < $total_front){
                 $front = 1;
                 $front = 1;
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               INSERT INTO team_unit (team, unit, leader, front)
               INSERT INTO team_unit (team, unit, leader, front)
               VALUES (:team, :unit, :leader, :front);
               VALUES (:team, :unit, :leader, :front);
             ");
             ");

+ 9 - 13
application/action/optimize_get_rune_list.php

@@ -22,13 +22,9 @@
      * @return int|string 0 on success, negative values on error. If the API
      * @return int|string 0 on success, negative values on error. If the API
      * key has been updated, the new key.
      * key has been updated, the new key.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
 
 
-        global $db;
-        global $MODE;
-
         // Increase max execution time.
         // Increase max execution time.
         set_time_limit(60);
         set_time_limit(60);
         
         
@@ -119,29 +115,29 @@
             case 0: // Storage only (or itself)
             case 0: // Storage only (or itself)
                 $base_s .= "
                 $base_s .= "
                   (
                   (
-                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = $MODE)
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = $MODE)
+                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = " . get_context()->get_game_mode() . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . ")
                   )";
                   )";
                 break;
                 break;
             case 1: // Units in no teams (or itself)
             case 1: // Units in no teams (or itself)
                 $base_s .= "
                 $base_s .= "
                   (
                   (
-                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = $MODE)
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = $MODE)
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = $MODE AND unit NOT IN (SELECT DISTINCT unit FROM team_unit))
+                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = " . get_context()->get_game_mode() . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . " AND unit NOT IN (SELECT DISTINCT unit FROM team_unit))
                   )
                   )
                 ";
                 ";
                 break;
                 break;
             case 2: // Units in teams with 0 score (or itself)
             case 2: // Units in teams with 0 score (or itself)
                 $base_s .= "
                 $base_s .= "
                   (
                   (
-                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = $MODE)
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = $MODE)
+                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = " . get_context()->get_game_mode() . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . ")
                     OR rune.id NOT IN (
                     OR rune.id NOT IN (
                       SELECT DISTINCT unit 
                       SELECT DISTINCT unit 
                       FROM unit_rune 
                       FROM unit_rune 
                       WHERE
                       WHERE
-                        rta = $MODE
+                        rta = " . get_context()->get_game_mode() . "
                         AND unit NOT IN (
                         AND unit NOT IN (
                           SELECT DISTINCT unit 
                           SELECT DISTINCT unit 
                           FROM
                           FROM
@@ -177,7 +173,7 @@
 
 
         $total_candidates = 0;
         $total_candidates = 0;
         for ($i = 1; $i <= 6; $i ++){
         for ($i = 1; $i <= 6; $i ++){
-            $statement = $db->prepare($s[$i]);
+            $statement = get_context()->get_db()->prepare($s[$i]);
             $statement->bindValue(':player', $player, SQLITE3_TEXT);
             $statement->bindValue(':player', $player, SQLITE3_TEXT);
             $statement->bindValue(':unit_id', $unit_id, SQLITE3_TEXT);
             $statement->bindValue(':unit_id', $unit_id, SQLITE3_TEXT);
             $statement->bindValue(':stat_0', $stats[0], SQLITE3_TEXT);
             $statement->bindValue(':stat_0', $stats[0], SQLITE3_TEXT);

+ 1 - 3
application/action/rate_team.php

@@ -19,14 +19,12 @@
      *
      *
      * @return int 0 on success, negative values on error.
      * @return int 0 on success, negative values on error.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
-        global $db;
         $player = filter_input(INPUT_GET, "player");
         $player = filter_input(INPUT_GET, "player");
         $team = filter_input(INPUT_GET, "team");
         $team = filter_input(INPUT_GET, "team");
         $score = intval(filter_input(INPUT_GET, "score"));
         $score = intval(filter_input(INPUT_GET, "score"));
-        $statement = $db->prepare("
+        $statement = get_context()->get_db()->prepare("
           UPDATE team
           UPDATE team
           SET score = :score
           SET score = :score
           WHERE
           WHERE

+ 5 - 7
application/action/save_run_team.php

@@ -19,10 +19,8 @@
      * 
      * 
      * @return int 0 on success, negative values on error.
      * @return int 0 on success, negative values on error.
      * @category Action
      * @category Action
-     * @global resource Database connection.
      */
      */
     function action(){
     function action(){
-        global $db;
         $player = filter_input(INPUT_POST, 'player');
         $player = filter_input(INPUT_POST, 'player');
         $run = filter_input(INPUT_POST, 'run');
         $run = filter_input(INPUT_POST, 'run');
         $name = filter_input(INPUT_POST, 'name');
         $name = filter_input(INPUT_POST, 'name');
@@ -31,10 +29,10 @@
             return -1;
             return -1;
         }
         }
         $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
         $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
-        $q = $db->query($s);
+        $q = get_context()->get_db()->query($s);
         $r = $q->fetchArray(SQLITE3_ASSOC);
         $r = $q->fetchArray(SQLITE3_ASSOC);
         $team_id = $r["id"];
         $team_id = $r["id"];
-        $statement = $db->prepare("
+        $statement = get_context()->get_db()->prepare("
           SELECT
           SELECT
             run.area AS area,
             run.area AS area,
             run.stage AS stage,
             run.stage AS stage,
@@ -55,7 +53,7 @@
         if (!$r){
         if (!$r){
             return -2;
             return -2;
         }
         }
-        $statement = $db->prepare("
+        $statement = get_context()->get_db()->prepare("
           INSERT INTO team (
           INSERT INTO team (
             player,
             player,
             id,
             id,
@@ -91,9 +89,9 @@
             return -3;
             return -3;
         }
         }
         $s = "SELECT unit FROM data.run_party WHERE run = $run AND unit IS NOT NULL;";
         $s = "SELECT unit FROM data.run_party WHERE run = $run AND unit IS NOT NULL;";
-        $q = $db->query($s);
+        $q = get_context()->get_db()->query($s);
         while ($r = $q->fetchArray(SQLITE3_ASSOC)){
         while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               INSERT INTO data.team_unit (team, unit)
               INSERT INTO data.team_unit (team, unit)
               VALUES (:team, :unit)
               VALUES (:team, :unit)
             ");
             ");

+ 39 - 29
application/entity/Area.php

@@ -1,14 +1,14 @@
 <?php
 <?php
     /**
     /**
-     * Area type entity file.
+     * Area entity file.
      *
      *
      * Creates the entity and makes it available.
      * Creates the entity and makes it available.
      *
      *
      * @category Entity
      * @category Entity
      */
      */
 
 
-    /**
-     * Require dependent entities if not present.
+    /*
+     * Require entity dependencies if not present.
      */
      */
     require_once(PATH::ENTITY . "Entity.php");
     require_once(PATH::ENTITY . "Entity.php");
 
 
@@ -22,38 +22,23 @@
      */
      */
     class Area extends Entity{
     class Area extends Entity{
 
 
-        /**
-         * @var int Area identifier (it may not be unique!).
-         */
-        public $id;
-
-        /**
-         * @var int Area type.
-         */
-        public $type;
-
-        /**
-         * @var string Area name.
-         */
-        public $name;
+        private $id;
+        private $type;
+        private $name;
 
 
         /**
         /**
          * Constructor.
          * Constructor.
          *
          *
-         * Searches the database and retrieves the information about the
-         * run, populating it and it's items.
+         * Retrieves the area information from the database.
          *
          *
          * @param int $id Area identifier.
          * @param int $id Area identifier.
-         * @param int $type Area type (required).
-         * @global resource Database connection.
+         * @param int $type Area type.
          */
          */
         public function __construct($id, $type){
         public function __construct($id, $type){
 
 
-            global $db;
-
             $this->id = $id;
             $this->id = $id;
             $this->type = $type;
             $this->type = $type;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   id,
                   id,
                   type,
                   type,
@@ -75,7 +60,7 @@
                 $this->name = "Hall of Heroes";
                 $this->name = "Hall of Heroes";
             }
             }
             else{
             else{
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT name
                   SELECT name
                   FROM area_type
                   FROM area_type
                   WHERE id = :type;
                   WHERE id = :type;
@@ -88,11 +73,36 @@
         }
         }
 
 
         /**
         /**
-         * Gets the path to the area image. The image must be in the
-         * img/area/ directory, and its name must be the area type id,
-         * padded with '0' to 9 digites, and the extension must be '.png'.
+         * Retrieves the area identifier.
+         *
+         * @return int Area ID.
+         */
+        public function getId(){
+            return $this->id;
+        }
+    
+        /**
+         * Retrieves Area type identifier.
+         *
+         * @return int Area type ID
+         */
+        public function getType(){
+            return $this->type;
+        }
+    
+        /**
+         * Retrieves the area name.
+         *
+         * @return string The area name.
+         */
+        public function getName(){
+            return $this->name;
+        }
+    
+        /**
+         * Gets the URL to the area image.
          *
          *
-         * @param string $stage Stage number, for a better image in Cairos.
+         * @param string $stage Stage number, for a more accurate image in Dimension Hole.
          * @return string Image URL, or a fixed unknown image.
          * @return string Image URL, or a fixed unknown image.
          */
          */
         public function get_image($stage = null){
         public function get_image($stage = null){

+ 4 - 8
application/entity/Artifact.php

@@ -122,13 +122,10 @@
          * artifact, populating it and it's items.
          * artifact, populating it and it's items.
          *
          *
          * @param int $id Artifact id.
          * @param int $id Artifact id.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 type,
                 type,
@@ -165,7 +162,7 @@
                 $this->stat = new Artifact_Stat($this->id);
                 $this->stat = new Artifact_Stat($this->id);
 
 
                 // Get effects
                 // Get effects
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT slot
                   SELECT slot
                   FROM artifact_effect
                   FROM artifact_effect
                   WHERE artifact = :artifact
                   WHERE artifact = :artifact
@@ -181,7 +178,7 @@
                 if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
                 if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
                     $this->efficiency = $this->calculate_efficiency();
                     $this->efficiency = $this->calculate_efficiency();
                     $this->max_efficiency = $this->calculate_maximum_efficiency();
                     $this->max_efficiency = $this->calculate_maximum_efficiency();
-                    $statement = $db->prepare("
+                    $statement = get_context()->get_db()->prepare("
                       UPDATE artifact
                       UPDATE artifact
                       SET
                       SET
                         efficiency = :efficiency,
                         efficiency = :efficiency,
@@ -225,7 +222,6 @@
          * @return float Efficiency
          * @return float Efficiency
          */
          */
         private function calculate_efficiency(){
         private function calculate_efficiency(){
-            global $db;
             $eff = [0.0, 0.0, 0.0, 0.0];
             $eff = [0.0, 0.0, 0.0, 0.0];
 
 
             $query = "
             $query = "
@@ -246,7 +242,7 @@
                 if (sizeof($this->effects) > $i && $this->effects[$i] != null && $this->effects[$i]->value > 0){
                 if (sizeof($this->effects) > $i && $this->effects[$i] != null && $this->effects[$i]->value > 0){
                     $value = $this->effects[$i]->value;
                     $value = $this->effects[$i]->value;
                     $value = $this->effects[$i]->value;
                     $value = $this->effects[$i]->value;
-                    $statement = $db->prepare($query);
+                    $statement = get_context()->get_db()->prepare($query);
                     $statement->bindValue(':initial', 1, SQLITE3_TEXT);
                     $statement->bindValue(':initial', 1, SQLITE3_TEXT);
                     $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
                     $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
                     $statement->bindValue(':effect', $this->effects[$i]->effect, SQLITE3_TEXT);
                     $statement->bindValue(':effect', $this->effects[$i]->effect, SQLITE3_TEXT);

+ 66 - 41
application/entity/Artifact_Effect.php

@@ -7,7 +7,7 @@
      * @category Entity
      * @category Entity
      */
      */
 
 
-    /**
+    /*
      * Require dependent entities if not present.
      * Require dependent entities if not present.
      */
      */
     require_once(PATH::ENTITY . "Entity.php");
     require_once(PATH::ENTITY . "Entity.php");
@@ -21,55 +21,24 @@
      */
      */
     class Artifact_Effect extends Entity{
     class Artifact_Effect extends Entity{
 
 
-        /**
-         * @var int Effect slot.
-         *
-         * @see ARTIFACT_EFFECT_SLOT_ID
-         */
-        public $slot;
-
-        /**
-         * @var int Effect identifier.
-         *
-         * @see ARTIFACT_EFFECT_ID
-         */
-        public $effect;
-
-        /**
-         * @var string Effect name (uppercase).
-         */
-        public $name = "";
-
-        /**
-         * @var int Effect value.
-         */
-        public $value;
-
-        /**
-         * @var int Ammount gained by effect grindstone.
-         */
-        public $grind;
-
-        /**
-         * @var int Indicates if a gem has been used.
-         */
-        public $enchant;
+        private $slot;
+        private $effect;
+        private $name = "";
+        private $value;
+        private $grind;
+        private $enchant;
 
 
         /**
         /**
          * Constructor.
          * Constructor.
          *
          *
-         * Searches the database and retrieves the information about the
-         * artifact effect, populating it and it's items.
+         * Retrieves the artifact effect information from the database.
          *
          *
          * @param int $artifact Artifact id.
          * @param int $artifact Artifact id.
          * @param int $slot Artifact slot id.
          * @param int $slot Artifact slot id.
-         * @global resource Database connection.
          */
          */
         public function __construct($artifact, $slot){
         public function __construct($artifact, $slot){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 slot,
                 slot,
                 effect,
                 effect,
@@ -89,7 +58,7 @@
                 $this->value = $r["value"];
                 $this->value = $r["value"];
                 $this->enchant = $r["enchant"];
                 $this->enchant = $r["enchant"];
                 $this->grind = $r["grind"];
                 $this->grind = $r["grind"];
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT name
                   SELECT name
                   FROM effect_artifact
                   FROM effect_artifact
                   WHERE id = :id;
                   WHERE id = :id;
@@ -103,5 +72,61 @@
             }
             }
         }
         }
 
 
+        /**
+         * Retrieves the artifact effect's slot identifier.
+         *
+         * @see ARTIFACT_EFFECT_SLOT_ID
+         *
+         * @return int Effect slot ID.
+         */
+        public function getSlot(){
+            return $this->slot;
+        }
+        
+        /**
+         * Artifact effect identifier.
+         *
+         * @return int Effect ID.
+         */
+        public function getEffect(){
+            return $this->effect;
+        }
+        
+        /**
+         * Retrieves the artifact effect name.
+         *
+         * @return string The effect name.
+         */
+        public function getName(){
+            return $this->name;
+        }
+        
+        /**
+         * Retrieves the value of the artifact effect, excluding grinds.
+         *
+         * @return number Effect value.
+         */
+        public function getValue(){
+            return $this->value;
+        }
+        
+        /**
+         * Retrieves the grinded value on the effect.
+         *
+         * @return number Effect grinded value.
+         */
+        public function getGrind(){
+            return $this->grind;
+        }
+        
+        /**
+         * Checks if the effect has been enchanted.
+         *
+         * @return boolean True if the effect was enchanted, false otherwise
+         */
+        public function isEnchanted(){
+            return filter_var($this->enchant, FILTER_VALIDATE_BOOLEAN);
+        }
+
     }
     }
 ?>
 ?>

+ 37 - 26
application/entity/Artifact_Stat.php

@@ -7,7 +7,7 @@
      * @category Entity
      * @category Entity
      */
      */
 
 
-    /**
+    /*
      * Require dependent entities if not present.
      * Require dependent entities if not present.
      */
      */
     require_once(PATH::ENTITY . "Entity.php");
     require_once(PATH::ENTITY . "Entity.php");
@@ -21,37 +21,20 @@
      */
      */
     class Artifact_Stat extends Entity{
     class Artifact_Stat extends Entity{
 
 
-        /**
-         * @var int Stat of the artifact.
-         *
-         * @see ARTIFACT_STAT_ID
-         */
-        public $stat;
-
-        /**
-         * @var string Stat name (uppercase).
-         */
-        public $name = "";
-
-        /**
-         * @var int Stat value of the rune.
-         */
-        public $value;
+        private $stat;
+        private $name = "";
+        private $value;
 
 
         /**
         /**
          * Constructor.
          * Constructor.
          *
          *
-         * Searches the database and retrieves the information about the
-         * artifact stat, populating it and it's items.
+         * Retrieves the artifact stat information from the database.
          *
          *
-         * @param int $id Artifact id.
-         * @global resource Database connection.
+         * @param int $artifact_id Artifact id.
          */
          */
-        public function __construct($artifact){
+        public function __construct($artifact_id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 stat,
                 stat,
                 value
                 value
@@ -59,7 +42,7 @@
               WHERE
               WHERE
                 artifact = :artifact
                 artifact = :artifact
             ");
             ");
-            $statement->bindValue(':artifact', $artifact, SQLITE3_TEXT);
+            $statement->bindValue(':artifact', $artifact_id, SQLITE3_TEXT);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             if ($r){
             if ($r){
                 $this->stat = $r["stat"];
                 $this->stat = $r["stat"];
@@ -77,6 +60,34 @@
                 }
                 }
             }
             }
         }
         }
+        /**
+         * Retrieves the artifact stat identifier.
+         * 
+         * @see ARTIFACT_STAT_ID
+         *
+         * @return int Artifact stat ID.
+         */
+        public function getStat(){
+            return $this->stat;
+        }
+
+        /**
+         * Retrieves the artifact stat name.
+         *
+         * @return string Artifact stat name.
+         */
+        public function getName(){
+            return $this->name;
+        }
+
+        /**
+         * Retrieves the value of the artifact stat value.
+         *
+         * @return number Stat value.
+         */
+        public function getValue(){
+            return $this->value;
+        }
 
 
     }
     }
 ?>
 ?>

+ 1 - 4
application/entity/Buildable.php

@@ -44,13 +44,10 @@
          * building, populating it and it's items.
          * building, populating it and it's items.
          *
          *
          * @param int $id Buildable identifier.
          * @param int $id Buildable identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,

+ 1 - 4
application/entity/Building.php

@@ -45,13 +45,10 @@
          * building, populating it and it's items.
          * building, populating it and it's items.
          *
          *
          * @param int $id Building identifier.
          * @param int $id Building identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 player,
                 player,
                 buildable,
                 buildable,

+ 1 - 4
application/entity/Decoration.php

@@ -44,13 +44,10 @@
          * decoration, populating it and it's items.
          * decoration, populating it and it's items.
          *
          *
          * @param int $id Building identifier.
          * @param int $id Building identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 player,
                 player,
                 decorative,
                 decorative,

+ 2 - 5
application/entity/Decorative.php

@@ -74,13 +74,10 @@
          * decoration, populating it and it's items.
          * decoration, populating it and it's items.
          *
          *
          * @param int $id Decorative identifier.
          * @param int $id Decorative identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   id,
                   id,
                   name,
                   name,
@@ -102,7 +99,7 @@
                 $this->stat = $r["affected_stat"];
                 $this->stat = $r["affected_stat"];
                 $this->element = $r["element"];
                 $this->element = $r["element"];
                 $this->max_level = $r["max_level"];
                 $this->max_level = $r["max_level"];
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT
                     SELECT
                       level,
                       level,
                       bonus,
                       bonus,

+ 1 - 4
application/entity/Effect.php

@@ -48,13 +48,10 @@
          * skill level, populating it and it's items.
          * skill level, populating it and it's items.
          *
          *
          * @param int $id Effect identifier.
          * @param int $id Effect identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,

+ 2 - 5
application/entity/Enchantment.php

@@ -45,7 +45,7 @@
         public $quality_name;
         public $quality_name;
 
 
         /**
         /**
-         * @var K_Rune_Set Rune set the item can be used on.
+         * @var Rune_Set Rune set the item can be used on.
          */
          */
         public $rune;
         public $rune;
 
 
@@ -108,13 +108,10 @@
          * rune, populating it and it's items.
          * rune, populating it and it's items.
          *
          *
          * @param int $id Enchantment id.
          * @param int $id Enchantment id.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 enchantment.player AS player,
                 enchantment.player AS player,
                 enchantment.id AS id,
                 enchantment.id AS id,

+ 2 - 5
application/entity/Guild.php

@@ -79,13 +79,10 @@
          * guild, populating it and it's items.
          * guild, populating it and it's items.
          *
          *
          * @param int $id Guild identifier.
          * @param int $id Guild identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,
@@ -114,7 +111,7 @@
                 $this->comment = HTML::e($r["comment"]);
                 $this->comment = HTML::e($r["comment"]);
                 $this->notice = HTML::e($r["notice"]);
                 $this->notice = HTML::e($r["notice"]);
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT member
               SELECT member
               FROM guild_member
               FROM guild_member
               WHERE guild = :guild
               WHERE guild = :guild

+ 1 - 4
application/entity/Guild_Member.php

@@ -84,13 +84,10 @@
          * guild, populating it and it's items.
          * guild, populating it and it's items.
          *
          *
          * @param int $id Guild identifier.
          * @param int $id Guild identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 member,
                 member,
                 guild,
                 guild,

+ 1 - 4
application/entity/Guild_Skill.php

@@ -48,13 +48,10 @@
          * skill, populating it and it's items.
          * skill, populating it and it's items.
          *
          *
          * @param int $id Skill identifier.
          * @param int $id Skill identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 skill_group,
                 skill_group,

+ 2 - 5
application/entity/Guild_Skill_Group.php

@@ -49,13 +49,10 @@
          * skill group, populating it and it's items.
          * skill group, populating it and it's items.
          *
          *
          * @param int $id Skill group identifier.
          * @param int $id Skill group identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,
@@ -69,7 +66,7 @@
                 $this->id = $r["id"];
                 $this->id = $r["id"];
                 $this->name = HTML::e($r["name"]);
                 $this->name = HTML::e($r["name"]);
                 $this->description = HTML::e($r["description"]);
                 $this->description = HTML::e($r["description"]);
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT id
                   SELECT id
                   FROM guild_skill
                   FROM guild_skill
                   WHERE skill_group = :id;
                   WHERE skill_group = :id;

+ 1 - 3
application/entity/Inventory.php

@@ -49,10 +49,8 @@
          *
          *
          * @param int $id Item identifier.
          * @param int $id Item identifier.
          * @param int $type Item type identifier. Optional, will try to guess if null.
          * @param int $type Item type identifier. Optional, will try to guess if null.
-         * @global resource Database connection.
          */
          */
         public function __construct($id, $type = null){
         public function __construct($id, $type = null){
-            global $db;
             $s = "
             $s = "
               SELECT
               SELECT
                 inventory.id AS id,
                 inventory.id AS id,
@@ -69,7 +67,7 @@
             if ($type != null){
             if ($type != null){
                 $s .= "AND inventory.type = :type";
                 $s .= "AND inventory.type = :type";
             }
             }
-            $statement = $db->prepare($s);
+            $statement = get_context()->get_db()->prepare($s);
             $statement->bindValue(':id', $id, SQLITE3_TEXT);
             $statement->bindValue(':id', $id, SQLITE3_TEXT);
             $statement->bindValue(':type', $type, SQLITE3_TEXT);
             $statement->bindValue(':type', $type, SQLITE3_TEXT);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);

+ 2 - 5
application/entity/Item.php

@@ -60,12 +60,9 @@
          *
          *
          * @param int $id Item identifier.
          * @param int $id Item identifier.
          * @param int $type Item type identifier. Optional, will try to guess if null.
          * @param int $type Item type identifier. Optional, will try to guess if null.
-         * @global resource Database connection.
          */
          */
         public function __construct($id, $type = null){
         public function __construct($id, $type = null){
 
 
-            global $db;
-
             $s = "
             $s = "
                 SELECT
                 SELECT
                   item.id AS id,
                   item.id AS id,
@@ -87,7 +84,7 @@
             if ($type != null){
             if ($type != null){
                 $s .= "AND inventory.type = :type";
                 $s .= "AND inventory.type = :type";
             }
             }
-            $statement = $db->prepare($s);
+            $statement = get_context()->get_db()->prepare($s);
             $statement->bindValue(':id', $id, SQLITE3_TEXT);
             $statement->bindValue(':id', $id, SQLITE3_TEXT);
             $statement->bindValue(':type', $type, SQLITE3_TEXT);
             $statement->bindValue(':type', $type, SQLITE3_TEXT);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
@@ -96,7 +93,7 @@
                 $this->amount = $r["amount"];
                 $this->amount = $r["amount"];
                 if ($r["type"] == INVENTORY_TYPE_ID::GUILD_MONSTER_PIECE || $r["type"] == INVENTORY_TYPE_ID::MONSTER_PIECE){
                 if ($r["type"] == INVENTORY_TYPE_ID::GUILD_MONSTER_PIECE || $r["type"] == INVENTORY_TYPE_ID::MONSTER_PIECE){
                     $this->is_monster_pices = true;
                     $this->is_monster_pices = true;
-                    $this->id = new K_Unit($r["id"]);
+                    $this->id = new Monster($r["id"]);
                     $this->name = HTML::e($this->id->title) . " Pieces";
                     $this->name = HTML::e($this->id->title) . " Pieces";
                     $this->description = HTML::e($this->id->title) . " Pieces";
                     $this->description = HTML::e($this->id->title) . " Pieces";
                 }
                 }

+ 1 - 4
application/entity/Leader_Skill.php

@@ -53,13 +53,10 @@
          * skill, populating it and it's items.
          * skill, populating it and it's items.
          *
          *
          * @param int $id Skill identifier.
          * @param int $id Skill identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 stat,
                 stat,

+ 5 - 19
application/entity/Monster.php

@@ -232,12 +232,10 @@
          *
          *
          * @param int $id Monster identifier.
          * @param int $id Monster identifier.
          * @param bool $complete If false, query only monster.
          * @param bool $complete If false, query only monster.
-         * @global resource Database connection.
          */
          */
         public function __construct($id, $complete = true){
         public function __construct($id, $complete = true){
-            global $db;
             $this->id = $id;
             $this->id = $id;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 family,
                 family,
@@ -385,13 +383,10 @@
          * It is autoatically called at construction time if the
          * It is autoatically called at construction time if the
          * $complete parameter is true (by default). No point in calling it
          * $complete parameter is true (by default). No point in calling it
          * twice.
          * twice.
-         *
-         * @global resource Database connection.
          */
          */
         public function load_essences(){
         public function load_essences(){
-            global $db;
             $this->essences = [];
             $this->essences = [];
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 item,
                 item,
                 amount
                 amount
@@ -417,13 +412,10 @@
          * It is automatically called at construction time if the
          * It is automatically called at construction time if the
          * $complete parameter is true (by default). No point in calling it
          * $complete parameter is true (by default). No point in calling it
          * twice.
          * twice.
-         *
-         * @global resource Database connection.
          */
          */
         public function load_transformation(){
         public function load_transformation(){
-            global $db;
             $this->transformation = null;
             $this->transformation = null;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT id
               SELECT id
               FROM monster_transformation
               FROM monster_transformation
               WHERE monster = :monster;
               WHERE monster = :monster;
@@ -441,13 +433,10 @@
          * It is autoatically called at construction time if the
          * It is autoatically called at construction time if the
          * $complete parameter is true (by default). No point in calling it
          * $complete parameter is true (by default). No point in calling it
          * twice.
          * twice.
-         *
-         * @global resource Database connection.
          */
          */
         public function load_skills(){
         public function load_skills(){
-            global $db;
             $this->skill = [];
             $this->skill = [];
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT skill.id AS skill
               SELECT skill.id AS skill
               FROM
               FROM
                 skill,
                 skill,
@@ -470,13 +459,10 @@
          * It is autoatically called at construction time if the
          * It is autoatically called at construction time if the
          * $complete parameter is true (by default). No point in calling it
          * $complete parameter is true (by default). No point in calling it
          * twice.
          * twice.
-         *
-         * @global resource Database connection.
          */
          */
         public function load_sources(){
         public function load_sources(){
-            global $db;
             $this->sources = [];
             $this->sources = [];
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT source
               SELECT source
               FROM monster_source
               FROM monster_source
               WHERE monster = :monster;
               WHERE monster = :monster;

+ 2 - 7
application/entity/Monster_Transformation.php

@@ -52,11 +52,9 @@
          * trnsformed monster, populating it and it's items.
          * trnsformed monster, populating it and it's items.
          *
          *
          * @param int $id Transformed monster identifier.
          * @param int $id Transformed monster identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
-            global $db;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 family,
                 family,
@@ -76,13 +74,10 @@
 
 
         /**
         /**
          * Loads the information about the monster skills in the transformed form.
          * Loads the information about the monster skills in the transformed form.
-         *
-         * @global resource Database connection.
          */
          */
         private function load_skills(){
         private function load_skills(){
-            global $db;
             $this->skill = [];
             $this->skill = [];
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT skill
               SELECT skill
               FROM
               FROM
                 skill,
                 skill,

+ 387 - 162
application/entity/Player.php

@@ -27,115 +27,30 @@
      */
      */
     class Player extends Entity{
     class Player extends Entity{
 
 
-        /**
-         * @var int Player ID.
-         */
-        public $id;
-
-        /**
-         * @var Server Player server.
-         */
-        public $server;
-
-        /**
-         * @var string Player country (XX).
-         */
-        public $country;
-
-        /**
-         * @var string Player language (xx).
-         */
-        public $language;
-
-        /**
-         * @var int Player level.
-         */
-        public $level;
-
-        /**
-         * @var string Player name.
-         */
-        public $name;
-
-        /**
-         * @var int Total experience.
-         */
-        public $experience;
-
-        /**
-         * @var Unit Representative Unit.
-         */
-        public $rep;
-
-        /**
-         * @var int Timestamp of player registration.
-         */
-        public $joined = 0;
-
-        /**
-         * @var int Top rank in arena.
-         */
-        public $top_rank_arena = 0;
-
-        /**
-         * @var int Top rank in world arena.
-         */
-        public $top_rank_world_arena = 0;
-
-        /**
-         * @var int Top rank in special league.
-         */
-        public $top_rank_special_league = 0;
-
-        /**
-         * @var int Top rank in guild war.
-         */
-        public $top_rank_gw = 0;
-
-        /**
-         * @var int Top rank in guild siege.
-         */
-        public $top_rank_siege = 0;
-
-        /**
-         * @var int Top rank in World Boss.
-         */
-        public $top_rank_wboss = 0;
-
-        /**
-         * @var int Top rank in TOA normal.
-         */
-        public $top_rank_toan = 0;
-
-        /**
-         * @var int Top rank in TOA HARD.
-         */
-        public $top_rank_toah = 0;
-
-        /**
-         * @var int Top rank in TOA HELL.
-         */
-        public $top_rank_toal = 0;
-
-        /**
-         * @var \Unit[] Units in Arena defense.
-         */
-        public $defense = [];
-
-        /**
-         * @var \Unit[][] Units in Guild War defense.
-         */
-        public $gw_defense = [[], []];
-
-        /**
-         * @var \Unit[][] Units in Siege Battle defense.
-         */
-        public $siege_defense = [];
-
-        /**
-         * @var int[] Currency.
-         */
-        public $currency = [
+        private $id;
+        private $server;
+        private $country;
+        private $language;
+        private $level;
+        private $name;
+        private $experience;
+        private $rep = null;
+        private $rep_id = null;
+        private $joined = 0;
+        private $top_rank_arena = 0;
+        private $top_rank_world_arena = 0;
+        private $top_rank_special_league = 0;
+        private $top_rank_gw = 0;
+        private $top_rank_siege = 0;
+        private $top_rank_wboss = 0;
+        private $top_rank_toan = 0;
+        private $top_rank_toah = 0;
+        private $top_rank_toal = 0;
+        private $flag_defense = false;
+        private $arena_defense = [];
+        private $gw_defense = [[], []];
+        private $siege_defense = [];
+        private $currency = [
             "mana" => 0,
             "mana" => 0,
             "crystal" => 0,
             "crystal" => 0,
             "energy" => 0,
             "energy" => 0,
@@ -152,41 +67,17 @@
             "ancient_stone" => 0,
             "ancient_stone" => 0,
             "costume_point" => 0,
             "costume_point" => 0,
         ];
         ];
-
-        /**
-         * @var \Building[] List of Buildings.
-         */
-        public $building = [];
-
-        /**
-         * @var \Decoration[] List of Decorations.
-         */
-        public $decoration = [];
-
-        /**
-         * @var \item[] List of Scrolls in item.
-         */
-        public $item_scroll = [];
-
-        /**
-         * @var \item[] List of rune crafting items in item.
-         */
-        public $item_craft_rune = [];
-
-        /**
-         * @var \item[] List of rune crafting items in item.
-         */
-        public $item_craft = [];
-
-        /**
-         * @var \item[] List of rune crafting items in item.
-         */
-        public $item_essence = [];
-
-        /**
-         * @var \Record[] Player record runs.
-         */
-        public $record = [];
+        private $flag_building = false;
+        private $building = [];
+        private $decoration = [];
+        private $flag_item = false;
+        private $item_scroll = [];
+        private $item_craft_rune = [];
+        private $item_craft = [];
+        private $item_essence = [];
+        private $flag_record = false;
+        private $record = [];
+        private $public = false;
 
 
 
 
         /**
         /**
@@ -197,11 +88,9 @@
          *
          *
          * @param int $id Monster identifier.
          * @param int $id Monster identifier.
          * @param bool $complete If false, query only monster and k_monster.
          * @param bool $complete If false, query only monster and k_monster.
-         * @global resource Database connection.
          */
          */
         public function __construct($id, $complete = true){
         public function __construct($id, $complete = true){
-            global $db;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 server,
                 server,
@@ -234,7 +123,8 @@
                 top_rank_wboss,
                 top_rank_wboss,
                 top_rank_toan,
                 top_rank_toan,
                 top_rank_toah,
                 top_rank_toah,
-                top_rank_toal
+                top_rank_toal,
+                public
               FROM player
               FROM player
               WHERE id = :id;
               WHERE id = :id;
             ");
             ");
@@ -249,7 +139,7 @@
                 $this->level = $r["level"];
                 $this->level = $r["level"];
                 $this->experience = $r["experience"];
                 $this->experience = $r["experience"];
                 if (strlen($r["rep"]) > 0){
                 if (strlen($r["rep"]) > 0){
-                    $this->rep = new Unit($r["rep"]);
+                    $this->rep_id = $r["rep"];
                 }
                 }
                 $this->currency["mana"] = $r["mana"];
                 $this->currency["mana"] = $r["mana"];
                 $this->currency["crystal"] = $r["crystal"];
                 $this->currency["crystal"] = $r["crystal"];
@@ -265,7 +155,8 @@
                 $this->currency["event_coin"] = $r["event_coin"];
                 $this->currency["event_coin"] = $r["event_coin"];
                 $this->currency["social_point"] = $r["social_point"];
                 $this->currency["social_point"] = $r["social_point"];
                 $this->currency["costume_point"] = $r["costume_point"];
                 $this->currency["costume_point"] = $r["costume_point"];
-                $this->joined = $r["joined"];
+                $this->joined = new Datetime();
+                $this->joined->setTimestamp($r["joined"]);
                 $this->top_rank_arena = $r["top_rank_arena"];
                 $this->top_rank_arena = $r["top_rank_arena"];
                 $this->top_rank_world_arena = $r["top_rank_world_arena"];
                 $this->top_rank_world_arena = $r["top_rank_world_arena"];
                 $this->top_rank_special_league = $r["top_rank_special_league"];
                 $this->top_rank_special_league = $r["top_rank_special_league"];
@@ -275,8 +166,14 @@
                 $this->top_rank_toan = $r["top_rank_toan"];
                 $this->top_rank_toan = $r["top_rank_toan"];
                 $this->top_rank_toah = $r["top_rank_toah"];
                 $this->top_rank_toah = $r["top_rank_toah"];
                 $this->top_rank_toal = $r["top_rank_toal"];
                 $this->top_rank_toal = $r["top_rank_toal"];
+                if (strlen($r["public"]) == 1){
+                    $this->public = true;
+                }
             }
             }
-            $statement = $db->prepare("
+        }
+
+        private function load_defenses(){
+            $statement = get_context()->get_db()->prepare("
                 SELECT unit
                 SELECT unit
                 FROM defense
                 FROM defense
                 WHERE
                 WHERE
@@ -288,9 +185,9 @@
             $statement->bindValue(':area_type', AREA_TYPE_ID::ARENA, SQLITE3_INTEGER);
             $statement->bindValue(':area_type', AREA_TYPE_ID::ARENA, SQLITE3_INTEGER);
             $q = $statement->execute();
             $q = $statement->execute();
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->defense, new Unit($r["unit"], false));
+                array_push($this->arena_defense, new Unit($r["unit"], false));
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   unit,
                   unit,
                   position
                   position
@@ -312,7 +209,11 @@
                 }
                 }
             }
             }
             // TODO: Siege defenses
             // TODO: Siege defenses
-            $statement = $db->prepare("
+            $this->flag_defense = true;
+        }
+
+        private function load_buildings(){
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   building.id AS id,
                   building.id AS id,
                   min(building.buildable) AS min
                   min(building.buildable) AS min
@@ -321,7 +222,7 @@
                   buildable
                   buildable
                 WHERE
                 WHERE
                   player = :player AND
                   player = :player AND
-                  building.buildable = buildable.id 
+                  building.buildable = buildable.id
                 GROUP BY building.buildable;
                 GROUP BY building.buildable;
             ");
             ");
             $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
             $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
@@ -329,7 +230,7 @@
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->building, new Building($r["id"]));
                 array_push($this->building, new Building($r["id"]));
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT id
                 SELECT id
                 FROM decoration
                 FROM decoration
                 WHERE player = :player;
                 WHERE player = :player;
@@ -339,7 +240,11 @@
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->decoration, new Decoration($r["id"]));
                 array_push($this->decoration, new Decoration($r["id"]));
             }
             }
-            $statement = $db->prepare("
+            $this->flag_building = true;
+        }
+
+        private function load_items(){
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   id,
                   id,
                   type
                   type
@@ -357,7 +262,7 @@
                 array_push($this->item_scroll, new item($r["id"], $r["type"]));
                 array_push($this->item_scroll, new item($r["id"], $r["type"]));
             }
             }
             // Rune crafting items are marked as generic crafting.
             // Rune crafting items are marked as generic crafting.
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   id,
                   id,
                   type
                   type
@@ -374,7 +279,7 @@
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->item_craft_rune, new item($r["id"], $r["type"]));
                 array_push($this->item_craft_rune, new item($r["id"], $r["type"]));
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   id,
                   id,
                   type
                   type
@@ -391,7 +296,7 @@
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->item_craft, new item($r["id"], $r["type"]));
                 array_push($this->item_craft, new item($r["id"], $r["type"]));
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   item.id AS id,
                   item.id AS id,
                   item.type AS type
                   item.type AS type
@@ -422,7 +327,11 @@
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->item_essence, new item($r["id"], $r["type"]));
                 array_push($this->item_essence, new item($r["id"], $r["type"]));
             }
             }
-            $statement = $db->prepare("
+            $this->flag_item = true;
+        }
+
+        private function load_records(){
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   player,
                   player,
                   area_type,
                   area_type,
@@ -448,7 +357,7 @@
                     WHEN (area_type = 2 AND area = 4001) THEN 15 -- Hall of Wind
                     WHEN (area_type = 2 AND area = 4001) THEN 15 -- Hall of Wind
                     WHEN (area_type = 2 AND area = 7001) THEN 16 -- Hall of Light
                     WHEN (area_type = 2 AND area = 7001) THEN 16 -- Hall of Light
                     WHEN (area_type = 2 AND area = 1001) THEN 17 -- Hall of Dark
                     WHEN (area_type = 2 AND area = 1001) THEN 17 -- Hall of Dark
-                    ELSE area 
+                    ELSE area
                     END ASC
                     END ASC
             ");
             ");
             $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
             $statement->bindValue(':player', $this->id, SQLITE3_TEXT);
@@ -456,7 +365,323 @@
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->record, new Record($r["player"], $r["area_type"], $r["area"]));
                 array_push($this->record, new Record($r["player"], $r["area_type"], $r["area"]));
             }
             }
+            $this->flag_record = true;
+        }
+
+        /**
+         * Retrieves the player identifier
+         *
+         * @return int Plyaer ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+
+        /**
+         * Retrieves the player server.
+         *
+         * @return Server The player's account server.
+         */
+        public function get_server(){
+            return $this->server;
+        }
+
+        /**
+         * Retrieves the player's country.
+         *
+         * @return string Two digit country code.
+         */
+        public function get_country(){
+            return $this->country;
+        }
+
+        /**
+         * Retrieves the player's language.
+         *
+         * @return string Two digit language code.
+         */
+        public function get_language(){
+            return $this->language;
+        }
+
+        /**
+         * Retrieves the player's level,
+         *
+         * @return int Player's level
+         */
+        public function get_level(){
+            return $this->level;
+        }
+
+        /**
+         * Retrieves the player's name
+         *
+         * @return string The playe's name.
+         */
+        public function get_name(){
+            return $this->name;
+        }
+
+        /**
+         * Retrieves the total experience earned by the user.
+         *
+         * @return number Total experience.
+         */
+        public function get_experience(){
+            return $this->experience;
+        }
+
+        /**
+         * Retrieves the player's representative unit.
+         *
+         * @return Unit Player's representative
+         */
+        public function get_rep(){
+            if ($this->rep_id != null && $this->rep == null){
+                $this->rep = new Unit($this->rep_id);
+            }
+            return $this->rep;
+        }
+
+        /**
+         * Gets the date the user joined the game.
+         *
+         * If $format is supplied, a string in the desired format will be returned. If not, the raw
+         * DateTime object will e returned.
+         *
+         * @param string $format A date format (optional).
+         * @return DateTime | string The raw date, or a formatted version.
+         */
+        public function get_joined($format = null){
+            if (null == $format){
+                return $this->joined;
+            }
+            else{
+                return $this->joined->format($format);
+            }
+        }
+
+        /**
+         * Retrieves the user's top rank in the Arena.
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_arena(){
+            return $this->top_rank_arena;
+        }
+
+        /**
+         * Retrieves the user's top rank in the WorldArena.
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_world_arena(){
+            return $this->top_rank_world_arena;
+        }
+
+        /**
+         * Retrieves the user's top rank in the Arena.
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_special_league(){
+            return $this->top_rank_special_league;
+        }
+
+        /**
+         * Retrieves the user's top rank in Guild War.
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_gw(){
+            return $this->top_rank_gw;
+        }
+
+        /**
+         * Retrieves the user's top rank in Siege battle.
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_siege(){
+            return $this->top_rank_siege;
+        }
+
+        /**
+         * Retrieves the user's top rank in the World Boss.
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_wboss(){
+            return $this->top_rank_wboss;
+        }
+
+        /**
+         * Retrieves the user's top rank in the Trial of Ascension (normal difficulty).
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_toan(){
+            return $this->top_rank_toan;
+        }
+
+        /**
+         * Retrieves the user's top rank in the Trial of Ascension (hard difficulty).
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_toah(){
+            return $this->top_rank_toah;
+        }
+
+        /**
+         * Retrieves the user's top rank in the Trial of Ascension (hell difficulty).
+         *
+         * @return int Top rank.
+         */
+        public function get_top_rank_toal(){
+            return $this->top_rank_toal;
+        }
+
+        /**
+         * Retrieves the Arena defense units.
+         *
+         * @return \Unit[] Units in the arena defense.
+         */
+        public function get_arena_defense(){
+            if (!$this->flag_defense){
+                $this->load_defenses();
+            }
+            return $this->arena_defense;
         }
         }
 
 
+        /**
+         * Retrieves the Guild War defenses.
+         *
+         * @return Unit[][]: Units in Guild War defense, grouped by team.
+         */
+        public function get_gw_defense(){
+            if (!$this->flag_defense){
+                $this->load_defenses();
+            }
+            return $this->gw_defense;
+        }
+
+        /**
+         * Retrieves the Guild War defenses.
+         *
+         * @return Unit[][]: Units in Siege Battle defense, grouped by team.
+         */
+        public function get_siege_defense(){
+            if (!$this->flag_defense){
+                $this->load_defenses();
+            }
+            return $this->siege_defense;
+        }
+
+        /**
+         * Retrieves various currencies.
+         *
+         * @return int[] Array with the keys: mana, crystal, energy, energy_max, arena_energy,
+         * darkportal_energy, dimension_energy, honor_point, guild_point, honor_medal, honor_mark,
+         * event_coin, social_point, ancient_stone, costume_point,
+         */
+        public function get_currencies(){
+            return $this->currency;
+        }
+
+        /**
+         * Retrieves the list of buildings owned by the user.
+         *
+         * @return \Building[] Buildings owned.
+         */
+        public function get_buildings(){
+            if (!$this->flag_building){
+                $this->load_buildings();
+            }
+            return $this->building;
+        }
+
+        /**
+         * Retrieves the list of decorations owned by the user.
+         *
+         * @return \Decoration[] Owned decorations.
+         */
+        public function get_decorations(){
+            if (!$this->flag_building){
+                $this->load_buildings();
+            }
+            return $this->decoration;
+        }
+
+        /**
+         * Retrieves the list of owned scrolls.
+         *
+         * @return \Item[] Scrolls.
+         */
+        public function get_scrolls(){
+            if (!$this->flag_item){
+                $this->load_items();
+            }
+            return $this->item_scroll;
+        }
+
+        /**
+         * Retrieves the list of rune crafting mateials.
+         *
+         * @return \Item[] Rune craft materials.
+         */
+        public function get_rune_craft_materials(){
+            if (!$this->flag_item){
+                $this->load_items();
+            }
+            return $this->item_craft_rune;
+        }
+
+        /**
+         * Retrieves the list of crafting materials.
+         *
+         * @return \Item[] Crafting materials
+         */
+        public function get_craft_materials(){
+            if (!$this->flag_item){
+                $this->load_items();
+            }
+            return $this->item_craft;
+        }
+
+        /**
+         * Retrieves the list of essences owned by the player.
+         *
+         * @return \Item[] Essences.
+         */
+        public function get_essences(){
+            if (!$this->flag_item){
+                $this->load_items();
+            }
+            return $this->item_essence;
+        }
+
+        /**
+         * Retrieves the list of the player's records in the logbook.
+         *
+         * @return \Record[] List of records.
+         */
+        public function get_records(){
+            if (!$this->flag_record){
+                $this->load_records();
+            }
+            return $this->record;
+        }
+
+        /**
+         * Checks if the player profile is public.
+         *
+         * @return bool True for public profile, false otherwise.
+         */
+        public function is_public(){
+            return $this->public;
+        }
+
+
     }
     }
 ?>
 ?>

+ 4 - 7
application/entity/Record.php

@@ -81,13 +81,10 @@
          * @param int $player_id Selected player identifier.
          * @param int $player_id Selected player identifier.
          * @param int $area_type Area type identifier.
          * @param int $area_type Area type identifier.
          * @param int $area Area identifier.
          * @param int $area Area identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($player_id, $area_type, $area){
         public function __construct($player_id, $area_type, $area){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
                 SELECT
                 SELECT
                   player,
                   player,
                   area_type,
                   area_type,
@@ -102,7 +99,7 @@
                   area_type = :area_type AND
                   area_type = :area_type AND
                   area = :area;
                   area = :area;
             ");
             ");
-            $statement->bindValue(':player', $player_, SQLITE3_TEXT);
+            $statement->bindValue(':player', $player_id, SQLITE3_TEXT);
             $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
             $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
             $statement->bindValue(':area', $area, SQLITE3_TEXT);
             $statement->bindValue(':area', $area, SQLITE3_TEXT);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
@@ -113,7 +110,7 @@
                 $this->time = $r["time"];
                 $this->time = $r["time"];
                 $this->score = $r["score"];
                 $this->score = $r["score"];
                 $this->rank = $r["rank"];
                 $this->rank = $r["rank"];
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT
                     SELECT
                       unit,
                       unit,
                       monster,
                       monster,
@@ -129,7 +126,7 @@
                       front DESC,
                       front DESC,
                       leader DESC;
                       leader DESC;
                 ");
                 ");
-                $statement->bindValue(':player', $player, SQLITE3_TEXT);
+                $statement->bindValue(':player', $player_id, SQLITE3_TEXT);
                 $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
                 $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
                 $statement->bindValue(':area', $area, SQLITE3_TEXT);
                 $statement->bindValue(':area', $area, SQLITE3_TEXT);
                 $q = $statement->execute();
                 $q = $statement->execute();

+ 9 - 12
application/entity/Run.php

@@ -172,13 +172,10 @@
          * run, populating it and it's items.
          * run, populating it and it's items.
          *
          *
          * @param int $id Run identifier.
          * @param int $id Run identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 player,
                 player,
@@ -219,7 +216,7 @@
                 $this->helper = $r["helper"];
                 $this->helper = $r["helper"];
                 $this->score = $r["score"];
                 $this->score = $r["score"];
                 $this->rank = $r["rank"];
                 $this->rank = $r["rank"];
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT
                     SELECT
                       unit,
                       unit,
                       monster,
                       monster,
@@ -248,7 +245,7 @@
                         array_push($this->frontline, $r["unit"]);
                         array_push($this->frontline, $r["unit"]);
                     }
                     }
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT
                     SELECT
                       item,
                       item,
                       amount
                       amount
@@ -262,7 +259,7 @@
                     $i->amount =  $r["amount"];
                     $i->amount =  $r["amount"];
                     array_push($this->item, $i);
                     array_push($this->item, $i);
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT monster
                     SELECT monster
                     FROM run_drop_monster
                     FROM run_drop_monster
                     WHERE run = :run;
                     WHERE run = :run;
@@ -272,7 +269,7 @@
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                     array_push($this->monster, new Monster($r["monster"]));
                     array_push($this->monster, new Monster($r["monster"]));
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT monster
                     SELECT monster
                     FROM run_drop_sd
                     FROM run_drop_sd
                     WHERE run = :run;
                     WHERE run = :run;
@@ -282,7 +279,7 @@
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                     array_push($this->sd, new Monster($r["monster"]));
                     array_push($this->sd, new Monster($r["monster"]));
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT
                     SELECT
                       monster,
                       monster,
                       amount
                       amount
@@ -298,7 +295,7 @@
                     ];
                     ];
                     array_push($this->unit_piece, $i);
                     array_push($this->unit_piece, $i);
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT amount
                     SELECT amount
                     FROM run_drop_shapeshifting
                     FROM run_drop_shapeshifting
                     WHERE run = :run;
                     WHERE run = :run;
@@ -309,7 +306,7 @@
                 if ($r){
                 if ($r){
                     $this->shapeshifting = $r["amount"];
                     $this->shapeshifting = $r["amount"];
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT
                     SELECT
                       id,
                       id,
                       type,
                       type,
@@ -402,7 +399,7 @@
                     }
                     }
                     array_push($this->rune, $rune);
                     array_push($this->rune, $rune);
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT
                   SELECT
                     run_drop_enchantment.id AS id,
                     run_drop_enchantment.id AS id,
                     type,
                     type,

+ 6 - 10
application/entity/Rune.php

@@ -136,13 +136,10 @@
          * rune, populating it and it's items.
          * rune, populating it and it's items.
          *
          *
          * @param int $id Rune id.
          * @param int $id Rune id.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 type,
                 type,
@@ -176,7 +173,7 @@
                 $this->locked = $r["locked"];
                 $this->locked = $r["locked"];
 
 
                 // Get substats
                 // Get substats
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT slot
                   SELECT slot
                   FROM rune_stat
                   FROM rune_stat
                   WHERE rune = :rune
                   WHERE rune = :rune
@@ -204,7 +201,7 @@
                 if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
                 if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
                     $this->efficiency = $this->calculate_efficiency();
                     $this->efficiency = $this->calculate_efficiency();
                     $this->max_efficiency = $this->calculate_maximum_efficiency();
                     $this->max_efficiency = $this->calculate_maximum_efficiency();
-                    $statement = $db->prepare("
+                    $statement = get_context()->get_db()->prepare("
                       UPDATE rune
                       UPDATE rune
                       SET
                       SET
                         efficiency = :efficiency,
                         efficiency = :efficiency,
@@ -287,7 +284,6 @@
          * @return float Efficiency
          * @return float Efficiency
          */
          */
         private function calculate_efficiency(){
         private function calculate_efficiency(){
-            global $db;
             $eff = [0.0, 0.0, 0.0, 0.0, 0.0];
             $eff = [0.0, 0.0, 0.0, 0.0, 0.0];
 
 
             $query = "
             $query = "
@@ -309,7 +305,7 @@
             // Fixed stat 
             // Fixed stat 
             if ($this->innate_stat != null && $this->innate_stat->value > 0){
             if ($this->innate_stat != null && $this->innate_stat->value > 0){
                 $value = $this->innate_stat->value;
                 $value = $this->innate_stat->value;
-                $statement = $db->prepare($query);
+                $statement = get_context()->get_db()->prepare($query);
                 $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
                 $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
                 $statement->bindValue(':initial', 1, SQLITE3_TEXT);
                 $statement->bindValue(':initial', 1, SQLITE3_TEXT);
                 $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
                 $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
@@ -326,14 +322,14 @@
                 if (sizeof($this->stats) > $i && $this->stats[$i] != null && $this->stats[$i]->value > 0){
                 if (sizeof($this->stats) > $i && $this->stats[$i] != null && $this->stats[$i]->value > 0){
                     $value = $this->stats[$i]->value;
                     $value = $this->stats[$i]->value;
                     $value = $this->stats[$i]->value;
                     $value = $this->stats[$i]->value;
-                    $statement = $db->prepare($query);
+                    $statement = get_context()->get_db()->prepare($query);
                     $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
                     $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
                     $statement->bindValue(':initial', 1, SQLITE3_TEXT);
                     $statement->bindValue(':initial', 1, SQLITE3_TEXT);
                     $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
                     $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
                     $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
                     $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
                     $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
                     $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
                     $r_initial = $statement->execute()->fetchArray(SQLITE3_ASSOC);
                     $r_initial = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-                    $statement = $db->prepare($query);
+                    $statement = get_context()->get_db()->prepare($query);
                     $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
                     $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
                     $statement->bindValue(':initial', 0, SQLITE3_TEXT);
                     $statement->bindValue(':initial', 0, SQLITE3_TEXT);
                     $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
                     $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);

+ 1 - 4
application/entity/Rune_Set.php

@@ -48,13 +48,10 @@
          * set, populating it and it's items.
          * set, populating it and it's items.
          *
          *
          * @param int $id Set identifier.
          * @param int $id Set identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,

+ 1 - 4
application/entity/Rune_Stat.php

@@ -62,13 +62,10 @@
          * rune, populating it and it's items.
          * rune, populating it and it's items.
          *
          *
          * @param int $id Rune id.
          * @param int $id Rune id.
-         * @global resource Database connection.
          */
          */
         public function __construct($rune, $slot){
         public function __construct($rune, $slot){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 slot,
                 slot,
                 stat,
                 stat,

+ 1 - 4
application/entity/Server.php

@@ -38,13 +38,10 @@
          * server, populating it and it's items.
          * server, populating it and it's items.
          *
          *
          * @param int $id Server identifier.
          * @param int $id Server identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name
                 name

+ 3 - 6
application/entity/Skill.php

@@ -96,13 +96,10 @@
          * skill, populating it and it's items.
          * skill, populating it and it's items.
          *
          *
          * @param int $id Skill identifier.
          * @param int $id Skill identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,
@@ -130,7 +127,7 @@
                 $this->aoe = $r["aoe"];
                 $this->aoe = $r["aoe"];
                 $this->max_level = $r["max_level"];
                 $this->max_level = $r["max_level"];
                 $this->multiplier_formula = HTML::e($r["multiplier_formula"]);
                 $this->multiplier_formula = HTML::e($r["multiplier_formula"]);
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT
                   SELECT
                     skill,
                     skill,
                     level
                     level
@@ -143,7 +140,7 @@
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                     array_push($this->level, new Skill_Level($r["skill"], $r["level"]));
                     array_push($this->level, new Skill_Level($r["skill"], $r["level"]));
                 }
                 }
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                   SELECT DISTINCT effect
                   SELECT DISTINCT effect
                   FROM skill_effect
                   FROM skill_effect
                   WHERE skill = :skill;
                   WHERE skill = :skill;

+ 1 - 4
application/entity/Skill_Level.php

@@ -44,13 +44,10 @@
          *
          *
          * @param int $skill Skill identifier.
          * @param int $skill Skill identifier.
          * @param int $level Skill level.
          * @param int $level Skill level.
-         * @global resource Database connection.
          */
          */
         public function __construct($skill, $level){
         public function __construct($skill, $level){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 skill,
                 skill,
                 level,
                 level,

+ 1 - 3
application/entity/Source.php

@@ -49,11 +49,9 @@
          * source, populating it and it's items.
          * source, populating it and it's items.
          *
          *
          * @param int $id Surce identifier.
          * @param int $id Surce identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
-            global $db;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,

+ 3 - 6
application/entity/Team.php

@@ -58,7 +58,7 @@
         public $frontline = [];
         public $frontline = [];
 
 
         /**
         /**
-         * @var \K_Area Area the team is designed for.
+         * @var Area Area the team is designed for.
          */
          */
         public $area;
         public $area;
 
 
@@ -87,13 +87,10 @@
          *
          *
          * @param int $id Monster identifier.
          * @param int $id Monster identifier.
          * @param bool $complete If false, it won't load the units.
          * @param bool $complete If false, it won't load the units.
-         * @global resource Database connection.
          */
          */
         public function __construct($id, $complete = true){
         public function __construct($id, $complete = true){
 
 
-            global $db;
-
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 player,
                 player,
                 id,
                 id,
@@ -118,7 +115,7 @@
                 $this->stage = $r["stage"];
                 $this->stage = $r["stage"];
                 $this->score = $r["score"];
                 $this->score = $r["score"];
                 if ($complete){
                 if ($complete){
-                    $statement = $db->prepare("
+                    $statement = get_context()->get_db()->prepare("
                       SELECT
                       SELECT
                         unit,
                         unit,
                         leader,
                         leader,

+ 16 - 32
application/entity/Unit.php

@@ -367,16 +367,12 @@
          *
          *
          * @param int $id Monster identifier.
          * @param int $id Monster identifier.
          * @param bool $complete If false, query only unit and monster.
          * @param bool $complete If false, query only unit and monster.
-         * @global int Player ID.
-         * @global resource Database connection.
          */
          */
         public function __construct($id, $complete = true, $player = -1){
         public function __construct($id, $complete = true, $player = -1){
-            global $PLAYER;
-            global $db;
-            if ($player == -1 && isset($PLAYER->id) && null != $PLAYER){
-                $player = $PLAYER->id;
+            if ($player == -1 && null != get_context()->get_player()){
+                $player = get_context()->get_player()->get_id();
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 player,
                 player,
                 id,
                 id,
@@ -438,7 +434,7 @@
                     $this->load_teams();
                     $this->load_teams();
                     $this->check_storage();
                     $this->check_storage();
                     $this->lock = $r["lock"];
                     $this->lock = $r["lock"];
-                    $statement = $db->prepare("
+                    $statement = get_context()->get_db()->prepare("
                       SELECT level
                       SELECT level
                       FROM
                       FROM
                         unit_skill,
                         unit_skill,
@@ -453,7 +449,7 @@
                     while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                     while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                         array_push($this->skill_levels, $r["level"]);
                         array_push($this->skill_levels, $r["level"]);
                     }
                     }
-                    $statement = $db->prepare("
+                    $statement = get_context()->get_db()->prepare("
                       SELECT exp
                       SELECT exp
                       FROM experience
                       FROM experience
                       WHERE
                       WHERE
@@ -480,13 +476,9 @@
         /**
         /**
          * Checks if the monster is in storage and sets {@see $in_storage} to
          * Checks if the monster is in storage and sets {@see $in_storage} to
          * true or false.
          * true or false.
-         *
-         * @global Player Currently selected Player.
-         * @global resource Database connection.
          */
          */
         public function check_storage(){
         public function check_storage(){
-            global $db;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT 1
               SELECT 1
               FROM
               FROM
                 unit,
                 unit,
@@ -517,17 +509,12 @@
          *
          *
          * @gobal Player Currently selected player.
          * @gobal Player Currently selected player.
          * @gobal int Game mode (Normal/RTA).
          * @gobal int Game mode (Normal/RTA).
-         * @global resource Database connection.
          */
          */
         public function load_stats(){
         public function load_stats(){
 
 
-            global $PLAYER;
-            global $MODE;
-            global $db;
-
             // Runes
             // Runes
             $this->rune = [];
             $this->rune = [];
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT rune
               SELECT rune
               FROM unit_rune
               FROM unit_rune
               WHERE
               WHERE
@@ -535,7 +522,7 @@
                 rta = :rta;
                 rta = :rta;
             ");
             ");
             $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
             $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
-            $statement->bindValue(':rta', $MODE, SQLITE3_TEXT);
+            $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
             $q = $statement->execute();
             $q = $statement->execute();
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->rune, new Rune($r["rune"]));
                 array_push($this->rune, new Rune($r["rune"]));
@@ -551,7 +538,7 @@
 
 
             // Artifacts
             // Artifacts
             $this->artifact = [];
             $this->artifact = [];
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT artifact
               SELECT artifact
               FROM unit_artifact
               FROM unit_artifact
               WHERE
               WHERE
@@ -559,7 +546,7 @@
                 rta = :rta;
                 rta = :rta;
             ");
             ");
             $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
             $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
-            $statement->bindValue(':rta', $MODE, SQLITE3_TEXT);
+            $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
             $q = $statement->execute();
             $q = $statement->execute();
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $artifact = new Artifact($r["artifact"]);
                 $artifact = new Artifact($r["artifact"]);
@@ -569,21 +556,21 @@
                 else{
                 else{
                     $this->artifact_element = $artifact;
                     $this->artifact_element = $artifact;
                 }
                 }
-                switch($artifact->stat->stat){
+                switch($artifact->stat->getStat()){
                     case ARTIFACT_STAT_ID::ATK:
                     case ARTIFACT_STAT_ID::ATK:
-                        $this->artifact_attack += $artifact->stat->value;
+                        $this->artifact_attack += $artifact->stat->getValue();
                         break;
                         break;
                     case ARTIFACT_STAT_ID::DEF:
                     case ARTIFACT_STAT_ID::DEF:
-                        $this->artifact_defense += $artifact->stat->value;
+                        $this->artifact_defense += $artifact->stat->getValue();
                         break;
                         break;
                     case ARTIFACT_STAT_ID::HP:
                     case ARTIFACT_STAT_ID::HP:
-                        $this->artifact_hp += $artifact->stat->value;
+                        $this->artifact_hp += $artifact->stat->getValue();
                         break;
                         break;
                 }
                 }
             }
             }
 
 
             // Buildings
             // Buildings
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 affected_stat,
                 affected_stat,
                 bonus,
                 bonus,
@@ -672,13 +659,10 @@
 
 
         /**
         /**
          * Loads the {@see teams} array, with the teams the unit is on.
          * Loads the {@see teams} array, with the teams the unit is on.
-         *
-         * @global resource Database connection.
          */
          */
         public function load_teams(){
         public function load_teams(){
-            global $db;
             $this->teams = [];
             $this->teams = [];
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT DISTINCT team.id AS id
               SELECT DISTINCT team.id AS id
               FROM
               FROM
                 team,
                 team,

+ 2 - 4
application/entity/User.php

@@ -59,11 +59,9 @@
          * user, populating it and it's items.
          * user, populating it and it's items.
          *
          *
          * @param int $id User identifier.
          * @param int $id User identifier.
-         * @global resource Database connection.
          */
          */
         public function __construct($id){
         public function __construct($id){
-            global $db;
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT
               SELECT
                 id,
                 id,
                 name,
                 name,
@@ -83,7 +81,7 @@
                 $this->admin = $r["admin"];
                 $this->admin = $r["admin"];
 
 
                 // Get all accounts
                 // Get all accounts
-                $statement = $db->prepare("
+                $statement = get_context()->get_db()->prepare("
                     SELECT id
                     SELECT id
                     FROM player
                     FROM player
                     WHERE user = :user
                     WHERE user = :user

+ 3 - 15
application/page/Artifacts_Page.php

@@ -30,24 +30,16 @@
          */
          */
         public $artifacts = [];
         public $artifacts = [];
 
 
-        /**
-         * @var \Filter[] Custom filters for this page.
-         */
-        public $custom_filters = [];
-
         /**
         /**
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
             $this->view = PATH::VIEW . "artifacts.php";
             $this->view = PATH::VIEW . "artifacts.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $artifact = new Artifact($r["id"]);
                 $artifact = new Artifact($r["id"]);
                 if ($r["unit"]){
                 if ($r["unit"]){
@@ -113,12 +105,8 @@
          * filters.
          * filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currently selected player.
-         * @global int Game mode
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
-            global $MODE;
             $s = "
             $s = "
               SELECT
               SELECT
                 id,
                 id,
@@ -127,11 +115,11 @@
                   FROM unit_artifact
                   FROM unit_artifact
                   WHERE
                   WHERE
                     artifact = artifact.id AND
                     artifact = artifact.id AND
-                    rta = $MODE
+                    rta = " . get_context()->get_game_mode() . "
                 ) AS unit
                 ) AS unit
               FROM artifact artifact
               FROM artifact artifact
               WHERE
               WHERE
-                player = '" . $PLAYER->id . "' AND
+                player = '" . get_context()->get_player()->get_id() . "' AND
                 level >= " . $this->filters["MIN_LEVEL"] . " AND 
                 level >= " . $this->filters["MIN_LEVEL"] . " AND 
                 level <= " . $this->filters["MAX_LEVEL"] . " AND
                 level <= " . $this->filters["MAX_LEVEL"] . " AND
                 quality >= " . $this->filters["MIN_QUALITY"] . " AND
                 quality >= " . $this->filters["MIN_QUALITY"] . " AND

+ 2 - 7
application/page/Enchantments_Page.php

@@ -35,15 +35,12 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
             $this->view = PATH::VIEW . "enchantments.php";
             $this->view = PATH::VIEW . "enchantments.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $enchantment = new Enchantment($r["id"]);
                 $enchantment = new Enchantment($r["id"]);
                 //if ($enchantment->gem == true){
                 //if ($enchantment->gem == true){
@@ -120,15 +117,13 @@
          * filters.
          * filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currently selected player.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
             $s = "
             $s = "
               SELECT id
               SELECT id
               FROM enchantment
               FROM enchantment
               WHERE
               WHERE
-                player = '" . $PLAYER->id . "' AND
+                player = '" . get_context()->get_player()->get_id() . "' AND
                 quality >= " . $this->filters["MIN_QUALITY"] . " AND
                 quality >= " . $this->filters["MIN_QUALITY"] . " AND
                 quality <= " . $this->filters["MAX_QUALITY"] . "
                 quality <= " . $this->filters["MAX_QUALITY"] . "
             ";
             ";

+ 3 - 8
application/page/Guild_Page.php

@@ -35,20 +35,15 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global Player Currenty selected player.
-         * @global resource Connection to the database.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $PLAYER;
-            global $db;
             $this->view = PATH::VIEW . "guild.php";
             $this->view = PATH::VIEW . "guild.php";
             $s = "
             $s = "
               SELECT id
               SELECT id
               FROM guild
               FROM guild
-              WHERE id = (SELECT guild FROM guild_member WHERE member = '" . $PLAYER->id . "');
+              WHERE id = (SELECT guild FROM guild_member WHERE member = '" . get_context()->get_player()->get_id() . "');
             ";
             ";
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             if ($r){
             if ($r){
                 $guild_id =  $r["id"];
                 $guild_id =  $r["id"];
@@ -60,7 +55,7 @@
                   FROM guild_skill_group
                   FROM guild_skill_group
                   ORDER BY id;
                   ORDER BY id;
                 ";
                 ";
-                $q = $db->query($s);
+                $q = get_context()->get_db()->query($s);
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                     array_push($this->skill_groups, new Guild_Skill_Group($r["id"]));
                     array_push($this->skill_groups, new Guild_Skill_Group($r["id"]));
                 }
                 }

+ 3 - 6
application/page/Home_Page.php

@@ -30,15 +30,12 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global int Player ID.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $PLAYER;
-            $this->player = $PLAYER;
+            $this->player = get_context()->get_player();
             $this->view = PATH::VIEW . "home.php";
             $this->view = PATH::VIEW . "home.php";
-            $this->title = $this->player->name . " - SWDB";
-            $this->description = $this->player->name . " - Summoners War DataBase";
+            $this->title = get_context()->get_player()->get_name() . " - SWDB";
+            $this->description = get_context()->get_player()->get_name() . " - Summoners War DataBase";
             $this->canonical = URL::BASE;
             $this->canonical = URL::BASE;
         }
         }
     }
     }

+ 4 - 9
application/page/Catalog_Page.php → application/page/Monsters_Page.php

@@ -19,7 +19,7 @@
      *
      *
      * @category Page
      * @category Page
      */
      */
-    class Catalog_Page extends Page{
+    class Monsters_Page extends Page{
 
 
         /**
         /**
          * @var \Monster[] List of monsters to show.
          * @var \Monster[] List of monsters to show.
@@ -45,17 +45,12 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global resource Connection to the database.
-         * @global Player Currently selected player.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
-            global $PLAYER;
             $this->view = PATH::VIEW . "catalog.php";
             $this->view = PATH::VIEW . "catalog.php";
             $this->parse_filters();
             $this->parse_filters();
             $s_mon = $this->build_query();
             $s_mon = $this->build_query();
-            $q_mon = $db->query($s_mon);
+            $q_mon = get_context()->get_db()->query($s_mon);
             while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
             while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->monsters, new Monster($r_mon["id"], false));
                 array_push($this->monsters, new Monster($r_mon["id"], false));
             }
             }
@@ -63,10 +58,10 @@
               SELECT monster
               SELECT monster
               FROM collection
               FROM collection
               WHERE
               WHERE
-                player = " . $PLAYER->id . " AND
+                player = " . get_context()->get_player()->get_id() . " AND
                 open = 1
                 open = 1
             ";
             ";
-            $q_open = $db->query($s_open);
+            $q_open = get_context()->get_db()->query($s_open);
             while ($r_open = $q_open->fetchArray(SQLITE3_ASSOC)){
             while ($r_open = $q_open->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->monsters_open, $r_open["monster"]);
                 array_push($this->monsters_open, $r_open["monster"]);
             }
             }

+ 3 - 10
application/page/Optimizer_Page.php

@@ -29,23 +29,18 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global Player Currently selected player.
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $PLAYER;
-            global $db;
             $this->view = PATH::VIEW . "optimizer.php";
             $this->view = PATH::VIEW . "optimizer.php";
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->teams, new Team($r["id"]));
                 array_push($this->teams, new Team($r["id"]));
             }
             }
             $s = "
             $s = "
               SELECT id
               SELECT id
               FROM unit
               FROM unit
-              WHERE player = '" . $PLAYER->id . "';
+              WHERE player = '" . get_context()->get_player()->get_id() . "';
             ";
             ";
             $this->title = "Optmizer - SWDB";
             $this->title = "Optmizer - SWDB";
             $this->description = "Optimizer";
             $this->description = "Optimizer";
@@ -57,14 +52,12 @@
          * filters.
          * filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currently selected player.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
             $s = "
             $s = "
               SELECT id
               SELECT id
               FROM team
               FROM team
-              WHERE player = '" . $PLAYER->id . "'
+              WHERE player = '" . get_context()->get_player()->get_id() . "'
               ORDER BY
               ORDER BY
                 area_type,
                 area_type,
                 area
                 area

+ 2 - 7
application/page/Profile_Page.php

@@ -39,13 +39,8 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global User Logged-in user.
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $USER;
-            global $db;
             $this->view = PATH::VIEW . "profile.php";
             $this->view = PATH::VIEW . "profile.php";
             $s = "
             $s = "
               SELECT
               SELECT
@@ -53,9 +48,9 @@
                 mail,
                 mail,
                 api_key
                 api_key
               FROM user
               FROM user
-              WHERE id = '" . $USER->id . "';
+              WHERE id = '" . get_context()->get_user()->id . "';
             ";
             ";
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             if ($r = $q->fetchArray(SQLITE3_ASSOC)){
             if ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $this->name = $r["name"];
                 $this->name = $r["name"];
                 $this->mail = $r["mail"];
                 $this->mail = $r["mail"];

+ 5 - 13
application/page/Report_Rune_Enchantment_Page.php

@@ -96,15 +96,12 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
             $this->view = PATH::VIEW . "report_rune_enchantment.php";
             $this->view = PATH::VIEW . "report_rune_enchantment.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             $prev_monster = "";
             $prev_monster = "";
             $prev_rune = "";
             $prev_rune = "";
             $upgrade = null;
             $upgrade = null;
@@ -248,13 +245,8 @@
          * Builds the query for the page, using the providded or default filters.
          * Builds the query for the page, using the providded or default filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currently selected player.
-         * @global int Game mode.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
-            global $MODE;
-
             $s = "
             $s = "
               SELECT DISTINCT
               SELECT DISTINCT
                 unit.id AS unit,
                 unit.id AS unit,
@@ -268,12 +260,12 @@
                 enchantment,
                 enchantment,
                 enchantment_type
                 enchantment_type
               WHERE
               WHERE
-                unit.player = '" . $PLAYER->id . "'
-                AND rune.player = '" . $PLAYER->id . "'
-                AND enchantment.player = '" . $PLAYER->id . "'
+                unit.player = '" . get_context()->get_player()->get_id() . "'
+                AND rune.player = '" . get_context()->get_player()->get_id() . "'
+                AND enchantment.player = '" . get_context()->get_player()->get_id() . "'
                 AND unit.id = unit_rune.unit
                 AND unit.id = unit_rune.unit
                 AND rune.id = unit_rune.rune
                 AND rune.id = unit_rune.rune
-                AND unit_rune.rta = $MODE
+                AND unit_rune.rta = " . get_context()->get_game_mode() . "
                 AND unit.monster = monster.id
                 AND unit.monster = monster.id
                 AND enchantment.type = enchantment_type.id
                 AND enchantment.type = enchantment_type.id
                 -- RUNE FILTERS
                 -- RUNE FILTERS

+ 5 - 12
application/page/Report_Skillup_Page.php

@@ -47,15 +47,12 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
             $this->view = PATH::VIEW . "report_skillup.php";
             $this->view = PATH::VIEW . "report_skillup.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->units, new Unit($r["id"]));
                 array_push($this->units, new Unit($r["id"]));
             }
             }
@@ -123,12 +120,8 @@
          * filters.
          * filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currenty selected player.
-         * @global int Game mode.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
-            global $MODE;
             $s = "
             $s = "
               SELECT DISTINCT
               SELECT DISTINCT
                 unit.id AS id,
                 unit.id AS id,
@@ -161,7 +154,7 @@
                 monster_skill,
                 monster_skill,
                 skill
                 skill
               WHERE
               WHERE
-                unit.player = '" . $PLAYER->id . "' AND
+                unit.player = '" . get_context()->get_player()->get_id() . "' AND
                 unit.monster = monster.id AND
                 unit.monster = monster.id AND
                 unit_skill.unit = unit.id AND ";
                 unit_skill.unit = unit.id AND ";
             switch ($this->filters["UNIT"]){
             switch ($this->filters["UNIT"]){
@@ -177,7 +170,7 @@
                             team_unit
                             team_unit
                           WHERE
                           WHERE
                             team.id = team_unit.team AND
                             team.id = team_unit.team AND
-                            team.player = '" . $PLAYER->id . "'
+                            team.player = '" . get_context()->get_player()->get_id() . "'
                         )
                         )
                       ) AND ";
                       ) AND ";
                     break;
                     break;
@@ -191,7 +184,7 @@
                             team_unit
                             team_unit
                           WHERE
                           WHERE
                             team.id = team_unit.team AND
                             team.id = team_unit.team AND
-                            team.player = '" . $PLAYER->id . "' AND
+                            team.player = '" . get_context()->get_player()->get_id() . "' AND
                             team.score > 0
                             team.score > 0
                         )
                         )
                       ) AND ";
                       ) AND ";
@@ -251,7 +244,7 @@
                 $s = $s . " AND unit.building <> " . BUILDING_ID::MONSTER_STORAGE;
                 $s = $s . " AND unit.building <> " . BUILDING_ID::MONSTER_STORAGE;
             }
             }
             if (!$this->filters["WITHOUT_RUNES"]){
             if (!$this->filters["WITHOUT_RUNES"]){
-                $s = $s . " AND unit.id IN (SELECT DISTINCT unit FROM unit_rune WHERE rta = $MODE) ";
+                $s = $s . " AND unit.id IN (SELECT DISTINCT unit FROM unit_rune WHERE rta = " . get_context()->get_game_mode() . ") ";
             }
             }
             if (!$this->filters["FAMILY"]){
             if (!$this->filters["FAMILY"]){
                 $s = $s . " AND unit.monster NOT IN (SELECT id FROM monster m WHERE family IN (SELECT family FROM monster k WHERE k.family = m.family AND k.natural_stars < m.natural_stars AND k.natural_stars < " . $this->filters["MIN_NATURAL_STARS"] . ")) ";
                 $s = $s . " AND unit.monster NOT IN (SELECT id FROM monster m WHERE family IN (SELECT family FROM monster k WHERE k.family = m.family AND k.natural_stars < m.natural_stars AND k.natural_stars < " . $this->filters["MIN_NATURAL_STARS"] . ")) ";

+ 3 - 11
application/page/Runes_Page.php

@@ -58,17 +58,13 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global int Player ID.
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
             $this->view = PATH::VIEW . "runes.php";
             $this->view = PATH::VIEW . "runes.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
             $this->filters["GROUP"] = 1;
             $this->filters["GROUP"] = 1;
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $rune = new Rune($r["id"]);
                 $rune = new Rune($r["id"]);
                 if ($r["unit"]){
                 if ($r["unit"]){
@@ -161,12 +157,8 @@
          * filters.
          * filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Curently sleected player.
-         * @global int Game mode.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
-            global $MODE;
             $s = "
             $s = "
               SELECT
               SELECT
                 id,
                 id,
@@ -175,12 +167,12 @@
                   FROM unit_rune
                   FROM unit_rune
                   WHERE
                   WHERE
                     rune = rune.id AND
                     rune = rune.id AND
-                    rta = $MODE
+                    rta = " . get_context()->get_game_mode() . "
                 ) AS unit
                 ) AS unit
               FROM
               FROM
                 rune rune
                 rune rune
               WHERE
               WHERE
-                player = '" . $PLAYER->id . "' AND
+                player = '" . get_context()->get_player()->get_id() . "' AND
                 stars >= " . $this->filters["MIN_STARS"] . " AND
                 stars >= " . $this->filters["MIN_STARS"] . " AND
                 stars <= " . $this->filters["MAX_STARS"] . " AND
                 stars <= " . $this->filters["MAX_STARS"] . " AND
                 level >= " . $this->filters["MIN_LEVEL"] . " AND
                 level >= " . $this->filters["MIN_LEVEL"] . " AND

+ 2 - 7
application/page/Runs_Page.php

@@ -29,15 +29,12 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
             $this->view = PATH::VIEW . "runs.php";
             $this->view = PATH::VIEW . "runs.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->runs, new Run($r["id"]));
                 array_push($this->runs, new Run($r["id"]));
             }
             }
@@ -93,14 +90,12 @@
          * filters.
          * filters.
          * 
          * 
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currently selected player.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
             $s = "
             $s = "
                 SELECT id
                 SELECT id
                 FROM run
                 FROM run
-                WHERE player = '" . $PLAYER->id . "'
+                WHERE player = '" . get_context()->get_player()->get_id() . "'
              ";
              ";
             if ($this->filters["AREA_TYPE"] > 0){
             if ($this->filters["AREA_TYPE"] > 0){
                 $s = $s . " AND area_type =  " . $this->filters["AREA_TYPE"] . " ";
                 $s = $s . " AND area_type =  " . $this->filters["AREA_TYPE"] . " ";

+ 13 - 18
application/page/Stats_Page.php

@@ -83,13 +83,8 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global Player Currently selected player.
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $PLAYER;
-            global $db;
             $this->view = PATH::VIEW . "stats.php";
             $this->view = PATH::VIEW . "stats.php";
             $this->title = "Stats - SWDB";
             $this->title = "Stats - SWDB";
             $this->description = "Player statistics";
             $this->description = "Player statistics";
@@ -105,7 +100,7 @@
 
 
             // Build query modifier:
             // Build query modifier:
             $query_where = "
             $query_where = "
-              run.player = '" . $PLAYER->id . "' AND
+              run.player = '" . get_context()->get_player()->get_id() . "' AND
               run.area = " . $this->filters["AREA"] . "
               run.area = " . $this->filters["AREA"] . "
             ";
             ";
             if ($this->filters["STAGE"] > 0){
             if ($this->filters["STAGE"] > 0){
@@ -127,7 +122,7 @@
               ORDER BY time DESC
               ORDER BY time DESC
               LIMIT 1;
               LIMIT 1;
             ";
             ";
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             if ($r = $q->fetchArray(SQLITE3_ASSOC)){
             if ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $this->best_run = new Run($r["id"]);
                 $this->best_run = new Run($r["id"]);
             }
             }
@@ -138,21 +133,21 @@
                 (SELECT COUNT(win) FROM run WHERE $query_where AND win = 1 ) AS win,
                 (SELECT COUNT(win) FROM run WHERE $query_where AND win = 1 ) AS win,
                 (SELECT COUNT(win) FROM run WHERE $query_where AND win = 0) AS lose;
                 (SELECT COUNT(win) FROM run WHERE $query_where AND win = 0) AS lose;
             ";
             ";
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             $this->win_lose = [$r["win"], $r["lose"]];
             $this->win_lose = [$r["win"], $r["lose"]];
 
 
             // Drop type rate
             // Drop type rate
             $s = "
             $s = "
               SELECT
               SELECT
-                (SELECT COUNT(run) FROM run run, run_drop_rune run_drop_rune WHERE $query_where AND run.id = run_drop_rune.run AND player = '" . $PLAYER->id . "') AS rune,
-                (SELECT COUNT(run) FROM run run, run_drop_rune_craft run_drop_rune_craft WHERE $query_where AND run.id = run_drop_rune_craft.run AND player = '" . $PLAYER->id . "') AS rune_craft,
-                (SELECT COUNT(run) FROM run run, run_drop_item run_drop_item WHERE $query_where AND run.id = run_drop_item.run AND player = '" . $PLAYER->id . "') AS item,
-                (SELECT COUNT(run) FROM run run, run_drop_sd run_drop_sd WHERE $query_where AND run.id = run_drop_sd.run AND player = '" . $PLAYER->id . "') AS sd,
-                (SELECT COUNT(run) FROM run run, run_drop_shapeshifting run_drop_shapeshifting WHERE $query_where AND run.id = run_drop_shapeshifting.run AND player = '" . $PLAYER->id . "') AS shapeshifting,
-                (SELECT COUNT(run) run run, run_drop_unit run_drop_unit WHERE $query_where AND run.id = run_drop_unit.run AND player = '" . $PLAYER->id . "') AS unit;
+                (SELECT COUNT(run) FROM run run, run_drop_rune run_drop_rune WHERE $query_where AND run.id = run_drop_rune.run AND player = '" . get_context()->get_player()->get_id() . "') AS rune,
+                (SELECT COUNT(run) FROM run run, run_drop_rune_craft run_drop_rune_craft WHERE $query_where AND run.id = run_drop_rune_craft.run AND player = '" . get_context()->get_player()->get_id() . "') AS rune_craft,
+                (SELECT COUNT(run) FROM run run, run_drop_item run_drop_item WHERE $query_where AND run.id = run_drop_item.run AND player = '" . get_context()->get_player()->get_id() . "') AS item,
+                (SELECT COUNT(run) FROM run run, run_drop_sd run_drop_sd WHERE $query_where AND run.id = run_drop_sd.run AND player = '" . get_context()->get_player()->get_id() . "') AS sd,
+                (SELECT COUNT(run) FROM run run, run_drop_shapeshifting run_drop_shapeshifting WHERE $query_where AND run.id = run_drop_shapeshifting.run AND player = '" . get_context()->get_player()->get_id() . "') AS shapeshifting,
+                (SELECT COUNT(run) run run, run_drop_unit run_drop_unit WHERE $query_where AND run.id = run_drop_unit.run AND player = '" . get_context()->get_player()->get_id() . "') AS unit;
             ";
             ";
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             $this->drop_type["rune"] = $r["rune"];
             $this->drop_type["rune"] = $r["rune"];
             $this->drop_type["rune_craft"] = $r["rune_craft"];
             $this->drop_type["rune_craft"] = $r["rune_craft"];
@@ -175,7 +170,7 @@
               GROUP BY slot
               GROUP BY slot
               ORDER BY slot;
               ORDER BY slot;
             ";
             ";
-            $q = $db->query($s);
+                $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $this->drop_rune_slot[$r["slot"]] = $r["count"];
                 $this->drop_rune_slot[$r["slot"]] = $r["count"];
             }
             }
@@ -194,7 +189,7 @@
               GROUP BY stars
               GROUP BY stars
               ORDER BY stars DESC;
               ORDER BY stars DESC;
             ";
             ";
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $this->drop_rune_stars[strval($r["stars"])] = $r["count"];
                 $this->drop_rune_stars[strval($r["stars"])] = $r["count"];
             }
             }
@@ -213,7 +208,7 @@
               GROUP BY quality
               GROUP BY quality
               ORDER BY quality DESC;
               ORDER BY quality DESC;
             ";
             ";
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $this->drop_rune_quality[strval($r["quality"])] = $r["count"];
                 $this->drop_rune_quality[strval($r["quality"])] = $r["count"];
             }
             }

+ 4 - 11
application/page/Teams_Page.php

@@ -35,26 +35,21 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global Player Currently selected player.
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $PLAYER;
-            global $db;
             $this->view = PATH::VIEW . "teams.php";
             $this->view = PATH::VIEW . "teams.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->teams, new Team($r["id"]));
                 array_push($this->teams, new Team($r["id"]));
             }
             }
-            $statement = $db->prepare("
+            $statement = get_context()->get_db()->prepare("
               SELECT id
               SELECT id
               FROM unit
               FROM unit
               WHERE player = :player;
               WHERE player = :player;
             ");
             ");
-            $statement->bindValue(':player', $PLAYER->id, SQLITE3_TEXT);
+            $statement->bindValue(':player', get_context()->get_player()->get_id(), SQLITE3_TEXT);
             $q = $statement->execute();
             $q = $statement->execute();
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->units, new Unit($r["id"], false));
                 array_push($this->units, new Unit($r["id"], false));
@@ -84,14 +79,12 @@
          * filters.
          * filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currently selected player.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
             $s = "
             $s = "
               SELECT id
               SELECT id
               FROM team
               FROM team
-              WHERE player = '" . $PLAYER->id . "'
+              WHERE player = '" . get_context()->get_player()->get_id() . "'
               ORDER BY
               ORDER BY
                 area_type,
                 area_type,
                 area
                 area

+ 3 - 8
application/page/Units_Page.php

@@ -49,21 +49,18 @@
          * Constructor.
          * Constructor.
          *
          *
          * Retrieves the data and initializes the variables.
          * Retrieves the data and initializes the variables.
-         *
-         * @global resource Database connection.
          */
          */
         public function __construct(){
         public function __construct(){
-            global $db;
             $this->view = PATH::VIEW . "units.php";
             $this->view = PATH::VIEW . "units.php";
             $this->parse_filters();
             $this->parse_filters();
             $s = $this->build_query();
             $s = $this->build_query();
-            $q = $db->query($s);
+            $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->units, new Unit($r["id"]));
                 array_push($this->units, new Unit($r["id"]));
             }
             }
             // Get skill effects
             // Get skill effects
             $s_eff = "SELECT id FROM effect ORDER BY is_buff DESC";
             $s_eff = "SELECT id FROM effect ORDER BY is_buff DESC";
-            $q_eff = $db->query($s_eff);
+            $q_eff = get_context()->get_db()->query($s_eff);
             while ($r_eff = $q_eff->fetchArray(SQLITE3_ASSOC)){
             while ($r_eff = $q_eff->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->effects, new Effect($r_eff["id"]));
                 array_push($this->effects, new Effect($r_eff["id"]));
             }
             }
@@ -117,17 +114,15 @@
          * filters.
          * filters.
          *
          *
          * @return string The query to be executed.
          * @return string The query to be executed.
-         * @global Player Currently selected player.
          */
          */
         private function build_query(){
         private function build_query(){
-            global $PLAYER;
             $s = "
             $s = "
                 SELECT unit.id AS id
                 SELECT unit.id AS id
                 FROM
                 FROM
                   unit,
                   unit,
                   monster
                   monster
                 WHERE
                 WHERE
-                  unit.player = '" . $PLAYER->id . "' AND
+                  unit.player = '" . get_context()->get_player()->get_id() . "' AND
                   unit.monster = monster.id AND 
                   unit.monster = monster.id AND 
                   stars >= " . $this->filters["MIN_STARS"] . " AND 
                   stars >= " . $this->filters["MIN_STARS"] . " AND 
                   stars <= " . $this->filters["MAX_STARS"];
                   stars <= " . $this->filters["MAX_STARS"];

+ 4 - 3
application/view/artifacts.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Artifacts_Page $page The page model.
      * @var Artifacts_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -56,7 +57,7 @@
             <p>
             <p>
                 Manage your enchantments
                 Manage your enchantments
             </p>
             </p>
-            <form action='/<?=$PLAYER->id?>/artifacts/' method='get' id='filter_artifacts' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/artifacts/' method='get' id='filter_artifacts' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='label'>
                         <td class='label'>

+ 6 - 5
application/view/catalog.php

@@ -5,8 +5,9 @@
      * Contains the view layout and some code to present the data
      * Contains the view layout and some code to present the data
      *
      *
      * @category View
      * @category View
-     * @var Catalog_Page $page The page model
-     * @var player $PLAYER Currently selected player.
+     * @var Monsters_Page $page The page model
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -57,7 +58,7 @@
             <p>
             <p>
                 A list with every monster in the game.
                 A list with every monster in the game.
             </p>
             </p>
-            <form action='/<?=$PLAYER->id?>/catalog/' method='get' id='filter_catalog' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/catalog/' method='get' id='filter_catalog' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='label'>
                         <td class='label'>
@@ -127,7 +128,7 @@
                         }
                         }
 ?>
 ?>
                         <div class='monster <?=$closed?>'>
                         <div class='monster <?=$closed?>'>
-                            <a href='/<?=$PLAYER->id?>/catalog/<?=$mon->id?>'>
+                            <a href='/<?=get_context()->get_player()->get_id()?>/catalog/<?=$mon->id?>'>
                                 <div class='monster_panel'>
                                 <div class='monster_panel'>
                                     <?=HTML::unit_panel($mon)?>
                                     <?=HTML::unit_panel($mon)?>
                                 </div>
                                 </div>

+ 4 - 3
application/view/enchantments.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Artifacts_Page $page The page model.
      * @var Artifacts_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -93,7 +94,7 @@
             <p>
             <p>
                 Manage your enchantments
                 Manage your enchantments
             </p>
             </p>
-            <form action='/<?=$PLAYER->id?>/enchantments/' method='get' id='filter_artifacts' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/enchantments/' method='get' id='filter_artifacts' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='label'>
                         <td class='label'>

+ 2 - 1
application/view/error.php

@@ -6,6 +6,7 @@
      *
      *
      * @category View
      * @category View
      * @var Landing_Page $page The page model.
      * @var Landing_Page $page The page model.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -18,7 +19,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php

+ 2 - 1
application/view/guild.php

@@ -6,6 +6,7 @@
      *
      *
      * @category View
      * @category View
      * @var Guild_Page $page The page model.
      * @var Guild_Page $page The page model.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -18,7 +19,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php

+ 2 - 1
application/view/help.php

@@ -6,6 +6,7 @@
      *
      *
      * @category View
      * @category View
      * @var Page $page The page model.
      * @var Page $page The page model.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
     // TODO: Implement
     // TODO: Implement
 ?>
 ?>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php

+ 50 - 47
application/view/home.php

@@ -6,8 +6,9 @@
      *
      *
      * @category View
      * @category View
      * @var Home_Page $page The page model.
      * @var Home_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
      * @var int[] $EFFECT_AREA Required constants.
      * @var int[] $EFFECT_AREA Required constants.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -20,7 +21,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -52,10 +53,10 @@
 ?>
 ?>
         <aside>
         <aside>
             <h2>
             <h2>
-                <?=$page->player->name?>
+                <?=get_context()->get_player()->get_name()?>
             </h2>
             </h2>
             <p>
             <p>
-                <?=$page->player->name?>'s profile
+                <?=get_context()->get_player()->get_name()?>'s profile
             </p>
             </p>
             <table id='profile'>
             <table id='profile'>
                 <tr>
                 <tr>
@@ -63,7 +64,7 @@
                         Lv.
                         Lv.
                     </td>
                     </td>
                     <td class='value'>
                     <td class='value'>
-                        <?=$page->player->level?>
+                        <?=get_context()->get_player()->get_level()?>
                     </td>
                     </td>
                 </tr>
                 </tr>
                 <tr>
                 <tr>
@@ -71,7 +72,7 @@
                         Exp.
                         Exp.
                     </td>
                     </td>
                     <td class='value'>
                     <td class='value'>
-                        <?=$page->player->experience?>
+                        <?=get_context()->get_player()->get_experience()?>
                     </td>
                     </td>
                 </tr>
                 </tr>
                 <tr>
                 <tr>
@@ -79,7 +80,7 @@
                         Country
                         Country
                     </td>
                     </td>
                     <td class='value'>
                     <td class='value'>
-                        <?=$page->player->country?>
+                        <?=get_context()->get_player()->get_country()?>
                     </td>
                     </td>
                 </tr>
                 </tr>
                 <tr>
                 <tr>
@@ -87,7 +88,7 @@
                         Since
                         Since
                     </td>
                     </td>
                     <td class='value'>
                     <td class='value'>
-                        <?=date('Y-m-d', $page->player->joined)?>
+                        <?=get_context()->get_player()->get_joined('Y-m-d')?>
                     </td>
                     </td>
                 </tr>
                 </tr>
                 <tr>
                 <tr>
@@ -95,7 +96,7 @@
                         Days
                         Days
                     </td>
                     </td>
                     <td class='value'>
                     <td class='value'>
-                        <?=round((time() - $page->player->joined) / (60 * 60 * 24))?>
+                        <?=round((time() - get_context()->get_player()->get_joined('U')) / (60 * 60 * 24))?>
                     </td>
                     </td>
                 </tr>
                 </tr>
             </table>
             </table>
@@ -118,7 +119,7 @@
                                     Rep monster:
                                     Rep monster:
                                 </h5>
                                 </h5>
                                 <div class='monster_panel'>
                                 <div class='monster_panel'>
-                                    <?=HTML::unit_panel($page->player->rep)?>
+                                    <?=HTML::unit_panel(get_context()->get_player()->get_rep())?>
                                 </div> <!-- .monster_panel -->
                                 </div> <!-- .monster_panel -->
                             </div>
                             </div>
                             <div id='placements_arena'>
                             <div id='placements_arena'>
@@ -127,7 +128,7 @@
                                 </h5>
                                 </h5>
 <?php
 <?php
                                 $first = true;
                                 $first = true;
-                                foreach ($page->player->defense as $defense){
+                                foreach (get_context()->get_player()->get_arena_defense() as $defense){
 ?>
 ?>
                                     <div class='monster_panel'>
                                     <div class='monster_panel'>
                                         <?=HTML::unit_panel($defense)?>
                                         <?=HTML::unit_panel($defense)?>
@@ -150,7 +151,8 @@
                                 </h5>
                                 </h5>
 <?php
 <?php
                                 $first = true;
                                 $first = true;
-                                foreach ($page->player->gw_defense[0] as $defense){
+                                // TODO: Watch if null
+                                foreach (get_context()->get_player()->get_gw_defense()[0] as $defense){
 ?>
 ?>
                                     <div class='monster_panel'>
                                     <div class='monster_panel'>
                                         <?=HTML::unit_panel($defense)?>
                                         <?=HTML::unit_panel($defense)?>
@@ -169,7 +171,8 @@
                                 <hr/>
                                 <hr/>
                         <?php
                         <?php
                                 $first = true;
                                 $first = true;
-                                foreach ($page->player->gw_defense[1] as $defense){
+                                // TODO: Watch if null
+                                foreach (get_context()->get_player()->get_gw_defense()[1] as $defense){
 ?>
 ?>
                                     <div class='monster_panel'>
                                     <div class='monster_panel'>
                                         <?=HTML::unit_panel($defense)?>
                                         <?=HTML::unit_panel($defense)?>
@@ -193,9 +196,9 @@
                             </h4>
                             </h4>
 <?php
 <?php
                             // Buildings
                             // Buildings
-                            $half = sizeof($page->player->building) / 2;
+                            $half = sizeof(get_context()->get_player()->get_buildings()) / 2;
                             $i = 0;
                             $i = 0;
-                            foreach ($page->player->building as $building){
+                            foreach (get_context()->get_player()->get_buildings() as $building){
                                 if ($i == $half){
                                 if ($i == $half){
 ?>
 ?>
                                     <br class='desktop'/>
                                     <br class='desktop'/>
@@ -210,9 +213,9 @@
                             <br/>
                             <br/>
 <?php
 <?php
                             // Decorations
                             // Decorations
-                            $half = sizeof($page->player->decoration) / 2;
+$                           $half = sizeof(get_context()->get_player()->get_decorations()) / 2;
                             $i = 0;
                             $i = 0;
-                            foreach ($page->player->decoration as $decoration){
+                            foreach (get_context()->get_player()->get_decorations() as $decoration){
                                 if ($i == $half){
                                 if ($i == $half){
 ?>
 ?>
                                     <br class='desktop'/>
                                     <br class='desktop'/>
@@ -232,66 +235,66 @@
                             <ul>
                             <ul>
                                 <li>
                                 <li>
                                     <img title='Energy' src='<?=URL::IMG["CURRENCY"]?>energy.png'/>
                                     <img title='Energy' src='<?=URL::IMG["CURRENCY"]?>energy.png'/>
-                                    <?=$page->player->currency["energy"]?> / <?=$page->player->currency["energy_max"]?>
+                                    <?=get_context()->get_player()->get_currencies()["energy"]?> / <?=get_context()->get_player()->get_currencies()["energy_max"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Arena Invitations' src='<?=URL::IMG["CURRENCY"]?>arenaenergy.png'/>
                                     <img title='Arena Invitations' src='<?=URL::IMG["CURRENCY"]?>arenaenergy.png'/>
-                                    <?=$page->player->currency["arena_energy"]?> / 10
+                                    <?=get_context()->get_player()->get_currencies()["arena_energy"]?> / 10
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Dimensional Energy' src='<?=URL::IMG["CURRENCY"]?>dimensionenergy.png'/>
                                     <img title='Dimensional Energy' src='<?=URL::IMG["CURRENCY"]?>dimensionenergy.png'/>
-                                    <?=$page->player->currency["dimension_energy"]?> / 10
+                                    <?=get_context()->get_player()->get_currencies()["dimension_energy"]?> / 10
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Dimensional Crystal' src='<?=URL::IMG["CURRENCY"]?>darkportalenergy.png'/>
                                     <img title='Dimensional Crystal' src='<?=URL::IMG["CURRENCY"]?>darkportalenergy.png'/>
-                                    <?=$page->player->currency["darkportal_energy"]?> / 10
+                                    <?=get_context()->get_player()->get_currencies()["darkportal_energy"]?> / 10
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Mana' src='<?=URL::IMG["CURRENCY"]?>mana.png'/>
                                     <img title='Mana' src='<?=URL::IMG["CURRENCY"]?>mana.png'/>
-                                    <?=$page->player->currency["mana"]?>
+                                    <?=get_context()->get_player()->get_currencies()["mana"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Crystal' src='<?=URL::IMG["CURRENCY"]?>crystal.png'/>
                                     <img title='Crystal' src='<?=URL::IMG["CURRENCY"]?>crystal.png'/>
-                                    <?=$page->player->currency["crystal"]?>
+                                    <?=get_context()->get_player()->get_currencies()["crystal"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Social Points' src='<?=URL::IMG["CURRENCY"]?>socialpoint.png'/>
                                     <img title='Social Points' src='<?=URL::IMG["CURRENCY"]?>socialpoint.png'/>
-                                    <?=$page->player->currency["social_point"]?>
+                                    <?=get_context()->get_player()->get_currencies()["social_point"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Honor Points' src='<?=URL::IMG["CURRENCY"]?>honor.png'/>
                                     <img title='Honor Points' src='<?=URL::IMG["CURRENCY"]?>honor.png'/>
-                                    <?=$page->player->currency["honor_point"]?>
+                                    <?=get_context()->get_player()->get_currencies()["honor_point"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Guild Points' src='<?=URL::IMG["CURRENCY"]?>guildpoint.png'/>
                                     <img title='Guild Points' src='<?=URL::IMG["CURRENCY"]?>guildpoint.png'/>
-                                    <?=$page->player->currency["guild_point"]?>
+                                    <?=get_context()->get_player()->get_currencies()["guild_point"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Honor Medals' src='<?=URL::IMG["CURRENCY"]?>badge.png'/>
                                     <img title='Honor Medals' src='<?=URL::IMG["CURRENCY"]?>badge.png'/>
-                                    <?=$page->player->currency["honor_medal"]?>
+                                    <?=get_context()->get_player()->get_currencies()["honor_medal"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img src='<?=URL::IMG["CURRENCY"]?>mark.png'/>
                                     <img src='<?=URL::IMG["CURRENCY"]?>mark.png'/>
-                                    <?=$page->player->currency["honor_mark"]?>
+                                    <?=get_context()->get_player()->get_currencies()["honor_mark"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Ancient Coins' src='<?=URL::IMG["CURRENCY"]?>ancientcoin.png'/>
                                     <img title='Ancient Coins' src='<?=URL::IMG["CURRENCY"]?>ancientcoin.png'/>
-                                    <?=$page->player->currency["event_coin"]?>
+                                    <?=get_context()->get_player()->get_currencies()["event_coin"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Ancient Crystal' src='<?=URL::IMG["CURRENCY"]?>ancientstone.png'/>
                                     <img title='Ancient Crystal' src='<?=URL::IMG["CURRENCY"]?>ancientstone.png'/>
-                                    <?=$page->player->currency["ancient_stone"]?>
+                                    <?=get_context()->get_player()->get_currencies()["ancient_stone"]?>
                                 </li>
                                 </li>
                                 <li>
                                 <li>
                                     <img title='Shapeshifting Stones' src='<?=URL::IMG["CURRENCY"]?>costumestone.png'/>
                                     <img title='Shapeshifting Stones' src='<?=URL::IMG["CURRENCY"]?>costumestone.png'/>
-                                    <?=$page->player->currency["costume_point"]?>
+                                    <?=get_context()->get_player()->get_currencies()["costume_point"]?>
                                 </li>
                                 </li>
                             </ul>
                             </ul>
 <?php
 <?php
                             // Scrolls
                             // Scrolls
-                            $half = sizeof($page->player->building) / 2;
+                            $half = sizeof(get_context()->get_player()->get_scrolls()) / 2;
                             $i = 0;
                             $i = 0;
-                            foreach ($page->player->item_scroll as $item){
+                            foreach (get_context()->get_player()->get_scrolls() as $item){
                                 if ($half > 6 && $i == $half){
                                 if ($half > 6 && $i == $half){
 ?>
 ?>
                                     <br class='desktop'/>
                                     <br class='desktop'/>
@@ -307,7 +310,7 @@
 <?php
 <?php
                             // Rune craft materials
                             // Rune craft materials
                             $prev = 0;
                             $prev = 0;
-                            foreach ($page->player->item_craft_rune as $item){
+                            foreach (get_context()->get_player()->get_rune_craft_materials() as $item){
 ?>
 ?>
                                 <?=HTML::item_panel($item)?>
                                 <?=HTML::item_panel($item)?>
 <?php
 <?php
@@ -318,7 +321,7 @@
 <?php
 <?php
                             // Other craft materials
                             // Other craft materials
                             $prev = 0;
                             $prev = 0;
-                            foreach ($page->player->item_craft as $item){
+                            foreach (get_context()->get_player()->get_craft_materials() as $item){
                                 if ($prev != 0 && $prev < 5000 && $item->id > 5000){
                                 if ($prev != 0 && $prev < 5000 && $item->id > 5000){
 ?>
 ?>
                                     <br class='desktop'/>
                                     <br class='desktop'/>
@@ -335,7 +338,7 @@
                             // Essences
                             // Essences
                             $prev = "";
                             $prev = "";
                             $i = 0;
                             $i = 0;
-                            foreach ($page->player->item_essence as $item){
+                            foreach (get_context()->get_player()->get_essences() as $item){
                                 //if ($prev != "" && $prev != preg_split('/\s+/', $item->name)[2]){
                                 //if ($prev != "" && $prev != preg_split('/\s+/', $item->name)[2]){
                                 if ($i > 0 && $i % 6 == 0){
                                 if ($i > 0 && $i % 6 == 0){
 ?>
 ?>
@@ -363,7 +366,7 @@
                                             Arena
                                             Arena
                                         </td>
                                         </td>
                                         <td class='value rank'>
                                         <td class='value rank'>
-                                            <?=HTML::arena_rank_icon($page->player->top_rank_arena)?>
+                                            <?=HTML::arena_rank_icon(get_context()->get_player()->get_top_rank_arena())?>
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                     <tr>
                                     <tr>
@@ -371,7 +374,7 @@
                                             World Arena
                                             World Arena
                                         </td>
                                         </td>
                                         <td class='value rank'>
                                         <td class='value rank'>
-                                            <?=HTML::arena_rank_icon($page->player->top_rank_world_arena)?>
+                                            <?=HTML::arena_rank_icon(get_context()->get_player()->get_top_rank_world_arena())?>
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                     <tr>
                                     <tr>
@@ -379,7 +382,7 @@
                                             Special League
                                             Special League
                                         </td>
                                         </td>
                                         <td class='value rank'>
                                         <td class='value rank'>
-                                            <?=HTML::arena_rank_icon($page->player->top_rank_special_league)?>
+                                            <?=HTML::arena_rank_icon(get_context()->get_player()->get_top_rank_special_league())?>
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                     <tr>
                                     <tr>
@@ -387,7 +390,7 @@
                                             Guild War
                                             Guild War
                                         </td>
                                         </td>
                                         <td class='value rank'>
                                         <td class='value rank'>
-                                            <?=HTML::arena_rank_icon($page->player->top_rank_gw - 10)?>
+                                            <?=HTML::arena_rank_icon(get_context()->get_player()->get_top_rank_gw() - 10)?>
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                     <tr>
                                     <tr>
@@ -395,7 +398,7 @@
                                             Siege Battle
                                             Siege Battle
                                         </td>
                                         </td>
                                         <td class='value rank'>
                                         <td class='value rank'>
-                                            <?=HTML::arena_rank_icon($page->player->top_rank_siege)?>
+                                            <?=HTML::arena_rank_icon(get_context()->get_player()->get_top_rank_siege())?>
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                     <tr>
                                     <tr>
@@ -404,7 +407,7 @@
                                         </td>
                                         </td>
                                         <td class='value wboss'>
                                         <td class='value wboss'>
                                             <!-- TODO Rank 12?? -->
                                             <!-- TODO Rank 12?? -->
-                                            <?=WORLD_BOSS_RANK_ID::RANK[$page->player->top_rank_wboss]?>
+                                            <?=WORLD_BOSS_RANK_ID::RANK[get_context()->get_player()->get_top_rank_wboss()]?>
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                     <tr>
                                     <tr>
@@ -412,7 +415,7 @@
                                             Trial of Ascension (N)
                                             Trial of Ascension (N)
                                         </td>
                                         </td>
                                         <td class='value toa'>
                                         <td class='value toa'>
-                                            <?=$page->player->top_rank_toan?>F
+                                            <?=get_context()->get_player()->get_top_rank_toan()?>F
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                     <tr>
                                     <tr>
@@ -420,13 +423,13 @@
                                             Trial of Ascension (N)
                                             Trial of Ascension (N)
                                         </td>
                                         </td>
                                         <td class='value toa'>
                                         <td class='value toa'>
-                                            <?=$page->player->top_rank_toah?>F
+                                            <?=get_context()->get_player()->get_top_rank_toah()?>F
                                         </td>
                                         </td>
                                     </tr>
                                     </tr>
                                 </table>
                                 </table>
                                 <table id='battle_records'>
                                 <table id='battle_records'>
 <?php
 <?php
-                                    foreach ($page->player->record as $record){
+                                    foreach (get_context()->get_player()->get_records() as $record){
 ?>
 ?>
                                         <tr>
                                         <tr>
                                             <td class='record_dungeon'>
                                             <td class='record_dungeon'>
@@ -493,7 +496,7 @@
                                                         <hr class='frontline'/>
                                                         <hr class='frontline'/>
 <?php
 <?php
                                                     }
                                                     }
-                                                    if ($party instanceof K_Unit){
+                                                    if ($party instanceof Monster){
                                                         $disabled = "disabled";
                                                         $disabled = "disabled";
                                                     }
                                                     }
                                                     else{
                                                     else{
@@ -501,7 +504,7 @@
                                                     }
                                                     }
                                                     if ($disabled == ""){
                                                     if ($disabled == ""){
 ?>
 ?>
-                                                        <a target='_blank' href='/<?=$PLAYER->id?>/monster/<?=$party->id?>'>
+                                                        <a target='_blank' href='/<?=get_context()->get_player()->get_id()?>/monster/<?=$party->id?>'>
 <?php
 <?php
                                                     }
                                                     }
 ?>
 ?>

+ 17 - 19
application/view/inc/header.php

@@ -6,8 +6,6 @@
      *
      *
      * @category View
      * @category View
      */
      */
-
-    /** @var int $PLAYER Player id. */
 ?>
 ?>
 <script>
 <script>
     function setMode(rta){
     function setMode(rta){
@@ -20,7 +18,7 @@
         else{
         else{
             return false;
             return false;
         }
         }
-        params = '?player=<?=$PLAYER->id?>&mode=' + mode;
+        params = '?player=<?=get_context()->get_player()->get_id()?>&mode=' + mode;
         var xhttp = new XMLHttpRequest();
         var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         xhttp.onreadystatechange = function() {
             if (this.readyState == 4){
             if (this.readyState == 4){
@@ -54,71 +52,71 @@
                         </div>
                         </div>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/'>
                             Home
                             Home
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/units/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/units/'>
                             Units
                             Units
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/runes/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/runes/'>
                             Runes
                             Runes
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/artifacts/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/artifacts/'>
                             Artifacts
                             Artifacts
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/enchantments/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/enchantments/'>
                             Enchantments
                             Enchantments
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/teams/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/teams/'>
                             Teams
                             Teams
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='last profile'>
                     <td class='last profile'>
-                        <a href='/<?=$PLAYER->id?>/profile/'>
-                            <?=$PLAYER->name?>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/profile/'>
+                            <?=get_context()->get_player()->get_name()?>
                         </a>
                         </a>
                     </td>
                     </td>
                 </tr>
                 </tr>
                 <tr>
                 <tr>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/catalog/'>
-                            Catalog
+                        <a href='/<?=get_context()->get_player()->get_id()?>/monsters/'>
+                            Monsters
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/guild/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/guild/'>
                             Guild
                             Guild
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/runs/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/runs/'>
                             Runs
                             Runs
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/report/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/report/'>
                             Reports
                             Reports
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='item'>
                     <td class='item'>
-                        <a href='/<?=$PLAYER->id?>/optimizer/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/optimizer/'>
                             Optimizer
                             Optimizer
                         </a>
                         </a>
                     </td>
                     </td>
                     <td class='no_item'>
                     <td class='no_item'>
                     </td>
                     </td>
                     <!--<td class='item'>
                     <!--<td class='item'>
-                        <a href='/<?=$PLAYER->id?>/stats/'>
+                        <a href='/<?=get_context()->get_player()->get_id()?>/stats/'>
                             Stats
                             Stats
                         </a>
                         </a>
                     </td>-->
                     </td>-->
@@ -128,7 +126,7 @@
                                 N<span class='desktop'>ormal</span>
                                 N<span class='desktop'>ormal</span>
                             </span>
                             </span>
                             <label class='switch'>
                             <label class='switch'>
-                                <input type="checkbox" <?=($MODE == GAME_MODE_ID::RTA ? "checked='cheecked'" : "")?> onChange='setMode(this.checked);'/>
+                                <input type="checkbox" <?=(get_context()->get_game_mode() == GAME_MODE_ID::RTA ? "checked='cheecked'" : "")?> onChange='setMode(this.checked);'/>
                                 <span class="slider round"></span>
                                 <span class="slider round"></span>
                             </label>
                             </label>
                             <span class='mode'>
                             <span class='mode'>

+ 2 - 1
application/view/monster.php

@@ -6,6 +6,7 @@
      *
      *
      * @category View
      * @category View
      * @var Monster_Page $page The page model.
      * @var Monster_Page $page The page model.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 
 
 ?>
 ?>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php

+ 7 - 6
application/view/optimizer.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Optimizer_Page $page The page model.
      * @var Optimizer_Page $page The page model.
-     * @var Player $PLAYER Currently selected player.
+     * @var Player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -85,7 +86,7 @@
              * @return true on success, false on error.
              * @return true on success, false on error.
              */
              */
             function rateTeam(team, score){
             function rateTeam(team, score){
-                params = '?player=<?=$PLAYER->id?>&team=' + team + '&score=' + score;
+                params = '?player=<?=get_context()->get_player()->get_id()?>&team=' + team + '&score=' + score;
                 console.log(params);
                 console.log(params);
                 var xhttp = new XMLHttpRequest();
                 var xhttp = new XMLHttpRequest();
                 xhttp.onreadystatechange = function() {
                 xhttp.onreadystatechange = function() {
@@ -107,7 +108,7 @@
              * @param unit ID of the unit to optimize.
              * @param unit ID of the unit to optimize.
              */
              */
             function optimize(unit){
             function optimize(unit){
-                window.location.href = "/<?=$PLAYER->id?>/optimizer/" + unit;
+                window.location.href = "/<?=get_context()->get_player()->get_id()?>/optimizer/" + unit;
             }
             }
 
 
             /**
             /**
@@ -185,7 +186,7 @@
                 <br/>
                 <br/>
                 <br/>
                 <br/>
                 <br/>
                 <br/>
-                To optimize units that are not on teams, do so from the <a href='/<?=$PLAYER->id?>/monsters/'>monsters page</a>.
+                To optimize units that are not on teams, do so from the <a href='/<?=get_context()->get_player()->get_id()?>/monsters/'>monsters page</a>.
             </p>
             </p>
         </aside>
         </aside>
         <main>
         <main>
@@ -226,7 +227,7 @@
 <?php
 <?php
                                         }
                                         }
 ?>
 ?>
-                                        <a href='/<?=$PLAYER->id?>/monsters/<?=$unit->id?>' target='_blank'>
+                                        <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$unit->id?>' target='_blank'>
                                             <div class='monster_panel'>
                                             <div class='monster_panel'>
                                                 <?=HTML::unit_panel($unit)?>
                                                 <?=HTML::unit_panel($unit)?>
 <?php
 <?php

+ 6 - 5
application/view/optimizer_unit.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Optimizer_Unit_Page $page The page model.
      * @var Optimizer_Unit_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -230,7 +231,7 @@
                 var x;
                 var x;
 
 
                 // Player id - mandatory
                 // Player id - mandatory
-                params = 'player=<?=$PLAYER->id?>';
+                params = 'player=<?=get_context()->get_player()->get_id()?>';
 
 
                 // Unit id - mandatory
                 // Unit id - mandatory
                 params += '&unit=<?=$page->unit->id?>';
                 params += '&unit=<?=$page->unit->id?>';
@@ -744,7 +745,7 @@
                         }
                         }
                     }
                     }
                 };
                 };
-                params = 'player=<?=$PLAYER->id?>&unit=<?=$page->unit->id?>&tuning=' + document.getElementById('tuning').options[document.getElementById('tuning').selectedIndex].value;
+                params = 'player=<?=get_context()->get_player()->get_id()?>&unit=<?=$page->unit->id?>&tuning=' + document.getElementById('tuning').options[document.getElementById('tuning').selectedIndex].value;
                 params += '&options=' + JSON.stringify(valid_combinations);
                 params += '&options=' + JSON.stringify(valid_combinations);
                 xhttp.open('POST', '/action/optimize_get_options/', true);
                 xhttp.open('POST', '/action/optimize_get_options/', true);
                 xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                 xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
@@ -1258,7 +1259,7 @@
                                 foreach($page->unit->teams as $team){
                                 foreach($page->unit->teams as $team){
 ?>
 ?>
                                     <li>
                                     <li>
-                                        <a target='blank' href='/<?=$PLAYER-id?>/teams/<?=$team->id?>'>
+                                        <a target='blank' href='/<?=get_context()->get_player()-id?>/teams/<?=$team->id?>'>
                                             <?=$team->name?>
                                             <?=$team->name?>
                                         </a>
                                         </a>
                                     </li>
                                     </li>

+ 2 - 1
application/view/profile.php

@@ -7,6 +7,7 @@
      * @category View
      * @category View
      * @var Profile_Page $page The page model.
      * @var Profile_Page $page The page model.
      * @var User $USER Currently logged-in user.
      * @var User $USER Currently logged-in user.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php

+ 5 - 3
application/view/report.php

@@ -6,6 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Report_Page $page The page model.
      * @var Report_Page $page The page model.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -18,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -67,7 +69,7 @@
                         Shows a list of the monstes in need of skilling-up
                         Shows a list of the monstes in need of skilling-up
                         It sorts monster not by the absolute ammount of remaining power-ups, but by a ponderated list tht takes into account to which skills the previous power ups have gone, placing more value in the more advanced skills. 
                         It sorts monster not by the absolute ammount of remaining power-ups, but by a ponderated list tht takes into account to which skills the previous power ups have gone, placing more value in the more advanced skills. 
                     </p>
                     </p>
-                    <a class='a_button' href='/<?=$PLAYER->id?>/report/skillup/'>
+                    <a class='a_button' href='/<?=get_context()->get_player()->get_id()?>/report/skillup/'>
                         Go
                         Go
                     </a>
                     </a>
                 </article>
                 </article>
@@ -82,7 +84,7 @@
                         Shows monsters with runes that can be grinded or enchanted.
                         Shows monsters with runes that can be grinded or enchanted.
                         It list the grindstones and gems that are available for each rune.
                         It list the grindstones and gems that are available for each rune.
                     </p>
                     </p>
-                    <a class='a_button' href='/<?=$PLAYER->id?>/report/rune_enchantment/'>
+                    <a class='a_button' href='/<?=get_context()->get_player()->get_id()?>/report/rune_enchantment/'>
                         Go
                         Go
                     </a>
                     </a>
                 </article>
                 </article>

+ 5 - 4
application/view/report_rune_enchantment.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Report_Rune_Enchantment_Page $page The page model.
      * @var Report_Rune_Enchantment_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -110,7 +111,7 @@
             <h2>
             <h2>
                 Report filters
                 Report filters
             </h2>
             </h2>
-            <form action='/<?=$PLAYER->id?>/report/rune_enchantment/' method='get' id='filter_runeenchantment' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/report/rune_enchantment/' method='get' id='filter_runeenchantment' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td colspan='2' class='header'>
                         <td colspan='2' class='header'>
@@ -472,7 +473,7 @@
     ?>
     ?>
                         <tr>
                         <tr>
                             <td class='header' colspan='2'>
                             <td class='header' colspan='2'>
-                                <a href='/<?=$PLAYER->id?>/monsters/<?=$upgrade["unit"]->id?>/' target='_blank'>
+                                <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$upgrade["unit"]->id?>/' target='_blank'>
                                     <div class='monster_panel'>
                                     <div class='monster_panel'>
                                         <?=HTML::unit_panel($upgrade["unit"])?>
                                         <?=HTML::unit_panel($upgrade["unit"])?>
                                     </div>
                                     </div>

+ 5 - 4
application/view/report_skillup.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Report_Skillup_Page $page The page model.
      * @var Report_Skillup_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -54,7 +55,7 @@
                 Report filters
                 Report filters
             </h2>
             </h2>
             <article id='filters_content'>
             <article id='filters_content'>
-                <form action='/<?=$PLAYER->id?>/report/skillup/' method='get' id='filter_skillup' class='filter'>
+                <form action='/<?=get_context()->get_player()->get_id()?>/report/skillup/' method='get' id='filter_skillup' class='filter'>
                     <table>
                     <table>
                         <tr>
                         <tr>
                             <td class='filter' id='filter_stars'>
                             <td class='filter' id='filter_stars'>
@@ -234,7 +235,7 @@
                         </tr>
                         </tr>
                         <tr>
                         <tr>
                             <td rowspan='3' class='img'>
                             <td rowspan='3' class='img'>
-                                <a href='/<?=$PLAYER->id?>/monsters/<?=$unit->id?>/' target='_blank'>
+                                <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$unit->id?>/' target='_blank'>
                                     <div class='monster_panel'>
                                     <div class='monster_panel'>
                                         <?=HTML::unit_panel($unit)?>
                                         <?=HTML::unit_panel($unit)?>
                                     </div>
                                     </div>

+ 4 - 3
application/view/runes.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Runes_Page $page The page model.
      * @var Runes_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -112,7 +113,7 @@
             <p>
             <p>
                 Manage your runes
                 Manage your runes
             </p>
             </p>
-            <form action='/<?=$PLAYER->id?>/runes/' method='get' id='filter_runes' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/runes/' method='get' id='filter_runes' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='label' >
                         <td class='label' >

+ 7 - 6
application/view/runs.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Runs_Page $page The page model.
      * @var Runs_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -83,7 +84,7 @@
                 };
                 };
                 xhttp.open("POST", "/action/save_run_team/", true);
                 xhttp.open("POST", "/action/save_run_team/", true);
                 xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                 xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-                xhttp.send('player=<?=$PLAYER->id?>&run=' + id + '&name=' + encodeURI(name) + '&description=' + encodeURI(description));
+                xhttp.send('player=<?=get_context()->get_player()->get_id()?>&run=' + id + '&name=' + encodeURI(name) + '&description=' + encodeURI(description));
             }
             }
 
 
             /**
             /**
@@ -154,7 +155,7 @@
             <p>
             <p>
                 View and compare saved runs
                 View and compare saved runs
             </p>
             </p>
-            <form action='/<?=$PLAYER->id?>/runs/' method='get' id='filter_runeupgrade' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/runs/' method='get' id='filter_runeupgrade' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='label'>
                         <td class='label'>
@@ -350,7 +351,7 @@
                                             <hr class='frontline'/>
                                             <hr class='frontline'/>
 <?php
 <?php
                                         }
                                         }
-                                        if ($party instanceof K_Unit){
+                                        if ($party instanceof Monster){
                                             $enable_save = false;
                                             $enable_save = false;
                                             $disabled = "disabled";
                                             $disabled = "disabled";
                                         }
                                         }
@@ -359,7 +360,7 @@
                                         }
                                         }
                                         if ($disabled == ""){
                                         if ($disabled == ""){
 ?>
 ?>
-                                            <a target='_blank' href='/<?=$PLAYER->id?>/monster/<?=$party->id?>'>
+                                            <a target='_blank' href='/<?=get_context()->get_player()->get_id()?>/monster/<?=$party->id?>'>
 <?php
 <?php
                                         }
                                         }
 ?>
 ?>

+ 4 - 3
application/view/stats.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Stats_Page $page The page model.
      * @var Stats_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -532,7 +533,7 @@
             <h2>
             <h2>
                 Statistics
                 Statistics
             </h2>
             </h2>
-            <form action='/<?=$PLAYER-id?>/stats/' method='get' class='filter'>
+            <form action='/<?=get_context()->get_player()-id?>/stats/' method='get' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='filter'>
                         <td class='filter'>

+ 8 - 7
application/view/teams.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Teams_Page $page The page model.
      * @var Teams_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -79,7 +80,7 @@
              * @return true on success, false on error.
              * @return true on success, false on error.
              */
              */
             function rateTeam(team, score){
             function rateTeam(team, score){
-                params = '?player=<?=$PLAYER->id?>&team=' + team + '&score=' + score;
+                params = '?player=<?=get_context()->get_player()->get_id()?>&team=' + team + '&score=' + score;
                 console.log(params);
                 console.log(params);
                 var xhttp = new XMLHttpRequest();
                 var xhttp = new XMLHttpRequest();
                 xhttp.onreadystatechange = function() {
                 xhttp.onreadystatechange = function() {
@@ -176,7 +177,7 @@
                 }
                 }
 
 
                 var request =
                 var request =
-                  'player=<?=$PLAYER->id?>' +
+                  'player=<?=get_context()->get_player()->get_id()?>' +
                   '&area_type=' + area_type +
                   '&area_type=' + area_type +
                   '&area=' + area +
                   '&area=' + area +
                   '&difficulty=' + difficulty +
                   '&difficulty=' + difficulty +
@@ -235,7 +236,7 @@
                 if (!confirm("Permanently delete team?")){
                 if (!confirm("Permanently delete team?")){
                     return
                     return
                 }
                 }
-                var request = 'player=<?=$PLAYER->id?>&id=' + id;
+                var request = 'player=<?=get_context()->get_player()->get_id()?>&id=' + id;
                 var xhttp = new XMLHttpRequest();
                 var xhttp = new XMLHttpRequest();
                 xhttp.onreadystatechange = function() {
                 xhttp.onreadystatechange = function() {
                     if (this.readyState == 4){ 
                     if (this.readyState == 4){ 
@@ -711,7 +712,7 @@
             <p>
             <p>
                 View and manage teams
                 View and manage teams
             </p>
             </p>
-            <form action='/<?=$PLAYER->id?>/teams/' method='get'  id='filter_monsters' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/teams/' method='get'  id='filter_monsters' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='label'>
                         <td class='label'>
@@ -804,7 +805,7 @@
 <?php
 <?php
                                         }
                                         }
 ?>
 ?>
-                                        <a href='/<?=$PLAYER->id?>/monsters/<?=$unit->id?>'>
+                                        <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$unit->id?>'>
                                             <div class='monster_panel'>
                                             <div class='monster_panel'>
                                                 <?=HTML::unit_panel($unit)?>
                                                 <?=HTML::unit_panel($unit)?>
 <?php
 <?php

+ 5 - 4
application/view/unit.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Monster_Page $page The page model.
      * @var Monster_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -92,7 +93,7 @@
                                 foreach($page->unit->teams as $team){
                                 foreach($page->unit->teams as $team){
 ?>
 ?>
                                     <li>
                                     <li>
-                                        <a target='blank' href='/<?=$PLAYER->id?>/teams/<?=$team->id?>'>
+                                        <a target='blank' href='/<?=get_context()->get_player()->get_id()?>/teams/<?=$team->id?>'>
                                             <?=$team->name?>
                                             <?=$team->name?>
                                         </a>
                                         </a>
                                     </li>
                                     </li>
@@ -104,7 +105,7 @@
 <?php
 <?php
                     }
                     }
 ?>
 ?>
-                    <a id='optimize' class='a_button' href='/<?=$PLAYER->id?>/optimizer/<?=$page->unit->id?>'>
+                    <a id='optimize' class='a_button' href='/<?=get_context()->get_player()->get_id()?>/optimizer/<?=$page->unit->id?>'>
                         Optimize
                         Optimize
                     </a>
                     </a>
                 </div>
                 </div>

+ 5 - 4
application/view/units.php

@@ -6,7 +6,8 @@
      *
      *
      * @category View
      * @category View
      * @var Monsters_Page $page The page model.
      * @var Monsters_Page $page The page model.
-     * @var player $PLAYER Currently selected player.
+     * @var Player get_context()->get_player() Currently selected player.
+     * @var int get_context()->get_game_mode() Game mode.
      */
      */
 ?>
 ?>
 <!DOCTYPE html>
 <!DOCTYPE html>
@@ -19,7 +20,7 @@
         <!-- CSS files -->
         <!-- CSS files -->
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
         <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
 <?php
 <?php
-        if ($MODE == GAME_MODE_ID::RTA){
+        if (get_context()->get_game_mode() == GAME_MODE_ID::RTA){
 ?>
 ?>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
             <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui-rta.css'/>
 <?php
 <?php
@@ -56,7 +57,7 @@
             <p>
             <p>
                 Monsters
                 Monsters
             </p>
             </p>
-            <form action='/<?=$PLAYER->id?>/units/' method='get'  id='filter_monsters' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/units/' method='get'  id='filter_monsters' class='filter'>
                 <table>
                 <table>
                     <tr>
                     <tr>
                         <td class='label'>
                         <td class='label'>
@@ -176,7 +177,7 @@
                     foreach ($page->units as $unit){
                     foreach ($page->units as $unit){
 ?>
 ?>
                         <div class='monster'>
                         <div class='monster'>
-                            <a href='/<?=$PLAYER->id?>/units/<?=$unit->id?>'>
+                            <a href='/<?=get_context()->get_player()->get_id()?>/units/<?=$unit->id?>'>
                                 <div class='monster_panel'>
                                 <div class='monster_panel'>
                                     <?=HTML::unit_panel($unit)?>
                                     <?=HTML::unit_panel($unit)?>
                                 </div>
                                 </div>

+ 13 - 1
public/index.php

@@ -9,7 +9,19 @@
 
 
     require_once(__DIR__ . "/../application/Controller.php");
     require_once(__DIR__ . "/../application/Controller.php");
 
 
+    $controller = new Controller();
+
+    $request = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+    $params = explode('/', $request);
+
+    function get_context(){
+        global $controller;
+        return $controller->get_context();
+    }
+
     $request = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
     $request = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
     $params = explode('/', $request);
     $params = explode('/', $request);
-    new Controller($params);
+    $controller->prepare($params);
+    $controller->action();
+
 ?>
 ?>