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

class Login extends CI_Controller{
    //put your code here
     function __construct() {
        parent::__construct();
        $this->load->model('customerloginmodel/customerloginmodel','customerloginmodel');
    }

    public function index() {
        $this->load->helper('form','url');
        $this->load->library('form_validation');
        $config = array(
        'username' => array(
            '' 
        ) );
        $this->form_validation->set_rules('username', 'Username', 'required|trim|xss_clean|callback__alpha_dash_space');
        $this->form_validation->set_rules('password', 'Password', 'required');
        if($this->form_validation->run()==FALSE){
            //$this->load->view('common/header');
            //$this->load->view('common/menu');
            //echo 'hi';
           $this->load->view('customerPanel/login');
           //$this->load->view('common/footer');
        }else{
            $admin_data = $this->customerloginmodel->login_info(); 


            if ($admin_data['login_validation'] == FALSE) {
                 $sdata['exception'] = 'Username & Password invalid!';
                $this->session->set_userdata($sdata);
                redirect(base_url('customercontrolar'));
            } else {

                if($admin_data['customer_access']==1)
                {    
                    $session_data = array(
                        'id' => $admin_data['id'],
                        'applicant_name' => $admin_data['applicant_name'],                    
                        'customerId' => $admin_data['customerId'],
                        'customer_access' => $admin_data['customer_access'],
                        'logged_info_customer' => TRUE
                    );

                    $this->session->set_userdata($session_data);
                    redirect(base_url('customercontrolar/home'));
                }
                else{
                    $sdata['exception'] = 'You are not authorize to access';
                    $this->session->set_userdata($sdata);
                    redirect(base_url('customercontrolar'));
                }
            }
        }
        

    }
}
