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

452 lines
13 KiB
PHP

<?php
$sub_menu = '710304';
include_once('./_common.php');
auth_check_menu($auth, $sub_menu, "r");
$g5['title'] = '응답 관리';
include_once(G5_ADMIN_PATH.'/admin.head.php');
// 설문 선택
$sv_id = isset($_GET['sv_id']) ? (int)$_GET['sv_id'] : 0;
// 설문 목록 가져오기
$survey_list = array();
$survey_sql = "SELECT sv_id, sv_title FROM survey_master ORDER BY sv_created_at DESC";
$survey_result = sql_query($survey_sql);
while ($survey_row = sql_fetch_array($survey_result)) {
$survey_list[] = $survey_row;
}
if ($sv_id) {
$survey = get_survey($sv_id);
if (!$survey) {
alert('존재하지 않는 설문입니다.', 'response_list.php');
}
}
// 변수 초기화
$sfl = isset($_GET['sfl']) ? clean_xss_tags($_GET['sfl']) : 'sr_mb_id';
$stx = isset($_GET['stx']) ? clean_xss_tags($_GET['stx']) : '';
$status = isset($_GET['status']) ? clean_xss_tags($_GET['status']) : '';
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
// 검색 조건
$where = " WHERE 1=1 ";
$sql_search = "";
if ($sv_id) {
$where .= " AND sr.sv_id = '".sql_real_escape_string($sv_id)."' ";
$sql_search .= "&sv_id=$sv_id";
}
if ($stx) {
if ($sfl == 'sr_mb_id') {
$where .= " AND sr.sr_mb_id LIKE '%".sql_real_escape_string($stx)."%' ";
} elseif ($sfl == 'sr_ip') {
$where .= " AND sr.sr_ip LIKE '%".sql_real_escape_string($stx)."%' ";
}
$sql_search .= "&sfl=$sfl&stx=".urlencode($stx);
}
if ($status) {
$where .= " AND sr.sr_status = '".sql_real_escape_string($status)."' ";
$sql_search .= "&status=".urlencode($status);
}
// 페이징
$sql_common = " FROM survey_responses sr
LEFT JOIN survey_master sm ON sr.sv_id = sm.sv_id
$where ";
$sql = " SELECT COUNT(*) as cnt $sql_common ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$rows = 20;
$total_page = ceil($total_count / $rows);
if ($page < 1) $page = 1;
$from_record = ($page - 1) * $rows;
$sql = " SELECT sr.*, sm.sv_title
$sql_common
ORDER BY sr.sr_started_at DESC
LIMIT $from_record, $rows ";
$result = sql_query($sql);
// 상태별 카운트
$status_counts = array();
$status_where = $sv_id ? " WHERE sv_id = '$sv_id' " : " WHERE 1=1 ";
$status_sql = "SELECT sr_status, COUNT(*) as cnt FROM survey_responses $status_where GROUP BY sr_status";
$status_result = sql_query($status_sql);
while ($status_row = sql_fetch_array($status_result)) {
$status_counts[$status_row['sr_status']] = $status_row['cnt'];
}
?>
<style>
.response-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;
}
.response-stats {
display: flex;
gap: 20px;
margin-bottom: 20px;
}
.stat-card {
flex: 1;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
text-align: center;
border-left: 4px solid #AA20FF;
}
.stat-number {
font-size: 2em;
font-weight: bold;
color: #AA20FF;
margin-bottom: 5px;
}
.stat-label {
color: #666;
font-size: 0.9em;
}
.survey-selector {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.survey-selector select {
width: 100%;
max-width: 400px;
padding: 10px 15px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 1em;
}
.status-filter {
display: flex;
gap: 10px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.status-btn {
padding: 8px 16px;
border: 1px solid #ddd;
background: white;
color: #666;
text-decoration: none;
border-radius: 20px;
font-size: 0.9em;
transition: all 0.3s;
}
.status-btn:hover,
.status-btn.active {
background: #AA20FF;
color: white;
border-color: #AA20FF;
}
.response-table {
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.response-table table {
width: 100%;
border-collapse: collapse;
}
.response-table th {
background: #fff;
padding: 15px 10px;
text-align: left;
font-weight: 600;
border-bottom: 1px solid #dee2e6;
}
.response-table td {
padding: 15px 10px;
border-bottom: 1px solid #f1f3f4;
vertical-align: middle;
}
.response-table tr:hover {
background: #fff;
}
.status-badge {
padding: 4px 12px;
border-radius: 12px;
font-size: 0.8em;
font-weight: 500;
text-transform: uppercase;
}
.status-started { background: #fff3cd; color: #856404; }
.status-completed { background: #d4edda; color: #155724; }
.status-abandoned { background: #f8d7da; color: #721c24; }
.action-buttons {
display: flex;
gap: 5px;
}
.btn-sm {
padding: 5px 10px;
font-size: 0.8em;
border-radius: 4px;
text-decoration: none;
border: none;
cursor: pointer;
transition: all 0.3s;
}
.btn-primary { background: #007bff; color: white; }
.btn-info { background: #17a2b8; color: white; }
.btn-danger { background: #dc3545; color: white; }
.btn-sm:hover {
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.search-form {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.search-form .form-row {
display: flex;
gap: 10px;
align-items: center;
}
.search-form select,
.search-form input {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
}
/* 반응형 */
@media (max-width: 768px) {
.response-stats {
flex-direction: column;
}
.status-filter {
justify-content: center;
}
.search-form .form-row {
flex-direction: column;
}
.response-table {
font-size: 0.9em;
}
.response-table th,
.response-table td {
padding: 10px 5px;
}
.action-buttons {
flex-direction: column;
}
}
</style>
<div class="response-header">
<div>
<h1><i class="fa fa-users"></i> 응답 관리</h1>
<p>설문 응답을 관리하고 분석할 수 있습니다</p>
</div>
</div>
<div class="response-stats">
<div class="stat-card">
<div class="stat-number"><?php echo number_format($status_counts['completed'] ?? 0); ?></div>
<div class="stat-label">완료된 응답</div>
</div>
<div class="stat-card">
<div class="stat-number"><?php echo number_format($status_counts['started'] ?? 0); ?></div>
<div class="stat-label">진행중인 응답</div>
</div>
<div class="stat-card">
<div class="stat-number"><?php echo number_format($status_counts['abandoned'] ?? 0); ?></div>
<div class="stat-label">중단된 응답</div>
</div>
<div class="stat-card">
<div class="stat-number"><?php echo number_format($total_count); ?></div>
<div class="stat-label">전체 응답</div>
</div>
</div>
<div class="survey-selector">
<label for="survey_select"><strong>설문 선택:</strong></label>
<select id="survey_select" onchange="location.href='?sv_id='+this.value">
<option value="">전체 설문</option>
<?php foreach ($survey_list as $survey_item): ?>
<option value="<?php echo $survey_item['sv_id']; ?>" <?php echo $sv_id == $survey_item['sv_id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($survey_item['sv_title']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="search-form">
<form method="get" class="form-row">
<?php if ($sv_id): ?>
<input type="hidden" name="sv_id" value="<?php echo $sv_id; ?>">
<?php endif; ?>
<select name="sfl">
<option value="sr_mb_id"<?php echo $sfl == 'sr_mb_id' ? ' selected' : ''; ?>>회원ID</option>
<option value="sr_ip"<?php echo $sfl == 'sr_ip' ? ' selected' : ''; ?>>IP주소</option>
</select>
<input type="text" name="stx" value="<?php echo $stx; ?>" placeholder="검색어를 입력하세요">
<button type="submit" class="btn-sm btn-primary">
<i class="fa fa-search"></i> 검색
</button>
<?php if ($stx): ?>
<a href="?<?php echo $sv_id ? 'sv_id='.$sv_id : ''; ?>" class="btn-sm btn-warning">
<i class="fa fa-times"></i> 초기화
</a>
<?php endif; ?>
</form>
</div>
<div class="status-filter">
<a href="?<?php echo $sv_id ? 'sv_id='.$sv_id : ''; ?>" class="status-btn <?php echo !isset($_GET['status']) ? 'active' : ''; ?>">
<i class="fa fa-list"></i> 전체
</a>
<a href="?<?php echo $sv_id ? 'sv_id='.$sv_id.'&' : ''; ?>status=completed" class="status-btn <?php echo $status == 'completed' ? 'active' : ''; ?>">
<i class="fa fa-check"></i> 완료 (<?php echo $status_counts['completed'] ?? 0; ?>)
</a>
<a href="?<?php echo $sv_id ? 'sv_id='.$sv_id.'&' : ''; ?>status=started" class="status-btn <?php echo $status == 'started' ? 'active' : ''; ?>">
<i class="fa fa-play"></i> 진행중 (<?php echo $status_counts['started'] ?? 0; ?>)
</a>
<a href="?<?php echo $sv_id ? 'sv_id='.$sv_id.'&' : ''; ?>status=abandoned" class="status-btn <?php echo $status == 'abandoned' ? 'active' : ''; ?>">
<i class="fa fa-times"></i> 중단 (<?php echo $status_counts['abandoned'] ?? 0; ?>)
</a>
</div>
<div class="response-table">
<table>
<thead>
<tr>
<th width="60">ID</th>
<?php if (!$sv_id): ?>
<th>설문 제목</th>
<?php endif; ?>
<th width="100">응답자</th>
<th width="120">IP주소</th>
<th width="80">상태</th>
<th width="120">시작시간</th>
<th width="120">완료시간</th>
<th width="150">관리</th>
</tr>
</thead>
<tbody>
<?php
if (sql_num_rows($result) > 0) {
while ($row = sql_fetch_array($result)) {
// 상태별 클래스
$status_class = 'status-' . $row['sr_status'];
$status_text = array(
'started' => '진행중',
'completed' => '완료',
'abandoned' => '중단'
);
?>
<tr>
<td><?php echo $row['sr_id']; ?></td>
<?php if (!$sv_id): ?>
<td>
<strong><?php echo htmlspecialchars($row['sv_title']); ?></strong>
</td>
<?php endif; ?>
<td><?php echo $row['sr_mb_id'] ?: '익명'; ?></td>
<td><?php echo $row['sr_ip']; ?></td>
<td>
<span class="status-badge <?php echo $status_class; ?>">
<?php echo $status_text[$row['sr_status']]; ?>
</span>
</td>
<td>
<small><?php echo date('Y-m-d H:i', strtotime($row['sr_started_at'])); ?></small>
</td>
<td>
<?php if ($row['sr_completed_at']): ?>
<small><?php echo date('Y-m-d H:i', strtotime($row['sr_completed_at'])); ?></small>
<?php else: ?>
<span style="color: #999;">-</span>
<?php endif; ?>
</td>
<td>
<div class="action-buttons">
<?php if ($row['sr_status'] == 'completed'): ?>
<a href="response_view.php?sr_id=<?php echo $row['sr_id']; ?>" class="btn-sm btn-primary" title="응답 보기">
<i class="fa fa-eye"></i>
</a>
<a href="statistics.php?sv_id=<?php echo $row['sv_id']; ?>" class="btn-sm btn-info" title="통계">
<i class="fa fa-chart-bar"></i>
</a>
<?php endif; ?>
<a href="response_delete.php?sr_id=<?php echo $row['sr_id']; ?>" class="btn-sm btn-danger" title="삭제" onclick="return confirm('정말 삭제하시겠습니까?')">
<i class="fa fa-trash"></i>
</a>
</div>
</td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="<?php echo $sv_id ? '7' : '8'; ?>" style="text-align: center; padding: 50px; color: #999;">
<i class="fa fa-inbox" style="font-size: 3em; margin-bottom: 20px; display: block;"></i>
등록된 응답이 없습니다.
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php
// 페이징
if ($total_page > 1) {
$paging = get_paging(10, $page, $total_page, "?$sql_search&page=");
echo '<div style="margin-top: 20px;">' . $paging . '</div>';
}
?>
<?php
include_once(G5_ADMIN_PATH.'/admin.tail.php');
?>