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

class Popup_supp 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_supp();
	}

/*List Supplier*/
function list_supp()
{
//Default
if($this->session->userdata('txt_cari')=='')
{
$this->session->set_userdata('txt_cari', '');
$this->session->set_userdata('txt_opt', 'idsupp');
}
//$this->fungsi->menu_auth();	
  $data['title'] ='.::PT WGI Web Application::. | Popup List Supplier';
  $data['sub_title'] = 'POPUP SUPPLIER';
  $data['content'] = 'popup/popup_supp';	
  $data['form_action']= site_url('popup/popup_supp/');

//Otorisasi menu

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

/* Setting Parameter Untuk Paging */
$uri_segment = 4;
$offset =    $this->uri->segment($uri_segment);
$supp = $this->cabang_model->search($this->limit, $offset,$data['txt_opt'],$data['txt_cari'])->result();
$num_rows = $this->cabang_model->count_all_num_rows_search($data['txt_opt'],$data['txt_cari']);
$config['base_url'] = site_url('popup/popup_supp/list_supp/');
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', 'Option');
		
			foreach ($supp  as $supps)
			{		
$this->table->add_row($supps->idsupp, $supps->suppname, $supps->pic, $supps->addr, anchor('#','Select',array('class' => 'ok','onclick' => 'sendValue('.'\''.$supps->suppname.'\''.','.'\''.$supps->idsupp.'\''.');')));		
					
			}
			$data['table'] = $this->table->generate();
			$data['message']= '';
			}
			else
			{
			$data['message']= 'Data Empty.';
			}		
		$data['link'] = array('link_add' => anchor('branch/cabang_supp/add_supp_proc','Add Supplier', array('class' => 'add','target' => '_blank')));
		$this->load->view('templates/theme01/template_popup', $data);


}



}

