diff --git a/application/controller/watch_controller.php b/application/controller/watch_controller.php
new file mode 100644
index 0000000..9c722bd
--- /dev/null
+++ b/application/controller/watch_controller.php
@@ -0,0 +1,71 @@
+sortByColumn = $sortingColumn;
+ $this->model = new watch_model();
+ }
+
+ protected function index(){
+ echo $this->listWatches();
+ }
+
+ private function listWatches(){
+ $this->action = "listwatches";
+ $watchEntries = $this->model->getWatchEntries($this->getPage(), 20, $this->sortByColumn);
+ return $this->getView($watchEntries);
+ }
+
+ protected function unwatch(){
+ if(!$this->isAdmin()){return;}
+
+ if(empty($_POST['watch_id']) || $_POST['watch_id'] < 0 || !isset($_POST['unwatch_reason'])){
+ echo "Invalid watch id";
+ return;
+ }
+ $result = $this->model->disableWatch($_POST['watch_id'], $_POST['unwatch_reason'], $this->getUsername());
+ echo $result;
+ }
+
+ protected function watch(){
+ if(!$this->isAdmin()){return;}
+
+ if(empty($_POST['player']) || empty($_POST['watch-server']) || empty($_POST['watch-expiration'])
+ || !isset($_POST['watch-reason'])){
+ $answer = new AJAXAnswer("One or many parameters are missing !", false);
+ echo $answer->getJSON();
+ return;
+ }
+ $uuid = $this->model->getPlayerUUID($_POST['player']);
+ if($uuid == null){
+ $answer = new AJAXAnswer("Error : " . $_POST['player'] . "'s UUID can't be found.", false);
+ echo $answer->getJSON();
+ return;
+ }
+ $watchExpiration;
+ if($_POST['watch-expiration'] == "definitive"){
+ $watchExpiration = null;
+ }else{
+ $watchExpiration = DateTime::createFromFormat("m/d/Y h:i A", $_POST['watch-expiration']);
+ $watchExpiration = $watchExpiration->format("Y-m-d H:i:s");
+ }
+
+ $result = $this->model->watch($uuid, $_POST['watch-server'], $watchExpiration, $this->getUsername(), $_POST['watch-reason']);
+ echo $result;
+ }
+
+ public function getPaginationView(){
+ return $this->generatePaginationView($this->getPage(), $this->model->getTotalPages(20));
+ }
+
+ public function getSortingColumn(){
+ return $this->sortByColumn;
+ }
+}
\ No newline at end of file
diff --git a/application/models/profile_model.php b/application/models/profile_model.php
index 4b28bd3..ac66931 100644
--- a/application/models/profile_model.php
+++ b/application/models/profile_model.php
@@ -38,6 +38,7 @@ class PlayerData{
// Entries of all the modules
private $banEntries;
private $muteEntries;
+ private $watchEntries;
private $kickEntries;
private $commentEntries;
@@ -60,6 +61,7 @@ public function __construct($playerUUID, $database){
// Gather different modules stats
$banModel = new ban_model(); $this->banEntries = $banModel->getPlayerBans($this->uuid);
$muteModel = new mute_model(); $this->muteEntries = $muteModel->getPlayerMutes($this->uuid);
+ $watchModel = new watch_model(); $this->watchEntries = $watchModel->getPlayerWatches($this->uuid);
$kickModel = new kick_model(); $this->kickEntries = $kickModel->getPlayerKicks($this->uuid);
$commentModel = new comment_model(); $this->commentEntries = $commentModel->getPlayerComments($this->uuid);
}
@@ -74,6 +76,7 @@ public function getData(){
"lastip" => $this->lastip,
"bans" => $this->banEntries,
"mutes" => $this->muteEntries,
+ "watches" => $this->watchEntries,
"kicks" => $this->kickEntries,
"comments" => $this->commentEntries
);
diff --git a/application/models/watch_model.php b/application/models/watch_model.php
new file mode 100644
index 0000000..f1d949b
--- /dev/null
+++ b/application/models/watch_model.php
@@ -0,0 +1,181 @@
+sortByColumnMap = array(
+ "player" => "UUID",
+ "server" => "watch_server",
+ "reason" => "watch_reason",
+ "staff" => "watch_staff",
+ "date" => "watch_begin DESC",
+ "state" => "watch_state",
+ "unwatch_date" => "watch_unwatchdate DESC, watch_end DESC",
+ "unwatch_staff" => "watch_unwatchstaff",
+ "unwatch_reason" => "watch_unwatchreason"
+ );
+ }
+
+ public function getwatchEntries($pageNo, $entriesPerPage, $sortingColumn = "date"){
+ if(!array_key_exists($sortingColumn, $this->sortByColumnMap)){
+ $sortingColumn = "date";
+ }
+
+ $orderByColumn = $this->sortByColumnMap[$sortingColumn];
+ $query = $this->database->prepare( "SELECT watchs.*, (SELECT players.BAT_player FROM BAT_players players
+ WHERE watchs.UUID = players.UUID) as player FROM BAT_watch watchs 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();
+ $watchEntries = array();
+ while ( $data = $query->fetch () ) {
+ $watchEntries[] = new WatchEntry($data);
+ }
+ return $watchEntries;
+ }
+
+ public function getTotalPages($entriesPerPage){
+ $totalPages = 0;
+ $result = $this->database->query("SELECT COUNT(*) FROM BAT_watch;");
+ while( $data = $result->fetch()){
+ $totalPages = ceil($data['COUNT(*)'] / $entriesPerPage);
+ }
+ if($totalPages < 1){
+ $totalPages = 1;
+ }
+ return $totalPages;
+ }
+
+ public function getPlayerWatches($uuid){
+ $query = $this->database->prepare( "SELECT * FROM BAT_watch WHERE UUID = :uuid ORDER BY watch_begin;" );
+ $query->execute(array("uuid" => $uuid));
+ $watchEntries = array();
+ while ( $data = $query->fetch () ) {
+ $watchEntries[] = new WatchEntry($data);
+ }
+ return $watchEntries;
+ }
+
+ public function disableWatch($watchID, $unwatchReason, $unwatchStaff){
+ $query = $this->database->prepare("UPDATE BAT_watch SET watch_state = 0,
+ watch_unwatchreason = :unwatch_reason, watch_unwatchstaff = :unwatch_staff, watch_unwatchdate = NOW()
+ WHERE watch_id = :watchID AND watch_state = 1;");
+ $query->execute(array(
+ "unwatch_reason" => $unwatchReason,
+ "unwatch_staff" => $unwatchStaff,
+ "watchID" => $watchID));
+ if($query->rowCount() > 0){
+ $answer = new AJAXAnswer("Successfully unwatchd.", true);
+ return $answer->getJSON();
+ }else{
+ $answer = new AJAXAnswer("Error : No active watch with this id!", false);
+ return $answer->getJSON();
+ }
+ }
+
+ public function watch($uuid, $watchServer, $watchExpiration, $watchStaff, $watchReason){
+ $query = $this->database->prepare("INSERT INTO `BAT_watch`(UUID, watch_staff, watch_server, watch_end, watch_reason)
+ VALUES (:uuid, :staff, :server, :expiration, :reason)");
+ if($watchExpiration == null){
+ $query->bindParam(":expiration", $watchExpiration, PDO::PARAM_NULL);
+ }else{
+ $query->bindParam(":expiration", $watchExpiration);
+ }
+ $query->bindParam(":uuid", $uuid);
+ $query->bindParam(":staff", $watchStaff);
+ $query->bindParam(":server", $watchServer);
+ $query->bindParam(":reason", $watchReason);
+ $query->execute();
+ if($query->rowCount() > 0){
+ $answer = new AJAXAnswer("Watchd successfully!", true);
+ return $answer->getJSON();
+ }else{
+ $answer = new AJAXAnswer("Error : the watch process has failed for unknown reason.", false);
+ return $answer->getJSON();
+ }
+ }
+}
+class WatchEntry extends PunishmentEntry{
+ private $headUrl;
+ private $server;
+ private $state;
+ private $unwatchDate;
+ private $unwatchStaff;
+ private $unwatchReason;
+
+ function __construct($data){
+ $this->id = $data['watch_id'];
+ if(isset($data['player'])){
+ $this->player = $data['player'];
+ $this->headUrl = "https://cravatar.eu/head/".$this->player."/32";
+ }else{
+ if(isset($data['watch_ip'])){
+ $this->markAsIpPunishment();
+ $this->player = $data['watch_ip'];
+ }else{
+ $this->player = $data['UUID'];
+ $this->headUrl = "https://cravatar.eu/head/char/32";
+ }
+ }
+ $this->server = ($data ['watch_server'] == "(global)") ? Message::globalPunishment : $data ['watch_server'];
+ $this->reason = (empty($data ['watch_reason'])) ? Message::noReason : $data ['watch_reason'];
+ $this->staff = $data ['watch_staff'];
+ $this->date = $data['watch_begin'];
+ $this->state = $data['watch_state'];
+ if($this->state){
+ if(isset($data['watch_end'])){
+ $this->unwatchDate = $data['watch_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 ! */
+ $unwatchDateTime = new DateTime($data['watch_end']);
+ $currentTime = new DateTime("now");
+ $interval = $unwatchDateTime->diff($currentTime);
+ if($unwatchDateTime < $currentTime){
+ $this->state = false;
+ }
+ }else{
+ $this->unwatchDate = Message::noData;
+ }
+ }else{
+ if(isset($data['watch_unwatchdate'])){
+ if(isset($data['watch_end'])){
+ $unwatchDateTime = new DateTime($data['watch_unwatchdate']);
+ $endwatchDateTime = new DateTime($data['watch_end']);
+ $interval = $unwatchDateTime->diff($endwatchDateTime);
+ $this->unwatchDate = ($unwatchDateTime < $endwatchDateTime) ? $data['watch_unwatchdate'] : $data['watch_end'];
+ }else{
+ $this->unwatchDate = $data['watch_unwatchdate'];
+ }
+ }else{
+ $this->unwatchDate = $data['watch_end'];
+ }
+ }
+ $this->unwatchStaff = (isset($data ['watch_unwatchstaff'])) ? $data ['watch_unwatchstaff'] : Message::noData;
+ $this->unwatchReason = (isset($data ['watch_unwatchreason'])) ? (($data ['watch_unwatchreason'] != "noreason") ? $data ['watch_unwatchreason'] : 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,
+ "unwatch_date" => $this->unwatchDate,
+ "unwatch_staff" => $this->unwatchStaff,
+ "unwatch_reason" => $this->unwatchReason,
+ "ipPunishment" => $this->isIPPunishment()
+ );
+ }
+}
diff --git a/application/views/home/index.php b/application/views/home/index.php
index 7eb2252..f8c543f 100644
--- a/application/views/home/index.php
+++ b/application/views/home/index.php
@@ -1,4 +1,4 @@
-
-
punishment list
-
Hi, welcome to punishment list!
-
+
+
punishment list
+
Hi, welcome to punishment list!
+
diff --git a/application/views/profile/viewprofile.php b/application/views/profile/viewprofile.php
index e27e56f..24d41ab 100644
--- a/application/views/profile/viewprofile.php
+++ b/application/views/profile/viewprofile.php
@@ -1,170 +1,212 @@
-
-
-
-
![<?php echo $data['player'];?> head](<?php echo $data['headUrl'];?>)
-
-
-
-
-
-
- - First login :
- - Last login :
-
-
-
-
-
-
">
-
-
Ban list - This player has never been banned!
-
-
-
-
-
-
- Server |
- Reason |
- Staff |
- Date |
- State |
- Unban date |
- Unban staff |
- Unban reason |
-
-
-
- getData();?>
- ">
- |
- |
- |
- |
- "> |
- |
- |
- |
-
-
-
-
-
-
-
-
-
">
-
-
Mute list - This player has never been muted!
-
-
-
-
-
-
- Server |
- Reason |
- Staff |
- Date |
- State |
- Unmute date |
- Unmute staff |
- Unmute reason |
-
-
-
- getData();?>
- ">
- |
- |
- |
- |
- "> |
- |
- |
- |
-
-
-
-
-
-
-
-
-
">
-
-
Kick list - This player has never been kicked!
-
-
-
-
-
-
- Server |
- Reason |
- Staff |
- Date |
-
-
-
- getData();?>
-
- |
- |
- |
- |
-
-
-
-
-
-
-
-
-
-
+
+
+
+
![<?php echo $data['player'];?> head](<?php echo $data['headUrl'];?>)
+
+
+
+
+
+
+ - First login :
+ - Last login :
+
+
+
+
+
+
">
+
+
Ban list - This player has never been banned!
+
+
+
+
+
+
+ Server |
+ Reason |
+ Staff |
+ Date |
+ State |
+ Unban date |
+ Unban staff |
+ Unban reason |
+
+
+
+ getData();?>
+ ">
+ |
+ |
+ |
+ |
+ "> |
+ |
+ |
+ |
+
+
+
+
+
+
+
+
+
">
+
+
Mute list - This player has never been muted!
+
+
+
+
+
+
+ Server |
+ Reason |
+ Staff |
+ Date |
+ State |
+ Unmute date |
+ Unmute staff |
+ Unmute reason |
+
+
+
+ getData();?>
+ ">
+ |
+ |
+ |
+ |
+ "> |
+ |
+ |
+ |
+
+
+
+
+
+
+
+
+
">
+
+
Watch list - This player has never been muted!
+
+
+
+
+
+
+ Server |
+ Reason |
+ Staff |
+ Date |
+ State |
+ Unwatch date |
+ Unwatch staff |
+ Unwatch reason |
+
+
+
+ getData();?>
+ ">
+ |
+ |
+ |
+ |
+ "> |
+ |
+ |
+ |
+
+
+
+
+
+
+
+
+
">
+
+
Kick list - This player has never been kicked!
+
+
+
+
+
+
+ Server |
+ Reason |
+ Staff |
+ Date |
+
+
+
+ getData();?>
+
+ |
+ |
+ |
+ |
+
+
+
+
+
+
+
+
+
+
diff --git a/application/views/watch/listwatches.php b/application/views/watch/listwatches.php
new file mode 100644
index 0000000..23d85ca
--- /dev/null
+++ b/application/views/watch/listwatches.php
@@ -0,0 +1,67 @@
+
+
+
+
+ Player |
+ Server |
+ Reason |
+ Staff |
+ Date |
+ State |
+ Unwatch date |
+ Unwatch staff |
+ Unwatch reason |
+
+
+
+ There are no watchs. | ";}
+ else{
+ foreach ($data as $entry){
+ $watch = $entry->getData();
+ ?>
+ ">
+ isAdmin()) ? $watch['player'] : Message::ipHidden)
+ : $watch['headImg'] . $watch['player'];
+ echo $contentToDisplay;
+ ?> |
+ |
+ |
+ |
+ |
+ "> |
+ |
+ |
+ |
+
+
+
+
\ No newline at end of file
Warning list - Nobody has warned this player!
- - Warning list