<?php
if (!defined('_GNUBOARD_')) exit; // 개별 실행 방지
$x2_ver = isset($_POST['x2_ver']) ? sql_real_escape_string(trim($_POST['x2_ver'])) : '';
$x2_ca2 = isset($_POST['x2_ca2']) ? sql_real_escape_string(trim($_POST['x2_ca2'])) : '';
$x2_ca3 = isset($_POST['x2_ca3']) ? sql_real_escape_string(trim($_POST['x2_ca3'])) : '';
$x2_ca4 = isset($_POST['x2_ca4']) ? sql_real_escape_string(trim($_POST['x2_ca4'])) : '';
$x2_txt = isset($_POST['x2_txt']) ? sql_real_escape_string($_POST['x2_txt']) : '';
$x2_top = (isset($_POST['x2_top']) && $_POST['x2_top'] == '1') ? '1' : '0';
$x2_project = isset($_POST['x2_project']) ? sql_real_escape_string(trim($_POST['x2_project'])) : '';
$x2_label = (isset($_POST['x2_label']) && $_POST['x2_label'] == '1') ? '1' : '0';
$x2_memo_clean = (isset($_POST['x2_memo_clean']) && $_POST['x2_memo_clean'] == '1') ? '1' : '0';
$x2_see = (isset($_POST['x2_see']) && $_POST['x2_see'] == '1') ? '1' : '0';
$x2_line = isset($_POST['x2_line']) ? sql_real_escape_string($_POST['x2_line']) : '';
$x2_memo = isset($_POST['x2_memo']) ? sql_real_escape_string($_POST['x2_memo']) : '';
$x2_note = isset($_POST['x2_note']) ? sql_real_escape_string($_POST['x2_note']) : '';
$x2_weather = isset($_POST['x2_weather']) ? sql_real_escape_string(trim($_POST['x2_weather'])) : '';
$x2_way = '';
if (isset($_POST['x2_way']) && is_array($_POST['x2_way'])) {
$x2_way_tokens = array();
foreach ($_POST['x2_way'] as $way_token) {
$way_token = trim($way_token);
if ($way_token === '') continue;
$x2_way_tokens[] = str_replace('|', '', $way_token);
}
if (!empty($x2_way_tokens)) {
$x2_way = sql_real_escape_string(implode(' | ', $x2_way_tokens));
}
}
$x2_point = '';
if (isset($_POST['x2_point']) && is_array($_POST['x2_point'])) {
$x2_point_tokens = array();
foreach ($_POST['x2_point'] as $point_token) {
$point_token = trim($point_token);
if ($point_token === '') continue;
$x2_point_tokens[] = str_replace('|', '', $point_token);
}
if (!empty($x2_point_tokens)) {
$x2_point = sql_real_escape_string(implode(' | ', $x2_point_tokens));
}
}
$x2_healing = '';
if (isset($_POST['x2_healing']) && is_array($_POST['x2_healing'])) {
$x2_healing_tokens = array();
foreach ($_POST['x2_healing'] as $healing_token) {
$healing_token = trim($healing_token);
if ($healing_token === '') continue;
$x2_healing_tokens[] = str_replace('|', '', $healing_token);
}
if (!empty($x2_healing_tokens)) {
$x2_healing = sql_real_escape_string(implode(' | ', $x2_healing_tokens));
}
}
$x2_routine = '';
if (isset($_POST['x2_routine']) && is_array($_POST['x2_routine'])) {
$x2_routine_tokens = array();
foreach ($_POST['x2_routine'] as $routine_token) {
$routine_token = trim($routine_token);
if ($routine_token === '') continue;
$x2_routine_tokens[] = str_replace('|', '', $routine_token);
}
if (!empty($x2_routine_tokens)) {
$x2_routine = sql_real_escape_string(implode(' | ', $x2_routine_tokens));
}
}
$x2_health = '';
if (isset($_POST['x2_health']) && is_array($_POST['x2_health'])) {
$x2_health_tokens = array();
foreach ($_POST['x2_health'] as $health_token) {
$health_token = trim($health_token);
if ($health_token === '') continue;
$x2_health_tokens[] = str_replace('|', '', $health_token);
}
if (!empty($x2_health_tokens)) {
$x2_health = sql_real_escape_string(implode(' | ', $x2_health_tokens));
}
}
$x2_week = '';
if (isset($_POST['x2_week']) && is_array($_POST['x2_week'])) {
$x2_week_tokens = array();
for ($week_idx = 0; $week_idx < 7; $week_idx++) {
$week_token = isset($_POST['x2_week'][$week_idx]) ? trim($_POST['x2_week'][$week_idx]) : '';
$week_token = str_replace('^', ' ', $week_token);
$x2_week_tokens[] = $week_token;
}
$x2_week = sql_real_escape_string(implode(' ^ ', $x2_week_tokens));
}
$x2_daily = isset($_POST['x2_daily']) ? sql_real_escape_string($_POST['x2_daily']) : '';
$x2_key = isset($_POST['x2_key']) ? sql_real_escape_string($_POST['x2_key']) : '';
$x2_ess = isset($_POST['x2_ess']) ? sql_real_escape_string($_POST['x2_ess']) : (isset($_POST['x2_Ess']) ? sql_real_escape_string($_POST['x2_Ess']) : '');
$x2_extra1 = isset($_POST['x2_extra1']) ? sql_real_escape_string(trim($_POST['x2_extra1'])) : '';
$x2_extra2 = isset($_POST['x2_extra2']) ? sql_real_escape_string(trim($_POST['x2_extra2'])) : '';
// 2. 날짜/시간 커스텀 업데이트 로직 정제
$add_sql = "";
if (!empty($_POST['wr_date_custom']) && !empty($_POST['wr_time_custom'])) {
$custom_datetime = "{$_POST['wr_date_custom']} {$_POST['wr_time_custom']}";
$add_sql = " , wr_datetime = '{$custom_datetime}' ";
}
// 3. 폼 입력값 기준으로 커스텀 컬럼 업데이트
$sql = " UPDATE {$write_table}
SET x2_ver = '{$x2_ver}',
x2_ca2 = '{$x2_ca2}',
x2_ca3 = '{$x2_ca3}',
x2_ca4 = '{$x2_ca4}',
x2_txt = '{$x2_txt}',
x2_top = '{$x2_top}',
x2_project = '{$x2_project}',
x2_label = '{$x2_label}',
x2_line = '{$x2_line}',
x2_note = '{$x2_note}',
x2_memo = '{$x2_memo}',
x2_memo_clean = '{$x2_memo_clean}',
x2_weather = '{$x2_weather}',
x2_see = '{$x2_see}',
x2_way = '{$x2_way}',
x2_point = '{$x2_point}',
x2_healing = '{$x2_healing}',
x2_routine = '{$x2_routine}',
x2_health = '{$x2_health}',
x2_week = '{$x2_week}',
x2_daily = '{$x2_daily}',
x2_key = '{$x2_key}',
x2_ess = '{$x2_ess}',
x2_extra1 = '{$x2_extra1}',
x2_extra2 = '{$x2_extra2}'
{$add_sql}
WHERE wr_id = '{$wr_id}' ";
$result = sql_query($sql, false);
if (!$result) {
$sql_extra = " UPDATE {$write_table}
SET x2_way = '{$x2_way}',
x2_point = '{$x2_point}',
x2_healing = '{$x2_healing}',
x2_routine = '{$x2_routine}',
x2_health = '{$x2_health}',
x2_note = '{$x2_note}',
x2_weather = '{$x2_weather}',
x2_week = '{$x2_week}',
x2_daily = '{$x2_daily}',
x2_key = '{$x2_key}',
x2_ess = '{$x2_ess}',
x2_extra1 = '{$x2_extra1}',
x2_extra2 = '{$x2_extra2}'
WHERE wr_id = '{$wr_id}' ";
sql_query($sql_extra, false);
}
?>