Files
2026-06-11 18:47:38 +09:00

292 lines
7.1 KiB
PHP

<?php
$sub_menu = '710500';
include_once('./_common.php');
auth_check_menu($auth, $sub_menu, "r");
$g5['title'] = '통계 분석';
include_once(G5_ADMIN_PATH.'/admin.head.php');
// 통계 분석 가능한 설문 목록 (완료된 응답이 있는 설문들)
$sql = "SELECT sm.*,
COUNT(sr.sr_id) as total_responses,
COUNT(CASE WHEN sr.sr_status = 'completed' THEN 1 END) as completed_responses
FROM survey_master sm
LEFT JOIN survey_responses sr ON sm.sv_id = sr.sv_id
WHERE sm.sv_status != 'deleted'
GROUP BY sm.sv_id
HAVING completed_responses > 0
ORDER BY sm.sv_created_at DESC";
$result = sql_query($sql);
?>
<style>
.statistics-header {
display: flex;
justify-content: between;
align-items: center;
margin-bottom: 20px;
padding: 20px;
background: linear-gradient(135deg, #AA20FF 0%, #8A1ACC 100%);
color: white;
border-radius: 8px;
}
.survey-stats-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.survey-stats-card {
background: white;
border-radius: 12px;
padding: 25px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
transition: all 0.3s ease;
border-left: 4px solid #AA20FF;
}
.survey-stats-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.survey-card-header {
margin-bottom: 20px;
}
.survey-title {
font-size: 1.3em;
font-weight: 600;
color: #333;
margin-bottom: 8px;
line-height: 1.3;
}
.survey-meta {
display: flex;
gap: 15px;
font-size: 0.9em;
color: #666;
margin-bottom: 15px;
}
.survey-stats-info {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
margin-bottom: 20px;
}
.stat-item {
text-align: center;
padding: 15px;
background: #fff;
border-radius: 8px;
}
.stat-number {
font-size: 1.8em;
font-weight: 700;
color: #AA20FF;
margin-bottom: 5px;
}
.stat-label {
font-size: 0.8em;
color: #666;
font-weight: 500;
text-transform: uppercase;
}
.survey-actions {
display: flex;
gap: 10px;
justify-content: center;
}
.btn-stats {
flex: 1;
padding: 10px 15px;
background: #AA20FF;
color: white;
text-decoration: none;
border-radius: 6px;
text-align: center;
font-weight: 500;
transition: all 0.3s ease;
border: none;
cursor: pointer;
}
.btn-stats:hover {
background: #8A1ACC;
color: white;
transform: translateY(-1px);
}
.btn-export {
background: #28a745;
}
.btn-export:hover {
background: #218838;
}
.empty-state {
text-align: center;
padding: 80px 20px;
color: #666;
}
.empty-state i {
font-size: 4em;
margin-bottom: 20px;
opacity: 0.3;
}
.completion-rate {
display: flex;
align-items: center;
gap: 10px;
margin-top: 10px;
}
.progress-bar {
flex: 1;
height: 6px;
background: #e0e0e0;
border-radius: 3px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #AA20FF 0%, #8A1ACC 100%);
border-radius: 3px;
transition: width 0.5s ease;
}
.progress-text {
font-size: 0.9em;
font-weight: 600;
color: #AA20FF;
min-width: 40px;
}
/* 반응형 */
@media (max-width: 768px) {
.survey-stats-grid {
grid-template-columns: 1fr;
}
.survey-stats-info {
grid-template-columns: 1fr;
}
.survey-actions {
flex-direction: column;
}
.survey-meta {
flex-direction: column;
gap: 5px;
}
}
</style>
<div class="statistics-header">
<div>
<h1><i class="fa fa-chart-bar"></i> 통계 분석</h1>
<p>설문별 응답 현황과 통계를 확인할 수 있습니다</p>
</div>
</div>
<?php if (sql_num_rows($result) > 0): ?>
<div class="survey-stats-grid">
<?php while ($survey = sql_fetch_array($result)): ?>
<?php
$completion_rate = $survey['total_responses'] > 0 ?
round(($survey['completed_responses'] / $survey['total_responses']) * 100, 1) : 0;
// 평균 응답 시간 계산
$avg_time_sql = "
SELECT AVG(TIMESTAMPDIFF(MINUTE, sr_started_at, sr_completed_at)) as avg_minutes
FROM survey_responses
WHERE sv_id = '{$survey['sv_id']}'
AND sr_status = 'completed'
AND sr_completed_at IS NOT NULL
";
$avg_time_result = sql_fetch($avg_time_sql);
$avg_response_time = round($avg_time_result['avg_minutes'] ?? 0, 1);
?>
<div class="survey-stats-card">
<div class="survey-card-header">
<h3 class="survey-title"><?php echo htmlspecialchars($survey['sv_title']); ?></h3>
<div class="survey-meta">
<span><i class="fa fa-user"></i> <?php echo $survey['sv_created_by']; ?></span>
<span><i class="fa fa-calendar"></i> <?php echo date('Y-m-d', strtotime($survey['sv_created_at'])); ?></span>
<span class="status-badge status-<?php echo $survey['sv_status']; ?>">
<?php
$status_text = [
'draft' => '작성중',
'active' => '진행중',
'closed' => '종료',
'deleted' => '삭제됨'
];
echo $status_text[$survey['sv_status']];
?>
</span>
</div>
</div>
<div class="survey-stats-info">
<div class="stat-item">
<div class="stat-number"><?php echo number_format($survey['completed_responses']); ?></div>
<div class="stat-label">완료된 응답</div>
</div>
<div class="stat-item">
<div class="stat-number"><?php echo $avg_response_time; ?>분</div>
<div class="stat-label">평균 응답시간</div>
</div>
</div>
<div class="completion-rate">
<div class="progress-bar">
<div class="progress-fill" style="width: <?php echo $completion_rate; ?>%"></div>
</div>
<div class="progress-text"><?php echo $completion_rate; ?>%</div>
</div>
<div class="survey-actions">
<a href="statistics.php?sv_id=<?php echo $survey['sv_id']; ?>" class="btn-stats">
<i class="fa fa-chart-bar"></i> 통계 보기
</a>
<a href="export.php?sv_id=<?php echo $survey['sv_id']; ?>" class="btn-stats btn-export">
<i class="fa fa-file-excel"></i> 내보내기
</a>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else: ?>
<div class="empty-state">
<i class="fa fa-chart-bar"></i>
<h3>통계 분석 가능한 설문이 없습니다</h3>
<p>완료된 응답이 있는 설문만 통계 분석이 가능합니다.</p>
<a href="survey_list.php" style="color: #AA20FF; margin-top: 15px; display: inline-block;">
설문 목록으로 이동
</a>
</div>
<?php endif; ?>
<?php
include_once(G5_ADMIN_PATH.'/admin.tail.php');
?>
</content>
</invoke>