GNU/skin/board/work/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);

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'];
}

$current_ca_name = $write['ca_name'] ? $write['ca_name'] : date("Y-m");
$file_count = (isset($board['bo_upload_count']) && $board['bo_upload_count']) ? $board['bo_upload_count'] : 0;

$line_rows = array();
if (!empty($write['x2_line'])) {
    $line_tokens = explode('@', $write['x2_line']);
    foreach ($line_tokens as $line_token) {
        if ($line_token === '') continue;
        $line_parts = explode('^', $line_token, 2);
        $line_content = isset($line_parts[0]) ? $line_parts[0] : '';
        $line_time = isset($line_parts[1]) && trim($line_parts[1]) !== '' ? trim($line_parts[1]) : date('Y-m-d H:i:s');
        $line_rows[] = array(
            'content' => $line_content,
            'time' => $line_time
        );
    }
}

if (empty($line_rows)) {
    $line_rows[] = array(
        'content' => '',
        'time' => date('Y-m-d H:i:s')
    );
}

$memo_open = !empty($write['x2_memo']);

$prev_note_sql = " select x2_note from {$write_table} ";
if (!empty($wr_id)) {
    $prev_note_sql .= " where wr_id <> '".(int)$wr_id."' ";
}
$prev_note_sql .= " order by wr_id desc limit 1 ";
$prev_note = sql_fetch($prev_note_sql);

$write_x2_note = isset($write['x2_note']) ? trim($write['x2_note']) : '';
$prev_x2_note = isset($prev_note['x2_note']) ? trim($prev_note['x2_note']) : '';
$x2_note_value = ($write_x2_note !== '') ? $write_x2_note : $prev_x2_note;
$note_open = ($write_x2_note !== '');

$relay_rows = array();
if (!empty($write['x2_relay'])) {
    $relay_tokens = explode('@', $write['x2_relay']);
    foreach ($relay_tokens as $relay_token) {
        if ($relay_token === '') continue;
        $relay_parts = explode('^', $relay_token, 2);
        $relay_content = isset($relay_parts[0]) ? $relay_parts[0] : '';
        $relay_time = isset($relay_parts[1]) && trim($relay_parts[1]) !== '' ? trim($relay_parts[1]) : date('Y-m-d H:i:s');
        $relay_rows[] = array(
            'content' => $relay_content,
            'time' => $relay_time
        );
    }
}
$relay_open = !empty($relay_rows);
?>

<div id="relay-side-menu" class="<?php echo $relay_open ? 'is-open' : ''; ?>">
    <ul>
        <li><label>RELAY</label><label>| 릴레이 작업</label></li>
        <li><button type="button" class="btn-relay-close" style="position:absolute; cursor:pointer;"><i class="fa-solid fa-xmark"></i></button></li>
    </ul>
    <ul>
        <button type="button" class="btn-action btn-add-line" id="btn-add-relay-line">+ ADD RELAY LINE</button>
        <div id="relayRows">
            <?php foreach ($relay_rows as $relay_row) { ?>
            <div class="work-line-row relay-row">
                <div class="work-line-time-wrap">
                    <span class="field-caption no-margin">기록 시간</span>
                    <input type="text" class="work-line-time relay-line-time" value="<?php echo htmlspecialchars($relay_row['time'], ENT_QUOTES); ?>" readonly>
                </div>
                <textarea class="work-line-content relay-line-content" rows="4" placeholder="릴레이 내용을 입력하세요"><?php echo htmlspecialchars($relay_row['content'], ENT_QUOTES); ?></textarea>
            </div>
            <?php } ?>
        </div>
    </ul>
</div>

<div id="note-side-menu" class="<?php echo $note_open ? 'is-open' : ''; ?>">
    <ul>
        <li><label>NOTE</label><label>| 노트 입력</label></li>
        <li><button type="button" class="btn-note-close" style="position:absolute; cursor:pointer;"><i class="fa-solid fa-xmark"></i></button></li>
    </ul>
    <div class="note-side-body">
        <textarea name="x2_note" id="x2_note" form="fwrite" rows="18" placeholder="노트를 입력하세요"><?php echo htmlspecialchars($x2_note_value, ENT_QUOTES); ?></textarea>
    </div>
</div>

<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(); ?>">
            <input type="hidden" name="x2_relay" id="x2_relay_serialized" value="<?php echo htmlspecialchars($write['x2_relay'], ENT_QUOTES); ?>">

            <div class="write-top-bar">
                <h2 class="write-top-title"><i class="fa-solid fa-rocket"></i> WOKK CONTROL</h2>
                <div class="write-top-actions">
                    <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>

            <div class="Project_Box" id="project-detail-area" style="<?php echo (isset($write['x2_project_bt']) && $write['x2_project_bt'] == '1') ? 'display:block;' : 'display:none;'; ?>">
                <textarea name="x2_project_txt" rows="5" placeholder="[체크] 입력 : 보드 상단 노출&#10;[제목] 프로젝트명: 타이틀 출력&#10;[링크] 기본 링크 : 버튼"><?php echo htmlspecialchars($write['x2_project_txt'], ENT_QUOTES); ?></textarea>
            </div>

            <table class="write-table">
                <tr>
                    <td class="td-label"><i class="fa-solid fa-satellite-dish"></i> 분류/시간 설정</td>
                    <td class="td-value">
                        <div class="field-row-wrap">
                            <?php if ($is_category) { ?>
                            <span class="field-caption">분류</span>
                            <select name="ca_name" required>
                                <option value="">분류 선택</option>
                                <?php
                                $category_option = str_replace('value="'.$current_ca_name.'"', 'value="'.$current_ca_name.'" selected', $category_option);
                                $category_option = str_replace("value='".$current_ca_name."'", "value='".$current_ca_name."' selected", $category_option);
                                echo $category_option;
                                ?>
                            </select>
                            <?php } ?>

                            <span class="field-caption">종류</span>
                            <select name="x2_ca2" required>
                                <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 class="field-caption">형태</span>
                            <select name="x2_ca3" id="x2_ca3" required>
                                <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 class="field-caption">상태</span>
                            <select name="x2_ca4" id="x2_ca4" required>
                                <option value=''>선택</option>
                                <?php
                                $bo_3_opts = explode("|", $board['bo_3']);
                                foreach($bo_3_opts as $val) {
                                    if (!trim($val)) continue;
                                    $selected = (isset($write['x2_ca4']) && $write['x2_ca4'] == $val) ? "selected" : "";
                                    echo "<option value='{$val}' {$selected}>{$val}</option>";
                                }
                                ?>
                            </select>

                            <button type="button" class="btn-action btn-note" id="note-toggle-btn" aria-expanded="<?php echo $note_open ? 'true' : 'false'; ?>">노트</button>
                            <button type="button" class="btn-action btn-note" id="relay-toggle-btn" aria-expanded="<?php echo $relay_open ? 'true' : 'false'; ?>">릴레이</button>
                            <button type="button" class="btn-action btn-note" id="memo-toggle-btn" aria-expanded="<?php echo $memo_open ? 'true' : 'false'; ?>">메모</button>
                        </div>

                        <div id="memo-area" class="memo-area <?php echo $memo_open ? 'open' : ''; ?>">
                            <div class="memo-clean-wrap">
                                <label class="switch">
                                    <input type="checkbox" name="x2_memo_clean" value="1" <?php echo (isset($write['x2_memo_clean']) && $write['x2_memo_clean'] == "1") ? "checked" : ""; ?>>
                                    <span class="slider"></span>
                                </label>
                                <span class="field-caption no-margin">메모 정리</span>
                            </div>
                            <textarea name="x2_memo" rows="5" placeholder="메모를 입력하세요"><?php echo $write['x2_memo']; ?></textarea>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="td-label"><i class="fa-solid fa-satellite-dish"></i> 분류/시간 설정</td>
                    <td class="td-value">
                        <div class="field-row-wrap">
                            <span class="field-caption">우선</span>
                            <label class="switch">
                                <input type="checkbox" name="x2_top" value="1" <?php echo ($write['x2_top'] == "1") ? "checked" : ""; ?>>
                                <span class="slider"></span>
                            </label>
                            
                            <span class="field-caption">라벨</span>
                            <input type="hidden" name="x2_label" value="0">
                            <label class="switch">
                                <input type="checkbox" name="x2_label" value="1" <?php echo (isset($write['x2_label']) && $write['x2_label'] == "1") ? "checked" : ""; ?>>
                                <span class="slider"></span>
                            </label>

                            <span class="field-caption">공개</span>
                            <label class="switch">
                                <input type="checkbox" name="x2_see" value="1" <?php echo ($write['x2_see'] == "1") ? "checked" : ""; ?>>
                                <span class="slider"></span>
                            </label>

                            <span class="field-caption">프로젝트</span>
                            <label class="switch">
                                <input type="checkbox" name="x2_project_bt" value="1" <?php echo (isset($write['x2_project_bt']) && $write['x2_project_bt'] == "1") ? "checked" : ""; ?> onchange="$('#project-detail-area').slideToggle();">
                                <span class="slider"></span>
                            </label>

                            <span class="field-caption no-margin">프로젝트명</span>
                            <input type="text" name="x2_project" value="<?php echo $write['x2_project']; ?>" size="40" placeholder="Project">

                            <span class="field-caption no-margin">버전</span>
                            <input type="text" name="x2_ver" value="<?php echo $default_ver; ?>" size="8" placeholder="Version">

                            <div class="date-time-wrap">
                                <input type="date" name="wr_date_custom" id="wr_date_custom" value="<?php echo substr($write['wr_datetime'],0,10); ?>">
                                <input type="time" name="wr_time_custom" id="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 class="td-value">
                        <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-tags"></i> 태그</td>
                    <td class="td-value">
                        <input type="text" name="wr_1" value="<?php echo $write['wr_1']; ?>" style="width:100%" placeholder="태그를 입력하세요(쉼표로 구분)">
                    </td>
                </tr>

                <tr>
                    <td colspan="2" class="editor-toggle-row">
                        <button type="button" class="btn-action btn-editor-toggle" 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>

                <div class="extra-code-section">
                    <h3 style="color:#e2e8f0; font-size:0.9rem; margin-bottom:15px;"><i class="fa-solid fa-code" style="color:#00f2ff; margin-right:10px;"></i> 추가 코드</h3>
                    <textarea name="x2_txt" rows="8" placeholder="추가 코드를 입력하세요"><?php echo $write['x2_txt']; ?></textarea>
                </div>

                <div class="extra-code-section work-line-section">
                    <h3 class="section-title"><i class="fa-solid fa-list-check"></i> 작업 라인</h3>
                    <input type="hidden" name="x2_line" id="x2_line_serialized" value="<?php echo htmlspecialchars($write['x2_line'], ENT_QUOTES); ?>">

                    <div id="workLineRows">
                        <?php foreach ($line_rows as $line_idx => $line_row) { ?>
                        <div class="work-line-row" data-index="<?php echo $line_idx; ?>">
                            <div class="work-line-time-wrap">
                                <span class="field-caption no-margin">기록 시간</span>
                                <input type="text" class="work-line-time" value="<?php echo htmlspecialchars($line_row['time'], ENT_QUOTES); ?>" readonly>
                            </div>
                            <textarea class="work-line-content" rows="4" placeholder="작업 내용을 입력하세요"><?php echo htmlspecialchars($line_row['content'], ENT_QUOTES); ?></textarea>
                        </div>
                        <?php } ?>
                    </div>

                    <button type="button" class="btn-action btn-add-line" id="btn-add-work-line">+ ADD WORK LINE</button>
                </div>
                
                <table class="write-table">
                    <tr>
                        <td class="td-label"><i class="fa-solid fa-link"></i> 링크 #1</td>
                        <td class="td-value">
                            <div class="link-item">
                                <input type="text" name="wr_link1" value="<?php echo $write['wr_link1']; ?>" style="width:100%" placeholder="참조 링크 #1">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label"><i class="fa-solid fa-link"></i> 링크 #2</td>
                        <td class="td-value">
                            <div class="link-item">
                                <input type="text" name="wr_link2" value="<?php echo $write['wr_link2']; ?>" style="width:100%" placeholder="참조 링크 #2">
                            </div>
                        </td>
                    </tr>
                </table>

                <table class="write-table">
                    <tr>
                        <td class="td-label"><i class="fa-solid fa-paperclip"></i> 파일로드 첨부</td>
                        <td class="td-value">
                            <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 btn-add-file" onclick="file_add();">+ ADD FILE SLOT</button>
                        </td>
                    </tr>
                </table>
            </div>

            <div class="write-submit-wrap">
                <button type="submit" class="btn-action btn-save-main">MISSION COMPLETE & SAVE</button>
            </div>
        </form>
    </article>
</div>

<?php include_once("{$board_skin_path}/write/write.script.php"); ?>