diff --git a/.gitignore b/.gitignore index bcc0b7a..723ef36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -.idea -vendor/ \ No newline at end of file +.idea \ No newline at end of file diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..5a928f6 --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +Options -Indexes diff --git a/NamelessMC Addon/Bungee Admin Tools Web Interface/initialisation.php b/NamelessMC Addon/Bungee Admin Tools Web Interface/initialisation.php new file mode 100644 index 0000000..0300e18 --- /dev/null +++ b/NamelessMC Addon/Bungee Admin Tools Web Interface/initialisation.php @@ -0,0 +1,22 @@ + 'Core Protect 2', + 'bat_icon' => '', // Icon to display before the text in the navbar +); diff --git a/NamelessMC Addon/Bungee Admin Tools Web Interface/settings.php b/NamelessMC Addon/Bungee Admin Tools Web Interface/settings.php new file mode 100644 index 0000000..e805f91 --- /dev/null +++ b/NamelessMC Addon/Bungee Admin Tools Web Interface/settings.php @@ -0,0 +1,102 @@ +isLoggedIn()){ + if($user->canViewACP($user->data()->id)){ + if($user->isAdmLoggedIn()){ + // Can view + } else { + Redirect::to('/admin'); + die(); + } + } else { + Redirect::to('/'); + die(); + } +} else { + Redirect::to('/'); + die(); +} + +// Display information first +?> +

Addon: Bungee Admin Tools Web Interface

+Authors: MuhsinunC, AlphartDev, Partydragen, and Samerton
+Version: 1.0.0
+Description: Adds an online browser to explore Bungee Admin Tools Infractions
+ +
+ +
+
+

Installation

+
+
+

Setup

+ +
+
+ +
+
+

To Bungee Admin Tools Web Interface Theme

+
+
+

It's actually quite simple to change the theme (by default it's set to Yeti)! It was very hard for me to implement the themes into the web interface, but I made it EXTREMELY easy for u! :D <3

+

To change the theme, all you have to do is:

+ +
+
+ +
+
+

To Change Link Location

+
+
+

Unfortunately, I couldn't get the location selector module to work. I tried, believe me. If u know how to get it to work, PLEASE show me how! D:

+

Open "/addons/Bungee Admin Tools Web Interface/initialisation.php" and paste in the code snippets below or put none to hide the link (The link is hidden by default & the footer code is commented out as an example for you).

+ +
+
+ +
+
+

Other Info

+
+
+

To Do:

+ +
  • Original GitHub Repository
  • +
    +
    \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 9766d4e..0000000 --- a/README.md +++ /dev/null @@ -1,14 +0,0 @@ -BAT-WebInterface -================ - -This is a webinterface written in PHP for the BungeeAdminTools plugin, a bungeecord administration plugin. - -##How to deploy the webinterface : - The webinterface uses *Composer* (a dependency management system) and therefore asks a bit of work before being able to work.
    So you have two solutions : - * for users : download packaged (plug and play) version of the webinterface here
    - * for developers : once you cloned the repo, you should run the following commands : ```composer update``` and ```composer dump-autoload -o```. It should create a *vendor* directory in the root folder of the project and that's all you have to do to get an working application. - -##Links : -* WebInterface wiki : http://www.spigotmc.org/wiki/bungee-admin-tools-web-interface-documentation/ -* BAT plugin repository : https://github.com/alphartdev/BungeeAdminTools -* BAT page : http://www.spigotmc.org/resources/bungee-admin-tools.444/ diff --git a/Useful PHP.php b/Useful PHP.php new file mode 100644 index 0000000..ae9e009 --- /dev/null +++ b/Useful PHP.php @@ -0,0 +1,26 @@ +Helpful PHP: + +Get username: getUsername();?> + +Check if user is admin: isSU()){?> INPUT CONTENT FOR ADMIN EYES ONLY HERE Then end admin content with: +OR instead of ending ALL content, you can use this: instead of this , input content for non-admins, and THEN put to end ALL content. +This is helpful to stop an error saying that, wait a minute, this isn't an admin... HALP! + +Sign Out: Sign Out + +Accounts Button: isSU()){?>
  • Accounts
  • + +Check Page Name And If It's Equal To x Then Do Something: + +Reads the ?p=PAGENAME + +Get network name content from messages.php: + +Put "danger-bat" if player is checked to be currently banned: + +Put "danger-bat" if player is checked to be currently muted: + +Check if user is regular admin: isAdmin()){//Do stuff} ?> + +Check if user is Superuser admin: isSU()){//Do stuff} ?> +This admin has higher status & more rights than regular admin. This admin can manage regular admin accounts. :O :D \ No newline at end of file diff --git a/application/config/config.inc.php b/application/config/config.inc.php index 8a351cc..843ea95 100644 --- a/application/config/config.inc.php +++ b/application/config/config.inc.php @@ -4,7 +4,6 @@ $database = ""; $user = ""; $password = ""; -$port="3306"; // 3306 default port for mysql // Debug settings $debugMode = false; // Turn on to display all errors diff --git a/application/config/messages.php b/application/config/messages.php index db238cc..af2386a 100644 --- a/application/config/messages.php +++ b/application/config/messages.php @@ -1,15 +1,15 @@ -"; // Content to insert when there are no data, e.g when a ban is not over the unbandate is not set -const state_ACTIVE = "Active"; // When a punishment is active -const state_ENDED = "Ended"; // When a punisshment is ended -const commentTypeWarning = "Warning"; // When a comment's type is an warning -const commentTypeNote = "Note"; // When a comment's type is an note -const ipHidden = "Address IP hidden"; -} +"; // Content to insert when there are no data, e.g when a ban is not over the unbandate is not set +const state_ACTIVE = "Active"; // When a punishment is active +const state_ENDED = "Ended"; // When a punishment is ended +const commentTypeWarning = "Warning"; // When a comment's type is an warning +const commentTypeNote = "Note"; // When a comment's type is an note +const ipHidden = "IP address hidden"; +} ?> \ No newline at end of file diff --git a/application/controller/BaseController.php b/application/controller/BaseController.php index 07d3408..e74cb7e 100644 --- a/application/controller/BaseController.php +++ b/application/controller/BaseController.php @@ -52,81 +52,28 @@ protected function getSortingColumn(){ } return $sortingColumn; } - - protected function generatePaginationView($currentPage, $totalPages) { - - if ($totalPages == 1) { - return ""; + + protected function generatePaginationView($currentPage, $totalPages){ + $display = "
    "; return $display; } diff --git a/application/controller/admin_controller.php b/application/controller/admin_controller.php index 2aa9734..be0f53b 100644 --- a/application/controller/admin_controller.php +++ b/application/controller/admin_controller.php @@ -1,12 +1,12 @@ model = new admin_model(); } - + protected function index(){ if($this->isAdmin()){ $this->action = "index"; @@ -15,7 +15,7 @@ protected function index(){ $this->login(); } } - + // Login, logout pages protected function login(){ $this->action = "login"; @@ -39,33 +39,16 @@ protected function processlogin(){ } protected function logout(){ if(!$this->isAdmin()){return;} - + session_destroy(); $answer = new AJAXAnswer("You have successfully disconnected !", true, ""); echo $answer->getJSON(); } - - // User change password - protected function changepassword(){ - $this->action = "changepassword"; - echo $this->getView(array()); - } - - protected function updateaccount(){ - if(!$this->isAdmin()){$this->index();return;} - if(empty($_POST['password'])){ - $answer = new AJAXAnswer("Please fill in your new password !", false); - echo $answer->getJSON(); - return; - } - - echo $this->model->updateAccount($_SESSION['username'], $_POST['password']); - } - + // SuperUser features protected function manageaccounts(){ if(!$this->isSU()){$this->index();return;} - + echo $this->getView(array("users" => $this->model->listUsers())); } protected function createaccount(){ @@ -75,7 +58,7 @@ protected function createaccount(){ echo $answer->getJSON(); return; } - + echo $this->model->createAccount($_POST['user'], $_POST['password']); } protected function deleteaccount(){ @@ -90,7 +73,7 @@ protected function deleteaccount(){ echo $answer->getJSON(); return; } - + echo $this->model->removeAccount($_POST['user']); } protected function toggleSU(){ @@ -105,8 +88,8 @@ protected function toggleSU(){ echo $answer->getJSON(); return; } - + echo $this->model->toogleSU($_POST['user']); } - -} + +} \ No newline at end of file diff --git a/application/controller/profile.php b/application/controller/profile.php index 40ddb62..18f683a 100644 --- a/application/controller/profile.php +++ b/application/controller/profile.php @@ -1,70 +1,70 @@ -model = new profile_model(); - } - - protected function index(){ - $player = (isset($this->urlData['player'])) ? $this->urlData['player'] : null; - if(empty($player)){ - echo $this->getErrorPage("Please specify a player to view his profile ..."); - return; - } - // Check if the player arg is an IP and trigger IP search if that's the case - if(preg_match('/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/', - $player)){ - echo $this->listPlayersByIp($player); - }else{ - echo $this->viewprofile($player); - } - } - - public function searchplayer(){ - if(empty($this->urlData['term']) || strlen($this->urlData['term']) < 3){ - return; - } - $players = $this->model->getPlayersStartingWith($this->urlData['term']); - $dataSet = array(); - $i = 0; - foreach($players as $player){ - $entry = array( - "id" => $i, - "value" => $player - ); - $i++; - $dataSet[] = $entry; - } - echo json_encode($dataSet); - } - - private function listPlayersByIp($ip){ - if(!$this->isAdmin()){ - echo $this->getErrorPage("You must be authenticated to search player by IP ..."); - return; - } - $this->action = "playersByIp"; - $players = $this->model->getPlayersByIp($ip); - if(empty($players)){ - echo $this->getErrorPage("No player with the specified IP (" . $ip . ") was found in the database ..."); - return; - } - return $this->getView(array( - "ip" => $ip, - "players" => $players - )); - } - - private function viewprofile($player){ - $this->action = ($this->isAdmin()) ? "../admin/administrateprofile" : "viewprofile"; - $pUUID = $this->model->getPlayerUUID($player); - if($pUUID == null){ - echo $this->getErrorPage("This player was not found in the database ..."); - return; - } - $pData = $this->model->getPlayerData($pUUID); - return $this->getView($pData->getData()); - } +model = new profile_model(); + } + + protected function index(){ + $player = (isset($this->urlData['player'])) ? $this->urlData['player'] : null; + if(empty($player)){ + echo $this->getErrorPage("Please specify a player to view his profile ..."); + return; + } + // Check if the player arg is an IP and trigger IP search if that's the case + if(preg_match('/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/', + $player)){ + echo $this->listPlayersByIp($player); + }else{ + echo $this->viewprofile($player); + } + } + + public function searchplayer(){ + if(empty($this->urlData['term']) || strlen($this->urlData['term']) < 3){ + return; + } + $players = $this->model->getPlayersStartingWith($this->urlData['term']); + $dataSet = array(); + $i = 0; + foreach($players as $player){ + $entry = array( + "id" => $i, + "value" => $player + ); + $i++; + $dataSet[] = $entry; + } + echo json_encode($dataSet); + } + + private function listPlayersByIp($ip){ + if(!$this->isAdmin()){ + echo $this->getErrorPage("You must be authenticated to search player by IP ..."); + return; + } + $this->action = "playersByIp"; + $players = $this->model->getPlayersByIp($ip); + if(empty($players)){ + echo $this->getErrorPage("No player with the specified IP (" . $ip . ") was found in the database ..."); + return; + } + return $this->getView(array( + "ip" => $ip, + "players" => $players + )); + } + + private function viewprofile($player){ + $this->action = ($this->isAdmin()) ? "../admin/administrateprofile" : "viewprofile"; + $pUUID = $this->model->getPlayerUUID($player); + if($pUUID == null){ + echo $this->getErrorPage("This player was not found in the database ..."); + return; + } + $pData = $this->model->getPlayerData($pUUID); + return $this->getView($pData->getData()); + } } \ No newline at end of file diff --git a/application/models/BaseModel.php b/application/models/BaseModel.php index ffeedc8..dfcbc01 100644 --- a/application/models/BaseModel.php +++ b/application/models/BaseModel.php @@ -5,7 +5,7 @@ abstract class BaseModel{ public function __construct(){ require("application/config/config.inc.php"); try{ - $this->database = new PDO('mysql:host='.$host.';port='.$port.';dbname='.$database, $user, $password); + $this->database = new PDO('mysql:host='.$host.';dbname='.$database, $user, $password); }catch(Exception $e) { die('An error occured connecting to the database. Please check your database login information: '.$e->getMessage()); diff --git a/application/models/admin_model.php b/application/models/admin_model.php index da8697b..9ce7c85 100644 --- a/application/models/admin_model.php +++ b/application/models/admin_model.php @@ -1,123 +1,105 @@ -database->prepare("SELECT * FROM BAT_web WHERE user = :user;"); - $query->execute(array("user" => $user)); - $salt = null; - if(($data = $query->fetch()) != false){ - $salt = $data['salt']; - } - return $salt; - } - public function checkCredentials($user, $pwd){ - $salt = $this->getSalt($user); - if($salt == null){ - return false; - } - - $hash = hash("sha512", $pwd . $salt); - $query = $this->database->prepare("SELECT * FROM BAT_web WHERE user = :user AND password = :pwd;"); - $query->execute(array("user" => $user, "pwd" => $hash)); - if($query->rowCount() > 0){ - $row = $query->fetch(); - return ($row['superuser']) ? "superuser" : "admin"; - } - return false; - } - - public function createAccount($user, $password){ - if($this->getSalt($user) != null){ - $answer = new AJAXAnswer("Error: an account with this username already exists.", false); - return $answer->getJSON(); - } - - if(strlen($user) > 32){ - $answer = new AJAXAnswer("Error: the username length must be 32 characters or less.", false); - return $answer->getJSON(); - } - if(strlen($password) < 6){ - $answer = new AJAXAnswer("Error: the password must be 6 characters or longer", false); - return $answer->getJSON(); - } - - $salt = substr(md5(uniqid(rand(), true)), 0, 16); - $hash = hash("sha512", $password . $salt); - $query = $this->database->prepare("INSERT INTO BAT_web (user, password, salt) - VALUES (:user, :pwd, :salt);"); - $query->execute(array( - "user" => $user, - "pwd" => $hash, - "salt" => $salt)); - $answer = new AJAXAnswer("Account successfully created!", true); - return $answer->getJSON(); - } - - public function updateAccount($user, $password){ - if(strlen($password) < 6){ - $answer = new AJAXAnswer("Error: the password must be 6 characters or longer", false); - return $answer->getJSON(); - } - - $salt = substr(md5(uniqid(rand(), true)), 0, 16); - $hash = hash("sha512", $password . $salt); - $query = $this->database->prepare("UPDATE BAT_web SET password = :pwd, salt = :salt WHERE user = :user;"); - $query->execute(array( - "user" => $user, - "pwd" => $hash, - "salt" => $salt)); - $answer = new AJAXAnswer("Password successfully updated", true); - return $answer->getJSON(); - } - - public function removeAccount($user){ - $query = $this->database->prepare("DELETE FROM BAT_web WHERE user = :user;"); - $query->execute(array("user" => $user)); - if($query->rowCount() > 0){ - $answer = new AJAXAnswer("Account successfully deleted!", true); - return $answer->getJSON(); - }else{ - $answer = new AJAXAnswer("Error: there is no account with that name!", true); - return $answer->getJSON(); - } - } - public function toogleSU($user){ - $query = $this->database->prepare("UPDATE BAT_web SET superuser = !superuser WHERE user = :user;"); - $query->execute(array("user" => $user)); - if($query->rowCount() > 0){ - $answer = new AJAXAnswer($user . "'s SuperUser rights have been updated!", true); - return $answer->getJSON(); - }else{ - $answer = new AJAXAnswer("Error: there is no account with that name!", true); - return $answer->getJSON(); - } - } - - public function listUsers(){ - $query = $this->database->prepare("SELECT * FROM BAT_web;"); - $query->execute(); - $users = array(); - while($row = $query->fetch()){ - $adminProfile = new AdminProfile($row['user'], $row['superuser']); - $users[] = $adminProfile->getData(); - } - return $users; - } - -} -class AdminProfile{ - private $username; - private $superuser; - - public function __construct($username, $isSU){ - $this->username = $username; - $this->superuser = $isSU; - } - - public function getData(){ - return array( - "username" => $this->username, - "superuser" => $this->superuser - ); - } -} +database->prepare("SELECT * FROM BAT_web WHERE user = :user;"); + $query->execute(array("user" => $user)); + $salt = null; + if(($data = $query->fetch()) != false){ + $salt = $data['salt']; + } + return $salt; + } + public function checkCredentials($user, $pwd){ + $salt = $this->getSalt($user); + if($salt == null){ + return false; + } + + $hash = hash("sha512", $pwd . $salt); + $query = $this->database->prepare("SELECT * FROM BAT_web WHERE user = :user AND password = :pwd;"); + $query->execute(array("user" => $user, "pwd" => $hash)); + if($query->rowCount() > 0){ + $row = $query->fetch(); + return ($row['superuser']) ? "superuser" : "admin"; + } + return false; + } + + public function createAccount($user, $password){ + if($this->getSalt($user) != null){ + $answer = new AJAXAnswer("Error: an account with this username already exists.", false); + return $answer->getJSON(); + } + + if(strlen($user) > 32){ + $answer = new AJAXAnswer("Error: the username length must be 32 characters or less.", false); + return $answer->getJSON(); + } + if(strlen($password) < 6){ + $answer = new AJAXAnswer("Error: the password must be 6 characters or longer", false); + return $answer->getJSON(); + } + + $salt = substr(md5(uniqid(rand(), true)), 0, 16); + $hash = hash("sha512", $password . $salt); + $query = $this->database->prepare("INSERT INTO BAT_web (user, password, salt) + VALUES (:user, :pwd, :salt);"); + $query->execute(array( + "user" => $user, + "pwd" => $hash, + "salt" => $salt)); + $answer = new AJAXAnswer("Account successfully created!", true); + return $answer->getJSON(); + } + public function removeAccount($user){ + $query = $this->database->prepare("DELETE FROM BAT_web WHERE user = :user;"); + $query->execute(array("user" => $user)); + if($query->rowCount() > 0){ + $answer = new AJAXAnswer("Account successfully deleted!", true); + return $answer->getJSON(); + }else{ + $answer = new AJAXAnswer("Error: there is no account with that name!", true); + return $answer->getJSON(); + } + } + public function toogleSU($user){ + $query = $this->database->prepare("UPDATE BAT_web SET superuser = !superuser WHERE user = :user;"); + $query->execute(array("user" => $user)); + if($query->rowCount() > 0){ + $answer = new AJAXAnswer($user . "'s SuperUser rights have been updated!", true); + return $answer->getJSON(); + }else{ + $answer = new AJAXAnswer("Error: there is no account with that name!", true); + return $answer->getJSON(); + } + } + + public function listUsers(){ + $query = $this->database->prepare("SELECT * FROM BAT_web;"); + $query->execute(); + $users = array(); + while($row = $query->fetch()){ + $adminProfile = new AdminProfile($row['user'], $row['superuser']); + $users[] = $adminProfile->getData(); + } + return $users; + } + +} +class AdminProfile{ + private $username; + private $superuser; + + public function __construct($username, $isSU){ + $this->username = $username; + $this->superuser = $isSU; + } + + public function getData(){ + return array( + "username" => $this->username, + "superuser" => $this->superuser + ); + } +} diff --git a/application/models/ban_model.php b/application/models/ban_model.php index 90d29ce..7b7ab2a 100644 --- a/application/models/ban_model.php +++ b/application/models/ban_model.php @@ -1,182 +1,182 @@ -sortByColumnMap = array( - "player" => "UUID", - "server" => "ban_server", - "reason" => "ban_reason", - "staff" => "ban_staff", - "date" => "ban_begin DESC", - "state" => "ban_state", - "unban_date" => "ban_unbandate DESC, ban_end DESC", - "unban_staff" => "ban_unbanstaff", - "unban_reason" => "ban_unbanreason" - ); - } - - public function getBanEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ - if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ - $sortingColumn = "date"; - } - - $orderByColumn = $this->sortByColumnMap[$sortingColumn]; - $query = $this->database->prepare( "SELECT bans.*, (SELECT players.BAT_player FROM BAT_players players - WHERE bans.UUID = players.UUID) as player FROM BAT_ban bans ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); - $offset = (($pageNo - 1) * $entriesPerPage); - // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... - $query->bindParam(":offset", $offset, PDO::PARAM_INT); - $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); - $query->execute(); - $banEntries = array(); - while ( $data = $query->fetch () ) { - $banEntries[] = new BanEntry($data); - } - return $banEntries; - } - - public function getTotalPages($entriesPerPage){ - $totalPages = 0; - $result = $this->database->query("SELECT COUNT(*) FROM BAT_ban;"); - while( $data = $result->fetch()){ - $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); - } - if($totalPages < 1){ - $totalPages = 1; - } - return $totalPages; - } - - public function getPlayerBans($uuid){ - $query = $this->database->prepare( "SELECT * FROM BAT_ban WHERE UUID = :uuid ORDER BY ban_begin;" ); - $query->execute(array("uuid" => $uuid)); - $banEntries = array(); - while ( $data = $query->fetch () ) { - $banEntries[] = new BanEntry($data); - } - return $banEntries; - } - - public function disableBan($banID, $unbanReason, $unbanStaff){ - $query = $this->database->prepare("UPDATE BAT_ban SET ban_state = 0, - ban_unbanreason = :unban_reason, ban_unbanstaff = :unban_staff, ban_unbandate = NOW() - WHERE ban_id = :banID AND ban_state = 1;"); - $query->execute(array( - "unban_reason" => $unbanReason, - "unban_staff" => $unbanStaff, - "banID" => $banID)); - if($query->rowCount() > 0){ - $answer = new AJAXAnswer("Successfully unbanned.", true); - return $answer->getJSON(); - }else{ - $answer = new AJAXAnswer("Error : No active ban with this id!", false); - return $answer->getJSON(); - } - } - - public function ban($uuid, $banServer, $banExpiration, $banStaff, $banReason){ - $query = $this->database->prepare("INSERT INTO `BAT_ban`(UUID, ban_staff, ban_server, ban_end, ban_reason) - VALUES (:uuid, :staff, :server, :expiration, :reason)"); - if($banExpiration == null){ - $query->bindParam(":expiration", $banExpiration, PDO::PARAM_NULL); - }else{ - $query->bindParam(":expiration", $banExpiration); - } - $query->bindParam(":uuid", $uuid); - $query->bindParam(":staff", $banStaff); - $query->bindParam(":server", $banServer); - $query->bindParam(":reason", $banReason); - $query->execute(); - if($query->rowCount() > 0){ - $answer = new AJAXAnswer("Banned successfully!", true); - return $answer->getJSON(); - }else{ - $answer = new AJAXAnswer("Error : the ban process has failed for unknown reason.", false); - return $answer->getJSON(); - } - } - -} -class BanEntry extends PunishmentEntry{ - private $headUrl; - private $server; - private $state; - private $unbanDate; - private $unbanStaff; - private $unbanReason; - - function __construct($data){ - $this->id = $data['ban_id']; - if(isset($data['player'])){ - $this->player = $data['player']; - $this->headUrl = "https://cravatar.eu/head/".$this->player."/32"; - }else{ - if(isset($data['ban_ip'])){ - $this->player = $data['ban_ip']; - $this->markAsIpPunishment(); - }else{ - $this->player = $data['UUID']; - $this->headUrl = "https://cravatar.eu/head/char/32"; - } - } - $this->server = ($data ['ban_server'] == "(global)") ? Message::globalPunishment : $data ['ban_server']; - $this->reason = (empty($data ['ban_reason'])) ? Message::noReason : $data ['ban_reason']; - $this->staff = $data ['ban_staff']; - $this->date = $data['ban_begin']; - $this->state = $data['ban_state']; - if($this->state){ - if(isset($data['ban_end'])){ - $this->unbanDate = $data['ban_end']; - /* If the Bungee server is shutdown, the temp punishment won't be updated. - So we do the calculation here, but we don't touch to the database data ! */ - $unbanDateTime = new DateTime($data['ban_end']); - $currentTime = new DateTime("now"); - $interval = $unbanDateTime->diff($currentTime); - if($unbanDateTime < $currentTime){ - $this->state = false; - } - }else{ - $this->unbanDate = Message::noData; - } - }else{ - if(isset($data['ban_unbandate'])){ - if(isset($data['ban_end'])){ - $unbanDateTime = new DateTime($data['ban_unbandate']); - $endBanDateTime = new DateTime($data['ban_end']); - $interval = $unbanDateTime->diff($endBanDateTime); - $this->unbanDate = ($unbanDateTime < $endBanDateTime) ? $data['ban_unbandate'] : $data['ban_end']; - }else{ - $this->unbanDate = $data['ban_unbandate']; - } - }else{ - $this->unbanDate = $data['ban_end']; - } - } - $this->unbanStaff = (isset($data ['ban_unbanstaff'])) ? $data ['ban_unbanstaff'] : Message::noData; - $this->unbanReason = (isset($data ['ban_unbanreason'])) ? (($data ['ban_unbanreason'] != "noreason") ? $data ['ban_unbanreason'] : Message::noReason) : Message::noData; - } - - /** - * Get an associative array with tag and their associated data - */ - function getData(){ - return array ( - "id" => $this->id, - "headImg" => (isset($this->headUrl)) - ? "
    " : "", - "player" => $this->player, - "server" => $this->server, - "reason" => $this->reason, - "staff" => $this->staff, - "date" => $this->date, - "state" => $this->state, - "unban_date" => $this->unbanDate, - "unban_staff" => $this->unbanStaff, - "unban_reason" => $this->unbanReason, - "ipPunishment" => $this->isIPPunishment() - ); - } -} +sortByColumnMap = array( + "player" => "UUID", + "server" => "ban_server", + "reason" => "ban_reason", + "staff" => "ban_staff", + "date" => "ban_begin DESC", + "state" => "ban_state", + "unban_date" => "ban_unbandate DESC, ban_end DESC", + "unban_staff" => "ban_unbanstaff", + "unban_reason" => "ban_unbanreason" + ); + } + + public function getBanEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ + if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ + $sortingColumn = "date"; + } + + $orderByColumn = $this->sortByColumnMap[$sortingColumn]; + $query = $this->database->prepare( "SELECT bans.*, (SELECT players.BAT_player FROM BAT_players players + WHERE bans.UUID = players.UUID) as player FROM BAT_ban bans ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); + $offset = (($pageNo - 1) * $entriesPerPage); + // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... + $query->bindParam(":offset", $offset, PDO::PARAM_INT); + $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); + $query->execute(); + $banEntries = array(); + while ( $data = $query->fetch () ) { + $banEntries[] = new BanEntry($data); + } + return $banEntries; + } + + public function getTotalPages($entriesPerPage){ + $totalPages = 0; + $result = $this->database->query("SELECT COUNT(*) FROM BAT_ban;"); + while( $data = $result->fetch()){ + $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); + } + if($totalPages < 1){ + $totalPages = 1; + } + return $totalPages; + } + + public function getPlayerBans($uuid){ + $query = $this->database->prepare( "SELECT * FROM BAT_ban WHERE UUID = :uuid ORDER BY ban_begin;" ); + $query->execute(array("uuid" => $uuid)); + $banEntries = array(); + while ( $data = $query->fetch () ) { + $banEntries[] = new BanEntry($data); + } + return $banEntries; + } + + public function disableBan($banID, $unbanReason, $unbanStaff){ + $query = $this->database->prepare("UPDATE BAT_ban SET ban_state = 0, + ban_unbanreason = :unban_reason, ban_unbanstaff = :unban_staff, ban_unbandate = NOW() + WHERE ban_id = :banID AND ban_state = 1;"); + $query->execute(array( + "unban_reason" => $unbanReason, + "unban_staff" => $unbanStaff, + "banID" => $banID)); + if($query->rowCount() > 0){ + $answer = new AJAXAnswer("Successfully unbanned.", true); + return $answer->getJSON(); + }else{ + $answer = new AJAXAnswer("Error : No active ban with this id!", false); + return $answer->getJSON(); + } + } + + public function ban($uuid, $banServer, $banExpiration, $banStaff, $banReason){ + $query = $this->database->prepare("INSERT INTO `BAT_ban`(UUID, ban_staff, ban_server, ban_end, ban_reason) + VALUES (:uuid, :staff, :server, :expiration, :reason)"); + if($banExpiration == null){ + $query->bindParam(":expiration", $banExpiration, PDO::PARAM_NULL); + }else{ + $query->bindParam(":expiration", $banExpiration); + } + $query->bindParam(":uuid", $uuid); + $query->bindParam(":staff", $banStaff); + $query->bindParam(":server", $banServer); + $query->bindParam(":reason", $banReason); + $query->execute(); + if($query->rowCount() > 0){ + $answer = new AJAXAnswer("Banned successfully!", true); + return $answer->getJSON(); + }else{ + $answer = new AJAXAnswer("Error : the ban process has failed for unknown reason.", false); + return $answer->getJSON(); + } + } + +} +class BanEntry extends PunishmentEntry{ + private $headUrl; + private $server; + private $state; + private $unbanDate; + private $unbanStaff; + private $unbanReason; + + function __construct($data){ + $this->id = $data['ban_id']; + if(isset($data['player'])){ + $this->player = $data['player']; + $this->headUrl = "https://cravatar.eu/helmhead/".$this->player."/32"; + }else{ + if(isset($data['ban_ip'])){ + $this->player = $data['ban_ip']; + $this->markAsIpPunishment(); + }else{ + $this->player = $data['UUID']; + $this->headUrl = "https://cravatar.eu/helmhead/char/32"; + } + } + $this->server = ($data ['ban_server'] == "(global)") ? Message::globalPunishment : $data ['ban_server']; + $this->reason = (empty($data ['ban_reason'])) ? Message::noReason : $data ['ban_reason']; + $this->staff = $data ['ban_staff']; + $this->date = $data['ban_begin']; + $this->state = $data['ban_state']; + if($this->state){ + if(isset($data['ban_end'])){ + $this->unbanDate = $data['ban_end']; + /* If the Bungee server is shutdown, the temp punishment won't be updated. + So we do the calculation here, but we don't touch to the database data ! */ + $unbanDateTime = new DateTime($data['ban_end']); + $currentTime = new DateTime("now"); + $interval = $unbanDateTime->diff($currentTime); + if($unbanDateTime < $currentTime){ + $this->state = false; + } + }else{ + $this->unbanDate = Message::noData; + } + }else{ + if(isset($data['ban_unbandate'])){ + if(isset($data['ban_end'])){ + $unbanDateTime = new DateTime($data['ban_unbandate']); + $endBanDateTime = new DateTime($data['ban_end']); + $interval = $unbanDateTime->diff($endBanDateTime); + $this->unbanDate = ($unbanDateTime < $endBanDateTime) ? $data['ban_unbandate'] : $data['ban_end']; + }else{ + $this->unbanDate = $data['ban_unbandate']; + } + }else{ + $this->unbanDate = $data['ban_end']; + } + } + $this->unbanStaff = (isset($data ['ban_unbanstaff'])) ? $data ['ban_unbanstaff'] : Message::noData; + $this->unbanReason = (isset($data ['ban_unbanreason'])) ? (($data ['ban_unbanreason'] != "noreason") ? $data ['ban_unbanreason'] : Message::noReason) : Message::noData; + } + + /** + * Get an associative array with tag and their associated data + */ + function getData(){ + return array ( + "id" => $this->id, + "headImg" => (isset($this->headUrl)) + ? "
    " : "", + "player" => $this->player, + "server" => $this->server, + "reason" => $this->reason, + "staff" => $this->staff, + "date" => $this->date, + "state" => $this->state, + "unban_date" => $this->unbanDate, + "unban_staff" => $this->unbanStaff, + "unban_reason" => $this->unbanReason, + "ipPunishment" => $this->isIPPunishment() + ); + } +} diff --git a/application/models/comment_model.php b/application/models/comment_model.php index 44bd9f5..aca7f39 100644 --- a/application/models/comment_model.php +++ b/application/models/comment_model.php @@ -1,91 +1,91 @@ -sortByColumnMap = array( - "player" => "entity", - "reason" => "note", - "staff" => "staff", - "date" => "date DESC", - "type" => "type" - ); - } - - public function getCommentEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ - if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ - $sortingColumn = "date"; - } - - $orderByColumn = $this->sortByColumnMap[$sortingColumn]; - $query = $this->database->prepare( "SELECT comments.*, (SELECT players.BAT_player FROM BAT_players players - WHERE comments.entity = players.UUID) as player FROM bat_comments comments ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); - $offset = (($pageNo - 1) * $entriesPerPage); - // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... - $query->bindParam(":offset", $offset, PDO::PARAM_INT); - $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); - $query->execute(); - $commentEntries = array(); - while ( $data = $query->fetch () ) { - $commentEntries[] = new CommentEntry($data); - } - return $commentEntries; - } - - public function getTotalPages($entriesPerPage){ - $totalPages = 0; - $result = $this->database->query("SELECT COUNT(*) FROM bat_comments;"); - while( $data = $result->fetch()){ - $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); - } - if($totalPages < 1){ - $totalPages = 1; - } - return $totalPages; - } - - public function getPlayerComments($uuid){ - $query = $this->database->prepare( "SELECT * FROM bat_comments WHERE entity = :uuid ORDER BY date;" ); - $query->execute(array("uuid" => $uuid)); - $commentEntries = array(); - while ( $data = $query->fetch () ) { - $commentEntries[] = new CommentEntry($data); - } - return $commentEntries; - } -} -class CommentEntry extends PunishmentEntry{ - private $headUrl; - private $type; - - function __construct($data){ - if(isset($data['player'])){ - $this->player = $data['player']; - $this->headUrl = "https://cravatar.eu/head/".$this->player."/32"; - }else{ - $this->player = $data['entity']; - $this->headUrl = "https://cravatar.eu/head/char/32"; - } - $this->reason = $data ['note']; - $this->staff = $data ['staff']; - $this->date = $data['date']; - $this->type = $data['type']; - } - - /** - * Get an associative array with tag and their associated data - */ - function getData(){ - return array ( - "headImg" => (isset($this->headUrl)) - ? "
    " : "", - "player" => $this->player, - "reason" => $this->reason, - "staff" => $this->staff, - "date" => $this->date, - "type" => $this->type - ); - } +sortByColumnMap = array( + "player" => "entity", + "reason" => "note", + "staff" => "staff", + "date" => "date DESC", + "type" => "type" + ); + } + + public function getCommentEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ + if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ + $sortingColumn = "date"; + } + + $orderByColumn = $this->sortByColumnMap[$sortingColumn]; + $query = $this->database->prepare( "SELECT comments.*, (SELECT players.BAT_player FROM BAT_players players + WHERE comments.entity = players.UUID) as player FROM bat_comments comments ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); + $offset = (($pageNo - 1) * $entriesPerPage); + // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... + $query->bindParam(":offset", $offset, PDO::PARAM_INT); + $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); + $query->execute(); + $commentEntries = array(); + while ( $data = $query->fetch () ) { + $commentEntries[] = new CommentEntry($data); + } + return $commentEntries; + } + + public function getTotalPages($entriesPerPage){ + $totalPages = 0; + $result = $this->database->query("SELECT COUNT(*) FROM bat_comments;"); + while( $data = $result->fetch()){ + $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); + } + if($totalPages < 1){ + $totalPages = 1; + } + return $totalPages; + } + + public function getPlayerComments($uuid){ + $query = $this->database->prepare( "SELECT * FROM bat_comments WHERE entity = :uuid ORDER BY date;" ); + $query->execute(array("uuid" => $uuid)); + $commentEntries = array(); + while ( $data = $query->fetch () ) { + $commentEntries[] = new CommentEntry($data); + } + return $commentEntries; + } +} +class CommentEntry extends PunishmentEntry{ + private $headUrl; + private $type; + + function __construct($data){ + if(isset($data['player'])){ + $this->player = $data['player']; + $this->headUrl = "https://cravatar.eu/helmhead/".$this->player."/32"; + }else{ + $this->player = $data['entity']; + $this->headUrl = "https://cravatar.eu/helmhead/char/32"; + } + $this->reason = $data ['note']; + $this->staff = $data ['staff']; + $this->date = $data['date']; + $this->type = $data['type']; + } + + /** + * Get an associative array with tag and their associated data + */ + function getData(){ + return array ( + "headImg" => (isset($this->headUrl)) + ? "
    " : "", + "player" => $this->player, + "reason" => $this->reason, + "staff" => $this->staff, + "date" => $this->date, + "type" => $this->type + ); + } } \ No newline at end of file diff --git a/application/models/kick_model.php b/application/models/kick_model.php index de1eb3e..9f31311 100644 --- a/application/models/kick_model.php +++ b/application/models/kick_model.php @@ -1,93 +1,93 @@ -sortByColumnMap = array( - "player" => "UUID", - "server" => "kick_server", - "reason" => "kick_reason", - "staff" => "kick_staff", - "date" => "kick_date DESC", - "state" => "kick_state" - ); - } - - public function getKickEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ - if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ - $sortingColumn = "date"; - } - - $orderByColumn = $this->sortByColumnMap[$sortingColumn]; - $query = $this->database->prepare( "SELECT kicks.*, (SELECT players.BAT_player FROM BAT_players players - WHERE kicks.UUID = players.UUID) as player FROM BAT_kick kicks ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); - $offset = (($pageNo - 1) * $entriesPerPage); - // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... - $query->bindParam(":offset", $offset, PDO::PARAM_INT); - $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); - $query->execute(); - $kickEntries = array(); - while ( $data = $query->fetch () ) { - $kickEntries[] = new KickEntry($data); - } - return $kickEntries; - } - - public function getTotalPages($entriesPerPage){ - $totalPages = 0; - $result = $this->database->query("SELECT COUNT(*) FROM BAT_kick;"); - while( $data = $result->fetch()){ - $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); - } - if($totalPages < 1){ - $totalPages = 1; - } - return $totalPages; - } - - public function getPlayerKicks($uuid){ - $query = $this->database->prepare( "SELECT * FROM BAT_kick WHERE UUID = :uuid ORDER BY kick_date;" ); - $query->execute(array("uuid" => $uuid)); - $kickEntries = array(); - while ( $data = $query->fetch () ) { - $kickEntries[] = new KickEntry($data); - } - return $kickEntries; - } -} -class KickEntry extends PunishmentEntry{ - private $headUrl; - private $server; - private $state; - - function __construct($data){ - if(isset($data['player'])){ - $this->player = $data['player']; - $this->headUrl = "https://cravatar.eu/head/".$this->player."/32"; - }else{ - $this->player = $data['UUID']; - $this->headUrl = "https://cravatar.eu/head/char/32"; - } - $this->server = ($data ['kick_server'] == "(global)") ? Message::globalPunishment : $data ['kick_server']; - $this->reason = ($data ['kick_reason'] == "noreason") ? Message::noReason : $data ['kick_reason']; - $this->staff = $data ['kick_staff']; - $this->date = $data['kick_date']; - } - - /** - * Get an associative array with tag and their associated data - */ - function getData(){ - return array ( - "headImg" => (isset($this->headUrl)) - ? "
    " : "", - "player" => $this->player, - "server" => $this->server, - "reason" => $this->reason, - "staff" => $this->staff, - "date" => $this->date - ); - } +sortByColumnMap = array( + "player" => "UUID", + "server" => "kick_server", + "reason" => "kick_reason", + "staff" => "kick_staff", + "date" => "kick_date DESC", + "state" => "kick_state" + ); + } + + public function getKickEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ + if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ + $sortingColumn = "date"; + } + + $orderByColumn = $this->sortByColumnMap[$sortingColumn]; + $query = $this->database->prepare( "SELECT kicks.*, (SELECT players.BAT_player FROM BAT_players players + WHERE kicks.UUID = players.UUID) as player FROM BAT_kick kicks ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); + $offset = (($pageNo - 1) * $entriesPerPage); + // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... + $query->bindParam(":offset", $offset, PDO::PARAM_INT); + $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); + $query->execute(); + $kickEntries = array(); + while ( $data = $query->fetch () ) { + $kickEntries[] = new KickEntry($data); + } + return $kickEntries; + } + + public function getTotalPages($entriesPerPage){ + $totalPages = 0; + $result = $this->database->query("SELECT COUNT(*) FROM BAT_kick;"); + while( $data = $result->fetch()){ + $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); + } + if($totalPages < 1){ + $totalPages = 1; + } + return $totalPages; + } + + public function getPlayerKicks($uuid){ + $query = $this->database->prepare( "SELECT * FROM BAT_kick WHERE UUID = :uuid ORDER BY kick_date;" ); + $query->execute(array("uuid" => $uuid)); + $kickEntries = array(); + while ( $data = $query->fetch () ) { + $kickEntries[] = new KickEntry($data); + } + return $kickEntries; + } +} +class KickEntry extends PunishmentEntry{ + private $headUrl; + private $server; + private $state; + + function __construct($data){ + if(isset($data['player'])){ + $this->player = $data['player']; + $this->headUrl = "https://cravatar.eu/helmhead/".$this->player."/32"; + }else{ + $this->player = $data['UUID']; + $this->headUrl = "https://cravatar.eu/helmhead/char/32"; + } + $this->server = ($data ['kick_server'] == "(global)") ? Message::globalPunishment : $data ['kick_server']; + $this->reason = ($data ['kick_reason'] == "noreason") ? Message::noReason : $data ['kick_reason']; + $this->staff = $data ['kick_staff']; + $this->date = $data['kick_date']; + } + + /** + * Get an associative array with tag and their associated data + */ + function getData(){ + return array ( + "headImg" => (isset($this->headUrl)) + ? "
    " : "", + "player" => $this->player, + "server" => $this->server, + "reason" => $this->reason, + "staff" => $this->staff, + "date" => $this->date + ); + } } \ No newline at end of file diff --git a/application/models/mute_model.php b/application/models/mute_model.php index edb4834..cc71e9c 100644 --- a/application/models/mute_model.php +++ b/application/models/mute_model.php @@ -1,181 +1,181 @@ -sortByColumnMap = array( - "player" => "UUID", - "server" => "mute_server", - "reason" => "mute_reason", - "staff" => "mute_staff", - "date" => "mute_begin DESC", - "state" => "mute_state", - "unmute_date" => "mute_unmutedate DESC, mute_end DESC", - "unmute_staff" => "mute_unmutestaff", - "unmute_reason" => "mute_unmutereason" - ); - } - - public function getmuteEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ - if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ - $sortingColumn = "date"; - } - - $orderByColumn = $this->sortByColumnMap[$sortingColumn]; - $query = $this->database->prepare( "SELECT mutes.*, (SELECT players.BAT_player FROM BAT_players players - WHERE mutes.UUID = players.UUID) as player FROM BAT_mute mutes ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); - $offset = (($pageNo - 1) * $entriesPerPage); - // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... - $query->bindParam(":offset", $offset, PDO::PARAM_INT); - $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); - $query->execute(); - $muteEntries = array(); - while ( $data = $query->fetch () ) { - $muteEntries[] = new MuteEntry($data); - } - return $muteEntries; - } - - public function getTotalPages($entriesPerPage){ - $totalPages = 0; - $result = $this->database->query("SELECT COUNT(*) FROM BAT_mute;"); - while( $data = $result->fetch()){ - $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); - } - if($totalPages < 1){ - $totalPages = 1; - } - return $totalPages; - } - - public function getPlayerMutes($uuid){ - $query = $this->database->prepare( "SELECT * FROM BAT_mute WHERE UUID = :uuid ORDER BY mute_begin;" ); - $query->execute(array("uuid" => $uuid)); - $muteEntries = array(); - while ( $data = $query->fetch () ) { - $muteEntries[] = new MuteEntry($data); - } - return $muteEntries; - } - - public function disableMute($muteID, $unmuteReason, $unmuteStaff){ - $query = $this->database->prepare("UPDATE BAT_mute SET mute_state = 0, - mute_unmutereason = :unmute_reason, mute_unmutestaff = :unmute_staff, mute_unmutedate = NOW() - WHERE mute_id = :muteID AND mute_state = 1;"); - $query->execute(array( - "unmute_reason" => $unmuteReason, - "unmute_staff" => $unmuteStaff, - "muteID" => $muteID)); - if($query->rowCount() > 0){ - $answer = new AJAXAnswer("Successfully unmuted.", true); - return $answer->getJSON(); - }else{ - $answer = new AJAXAnswer("Error : No active mute with this id!", false); - return $answer->getJSON(); - } - } - - public function mute($uuid, $muteServer, $muteExpiration, $muteStaff, $muteReason){ - $query = $this->database->prepare("INSERT INTO `BAT_mute`(UUID, mute_staff, mute_server, mute_end, mute_reason) - VALUES (:uuid, :staff, :server, :expiration, :reason)"); - if($muteExpiration == null){ - $query->bindParam(":expiration", $muteExpiration, PDO::PARAM_NULL); - }else{ - $query->bindParam(":expiration", $muteExpiration); - } - $query->bindParam(":uuid", $uuid); - $query->bindParam(":staff", $muteStaff); - $query->bindParam(":server", $muteServer); - $query->bindParam(":reason", $muteReason); - $query->execute(); - if($query->rowCount() > 0){ - $answer = new AJAXAnswer("Muted successfully!", true); - return $answer->getJSON(); - }else{ - $answer = new AJAXAnswer("Error : the mute process has failed for unknown reason.", false); - return $answer->getJSON(); - } - } -} -class MuteEntry extends PunishmentEntry{ - private $headUrl; - private $server; - private $state; - private $unmuteDate; - private $unmuteStaff; - private $unmuteReason; - - function __construct($data){ - $this->id = $data['mute_id']; - if(isset($data['player'])){ - $this->player = $data['player']; - $this->headUrl = "https://cravatar.eu/head/".$this->player."/32"; - }else{ - if(isset($data['mute_ip'])){ - $this->markAsIpPunishment(); - $this->player = $data['mute_ip']; - }else{ - $this->player = $data['UUID']; - $this->headUrl = "https://cravatar.eu/head/char/32"; - } - } - $this->server = ($data ['mute_server'] == "(global)") ? Message::globalPunishment : $data ['mute_server']; - $this->reason = (empty($data ['mute_reason'])) ? Message::noReason : $data ['mute_reason']; - $this->staff = $data ['mute_staff']; - $this->date = $data['mute_begin']; - $this->state = $data['mute_state']; - if($this->state){ - if(isset($data['mute_end'])){ - $this->unmuteDate = $data['mute_end']; - /* If the Bungee server is shutdown, the temp punishment won't be updated. - So we do the calculation here, but we don't touch to the database data ! */ - $unmuteDateTime = new DateTime($data['mute_end']); - $currentTime = new DateTime("now"); - $interval = $unmuteDateTime->diff($currentTime); - if($unmuteDateTime < $currentTime){ - $this->state = false; - } - }else{ - $this->unmuteDate = Message::noData; - } - }else{ - if(isset($data['mute_unmutedate'])){ - if(isset($data['mute_end'])){ - $unmuteDateTime = new DateTime($data['mute_unmutedate']); - $endmuteDateTime = new DateTime($data['mute_end']); - $interval = $unmuteDateTime->diff($endmuteDateTime); - $this->unmuteDate = ($unmuteDateTime < $endmuteDateTime) ? $data['mute_unmutedate'] : $data['mute_end']; - }else{ - $this->unmuteDate = $data['mute_unmutedate']; - } - }else{ - $this->unmuteDate = $data['mute_end']; - } - } - $this->unmuteStaff = (isset($data ['mute_unmutestaff'])) ? $data ['mute_unmutestaff'] : Message::noData; - $this->unmuteReason = (isset($data ['mute_unmutereason'])) ? (($data ['mute_unmutereason'] != "noreason") ? $data ['mute_unmutereason'] : Message::noReason) : Message::noData; - } - - /** - * Get an associative array with tag and their associated data - */ - function getData(){ - return array ( - "id" => $this->id, - "headImg" => (isset($this->headUrl)) - ? "
    " : "", - "player" => $this->player, - "server" => $this->server, - "reason" => $this->reason, - "staff" => $this->staff, - "date" => $this->date, - "state" => $this->state, - "unmute_date" => $this->unmuteDate, - "unmute_staff" => $this->unmuteStaff, - "unmute_reason" => $this->unmuteReason, - "ipPunishment" => $this->isIPPunishment() - ); - } -} +sortByColumnMap = array( + "player" => "UUID", + "server" => "mute_server", + "reason" => "mute_reason", + "staff" => "mute_staff", + "date" => "mute_begin DESC", + "state" => "mute_state", + "unmute_date" => "mute_unmutedate DESC, mute_end DESC", + "unmute_staff" => "mute_unmutestaff", + "unmute_reason" => "mute_unmutereason" + ); + } + + public function getmuteEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){ + if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){ + $sortingColumn = "date"; + } + + $orderByColumn = $this->sortByColumnMap[$sortingColumn]; + $query = $this->database->prepare( "SELECT mutes.*, (SELECT players.BAT_player FROM BAT_players players + WHERE mutes.UUID = players.UUID) as player FROM BAT_mute mutes ORDER BY ".$orderByColumn." LIMIT :offset, :limit;" ); + $offset = (($pageNo - 1) * $entriesPerPage); + // Must manually bind parameters because of an old bug in PDO which forbid to add parameter to LIMIT statemnt ... + $query->bindParam(":offset", $offset, PDO::PARAM_INT); + $query->bindParam(":limit", $entriesPerPage, PDO::PARAM_INT); + $query->execute(); + $muteEntries = array(); + while ( $data = $query->fetch () ) { + $muteEntries[] = new MuteEntry($data); + } + return $muteEntries; + } + + public function getTotalPages($entriesPerPage){ + $totalPages = 0; + $result = $this->database->query("SELECT COUNT(*) FROM BAT_mute;"); + while( $data = $result->fetch()){ + $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage); + } + if($totalPages < 1){ + $totalPages = 1; + } + return $totalPages; + } + + public function getPlayerMutes($uuid){ + $query = $this->database->prepare( "SELECT * FROM BAT_mute WHERE UUID = :uuid ORDER BY mute_begin;" ); + $query->execute(array("uuid" => $uuid)); + $muteEntries = array(); + while ( $data = $query->fetch () ) { + $muteEntries[] = new MuteEntry($data); + } + return $muteEntries; + } + + public function disableMute($muteID, $unmuteReason, $unmuteStaff){ + $query = $this->database->prepare("UPDATE BAT_mute SET mute_state = 0, + mute_unmutereason = :unmute_reason, mute_unmutestaff = :unmute_staff, mute_unmutedate = NOW() + WHERE mute_id = :muteID AND mute_state = 1;"); + $query->execute(array( + "unmute_reason" => $unmuteReason, + "unmute_staff" => $unmuteStaff, + "muteID" => $muteID)); + if($query->rowCount() > 0){ + $answer = new AJAXAnswer("Successfully unmuted.", true); + return $answer->getJSON(); + }else{ + $answer = new AJAXAnswer("Error : No active mute with this id!", false); + return $answer->getJSON(); + } + } + + public function mute($uuid, $muteServer, $muteExpiration, $muteStaff, $muteReason){ + $query = $this->database->prepare("INSERT INTO `BAT_mute`(UUID, mute_staff, mute_server, mute_end, mute_reason) + VALUES (:uuid, :staff, :server, :expiration, :reason)"); + if($muteExpiration == null){ + $query->bindParam(":expiration", $muteExpiration, PDO::PARAM_NULL); + }else{ + $query->bindParam(":expiration", $muteExpiration); + } + $query->bindParam(":uuid", $uuid); + $query->bindParam(":staff", $muteStaff); + $query->bindParam(":server", $muteServer); + $query->bindParam(":reason", $muteReason); + $query->execute(); + if($query->rowCount() > 0){ + $answer = new AJAXAnswer("Muted successfully!", true); + return $answer->getJSON(); + }else{ + $answer = new AJAXAnswer("Error : the mute process has failed for unknown reason.", false); + return $answer->getJSON(); + } + } +} +class MuteEntry extends PunishmentEntry{ + private $headUrl; + private $server; + private $state; + private $unmuteDate; + private $unmuteStaff; + private $unmuteReason; + + function __construct($data){ + $this->id = $data['mute_id']; + if(isset($data['player'])){ + $this->player = $data['player']; + $this->headUrl = "https://cravatar.eu/helmhead/".$this->player."/32"; + }else{ + if(isset($data['mute_ip'])){ + $this->markAsIpPunishment(); + $this->player = $data['mute_ip']; + }else{ + $this->player = $data['UUID']; + $this->headUrl = "https://cravatar.eu/helmhead/char/32"; + } + } + $this->server = ($data ['mute_server'] == "(global)") ? Message::globalPunishment : $data ['mute_server']; + $this->reason = (empty($data ['mute_reason'])) ? Message::noReason : $data ['mute_reason']; + $this->staff = $data ['mute_staff']; + $this->date = $data['mute_begin']; + $this->state = $data['mute_state']; + if($this->state){ + if(isset($data['mute_end'])){ + $this->unmuteDate = $data['mute_end']; + /* If the Bungee server is shutdown, the temp punishment won't be updated. + So we do the calculation here, but we don't touch to the database data ! */ + $unmuteDateTime = new DateTime($data['mute_end']); + $currentTime = new DateTime("now"); + $interval = $unmuteDateTime->diff($currentTime); + if($unmuteDateTime < $currentTime){ + $this->state = false; + } + }else{ + $this->unmuteDate = Message::noData; + } + }else{ + if(isset($data['mute_unmutedate'])){ + if(isset($data['mute_end'])){ + $unmuteDateTime = new DateTime($data['mute_unmutedate']); + $endmuteDateTime = new DateTime($data['mute_end']); + $interval = $unmuteDateTime->diff($endmuteDateTime); + $this->unmuteDate = ($unmuteDateTime < $endmuteDateTime) ? $data['mute_unmutedate'] : $data['mute_end']; + }else{ + $this->unmuteDate = $data['mute_unmutedate']; + } + }else{ + $this->unmuteDate = $data['mute_end']; + } + } + $this->unmuteStaff = (isset($data ['mute_unmutestaff'])) ? $data ['mute_unmutestaff'] : Message::noData; + $this->unmuteReason = (isset($data ['mute_unmutereason'])) ? (($data ['mute_unmutereason'] != "noreason") ? $data ['mute_unmutereason'] : Message::noReason) : Message::noData; + } + + /** + * Get an associative array with tag and their associated data + */ + function getData(){ + return array ( + "id" => $this->id, + "headImg" => (isset($this->headUrl)) + ? "
    " : "", + "player" => $this->player, + "server" => $this->server, + "reason" => $this->reason, + "staff" => $this->staff, + "date" => $this->date, + "state" => $this->state, + "unmute_date" => $this->unmuteDate, + "unmute_staff" => $this->unmuteStaff, + "unmute_reason" => $this->unmuteReason, + "ipPunishment" => $this->isIPPunishment() + ); + } +} diff --git a/application/models/profile_model.php b/application/models/profile_model.php index 4b28bd3..37f7e73 100644 --- a/application/models/profile_model.php +++ b/application/models/profile_model.php @@ -1,81 +1,81 @@ -database); - } - - public function getPlayersStartingWith($prefix){ - $query = $this->database->prepare( "SELECT BAT_player FROM BAT_players comments WHERE BAT_player LIKE :prefix;" ); - $query->execute(array("prefix" => $prefix . "%")); - $players = array(); - while($data = $query->fetch()){ - $players[] = $data['BAT_player']; - } - return $players; - } - - public function getPlayersByIp($ip){ - $query = $this->database->prepare( "SELECT BAT_player FROM BAT_players comments WHERE lastip = :ip;" ); - $query->execute(array("ip" => $ip )); - $players = array(); - while($data = $query->fetch()){ - $players[] = $data['BAT_player']; - } - return $players; - } -} -class PlayerData{ - // Basic informations - private $player; - private $uuid; - - // Additionals stats - private $firstlogin; - private $lastlogin; - private $lastip; - - // Entries of all the modules - private $banEntries; - private $muteEntries; - private $kickEntries; - private $commentEntries; - - public function __construct($playerUUID, $database){ - $this->uuid = $playerUUID; - - // Gather additionals stats - $query = $database->prepare( "SELECT * FROM BAT_players WHERE UUID = :uuid;" ); - $query->execute(array(":uuid" => $this->uuid)); - $data = $query->fetch(); - if($data != false){ - $this->player = $data['BAT_player']; - $this->firstlogin = $data['firstlogin']; - $this->lastlogin = $data['lastlogin']; - $this->lastip = $data['lastip']; - }else{ - die("Player not found !"); - } - - // Gather different modules stats - $banModel = new ban_model(); $this->banEntries = $banModel->getPlayerBans($this->uuid); - $muteModel = new mute_model(); $this->muteEntries = $muteModel->getPlayerMutes($this->uuid); - $kickModel = new kick_model(); $this->kickEntries = $kickModel->getPlayerKicks($this->uuid); - $commentModel = new comment_model(); $this->commentEntries = $commentModel->getPlayerComments($this->uuid); - } - - public function getData(){ - return array( - "headUrl" => "https://cravatar.eu/head/".$this->player."/192", - "player" => $this->player, - "uuid" => $this->uuid, - "firstlogin" => $this->firstlogin, - "lastlogin" => $this->lastlogin, - "lastip" => $this->lastip, - "bans" => $this->banEntries, - "mutes" => $this->muteEntries, - "kicks" => $this->kickEntries, - "comments" => $this->commentEntries - ); - } +database); + } + + public function getPlayersStartingWith($prefix){ + $query = $this->database->prepare( "SELECT BAT_player FROM BAT_players comments WHERE BAT_player LIKE :prefix;" ); + $query->execute(array("prefix" => $prefix . "%")); + $players = array(); + while($data = $query->fetch()){ + $players[] = $data['BAT_player']; + } + return $players; + } + + public function getPlayersByIp($ip){ + $query = $this->database->prepare( "SELECT BAT_player FROM BAT_players comments WHERE lastip = :ip;" ); + $query->execute(array("ip" => $ip )); + $players = array(); + while($data = $query->fetch()){ + $players[] = $data['BAT_player']; + } + return $players; + } +} +class PlayerData{ + // Basic informations + private $player; + private $uuid; + + // Additionals stats + private $firstlogin; + private $lastlogin; + private $lastip; + + // Entries of all the modules + private $banEntries; + private $muteEntries; + private $kickEntries; + private $commentEntries; + + public function __construct($playerUUID, $database){ + $this->uuid = $playerUUID; + + // Gather additionals stats + $query = $database->prepare( "SELECT * FROM BAT_players WHERE UUID = :uuid;" ); + $query->execute(array(":uuid" => $this->uuid)); + $data = $query->fetch(); + if($data != false){ + $this->player = $data['BAT_player']; + $this->firstlogin = $data['firstlogin']; + $this->lastlogin = $data['lastlogin']; + $this->lastip = $data['lastip']; + }else{ + die("Player not found !"); + } + + // Gather different modules stats + $banModel = new ban_model(); $this->banEntries = $banModel->getPlayerBans($this->uuid); + $muteModel = new mute_model(); $this->muteEntries = $muteModel->getPlayerMutes($this->uuid); + $kickModel = new kick_model(); $this->kickEntries = $kickModel->getPlayerKicks($this->uuid); + $commentModel = new comment_model(); $this->commentEntries = $commentModel->getPlayerComments($this->uuid); + } + + public function getData(){ + return array( + "headUrl" => "https://cravatar.eu/helmhead/".$this->player."/192", + "player" => $this->player, + "uuid" => $this->uuid, + "firstlogin" => $this->firstlogin, + "lastlogin" => $this->lastlogin, + "lastip" => $this->lastip, + "bans" => $this->banEntries, + "mutes" => $this->muteEntries, + "kicks" => $this->kickEntries, + "comments" => $this->commentEntries + ); + } } \ No newline at end of file diff --git a/application/views/_template/admin/navbarAddon.php b/application/views/_template/admin/navbarAddon.php index 0e93f9f..3609c8f 100644 --- a/application/views/_template/admin/navbarAddon.php +++ b/application/views/_template/admin/navbarAddon.php @@ -1,12 +1,39 @@ -
  • -
  • Hi, getUsername() ?> !
  • -
  • -
  • Panel
  • -isSU()){?>
  • Accounts
  • -
  • Change password
  • -
  • Disconnect
  • + + + + + + - + \ No newline at end of file diff --git a/application/views/_template/footer.php b/application/views/_template/footer.php index 98687ba..c1bf1ea 100644 --- a/application/views/_template/footer.php +++ b/application/views/_template/footer.php @@ -4,9 +4,10 @@
    - -
    Powered by BungeeAdminTools - - Administration panel -isAdmin()) {include("admin/footerAddon.php");} ?>
    + +
    + Powered by BungeeAdminTools + isAdmin()) {include("admin/footerAddon.php");} ?> +
    diff --git a/application/views/_template/header.php b/application/views/_template/header.php index b833184..75fc321 100644 --- a/application/views/_template/header.php +++ b/application/views/_template/header.php @@ -1,48 +1,68 @@ - -<?php echo Message::network;?> punishment list - - - - - - - - - - - + + <?php echo Message::network;?> Infractions + + + + + + + + + + + + + + + + + + + + + + -