Update chatsnap site to handle new token system
This commit is contained in:
parent
5c5c159ee3
commit
f39ee7c247
@ -15,9 +15,6 @@
|
|||||||
/** @var Int */
|
/** @var Int */
|
||||||
private $category;
|
private $category;
|
||||||
|
|
||||||
/** @var Snapshot */
|
|
||||||
private $snapshot;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report constructor.
|
* Report constructor.
|
||||||
* @param Int $id
|
* @param Int $id
|
||||||
@ -25,16 +22,14 @@
|
|||||||
* @param User $suspect
|
* @param User $suspect
|
||||||
* @param UserReport[] $reporters
|
* @param UserReport[] $reporters
|
||||||
* @param Int $category
|
* @param Int $category
|
||||||
* @param Snapshot $snapshot
|
|
||||||
*/
|
*/
|
||||||
function __construct($id, $handler, $suspect, $reporters, $category, $snapshot)
|
function __construct($id, $handler, $suspect, $reporters, $category)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->handler = $handler;
|
$this->handler = $handler;
|
||||||
$this->suspect = $suspect;
|
$this->suspect = $suspect;
|
||||||
$this->reporters = $reporters;
|
$this->reporters = $reporters;
|
||||||
$this->category = $category;
|
$this->category = $category;
|
||||||
$this->snapshot = $snapshot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,12 +98,4 @@
|
|||||||
{
|
{
|
||||||
return $this->category;
|
return $this->category;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Snapshot
|
|
||||||
*/
|
|
||||||
public function getSnapshot()
|
|
||||||
{
|
|
||||||
return $this->snapshot;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -89,7 +89,7 @@
|
|||||||
function getReport($reportId)
|
function getReport($reportId)
|
||||||
{
|
{
|
||||||
$connection = getConnection("ACCOUNT");
|
$connection = getConnection("ACCOUNT");
|
||||||
$statement = $connection->prepare('SELECT reports.suspectId, reports.categoryId, reports.snapshotId, reportHandlers.handlerId FROM reports
|
$statement = $connection->prepare('SELECT reports.suspectId, reports.categoryId, reportHandlers.handlerId FROM reports
|
||||||
LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId AND reportHandlers.aborted IS FALSE
|
LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId AND reportHandlers.aborted IS FALSE
|
||||||
LEFT JOIN reportResults ON reports.id = reportResults.reportId
|
LEFT JOIN reportResults ON reports.id = reportResults.reportId
|
||||||
WHERE reports.id = ?;');
|
WHERE reports.id = ?;');
|
||||||
@ -97,26 +97,20 @@
|
|||||||
$statement->bind_param('i', $reportId);
|
$statement->bind_param('i', $reportId);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$statement->store_result();
|
$statement->store_result();
|
||||||
$statement->bind_result($suspectId, $categoryId, $snapshotId, $handlerId);
|
$statement->bind_result($suspectId, $categoryId, $handlerId);
|
||||||
|
|
||||||
if ($statement->fetch())
|
if ($statement->fetch())
|
||||||
{
|
{
|
||||||
$suspectUser = getUser($suspectId);
|
$suspectUser = getUser($suspectId);
|
||||||
$reportReasons = getReporters($reportId);
|
$reportReasons = getReporters($reportId);
|
||||||
$snapshot = null;
|
|
||||||
$handlerUser = null;
|
$handlerUser = null;
|
||||||
|
|
||||||
if (!is_null($snapshotId))
|
|
||||||
{
|
|
||||||
$snapshot = getSnapshot($snapshotId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($handlerId))
|
if (!is_null($handlerId))
|
||||||
{
|
{
|
||||||
$handlerUser = getUser($handlerId);
|
$handlerUser = getUser($handlerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Report($reportId, $handlerUser, $suspectUser, $reportReasons, $categoryId, $snapshot);
|
return new Report($reportId, $handlerUser, $suspectUser, $reportReasons, $categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$statement->close();
|
$statement->close();
|
||||||
@ -124,7 +118,39 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSnapshot($messageId)
|
/**
|
||||||
|
* @param string $token
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
function getSnapshotId($token)
|
||||||
|
{
|
||||||
|
$connection = getConnection('ACCOUNT');
|
||||||
|
$statement = $connection->prepare('SELECT id FROM snapshots WHERE token = ?;');
|
||||||
|
$statement->bind_param('s', $token); // TODO: correct data type
|
||||||
|
$statement->execute();
|
||||||
|
$statement->bind_result($snapshotId);
|
||||||
|
$statement->store_result();
|
||||||
|
$statement->fetch();
|
||||||
|
return $snapshotId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $snapshotId
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
function getSnapshotReportId($snapshotId)
|
||||||
|
{
|
||||||
|
$connection = getConnection('ACCOUNT');
|
||||||
|
$statement = $connection->prepare('SELECT reportId FROM reports WHERE snapshotId = ?;');
|
||||||
|
$statement->bind_param('i', $snapshotId);
|
||||||
|
$statement->execute();
|
||||||
|
$statement->bind_result($reportId);
|
||||||
|
$statement->store_result();
|
||||||
|
$statement->fetch();
|
||||||
|
return $reportId;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSnapshot($snapshotId)
|
||||||
{
|
{
|
||||||
/** @var $messages Message[] */
|
/** @var $messages Message[] */
|
||||||
$messages = array();
|
$messages = array();
|
||||||
@ -135,14 +161,14 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
|
|||||||
AND snapshotMessages.id = snapshotMessageMap.messageId
|
AND snapshotMessages.id = snapshotMessageMap.messageId
|
||||||
AND snapshots.id = ?;");
|
AND snapshots.id = ?;");
|
||||||
|
|
||||||
$statement->bind_param('i', $messageId);
|
$statement->bind_param('i', $snapshotId);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$statement->bind_result($messageId, $senderId, $snapshotType, $server, $time, $message);
|
$statement->bind_result($snapshotId, $senderId, $snapshotType, $server, $time, $message);
|
||||||
$statement->store_result();
|
$statement->store_result();
|
||||||
|
|
||||||
while ($statement->fetch())
|
while ($statement->fetch())
|
||||||
{
|
{
|
||||||
$recipients = getUsers(getMessageRecipients($messageId));
|
$recipients = getUsers(getMessageRecipients($snapshotId));
|
||||||
$message = new Message(getUser($senderId), $recipients, $time, $snapshotType, $message, $server);
|
$message = new Message(getUser($senderId), $recipients, $time, $snapshotType, $message, $server);
|
||||||
array_push($messages, $message);
|
array_push($messages, $message);
|
||||||
}
|
}
|
||||||
@ -161,20 +187,20 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Snapshot($messageId, $messages, $snapshotUsers);
|
return new Snapshot($snapshotId, $messages, $snapshotUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $messageId
|
* @param $snapshotId
|
||||||
* @return Integer[] array
|
* @return Integer[] array
|
||||||
*/
|
*/
|
||||||
function getMessageRecipients($messageId)
|
function getMessageRecipients($snapshotId)
|
||||||
{
|
{
|
||||||
$recipientIds = array();
|
$recipientIds = array();
|
||||||
$connection = getConnection("ACCOUNT");
|
$connection = getConnection("ACCOUNT");
|
||||||
$statement = $connection->prepare("SELECT recipientId FROM snapshotRecipients WHERE messageId = ?");
|
$statement = $connection->prepare("SELECT recipientId FROM snapshotRecipients WHERE messageId = ?");
|
||||||
|
|
||||||
$statement->bind_param('i', $messageId);
|
$statement->bind_param('i', $snapshotId);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$statement->bind_result($recipientId);
|
$statement->bind_result($recipientId);
|
||||||
|
|
||||||
@ -355,28 +381,39 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
|
|||||||
return '?' . http_build_query($vars);
|
return '?' . http_build_query($vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
$validId = isset($_GET['id']);
|
$validToken = isset($_GET['token']);
|
||||||
$idError = "";
|
$idError = "";
|
||||||
|
|
||||||
$id = null;
|
$token = null;
|
||||||
$expanded = null;
|
$expanded = null;
|
||||||
$report = null;
|
$report = null;
|
||||||
$snapshot = null;
|
$snapshot = null;
|
||||||
|
|
||||||
if ($validId)
|
if ($validToken)
|
||||||
{
|
{
|
||||||
$id = $_GET['id'];
|
$token = $_GET['token'];
|
||||||
$expanded = isset($_GET['expanded']) && $_GET['expanded'];
|
$expanded = isset($_GET['expanded']) && $_GET['expanded'];
|
||||||
$report = getReport($id);
|
$snapshotId = getSnapshotId($token);
|
||||||
|
|
||||||
if ($report)
|
if ($snapshotId != null)
|
||||||
{
|
{
|
||||||
$snapshot = $report->getSnapshot();
|
$snapshot = getSnapshot($snapshotId);
|
||||||
|
$reportId = getSnapshotReportId($snapshotId);
|
||||||
|
|
||||||
|
if ($reportId)
|
||||||
|
{
|
||||||
|
$report = getReport($reportId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$validToken = false;
|
||||||
|
$idError = 'Associated report not found.'; // TODO: Allow snapshots without reports in future
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$validId = false;
|
$validToken = false;
|
||||||
$idError = "Invalid id.";
|
$idError = 'Invalid token.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@ -389,7 +426,7 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
|
|||||||
<link href='https://fonts.googleapis.com/css?family=Crete+Round' rel='stylesheet' type='text/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'>
|
<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
|
||||||
<title>
|
<title>
|
||||||
<?php if ($validId): ?>
|
<?php if ($validToken): ?>
|
||||||
Report #<?= $report->getId() ?>
|
Report #<?= $report->getId() ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
Report System
|
Report System
|
||||||
@ -405,17 +442,17 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
|
|||||||
<h1>Report System</h1>
|
<h1>Report System</h1>
|
||||||
</div>
|
</div>
|
||||||
<div id="search">
|
<div id="search">
|
||||||
<form id="id-input" name="id-input" action="view.php" method="get">
|
<form id="token-input" name="token-input" action="view.php" method="get">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input name="id" type="text" class="form-control" placeholder="Enter snapshot id...">
|
<input name="token" type="text" class="form-control" placeholder="Enter snapshot token...">
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button class="btn btn-secondary" type="submit" form="id-input"><i class="fa fa-search"></i> Search</button>
|
<button class="btn btn-secondary" type="submit" form="token-input"><i class="fa fa-search"></i> Search</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if (isset($_GET['id']) && !$validId && !empty($idError)): ?>
|
<?php if (isset($_GET['id']) && !$validToken && !empty($idError)): ?>
|
||||||
<div id="content" class="center-block" style="text-align: center; background-color: rgba(204, 34, 42, 0.52);">
|
<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>
|
<p class="error-oh-no" style="font-size: 60px;">What did you do?!?!?</p>
|
||||||
<img src="img/shaun.gif" />
|
<img src="img/shaun.gif" />
|
||||||
|
Loading…
Reference in New Issue
Block a user