<?php $ci = get_instance();?>
<?php if(isset($config, $count)):?>
	<div class="pull-left">
		<ul class="pagination" style="margin-left: 20px;">
			<?php 
				$no_of_paginations = ceil($count / $config['per_page']);
				if($config['cur_page'] >= 3){
					$start_loop = $config['cur_page'] - 2;
					if($no_of_paginations > $config['cur_page'] + 2){
						$end_loop = $config['cur_page'] + 2;
					}
					elseif($config['cur_page'] <= $no_of_paginations && $config['cur_page'] > $no_of_paginations - 4){
						$start_loop = $no_of_paginations - 4;
						$end_loop = $no_of_paginations;
						
						if($start_loop < 1) $start_loop = 1;
					}
					else{
						$end_loop = $no_of_paginations;
					}
				}
				else{
					$start_loop = 1;
					if($no_of_paginations > 5){
						$end_loop = 5;
					}
					else{
						$end_loop = $no_of_paginations;
					}
				}
			?>
			<?php if($config['first_btn'] && $config['cur_page'] > 1):	//FOR ENABLING THE FIRST BUTTON?>
				<li>
					<a href="javascript:;" onClick="page_onchange(1);">
						First
					</a>
				</li>
			<?php endif;?>
			
			<?php if($config['previous_btn'] && $config['cur_page'] > 1):	//FOR ENABLING THE PREVIOUS BUTTON?>
				<?php $pre = $config['cur_page'] - 1;?>
				<li>
					<a href="javascript:;" onClick="page_onchange(<?php echo $pre;?>);">
						<i class="fa fa-chevron-left"></i>
					</a>
				</li>
			<?php endif;?>
			
			<?php for($i=$start_loop; $i<=$end_loop; $i++):?>
				<li <?php if($config['cur_page'] == $i) echo "class='active'";?>>
					<a href="javascript:;" onClick="page_onchange(<?php echo $i;?>);">
						<?php echo $i;?>
					</a>
				</li>
			<?php endfor;?>
			
			<?php if($config['next_btn'] && $config['cur_page'] < $no_of_paginations):	//TO ENABLE THE NEXT BUTTON?>
				<?php $nex = $config['cur_page'] + 1;?>
				<li>
					<a href="javascript:;" onClick="page_onchange(<?php echo $nex;?>);">
						<i class="fa fa-chevron-right"></i>
					</a>
				</li>
			<?php endif;?>
			
			<?php if($config['last_btn'] && $config['cur_page'] < $no_of_paginations):	//TO ENABLE THE END BUTTON?>
				<li>
					<a href="javascript:;" onClick="page_onchange(<?php echo $no_of_paginations;?>);">
						Last
					</a>
				</li>
			<?php endif;?>
		</ul>
	</div>
	
	<div class="pull-left" style="margin: 20px 0 20px 10px;">
		<form onSubmit="page_onchange($(this).find('input').val()); return false;">
			<div class="pull-left" style="margin: 5px 5px 0 0;">
				Page:
			</div>
			<div class="pull-left" style="width: 50px;">
				<input type="text" onClick="$(this).select();" value="<?php echo $config['cur_page'];?>" class="form-control" style="text-align: center;" autocomplete="OFF">
			</div>
		</form>
	</div>
<?php endif;?>