2015-12-07 18:05:58 +01:00
|
|
|
<?php
|
|
|
|
$dataDir = "data/";
|
2015-12-07 19:11:40 +01:00
|
|
|
$uuidPattern = "/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i";
|
2015-12-07 18:05:58 +01:00
|
|
|
|
|
|
|
// ID corresponds to the Report ID
|
|
|
|
if (!isset($_GET["id"]) || empty($_GET["id"])) {
|
2015-12-07 19:11:40 +01:00
|
|
|
echo "No id defined.";
|
2015-12-07 18:05:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $_GET["id"];
|
|
|
|
$filePath = $dataDir . $id . ".json";
|
|
|
|
|
2015-12-07 19:11:40 +01:00
|
|
|
if (file_exists($filePath) && preg_match($uuidPattern, $id)) {
|
2015-12-07 18:05:58 +01:00
|
|
|
displayMessages($filePath);
|
|
|
|
} else {
|
2015-12-07 19:11:40 +01:00
|
|
|
echo "Invalid id.";
|
2015-12-07 18:05:58 +01:00
|
|
|
}
|
|
|
|
|
2015-12-07 19:11:40 +01:00
|
|
|
|
|
|
|
|
2015-12-07 18:05:58 +01:00
|
|
|
function displayMessages($filePath) {
|
2015-12-07 19:11:40 +01:00
|
|
|
$dataArray = getData($filePath);
|
|
|
|
$snapshotArray = $dataArray["snapshots"];
|
|
|
|
$usernameMap = $dataArray["usernames"];
|
2015-12-07 18:05:58 +01:00
|
|
|
|
2015-12-07 19:11:40 +01:00
|
|
|
foreach ($snapshotArray as $snapshotData) {
|
|
|
|
echo getMessageLine($snapshotData, $usernameMap);
|
2015-12-07 18:05:58 +01:00
|
|
|
echo "<br \>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 19:11:40 +01:00
|
|
|
function getData($filename) {
|
2015-12-07 18:05:58 +01:00
|
|
|
return json_decode(file_get_contents($filename), true);
|
|
|
|
}
|
|
|
|
|
2015-12-07 19:11:40 +01:00
|
|
|
function getMessageLine($messageData, $usernameMap) {
|
|
|
|
return $usernameMap[$messageData["sender"]] . ": " . $messageData["message"];
|
2015-12-07 18:05:58 +01:00
|
|
|
}
|