<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Backend_pagination Class
 *
 * @package	Accident Management 
 * @subpackage	Custom Pagination controller 
 * @author	Harshada Kakade
 * @copyright	Copyright (c) 2013 - 2014 
 * @since		Version 1.0
 */

class Backend_pagination extends CI_Controller {
	
	//offset of the page
	public $offsetPage;
	public $arr_data;
	public $offset;
	public $url;
	public $strpagination;
	public $limit;
    public $per_page = 20;

	/**
	* __construct
	*
	* Calls parent constructor 
	* @author	Harshada Kakade
	* @access	public
	* @param  null
	* @return	void 
	*/
	function __construct()
	{
		parent::__construct();	
		
	}

	/**
	* index
	*
	* This displays Manage
	* 
	* @author	Harshada Kakade
	* @access	public
	* @param	null
	* @return	void
	*/
	public function request()
	{
		
		$arrData['middle'] = 'request'; 
		$this->load->view('frontend/template',$arrData);
	}
	
	/**
	* pagination
	*
	* This manages pagination settings
	* 
	* @author	Harshada Kakade 
	* @access	public
	* @param	null
	* @return	void
	*/
	public function pagination()
	{
		$per_page = $this->per_page;
		$no_of_links = 1;
		$arrData['perpage'] = $per_page;
		$arrData['no_of_links'] = $no_of_links;
		return $arrData;
	}

	public function get_pagination_settings($custom_config)
	{
		$resPagination = $this->pagination();
		$config = array();
		$config['full_tag_open'] = "<div class=''><ul class=''>";
		$config['full_tag_close'] = "</ul></div>";
		$config['uri_segment'] = ( isset($custom_config['uri_segment']) ? $custom_config['uri_segment'] : 3 );
		#$config['num_tag_open'] = '<li>';
		#$config['num_tag_close'] = '</li>';
		#$config['cur_tag_open'] = '<li><a>';
		#$config['cur_tag_close'] = '</a></li>';
		$config['use_page_numbers'] = TRUE;
		$config['next_link'] = 'Next';
		#$config['next_tag_open'] = '<li data-lp="2" class="next">';
		#$config['next_tag_close'] = '</li>';
		$config['prev_link'] = 'Prev';
		#$config['prev_tag_open'] = '<li>';
		#$config['prev_tag_close'] = '</li>';
		$config['first_link'] = 'First';
		#$config['first_tag_open'] = '<li data-lp="2" class="next">';
		#$config['first_tag_close'] = '</li>';
		$config['last_link'] = 'Last';
		#$config['last_tag_open'] = '<li data-lp="2" class="next">';
		#$config['last_tag_close'] = '</li>';
		//$config['last_tag_open'] = '<li data-lp="2" class="next">';
		#$config['last_link'] = 'Last';
		//$config['last_tag_close'] ='</li>';
		$config['num_links'] = isset($resPagination['no_of_links'])?$resPagination['no_of_links']:3;
		$config['per_page'] = isset($resPagination['perpage'])?$resPagination['perpage']:1;
		if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");
		return $config;
	}
	/**
	* setup_pagination
	*
	* This manages pagination settings
	* 
	* @author	Harshada Kakade
	* @access	public
	* @param	null
	* @return	void
	*/
	
	public function setup_pagination($custom_config = array()){
		$total_rows = 0;

		if(is_array($this->arr_data) && sizeof($this->arr_data)) {

			$total_rows = sizeof($this->arr_data);
		}
		
		$resPagination = $this->pagination();
		$config = array();
		$config = $this->get_pagination_settings($custom_config);
		//load pagination library
		$this->load->library('pagination');
		//set pagination config vars
		$config['base_url'] = base_url().$this->url;
		$config['total_rows'] = $total_rows;
		$config['cur_page'] = $this->offset;
	
		$this->limit = $limit = isset($resPagination['perpage'])?$resPagination['perpage']:2;
		//initialize pagination with config
		$this->pagination->initialize($config);
		$this->strpagination = $this->pagination->create_links();
		//get records  based on current page
		$this->offsetPage = ($this->offset - 1) * $limit;
		
	}
	
	/**
	* get_serial_num
	*
	* This manages serial number
	* 
	* @author	Harshada Kakade
	* @access	public
	* @param	null
	* @return	void
	*/
	
	public function get_serial_num($page_num){
		
		$sr_no = (($page_num * PER_PAGE) - PER_PAGE) + 1;
		return $sr_no;
		
	}
}

