<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of User_Controller
 *
 * @author Code sys PC 7
 */
class User_Controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('user');
        $this->load->helper('form');
        $this->load->helper('url');
    }

    function checkUsersLoginDetails() {
        $username = $this->input->post("username");
        $password = $this->input->post("password");
        $log_details = array('username' => $username, 'password' => $password);
        $isUser = $this->user->checkLoginDetails($log_details);
        if ($isUser) {
            foreach ($isUser->result() as $row) {
                session_start();
                $sesiondata = array('id' => $row->iduser, 'username' => $row->username, 'name' => $row->name);
                $_SESSION['user'] = $sesiondata;
                break;
            }
            redirect(base_url()."index.php/Ui_controller/main");
        } else {
            redirect(base_url() . "?er_msg=Invalid Login Details Please Check and Try Again");
        }
    }

    public function logout() {
        if (session_id() == '') {
            session_start();
        }
        unset($_SESSION['user']);
        session_destroy();
        redirect(base_url());
    }
    
}
