GNU/skin/board/daemon_kind_stock/write.skin.php
<?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);

// 버전 기본값 설정
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'];
}

$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'])));
?>

<style>
    /* 배경 및 애니메이션 */
    @keyframes fadeInUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
    #WRITE_WRAP { position: relative; min-height: 100vh; background: #020617; padding: 40px 0; font-family: 'Pretendard', sans-serif; color: #f1f5f9; overflow-x: hidden; color-scheme: dark; }
    #space-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; opacity: 0.25; }
    
    /* 레이아웃 폭 및 좌우 마진 50px */
    #WRITE { position: relative; z-index: 2; width: calc(100% - 100px); margin: 0 50px; animation: fadeInUp 1s ease-out forwards; }
    #fwrite { background: rgba(0, 0, 0, 0.95); border: 1px solid #1e293b; border-radius: 7px; box-shadow: 0 25px 50px rgba(0,0,0,0.8); overflow: hidden; }

    /* 테이블 레이아웃 */
    .write-table { width: 100%; border-collapse: collapse; }
    .write-table tr { border-bottom: 1px solid #1e293b; position: relative; }
    .td-label { width: 180px; padding: 25px 30px; color: #94a3b8; font-size: 0.85rem; font-weight: 700; background: #080c14; }
    .td-label i { width: 25px; color: #00d4ff; margin-right: 5px; }

    /* 입력 폼 공통 */
    input[type="text"], input[type="date"], input[type="time"], select, textarea {
        background: #050505 !important; border: 1px solid #1e293b !important;
        color: #fff !important; padding: 10px 15px !important; border-radius: 4px !important; font-size: 0.85rem; transition: 0.2s;
        outline: none;
    }
    input:focus, select:focus { border-color: #00d4ff !important; box-shadow: 0 0 10px rgba(0, 212, 255, 0.2); }

    /* 날짜/시간 블랙 디자인 메뉴 */
    input[type="date"], input[type="time"] { position: relative; cursor: pointer; }
    input[type="date"]::-webkit-calendar-picker-indicator,
    input[type="time"]::-webkit-calendar-picker-indicator {
        position: absolute; left: 0; top: 0; width: 100%; height: 100%;
        margin: 0; padding: 0; cursor: pointer; opacity: 0;
    }

    /* 풍선 도움말 (마우스 오버) */
    .form-group { position: relative; display: inline-block; }
    .tip-balloon {
        position: absolute; bottom: 140%; left: 50%; transform: translateX(-50%); background: #00d4ff; color: #000; padding: 6px 14px;
        font-size: 0.75rem; font-weight: 800; border-radius: 4px; display: none; white-space: nowrap; z-index: 100;
        box-shadow: 0 8px 20px rgba(0, 212, 255, 0.4); pointer-events: none;
    }
    .tip-balloon::after { content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: #00d4ff; }
    .form-group:hover .tip-balloon { display: block; }

    /* 실시간 동적 출력 박스 (자산 제어 아래 배치) */
    .dynamic-result-area {
        background: #050505; padding: 20px 30px; border-bottom: 1px solid #1e293b;
        display: flex; flex-wrap: wrap; gap: 15px 40px; border-left: 4px solid #00d4ff;
    }
    .res-item { font-family: 'JetBrains Mono'; font-size: 0.72rem; display: flex; align-items: center; }
    .res-item span { color: #576574; margin-right: 10px; font-weight: bold; }
    .res-item b { color: #00d4ff; text-transform: uppercase; }

    /* 제목 셀렉트 메뉴 폭 320px */
    .select-coin { width: 320px !important; }

    /* 첨부파일 디자인 수정 */
    .file-box-custom { 
        display: none; align-items: center; gap: 15px; padding: 15px; 
        background: rgba(255, 255, 255, 0.02); border: 1px solid #1e293b; 
        border-radius: 8px; margin-bottom: 6px; transition: 0.3s;
    }
    .file-box-custom.active { display: flex; }
    .file-box-custom:hover { background: rgba(255, 255, 255, 0.05); border-color: #00d4ff; }
    .file-btn-ui { 
        background: #1e293b; color: #fff; padding: 8px 15px; border-radius: 4px; 
        font-size: 0.75rem; font-weight: bold; cursor: pointer; white-space: nowrap;
    }
    .file-info-ui { flex: 1; color: #94a3b8; font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; }
    .file-desc-ui { width: 350px !important; background: #000 !important; border: 1px solid #334155 !important; }

    /* 상세 파라미터 버튼 효과 */
    .btn-toggle-clean { 
        background: #0f172a; border: 1px solid #1e293b; color: #00d4ff; 
        padding: 14px; font-size: 0.85rem; font-weight: 700; width: 100%; 
        cursor: pointer; transition: 0.3s; letter-spacing: 1px;
    }
    .btn-toggle-clean:hover { 
        background: rgba(0, 212, 255, 0.1); color: #ffffff; 
        border-color: #00d4ff; box-shadow: inset 0 0 10px rgba(0, 212, 255, 0.2); 
    }
    .btn-toggle-clean i { transition: 0.3s; }

    /* 버튼 스타일 */
    .btn-submit { 
        background: #00d4ff; color: #020617; width: 200px !important; height: 50px;
        font-weight: 800; font-size: 0.95rem; border: none; border-radius: 4px; cursor: pointer; transition: 0.2s; 
    }
    .btn-submit:hover { background: #fff; transform: translateY(-2px); box-shadow: 0 5px 20px rgba(0, 212, 255, 0.4); }
    
    /* 스위치 토글 */
    .toggle-btn { position: relative; display: inline-block; width: 60px; height: 26px; }
    .toggle-btn input { opacity: 0; width: 0; height: 0; }
    .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #1e293b; transition: .4s; border-radius: 30px; }
    .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 4px; bottom: 4px; background-color: #94a3b8; transition: .4s; border-radius: 50%; }
    input:checked + .slider { background-color: #00d4ff; }
    input:checked + .slider:before { transform: translateX(34px); background-color: #fff; }
</style>

<div id="WRITE_WRAP">
    <canvas id="space-canvas"></canvas>

    <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 style="padding: 20px 30px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #1e293b; background: #080c14;">
                <h2 style="margin:0; font-size:1.1rem; color:#fff; font-weight:900;"><i class="fa-solid fa-code-commit" style="color:#00d4ff;"></i> SYSTEM_OVERRIDE_INTERFACE</h2>
                <div style="display:flex; gap:10px;">
                    <button type="button" class="btn-toggle-clean" style="width:auto; padding:8px 20px; border-radius:4px;" onclick="window.history.back();">취 소</button>
                    <button type="submit" class="btn-submit" style="width:120px !important; height:auto; padding:8px 20px;">저 장</button>
                </div>
            </div>

            <table class="write-table">
                <!-- 시스템 상태 -->
                <tr>
                    <td class="td-label"><i class="fa-solid fa-bolt"></i> 시스템 상태</td>
                    <td style="padding:20px 30px;">
                        <div style="display:flex; gap:30px; align-items:center;">
                            <div class="switch-box form-group" style="display:flex; align-items:center; gap:10px;">
                                <span style="color:#00d4ff; font-weight:800; font-size:0.75rem;">작동 상태 : </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 style="color:#00d4ff; font-weight:800; font-size:0.75rem;">시장 분류 : </span>
                                <select name="ca_name" id="id_ca_name" required>
                                    <option value="">CATEGORY</option>
                                    <?php echo $category_option; ?>
                                </select>
                                <div class="tip-balloon">시장 기준 : 분류</div>
                            </div>
                            <?php } ?>
                            <div class="form-group">
                                <span style="color:#00d4ff; font-weight:800; font-size:0.75rem;">업종/섹터 분류 : </span>
                                <select name="x2_ca2" id="id_x2_ca2">
                                    <option value=''>TYPE</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 style="color:#00d4ff; font-weight:800; font-size:0.75rem;">테마 : </span>
                                <select name="x2_ca3" id="id_x2_ca3">
                                    <option value=''>PERIOD</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 style="color:#00d4ff; font-weight:800; font-size:0.75rem;">버전 : </span>
                                <input type="text" name="x2_ver" id="id_x2_ver" value="<?php echo $default_ver; ?>" size="12" placeholder="VERSION">
                                <div class="tip-balloon">빌드 버전 정보</div>
                            </div>
                            <div style="display:flex; gap:8px; margin-left:auto;">
                                <div class="form-group">
                                    <input type="date" name="date" 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="time" 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 style="padding:20px 30px;">
                        <div style="display:flex; align-items:center; gap:20px;">
                            <span style="color:#00d4ff; font-weight:800; font-size:0.75rem;">종목 코드 :</span>
                            <div class="form-group">
                                <input type="text" name="wr_subject" id="wr_subject" value="<?php echo $write['wr_subject']; ?>" size="12" placeholder="주식 종목 코드">
                                <div class="tip-balloon">주식종목 코드</div>
                            </div>
                            <span style="color:#00d4ff; font-weight:800; font-size:0.75rem;">종목명 :</span>
                            <div class="form-group">
                                <input type="text" name="wr_subject_kr" id="wr_subject_kr" value="<?php echo $write['wr_subject_kr']; ?>" size="12" placeholder="주식 종목명">
                                <div class="tip-balloon">주식종목명</div>
                            </div>
                            <span style="color:#00d4ff; font-weight:800; font-size:0.75rem; margin-left:20px;">태그 :</span>
                            <div class="form-group" style="flex:1;">
                                <input type="text" name="wr_1" id="id_tag" value="<?php echo isset($write['wr_1']) ? $write['wr_1'] : ''; ?>" style="width:100%;" placeholder="COMMA_SEPARATED_TAGS">
                                <div class="tip-balloon">데이터 식별 태그</div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>

            <!-- 동적 실시간 출력 (자산 제어 아래 배치) -->
            <div class="dynamic-result-area">
                <div class="res-item"><span>[STATE]</span> <b id="res_state">-</b></div>
                <div class="res-item"><span>[COIN]</span> <b id="res_coin">-</b></div>
                <div class="res-item"><span>[CAT]</span> <b id="res_cat">-</b></div>
                <div class="res-item"><span>[MODE]</span> <b id="res_mode">-</b></div>
                <div class="res-item"><span>[TIME]</span> <b id="res_time">-</b></div>
                <div class="res-item"><span>[VER]</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" style="display:<?php echo $has_data ? 'block' : 'none'; ?>; border-top:1px solid #1e293b;">
                <table class="write-table">
                    <tr>
                        <td class="td-label"><i class="fa-solid fa-file-code"></i> 상세 설명</td>
                        <td style="padding:25px 30px; background:#000;"><?php echo $editor_html; ?></td>
                    </tr>
                    <tr>
                        <td class="td-label"><i class="fa-solid fa-paperclip"></i> 페이로드 첨부</td>
                        <td style="padding:25px 30px;">
                            <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">FILE_SELECT</label>
                                    <input type="file" name="bf_file[<?php echo $i; ?>]" id="bf_file_<?php echo $i; ?>" style="display:none;" 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'] : "NO_DATA_STREAMED"; ?>
                                    </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="FILE_DESCRIPTION">
                                    <?php } ?>

                                    <?php if($w == 'u' && isset($file[$i]['file']) && $file[$i]['file']) { ?>
                                        <label style="color:#ff2d55; font-size:0.75rem; margin-left:10px;"><input type="checkbox" name="bf_file_del[<?php echo $i; ?>]" value="1"> DEL</label>
                                    <?php } ?>
                                </div>
                                <?php } ?>
                            </div>
                            <button type="button" class="btn-toggle-clean" style="width:auto; padding:6px 15px; margin-top:10px; font-size:0.75rem;" onclick="addFileSlot();">+ ADD_SLOT</button>
                        </td>
                    </tr>
                </table>
            </div>

            <div style="padding:50px; text-align:center; background:#080c14; border-top:1px solid #1e293b;">
                <button type="submit" class="btn-submit">DATA_SAVE(SEND)</button>
            </div>
        </form>
    </article>
</div>

<script>
$(function() {


    // 실시간 동적 출력 기능
    function updateFeedback() {
        const state = $('#id_x2_run').is(':checked') ? 'ACTIVE' : 'STOPPED';
        $('#res_state').text(state).css('color', state === 'ACTIVE' ? '#00d4ff' : '#ff2d55');
        
        const selectedCoin = $('#wr_subject').val();
        $('#res_coin').text(selectedCoin ? selectedCoin : '-');
        
        $('#res_cat').text($('#id_ca_name option:selected').text() || '-');
        $('#res_mode').text(($('#id_x2_ca2 option:selected').text() || '-') + ' / ' + ($('#id_x2_ca3 option:selected').text() || '-'));
        $('#res_time').text($('#id_date').val() + ' ' + $('#id_time').val());
        $('#res_ver').text($('#id_x2_ver').val() || '-');
    }

    $('input, select').on('change keyup input', updateFeedback);
    setTimeout(updateFeedback, 500);

    // 배경 애니메이션
    const canvas = document.getElementById('space-canvas');
    const ctx = canvas.getContext('2d');
    let stars = [];
    function init() {
        canvas.width = window.innerWidth; canvas.height = window.innerHeight; stars = [];
        for(let i=0; i<100; i++) stars.push({ x: Math.random() * canvas.width, y: Math.random() * canvas.height, size: Math.random() * 2, spd: Math.random() * 0.4 });
    }
    function draw() {
        ctx.clearRect(0,0,canvas.width,canvas.height); ctx.fillStyle = "rgba(255,255,255,0.4)";
        stars.forEach(s => { ctx.beginPath(); ctx.arc(s.x, s.y, s.size, 0, Math.PI*2); ctx.fill(); s.y += s.spd; if(s.y > canvas.height) s.y = 0; });
        requestAnimationFrame(draw);
    }
    init(); draw();
    window.onresize = init;
});

// 파일 업로드 핸들링
function updateFileInfo(input, index) {
    if(input.files.length > 0) {
        document.getElementById('f_name_' + index).innerText = input.files[0].name;
        document.getElementById('f_name_' + index).style.color = "#00d4ff";
    }
}
function addFileSlot() {
    $('.file-box-custom:not(.active)').first().addClass('active');
}

function toggleExtraArea() {
    const area = $('#extra_area');
    const icon = $('#btn_extra_toggle i');
    if(area.is(':visible')) {
        area.slideUp(250); icon.removeClass('fa-chevron-up').addClass('fa-chevron-down');
    } else {
        area.slideDown(250); icon.removeClass('fa-chevron-down').addClass('fa-chevron-up');
    }
}

function fwrite_submit(f) {
    <?php echo $editor_js; ?>
    return true;
}
</script>