GNU/_PAGE/menu/board/daemon_main.php
<?php require_once '/home/www/GNU/_PAGE/head.php'; ?>

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700;800&family=Material+Symbols+Rounded:FILL@0..1" rel="stylesheet">
<link rel="stylesheet" href="<?php echo G5_URL; ?>/_PAGE/menu/board/daemon_main.css">

<div class="daemon-wrap">
	<?php
	$menu_items = array(
		'all' => '전체 : BOARD',
		'data_colle' => 'BOARD : 데이터 수집',
		'trading' => 'BOARD : 매매',
		'upbit' => 'BOARD : 업비트',
		'bybit' => 'BOARD : 바이비트',
		'daemon' => 'BOARD : 데몬'
	);

	$view = isset($_GET['view']) ? trim($_GET['view']) : 'all';
	if (!isset($menu_items[$view])) {
		$view = 'all';
	}

	$base_group_where = " gr_id in ('data_colle', 'trading', 'daemon') ";

	$list_configs = array();

	if ($view === 'all') {
		$list_configs = array(
			array(
				'title' => '데이터 수집 : BOARD',
				'label' => 'group id : data_colle',
				'group_name' => '데이터 수집',
				'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
							from {$g5['board_table']}
							where gr_id = 'data_colle'
							order by bo_order, bo_table "
			),
			array(
				'title' => '매매 : BOARD',
				'label' => 'group id : trading',
				'group_name' => '매매',
				'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
							from {$g5['board_table']}
							where gr_id = 'trading'
							order by bo_order, bo_table "
			),
			array(
				'title' => '업비트 : BOARD',
				'label' => 'prefix : _upbit',
				'group_name' => '업비트',
				'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
							from {$g5['board_table']}
							where {$base_group_where}
							and bo_table regexp '(^|_)upbit(_|$)'
							order by bo_order, bo_table "
			),
			array(
				'title' => '바이비트 : BOARD',
				'label' => 'prefix : _bybit',
				'group_name' => '바이비트',
				'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
							from {$g5['board_table']}
							where {$base_group_where}
							and bo_table regexp '(^|_)bybit(_|$)'
							order by bo_order, bo_table "
			),
            			array(
				'title' => '데몬 : BOARD',
				'label' => 'group id : daemon',
				'group_name' => '데몬',
				'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
							from {$g5['board_table']}
							where gr_id = 'daemon'
							order by bo_order, bo_table "
			)
		);
	} elseif ($view === 'upbit') {
		$list_configs[] = array(
			'title' => '업비트',
			'label' => 'prefix : _upbit',
			'group_name' => '업비트',
			'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
						from {$g5['board_table']}
						where {$base_group_where}
						and bo_table regexp '(^|_)upbit(_|$)'
						order by bo_order, bo_table "
		);
	} elseif ($view === 'bybit') {
		$list_configs[] = array(
			'title' => '바이비트',
			'label' => 'prefix : _bybit',
			'group_name' => '바이비트',
			'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
						from {$g5['board_table']}
						where {$base_group_where}
						and bo_table regexp '(^|_)bybit(_|$)'
						order by bo_order, bo_table "
		);
	} else {
		$group_title_map = array(
			'data_colle' => '데이터 수집',
			'trading' => '매매',
			'daemon' => '데몬'
		);

		$list_configs[] = array(
			'title' => $group_title_map[$view],
			'label' => 'group id : ' . $view,
			'group_name' => $group_title_map[$view],
			'sql' => " select bo_subject, bo_table, bo_10_subj, bo_count_write
						from {$g5['board_table']}
						where gr_id = '{$view}'
						order by bo_order, bo_table "
		);
	}

	$render_sections = array();
	$total_post_count = 0;

	foreach ($list_configs as $config) {
		$sql = $config['sql'];
		$result = sql_query($sql);

		$board_rows = array();
		$section_post_count = 0;
		while ($row = sql_fetch_array($result)) {
			$board_rows[] = $row;
			$section_post_count += (int)$row['bo_count_write'];
		}

		$config['rows'] = $board_rows;
		$config['board_count'] = count($board_rows);
		$render_sections[] = $config;
		$total_post_count += $section_post_count;
	}

	$group_count = count($render_sections);
	$menu_count = count($menu_items);

	$self_path = htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8');
	?>
	<div class="daemon-hero">
		<div class="daemon-hero-title-wrap">
			<span class="material-symbols-rounded daemon-hero-icon" aria-hidden="true">dashboard</span>
			<h1 class="daemon-hero-title">Demon Management Board <label>데몬 관리 보드</label></h1>
		</div>
		<div class="daemon-hero-stats">
			<div class="daemon-stat-item">
				<span class="material-symbols-rounded" aria-hidden="true">hub</span>
				<strong><?php echo number_format($group_count); ?></strong>
				<em>그룹 수</em>
			</div>
			<div class="daemon-stat-item">
				<span class="material-symbols-rounded" aria-hidden="true">menu</span>
				<strong><?php echo number_format($menu_count); ?></strong>
				<em>메뉴 수</em>
			</div>
			<div class="daemon-stat-item">
				<span class="material-symbols-rounded" aria-hidden="true">article</span>
				<strong><?php echo number_format($total_post_count); ?></strong>
				<em>총 게시물 수</em>
			</div>
		</div>
	</div>

	<div class="daemon-layout">
		<div class="daemon-sidebar">
			<div class="daemon-menu-card">
				<h3 class="daemon-menu-title">데몬 관리 메뉴</h3>
				<ul class="daemon-menu-list">
					<?php foreach ($menu_items as $menu_key => $menu_label) { ?>
					<li>
						<a class="daemon-menu-link <?php echo $view === $menu_key ? 'active' : ''; ?>" href="<?php echo $self_path; ?>?view=<?php echo urlencode($menu_key); ?>"><?php echo get_text($menu_label); ?></a>
					</li>
					<?php } ?>
				</ul>
			</div>
		</div>

		<div class="daemon-content">
	<?php
	foreach ($render_sections as $config) {
		$board_rows = $config['rows'];
		$board_count = $config['board_count'];
	?>
	<div class="daemon-card">
		<div class="daemon-head">
			<div class="daemon-head-top">
				<h2 class="daemon-title"><?php echo get_text($config['title']); ?></h2>
				<p class="daemon-count">게시판 수량 : <?php echo number_format($board_count); ?></p>
			</div>
			<p class="daemon-group"><?php echo get_text($config['label']); ?></p>
		</div>

		<table class="daemon-table">
		<thead>
			<tr>
				<th>그룹명</th>
				<th>제목</th>
				<th>테이블명</th>
				<th>추가설명</th>
				<th>게시물 수량</th>
				<th>링크</th>
			</tr>
		</thead>
		<tbody>
			<?php
			$has_row = $board_count > 0;
			foreach ($board_rows as $row) {
				$board_link = G5_BBS_URL . '/board.php?bo_table=' . urlencode($row['bo_table']);
				$board_link_attr = htmlspecialchars($board_link, ENT_QUOTES, 'UTF-8');
			?>
			<tr>
				<td class="group-name"><?php echo get_text($config['group_name']); ?></td>
				<td class="subject"><?php echo get_text($row['bo_subject']); ?></td>
				<td class="table-name"><?php echo get_text($row['bo_table']); ?></td>
				<td class="extra-desc"><?php echo get_text($row['bo_10_subj']); ?></td>
				<td class="post-count"><?php echo number_format((int)$row['bo_count_write']); ?></td>
				<td class="board-link">
					<div class="board-link-actions">
						<a href="<?php echo $board_link; ?>" target="_blank" rel="noopener">새창</a>
						<button type="button" class="board-popup-open" data-popup-url="<?php echo $board_link_attr; ?>">팝업창</button>
					</div>
				</td>
			</tr>
			<?php } ?>

			<?php if (!$has_row) { ?>
			<tr>
				<td colspan="6" class="empty">해당 그룹에 게시판이 없습니다.</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
	</div>
	<?php } ?>
		</div>
	</div>

	<div id="daemon-board-modal" class="daemon-modal" aria-hidden="true">
		<div class="daemon-modal-dialog" role="dialog" aria-modal="true" aria-label="게시판 팝업">
			<div class="daemon-modal-head">
				<strong>게시판 팝업</strong>
				<button type="button" class="daemon-modal-close">닫기</button>
			</div>
			<div class="daemon-modal-body">
				<iframe id="daemon-board-frame" src="about:blank" title="게시판 미리보기" loading="lazy" scrolling="auto"></iframe>
			</div>
		</div>
	</div>
</div>

<script>
(function () {
	var modal = document.getElementById('daemon-board-modal');
	var frame = document.getElementById('daemon-board-frame');
	if (!modal || !frame) {
		return;
	}

	function openModal(url) {
		frame.setAttribute('src', url);
		modal.classList.add('is-open');
		modal.setAttribute('aria-hidden', 'false');
		document.body.classList.add('daemon-modal-open');
	}

	function applyFrameScrollbarStyle() {
		try {
			var frameDoc = frame.contentDocument || frame.contentWindow.document;
			if (!frameDoc) {
				return;
			}

			var styleId = 'daemon-frame-scrollbar-style';
			if (frameDoc.getElementById(styleId)) {
				return;
			}

			var styleTag = frameDoc.createElement('style');
			styleTag.id = styleId;
			styleTag.textContent = 'html, body { scrollbar-color: #232e42 #0c1224; scrollbar-width: thin; }' +
				'::-webkit-scrollbar { width: 12px; height: 0; }' +
				'::-webkit-scrollbar-track { background: #0c1224; }' +
				'::-webkit-scrollbar-thumb { background: #232e42; border-radius: 10px; border: 2px solid #0c1224; }' +
				'::-webkit-scrollbar-thumb:hover { background: #3b4a67; }';

			(frameDoc.head || frameDoc.documentElement).appendChild(styleTag);
		} catch (error) {
		}
	}

	function closeModal() {
		modal.classList.remove('is-open');
		modal.setAttribute('aria-hidden', 'true');
		frame.setAttribute('src', 'about:blank');
		document.body.classList.remove('daemon-modal-open');
	}

	frame.addEventListener('load', applyFrameScrollbarStyle);

	document.addEventListener('click', function (event) {
		var openBtn = event.target.closest('.board-popup-open');
		if (openBtn) {
			openModal(openBtn.getAttribute('data-popup-url'));
			return;
		}

		if (event.target.closest('.daemon-modal-close')) {
			closeModal();
			return;
		}

		if (event.target === modal) {
			closeModal();
		}
	});
})();
</script>

<?php require_once '/home/www/GNU/_PAGE/tail.php'; ?>