<?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'];
}
// [혜정 센스] 분류 기본값 설정 로직: 현재값 없으면 오늘 날짜(YYYY-MM)
$current_ca_name = $write['ca_name'] ? $write['ca_name'] : date("Y-m");
$selected_styles = array();
if (!empty($write['x2_style'])) {
$selected_styles = array_filter(array_map('trim', explode('|', $write['x2_style'])));
}
$selected_shadows = array();
if (!empty($write['x2_shadow'])) {
$selected_shadows = array_filter(array_map('trim', explode('|', $write['x2_shadow'])));
}
$bo_4_opts = array_filter(array_map('trim', explode('|', (string)$board['bo_4'])));
$bo_5_opts = array_filter(array_map('trim', explode('|', (string)$board['bo_5'])));
$bo_6_opts = array_filter(array_map('trim', explode('|', (string)$board['bo_6'])));
$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_date = date('Y-m-d');
$line_time = date('H:i:s');
$line_content = '';
$line_title = '';
if (strpos($line_token, '#') !== false) {
$line_parts = explode('#', $line_token, 4);
$line_date = isset($line_parts[0]) && trim($line_parts[0]) !== '' ? trim($line_parts[0]) : date('Y-m-d');
$line_content = isset($line_parts[1]) ? trim($line_parts[1]) : '';
$line_title = isset($line_parts[2]) ? trim($line_parts[2]) : '';
$line_time = isset($line_parts[3]) && trim($line_parts[3]) !== '' ? trim($line_parts[3]) : date('H:i:s');
} else {
$line_parts = explode('^', $line_token, 2);
$line_content = isset($line_parts[0]) ? trim($line_parts[0]) : '';
if (isset($line_parts[1]) && trim($line_parts[1]) !== '') {
$legacy_datetime = trim($line_parts[1]);
$line_date = preg_match('/^\d{4}-\d{2}-\d{2}/', $legacy_datetime) ? substr($legacy_datetime, 0, 10) : date('Y-m-d');
$line_time = preg_match('/\d{2}:\d{2}:\d{2}$/', $legacy_datetime) ? substr($legacy_datetime, 11, 8) : date('H:i:s');
}
}
$line_rows[] = array(
'date' => $line_date,
'time' => $line_time,
'content' => $line_content,
'title' => $line_title
);
}
}
if (empty($line_rows)) {
$line_rows[] = array(
'date' => date('Y-m-d'),
'time' => date('H:i:s'),
'content' => '',
'title' => ''
);
}
$memo_open = !empty($write['x2_memo']);
?>
<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> ROUTINE 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>
<table class="write-table">
<tr>
<td class="td-label"><i class="fa-solid fa-sliders"></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-memo-toggle" id="memo-toggle-btn" aria-expanded="<?php echo $memo_open ? 'true' : 'false'; ?>">메모</button>
<div class="date-time-wrap">
<span class="field-caption no-margin">버전</span>
<input type="text" name="x2_ver" value="<?php echo $default_ver; ?>" size="8" placeholder="Version">
<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 (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-gears"></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 (isset($write['x2_see']) && $write['x2_see'] == "1") ? "checked" : ""; ?>>
<span class="slider"></span>
</label>
<span class="field-caption">반복</span>
<label class="switch">
<input type="checkbox" name="x2_ds" value="1" <?php echo (isset($write['x2_ds']) && $write['x2_ds'] == '1') ? 'checked' : ''; ?>>
<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">
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-palette"></i> 스타일</td>
<td class="td-value">
<div class="field-row-wrap style-shadow-wrap">
<?php if (!empty($bo_4_opts)) { ?>
<?php foreach ($bo_4_opts as $style_opt) {
$is_checked = in_array($style_opt, $selected_styles, true);
?>
<div class="toggle-item-wrap">
<span class="field-caption no-margin"><?php echo $style_opt; ?></span>
<label class="switch">
<input type="checkbox" name="x2_style[]" value="<?php echo htmlspecialchars($style_opt, ENT_QUOTES); ?>" <?php echo $is_checked ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
<?php } ?>
<?php } else { ?>
<span class="field-caption no-margin">bo_4 값이 없습니다.</span>
<?php } ?>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-moon"></i> 힐링</td>
<td class="td-value">
<div class="field-row-wrap style-shadow-wrap">
<?php if (!empty($bo_5_opts)) { ?>
<?php foreach ($bo_5_opts as $style_opt) {
$is_checked = in_array($style_opt, $selected_styles, true);
?>
<div class="toggle-item-wrap">
<span class="field-caption no-margin"><?php echo $style_opt; ?></span>
<label class="switch">
<input type="checkbox" name="x2_style[]" value="<?php echo htmlspecialchars($style_opt, ENT_QUOTES); ?>" <?php echo $is_checked ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
<?php } ?>
<?php } else { ?>
<span class="field-caption no-margin">bo_5 값이 없습니다.</span>
<?php } ?>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-moon"></i> 일상</td>
<td class="td-value">
<div class="field-row-wrap style-shadow-wrap">
<?php if (!empty($bo_6_opts)) { ?>
<?php foreach ($bo_6_opts as $shadow_opt) {
$is_checked = in_array($shadow_opt, $selected_shadows, true);
?>
<div class="toggle-item-wrap">
<span class="field-caption no-margin"><?php echo $shadow_opt; ?></span>
<label class="switch">
<input type="checkbox" name="x2_shadow[]" value="<?php echo htmlspecialchars($shadow_opt, ENT_QUOTES); ?>" <?php echo $is_checked ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
<?php } ?>
<?php } else { ?>
<span class="field-caption no-margin">bo_6 값이 없습니다.</span>
<?php } ?>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-heading"></i> 루틴 제목</td>
<td class="td-value">
<input type="text" name="wr_subject" class="full-width-input" value="<?php echo $subject; ?>" required 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" class="full-width-input" value="<?php echo $write['wr_1']; ?>" 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" class="<?php echo ($w=='u' || $write['wr_content']) ? 'is-open' : ''; ?>">
<div class="editor-holder">
<h3 class="section-title"><i class="fa-solid fa-code"></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="4" 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> 루틴 라인
<span class="field-caption">날짜 미출력</span>
<label class="switch">
<input type="checkbox" name="x2_de" value="1" <?php echo (isset($write['x2_de']) && $write['x2_de'] == '1') ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</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-top-wrap">
<input type="text" class="work-line-title" value="<?php echo htmlspecialchars($line_row['title'], ENT_QUOTES); ?>" placeholder="루틴 제목을 입력하세요">
<div class="work-line-date-wrap">
<span class="field-caption no-margin">날짜</span>
<input type="date" class="work-line-date" value="<?php echo htmlspecialchars($line_row['date'], ENT_QUOTES); ?>">
</div>
<div class="work-line-time-wrap">
<span class="field-caption no-margin">시간</span>
<input type="time" class="work-line-time" step="1" value="<?php echo htmlspecialchars($line_row['time'], ENT_QUOTES); ?>">
</div>
</div>
<textarea class="work-line-content" rows="6" 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" rowspan="2"><i class="fa-solid fa-link"></i> 링크 #1</td>
<td class="td-value">
<div class="link-item">
<input type="text" name="wr_link1" class="full-width-input" value="<?php echo $write['wr_link1']; ?>" placeholder="참조 링크 #1">
</div>
</td>
</tr>
<tr>
<td class="td-value">
<div class="link-item">
<input type="text" name="wr_link2" class="full-width-input" value="<?php echo $write['wr_link2']; ?>" 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; ?>" class="file-input-hidden" onchange="updateFileName(this, <?php echo $i; ?>)">
<span id="file_name_<?php echo $i; ?>" class="file-name-view">
<?php if($w == 'u' && isset($file[$i]['file']) && $file[$i]['file']) {
echo $file[$i]['source'];
echo " <label class='file-delete-label'><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"); ?>