<?php namespace App\Http\Controllers;

use App\Models\Rekaptakmarcluster;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator as Paginator;
use Illuminate\Support\Facades\DB;
use Validator, Input, Redirect ; 


class RekaptakmarclusterController extends Controller {

	protected $layout = "layouts.main";
	protected $data = array();	
	public $module = 'rekaptakmarcluster';
	static $per_page	= '50';

	public function __construct()
	{
		
		parent::__construct();
		$this->model = new Rekaptakmarcluster();
		$this->info = $this->model->makeInfo( $this->module);
		$this->access = array();
	
		$this->data = array_merge(array(
			'pageTitle'	=> 	$this->info['title'],
			'pageNote'	=>  $this->info['note'],
			'pageModule'=> 'rekaptakmarcluster',
			'return'	=> self::returnUrl()
			
		),$this->data);


		
	}

	public function index( Request $request )
	{
		$getlevel = DB::table('tb_groups')
		->select('level')
		->where('group_id',\Session::get('gid'))
		->first();

		$filter = 'where 0=0 and plant != "" ';
		if(!empty($request->input('plant'))){
			$filter .= ' and plant = "'.$request->input('plant').'"';
		}

		if($getlevel->level > 2){
			$filter .= ' and plant = "'.\Session::get('fid').'"';	
		}
		$params = array(
			'params'	=> $filter,
			'limit' => 1000
		);

		$this->data['level'] = $getlevel->level;	
		$this->grab( $request,$params) ;
		if($this->access['is_view'] ==0) 
			return redirect('dashboard')->with('message', __('core.note_restric'))->with('status','error');				
		// Render into template
		return view( $this->module.'.index',$this->data);
	}	
	function show( Request $request , $id ) 
	{
		/* Handle import , export and view */
		$task =$id ;
		switch( $task)
		{

			case 'export':
				return $this->getExport( $request );
				break;
	
		}
	}
}