<?php
if (!defined('_GNUBOARD_')) exit;
include_once("{$board_skin_path}/db_update.php");
add_stylesheet('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">', 0);
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.write.css">', 0);
// 버전 기본값 설정
if (!$write['x2_ver']) {
$row_ver = sql_fetch(" select x2_ver from {$write_table} order by wr_id desc limit 1 ");
$default_ver = isset($row_ver['x2_ver']) ? $row_ver['x2_ver'] : '';
} else {
$default_ver = $write['x2_ver'];
}
// 한글명 변수
$x2_korean_name = isset($write['x2_korean_name']) ? $write['x2_korean_name'] : '';
// --------------------------------------------------------------------------
// 이미 등록된 코인 리스트 추출
// 기본: 현재 게시판
// 추가: bo_10 / bo_10_sub 여분필드에 bo_table명이 있으면 해당 게시판도 포함
// --------------------------------------------------------------------------
$exist_coins = [];
// 1. 현재 게시판
$res_exist = sql_query(" select wr_subject from {$write_table} ");
while ($row_ex = sql_fetch_array($res_exist)) {
$exist_coins[] = strtoupper(trim($row_ex['wr_subject']));
}
// 2. bo_10 여분필드에 지정된 게시판
if (!empty($board['bo_10'])) {
$extra_table1 = $g5['write_prefix'] . trim($board['bo_10']);
$res_extra1 = sql_query(" select wr_subject from {$extra_table1} ");
if ($res_extra1) {
while ($row_ex1 = sql_fetch_array($res_extra1)) {
$exist_coins[] = strtoupper(trim($row_ex1['wr_subject']));
}
}
}
// 3. bo_10_sub 여분필드에 지정된 게시판
if (!empty($board['bo_10_sub'])) {
$extra_table2 = $g5['write_prefix'] . trim($board['bo_10_sub']);
$res_extra2 = sql_query(" select wr_subject from {$extra_table2} ");
if ($res_extra2) {
while ($row_ex2 = sql_fetch_array($res_extra2)) {
$exist_coins[] = strtoupper(trim($row_ex2['wr_subject']));
}
}
}
// 중복 제거 후 JSON 인코딩
$exist_coins = array_values(array_unique($exist_coins));
$exist_json = json_encode($exist_coins);
// --------------------------------------------------------------------------
$file_count = (isset($board['bo_upload_count']) && $board['bo_upload_count']) ? $board['bo_upload_count'] : 0;
// 데이터 존재 여부 (에디터 내용, 링크, 파일)
$has_data = ($w == 'u' && (trim($write['wr_content']) || trim($write['wr_link1']) || trim($write['wr_link2']) || (isset($file[0]['file']) && $file[0]['file'])));
$extra_area_class = $has_data ? 'is-open' : 'is-close';
$memo_panel_class = !empty($write['x2_memo_button']) ? 'is-open' : 'is-close';
?>
<div id="WRITE_WRAP">
<article id="WRITE">
<form name="fwrite" id="fwrite" action="<?php echo $action_url; ?>" onsubmit="return fwrite_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off">
<input type="hidden" name="w" value="<?php echo $w; ?>">
<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
<input type="hidden" name="wr_id" value="<?php echo $wr_id; ?>">
<input type="hidden" name="sca" value="<?php echo $sca; ?>">
<div class="write-head">
<h2 class="write-title"><i class="fa-solid fa-code-commit"></i> BYBIT_DAEMON_INTERFACE</h2>
<div class="write-head-btns">
<button type="button" class="btn-toggle-clean btn-head-cancel" onclick="window.history.back();">취 소</button>
<button type="submit" class="btn-submit btn-head-submit">저 장</button>
</div>
</div>
<table class="write-table">
<tr>
<td class="td-label"><i class="fa-solid fa-bolt"></i> 시스템 상태</td>
<td class="td-content">
<div class="row-flex row-gap-30">
<div class="switch-box form-group switch-inline">
<span class="field-label">작동 상태 : </span>
<label class="toggle-btn">
<input type="checkbox" name="x2_run" id="id_x2_run" value="1" <?php echo ($write['x2_run'] || $w=='') ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
<div class="tip-balloon">시스템 활성화 온/오프</div>
</div>
<?php if ($is_category) { ?>
<div class="form-group">
<span class="field-label">대분류 : </span>
<select name="ca_name" id="id_ca_name" required>
<option value="">카테고리 선택</option>
<?php echo $category_option; ?>
</select>
<div class="tip-balloon">데이터 대분류 섹터</div>
</div>
<?php } ?>
<div class="form-group">
<span class="field-label">중분류 : </span>
<select name="x2_ca2" id="id_x2_ca2">
<option value=''>타입 선택</option>
<?php $bo_1_opts = explode("|", $board['bo_1']); foreach($bo_1_opts as $val) { $selected = (isset($write['x2_ca2']) && $write['x2_ca2'] == $val) ? "selected" : ""; echo "<option value='{$val}' {$selected}>{$val}</option>"; } ?>
</select>
<div class="tip-balloon">데이터 중분류 타입</div>
</div>
<div class="form-group">
<span class="field-label">소분류 : </span>
<select name="x2_ca3" id="id_x2_ca3">
<option value=''>기간 선택</option>
<?php $bo_2_opts = explode("|", $board['bo_2']); foreach($bo_2_opts as $val) { $selected = (isset($write['x2_ca3']) && $write['x2_ca3'] == $val) ? "selected" : ""; echo "<option value='{$val}' {$selected}>{$val}</option>"; } ?>
</select>
<div class="tip-balloon">데이터 소분류 기간</div>
</div>
<!-- [항목 추가] 코인명 -->
<div class="form-group">
<span class="field-label">코인명 : </span>
<input type="text" name="x2_korean_name" id="id_x2_korean_name" value="<?php echo $x2_korean_name; ?>" size="12" placeholder="한글명">
<div class="tip-balloon">한글 코인명</div>
</div>
<div class="form-group">
<span class="field-label">버전 : </span>
<input type="text" name="x2_ver" id="id_x2_ver" value="<?php echo $default_ver; ?>" size="12" placeholder="버전">
<div class="tip-balloon">빌드 버전 정보</div>
</div>
<div class="row-flex row-gap-8 row-ml-auto">
<div class="form-group">
<input type="date" name="wr_date_custom" id="id_date" value="<?php echo $w=='u' ? substr($write['wr_datetime'],0,10) : date('Y-m-d'); ?>">
<div class="tip-balloon">데이터 생성 일자</div>
</div>
<div class="form-group">
<input type="time" name="wr_time_custom" id="id_time" value="<?php echo $w=='u' ? substr($write['wr_datetime'],11,8) : date('H:i:s'); ?>" step="1">
<div class="tip-balloon">데이터 생성 시각</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-coins"></i> 자산 종목</td>
<td class="td-content">
<div class="row-flex row-gap-20">
<span class="field-label">바이비트 자산</span>
<div class="form-group">
<select name="wr_subject" id="coin_select" class="select-coin" required>
<option value="">USDT 자산 검색 중...</option>
<?php if($w == 'u') { ?>
<option value="<?php echo $subject; ?>" selected><?php echo $subject; ?></option>
<?php } ?>
</select>
<div class="tip-balloon">USDT 종목 (중복 제외)</div>
</div>
<span class="field-label field-gap-left">태그</span>
<div class="form-group form-flex-1">
<input type="text" name="wr_1" id="id_tag" value="<?php echo isset($write['wr_1']) ? $write['wr_1'] : ''; ?>" class="w-full" placeholder="콤마로 구분된 태그">
<div class="tip-balloon">데이터 식별 태그</div>
</div>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-coins"></i> 기능 옵션</td>
<td class="td-content">
<div class="option-grid">
<div class="option-item form-group">
<span class="field-label">우선 부분</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_top" id="id_x2_top" value="1" <?php echo !empty($write['x2_top']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
<div class="tip-balloon">상단 고정/우선 노출</div>
</div>
<div class="option-item form-group">
<span class="field-label">라벨 부분</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_label" id="id_x2_label" value="1" <?php echo !empty($write['x2_label']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
<div class="tip-balloon">라벨 강조 출력</div>
</div>
<div class="option-item form-group">
<span class="field-label">핵심 부분</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_core" id="id_x2_core" value="1" <?php echo !empty($write['x2_core']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
<div class="tip-balloon">핵심 강조 출력</div>
</div>
<div class="option-item form-group">
<span class="field-label">메모 버튼</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_memo_button" id="id_x2_memo_button" value="1" <?php echo !empty($write['x2_memo_button']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
<div class="tip-balloon">메모 입력 영역 토글</div>
</div>
</div>
<div id="memo_panel" class="memo-panel <?php echo $memo_panel_class; ?>">
<div class="memo-head">
<span class="memo-title"><i class="fa-solid fa-note-sticky"></i> 메모 설정</span>
<div class="option-item form-group">
<span class="field-label">메모 삭제</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_memo_clean" id="id_x2_memo_clean" value="1" <?php echo !empty($write['x2_memo_clean']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
<div class="tip-balloon">저장 시 메모 텍스트 초기화</div>
</div>
</div>
<div class="memo-body">
<textarea name="x2_memo" id="id_x2_memo" rows="4" placeholder="메모를 입력하세요"><?php echo isset($write['x2_memo']) ? get_text($write['x2_memo'], 0) : ''; ?></textarea>
</div>
</div>
</td>
</tr>
</table>
<div class="dynamic-result-area">
<div class="res-item"><span>[상태]</span> <b id="res_state">-</b></div>
<div class="res-item"><span>[코인]</span> <b id="res_coin">-</b></div>
<div class="res-item"><span>[한글명]</span> <b id="res_korean_name">-</b></div>
<div class="res-item"><span>[분류]</span> <b id="res_cat">-</b></div>
<div class="res-item"><span>[모드]</span> <b id="res_mode">-</b></div>
<div class="res-item"><span>[시간]</span> <b id="res_time">-</b></div>
<div class="res-item"><span>[버전]</span> <b id="res_ver">-</b></div>
</div>
<button type="button" id="btn_extra_toggle" class="btn-toggle-clean" onclick="toggleExtraArea()">
상세 파라미터 및 페이로드 관리 <i class="fa-solid <?php echo $has_data ? 'fa-chevron-up' : 'fa-chevron-down'; ?>" style="margin-left:8px;"></i>
</button>
<div id="extra_area" class="extra-area <?php echo $extra_area_class; ?>">
<table class="write-table">
<tr>
<td class="td-label"><i class="fa-solid fa-file-code"></i> 상세 설명</td>
<td class="td-content td-dark"><?php echo $editor_html; ?></td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-paperclip"></i> 페이로드 첨부</td>
<td class="td-content">
<div id="variableFiles">
<?php for ($i=0; $is_file && $i<$file_count; $i++) {
$is_active = ($i == 0 || (isset($file[$i]['file']) && $file[$i]['file'])) ? "active" : "";
?>
<div class="file-box-custom <?php echo $is_active; ?>" id="f_row_<?php echo $i; ?>">
<label for="bf_file_<?php echo $i; ?>" class="file-btn-ui">파일 선택</label>
<input type="file" name="bf_file[<?php echo $i; ?>]" id="bf_file_<?php echo $i; ?>" class="file-hidden" onchange="updateFileInfo(this, <?php echo $i; ?>)">
<span id="f_name_<?php echo $i; ?>" class="file-info-ui">
<?php echo (isset($file[$i]['file']) && $file[$i]['file']) ? $file[$i]['source'] : "데이터 없음"; ?>
</span>
<?php if ($board['bo_use_file_content']) { ?>
<input type="text" name="bf_content[<?php echo $i; ?>]" value="<?php echo ($w == 'u') ? stripslashes($file[$i]['bf_content']) : ''; ?>" class="file-desc-ui" placeholder="파일 설명">
<?php } ?>
<?php if($w == 'u' && isset($file[$i]['file']) && $file[$i]['file']) { ?>
<label class="file-del-label"><input type="checkbox" name="bf_file_del[<?php echo $i; ?>]" value="1"> 삭제</label>
<?php } ?>
</div>
<?php } ?>
</div>
<button type="button" class="btn-toggle-clean btn-slot-add" onclick="addFileSlot();">+ 슬롯 추가</button>
</td>
</tr>
<!-- [링크 추가] 페이로드 첨부 아래 -->
<?php for ($i=1; $is_link && $i<=2; $i++) { ?>
<tr>
<td class="td-label"><i class="fa-solid fa-link"></i> 링크 #<?php echo $i ?></td>
<td class="td-content">
<input type="text" name="wr_link<?php echo $i ?>" value="<?php if($w=="u"){echo$write['wr_link'.$i];} ?>" class="frm_input w-full" size="50" placeholder="링크 URL을 입력하세요">
</td>
</tr>
<?php } ?>
</table>
</div>
<div class="write-foot">
<button type="submit" class="btn-submit">데이터 저장 (전송)</button>
</div>
</form>
</article>
</div>
<?php include_once($board_skin_path.'/write/write.script.php'); ?>