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

class Line extends MY_Controller {
	
	function __construct()
	{
		//$this->auth->auth_main();
		parent::__construct();		
		
		$this->modul='line';
		$this->title='PRODUCTION LINE';
		
		$this->username=$this->session->userdata('username');		
		$this->kd_cmpy=$this->session->userdata('kd_cmpy');
		$this->tp_prshn=$this->session->userdata('tp_prshn');
		
		$this->load->model($this->modul.'_mdl','mdl');
	}
	
	public function index()
	{		
		$data = array(
			'content' 	=> 	$this->modul.'/'.$this->modul,			
			't'			=>	$this->session->userdata('t'),
			'u'			=>	$this->session->userdata('u'),
			'h'			=>	$this->session->userdata('h')
			);		
		$this->load('tpl',$data['content'], $data);
		$this->load->view($this->modul.'/'.$this->modul.'_cjs');
		$this->load->view($this->modul.'/'.$this->modul.'_mjs');
		
	}
	
	function getPage(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];
		$rs = $this->mdl->getPage($page,$rows,$key);
		
		echo json_encode($rs);
	}
	
	function getform($cmd){
		$form_data = $this->input->post();
		$id=$form_data['id'];
		
		unset($form_data['id']);
		if ($cmd=="add"){	
			$this->add($form_data);	
		} else {
			$this->edit($form_data,$id);
		}
	}
	
	function aksi($cmd)
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
		$rows = isset($_REQUEST['rows']) ? intval($_REQUEST['rows']) : 100;	
		$key = $_REQUEST["q"];
		
		$data = array(
			'rs' 	=> 	$this->mdl->getPage($page,$rows,$key)
		);
		
		if ($cmd=='xls'){
			$filename =$this->modul.".xls";
			header('Content-type: application/ms-excel');
			header('Content-Disposition: attachment; filename='.$filename);
		}
		$this->load->view($this->modul.'/print',$data);
	}

}