35819-vm/results.php
2025-11-18 11:05:11 +00:00

187 lines
6.7 KiB
PHP

<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (!isset($_SESSION['results'])) {
// Redirect to the main page if no results are available
header('Location: index.php');
exit;
}
$results = $_SESSION['results'];
// Attempt to decode if the results are a JSON string
if (is_string($results)) {
$decoded_results = json_decode($results, true);
if (json_last_error() === JSON_ERROR_NONE) {
$results = $decoded_results;
} else {
// Handle the case where the string is not valid JSON
$results = []; // Reset to a safe value
}
}
$scores = $results['scores'] ?? [];
$analysis = $results['analysis'] ?? [];
$recommendations = $results['recommendations'] ?? [];
$nextSteps = $results['nextSteps'] ?? [];
// Clear the session data after displaying the results
unset($_SESSION['answers']);
unset($_SESSION['question_index']);
unset($_SESSION['results']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Burnout Analysis</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<div class="container mt-4">
<div class="card">
<div class="card-header text-center">
<h1>Your Burnout Analysis</h1>
</div>
<div class="card-body">
<?php if (empty($scores) || empty($analysis) || empty($recommendations) || empty($nextSteps)): ?>
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Analysis Failed</h4>
<p>We're sorry, but there was an error generating your burnout analysis. The data we received was incomplete or corrupted.</p>
<hr>
<p class="mb-0">Please try the survey again. If the problem persists, please contact support.</p>
</div>
<?php else: ?>
<?php if (!empty($analysis['overallSummary'])):
?>
<div class="alert alert-light" role="alert">
<h4 class="alert-heading">Overall Summary</h4>
<p><?php echo htmlspecialchars($analysis['overallSummary']); ?></p>
</div>
<?php
endif; ?>
<div class="row">
<div class="col-md-6">
<h2>Your Scores</h2>
<canvas id="burnoutChart"></canvas>
</div>
<div class="col-md-6">
<h2>Analysis</h2>
<?php if (!empty($analysis['exhaustionSummary'])):
?>
<h5>Exhaustion</h5>
<p><?php echo htmlspecialchars($analysis['exhaustionSummary']); ?></p>
<?php
endif; ?>
<?php if (!empty($analysis['cynicismSummary'])):
?>
<h5>Cynicism</h5>
<p><?php echo htmlspecialchars($analysis['cynicismSummary']); ?></p>
<?php
endif; ?>
<?php if (!empty($analysis['inefficacySummary'])):
?>
<h5>Inefficacy</h5>
<p><?php echo htmlspecialchars($analysis['inefficacySummary']); ?></p>
<?php
endif; ?>
</div>
</div>
<hr class="my-4">
<h2>Recommendations</h2>
<?php if (!empty($recommendations)):
?>
<div class="accordion" id="recommendationsAccordion">
<?php foreach ($recommendations as $index => $rec):
?>
<div class="accordion-item">
<h2 class="accordion-header" id="heading<?php echo $index; ?>">
<button class="accordion-button <?php echo $index > 0 ? 'collapsed' : ''; ?>" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $index; ?>" aria-expanded="<?php echo $index === 0 ? 'true' : 'false'; ?>" aria-controls="collapse<?php echo $index; ?>">
<?php echo htmlspecialchars($rec['title']); ?>
</button>
</h2>
<div id="collapse<?php echo $index; ?>" class="accordion-collapse collapse <?php echo $index === 0 ? 'show' : ''; ?>" aria-labelledby="heading<?php echo $index; ?>" data-bs-parent="#recommendationsAccordion">
<div class="accordion-body">
<?php echo htmlspecialchars($rec['description']); ?>
</div>
</div>
</div>
<?php
endforeach; ?>
</div>
<?php else:
?>
<p>No specific recommendations available at this time.</p>
<?php
endif; ?>
<hr class="my-4">
<h2>Next Steps</h2>
<?php if (!empty($nextSteps)):
?>
<ul>
<?php foreach ($nextSteps as $step):
?>
<li><?php echo htmlspecialchars($step); ?></li>
<?php
endforeach; ?>
</ul>
<?php else:
?>
<p>No specific next steps available at this time.</p>
<?php
endif; ?>
<?php endif; ?>
</div>
<div class="card-footer text-center">
<a href="index.php" class="btn btn-primary">Take the Survey Again</a>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const scores = <?php echo json_encode($scores); ?>;
const canvas = document.getElementById('burnoutChart');
if (canvas) {
const ctx = canvas.getContext('2d');
const burnoutChart = new Chart(ctx, {
type: 'radar',
data: {
labels: Object.keys(scores),
datasets: [{
label: 'Burnout Dimensions',
data: Object.values(scores),
backgroundColor: 'rgba(0, 123, 255, 0.2)',
borderColor: 'rgba(0, 123, 255, 1)',
borderWidth: 1
}]
},
options: {
scales: {
r: {
angleLines: {
display: false
},
suggestedMin: 0,
suggestedMax: 5
}
}
}
});
}
});
</script>
</body>
</html>