<?php
	$upcevent = gtAll("eventspost"," evn_id <> '' AND eventdate >= CURRENT_TIMESTAMP ","eventdate ASC LIMIT 5");
	
	$pscevent = gtAll("eventspost"," evn_id <> '' AND eventdate < CURRENT_TIMESTAMP ","eventdate DESC LIMIT 3");
	if(!empty($pscevent)){	foreach($pscevent as $yc){	$pol_arr[] = $yc['evn_id'];	}	}
	$exlst = implode("','",$pol_arr);
	
	$fgn = ($psg == 1 || empty($psg)) ? 3 : 12;
	
	//$phsc = ($psg < 1 || $psg == 1) ? "" : " AND evn_id NOT IN('$exlst') ";
	
	$statement = $db_con->prepare("SELECT count(evn_id) FROM eventspost WHERE delete_status = 0  AND eventdate < CURRENT_TIMESTAMP ");
	$sum_rows = 0; if(!empty($statement)) { $statement->execute(); 	$sum_rows = $statement->fetchColumn(); }
	$rows = $sum_rows; $page_rows = $fgn; $last = ceil($rows/$page_rows);
	if($last < 1){ 	$last = 1; } $pagenum = 1;
	if(isset($_GET['pg'])){	$pagenum = preg_replace('#[^0-9]#', '', $_GET['pg']);	}
	if ($pagenum < 1) { 	$pagenum = 1; } else if ($pagenum > $last) { $pagenum = $last; }
	$limit = ' LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
	
	
	
	$nquery = gtAll("eventspost"," evn_id <> '' AND eventdate < CURRENT_TIMESTAMP ","eventdate DESC $limit");
	$current = ($pagenum * $page_rows); $start_limit = (($pagenum - 1) * $page_rows) + 1;
	if($pagenum == $last){	$current_limit = $sum_rows; } else{	$current_limit = $current; }
	$nv = "?";
	$paginationCtrls = $paginationCtrlsLeft = $paginationCtrlsRight = '';
	if ($pagenum > 1 || $psg == 2) { $previous = $pagenum - 1;  $paginationCtrlsLeft .= '<a href="'.$_SERVER['PHP_SELF'].$nv.'pg='.$previous.'" title="Previous"><i class="fa fa-angle-left"></i></a>'; }
	else{ $paginationCtrlsLeft .= '<a href="javascript:void(0);" style="cursor: not-allowed;" title="Previous"><i class="fa fa-angle-left"></i></a>'; }
	if ($pagenum != $last) {$next = $pagenum + 1; $paginationCtrlsRight .= '<a href="'.$_SERVER['PHP_SELF'].$nv.'pg='.$next.'" title="Next"><i class="fa fa fa-angle-right"></i></a>';}
	else { $paginationCtrlsRight .= '<a href="javascript:void(0);" style="cursor: not-allowed;" title="Next"><i class="fa fa-angle-right"></i></a>'; }
	$paginationCtrls .= $paginationCtrlsLeft.'<span>Showing '.$start_limit .'-'. $current_limit.' of '.$sum_rows.'</span>'.$paginationCtrlsRight;
?>