<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
session_start();
require(root."/_common.php");
require(root."/_lib/db.php");
require(root."/_lib/main.php");
require(root."/mobileDetect/Mobile_Detect.php");
require(root."/_lib/bootstraps.php");
$page_title = "News";
$page_id = 'news';
$url = trim(cekpost(cleanQuery($_REQUEST["url"]), ""));
$p = trim(cekpost(cleanQuery($_REQUEST["p"]), ""));
if ($url!="") {
	#require(root."/_lib/GoogleUrlApi.php");
	$rs=array();$q="SELECT * FROM news WHERE url='$url' AND isactive=1 ORDER BY tanggal DESC LIMIT 0,1";
	#$rs = callRS($q);
	callRS($rs, $q);
	$page_title = $rs[0]["judul"];
} else {
	$rs=array();$q="SELECT * FROM news WHERE isactive=1 ORDER BY tanggal DESC LIMIT 0,350";
	#$rs = callRS($q);
	callRS($rs, $q);
}
require(root."/_tpl/html_begin.php");
require(root."/_tpl/tag_head.php");
require(root."/_tpl/ie_style_exception.php");
/*
 * begin
 * additional style
 * */
cout('<style type="text/css">');
cout('');
cout('</style>');
/*
 * end
 * additional style
 * 
 * v
 * v
 * closing tag head
 * 
 * */
require(root."/_tpl/body_open.php");

cout('<div class="container-fluid main-body">');
	cout('<div class="decor-1"></div>');
	
	cout('<div class="container-fluid">');
		cout('<div class="container for-footer">');
			cout('<div class="decor decor-1"></div>');
			cout('<div class="decor decor-2"></div>');
			cout('<div class="decor decor-3"></div>');
			cout('<div class="special-box">');
				cout('<div class="decor decor-1"></div>');
				cout('<div class="decor decor-2"></div>');
				cout('<div class="content">');
					cout('<div class="decor decor-1"></div>');
					cout('<div class="decor decor-2"></div>');
					cout('<div class="title">');
						cout('<div class="page-title">News</div>');
						cout('<div class="decor decor-1"></div>');
					cout('</div>');
					cout('<div class="real-content">');
						if ($url=="") {
							$p = intval($p==""?1:$p);
							$tdt = 10;
							$row1 = ($p-1) * $tdt;
							$tp = intval(count($rs) / $tdt) + (count($rs)%$tdt==0?0:1);
							$cc = -1;
							$str_paging = '';
							$str_paging .= '<ul class="pagination">';
								if ($p>1) {
									$str_paging .= '<li class="custom-pagination"><a href="'.absDom.'/news/page/1">&lt;&lt;</a></li>';
									$str_paging .= '<li class="custom-pagination"><a href="'.absDom.'/news/page/'.($p-1).'">&lt;</a></li>';
								}
								if ($tp>=5) {
									$curr0 = $p-2;
									$curr1 = $p+2;
									$last = $tp;
									if ($curr0<=1) {
										$curr0 = 1;
										$curr1 = $last>5? 5 : $last;
									}
									if ($curr1>=$last) {
										$curr0 = $last-4 < 1 ? 1 : $last-4;
										$curr1 = $last;
									}
									for ($t=$curr0; $t<=$curr1; $t++) {
										$act = ($t==$p)?'active':'';
										$str_paging .= '<li class="'.$act.' custom-pagination"><a href="'.absDom.'/news/page/'.$t.'">'.$t.'</a></li>';
									}
									#if ($p<$tp-10) {
									#	$str_paging .= '<li class="'.$act.'"><a href="#" onclick="return false;">...</a></li>';
									#	for ($t=$tp-2;$t<=$tp;$t++) {
									#		$act = ($t==$p)?'active':'';
									#		$str_paging .= '<li class="'.$act.'"><a href="'.absDom.'/news/page/'.$t.'">'.$t.'</a></li>';
									#	}
									#}
								} else {
									for ($t=1;$t<=$tp;$t++) {
										$act = ($t==$p)?'active':'';
										$str_paging .= '<li class="'.$act.' custom-pagination"><a href="'.absDom.'/news/page/'.$t.'">'.$t.'</a></li>';
									}
								}
								if ($p<$tp) {
									$str_paging .= '<li class="custom-pagination"><a href="'.absDom.'/news/page/'.($p+1).'">&gt;</a></li>';
								#	$str_paging .= '<li class="custom-pagination"><a href="'.absDom.'/news/page/'.$tp.'">&gt;&gt;</a></li>';
								}
							$str_paging .= '</ul>';
							if ($tp>1) { cout($str_paging); }
							if (count($rs)!=0) {
								for ($i=$row1;$i<($tdt*$p);$i++) {
									$cc++;
									if (isset($rs[$i]["kdnews"])) {
										$rsf=array(); $qf="SELECT * FROM u_files WHERE kdnews='".$rs[$i]["kdnews"]."'";
										#$rsf = callRS($qf);
										callRS($rsf, $qf);
										$path = str_replace("../../", "/", $rsf[0]["full_path"]);
										$resized = str_replace(".".$rsf[0]["ext"]."", "_600.".$rsf[0]["ext"]."", $path);
										$resized = $resized."?".time();
										$isrc = $resized;
										$ititle = $rsf[0]["image_title"];
										$ialt = $rsf[0]["image_alt"];
										$news_url = ''.absDom.'/news/story/'.$rs[$i]["url"].'';
										$isi = str_replace("\n", "<br/>", $rs[$i]["isi"]);
										$isi = str_replace("<br/><li>", "<li>", $isi);
										$isi = str_replace("<br/></ol>", "</ol>", $isi);
										$isi = str_replace("<br/></ul>", "</ul>", $isi);
										$isi = str_replace("../../../", "/", $isi);
										$isi = str_replace("../../", "/", $isi);
										$isi = str_replace("../", "/", $isi);
										$isi = first_n_words($isi, 200);
										cout('<div class="news-stripe">');
											cout('<div class="judul"><a href="'.$news_url.'">'.$rs[$i]["judul"].'</a></div>');
											cout('<div class="tanggal">'.date('d M Y', $rs[$i]["tanggal"]).'</div>');
											if (count($rsf)!=0) {
												cout('<div class="text-center for-img"><div class="img-container"><a href="'.$news_url.'"><img class="img-responsivex center-block" width="100" height="100" src="'.$isrc.'" alt="'.$ialt.'" /></a></div><div>'.$ititle.'</div></div>');
											}
											cout('<div class="preview">'.$isi.' ... <a href="'.$news_url.'">read more</a></div>');
										cout('</div><!--/.news-stripe-->');
										cout('<hr/>');
									}
								}
							}
							if ($tp>1) { cout($str_paging); }
						} else {
							$rsf=array(); $qf="SELECT * FROM u_files WHERE kdnews='".$rs[0]["kdnews"]."'";
							#$rsf = callRS($qf);
							callRS($rsf, $qf);
							$path = str_replace("../../", "/", $rsf[0]["full_path"]);
							$resized = str_replace(".".$rsf[0]["ext"]."", "_600.".$rsf[0]["ext"]."", $path);
							$resized = $resized."?".time();
							$isrc = $resized;
							$ititle = $rsf[0]["image_title"];
							$ialt = $rsf[0]["image_alt"];
							$news_url = ''.absDom.'/news/story/'.$rs[0]["url"].'';
							$isi = str_replace("\n", "<br/>", $rs[0]["isi"]);
							$isi = str_replace("<br/><li>", "<li>", $isi);
							$isi = str_replace("<br/></ol>", "</ol>", $isi);
							$isi = str_replace("<br/></ul>", "</ul>", $isi);
							$isi = str_replace("../../../", "/", $isi);
							$isi = str_replace("../../", "/", $isi);
							$isi = str_replace("../", "/", $isi);
							cout('<div class="news-details">');
								cout('<div class="judul">'.$rs[0]["judul"].'</a></div>');
								cout('<div class="tanggal">'.date('d M Y', $rs[0]["tanggal"]).'</div>');
								cout('<hr/>');
								if (count($rsf)!=0) {
									cout('<div class="text-center"><div><img class="img-responsive center-block" src="'.$isrc.'" alt="'.$ialt.'" /></div><div>'.$ititle.'</div></div>');
								}
								cout('<div class="row">');
									cout('<div class="col-xs-8 col-xs-offset-2">');
										cout('<div class="isi">'.$isi.'</div>');
									cout('</div><!--/.col-xs-8 col-xs-offset-2-->');
								cout('</div><!--/.row-->');
							cout('</div>');
							
							cout('<hr/>');
							cout('<div class="newsreturnlink"><a href="'.absDom.'/news/">Return to Index</a></div>');
							
						}
						
					cout('</div><!--/.real-content-->');
				cout('</div><!--/.content-->');
			cout('</div><!--/.special-box-->');
			
		cout('</div><!--/.container for-footer-->');
	cout('</div><!--/.container-fluid-->');
require(root."/_tpl/body_close.php");
?>