68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
require_once '../includes/header.php';
|
|
require_once '../db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'coach') {
|
|
header('Location: /login.php');
|
|
exit;
|
|
}
|
|
|
|
$coach_id = $_SESSION['user_id'];
|
|
|
|
if (!isset($_GET['id'])) {
|
|
header('Location: surveys.php');
|
|
exit;
|
|
}
|
|
|
|
$client_survey_id = $_GET['id'];
|
|
|
|
// Fetch client survey details and verify coach ownership
|
|
$stmt = db()->prepare(
|
|
'SELECT cs.*, s.title, s.description, c.name as client_name ' .
|
|
'FROM client_surveys cs ' .
|
|
'JOIN surveys s ON cs.survey_id = s.id ' .
|
|
'JOIN clients c ON cs.client_id = c.id ' .
|
|
'WHERE cs.id = ? AND s.coach_id = ?'
|
|
);
|
|
$stmt->execute([$client_survey_id, $coach_id]);
|
|
$client_survey = $stmt->fetch();
|
|
|
|
if (!$client_survey) {
|
|
header('Location: surveys.php');
|
|
exit;
|
|
}
|
|
|
|
// Fetch questions and responses
|
|
$qa_stmt = db()->prepare(
|
|
'SELECT q.question, qr.response ' .
|
|
'FROM survey_responses qr ' .
|
|
'JOIN survey_questions q ON qr.question_id = q.id ' .
|
|
'WHERE qr.client_survey_id = ? ORDER BY q.id'
|
|
);
|
|
$qa_stmt->execute([$client_survey_id]);
|
|
$qas = $qa_stmt->fetchAll();
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<h3>Survey Responses from <?php echo htmlspecialchars($client_survey['client_name']); ?></h3>
|
|
<h4><?php echo htmlspecialchars($client_survey['title']); ?></h4>
|
|
|
|
<div class="card mt-4">
|
|
<div class="card-body">
|
|
<?php foreach ($qas as $qa): ?>
|
|
<div class="mb-4">
|
|
<p class="font-weight-bold"><strong><?php echo htmlspecialchars($qa['question']); ?></strong></p>
|
|
<p class="text-muted"><?php echo nl2br(htmlspecialchars($qa['response'])); ?></p>
|
|
</div>
|
|
<hr>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<a href="survey_responses.php?id=<?php echo $client_survey['survey_id']; ?>" class="btn btn-secondary">Back to All Responses</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once '../includes/footer.php'; ?>
|