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

class Popup_trans extends CI_Controller {

	/*Limit Paging*/
	var $limit = 10;
	function __construct()
	{
		parent::__construct();
		$this->load->model('branch/cabang_model', '', TRUE);
	}

	function index()
	{
			//$this->fungsi->fungsi();
			$this->list_trans();
	}

/*List Supplier*/
function list_trans()
{
//Default
if($this->session->userdata('txt_cari_trans')=='')
{
$this->session->set_userdata('txt_cari_trans', '');
$this->session->set_userdata('txt_opt_trans', 'idtrans');
}
//$this->fungsi->menu_auth();	
  $data['title'] ='.::PT WGI Web Application::. | Popup List Transporter';
  $data['sub_title'] = 'POPUP TRANSPORTER';
  $data['content'] = 'popup/popup_trans';	
  $data['form_action']= site_url('popup/popup_trans/');

//Otorisasi menu

		
		$this->fungsi->trans_auth($this->session->userdata('view'));
		$data['form_action']= site_url('popup/popup_trans/popup_trans');
	
if(isset($_POST['button']))
			{
				$data['txt_cari_trans'] = $this->input->post('txt_cari_trans');
				$data['txt_opt_trans'] = $this->input->post('txt_opt_trans');
				//set session user data untuk pencarian, untuk paging pencarian
				$this->session->set_userdata('txt_cari_trans', $data['txt_cari_trans']);
				$this->session->set_userdata('txt_opt_trans', $data['txt_opt_trans']);
			} 
			else 
			{
				$data['txt_cari_trans'] = $this->session->userdata('txt_cari_trans');
				$data['txt_opt_trans'] = $this->session->userdata('txt_opt_trans');
			}

/* Setting Parameter Untuk Paging */
$uri_segment = 4;
$offset =    $this->uri->segment($uri_segment);
$trans = $this->cabang_model->search_trans($this->limit, $offset,$data['txt_opt_trans'],$data['txt_cari_trans'])->result();
$num_rows = $this->cabang_model->count_all_num_rows_search_trans($data['txt_opt_trans'],$data['txt_cari_trans']);
$config['base_url'] = site_url('popup/popup_trans/list_trans/');
if ($num_rows > 0) // Jika query menghasilkan data
		{
			// Membuat pagination			
			$config['total_rows'] = $num_rows;
			$config['per_page'] = $this->limit;
			$config['uri_segment'] = $uri_segment;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			$i = 0 + $offset;
			
			$tmpl = array( 'table_open'    => '<table border="0" cellpadding="1" cellspacing="1" id="list">',
						  'row_alt_start'  => '<tr class="zebra">',
						  'row_alt_end'    => '</tr>'
						  );
			$this->table->set_template($tmpl);

			// Set heading untuk tabel
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('ID', 'Name', 'PIC', 'Address', 'Vehicle Number','Option');
		
			foreach ($trans  as $transs)
			{		
$this->table->add_row($transs->idtrans, $transs->name, $transs->pic, $transs->addr, $transs->vnumb, anchor('#','Select',array('class' => 'ok','onclick' => 'sendValue('.'\''.$transs->name.'\''.','.'\''.$transs->idtrans.'\''.','.'\''.$transs->vnumb.'\''.','.'\''.$transs->pic.'\''.');')));		
					
			}
			$data['table'] = $this->table->generate();
			$data['message']= '';
			}
			else
			{
			$data['message']= 'Data Empty.';
			}		
		$data['link'] = array('link_add' => anchor('branch/cabang_trans/add_trans_proc','Add Transporter', array('class' => 'add','target' => '_blank')));
		$this->load->view('templates/theme01/template_popup', $data);


}



}

