<?php
session_start();

if( isset($_SESSION['init_alert']) )
{
	if( ( $str_temp = trim($_SESSION['init_alert']) ) != '' )
		$str_init_alert = $str_temp;

	unset($_SESSION['init_alert']);
}

if( !isset($_REQUEST['news_id']) || !isset($_REQUEST['cate_id']) || ( $static_uint_news_id = (int)$_REQUEST['news_id'] ) <= 0 || ( $static_uint_cate_id = (int)$_REQUEST['cate_id'] ) <= 0 )
{
	header('Location:index.php');
	exit();
}

require_once('includes/common.php');

require_once('includes/data.php');
$obj_class_data = new class_data();

if( !( $arr_news = $obj_class_data->get_news_by_news_id_n_news_cate_id($static_uint_news_id, $static_uint_cate_id) ) )
{
	$_SESSION['init_alert'] = '所選擇的新聞不存在！';

	header('Location:index.php');
	exit();
}

if( !( $arr_news_cates = $obj_class_data->get_news_cates() ) || false === ( $uint_index = in_2d_array($static_uint_cate_id, $arr_news_cates, 'NewsCateId') ) )
{
	$_SESSION['init_alert'] = '指定的新聞分類不存在';

	header('Location: index.php');
	exit();
}

if( !isset($_SESSION['arr_news_read']) )
	$arr_news_read = $_SESSION['arr_news_read'] = array();
else
	$arr_news_read = $_SESSION['arr_news_read'];

if( !$arr_news_read || !in_array($static_uint_news_id, $arr_news_read) )
{
	$obj_class_data->refresh_news_read_count($static_uint_news_id);

	array_push($arr_news_read, $static_uint_news_id);

	$_SESSION['arr_news_read'] = $arr_news_read;
}

$str_content_file_name = 'documents/news/' . $arr_news[0]['NewsId'] . '.html';

if( file_exists($str_content_file_name) && $file_handle = @fopen($str_content_file_name, 'r') )
{
	if( $uint_filesize = filesize($str_content_file_name) )
		$str_content = fread($file_handle, $uint_filesize);
	else
		$str_content = '';

	fclose($file_handle);
}
else
	$str_content = '';

$arr_news_pictures = $obj_class_data->get_news_pictures($static_uint_news_id);
$arr_news_videos = $obj_class_data->get_news_videos($static_uint_news_id);

$arr_banner = $obj_class_data->get_banners($static_uint_cate_id, 2);

$arr_suggest_news = $obj_class_data->get_suggest_news(4);

$str_url = 'http://' . $_SERVER['HTTP_HOST'] . '/news.php?news_id=' . $static_uint_news_id . '&cate_id=' . $static_uint_cate_id;
?>
<!DOCTYPE html>
<html lang="zh-TW">
  <head>
    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
    <meta property="fb:app_id" content="1507360842898051" />
    <meta property="og:url" content="<?=$str_url?>" />
    <meta property="og:type" content="website" />
    <meta property="og:title" content="<?=$arr_news[0]['Subject']?> | 國防新聞網 - <?=$arr_news_cates[$uint_index]['NewsCateName']?>" />
    <meta property="og:description" content="<?=$arr_news[0]['Abstract']?>" />
<?
if( $arr_news_pictures )
{
?>
	<meta property="og:image" content="http://<?=$_SERVER['HTTP_HOST']?>/images/news/<?=$arr_news[0]['NewsId']?>/<?=$arr_news_pictures[0]['PictureId']?>.jpg?>" />
<?
}
?>
    <title><?=$arr_news[0]['Subject']?> | 國防新聞網 - <?=$arr_news_cates[$uint_index]['NewsCateName']?></title>
    <!-- Bootstrap -->
	<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
	<link href="css/css.css" rel="stylesheet" type="text/css" />
    <link href="css/blueimp-gallery-video.css" rel="stylesheet" type="text/css" />
    <link href="css/blueimp-gallery.css" rel="stylesheet" type="text/css" />
	<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />

	<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
		  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
		  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
		<![endif]-->
  </head>

   
<body<?=( isset($str_init_alert) ? ' onLoad="javascript:alert(\'' . $str_init_alert . '\');"' : '' )?>>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v2.5&appId=1507360842898051";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<? include('_title.php'); ?>
  <div id="c_contents" class="container" >
    <div id="c_contents_l">
    <div class="container-fluid contents_l_top" >
      <div class="nav_button"><a class="home_bn" href="index.php">首頁</a><a class="category_bn" href="news_list.php?cate_id=<?=$static_uint_cate_id?>"><?=$arr_news_cates[$uint_index]['NewsCateName']?></a></div>
	  <div class="fb-share-button fb-share" data-href="<?=$str_url?>" data-send="false" data-layout="button_count" data-width="70" data-show-faces="false" data-action="like" data-font="arial"></div>
    </div>
    <div>
<h1><?=$arr_news[0]['Subject']?></h1> 
<?
if( $arr_news_videos )
{
?>
    <div id="blueimp-video-carousel" class="blueimp-gallery blueimp-gallery-controls blueimp-gallery-carousel">
    <div class="slides"></div>
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="play-pause"></a>
    </div>
<?
}

if( $arr_news_pictures )
{
?>
    <div class="contents_pic">
    <div id="carousel2" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner" role="listbox">
<?
	foreach( $arr_news_pictures as $n=>$arr_row )
	{
?>
          <div class="item<?=( !$n ? ' active' : '' )?>"><img src="images/news/<?=$arr_news[0]['NewsId']?>/<?=$arr_row['PictureId']?>.jpg" alt="<?=$arr_row['Subject']?>" class="center-block">
            <div class="carousel-caption">
              <p><?=$arr_row['Subject']?></p>
            </div>
          </div>
<?
	}
?>
        </div>
        <a class="left carousel-control" href="#carousel2" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span></a><a class="right carousel-control" href="#carousel2" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span></a>
    </div>
    </div>
<?
}
?>
    <div class="clear_both"> </div>
    <h2><?=$arr_news[0]['Date']?>｜<?=$arr_news[0]['Author']?></h2>
     <div id="c_contents_l_box">
<?=$str_content?>
     </div>
    </div>
  </div>
  
  <div id="c_contents_r">
<?
if( isset($arr_banner[0]) && $arr_banner[0] )
{
?>
     <div class="contents_r_ad"><a href="<?=$arr_banner[0]['Url']?>"<?=( $arr_banner[0]['NewTarget'] ? ' target="_blank"' : '' )?>><img alt="<?=$arr_banner[0]['Slogan']?>" title="<?=$arr_banner[0]['Slogan']?>" src="images/banners/<?=$arr_banner[0]['BannerId']?>.jpg" /></a></div>
<?
}
?>
     <div class="container top_title_a">推薦要聞</div>
    <div class="container column_5" >
    <ul>
<?
if( $arr_suggest_news )
{
	foreach( $arr_suggest_news as $arr_row )
	{
?>
      <li>
      <a href="news.php?news_id=<?=$arr_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><img src="images/news/<?=$arr_row['NewsId']?>.jpg" /></a>
      <h1><a href="news.php?news_id=<?=$arr_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><?=mb_substr($arr_row['Subject'], 0, 25, 'UTF-8')?>...</a></h1>
      <h2><?=$arr_row['Date']?>｜<span class="category_subhead"><a href="news_list.php?cate_id=<?=$arr_row['NewsCateId']?>"><?=$arr_row['NewsCateName']?></a></span></h2>
      </li>
<?
	}
}
?>
    </ul>
    
    </div> 
<?
if( isset($arr_banner[1]) && $arr_banner[1] )
{
?>
     <div class="contents_r_ad"><a href="<?=$arr_banner[1]['Url']?>"<?=( $arr_banner[1]['NewTarget'] ? ' target="_blank"' : '' )?>><img alt="<?=$arr_banner[1]['Slogan']?>" title="<?=$arr_banner[1]['Slogan']?>" src="images/banners/<?=$arr_banner[1]['BannerId']?>.jpg" /></a></div>
<?
}
?>
 <div>
  <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ewmib.com -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-2989984388108378"
     data-ad-slot="9008499645"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
  </div>
  </div>
  </div>
  <div class="container-fluid" id="footer">
    <div class="container footer_nav">
      <ul>
      <li><a href="terms.php">使用條款</a></li>
      <li><a href="about.php">關於國防新聞網</a></li>
      <li><a href="policy.php">隱私政策</a></li>
      <li><a href="contact.php">聯絡我們</a></li>
      </ul>
    </div>
    <div class="container">
      <div class="copyright">Copyright © 2015 國防新聞網 All Rights Reserved.</div>
      <div class="go_top">
      <ul>
      <li><a id="footer_menu_2" title="返回頂端" href="#">go top</a></li>
      <li><a id="footer_menu_1" href="https://www.facebook.com/%E9%98%B2%E5%8B%99%E5%BF%AB%E9%96%80-243554065699495/" title="防務快門粉絲團" target="_blank" >防務快門粉絲團</a></li>
      </ul>
      </div>
    </div>
  </div>
  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
	<script src="js/jquery-1.11.2.min.js"></script>

	<!-- Include all compiled plugins (below), or include individual files as needed --> 
	<script src="js/bootstrap.js"></script>
<?
if( $arr_news_videos )
{
?>
<!-- *Video -->
<script src="js/blueimp-gallery.js"></script>
<script src="js/blueimp-gallery-video.js"></script>
<script src="js/blueimp-gallery-youtube.js"></script>
<script>
<!--
$(function () {
    'use strict';

    // Load demo images from flickr:
    

    // Initialize the Gallery as video carousel:
    blueimp.Gallery([
<?
	foreach( $arr_news_videos as $n=>$arr_row )
	{
		echo( $n ? ',' : '' );
?>
        {
            title: '<?=$arr_row['Subject']?>',
            type: 'text/html',
            youtube: '<?=$arr_row['VideoNo']?>'
        }
<?
	}
?>
    ], {
        container: '#blueimp-video-carousel',
        carousel: true
    });

});
//-->
</script>
<?
}
?>
<?php include_once("analyticstracking.php") ?>
  </body>
</html>
<style type="text/css">
body {
-moz-user-select : none;
-webkit-user-select: none;
}
</style>
<script type="text/javascript">
function iEsc(){ return false; }
function iRec(){ return true; }
function DisableKeys() {
if(event.ctrlKey || event.shiftKey || event.altKey) {
window.event.returnValue=false;
iEsc();}
}
document.ondragstart=iEsc;
document.onkeydown=DisableKeys;
document.oncontextmenu=iEsc;
if (typeof document.onselectstart !="undefined")
document.onselectstart=iEsc;
else{
document.onmousedown=iEsc;
document.onmouseup=iRec;
}
function DisableRightClick(qsyzDOTnet){
if (window.Event){
if (qsyzDOTnet.which == 2 || qsyzDOTnet.which == 3)
iEsc();}
else
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
iEsc();}
}
</script>