<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

include_once(G5_THEME_PATH.'/head.sub.php');
include_once(G5_LIB_PATH.'/latest.lib.php');
include_once(G5_LIB_PATH.'/outlogin.lib.php');
include_once(G5_LIB_PATH.'/poll.lib.php');
include_once(G5_LIB_PATH.'/visit.lib.php');
include_once(G5_LIB_PATH.'/connect.lib.php');
include_once(G5_LIB_PATH.'/popular.lib.php');
$oksite_bn = sql_fetch(" select * from `oksite_basic` where idx='1' ");
$oksite_mn = sql_fetch(" select * from `oksite_main` where idx='1' ");

?>

<!-- 상단 시작 { -->
<div id="hd" class="border-bottom">
  <div class="container">
    <div class="row">
        <h1 id="hd_h1"><?php echo $g5['title'] ?></h1>

        <div class="col-lg-6" id="skip_to_container"><a href="#container">본문 바로가기</a></div>

        <?php
        if(defined('_INDEX_')) { // index에서만 실행
            include G5_BBS_PATH.'/newwin.inc.php'; // 팝업레이어
        }
        ?>
        <div class="col-lg-6">
            <ul class="nav justify-content-end">
                <?php if ($is_member) {  ?>

                <li class="nav-item p-1 border-left"><a class="nav-link" href="<?php echo G5_BBS_URL ?>/member_confirm.php?url=<?php echo G5_BBS_URL ?>/register_form.php"><i class="fa fa-cog" aria-hidden="true"></i> 정보수정</a></li>
                <li class="nav-item p-1 border-left"><a class="nav-link" href="<?php echo G5_BBS_URL ?>/logout.php"><i class="fa fa-sign-out" aria-hidden="true"></i> 로그아웃</a></li>
                <?php if ($is_admin) {  ?>
                <li class="nav-item p-1 border-left"><a class="nav-link" href="<?php echo G5_ADMIN_URL ?>"><b><i class="fa fa-user-circle" aria-hidden="true"></i> 관리자</b></a></li>
                <?php }  ?>
                <?php } else {  ?>
                <li class="nav-item p-1 border-left"><a class="nav-link" href="<?php echo G5_BBS_URL ?>/register.php"><i class="fa fa-user-plus" aria-hidden="true"></i> 회원가입</a></li>
                <li class="nav-item p-1 border-left"><a class="nav-link" href="<?php echo G5_BBS_URL ?>/login.php"><b><i class="fa fa-sign-in" aria-hidden="true"></i> 로그인</b></a></li>
                <?php }  ?>
                <li class="nav-item p-1 border-left"><a class="nav-link" href="<?php echo G5_BBS_URL ?>/faq.php"><i class="fa fa-question" aria-hidden="true"></i> FAQ</a></li>
            </ul>

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

<div id="navigation" class="bg-danger mb-4">
  <div class="container">
    <nav class="navbar navbar-expand-lg navbar-dark bg-danger">
      <a class="navbar-brand" href="<?php echo G5_URL ?>"><?php
						$tr_logo = G5_PATH."/data/file/".$okone_bn['okone_file_name'];
					if($okone_bn['oksite_file_name'] && file_exists($tr_logo)){?>
					<img src="<?php echo G5_URL ?>/data/file/<?php echo $okone_bn['oksite_file_name']?>" alt="<?php echo $config['cf_title']; ?>">
					<?php } else {?>
					<img src="<?php echo G5_THEME_IMG_URL; ?>/logo.png" alt="<?php echo $config['cf_title']; ?>">
					<?php }?></a>

      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarokMobile" aria-controls="navbarokMobile" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarokMobile">
        <ul class="navbar-nav mr-auto">
          <?php
            $sql = " select *
              from {$g5['menu_table']}
              where me_use = '1'
              and length(me_code) = '2'
              order by me_order, me_id ";
            $result = sql_query($sql, false);
            $gnb_zindex = 999; // gnb_1dli z-index 값 설정용
            $menu_datas = array();

            for ($i=0; $row=sql_fetch_array($result); $i++) {
                $menu_datas[$i] = $row;

                $sql2 = " select *
                    from {$g5['menu_table']}
                    where me_use = '1'
                    and length(me_code) = '4'
                    and substring(me_code, 1, 2) = '{$row['me_code']}'
                    order by me_order, me_id ";
                $result2 = sql_query($sql2);
                for ($k=0; $row2=sql_fetch_array($result2); $k++) {
                  $menu_datas[$i]['sub'][$k] = $row2;
                }

              }

              $i = 0;
              foreach( $menu_datas as $row ){
                  if( empty($row) ) continue;

                  //submenu 확인하고 반영하기
                  if(!empty($row['sub'])){ // submenu 있는 경우
                    ?>
                    <li class = "nav-item dropdown">
                    <a class="nav-link text-white dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" href="<?php echo $row['me_link']; ?>" target="_<?php echo $row['me_target']; ?>"><?php echo $row['me_name'] ?></a>
                    <?php
                    $k = 0;
                      foreach( (array) $row['sub'] as $row2 ){

                        if( empty($row2) ) continue;

                        if($k == 0)
                            echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">'.PHP_EOL;
                        ?>
                        <a class="dropdown-item" href="<?php echo $row2['me_link']; ?>" target="_<?php echo $row2['me_target']; ?>"><?php echo $row2['me_name'] ?></a>
                        <?php
                        $k++;
                      }   //end foreach $row2

                      if($k > 0)
                      echo '</div>'.PHP_EOL;
                      ?>
                      </li>
                    <?php
                  } else { // submenu 없는 경우
                    ?>
                    <li class ="nav-item">
                    <a class="nav-link text-white" href="<?php echo $row['me_link']; ?>" target="_<?php echo $row['me_target']; ?>"><?php echo $row['me_name'] ?></a>
                    <?php
                    $k = 0;
                      foreach( (array) $row['sub'] as $row2 ){

                        if( empty($row2) ) continue;

                        if($k == 0)
                            echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">'.PHP_EOL;
                        ?>
                        <a class="dropdown-item" href="<?php echo $row2['me_link']; ?>" target="_<?php echo $row2['me_target']; ?>"><?php echo $row2['me_name'] ?></a>
                        <?php
                        $k++;
                      }   //end foreach $row2

                      if($k > 0)
                      echo '</div>'.PHP_EOL;
                      ?>
                      </li>

                    <?php
                  }

                  $i++;
                }   //end foreach $row

                if ($i == 0) {  ?>
                <li  class ='nav-item text-white'>메뉴 준비 중입니다.<?php if ($is_admin) { ?> <a href="<?php echo G5_ADMIN_URL; ?>/menu_list.php" class="text-white">관리자모드 &gt; 환경설정 &gt; 메뉴설정</a>에서 설정하실 수 있습니다.<?php } ?></li>
                <?php } ?>
    				 </ul>
             <?php
              if($oksite_mn['mainbbs1']){?>
                  <a class="btn btn-outline-light my-2 my-sm-0" href="<?php echo G5_BBS_URL; ?>/board.php?bo_table=<?php echo $oksite_mn['mainbbs1'];?>">예약확인</a>
              <?php } else {?>
                  <a class="btn btn-outline-light my-2 my-sm-0" href="<?php echo G5_BBS_URL; ?>/board.php?bo_table=qa">예약확인</a>
              <?php
              }
             ?>

    	</div><!-- #nav-menu-container -->
    </nav>
  </div>
</div>
<!-- } 상단 끝 -->

<!-- 콘텐츠 시작 { -->
<div id="main" class="container">
  <div class="row">

    <div class="col-lg-9 col-md-9 col-sm-6">
        <?php if (!defined("_INDEX_")) { ?>
          <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="<?php echo G5_URL; ?>/">Home</a></li>
              <li class="breadcrumb-item active" aria-current="page"><?php echo get_head_title($g5['title']); ?></li>
              </ol>
            </nav>
        <?php } ?>
