<?php

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

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     * 	- or -
     * 		http://example.com/index.php/welcome/index
     * 	- or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');

        $this->load->model('welcome_model', 'w_model');
    }

    /**
     * Default controller.
     * 
     * 
     */
    public function welcomeAdmin() {
        $response_data['response'] = $this->session->flashdata('response');
        $response_data['status'] = $this->session->flashdata('status');
        $response_data['message'] = $this->session->flashdata('message');
        $logedInStatus = $this->session->userdata('logedInStatus');
        if ($logedInStatus) {
            $this->session->set_userdata('rendering', 'success');
        } else {
            $this->session->set_userdata('rendering', 'login');
        }

        $this->load->view('welcome', $response_data);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function userAuthenticationUserIdPassword() {
        $post_data = array();

        $post_data['loginId'] = $this->input->post('userId');

        $post_data['password'] = base64_encode($this->input->post('password'));


        $response_data = $this->w_model->userAuthenticationUserIdPassword_model($post_data);
       
        if ($response_data['status']) {

            $this->session->set_userdata('logedInStatus', $response_data['status']);
            $this->session->set_userdata('userRight', $this->w_model->getUserRightFunctionModel($response_data['response_data'][0]['userId']));
        }
        $this->session->set_flashdata('response', $response_data['response_data']);
        $this->session->set_flashdata('status', $response_data['status']);
        $this->session->set_flashdata('message', $response_data['message']);
        redirect();
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function newUserRegistrationForm() {
        
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function newUserRegistrationFormSubmit() {
        
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function imageUploadPage() {
        $this->load->view('image');
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function userLogoutUniversal() {
        $this->session->sess_destroy();
        $message = "Logout successfully";
        $this->session->set_flashdata('response', true);
        $this->session->set_flashdata('status', false);
        $this->session->set_flashdata('message', $message);
        redirect('');
    }

}
