GNU/skin/board/daemon_setting/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);
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.write.css">', 0);

// 5. 버전 폼 기본값 설정 (이전 게시물 값 가져오기)
if (!$write['x2_ver']) {
    $row_ver = sql_fetch(" select x2_ver from {$write_table} order by wr_id desc limit 1 ");
    $default_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;
?>

<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; ?>">
            <input type="hidden" name="uid" value="<?php echo get_uniqid(); ?>">

            <div style="padding: 30px 40px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.1);">
                <h2 style="margin:0; font-size:1.8rem; color:#00f2ff; letter-spacing:1px; font-weight:800;"><i class="fa-solid fa-rocket"></i> DATA CONTROL</h2>
                <div style="display:flex; gap:15px;">
                    <button type="button" class="btn-action btn-cancel-top" onclick="window.history.back();">CANCEL</button>
                    <button type="submit" class="btn-action btn-save-top">SAVE MISSION</button>
                </div>
            </div>

            <table class="write-table">
                <tr>
                    <td class="td-label"><i class="fa-solid fa-satellite-dish"></i> 분류/시간 설정</td>
                    <td style="padding:20px 40px;">
                        <div style="display:flex; flex-wrap:wrap; gap:15px; align-items:center;">
                            <?php if ($is_category) { ?>
                                <select name="ca_name" id="ca_name">
                                    <option value="">분류 선택</option>
                                    <?php echo get_category_option($board['bo_category_list'], $ca_name); ?>
                                </select>
                            <?php } ?>

                            <span style="color:#64748b; font-size:0.9rem;">종류</span>
                            <select name="x2_ca2">
                                <option value=''>선택</option>
                                <?php
                                $bo_1_opts = explode("|", $board['bo_1']);
                                foreach($bo_1_opts as $val) {
                                    $selected = ($write['x2_ca2'] == $val) ? "selected" : "";
                                    echo "<option value='{$val}' {$selected}>{$val}</option>";
                                }
                                ?>
                            </select>

                            <span style="color:#64748b; font-size:0.9rem;">형태</span>
                            <select name="x2_ca3" id="x2_ca3">
                                <option value=''>선택</option>
                                <?php
                                $bo_2_opts = explode("|", $board['bo_2']);
                                foreach($bo_2_opts as $val) {
                                    if (!trim($val)) continue;
                                    $selected = (isset($write['x2_ca3']) && $write['x2_ca3'] == $val) ? "selected" : "";
                                    echo "<option value='{$val}' {$selected}>{$val}</option>";
                                }
                                ?>
                            </select>

                            <span style="color:#64748b; font-size:0.9rem;">VER</span>
                            <input type="text" name="x2_ver" value="<?php echo $default_ver; ?>" size="8" placeholder="Version">

                            <div style="margin-left:auto; display:flex; gap:10px; align-items:center;">
                                <i class="fa-regular fa-calendar-check" style="color:#fff; font-size:1.1rem;"></i>
                                <input type="date" name="wr_date_custom" value="<?php echo substr($write['wr_datetime'],0,10); ?>">
                                <input type="time" name="wr_time_custom" value="<?php echo substr($write['wr_datetime'],11,8); ?>" step="1">
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td class="td-label"><i class="fa-solid fa-pen-fancy"></i> 데몬 작업 제목</td>
                    <td style="padding:20px 40px;">
                        <input type="text" name="wr_subject" value="<?php echo $subject; ?>" required style="width:100%" placeholder="제목을 입력하세요">
                    </td>
                </tr>
                <tr>
                    <td class="td-label"><i class="fa-solid fa-pen-fancy"></i> 데몬 정보</td>
                    <td style="padding:20px 40px;">
                        <div style="display:flex; flex-wrap:wrap; gap:12px 16px; align-items:center; width:100%;">
                            <span style="color:#64748b; font-size:0.9rem; flex:0 0 auto;">데몬명</span>
                            <input type="text" name="x2_daemon_name" value="<?php echo isset($write['x2_daemon_name']) ? $write['x2_daemon_name'] : ''; ?>" placeholder="데몬명 입력" style="width:300px; flex:0 0 300px; min-width:300px;">
                            <span style="color:#64748b; font-size:0.9rem; flex:0 0 auto;">데몬테이블</span>
                            <input type="text" name="x2_daemon_table" value="<?php echo isset($write['x2_daemon_table']) ? $write['x2_daemon_table'] : ''; ?>" placeholder="데몬테이블 입력" style="width:300px; flex:0 0 300px; min-width:300px;">
                            <span style="color:#64748b; font-size:0.9rem; flex:0 0 auto;">데몬경로</span>
                            <input type="text" name="x2_daemon_url" value="<?php echo isset($write['x2_daemon_url']) ? $write['x2_daemon_url'] : ''; ?>" placeholder="데몬경로 입력" style="flex:1 1 0; min-width:280px; width:100%;">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="td-label"><i class="fa-solid fa-pen-fancy"></i> 간략설명</td>
                    <td style="padding:20px 40px;">
                        <input type="text" name="x2_description" value="<?php echo isset($write['x2_description']) ? $write['x2_description'] : ''; ?>" placeholder="간략설명 입력" style="width:100%;">
                    </td>
                </tr>

                <tr>
                    <td class="td-label"><span class="tag-icon"><i class="fa-solid fa-tags"></i></span> 태그</td>
                    <td style="padding:20px 40px;">                        
                        <div class="tag-input-wrap">
                            <input type="text" name="wr_1" value="<?php echo $write['wr_1']; ?>" class="tag-input" placeholder="태그를 입력하세요 (쉼표로 구분)">
                        </div>
                    </td>
                </tr>

                <tr>
                    <td colspan="2" style="text-align:center; padding:15px; background:rgba(255,255,255,0.01);">
                        <button type="button" class="btn-action" style="background:none; border:1px dashed #00f2ff; color:#00f2ff; padding:8px 30px; border-radius:5px; cursor:pointer;" onclick="$('#Editor-Area').slideToggle();">데이터 에디터 & 첨부파일 관리</button>
                    </td>
                </tr>
            </table>

            <div id="Editor-Area" style="<?php echo ($w=='u' || $write['wr_content']) ? 'display:block;' : 'display:none;'; ?>">
                <div style="padding:30px; background: rgba(0, 0, 0, 0.4);">
                    <?php echo $editor_html; ?>
                </div>

                <table class="write-table">
                    <tr>
                        <td class="td-label"><i class="fa-solid fa-code"></i> 추가 코드</td>
                        <td style="padding:20px 40px;">
                            <textarea name="x2_txt" id="x2_txt" rows="10" placeholder="추가 코드를 입력하세요" style="width:100%"><?php echo get_text($write['x2_txt'], 0); ?></textarea>
                        </td>
                    </tr>

                    <tr>
                        <td class="td-label"><i class="fa-solid fa-link"></i> 참조 링크 #1</td>
                        <td style="padding:20px 40px;">
                            <input type="text" name="wr_link1" value="<?php echo $write['wr_link1']; ?>" style="width:100%" placeholder="https://...">
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label"><i class="fa-solid fa-link"></i> 참조 링크 #2</td>
                        <td style="padding:20px 40px;">
                            <input type="text" name="wr_link2" value="<?php echo $write['wr_link2']; ?>" style="width:100%" placeholder="https://...">
                        </td>
                    </tr>

                    <tr>
                        <td class="td-label"><i class="fa-solid fa-paperclip"></i> 페이로드 첨부</td>
                        <td style="padding:20px 40px;">
                            <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-row <?php echo $is_active; ?>" id="file_row_<?php echo $i; ?>">
                                    <label for="bf_file_<?php echo $i; ?>" class="file-btn-custom">FILE #<?php echo $i+1; ?></label>
                                    <input type="file" name="bf_file[<?php echo $i; ?>]" id="bf_file_<?php echo $i; ?>" style="display:none;" onchange="updateFileName(this, <?php echo $i; ?>)">
                                    
                                    <span id="file_name_<?php echo $i; ?>" style="color:#8fa3ad; font-size:0.85rem; flex:1;">
                                        <?php if($w == 'u' && isset($file[$i]['file']) && $file[$i]['file']) { 
                                            echo $file[$i]['source']; 
                                            echo " <label style='color:#ff4757; margin-left:10px; cursor:pointer;'><input type='checkbox' name='bf_file_del[$i]' value='1'> 삭제</label>";
                                        } else { echo "No file selected"; } ?>
                                    </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-input" placeholder="파일 설명 입력">
                                    <?php } ?>
                                </div>
                                <?php } ?>
                            </div>
                            <button type="button" class="btn-action" style="background:none; border:1px solid #334155; color:#8fa3ad; padding:8px 20px; border-radius:6px; cursor:pointer;" onclick="file_add();">+ ADD FILE SLOT</button>
                        </td>
                    </tr>
                </table>
            </div>

            <div style="padding:60px; text-align:center; border-top:1px solid rgba(255,255,255,0.05);">
                <button type="submit" class="btn-action btn-save-main">MISSION COMPLETE & SAVE</button>
            </div>
        </form>
    </article>
</div>

<script>
function updateFileName(input, index) {
    const fileName = input.files[0] ? input.files[0].name : "No file selected";
    document.getElementById('file_name_' + index).innerText = fileName;
    document.getElementById('file_name_' + index).style.color = "#00f2ff";
}

function file_add() {
    var rows = document.querySelectorAll('.file-row:not(.active)');
    if (rows.length > 0) rows[0].classList.add('active');
}

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