<?php
if (isset($tpl['paginator']) && $tpl['paginator']['pages'] > 1)
{		
	$page = 1 ;
	$query_string = $_SERVER['QUERY_STRING'];
	if(empty($query_string)){
		$query_string = "controller=pjLoad&amp;action=pjActionIndex";
	}
	if(isset($_GET['pjPage'])){
		$page = $_GET['pjPage'];
		$query_string = str_replace("&pjPage=" . $page, "", $query_string);
	}
	?>
	<footer class="pjMlFoot">
		<div class="text-center pjMlPagination">
			<ul class="pagination">
				<?php
				$stages = 3;
				$lastpage = $tpl['paginator']['pages'];
									
				if ($page > 1)
				{
					?>
					<li>
						<a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $page - 1; ?>" aria-label="Previous">
							<span aria-hidden="true">
								<i class="fa fa-angle-left"></i>
								<span class="hidden-xs"> <?php __('front_paging_previous');?></span>
							</span>
						</a>
					</li>
					<?php
				}else{
					?>
					<li>
						<a href="javascript:void(0);" aria-label="Previous">
							<span aria-hidden="true">
								<i class="fa fa-angle-left"></i>
								<span class="hidden-xs"> <?php __('front_paging_previous');?></span>
							</span>
						</a>
					</li>
					<?php
				}
				if ($lastpage < 7 + ($stages * 2))
				{
					for ($counter = 1; $counter <= $lastpage; $counter++)
					{
						if ($counter == $page)
						{
							?><li class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
						}else{
							?><li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
						}
					}
				} else if ($lastpage > 5 + ($stages * 2)){
					
					if($page < 1 + ($stages * 2))		
					{
						for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
						{
							if ($counter == $page)
							{
								?><li class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
							}else{
								?><li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
							}	
						}
						?>
						<li class="pjMlPaginationSeparator">
							<span>...</span>
						</li>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $lastpage - 1; ?>"><?php echo $lastpage - 1; ?></a></li>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $lastpage; ?>"><?php echo $lastpage; ?></a></li>
						<?php
					}else if($lastpage - ($stages * 2) > $page && $page > ($stages * 2)){
						?>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=1">1</a></li>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=2">2</a></li>
						<li class="pjMlPaginationSeparator">
							<span>...</span>
						</li>
						<?php
						for ($counter = $page - $stages; $counter <= $page + $stages; $counter++){
							if ($counter == $page)
							{
								?><li class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
							}else{
								?><li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
							}
						}
						?>
						<li class="pjMlPaginationSeparator">
							<span>...</span>
						</li>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $lastpage - 1; ?>"><?php echo $lastpage - 1; ?></a></li>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $lastpage; ?>"><?php echo $lastpage; ?></a></li>
						<?php
					}else{
						?>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=1">1</a></li>
						<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=2">2</a></li>
						<li class="pjMlPaginationSeparator">
							<span>...</span>
						</li>
						<?php
						for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
						{
							if ($counter == $page)
							{
								?><li class="active"><a href="javascript:void(0);"><?php echo $counter; ?></a></li><?php
							}else{
								?><li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $counter; ?>"><?php echo $counter; ?></a></li><?php
							}
						}
					}	
				}
				if ($page < $counter - 1){
					?>
					<li>
						<a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_string;?>&amp;pjPage=<?php echo $page + 1; ?>" aria-label="Next">
							<span aria-hidden="true">
								<span class="hidden-xs"><?php __('front_paging_next');?> </span>
								<i class="fa fa-angle-right"></i>
							</span>
						</a>
					</li>
					<?php
				}else{
					?>
					<li>
						<a href="javascript:void(0);" aria-label="Next">
							<span aria-hidden="true">
								<span class="hidden-xs"><?php __('front_paging_next');?> </span>
								<i class="fa fa-angle-right"></i>
							</span>
						</a>
					</li>
					<?php
				}
				?>
			</ul>
		</div>
	</footer>
	<?php
} 
?>