35696-vm/report.php
Flatlogic Bot 011d28fa8c seck
2025-11-13 18:26:31 +00:00

95 lines
3.8 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
// Check for active subscription
if (!hasActiveSubscription($_SESSION['user_id'])) {
// Redirect to billing page if no active subscription
header('Location: billing.php');
exit();
}
if (!isset($_GET['id'])) {
header('Location: index.php');
exit();
}
$uploadId = $_GET['id'];
$userId = $_SESSION['user_id'];
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM uploads WHERE id = ? AND user_id = ? AND status = 'completed'");
$stmt->execute([$uploadId, $userId]);
$upload = $stmt->fetch();
if (!$upload) {
// Redirect if the upload doesn't exist, doesn't belong to the user, or isn't completed
header('Location: index.php');
exit();
}
$analysisResult = json_decode($upload['analysis_result'], true);
$imagePath = htmlspecialchars($upload['file_path']);
list($width, $height) = getimagesize($upload['file_path']);
include 'partials/header.php';
?>
<main class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="h3">Analysis Report</h2>
<a href="index.php" class="btn btn-outline-secondary">Back to Dashboard</a>
</div>
<div class="card border-0 shadow-sm">
<div class="card-body">
<div class="row">
<div class="col-md-7">
<h4 class="mb-3">Vehicle Image</h4>
<div id="image-container" class="position-relative" style="width: <?php echo $width; ?>px; max-width: 100%;">
<img src="<?php echo $imagePath; ?>" class="img-fluid" alt="Analyzed Vehicle Image">
<?php if (isset($analysisResult['bounding_box'])):
$box = $analysisResult['bounding_box'];
// Calculate percentages for responsive scaling
$left = ($box['x'] / $width) * 100;
$top = ($box['y'] / $height) * 100;
$boxWidth = ($box['width'] / $width) * 100;
$boxHeight = ($box['height'] / $height) * 100;
?>
<div class="bounding-box" style="left: <?php echo $left; ?>%; top: <?php echo $top; ?>%; width: <?php echo $boxWidth; ?>%; height: <?php echo $boxHeight; ?>%;"></div>
<?php endif; ?>
</div>
</div>
<div class="col-md-5">
<h4 class="mb-3">Report Details</h4>
<?php if ($analysisResult): ?>
<div class="table-responsive">
<table class="table table-bordered">
<?php foreach ($analysisResult as $key => $value):
if (is_array($value)) continue; // Skip arrays like bounding_box
?>
<tr>
<th class="w-50"><strong><?php echo ucfirst(str_replace('_', ' ', htmlspecialchars($key))); ?></strong></th>
<td><?php echo is_bool($value) ? ($value ? 'Yes' : 'No') : htmlspecialchars($value); ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<h5 class="mt-4">Raw JSON Output</h5>
<pre class="bg-light p-3 rounded"><code><?php echo json_encode($analysisResult, JSON_PRETTY_PRINT); ?></code></pre>
<?php else: ?>
<p>No analysis data available.</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
</main>
<?php include 'partials/footer.php'; ?>