<?php
session_start();

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

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

require_once('includes/common.php');

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

if( $arr_news_cates = $obj_class_data->get_news_cates() )
{
	$arr_news_id_existed = array();

	foreach( $arr_news_cates as $i=>$arr_row )
	{
		$arr_data = array();

		if( $arr_temp = $obj_class_data->get_news($arr_row['NewsCateId'], 0, 4 * ($i + 1)) )
		{
			$uint_news_counter = 0;

			foreach( $arr_temp as $arr_sub_row )
			{
				if( $uint_news_counter >= 4 )
					break;

				if( $arr_news_id_existed && in_array($arr_sub_row['NewsId'], $arr_news_id_existed) )
					continue;
				else
				{
					array_push($arr_data, $arr_sub_row);
					array_push($arr_news_id_existed, $arr_sub_row['NewsId']);

					$uint_news_counter++;
				}
			}
		}

		$arr_news_cates[$i]['News'] = $arr_data;
	}
}

$arr_top_news = $obj_class_data->get_top_news();

$arr_latest_news = $obj_class_data->get_latest_news(5);

$arr_banner = $obj_class_data->get_banners(0, 1);
?>
<!DOCTYPE html>
<html lang="en">
  <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 name="robots" content="all" />
    <meta name="keywords" content="國防新聞網,中文軍事新聞,軍事新聞" />
    <meta property="fb:app_id" content="1507360842898051" />
    <meta property="og:url" content="http://www.ewmib.com/index.php" />
    <meta property="og:type" content="website" />
    <meta property="og:title" content="國防新聞網-中文軍事新聞" />
    <meta property="og:description" content="從大戰略、國家戰略、野戰戰略，到戰術、戰法、戰具，以及個人的裝備，再延伸到軍事收藏，全都在國防新聞網。 " />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0, user-scalable=yes"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>國防新聞網</title>
    <!-- Bootstrap -->
	<link href="css/bootstrap.css" rel="stylesheet">
	<link href="css/css.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 . '\');"' : '' )?>>
<? include('_title.php'); ?>
  <div id="index_contents" class="container">
   <div id="index_contents_l">
<?
if( $arr_top_news )
{
?>
     <div id="carousel1" class="carousel slide" data-ride="carousel">
       <ol class="index_top_ad carousel-indicators">
<?
	$i_max = count($arr_top_news);

	for( $i=0; $i<$i_max; $i++ )
		echo('         <li data-target="#carousel1" data-slide-to="' . $i . '"' . ( !$i ? ' class="active"' : '' ) . '></li>' . "\n");
?>
	   </ol>
       <div class="carousel-inner" role="listbox">
<?
	foreach( $arr_top_news as $n=>$arr_row )
	{
?>
         <div class="item<?=( !$n ? ' active' : '' )?>"><img src="images/news/<?=$arr_row['NewsId']?>.jpg" alt="<?=$arr_row['Subject']?>" class="center-block" />
           <div class="carousel-caption">
             <h3><a href="news.php?news_id=<?=$arr_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><?=$arr_row['Subject']?></a></h3>
             <p class="index_top_ad"><a href="news.php?news_id=<?=$arr_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><?=mb_substr($arr_row['Abstract'], 0, 25, 'UTF-8')?>...</a></p>
           </div>
         </div>
<?
	}
?>
       </div>
       <a class="left carousel-control" href="#carousel1" 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="#carousel1" 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 id="index_contents_r">
   <h1>最新軍情</h1>
<?
if( $arr_latest_news )
{
	foreach( $arr_latest_news as $arr_row )
	{
?>
   <p><a href="news.php?news_id=<?=$arr_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><?=mb_substr($arr_row['Subject'], 0, 12, 'UTF-8')?>...</a><br>
     <span class="time_category"><?=$arr_row['Date']?>｜</span><span class="category_subhead"><a href="news_list.php?cate_id=<?=$arr_row['NewsCateId']?>"><?=$arr_row['NewsCateName']?></a></span></p>
<?
	}
}
?>
   </div> 
   </div>
<?
if( $arr_news_cates )
{
	foreach( $arr_news_cates as $n=>$arr_row )
	{
?>
    <div class="top_title"><a href="news_list.php?cate_id=<?=$arr_row['NewsCateId']?>"><?=$arr_row['NewsCateName']?></a></div>
    <div class="container column_4" >
<?
		if( $arr_row['News'] )
		{
?>
    <ul>
<?
			foreach( $arr_row['News'] as $arr_sub_row )
			{
?>
      <li>
      <a href="news.php?news_id=<?=$arr_sub_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><img src="images/news/<?=$arr_sub_row['NewsId']?>.jpg" /></a>
      <h1><a href="news.php?news_id=<?=$arr_sub_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><?=$arr_sub_row['Subject']?></a></h1>
      <p><a href="news.php?news_id=<?=$arr_sub_row['NewsId']?>&cate_id=<?=$arr_row['NewsCateId']?>"><?=mb_substr($arr_sub_row['Abstract'], 0, 25, 'UTF-8')?>...</a></p>
      </li>
<?
			}
?>
    </ul>
<?
		}
?>
    </div >
    <div>
<!-- ewmib.com ad
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<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>
<?
		if( !$n && $arr_banner )
		{
?>
    <div class="contents_l_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-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>
    <?php include_once("analyticstracking.php") ?>
  </body>
</html>
