GNU/skin/board/outline_target/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 (!function_exists('x2_base64url_encode')) {
    function x2_base64url_encode($data)
    {
        return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
    }
}

if (!function_exists('x2_jwt_hs256')) {
    function x2_jwt_hs256(array $payload, $secret)
    {
        $header = ['alg' => 'HS256', 'typ' => 'JWT'];
        $h = x2_base64url_encode(json_encode($header));
        $p = x2_base64url_encode(json_encode($payload));
        $s = hash_hmac('sha256', $h.'.'.$p, $secret, true);
        return $h.'.'.$p.'.'.x2_base64url_encode($s);
    }
}

if (!function_exists('x2_http_get_json')) {
    function x2_http_get_json($url, array $headers = [])
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
        curl_setopt($ch, CURLOPT_TIMEOUT, 8);
        if (!empty($headers)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }

        $response = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if ($response === false || $http_code < 200 || $http_code >= 300) {
            return null;
        }

        $decoded = json_decode($response, true);
        return is_array($decoded) ? $decoded : null;
    }
}

if (!function_exists('x2_to_float')) {
    function x2_to_float($value)
    {
        $clean = preg_replace('/[^0-9.\-]/', '', (string)$value);
        return ($clean === '' || $clean === '-' || $clean === '.') ? 0.0 : (float)$clean;
    }
}

if (!function_exists('x2_saved_or_default')) {
    function x2_saved_or_default($saved, $default)
    {
        return trim((string)$saved) !== '' ? $saved : $default;
    }
}

if (!function_exists('x2_fetch_upbit_current_asset')) {
    function x2_fetch_upbit_current_asset()
    {
        $key_candidates = [
            '/home/www/DB/key_upbit_trade.php',
            isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'].'/DB/key_upbit_trade.php' : ''
        ];

        $UPBIT_ACCESS_KEY = '';
        $UPBIT_SECRET_KEY = '';

        foreach ($key_candidates as $key_path) {
            if ($key_path && file_exists($key_path)) {
                include $key_path;
                if (!empty($UPBIT_ACCESS_KEY) && !empty($UPBIT_SECRET_KEY)) {
                    break;
                }
            }
        }

        if (empty($UPBIT_ACCESS_KEY) || empty($UPBIT_SECRET_KEY)) {
            return 0.0;
        }

        $payload = [
            'access_key' => $UPBIT_ACCESS_KEY,
            'nonce' => function_exists('uuid_create') ? uuid_create(UUID_TYPE_RANDOM) : md5(uniqid('', true))
        ];

        $jwt = x2_jwt_hs256($payload, $UPBIT_SECRET_KEY);
        $accounts = x2_http_get_json('https://api.upbit.com/v1/accounts', ['Authorization: Bearer '.$jwt]);

        if (!is_array($accounts)) {
            return 0.0;
        }

        $total = 0.0;
        $need_markets = [];
        $holding_map = [];
        $avg_map = [];

        foreach ($accounts as $account) {
            $currency = strtoupper($account['currency'] ?? '');
            $balance = (float)($account['balance'] ?? 0);
            $locked = (float)($account['locked'] ?? 0);
            $amount = $balance + $locked;

            if ($amount <= 0) {
                continue;
            }

            if ($currency === 'KRW') {
                $total += $amount;
                continue;
            }

            $market = 'KRW-'.$currency;
            $holding_map[$market] = $amount;
            $avg_map[$market] = (float)($account['avg_buy_price'] ?? 0);
            $need_markets[] = $market;
        }

        if (!empty($need_markets)) {
            $price_map = [];
            $need_markets = array_values(array_unique($need_markets));
            $chunks = array_chunk($need_markets, 100);

            foreach ($chunks as $markets) {
                $url = 'https://api.upbit.com/v1/ticker?markets='.urlencode(implode(',', $markets));
                $ticker_rows = x2_http_get_json($url);
                if (!is_array($ticker_rows)) {
                    continue;
                }
                foreach ($ticker_rows as $ticker_row) {
                    $market = $ticker_row['market'] ?? '';
                    $trade_price = (float)($ticker_row['trade_price'] ?? 0);
                    if ($market !== '' && $trade_price > 0) {
                        $price_map[$market] = $trade_price;
                    }
                }
            }

            foreach ($holding_map as $market => $quantity) {
                $market_price = isset($price_map[$market]) ? (float)$price_map[$market] : 0;
                if ($market_price <= 0 && isset($avg_map[$market])) {
                    $market_price = (float)$avg_map[$market];
                }
                $total += $quantity * $market_price;
            }
        }

        return $total;
    }
}

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

// 카테고리 기본값: 값이 없으면 오늘(YYYY-MM)
$category_value = isset($write['ca_name']) ? trim($write['ca_name']) : '';
$category_default = date('Y-m');
$use_category_default = ($category_value === '');

// --------------------------------------------------------------------------
// [수정 완료] 이미 등록된 코인 리스트 추출 (현재 게시판 자동 인식)
// --------------------------------------------------------------------------
$exist_coins = [];
$sql_exist = " select wr_subject from {$write_table} "; 
$res_exist = sql_query($sql_exist);
while($row_ex = sql_fetch_array($res_exist)) {
    $exist_coins[] = strtoupper(trim($row_ex['wr_subject']));
}
$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';

$x2_datetime_raw = isset($write['x2_datetime']) ? trim($write['x2_datetime']) : '';
$x2_datetime_default = date('Y-m-d\TH:i');
$x2_datetime_saved = '';
if ($x2_datetime_raw !== '') {
    $x2_datetime_ts = strtotime($x2_datetime_raw);
    $x2_datetime_saved = $x2_datetime_ts ? date('Y-m-d\TH:i', $x2_datetime_ts) : $x2_datetime_raw;
}
$x2_datetime_value = x2_saved_or_default($x2_datetime_saved, $x2_datetime_default);

$base_amount_input = isset($write['x2_base_amount']) ? $write['x2_base_amount'] : '';
$target_amount_input = isset($write['x2_target_amount']) ? $write['x2_target_amount'] : '';

$base_amount_num = x2_to_float($base_amount_input);
$target_amount_num = x2_to_float($target_amount_input);

$current_asset_saved = isset($write['x2_current_asset']) ? trim($write['x2_current_asset']) : '';
$current_asset_num = ($current_asset_saved !== '') ? x2_to_float($current_asset_saved) : x2_fetch_upbit_current_asset();
$current_asset_default = number_format($current_asset_num, 0, '.', ',');
$current_asset_input = x2_saved_or_default($current_asset_saved, $current_asset_default);

$profit_amount_saved = isset($write['x2_profit_amount']) ? trim($write['x2_profit_amount']) : '';
$profit_amount_num = $current_asset_num - $base_amount_num;
$profit_amount_default = number_format($profit_amount_num, 0, '.', ',');
$profit_amount_input = x2_saved_or_default($profit_amount_saved, $profit_amount_default);

$profit_rate_saved = isset($write['x2_profit_rate']) ? trim($write['x2_profit_rate']) : '';
$profit_rate_num = ($base_amount_num != 0.0) ? (($profit_amount_num / $base_amount_num) * 100) : 0.0;
$profit_rate_default = number_format($profit_rate_num, 2, '.', '');
$profit_rate_input = x2_saved_or_default($profit_rate_saved, $profit_rate_default);

$reach_rate_saved = isset($write['x2_reach_rate']) ? trim($write['x2_reach_rate']) : '';
$reach_rate_num = 0.0;
if (($target_amount_num - $base_amount_num) != 0.0) {
    $reach_rate_num = (($current_asset_num - $base_amount_num) / ($target_amount_num - $base_amount_num)) * 100;
}
$reach_rate_default = number_format($reach_rate_num, 2, '.', '');
$reach_rate_input = x2_saved_or_default($reach_rate_saved, $reach_rate_default);

$unit_base_input = isset($write['x2_unit_base']) ? $write['x2_unit_base'] : '';
$unit_add_input = isset($write['x2_unit_add']) ? $write['x2_unit_add'] : '';
$unit_max_input = isset($write['x2_unit_max']) ? $write['x2_unit_max'] : '';

$unit_base_num = x2_to_float($unit_base_input);
$unit_add_num = x2_to_float($unit_add_input);
$unit_max_num = x2_to_float($unit_max_input);

$base_increase_saved = isset($write['x2_base_increase_rate']) ? trim($write['x2_base_increase_rate']) : '';
$base_increase_num = ($unit_base_num != 0.0) ? ((($unit_add_num - $unit_base_num) / $unit_base_num) * 100) : 0.0;
$base_increase_default = number_format($base_increase_num, 2, '.', '');
$base_increase_input = x2_saved_or_default($base_increase_saved, $base_increase_default);

$max_increase_saved = isset($write['x2_max_increase_rate']) ? trim($write['x2_max_increase_rate']) : '';
$max_increase_num = ($unit_base_num != 0.0) ? ((($unit_max_num - $unit_base_num) / $unit_base_num) * 100) : 0.0;
$max_increase_default = number_format($max_increase_num, 2, '.', '');
$max_increase_input = x2_saved_or_default($max_increase_saved, $max_increase_default);
?>

<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 !empty($write['x2_run']) ? 'checked' : ''; ?>>
                                    <span class="slider"></span>
                                </label>
                                <div class="tip-balloon">시스템 활성화 온/오프</div>
                            </div>
                            <div class="switch-box form-group switch-inline">
                                <span class="field-label">완료일 : </span>
                                <input type="datetime-local" name="x2_datetime" id="id_date_end" class="input-complete-date" value="<?php echo $x2_datetime_value; ?>">
                                <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>
                                    <?php if ($use_category_default) { ?>
                                    <option value="<?php echo $category_default; ?>" selected><?php echo $category_default; ?></option>
                                    <?php } else { ?>
                                    <option value="">분류 선택</option>
                                    <?php } ?>
                                    <?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_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 form-flex-1">
                                <input type="text" name="wr_subject" id="id_tag" value="<?php echo isset($write['wr_subject']) ? $write['wr_subject'] : ''; ?>" class="w-full" placeholder="제목">
                                <div class="tip-balloon">아웃라인 프로젝트 : 제목</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>

                <tr>
                    <td class="td-label"><i class="fa-solid fa-coins"></i> 추가 옵션</td>
                    <td class="td-content">
                        <div class="inline-fields-wrap">
                            <div class="form-group inline-field">
                                <span class="field-label">기본금액</span>
                                <input type="text" name="x2_base_amount" id="id_x2_base_amount" value="<?php echo $base_amount_input; ?>" placeholder="기본금액 입력">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">현재자산</span>
                                <input type="text" name="x2_current_asset" id="id_x2_current_asset" value="<?php echo $current_asset_input; ?>" placeholder="현재자산">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">목표금액</span>
                                <input type="text" name="x2_target_amount" id="id_x2_target_amount" value="<?php echo $target_amount_input; ?>" placeholder="목표금액 입력">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">수익금</span>
                                <input type="text" name="x2_profit_amount" id="id_x2_profit_amount" value="<?php echo $profit_amount_input; ?>" placeholder="수익금">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">수익률</span>
                                <input type="text" name="x2_profit_rate" id="id_x2_profit_rate" value="<?php echo $profit_rate_input; ?>" placeholder="수익률(%)">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">도달률</span>
                                <input type="text" name="x2_reach_rate" id="id_x2_reach_rate" value="<?php echo $reach_rate_input; ?>" placeholder="도달률(%)">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">목표형태</span>
                                <select name="x2_target_type" id="id_x2_target_type">
                                    <option value="">목표형태 선택</option>
                                    <?php $bo_3_opts = explode("|", $board['bo_3']); foreach($bo_3_opts as $val) { $val = trim($val); if($val==='') continue; $selected = (isset($write['x2_target_type']) && $write['x2_target_type'] == $val) ? "selected" : ""; echo "<option value='{$val}' {$selected}>{$val}</option>"; } ?>
                                </select>
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td class="td-label"><i class="fa-solid fa-coins"></i> 매매 금액</td>
                    <td class="td-content">
                        <div class="inline-fields-wrap">
                            <div class="form-group inline-field">
                                <span class="field-label">기본단위</span>
                                <input type="text" name="x2_unit_base" id="id_x2_unit_base" value="<?php echo $unit_base_input; ?>" placeholder="기본단위 입력">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">추가단위</span>
                                <input type="text" name="x2_unit_add" id="id_x2_unit_add" value="<?php echo $unit_add_input; ?>" placeholder="추가단위 입력">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">기본증가율</span>
                                <input type="text" name="x2_base_increase_rate" id="id_x2_base_increase_rate" value="<?php echo $base_increase_input; ?>" placeholder="자동기본증가율(%)">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">최대단위</span>
                                <input type="text" name="x2_unit_max" id="id_x2_unit_max" value="<?php echo $unit_max_input; ?>" placeholder="최대단위 입력">
                            </div>
                            <div class="form-group inline-field">
                                <span class="field-label">최대증가율</span>
                                <input type="text" name="x2_max_increase_rate" id="id_x2_max_increase_rate" value="<?php echo $max_increase_input; ?>" placeholder="자동최대증가율(%)">
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td class="td-label"><i class="fa-solid fa-coins"></i> 매매 종목</td>
                    <td class="td-content">
                        <div class="form-group block-field">
                            <input type="text" name="x2_trade_item" id="id_x2_trade_item" value="<?php echo isset($write['x2_trade_item']) ? $write['x2_trade_item'] : ''; ?>" class="w-full" placeholder="매매 종목 입력">
                        </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-file-lines"></i> 추가 설명</td>
                        <td class="td-content td-dark">
                            <textarea name="x2_text" id="id_x2_text" rows="6" class="w-full" placeholder="추가 설명을 입력하세요"><?php echo isset($write['x2_text']) ? get_text($write['x2_text'], 0) : ''; ?></textarea>
                        </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'); ?>