<?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'];
}
// 분류 기본값: 값 없으면 오늘 년도-월 (예: 2026-03)
$current_ca_name = $write['ca_name'] ? $write['ca_name'] : date("Y-m");
// 메모 영역 기본 열림 여부
$memo_open = !empty($write['x2_memo']);
$file_count = (isset($board['bo_upload_count']) && $board['bo_upload_count']) ? $board['bo_upload_count'] : 0;
?>
<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; ?>">
<input type="hidden" name="uid" value="<?php echo get_uniqid(); ?>">
<div class="write-top-bar">
<h2 class="write-top-title"><i class="fa-solid fa-rocket"></i> BACKUP 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" id="btn_submit">SAVE MISSION</button>
</div>
</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">
<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">
<option value=''>선택</option>
<?php
$bo_1_opts = explode("|", $board['bo_1']);
foreach ($bo_1_opts as $val) {
$val = trim($val); if (!$val) continue;
$sel = ($write['x2_ca2'] == $val) ? "selected" : "";
echo "<option value='{$val}' {$sel}>{$val}</option>";
}
?>
</select>
<span class="field-caption">형태</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) {
$val = trim($val); if (!$val) continue;
$sel = (isset($write['x2_ca3']) && $write['x2_ca3'] == $val) ? "selected" : "";
echo "<option value='{$val}' {$sel}>{$val}</option>";
}
?>
</select>
<span class="field-caption">종류</span>
<select name="x2_ca4" id="x2_ca4">
<option value=''>선택</option>
<?php
$bo_3_opts = explode("|", $board['bo_3']);
foreach ($bo_3_opts as $val) {
$val = trim($val); if (!$val) continue;
$sel = (isset($write['x2_ca4']) && $write['x2_ca4'] == $val) ? "selected" : "";
echo "<option value='{$val}' {$sel}>{$val}</option>";
}
?>
</select>
<span class="field-caption">버전</span>
<input type="text" name="x2_ver" value="<?php echo $default_ver; ?>" size="8" placeholder="Version">
<button type="button" class="btn-action btn-memo-toggle" id="memo-toggle-btn"
aria-expanded="<?php echo $memo_open ? 'true' : 'false'; ?>">메모</button>
<div class="date-time-wrap">
<i class="fa-regular fa-calendar-check" style="color:#aac; font-size:1rem;"></i>
<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>
<!-- 메모 슬라이딩 패널 -->
<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 (!empty($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 htmlspecialchars($write['x2_memo'], ENT_QUOTES); ?></textarea>
</div>
</td>
</tr>
<!-- ▣ 추가 옵션 -->
<tr>
<td class="td-label"><i class="fa-solid fa-sliders"></i> 추가 옵션</td>
<td class="td-value">
<div class="field-row-wrap">
<span class="field-caption no-margin">우선</span>
<input type="hidden" name="x2_top" value="0">
<label class="switch">
<input type="checkbox" name="x2_top" value="1"
<?php echo (!empty($write['x2_top']) && $write['x2_top'] == "1") ? "checked" : ""; ?>>
<span class="slider"></span>
</label>
<span class="field-caption no-margin">라벨</span>
<input type="hidden" name="x2_label" value="0">
<label class="switch">
<input type="checkbox" name="x2_label" value="1"
<?php echo (!empty($write['x2_label']) && $write['x2_label'] == "1") ? "checked" : ""; ?>>
<span class="slider"></span>
</label>
<span class="field-caption no-margin">완성</span>
<input type="hidden" name="x2_ok" value="0">
<label class="switch">
<input type="checkbox" name="x2_ok" value="1"
<?php echo (!empty($write['x2_ok']) && $write['x2_ok'] == "1") ? "checked" : ""; ?>>
<span class="slider"></span>
</label>
<span class="field-caption no-margin">세트</span>
<input type="hidden" name="x2_set" value="0">
<label class="switch">
<input type="checkbox" name="x2_set" value="1"
<?php echo (!empty($write['x2_set']) && $write['x2_set'] == "1") ? "checked" : ""; ?>>
<span class="slider"></span>
</label>
</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>
<!-- ▣ 백업 첨부 -->
<?php if ($is_file) { ?>
<tr>
<td class="td-label"><i class="fa-solid fa-paperclip"></i> 백업 첨부</td>
<td class="td-value">
<div id="variableFiles">
<?php for ($i = 0; $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.82rem; 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>
<?php } ?>
<!-- ▣ 태그 -->
<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%;" class="tag-input" 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 class="extra-code-section">
<h3 class="section-title"><i class="fa-solid fa-file-lines"></i> 내용</h3>
<?php echo $editor_html; ?>
</div>
<div class="extra-code-section">
<h3 class="section-title"><i class="fa-solid fa-code"></i> 추가 내용</h3>
<textarea name="x2_txt" rows="8" placeholder="추가 내용을 입력하세요"><?php echo htmlspecialchars($write['x2_txt'], ENT_QUOTES); ?></textarea>
</div>
<!-- 그누보드 링크 기능 -->
<div class="extra-code-section">
<h3 class="section-title"><i class="fa-solid fa-link"></i> 링크</h3>
<div class="link-item">
<i class="fa-solid fa-arrow-right"></i>
<input type="text" name="wr_link1" value="<?php echo $write['wr_link1']; ?>"
style="width:100%;" placeholder="참조 링크 #1">
</div>
<div class="link-item">
<i class="fa-solid fa-arrow-right"></i>
<input type="text" name="wr_link2" value="<?php echo $write['wr_link2']; ?>"
style="width:100%;" placeholder="참조 링크 #2">
</div>
</div>
</div>
<!-- ▣ 제출 버튼 -->
<div class="write-submit-wrap">
<button type="submit" class="btn-action btn-save-main" id="btn_submit_bottom">MISSION COMPLETE & SAVE</button>
</div>
</form>
</article>
</div>
<?php include_once("{$board_skin_path}/write/write.script.php"); ?>