<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {

	public function index()
	{
		if($this->input->post()){

			
			$userdata = $this->User_m->login($_POST);
			
			if($userdata){
	                      $usersession = array(
	                		'id'=>$userdata[0]['id'],
	                		'username'=>$userdata[0]['username'],
	                		'name'=>$userdata[0]['name'],
	                		'password'=>$userdata[0]['password'],
	                		
	                		'role'=>$userdata[0]['role'],
						);
						$this->session->set_userdata($usersession);
						if($userdata[0]['role']==1)
						{
							if($userdata){$data=array('status'=>'true','role'=>1);}else{$data=array('status'=>'false');}
							echo json_encode($data);
						}else if($userdata[0]['role']==2)
						{
							if($userdata){$data=array('status'=>'true','role'=>2);}else{$data=array('status'=>'false');}
							echo json_encode($data);
						}if($userdata[0]['role']==3)
						{
							if($userdata){$data=array('status'=>'true','role'=>3);}else{$data=array('status'=>'false');}
							echo json_encode($data);
						}if($userdata[0]['role']==4)
						{
							if($userdata){$data=array('status'=>'true','role'=>4);}else{$data=array('status'=>'false');}
							echo json_encode($data);
						}if($userdata[0]['role']==5)
						{
							if($userdata){$data=array('status'=>'true','role'=>5);}else{$data=array('status'=>'false');}
							echo json_encode($data);
						}if($userdata[0]['role']==6)
						{
							if($userdata){$data=array('status'=>'true','role'=>6);}else{$data=array('status'=>'false');}
							echo json_encode($data);
						}if($userdata[0]['role']==7)
						{
							if($userdata){$data=array('status'=>'true','role'=>7);}else{$data=array('status'=>'false');}
							echo json_encode($data);
						}


			}else{$this->load->view('signin');}  
		}else{$this->load->view('signin');}  
	}//end function index()
	
	
	
	
	/*public function processSignin()
	{

		$response['success'] = $this->input->post('username').' '.$this->input->post('password');
   	 	echo json_encode($response);
		
	}*/
	
	
	
	
	
	

	
}