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

class Authentication extends CI_Controller{
	function __construct()
	{
		parent::__construct();
		$this->load->model('master_model');
		//$this->load->library('phpmailer_lib');
		//$mail = $this->phpmailer_lib->load();

	}
	function verification(){

		// if(isset($this->session->userdata['logged_in'])){
		// 	 redirect('http://jade.nityam.in/index.php/gc/dashboard');
		// }else{
		$this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean');
		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
		$this->form_validation->set_rules('remember', 'Remember me', 'integer');
        
   		if ($this->form_validation->run()) {
            $login = $this->input->post('login');
            $password= $this->input->post('password');
            $pass=md5($password);
                        	  $condition[] = array('where','user_name',$login);
                        	  $condition[] = array('where','user_password',$pass);
                               $condition[] = array('join','user_type','users.user_type_id = user_type.user_type_id');

    			 $select_array=array(
                                'table_name'=>'users',
                                'table_fields'=>'user_name,user_password,user_id,users.user_type_id,user_type,module_ids,first_name,last_name',
                                'condition'=>$condition,
                                'limit'=>'',
                                'offset'=>''
                            );
                $field=$this->master_model->select_data($select_array);               
                 foreach ($field as  $value) {

                     $user_type_id=$value['user_type_id'];
                    $module_ids=$value['module_ids'];
                    $user_type=$value['user_type'];
                    $user_id=$value['user_id'];
                    $first_name=$value['first_name'];
                    $last_name=$value['last_name'];
                 }
               $newdata = array( 
                            'user_type_id'  => $user_type_id, 
                            'module_ids'     => $module_ids, 
                            'user_type' => $user_type,
                            'user_id' => $user_id,
                            'first_name' => $first_name,
                            'last_name' => $last_name
               ); 
             $this->session->set_userdata($newdata);

              $users['user']=$this->master_model->select_data($select_array);
                if(!empty($users['user'])&& is_array($users['user'])){

                  //$this->session->set_flashdata('message',' data updated  successfully');
				  redirect('https://shagoon.nityamhygiene.in/index.php/gc/dashboard');
				  // $this->session->set_userdata(array('user'=>$user)); 
  
  	            }else{
                    $this->session->set_flashdata('message','username and password not matched');
  	            	redirect('https://shagoon.nityamhygiene.in/index.php/main/index');
  	            }
        }else{
        	echo "failed login";
        }
	      

	//}
   }
   function forgot_password(){
		
		$this->_page_data['page_title']="Forgot Password";
		$this->_page_data['bredcrum']=array();
		$this->load->view('forgot_password_form',$this->_page_data);
	}
	function mail_forgot_passoword(){

    $data_array = array(
            $data_array['from_email_ids'] => 'shreyas@nityam.in',
            $data_array['to_email_ids'] => 'shreyas@nityam.in',
            $data_array['cc_email_ids'] => '',
            $data_array['bcc_email_ids'] => '',
            $data_array['email_subject'] => 'Password',
            $data_array['email_message'] => 'your password',
            $data_array['path'] => '', //for attchment
);
     $this->customized_email($data_array);
       


      
    }
    function change_password(){
        $this->_page_data['page_title']="Change Password";
        $this->_page_data['bredcrum']=array();
       $this->load->view('forgot_password_form',$this->_page_data);
    }
    
			//header('location:index.php');
			
}