<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
add_stylesheet('<link rel="stylesheet" href="'.$list_skin_url.'/style.css">', 0);
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.list.css">', 0);
// 기존 로직 유지 (수정 금지)
$sfl_val = isset($sfl) ? $sfl : '';
$stx_val = isset($stx) ? $stx : '';
$base_url = get_pretty_url($bo_table);
$search_url = (strpos($base_url, '?') !== false) ? $base_url . '&' : $base_url . '?';
// 파라미터 규칙 (|| 두 개 필수) - 절대 유지
$sfl_target = 'x2_transaction_type||x2_type';
$bank_url = "board.php?bo_table=".$bo_table."&sfl=".$sfl_target."&stx=default+KRW";
$coin_url = "board.php?bo_table=".$bo_table."&sfl=x2_type&stx=A+B+C+D+E+F+G+H+I+J+L+M+N+O+P+Q+S+T+U+V+X+Y+Z&sop=or";
$interest_url = "board.php?bo_table=".$bo_table."&sfl=x2_transaction_type||x2_type&stx=internal+".urlencode('KRW');
// 년도 설정을 위한 변수 (2017 ~ 현재년도)
$current_year = date("Y");
$start_year = 2017;
$write_base = "board.php?bo_table=".$bo_table."&act=write";
?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
</style>
<div id="bo_list">
<div class="list-container">
<div class="list-header-title">
<h1><?php echo strtoupper($bo_table); ?></h1>
<p><?php echo $board['bo_subject']; ?></p>
</div>
<?php include $board_skin_path . '/api_assets.php'; ?>
<div class="top-action-bar">
<div class="filter-buttons">
<a href="<?php echo $base_url; ?>" class="btn-filter <?php echo ($stx_val == '') ? 'active' : ''; ?>">전체보기</a>
<select class="sel-filter" onchange="location.href='<?php echo $search_url; ?>sfl=x2_time&stx='+this.value;">
<option value="">년도 선택</option>
<?php for($y = $current_year; $y >= $start_year; $y--) { ?>
<option value="<?php echo $y; ?>" <?php echo ($sfl_val == 'x2_time' && $stx_val == $y) ? 'selected' : ''; ?>><?php echo $y; ?>년</option>
<?php } ?>
</select>
<a href="<?php echo $search_url.'sfl=x2_direction&stx='.urlencode('입금'); ?>" class="btn-filter <?php echo ($stx_val == '입금') ? 'active' : ''; ?>">입금</a>
<a href="<?php echo $search_url.'sfl=x2_direction&stx='.urlencode('출금'); ?>" class="btn-filter <?php echo ($stx_val == '출금') ? 'active' : ''; ?>">출금</a>
<a href="<?php echo $bank_url; ?>" class="btn-filter <?php echo (strpos($stx_val, 'KRW') !== false) ? 'active' : ''; ?>">은행</a>
<a href="<?php echo $coin_url; ?>" class="btn-filter <?php echo ($sop == 'or' && strpos($sfl_val, 'x2_type') !== false) ? 'active' : ''; ?>">거래소</a>
<a href="<?php echo $interest_url; ?>" class="btn-filter <?php echo (strpos($stx_val, 'internal') !== false) ? 'active' : ''; ?>">이자</a>
</div>
<div class="right-tools">
<div class="realtime-search-wrap">
<input type="text" id="uuid_search" placeholder="UUID 실시간 필터링..." onkeyup="filterUUID()">
</div>
<div class="admin-buttons">
<?php if ($admin_href) { ?><a href="<?php echo $admin_href ?>" class="btn-top btn-top-admin">ADMIN</a><?php } ?>
<?php if ($is_admin) { ?><a href="<?php echo $write_href ?>" class="btn-top btn-write">WRITE</a><?php } ?>
</div>
</div>
</div>
<div class="data-card">
<table class="tbl-data" id="main_table">
<thead>
<tr>
<th style="width:90px;">#</th>
<th style="width:90px;">방향</th>
<th style="width:90px;">자산</th>
<th style="width:100px;">상태</th>
<th style="width:100px;">거래유형</th>
<th style="width:150px;">금액</th>
<th style="width:80px;">수수료</th>
<th>UUID</th>
<th style="width:300px;">지갑주소</th>
<th style="width:190px;">제목(기록상세)</th>
<th style="width:150px;">거래일시</th>
</tr>
</thead>
<tbody>
<?php for ($i=0; $i<count($list); $i++) {
$dir = strtoupper($list[$i]['x2_direction']);
$is_in = (stripos($dir, '입금') !== false || $dir == 'IN' || $dir == 'DEPOSIT');
$box_class = $is_in ? 'bg-in' : 'bg-out';
$amt_color = $is_in ? '#10b981' : '#ef4444';
?>
<tr class="data-row" onclick="location.href='<?php echo $list[$i]['href'] ?>'">
<td class="td-num"><?php echo $list[$i]['num'] ?></td>
<td class="td-directio"><span class="dir-box <?php echo $box_class; ?>"><?php echo $dir; ?></span></td>
<td class="td-type"><span><?php echo $list[$i]['x2_type'] ?></span></td>
<td style="text-align:center;">
<?php
$st = strtoupper($list[$i]['x2_state']);
$st_class = ($st == 'DONE' || $st == '완료') ? 'st-done' : (($st == 'CANCELLED' || $st == '취소') ? 'st-fail' : 'st-wait');
echo "<span class='{$st_class}'>{$st}</span>";
?>
</td>
<td style="text-align:center; color:#94a3b8;"><?php echo $list[$i]['x2_transaction_type'] ?></td>
<td style="text-align:right; font-weight:800; color:<?php echo $amt_color; ?>; font-family: monospace; font-size:15px;"><?php echo number_format($list[$i]['x2_amount'], 4) ?></td>
<td style="text-align:right; color:#ef4444; font-size:13px;"><?php echo $list[$i]['x2_fee'] ?></td>
<td class="uuid-cell" style="color:#64748b;"><?php echo $list[$i]['x2_uuid'] ?></td>
<td><?php echo $list[$i]['x2_address'] ?></td>
<td style="color:#94a3b8;"><?php echo $list[$i]['subject'] ?></td>
<td style="text-align:center; color:#94a3b8; font-size:12px;"><?php echo substr($list[$i]['x2_time'], 0, 10) ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php if ($total_page > 1) { ?>
<div id="TERM_PAGING_DIRECT">
<?php
$pg_count = $config['cf_write_pages'];
$start_pg = ( ( (int)( ($page - 1 ) / $pg_count ) ) * $pg_count ) + 1;
$end_pg = $start_pg + $pg_count - 1;
if ($end_pg >= $total_page) $end_pg = $total_page;
if ($page > 1) { echo '<a href="'.get_pretty_url($bo_table, '', $qstr.'&page=1').'" class="trm-btn">시작</a>'; }
if ($start_pg > 1) { echo '<a href="'.get_pretty_url($bo_table, '', $qstr.'&page='.($start_pg-1)).'" class="trm-btn">이전</a>'; }
for ($k=$start_pg; $k<=$end_pg; $k++) {
if ($page != $k) { echo '<a href="'.get_pretty_url($bo_table, '', $qstr.'&page='.$k).'" class="trm-btn">'.$k.'</a>'; }
else { echo '<strong class="trm-btn trm-current">'.$k.'</strong>'; }
}
if ($total_page > $end_pg) { echo '<a href="'.get_pretty_url($bo_table, '', $qstr.'&page='.($end_pg+1)).'" class="trm-btn">다음</a>'; }
if ($page < $total_page) { echo '<a href="'.get_pretty_url($bo_table, '', $qstr.'&page='.$total_page).'" class="trm-btn">끝</a>'; }
?>
</div>
<?php } ?>
</div>
</div>
<script>
function filterUUID() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("uuid_search");
filter = input.value.toUpperCase();
table = document.getElementById("main_table");
tr = table.getElementsByClassName("data-row");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByClassName("uuid-cell")[0];
if (td) {
txtValue = td.textContent || td.innerText;
tr[i].style.display = (txtValue.toUpperCase().indexOf(filter) > -1) ? "" : "none";
}
}
}
</script>