<?php
if (basename($_SERVER['SCRIPT_FILENAME']) == basename(__FILE__)){
echo "<p align=center><br><br><br><br><br><br><font size=\"6\" color=\"#FF0000\">ILLEGAL ACCESS !!";
echo "<meta http-equiv=\"refresh\" content=\"2; url=../index.php\">";
exit();} 
?>
 <div class="row">
            <div class="col-md-12">
                <h1 class="page-header">
                    <img src="../themes/img/news.png" alt="News" class="header-icon" width="30">
                    News
                </h1>
            </div>
        </div>

<div class="row">
            	
                
                
                
                             <div class="col-md-12">
                
                
				  <div class="panel panel-inverse">
                        <div class="panel-heading bg-grey">
                            <h4 class="text-white">News</h4>
                        </div>
                        <div class="panel-body">







<?php
if (isset($_GET['page']) && $_GET['page'] == "detail") {
if(isset($_GET["nid"])){ $nid = $_GET["nid"]; }
$nide = anti_injection($nid);
//$sesine = anti_injection($nid[4]);
//$token = anti_injection($nid[5]);
//$cek=md5(md5(date("j, n, Y")).md5($session).md5($sesine));
//if($token==$cek){
$db->select("id_berita, id_user, judul, isi_berita, gambar, tanggal, counter, published", "berita", "id_berita='".mysql_real_escape_string($nide)."'","");
if($db->num_rows() > 0) {
	$row = $db->fetch_row();
	$tglne = formatgl($row[5]);
	$judul = $row[2];
	$isine = $row[3];
	$tgl = formatgl($row[5]);
	$counter = $row[7];
	$adafoto = $row[4];

	    ?>
       	<h3><?php echo $judul_nws;?></h3>
    <p><?php echo $isine;?></p>
    <div>
        <span class="badge badge-success">Posted <?php echo $tgl;?></span><div class="pull-right"><span class="label"></span> <span class="label"></span> <span class="label"></span> <span class="label"></span></div>
    </div> 
    <hr>                      
		
		<?php
		
		$db->update("berita", "counter=$row[6]+1", "id_berita='$nide'");
}else{
	echo "<div class='alert alert-info alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Not Found</div>";

}
} else {
?>            


<?php
$batas   = 10;
if(isset($_GET['halaman'])) { $halaman = anti_injection($_GET['halaman']); } 
if(empty($halaman)){
	$posisi  = 0;
	$halaman = 1;
}
else{
	$posisi = ($halaman-1) * $batas;
}

$db->select("id_berita, id_user, judul, isi_berita, gambar, tanggal, counter, published", "berita", "published=1", "id_berita desc LIMIT $posisi,$batas");

if($db->num_rows() > 0) {
	while($row_nws = $db->fetch_row()) {
	$tgle_nws = formatglx($row_nws[5]);
	$judul_nws = $row_nws[2];
	$isine_nws = $row_nws[3];
	$user_nws = $row_nws[1];
	$idne = anti_injection($row_nws[0]);
    	$isinyax = substr($isine_nws,0,250);

	
	?>
                    
                    
                    	<h3><a href='?go=news&page=detail&nid=<?php echo $idne; ?>' title='<?php echo $judul_nws; ?>'><?php echo $judul_nws;?></a></h3>
    <p><?php echo $isinyax;?>.... <a href='?go=news&page=detail&nid=<?php echo $idne; ?>' title='Readmore'>Readmore</a></p>
    <div>
        <span class="badge badge-success">Posted <?php echo $tgle_nws;?></span><div class="pull-right"><span class="label"></span> <span class="label"></span> <span class="label"></span> <span class="label"></span></div>
    </div> 
    <hr>                        
                                                
                                                
                                                
                                                
                                                
                                                
                                                
                                                
              
<?php
		
			}	
} else {
	echo "<div class='list'><div class='alert info notification' align='left'>News is not available</div></div>";
}	
?>












<div class="clearBoth"></div>
<div align="center">
<?
//Langkah 3: Hitung total data dan halaman 
$tampil2 = mysql_query("SELECT * FROM berita WHERE published=1");
$jmldata = mysql_num_rows($tampil2);
$jmlhal  = ceil($jmldata/$batas);
if($jmldata > 10){
echo "<br><div class=pagiNation><div class='dataTables_paginate ui-buttonset paging_full_numbers'>";
// Link ke halaman sebelumnya (previous)
if($halaman > 1){
	$prev=$halaman-1;
	echo "<span class='next ui-button'><a href='?go=news&halaman=$prev'>".$LANG["prev"]."</a></span> ";
}
else{ 
	echo "<span class='ui-button ui-state-disabled'>".$LANG["prev"]."</span> ";
}

// Tampilkan link halaman 1,2,3 ...
for($i=1;$i<=$jmlhal;$i++)
if ($i != $halaman){
	echo " <span class='ui-button'><a href='?go=news&halaman=$i'>$i</a></span>";
}
else{
	echo " <span class='ui-button ui-state-disabled'>$i</span> ";
}

// Link kehalaman berikutnya (Next)
if($halaman < $jmlhal){
	$next=$halaman+1;
	echo "<span class='next ui-button'><a href='?go=news&halaman=$next'>".$LANG["next"]."</a></span>";
}
else{ 
	echo "<span class='ui-button ui-state-disabled'>".$LANG["next"]."</span>";
}
echo "</div></div>";
}
}
?>
</div></div></div>