지난 시간에는 신청폼에 입력하는 데이터를 게시판에 쌓이도록 했다.
이번에는 게시판에 쌓이는 데이터를 관리자에서 확인할 수 있도록 해본다.
관리자 메뉴에서 상담 내역을 표로 조회하는 것부터 시작한다.
1. /adm/consultation_list.php 생성
<?php
$sub_menu = '910100';
include_once('./_common.php');
if ($is_admin !== 'super') {
alert('최고관리자만 접근할 수 있습니다.');
}
$g5['title'] = '상담 신청 관리';
include_once(G5_ADMIN_PATH.'/admin.head.php');
$bo_table = 'consultation';
$write_table = $g5['write_prefix'].$bo_table;
// 검색값
$search_field = isset($_GET['search_field'])
? $_GET['search_field']
: '';
$search_keyword = isset($_GET['search_keyword'])
? trim($_GET['search_keyword'])
: '';
$consult_part = isset($_GET['consult_part'])
? trim($_GET['consult_part'])
: '';
$where = array();
if ($search_keyword !== '') {
$keyword = sql_escape_string($search_keyword);
if ($search_field === 'name') {
$where[] = "wr_name like '%{$keyword}%'";
} elseif ($search_field === 'phone') {
$phone_keyword = preg_replace('/[^0-9]/', '', $search_keyword);
$phone_keyword = sql_escape_string($phone_keyword);
$where[] = "wr_3 like '%{$phone_keyword}%'";
}
}
$allowed_parts = array(
'유륜',
'외음부',
'팔꿈치',
'겨드랑이',
'기타 부위'
);
if (in_array($consult_part, $allowed_parts, true)) {
$part = sql_escape_string($consult_part);
$where[] = "wr_1 = '{$part}'";
}
$where_sql = '';
if (!empty($where)) {
$where_sql = ' where '.implode(' and ', $where);
}
// 전체 개수
$row = sql_fetch("
select count(*) as cnt
from {$write_table}
{$where_sql}
");
$total_count = (int) $row['cnt'];
// 페이지 설정
$rows = 20;
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
if ($page < 1) {
$page = 1;
}
$total_page = ceil($total_count / $rows);
if ($total_page > 0 && $page > $total_page) {
$page = $total_page;
}
$from_record = ($page - 1) * $rows;
// 상담 목록
$result = sql_query("
select *
from {$write_table}
{$where_sql}
order by wr_id desc
limit {$from_record}, {$rows}
");
// 검색조건 유지
$query_params = array(
'search_field' => $search_field,
'search_keyword' => $search_keyword,
'consult_part' => $consult_part
);
$query_string = http_build_query($query_params);
?>
<style>
.consultation-summary {
margin: 0 0 15px;
font-size: 14px;
}
.consultation-table td {
vertical-align: middle;
}
.consultation-table .consult-name {
font-weight: 700;
}
.consultation-table .consult-phone {
white-space: nowrap;
}
.consultation-empty {
padding: 60px 10px !important;
text-align: center;
}
.consultation-search {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-bottom: 15px;
}
.consultation-search select,
.consultation-search input {
height: 35px;
}
.consultation-search input {
width: 220px;
padding: 0 10px;
border: 1px solid #d5d5d5;
}
.consultation-status {
display: inline-block;
padding: 5px 9px;
border-radius: 20px;
background: #f1f3f5;
font-size: 12px;
}
</style>
<div class="local_ov01 local_ov">
전체 상담 신청
<strong><?php echo number_format($total_count); ?>건</strong>
</div>
<form method="get" class="consultation-search">
<select name="consult_part">
<option value="">전체 상담 부위</option>
<?php foreach ($allowed_parts as $part) { ?>
<option
value="<?php echo get_text($part); ?>"
<?php echo $consult_part === $part ? 'selected' : ''; ?>
>
<?php echo get_text($part); ?>
</option>
<?php } ?>
</select>
<select name="search_field">
<option
value="name"
<?php echo $search_field === 'name' ? 'selected' : ''; ?>
>
성함
</option>
<option
value="phone"
<?php echo $search_field === 'phone' ? 'selected' : ''; ?>
>
연락처
</option>
</select>
<input
type="text"
name="search_keyword"
value="<?php echo get_text($search_keyword); ?>"
placeholder="검색어를 입력해주세요"
>
<button type="submit" class="btn btn_02">검색</button>
<a href="./consultation_list.php" class="btn btn_01">
초기화
</a>
</form>
<div class="tbl_head01 tbl_wrap">
<table class="consultation-table">
<caption>상담 신청 목록</caption>
<thead>
<tr>
<th scope="col">번호</th>
<th scope="col">접수일</th>
<th scope="col">성함</th>
<th scope="col">연락처</th>
<th scope="col">상담 부위</th>
<th scope="col">통화 가능 시간</th>
<th scope="col">상태</th>
</tr>
</thead>
<tbody>
<?php
$list_num = $total_count - $from_record;
for ($i = 0; $row = sql_fetch_array($result); $i++) {
$status = $row['wr_5'] !== ''
? $row['wr_5']
: '상담 전';
$phone = preg_replace(
'/^(01[0-9])([0-9]{3,4})([0-9]{4})$/',
'$1-$2-$3',
$row['wr_3']
);
?>
<tr>
<td class="td_num">
<?php echo number_format($list_num); ?>
</td>
<td class="td_datetime">
<?php echo get_text($row['wr_datetime']); ?>
</td>
<td class="consult-name">
<?php echo get_text($row['wr_name']); ?>
</td>
<td class="consult-phone">
<?php echo get_text($phone); ?>
</td>
<td>
<?php echo get_text($row['wr_1']); ?>
</td>
<td>
<?php echo get_text($row['wr_2']); ?>
</td>
<td>
<span class="consultation-status">
<?php echo get_text($status); ?>
</span>
</td>
</tr>
<?php
$list_num--;
}
if ($i === 0) {
?>
<tr>
<td colspan="7" class="consultation-empty">
등록된 상담 신청이 없습니다.
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php
echo get_paging(
G5_IS_MOBILE ? 5 : 10,
$page,
$total_page,
'./consultation_list.php?'.$query_string.'&page='
);
include_once(G5_ADMIN_PATH.'/admin.tail.php');
?>
2. 관리자 메뉴 파일 생성
/adm 폴더에 admin.menu910.php가 이미 있는지 먼저 확인한 뒤, 없으면 새로 만들고 아래 내용을 넣는다.
<?php
if (!defined('_GNUBOARD_')) exit;
$menu['menu910'] = array(
array('910000', '상담 관리', G5_ADMIN_URL.'/consultation_list.php', 'consultation'),
array('910100', '상담 신청 관리', G5_ADMIN_URL.'/consultation_list.php', 'consultation_list')
);
?>
3. 확인
파일 2개를 업로드 후 관리자 페이지를 새로고침한다.
consultation_list.phpadmin.menu910.php
관리자 페이지에 consultation 게시판의 상담 신청이 표로 나오게 된다.

답글 남기기