<?php
# vim: set fenc=utf-8 ci sts=4 ts=4 et:
require_once __DIR__ . '/common/csrf.php';
require_once __DIR__ . '/init.php';
require_once 'aip/FileControl.php';

# AIP 뉴스
$sql = "SELECT seq, title, thumnail, content, regdate FROM board_notice WHERE delflag='n' AND mainy='y' ORDER BY seq DESC LIMIT 3";
$aipnews = $db->lists($sql);

$cssFiles = ['/css/main.css', '/css/popup.css', '/css/modal.css'];
$jsFiles = [
    '/js/main.js',
    '/js/velocity.min.js',
    '/js/velocity.ui.min.js',
];
require_once WEB_DIR . '/header.php';
?>

<script>
$(function() {
    $(".modal1").each(function(l) {
        $(this).on("show.bs.modal", function(l) {
            var o = $(this).attr("data-easein");
            "shake" == o ? $(".modal-dialog").velocity("callout." + o) : "pulse" == o ? $(
                ".modal-dialog").velocity("callout." + o) : "tada" == o ? $(
                ".modal-dialog").velocity("callout." + o) : "flash" == o ? $(
                ".modal-dialog").velocity("callout." + o) : "bounce" == o ? $(
                ".modal-dialog").velocity("callout." + o) : "swing" == o ? $(
                ".modal-dialog").velocity("callout." + o) : $(".modal-dialog").velocity(
                "transition." + o)
        })
    });
})
</script>

<main role="main" id="main">
    <section id="bnr">
        <div class="container">
            <div class="main-contents center column">
                <h1 class="main-title">AIP</h1>
                <p class="main-sub-title center"><span>A</span>dvanced <span>I</span>ndustrial Strategy
                    <span>P</span>rogram
                    <!-- <img src="/img/main/icon_arrow.svg" alt="화살표이미지"> -->
                </p>
                <h2 class="main-desc">
                    기술지식 중심의 최고경영리더교육,<br>
                    최고경영자들을 위해 준비된 특별한 교육 프로그램
                </h2>
                <div class="aip-nav start">
                    <div class="aip-title start">
                        <img src="/img/main/img_txt.svg" alt="Advanced Industrial Strategy Program">
                    </div>
                    <a class="aip-scroll center hand">
                        <img src="/img/main/icon_arrow_down.svg" alt="스크롤다운버튼">
                    </a>
                </div>
            </div>
        </div>
    </section>
    <section id="desc">
        <div class="container between">
            <div class="desc-left">
                <p class="aip-desc">
                    성공한 리더가 또 다른 리더를 육성하는데<br>
                    이바지 할 수 있도록 최고산업전략과정에서는 <br>
                    미래지향적 도전의식과 잠재력을 갖춘 <br>
                    여러분을 초대합니다.
                </p>
                <a class="start" href="/intro/curriculum.php">View more <img src="/img/main/icon_arrow_more.svg"
                        alt="더보기 버튼"></a>
            </div>
            <div class="desc-right start-col column">
                <a class="center column" href="/intro/curriculum/subject.php"><img src="/img/main/icon_curriculum.svg"
                        alt="교과 내용으로 이동">교과 내용</a>
                <a class="center column" href="/intro/curriculum/benefit.php"><img
                        src="/img/main/icon_characteristic.svg" alt="특성 및 특전으로 이동">특성 및 특전</a>
            </div>
        </div>
    </section>
    <section id="program">
        <div class="container between-start">
            <div class="program-left">
                <h2 class="program-title">PROGRAM</h2>
                <p class="program-desc">
                    기술혁신에능동적으로 대처하는 창조적 최고경영자의<br>
                    핵심역량을 개발합니다. </p>
            </div>
            <div class="program-right">
                <div class="slide-img-frame">
                    <img class="slide-img slide-img-1" src="/img/main/program_1.jpg" alt="배경이미지">
                    <img class="slide-img slide-img-2" src="/img/main/program_2.jpg" alt="배경이미지">
                    <img class="slide-img slide-img-3" src="/img/main/program_3.jpg" alt="배경이미지">

                </div>
            </div>
            <div class="slide-container">
                <div class="slide-contents">
                    <div class="slide-item">
                        <p class="slide-title">하이테크</p>
                        <h3 class="slide-title-en">HIGHTECH</h3>
                        <p class="slide-desc">4차 산업혁명과 인공지능, 산업의 터닝 포인트,<br>
                            백 투 베이직 등의 과정 들로 구성
                        </p>
                    </div>
                    <div class="slide-item">
                        <p class="slide-title">메가트렌드</p>
                        <h3 class="slide-title-en">Megatrends</h3>
                        <p class="slide-desc">사회적인 트렌드, 이슈의 주제와 4차 산업혁명의 혁신과<br> 융합 기술에 대한 과정들로 구성
                        </p>
                    </div>
                    <div class="slide-item">
                        <p class="slide-title">컨버전스</p>
                        <h3 class="slide-title-en">Convergence</h3>
                        <p class="slide-desc">경영진의 다각화를 위한 수업으로 리더십, 문화와 역사,<br> 선업정책의 이해 등 다양한 과정들로 구성
                        </p>
                    </div>
                    <nav class="slide-nav end">
                        <button id="nav-prev" class="nav-btn prev center"><img src="/img/main/icon_indicator_left.svg"
                                alt="이전"></button>
                        <button id="nav-next" class="nav-btn next center"><img src="/img/main/icon_indicator_right.svg"
                                alt="다음"></button>
                    </nav>
                </div>
            </div>
        </div>
    </section>
    <section id="testimonial">
        <div class="container">
            <div class="notice between-start">
                <div class="news">
                    <h2 class="notice-title between">AIP News
                        <a href="/bbs/notice/board_list.php"><img src="/img/main/icon_plus.svg" alt="더보기"></a>
                    </h2>
                    <ul class="notice-list">
                        <?php foreach ((array)$aipnews as $data) {
                            $sContent = Util::cutString(strip_tags(str_replace('&nbsp;', ' ', $data['content'])), 140, '...');
                        ?>
                        <li><a class="between"
                                href="/bbs/notice/board_read.php?seq=<?= $data['seq'] ?>"><?= $data['title'] ?><span
                                    class="date"><?= date('Y.m.d', $data['regdate']) ?></span></a></li>
                        <?php } ?>
                    </ul>
                </div>
                <div class="download">
                    <h2 class="notice-title">Download</h2>
                    <div class="download-contents center">
                        <div class="download-item download-item-1">
                            73기
                            <a href="/doc/brochure_73th.pdf" target="_blank">
                                <button type="button"><img src="/img/main/icon_download.svg"
                                        alt="안내 책자 브로슈어 다운로드"></button>
                            </a>
                        </div>
                        <div class="download-item download-item-2">
                            접수 지원서 다운로드
                            <!-- edit file 20260220 <a href="/doc/aip_form.hwp" target="_blank">-->
                            <a href="/doc/AIP_지원서.hwp" target="_blank">
                                <button type="button"><img src="/img/main/icon_download.svg" alt="접수 지원서 다운로드"></button>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="testimonial-contents">
                <h3 class="testimonial-title">Testimonial</h3>
                <div id="testimonial-panel1" class="tbox">
                    <div class="between">
                        <div class="testimonial-desc-frame">
                            <p class="testimonial-desc">서울대학교 최고산업전략과정(AIP)은 1989년 설립된 이후 66회에 걸쳐 3,400여명의 동문을 배출한 역사와 전통을 자랑하는 대한민국 최고의 최고경영자 과정입니다.
                                <br>국내 최고의 서울대학교 공과대학은 320여명의 우수한 교수진과 인공지능, 빅데이터, 클라우드, 블록체인 등의 신기술을 기반으로 새롭게 조직화되고 있는 FAANG공화국의 글로벌 네트워크
                                경제(플랫폼 경제)와 전통 제조업을 결합하여 혁신적인 새로운 비전을 제시하며 함께 고민하고 이끌어 갈 세계 최고의 기술 지식 중심의 최고경영자과정에 참여하시어 한국 사회를 이끌어가고 있는
                                최고의 오피니언 리더들에게 본 과정을 추천합니다.
                            </p>

                        </div>
                        <div class="testimonial-img-frame cener-top column">
                            <img src="../img/intro/recommend/profile_43.png" />
                            <p class="writer">김형진 / 총동창회 16대 회장 <br>
                                ㈜세종텔레콤 대표이사 회장</p>
                        </div>
                    </div>
                </div>
                <div id="testimonial-panel2" class="tbox">
                    <div class="between">
                        <div class="testimonial-desc-frame">
                            <p class="testimonial-desc"></p>
                        </div>
                        <div class="testimonial-img-frame center-top column">
                            <img src="" />
                            <p class="writer"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>

<?php
$sql = "SELECT a.seq, a.title, a.height, a.edate, a.width, a.url, a.content, b.rfilename, b.filename FROM board_popup AS a JOIN board_popup_file AS b ON a.seq=b.seq WHERE a.openy='y' AND a.delflag = 'n' AND a.sdate <= CURRENT_DATE() AND a.edate >= CURRENT_DATE() ORDER BY a.seq DESC LIMIT 1";
$data = $db->select($sql);

if (empty($data) == false) {
    $seq = $data['seq'];
    $title = $data['title'];
    $height = $data['height'];
    $width = $data['width'];
    $edate = strtotime($data['edate']);
    $url = $data['url'];
    $content = $data['content'];
    $filename = $data['rfilename'];
    $filenameForPDF = $data['filename'];

    // 파일이 PDF 인지 아닌지 여부 판단
    $filepath = DATA_DIR . "/popup/" . $filename;

    if (file_exists($filepath)) {

        // 
?>
<script>
//$(function() {
//    if (getCookie('popup') != 'popup') {
//        $("#costumModal30").modal('show', {
//            backdrop: 'static'
//        });
    }
    // else {
    //     $("#costumModal30").css('display', 'none');
    // }
    //})
    //

// 팝업이 뜨지 않아 뒤로 모달 html 뒤로 이동시켰음
// $(document).ready(function() {
//    // getCookie 함수가 정의될 때까지 대기
//    function tryShowPopup() {
//        if (typeof getCookie === 'function') {
//            if (getCookie('popup') != 'popup') {
//                $("#costumModal30").modal('show', {
//                    backdrop: 'static'
//                });
//            }
//        } else {
//            // getCookie 함수가 아직 로드되지 않았다면 잠시 후 다시 시도
//            setTimeout(tryShowPopup, 100);
//        }
//    }
//    tryShowPopup();
// })


</script>
<div id="costumModal30" style="display:none; top: 10px; transform: translateX(-50%);" class="modal1 main-modal" data-easein="bounceIn" tabindex="-1"
    role="dialog" aria-labelledby="costumModalLabel" aria-hidden="true">
    <div class="modal-dialog main-modal-dialog">
        <!-- <div class="modal-content main-modal-content">
                <div class="modal-body main-modal-body"> -->
         <div class="modal-content main-modal-content" style="position: relative;">
            <button type="button" id="popup-close-top" style="position: absolute; top: 10px; right: 10px; z-index: 10000; background: rgba(0,0,0,0.5); color: #fff; border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s;" onmouseover="this.style.background='rgba(0,0,0,0.7)'" onmouseout="this.style.background='rgba(0,0,0,0.5)'" title="닫기">×</button>
             <div class="modal-body main-modal-body">
                <div class="popup center column">
                    <img class="popup-img" id="popup-img" src="/inc/image.php?d=popup&f=<?= urlencode($filename) ?>"
                        url="<?= $url ?>" alt="팝업이미지"
                        style="cursor:pointer;width: <?= $width ?>px; height: <?= $height ?>px;">
                    <div class="popup-control between" style="cursor:pointer;width:<?= $width ?>px">
                        <div class="check-grp">
                            <div class="check-item">
                                <input type="checkbox" id="n_show">
                                <div class="showCheck"></div>
                                <label for="n_show">오늘 하루 보지 않기</label>
                            </div>
                        </div>
                        <a class="close" id="popup-close" style="cursor: pointer;"> 닫기</a>
                    </div>
                    <div class="popup-side-btn">
                        <?php
                                if ($url) {
                                ?>
                        <button type="button" id="goPage" class="btn-default orange side-btn">
                            <a href="<?= $url ?>" class="close" style="cursor: pointer;">
                                <span>
                                    모집 상세 안내
                                </span>
                            </a>
                        </button>
                        <?php
                                }
                                $filepath = DATA_DIR . "/popup/" . $filenameForPDF;

                                if (FileControl::isPdf($filepath)) {
                                ?>
                        <button type="button" id="openPdfViewer" class="btn-default orange side-btn">
                            <a class="close " style="cursor: pointer;">
                                <span>
                                    브로슈어 보기
                                </span>
                            </a>
                        </button>
                        <?php
                                }
                            if($content){
                                ?>
                        <button type="button" class="btn-default orange side-btn content">
                            <a class="close " href="/doc/brochure_73th.pdf" target="_blank">
                            <span>
                                <?= $content ?>
                            </span>
                            </a>
                        </button>
                        <?php }?>
                        <button type="button" id="goApplication" class="btn-default orange side-btn">
                            <a class="close" style="cursor: pointer;">
                                <span>
                                    원서 접수
                                </span>
                            </a>
                        </button>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<form name="formData" id="formData" method="get" action="pdfpopup.php" target="new">
    <input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
    <input type="hidden" name="filename" id="filename" value="<?= $filenameForPDF ?>">
    <input type="hidden" name="url" id="url" value="<?= $url ?>">
</form>

<script>
                                    
// 팝업이 뜨지 않아 뒤로 모달 html 뒤에 스크립트 추가
//$(function() {
$(document).ready(function() {
    // 팝업 모달 열기
    function tryShowPopup() {
        if (typeof getCookie === 'function') {
            if (getCookie('popup') != 'popup') {
                // 스크롤 복원 상태에서 팝업이 화면 밖에 가려지는 문제 방지
                window.scrollTo(0, 0);        
                // Bootstrap 모달이 로드되었는지 확인
                if (typeof bootstrap !== 'undefined' && bootstrap.Modal) {
                    // Bootstrap 5 방식
                    var modalElement = document.getElementById('costumModal30');
                    if (modalElement) {
                        var modal = new bootstrap.Modal(modalElement, {
                            backdrop: 'static',
                            keyboard: false
                        });
                        modal.show();
                     }
                } else if (typeof $.fn.modal !== 'undefined') {
                    // Bootstrap 4/jQuery 방식 (fallback)
                    $("#costumModal30").modal('show', {
                        backdrop: 'static'
                    });
                }
            }
        } else {
            // getCookie 함수가 아직 로드되지 않았다면 잠시 후 다시 시도
            setTimeout(tryShowPopup, 100);
        }
    }
    
    // 모달이 DOM에 추가된 후 실행
    if ($('#costumModal30').length > 0) {
        tryShowPopup();
    } else {
        // 모달이 아직 없으면 잠시 후 다시 시도
        setTimeout(function() {
            if ($('#costumModal30').length > 0) {
                tryShowPopup();
            }
        }, 100);
    }

    // 우측 상단 X 버튼 클릭 이벤트
    $("#popup-close-top").on("click", function() {
        if (typeof closePopup === 'function') {
            closePopup();
        } else {
            // closePopup 함수가 없으면 직접 닫기
            if (typeof bootstrap !== 'undefined' && bootstrap.Modal) {
                var modalElement = document.getElementById('costumModal30');
                if (modalElement) {
                    var modal = bootstrap.Modal.getInstance(modalElement);
                    if (modal) {
                        modal.hide();
                    }
                }
            } else if (typeof $.fn.modal !== 'undefined') {
                $("#costumModal30").modal('hide');
            }
        }
    });

    // 기타 이벤트 핸들러
    $("#goPage").on("click", function() {
        location.href = "<?= $url ?>"
    })

    $("#openPdfViewer").on("click", function() {
        window.open("", "new",
            "toolbar=no, menubar=no, scrollbars=no, resizable=yes, width=800px, height=950px, left=0, top=0"
        );
        $("#formData").submit();
    })

    $("#goApplication").on("click", function() {
        location.href = "/admission/application.php"
    })
})
</script>

<?php
    }
}
// }
?>
<?php require_once WEB_DIR . '/footer.php'; ?>
