2024-07-17 02:27:24 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Form Responses</title>
|
2024-07-17 10:35:29 +00:00
|
|
|
<link rel= "stylesheet" href = "<?= base_url() ?>assets/css/style.css">
|
2024-07-17 02:27:24 +00:00
|
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
2024-07-17 10:35:29 +00:00
|
|
|
align-items: flex-start; /* Change align-items to flex-start to avoid centering */
|
2024-07-17 02:27:24 +00:00
|
|
|
height: 100vh;
|
|
|
|
margin: 0;
|
2024-07-17 10:35:29 +00:00
|
|
|
font-family: Roboto, sans-serif;
|
|
|
|
background-color: #f0ebf8;
|
|
|
|
overflow-y: auto; /* Ensure vertical scrolling is enabled */
|
2024-07-17 02:27:24 +00:00
|
|
|
}
|
|
|
|
.container {
|
2024-07-17 10:35:29 +00:00
|
|
|
width: 90%;
|
|
|
|
max-width: 700px;
|
2024-07-17 02:27:24 +00:00
|
|
|
padding: 20px;
|
|
|
|
background: #f9f9f9;
|
|
|
|
border-radius: 8px;
|
|
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
2024-07-17 10:35:29 +00:00
|
|
|
margin: 20px 0; /* Add margin to the top and bottom to provide space around the container */
|
|
|
|
}
|
|
|
|
.question-box {
|
|
|
|
margin-bottom: 20px;
|
|
|
|
padding: 15px;
|
|
|
|
background: #ffffff;
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
border-radius: 8px;
|
|
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
|
|
}
|
|
|
|
.question-title {
|
|
|
|
font-size: 18px;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
color: #333;
|
2024-07-17 02:27:24 +00:00
|
|
|
}
|
|
|
|
.chart-container {
|
2024-07-17 10:35:29 +00:00
|
|
|
margin-top: 30px;
|
2024-07-17 02:27:24 +00:00
|
|
|
margin-bottom: 20px;
|
2024-07-17 10:35:29 +00:00
|
|
|
width:300px;
|
|
|
|
margin-left:200px;
|
|
|
|
|
2024-07-17 02:27:24 +00:00
|
|
|
}
|
|
|
|
.paragraph-answer {
|
|
|
|
margin-bottom: 10px;
|
2024-07-17 10:35:29 +00:00
|
|
|
padding: 10px;
|
|
|
|
background: #f5f5f5;
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
.paragraph-answer p {
|
|
|
|
margin: 0;
|
2024-07-17 02:27:24 +00:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<h1 style="text-align: center;">Form Responses</h1>
|
|
|
|
<?php foreach ($data as $question_id => $question): ?>
|
2024-07-17 10:35:29 +00:00
|
|
|
<div class="question-box">
|
|
|
|
<h2 class="question-title"><?php echo $question['question_text']; ?></h2>
|
2024-07-17 02:27:24 +00:00
|
|
|
<?php if ($question['question_type'] == 'multiple-choice'): ?>
|
|
|
|
<?php if (!empty($question['options'])): ?>
|
|
|
|
<div class="chart-container">
|
|
|
|
<canvas id="chart-<?php echo $question_id; ?>"></canvas>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
var ctx = document.getElementById('chart-<?php echo $question_id; ?>').getContext('2d');
|
|
|
|
var chartData = {
|
|
|
|
labels: [],
|
|
|
|
datasets: [{
|
|
|
|
label: 'Responses',
|
|
|
|
data: [],
|
|
|
|
backgroundColor: [],
|
|
|
|
borderColor: [],
|
|
|
|
borderWidth: 1
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var backgroundColors = [
|
|
|
|
'rgba(255, 99, 132, 0.2)',
|
|
|
|
'rgba(54, 162, 235, 0.2)',
|
|
|
|
'rgba(255, 206, 86, 0.2)',
|
|
|
|
'rgba(75, 192, 192, 0.2)',
|
|
|
|
'rgba(153, 102, 255, 0.2)',
|
|
|
|
'rgba(255, 159, 64, 0.2)'
|
|
|
|
];
|
|
|
|
var borderColors = [
|
|
|
|
'rgba(255, 99, 132, 1)',
|
|
|
|
'rgba(54, 162, 235, 1)',
|
|
|
|
'rgba(255, 206, 86, 1)',
|
|
|
|
'rgba(75, 192, 192, 1)',
|
|
|
|
'rgba(153, 102, 255, 1)',
|
|
|
|
'rgba(255, 159, 64, 1)'
|
|
|
|
];
|
|
|
|
|
|
|
|
var colorIndex = 0;
|
|
|
|
|
|
|
|
<?php foreach ($question['options'] as $option_text => $count): ?>
|
|
|
|
chartData.labels.push('<?php echo $option_text; ?>');
|
|
|
|
chartData.datasets[0].data.push(<?php echo $count; ?>);
|
|
|
|
chartData.datasets[0].backgroundColor.push(backgroundColors[colorIndex % backgroundColors.length]);
|
|
|
|
chartData.datasets[0].borderColor.push(borderColors[colorIndex % borderColors.length]);
|
|
|
|
colorIndex++;
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
|
|
var chart = new Chart(ctx, {
|
|
|
|
type: 'pie',
|
|
|
|
data: chartData
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php elseif ($question['question_type'] == 'checkbox'): ?>
|
|
|
|
<?php if (!empty($question['options'])): ?>
|
|
|
|
<div class="chart-container">
|
|
|
|
<canvas id="chart-<?php echo $question_id; ?>"></canvas>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
var ctx = document.getElementById('chart-<?php echo $question_id; ?>').getContext('2d');
|
|
|
|
var chartData = {
|
|
|
|
labels: [],
|
|
|
|
datasets: [{
|
|
|
|
label: 'Responses',
|
|
|
|
data: [],
|
|
|
|
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
|
|
|
borderColor: 'rgba(75, 192, 192, 1)',
|
|
|
|
borderWidth: 1
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
<?php foreach ($question['options'] as $option_text => $count): ?>
|
|
|
|
chartData.labels.push('<?php echo $option_text; ?>');
|
|
|
|
chartData.datasets[0].data.push(<?php echo $count; ?>);
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
|
|
var chart = new Chart(ctx, {
|
|
|
|
type: 'bar',
|
|
|
|
data: chartData,
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
y: {
|
|
|
|
beginAtZero: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php elseif ($question['question_type'] == 'paragraph'): ?>
|
|
|
|
<?php foreach ($question['answers'] as $answer): ?>
|
|
|
|
<div class="paragraph-answer">
|
|
|
|
<p>
|
|
|
|
<?php
|
|
|
|
$words = explode(' ', $answer);
|
|
|
|
echo implode(' ', array_slice($words, 0, 5));
|
|
|
|
if (count($words) > 5) echo '...';
|
|
|
|
?>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|