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

if (G5_IS_MOBILE) {
    include_once(G5_THEME_MOBILE_PATH.'/index.php');
    return;
}

include_once(G5_THEME_PATH.'/head.php');
?>

<h2 class="sound_only">최신글</h2>

<div class="latest_wr">
<!-- 최신글 시작 { -->

    <?php
    //  최신글
    $sql = " select bo_table
                from `{$g5['board_table']}` a left join `{$g5['group_table']}` b on (a.gr_id=b.gr_id)
                where a.bo_device <> 'mobile' ";
    if(!$is_admin)
        $sql .= " and a.bo_use_cert = '' ";
    $sql .= " and a.bo_table not in ('notice', 'gallery') ";     //공지사항과 갤러리 게시판은 제외
    $sql .= " order by b.gr_order, a.bo_order ";
    $result = sql_query($sql);
    for ($i=0; $row=sql_fetch_array($result); $i++) {
        if ($i%2==1) $lt_style = "margin-left:2%";
        else $lt_style = "";
    ?>
    <div style="float:left;<?php echo $lt_style ?>" class="lt_wr">
        <?php
        // 이 함수가 바로 최신글을 추출하는 역할을 합니다.
        // 사용방법 : latest(스킨, 게시판아이디, 출력라인, 글자수);
        // 테마의 스킨을 사용하려면 theme/basic 과 같이 지정
        echo latest('theme/basic', $row['bo_table'], 6, 24);
        ?>
    </div>
    <?php
    }
    ?>
    <!-- } 최신글 끝 -->
</div>


<?php
$today = date("Y-m-d");
$todays = explode('-',$today);

$year = $todays[0]; //년도
$month = $todays[1];//달
$day = $todays[2];//일

$ch = curl_init();
$url = 'http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/getRestDeInfo'; /*URL*/
$queryParams = '?' . urlencode('ServiceKey') . '=API key !!!!!!!!!!!!!!!!!!!!!! '; /*Service Key*/
$queryParams .= '&' . urlencode('solYear') . '=' . urlencode($year); /*연*/
$queryParams .= '&' . urlencode('solMonth') . '=' . urlencode($month); /*월*/

curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
curl_close($ch);


echo $response;

$xml = simplexml_load_string($response);

?>
<style>
.format{
  width:150px;
  text-align:center;
}
</style>
<br><br><br>

<!-- Wrap all page content in a page container (optional, but recommended for screen readers and iOS*) -->
  <div id="page"  style="display:flex; justify-content:center;">
    <header></header>
    <main>
      <!-- Add a button to open the popup (optional) -->
      <button class="JPO_open">이번달 공휴일 목록</button>
    </main>
    <footer></footer>
  </div>


  <!-- Add content to the popup -->
  <div id="JPO">
    <?php
        $display  = '<table>';
        $display .= '<th class="format">Name</th>';
        $display .= '<th class="format">Date </th></tr>';
        foreach ($xml->body->items->item as $item)
        {
            $display .= '<tr>';

            $display .='<td class="format">'.$item->dateName.'</td>';
            $display .='<td class="format">'.$item->locdate.'</td>';
            $display .= '</tr>';
        }
        $display .= '</table>';

       echo $display;
    ?>
    <!-- Add a button to close the popup (optional) -->
    <button class="JPO_close" style="margin-left:270px;">Close</button>
  </div>

  <!-- Include jQuery -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>

  <!-- Include jQuery Popup Overlay -->
  <script src="https://cdn.jsdelivr.net/gh/vast-engineering/jquery-popup-overlay@2/jquery.popupoverlay.min.js">
  </script>

  <script>
    $(document).ready(function() {
      // Initialize the plugin
      $('#JPO').popup();
      // Set default `pagecontainer` for all popups (optional, but recommended for screen readers and iOS*)
      $.fn.popup.defaults.pagecontainer = '#page'
    });
  </script>

  <style>
  #JPO {
  margin: 10px;
  padding: 0 10px;
  max-width: 60%;
  border: 2px solid #444;
  background: white;
}
  </style>

<br>




<br><br><br>

<?php 
/* PHP 샘플 코드 */

if(isset($_POST['locationInput'])){
    $searchedLocation  =  $_POST['locationInput'];
}else{
    $searchedLocation = '서울';
}

$ch = curl_init();
$url = 'http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/getCtprvnMesureSidoLIst'; /*URL*/
$queryParams = '?' . urlencode('ServiceKey') . '=API key !!!!!!!!!!!!!!!!!'; /*Service Key*/
$queryParams .= '&' . urlencode('numOfRows') . '=' . urlencode('10'); /*한 페이지 결과 수*/
$queryParams .= '&' . urlencode('pageNo') . '=' . urlencode('1'); /*페이지 번호*/
$queryParams .= '&' . urlencode('sidoName') . '=' . urlencode($searchedLocation); /*시도 이름 (서울, 부산, 대구, 인천, 광주, 대전, 울산, 경기, 강원, 충북, 충남, 전북, 전남, 경북, 경남, 제주, 세종)*/
$queryParams .= '&' . urlencode('searchCondition') . '=' . urlencode('DAILY'); /*요청 데이터기간 (시간 : HOUR, 하루 : DAILY)*/

curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
curl_close($ch);

$xml2 = simplexml_load_string($response);

$display  = '<table>';
$display .= '<th class="format">Data Time</th>';
$display .= '<th class="format">City Name </th>';
$display .= '<th class="format">SO2 Value </th>';
$display .= '<th class="format">PM25 Value </th></tr>';
foreach ($xml2->body->items->item as $item)
{
    $display .= '<tr>';

    $display .='<td class="format">'.$item->dataTime.'</td>';
    $display .='<td class="format">'.$item->cityName.'</td>';
    $display .='<td class="format">'.$item->so2Value.'</td>';
    $display .='<td class="format">'.$item->pm25Value.'</td>';
    $display .= '</tr>';
}
$display .= '</table>';

echo $display;
?>
<form action="" method="POST">
<input name="locationInput" type="text" placeholder="지역이름(ex.서울, 부산...)">
<input type="submit" name="post" value="검색">
</form>

<br><br><br>



<div class="latest_wr">
    <!--  사진 최신글2 { -->
    <?php
    // 이 함수가 바로 최신글을 추출하는 역할을 합니다.
    // 사용방법 : latest(스킨, 게시판아이디, 출력라인, 글자수);
    // 테마의 스킨을 사용하려면 theme/basic 과 같이 지정
    echo latest('theme/pic_basic', 'gallery', 5, 23);
    ?>
    <!-- } 사진 최신글2 끝 -->
</div>

<?php
include_once(G5_THEME_PATH.'/tail.php');
?>
