OLDBOY/skin/board/daemon_kind_sotck/write_update.skin.php
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
## 날짜/시간
$wr_datetime = "{$date} {$time}";
sql_query(" update $write_table set wr_datetime = '$wr_datetime' where wr_id = '$wr_id' ");
//-----------------------------------------------
## 종료일/시
if ($x2_end) {
    $x2_datetime = "{$x2_ymd} {$x2_his}";
    sql_query(" update $write_table set x2_datetime = '$x2_datetime' where wr_id = '$wr_id' ");
} else {
    sql_query(" update $write_table set x2_datetime = '' where wr_id = '$wr_id' ");
}
//-----------------------------------------------
## 비트코인 시세 집계 날짜
if ($jy_btc) {
    $btc_datetime = "{$btc_ymd} {$btc_his}";
    sql_query(" update $write_table set btc_datetime = '$btc_datetime' where wr_id = '$wr_id' ");
} else {
    sql_query(" update $write_table set btc_datetime = '' where wr_id = '$wr_id' ");
}
//-----------------------------------------------



sql_query(" update $write_table set x2_run = '$x2_run' where wr_id = '$wr_id' ");
sql_query(" update $write_table set x2_ca2 = '$x2_ca2' where wr_id = '$wr_id' ");
sql_query(" update $write_table set x2_ca3 = '$x2_ca3' where wr_id = '$wr_id' ");
sql_query(" update $write_table set x2_tag = '$x2_tag' where wr_id = '$wr_id' ");
sql_query(" update $write_table set x2_ver = '$x2_ver' where wr_id = '$wr_id' ");





// 1. 오빠가 입력한 코인명 (순정 이름)
$origin_coin = isset($wr_subject) ? trim($wr_subject) : '';

if ($origin_coin) {
    // 2. [목표 설정] 오빠 명령(x2_run)에 따라 최종 이름표 결정
    // 켜져 있으면(1) -> 순정 ("BTC")
    // 꺼져 있으면 -> 낙인 ("OFF_BTC")
    $is_active = (isset($_POST['x2_run']) && $_POST['x2_run'] == '1');
    $final_market = $is_active ? $origin_coin : 'OFF_' . $origin_coin;

    // 3. [구멍 탐색] 순정이든 낙인이든 일단 이 코인 행이 있는지 찾음
    // "야, 너 BTC든 OFF_BTC든 뭐라도 있냐?"
    global $db_upbit; // extend 연결 소환

    if (isset($db_upbit) && $db_upbit) {
        try {
            // 검색 조건: 순정 이름 OR 낙인 이름 둘 중 하나라도 있는지 확인
            $check_sql = "SELECT id, market FROM stats_direction_01 WHERE market IN (:clean, :off)";
            $stmt = $db_upbit->prepare($check_sql);
            $stmt->execute([
                ':clean' => $origin_coin, 
                ':off' => 'OFF_' . $origin_coin
            ]);
            
            $row = $stmt->fetch();

            if ($row) {
                // ★ [UPDATE] 이미 있는 년이다! -> 이름표만 바꿔 달아줌
                // 기존 값이랑 다를 때만 업데이트 (쓸데없는 짓 안 하게)
                if ($row['market'] != $final_market) {
                    $update_sql = "UPDATE stats_direction_01 SET market = :new_market, collected_at = NOW() WHERE id = :id";
                    $stmt_up = $db_upbit->prepare($update_sql);
                    $stmt_up->execute([
                        ':new_market' => $final_market,
                        ':id' => $row['id']
                    ]);
                }
            } else {
                // ★ [INSERT] 아예 없는 년이다! -> 새로 박음
                $insert_sql = "INSERT INTO stats_direction_01 (market, collected_at) VALUES (:new_market, NOW())";
                $stmt_in = $db_upbit->prepare($insert_sql);
                $stmt_in->execute([':new_market' => $final_market]);
            }

        } catch (PDOException $e) {
            // 에러 무시
        }
    }
}
?>