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

class Users extends CI_Controller {

	public function index()
	{	
		if($this->session->userdata('name'))
		{
			$this->load->view('main_header');
			$this->load->view('sidebar');
			$this->load->model('Model_user');
			$users = $this->Model_user->UserShow();
			$data['users']=$users;
			$this->load->view('users_show' ,$data);
			$this->load->view('footer');
		}
		else
		{
			redirect('login');
		}
		
	}
	public function UsersAdd()
	{	
		if($this->session->userdata('name'))
		{
			$this->load->view('main_header');
			$this->load->view('sidebar');
			$this->load->model('Model_user');
			$role = $this->Model_user->UserRoleShow();
			$data['role']=$role;
			$this->load->view('users_add' , $data);
			$this->load->view('footer');
		}
		else
		{
			redirect('login');
		}
		
	}
	public function UsersAddVerify()
	{
		$arrUserInfo['user_name']=$this->input->post('user_name');
		$arrUserInfo['user_password']=md5($this->input->post('password'));
		$arrUserInfo['user_role_id']=$this->input->post('users_role');
		$arrUserInfo['user_creation']=date("Y-m-d");
		$this->load->model('Model_user');
		$check = $this->Model_user->UesrAdd($arrUserInfo);
		if($check== true)
		{
			redirect('/Users');
		}
		
	}
	public function UserEdit($id)
	{	
		if($this->session->userdata('name'))
		{
			$this->load->view('main_header');
			$this->load->view('sidebar');
			$this->load->model('Model_user');
			$edit = $this->Model_user->UserShowEdit($id);
			$role = $this->Model_user->GetRole();
			$data['edit']=$edit;
			$data['role']=$role;
			$this->load->view('users_edit',$data);
			$this->load->view('footer');
		}
		else
		{
			redirect('login');
		}
		
	}
	public function UsersEditVerify()
	{
		$arrUserInfoUpdate['user_name']=$this->input->post('user_name');
		$arrUserInfoUpdate['user_role_id']=$this->input->post('users_role');
		$arrUserInfoUpdate['user_updation']=date("Y-m-d");
		$id=$this->input->post('id');
		$this->load->model('Model_user');
		$check = $this->Model_user->UesrUpdate($id,$arrUserInfoUpdate);
		if($check== true)
		{
			redirect('/Users');
		}
		
	}
	public function UsersRole()
	{	
		if($this->session->userdata('name'))
		{
			$this->load->view('main_header');
			$this->load->view('sidebar');
			$this->load->model('Model_user');
			$role = $this->Model_user->UserRoleShow();
			$data['role']=$role;
			$this->load->view('users_role_show', $data);
			$this->load->view('footer');
		}
		else
		{
			redirect('login');
		}
		
	}
		public function UsersRoleAdd()
	{	
		if($this->session->userdata('name'))
		{
			$this->load->view('main_header');
			$this->load->view('sidebar');
			$this->load->view('users_role_add');
			$this->load->view('footer');
		}
		else
		{
			redirect('login');
		}
		
	}
	public function UsersRoleAddVerify()
	{	
		$arrInfo['role_name']=$this->input->post('user_role');
		$arrInfo['role_creation']=date("Y-m-d");
		$this->load->model('Model_user');
		$check = $this->Model_user->UesrRoleAdd($arrInfo);
		if($check== true)
		{
			redirect('/Users/UsersRole');
		}
		
		
	}
		public function UsersRoleEdit($id)
	{	

		if($this->session->userdata('name'))
		{
			$this->load->view('main_header');
			$this->load->view('sidebar');
			$this->load->model('Model_user');
			$edit = $this->Model_user->UserRoleShowEdit($id);
			$data['edit']=$edit;
			$this->load->view('users_role_edit',$data);
			$this->load->view('footer');
		}
		else
		{
			redirect('login');
		}
		
	}
	public function UsersRoleEditVerify($id)
	{	

		if($this->session->userdata('name'))
		{
			$arrUpdate['role_name']=$this->input->post('role');
			$arrUpdate['role_updation']=date("Y-m-d");
			print_r($arrUpdate);
			
			$this->load->model('Model_user');
			$update = $this->Model_user->UserRoleUpdate($id,$arrUpdate);
			if($update== true)
		{
			redirect('/Users/UsersRole');
		}
		
			
		}
		else
		{
			redirect('login');
		}
		
	}








}