2015-12-15 23:13:23 +01:00
< ? php
require_once ( 'snapshot.php' );
require_once ( 'report.php' );
require_once ( 'message.php' );
2016-06-23 21:41:46 +02:00
require_once ( 'user.php' );
2015-12-15 23:13:23 +01:00
2016-06-19 23:21:12 +02:00
const CATEGORIES = array (
0 => 'Global' ,
1 => 'Hacking' ,
2 => 'Chat Abuse'
);
2015-12-16 01:22:55 +01:00
const dataDir = 'data/' ;
2016-02-27 01:08:48 +01:00
const collapsedMessageCount = 20 ;
2015-12-15 23:13:23 +01:00
// In Java this is "DateTimeFormatter.ISO_LOCAL_DATE_TIME"
2015-12-18 17:20:57 +01:00
const jsonDateTimeFormat = 'Y-m-d\TH:i:s' ;
2015-12-15 23:13:23 +01:00
2016-01-17 00:45:37 +01:00
/** @var mysqli[] $connections */
$connections = array (); // String index = Connection name
2016-06-23 21:41:46 +02:00
/** @var User[] $users */ // Account id index
$users = array ();
2016-01-17 00:45:37 +01:00
/** PARSE DB CONNECTIONS */
$dbConfigFile = new SplFileObject ( 'database-config.dat' );
if ( $dbConfigFile -> isFile ())
{
while ( ! $dbConfigFile -> eof ())
{
$line = trim ( $dbConfigFile -> fgets ());
if ( $line ) // check not empty line
{
$parts = explode ( ' ' , $line );
$fullUrl = $parts [ 1 ];
$urlParts = explode ( '/' , $fullUrl );
$host = $urlParts [ 0 ];
$database = $urlParts [ 1 ];
$name = $parts [ 0 ];
$username = $parts [ 2 ];
$password = $parts [ 3 ];
$connection = new mysqli ( $host , $username , $password , $database );
if ( $connection -> connect_error ) {
die ( " Connection \" $name\ " failed : $connection -> connect_error " );
}
$connections [ $name ] = $connection ;
}
}
}
else
{
die ( 'database-config.dat does not exist or is not a file.' );
}
/**
* @ param String $name
* @ return mysqli
*/
function getConnection ( $name )
{
global $connections ;
return $connections [ $name ];
}
2015-12-15 23:13:23 +01:00
/**
2016-06-19 23:21:12 +02:00
* @ param Int $reportId
2015-12-15 23:13:23 +01:00
* @ return Report
*/
2016-06-19 23:21:12 +02:00
function getReport ( $reportId )
2015-12-15 23:13:23 +01:00
{
2016-06-19 23:21:12 +02:00
$connection = getConnection ( " ACCOUNT " );
$statement = $connection -> prepare ( ' SELECT * FROM reports
LEFT JOIN reportHandlers ON reports . id = reportHandlers . reportId
LEFT JOIN reportResults ON reports . id = reportResults . reportId
2016-06-23 16:18:00 +02:00
WHERE reports . id = ? ' );
2016-06-19 23:21:12 +02:00
2016-06-23 21:41:46 +02:00
try
{
2016-06-19 23:21:12 +02:00
$statement -> bind_param ( 'i' , $reportId );
$statement -> execute ();
2015-12-15 23:13:23 +01:00
2016-06-19 23:21:12 +02:00
$result = $statement -> get_result ();
2015-12-15 23:13:23 +01:00
2016-06-19 23:21:12 +02:00
if ( $row = $result -> fetch_assoc ())
{
2016-06-23 16:18:00 +02:00
$suspectUser = getUser ( $row [ 'suspectId' ]);
$categoryId = $row [ 'categoryId' ];
2016-06-19 23:21:12 +02:00
$reportReasons = getReporters ( $reportId );
$handlerUser = null ;
2016-06-23 16:18:00 +02:00
if ( isset ( $row [ 'handlerId' ]))
2016-06-19 23:21:12 +02:00
{
2016-06-23 16:18:00 +02:00
$handlerUser = getUser ( $row [ 'handlerId' ]);
2016-06-19 23:21:12 +02:00
}
2015-12-15 23:13:23 +01:00
2016-06-19 23:21:12 +02:00
return new Report ( $reportId , $handlerUser , $suspectUser , $reportReasons , $categoryId );
}
2016-06-23 21:41:46 +02:00
}
finally
{
2016-06-19 23:21:12 +02:00
$statement -> close ();
2015-12-15 23:13:23 +01:00
}
2016-06-19 23:21:12 +02:00
return null ;
2015-12-15 23:13:23 +01:00
}
2016-06-23 21:41:46 +02:00
function getSnapshot ( $reportId )
{
/** @var $messages Message[] */
$messages = array ();
$connection = getConnection ( " ACCOUNT " );
$statement = $connection -> prepare ( " SELECT id, senderId, snapshotType, `server`, `time`, message FROM reportSnapshots, snapshots
WHERE snapshots . id = reportSnapshots . snapshotId
AND reportSnapshots . reportId = ? " );
try
{
$statement -> bind_param ( 'i' , $reportId );
$statement -> execute ();
$statement -> bind_result ( $snapshotId , $senderId , $snapshotType , $server , $time , $message );
$statement -> store_result ();
while ( $statement -> fetch ())
{
$recipients = getUsers ( getSnapshotRecipients ( $snapshotId ));
$message = new Message ( getUser ( $senderId ), $recipients , $time , $snapshotType , $message , $server );
array_push ( $messages , $message );
}
}
finally
{
$statement -> close ();
}
$snapshotUsers = array ();
foreach ( $messages as $message )
{
$sender = $message -> getSender ();
$snapshotUsers [ $sender -> getId ()] = $sender ;
foreach ( $message -> getRecipients () as $recipient )
{
$snapshotUsers [ $recipient -> getId ()] = $recipient ;
}
}
return new Snapshot ( $reportId , $messages , $snapshotUsers );
}
2015-12-15 23:13:23 +01:00
/**
2016-06-23 21:41:46 +02:00
* @ param $snapshotId
* @ return Integer [] array
2015-12-15 23:13:23 +01:00
*/
2016-06-23 21:41:46 +02:00
function getSnapshotRecipients ( $snapshotId )
2015-12-15 23:13:23 +01:00
{
2016-06-23 21:41:46 +02:00
$recipientIds = array ();
2016-06-19 23:21:12 +02:00
$connection = getConnection ( " ACCOUNT " );
2016-06-23 21:41:46 +02:00
$statement = $connection -> prepare ( " SELECT recipientId FROM snapshotRecipients WHERE snapshotId = ? " );
2015-12-15 23:13:23 +01:00
2016-06-23 21:41:46 +02:00
try
{
$statement -> bind_param ( 'i' , $snapshotId );
2016-01-17 00:45:37 +01:00
$statement -> execute ();
2016-06-23 21:41:46 +02:00
$statement -> bind_result ( $recipientId );
while ( $statement -> fetch ())
{
array_push ( $recipientIds , $recipientId );
}
}
finally
{
2016-01-17 00:45:37 +01:00
$statement -> close ();
2015-12-15 23:13:23 +01:00
}
2016-06-23 21:41:46 +02:00
return $recipientIds ;
}
/**
* @ param Integer [] $ids
* @ return User [] array
*/
function getUsers ( $ids )
{
$users = array ();
foreach ( $ids as $id )
{
array_push ( $users , getUser ( $id ));
}
return $users ;
}
/**
* @ param $id
* @ return User
*/
function getUser ( $id )
{
if ( isset ( $users [ $id ]))
{
return $users [ $id ];
}
else
{
$connection = getConnection ( " ACCOUNT " );
$statement = $connection -> prepare ( 'SELECT uuid, `name`, rank FROM accounts WHERE id = ?' );
try
{
$statement -> bind_param ( 'i' , $id );
$statement -> execute ();
$statement -> bind_result ( $uuid , $name , $rank );
$statement -> fetch ();
$user = new User ( $id , $uuid , $name , $rank );
$users [ $id ] = $user ;
return $user ;
}
finally
{
$statement -> close ();
}
}
2015-12-15 23:13:23 +01:00
}
2016-06-19 23:21:12 +02:00
function getReporters ( $reportId )
2015-12-15 23:13:23 +01:00
{
2016-06-19 23:21:12 +02:00
$connection = getConnection ( " ACCOUNT " );
2016-06-23 16:18:00 +02:00
$statement = $connection -> prepare ( " SELECT reporterId, reason FROM reportReasons WHERE reportId = ? " );
2016-06-19 23:21:12 +02:00
$reportReasons = new SplObjectStorage ();
2015-12-15 23:13:23 +01:00
2016-06-23 21:41:46 +02:00
try
{
2016-06-19 23:21:12 +02:00
$statement -> bind_param ( 'i' , $reportId );
$statement -> execute ();
$statement -> bind_result ( $reporterId , $reason );
2016-06-23 16:18:00 +02:00
$statement -> store_result (); // prevents issues with other queries running before this statement is closed
2016-06-19 23:21:12 +02:00
while ( $statement -> fetch ())
{
$reporterUser = getUser ( $reporterId );
$reportReasons [ $reporterUser ] = $reason ;
}
2016-06-23 21:41:46 +02:00
}
finally
{
2016-06-19 23:21:12 +02:00
$statement -> close ();
2015-12-15 23:13:23 +01:00
}
2016-06-19 23:21:12 +02:00
return $reportReasons ;
2015-12-15 23:13:23 +01:00
}
/**
2016-06-19 23:21:12 +02:00
* @ param Message $messageA
* @ param Message $messageB
* @ return int
2015-12-15 23:13:23 +01:00
*/
2016-06-19 23:21:12 +02:00
function compareMessageTimes ( $messageA , $messageB )
2015-12-15 23:13:23 +01:00
{
2016-06-19 23:21:12 +02:00
return $messageA -> getTimestamp () -> getTimestamp () - $messageB -> getTimestamp () -> getTimestamp ();
2015-12-15 23:13:23 +01:00
}
/**
* @ param String $dateTime
* @ param DateTimeZone $timezone
* @ return DateTime
*/
function parseDateTime ( $dateTime , $timezone )
{
2015-12-18 17:20:57 +01:00
return DateTime :: createFromFormat ( jsonDateTimeFormat , $dateTime , $timezone );
2015-12-15 23:13:23 +01:00
}
2015-12-29 06:51:50 +01:00
/**
* Converts an interval to minutes , days or months , depending on the size .
*
* @ param DateInterval $interval
* @ return string
*/
function approximateHumanInterval ( $interval )
{
2016-06-30 00:16:26 +02:00
if ( $interval -> y > 0 )
{
$humanString = $interval -> y . ' year' . ( $interval -> y != 0 ? 's' : '' );
} else if ( $interval -> m > 0 )
2015-12-29 06:51:50 +01:00
{
2016-01-30 00:12:50 +01:00
$humanString = $interval -> m . ' month' . ( $interval -> m != 0 ? 's' : '' );
2015-12-29 06:51:50 +01:00
}
else if ( $interval -> d > 0 )
{
2016-01-30 00:12:50 +01:00
$humanString = $interval -> d . ' day' . ( $interval -> d != 0 ? 's' : '' );
2015-12-29 06:51:50 +01:00
}
else if ( $interval -> h > 0 )
{
2016-01-30 00:12:50 +01:00
$humanString = $interval -> h . ' hour' . ( $interval -> h != 0 ? 's' : '' );
2015-12-29 06:51:50 +01:00
}
else
{
2016-01-30 00:12:50 +01:00
$humanString = $interval -> i . ' minute' . ( $interval -> i != 0 ? 's' : '' );
2015-12-29 06:51:50 +01:00
}
2016-01-30 00:12:50 +01:00
return $humanString ;
2015-12-29 06:51:50 +01:00
}
2016-02-27 01:08:48 +01:00
function getExpandedURL ()
{
$vars = $_GET ;
$vars [ 'expanded' ] = true ;
return '?' . http_build_query ( $vars );
}
2016-06-30 00:06:30 +02:00
$validId = isset ( $_GET [ 'id' ]);
2016-06-24 19:08:47 +02:00
$idError = " " ;
2015-12-18 17:20:57 +01:00
2016-06-24 19:08:47 +02:00
$id = null ;
2016-02-27 01:08:48 +01:00
$expanded = null ;
2015-12-18 17:20:57 +01:00
$report = null ;
2016-06-23 21:41:46 +02:00
$snapshot = null ;
2015-12-18 17:20:57 +01:00
2016-06-30 00:06:30 +02:00
if ( $validId )
2015-12-18 17:20:57 +01:00
{
2016-06-24 19:08:47 +02:00
$id = $_GET [ 'id' ];
2016-06-24 19:06:33 +02:00
$expanded = isset ( $_GET [ 'expanded' ]) && $_GET [ 'expanded' ];
2016-06-24 19:08:47 +02:00
$report = getReport ( $id );
2015-12-18 17:20:57 +01:00
2016-06-23 16:18:00 +02:00
if ( $report )
2015-12-18 17:20:57 +01:00
{
2016-06-24 19:08:47 +02:00
$snapshot = getSnapshot ( $id );
2015-12-18 17:20:57 +01:00
}
else
{
2016-06-30 00:06:30 +02:00
$validId = false ;
2016-06-24 19:08:47 +02:00
$idError = " Invalid id. " ;
2015-12-18 17:20:57 +01:00
}
}
2015-12-15 23:13:23 +01:00
?>
2015-12-16 01:22:55 +01:00
<! DOCTYPE html >
2015-12-15 23:13:23 +01:00
< html >
< head >
2015-12-16 01:22:55 +01:00
< script src = " js/jquery.js " ></ script >
< link rel = " stylesheet " href = " css/bootstrap.min.css " >
< script src = " js/bootstrap.min.js " ></ script >
< link rel = " stylesheet " href = " https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css " >
< link rel = " stylesheet " href = " css/tiger.css " >
< link href = 'https://fonts.googleapis.com/css?family=Crete+Round' rel = 'stylesheet' type = 'text/css' >
< link href = 'https://fonts.googleapis.com/css?family=Oswald' rel = 'stylesheet' type = 'text/css' >
2015-12-18 17:20:57 +01:00
< title >
2016-06-30 00:06:30 +02:00
< ? php if ( $validId ) : ?>
2015-12-18 17:20:57 +01:00
Report #<?= $report->getId() ?>
2016-02-27 01:25:48 +01:00
< ? php else : ?>
2015-12-18 17:20:57 +01:00
Report System
2016-02-27 01:25:48 +01:00
< ? php endif ; ?>
2015-12-16 01:22:55 +01:00
2015-12-18 17:20:57 +01:00
& middot ; Mineplex
</ title >
2015-12-15 23:13:23 +01:00
</ head >
< body >
2015-12-16 01:22:55 +01:00
< div id = " wrapper " >
< div id = " header " >
< img src = " img/logo.png " height = " 70px " width = " 70px " />
< h1 > Report System </ h1 >
<!-- < h2 >< i class = " fa fa-camera " ></ i >& nbsp ; & nbsp ; Chat Snap </ h2 > -->
</ div >
< div id = " search " >
2016-06-24 19:08:47 +02:00
< form id = " id-input " name = " id-input " action = " view.php " method = " get " >
2015-12-18 16:52:20 +01:00
< div class = " input-group " >
2016-06-24 19:08:47 +02:00
< input name = " id " type = " text " class = " form-control " placeholder = " Enter report id... " >
2015-12-18 16:52:20 +01:00
< span class = " input-group-btn " >
2016-06-24 19:08:47 +02:00
< button class = " btn btn-secondary " type = " submit " form = " id-input " >< i class = " fa fa-search " ></ i > Search </ button >
2015-12-18 16:52:20 +01:00
</ span >
</ div >
</ form >
2015-12-16 01:22:55 +01:00
</ div >
2015-12-18 18:41:03 +01:00
2016-06-30 00:06:30 +02:00
< ? php if ( isset ( $_GET [ 'id' ]) && ! $validId && ! empty ( $idError )) : ?>
2015-12-18 19:11:25 +01:00
< div id = " content " class = " center-block " style = " text-align: center; background-color: rgba(204, 34, 42, 0.52); " >
< p class = " error-oh-no " style = " font-size: 60px; " > What did you do ? ! ? ! ? </ p >
< img src = " img/shaun.gif " />
2016-06-24 19:08:47 +02:00
< p class = " error-oh-no " style = " font-size: 40px; " > Error : < ? = $idError ?> </p>
2015-12-18 19:11:25 +01:00
< br >
2015-12-16 01:22:55 +01:00
</ div >
2016-02-27 01:25:48 +01:00
< ? php else : ?>
2016-06-30 00:06:30 +02:00
< ? php if ( ! isset ( $_GET [ 'id' ])) exit (); ?>
2016-02-27 01:08:48 +01:00
2015-12-18 19:11:25 +01:00
< div id = " content " >
< div >
2015-12-16 01:22:55 +01:00
< hr >
2015-12-18 19:11:25 +01:00
< h2 style = " font-family: 'Oswald', sans-serif; text-align: center; " >
Report #<?= $report->getId() ?>
</ h2 >
< hr >
</ div >
< div class = " row " >
< div id = " chat " class = " col-lg-7 " >
< h4 >< i class = " fa fa-comments " ></ i >& nbsp ; & nbsp ; & nbsp ; Chat Log </ h4 >
< hr >
< div id = " log " class = " text-muted " >
2016-06-30 00:06:30 +02:00
< ? php
// INITIALIZE
// Get messages and the amount that we are going to display
$messages = $snapshot -> getMessages ();
$messageCount = count ( $messages );
$displayAmount = $expanded || $messageCount <= collapsedMessageCount ? $messageCount : collapsedMessageCount ;
// Put all reporter usernames in array for easy access later
$reporterUsernames = array ();
foreach ( $report -> getReporters () as $reporter )
{
$reporterUsernames [ count ( $reporterUsernames )] = $reporter -> getUsername ();
}
2016-06-30 00:16:26 +02:00
// TODO Calculate time since last report
// TODO actually calculate time
$lastReportTime = new DateTime ( '1999-01-12' );
$age = approximateHumanInterval ( $lastReportTime -> diff ( new DateTime ( 'now' , $lastReportTime -> getTimezone ())));
2016-06-30 00:06:30 +02:00
if ( $displayAmount == 0 ) : ?>
2016-06-30 00:07:26 +02:00
< span class = " black " > No chat log available for this report .</ span >
2016-06-30 00:06:30 +02:00
< ? php else :
for ( $i = 0 ; $i < $displayAmount ; $i ++ ) :
$message = $messages [ $i ];
$typeId = $message -> getType ();
$typeDisplayName = Message :: $TYPE_DISPLAY_NAMES [ $typeId ];
$isPM = $typeId == Message :: TYPE_PM ;
// If this is a PM, then the "-> <recipient>" suffix will be applied.
$involved = $message -> getSender () -> getUsername () . ( $isPM ? " -> " . $message -> getRecipients ()[ 0 ] -> getUsername () : " " );
?>
< span class = " label <?= $isPM ? " label - primary chat pm " : " label - info chat " ?> " style = " font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; " >< ? = $typeDisplayName ?> </span>
< span class = " black " >< ? = $involved ; ?> :</span> <?= $message->getMessage(); ?>
< ? php if ( $i < $displayAmount - 1 ) : // Don't break on the last element ?>
< br />
< ? php endif ; ?>
< ? php endfor ; ?>
2016-02-27 01:08:48 +01:00
< ? php endif ; ?>
2015-12-16 01:22:55 +01:00
</ div >
2016-02-27 01:08:48 +01:00
< ? php if ( ! $expanded && $displayAmount < $messageCount ) : ?>
< br />
< a href = " <?= getExpandedURL() ?> " > Show All ( < ? = $messageCount ?> messages)</a>
< ? php endif ; ?>
2015-12-18 19:11:25 +01:00
</ div >
< div id = " users " class = " col-lg-5 " >
< h4 >< i class = " fa fa-info-circle " ></ i >& nbsp ; & nbsp ; & nbsp ; Information </ h4 >
< hr >
< div class = " row " >
2016-01-07 16:52:03 +01:00
< div class = " col-lg-12 " >
< i class = " fa fa-clock-o fa-fw " ></ i >
2016-06-27 19:15:41 +02:00
< span class = " label label-pill label-default " title = " Last Report: <?= $lastReportTime->format ('Y/m/d H:i:s T') ?> " >< ? = $age . ' ago' ?> </span>
2016-01-07 16:52:03 +01:00
< br >
< i class = " fa fa-user-plus fa-fw " ></ i >
2016-02-27 01:08:48 +01:00
< span class = " label label-pill label-success " > Reported by < ? = implode ( " , " , $reporterUsernames ) ?> </span>
2016-01-07 16:52:03 +01:00
< br >
< i class = " fa fa-user-times fa-fw " ></ i >
< span class = " label label-pill label-danger " > Suspect is < ? = $report -> getSuspect () -> getUsername () ?> </span>
< br >
< i class = " fa fa-gavel fa-fw " ></ i >
< span class = " label label-pill label-warning " >
2016-02-27 01:25:48 +01:00
< ? php if ( $report -> getHandler () != null ) : ?>
Staff Member assigned is < ? = $report -> getHandler () -> getUsername () ?>
< ? php else : ?>
No Staff Member assigned
< ? php endif ; ?>
2016-01-08 16:06:13 +01:00
</ span >
2016-01-07 16:52:03 +01:00
< br >
2015-12-18 19:11:25 +01:00
</ div >
2015-12-16 01:22:55 +01:00
</ div >
2015-12-18 19:11:25 +01:00
< br >
< h4 >< i class = " fa fa-users " ></ i >& nbsp ; & nbsp ; & nbsp ; Users </ h4 >
< hr >
< ? php foreach ( $snapshot -> getPlayers () as $player ) : ?>
< img src = " http://cravatar.eu/avatar/<?= $player->getUUID () ?>/55.png " class = " pull-left " />
2016-01-17 00:45:37 +01:00
& nbsp ; & nbsp ; < b class = " name " >< ? = $player -> getUsername () ?> </b> <span class="label label-staff name"><?= $player->getRank() ?></span><br> <!-- TODO different styling for different ranks -->
2015-12-18 19:11:25 +01:00
< code style = " font-size: 11px; " >< ? = $player -> getUUID () ?> </code>
< br >< br >
< ? php endforeach ; ?>
2015-12-16 01:22:55 +01:00
</ div >
</ div >
</ div >
2016-02-27 01:25:48 +01:00
< ? php endif ; ?>
2016-01-07 16:52:03 +01:00
< div id = " footer " >
2015-12-16 01:22:55 +01:00
< a href = " http://www.mineplex.com " >< img src = " img/logo-full.png " width = " 225px " /></ a >
< div class = " btn-group pull-right indent-link " style = " font-family: 'Crete Round', serif; padding-top: 10px; " >
< a href = " http://www.mineplex.com " class = " btn btn-link btn-small text-muted " > Home </ a >
< a href = " http://www.mineplex.com/shop/ " class = " btn btn-link btn-small text-muted " > Shop </ a >
< a href = " http://www.mineplex.com/forums/ " class = " btn btn-link btn-small text-muted " > Forums </ a >
< a href = " http://www.mineplex.com/supporthub/ " class = " btn btn-link btn-small text-muted " > Support </ a >
</ div >
</ div >
</ div >
2015-12-15 23:13:23 +01:00
</ body >
</ html >
2016-02-27 01:25:48 +01:00
< ? php foreach ( $connections as $connection ) {
2016-02-27 01:08:48 +01:00
$connection -> close ();
2016-02-27 01:25:48 +01:00
} ?>