<?php
include_once('./_common.php');

$html_title = '링크 &gt; '.conv_subject($write['wr_subject'], 255);

$no = isset($_REQUEST['no']) ? preg_replace('/[^0-9]/i', '', $_REQUEST['no']) : '';

if (!($bo_table && $wr_id && $no))
    alert_close('값이 제대로 넘어오지 않았습니다.');

// SQL Injection 예방
$row = sql_fetch(" select count(*) as cnt from {$g5['write_prefix']}{$bo_table} ", FALSE);
if (!$row['cnt'])
    alert_close('존재하는 게시판이 아닙니다.');

if (!$write['wr_link'.$no])
    alert_close('링크가 없습니다.');

$ss_name = 'ss_link_'.$bo_table.'_'.$wr_id.'_'.$no;
if (empty($_SESSION[$ss_name]))
{
    $sql = " update {$g5['write_prefix']}{$bo_table} set wr_link{$no}_hit = wr_link{$no}_hit + 1 where wr_id = '{$wr_id}' ";
    sql_query($sql);

    set_session($ss_name, true);
}
?>

<!DOCTYPE html>
<html lang="kr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: rgba(204, 204, 204, 0.5); /* Gray background color with 50% transparency */
            overflow: hidden; /* Hide scrollbars during loading */
        }

        #loading {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 20px;
        }

        .container {
            height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            display: none; /* Hide container initially */
        }

        .button-container {
            position: absolute;
            top: 10px;
            right: 10px; /* Adjust the right position for the button */
        }

        .close-button {
            padding: 10px 20px; /* Increase the padding for a larger button */
            font-size: 16px; /* Adjust the font size as needed */
            /* Add any additional styling for the button */
        }

        
        #iframeContainer {
            width: 100%; /* Make the iframe fill the container */
            max-width: 800px; /* Set a maximum width for the iframe container if needed */
        }

        #iframeContent {
            width: 100%;
            height: 500px;
            border: none;
        }
    </style>
</head>
<body>
<div id="loading">로딩 중...</div>
    <div class="container">
        <div class="button-container">
            <button class="close-button" onclick="closePage()">닫기</button>
        </div>

        <!-- Add an iframe container to center the iframe -->
        <div id="iframeContainer">
            <iframe id="iframeContent" frameborder="0"></iframe>
        </div>
    </div>

    <script>
        // Show loading text initially
        document.getElementById('loading').style.display = 'block';

        // Load the link content into the iframe
        document.getElementById('iframeContent').src = '<?php echo set_http($write['wr_link'.$no]); ?>';

        // Simulate a delay (you can remove this in a real scenario)
        setTimeout(function() {
            // Hide loading text and show container after loading
            document.getElementById('loading').style.display = 'none';
            document.querySelector('.container').style.display = 'flex';
        }, 2000); // Adjust the delay time as needed

        function closePage() {
            // Close the current window
            window.close();
        }
    </script>
</body>
</html>

