<?php

/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 23/06/2018
 * Time: 03:18 AM
 */
class Login_Model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function Login_Check($user_userName, $user_Password, $remember_Me)
    {
        $retrieve = $this->db->get_where('user', array('user_userName' => $user_userName, 'user_Password' => md5($user_Password)));
        $count = $retrieve->num_rows();
        if ($count > 0) {
            if ($retrieve->row(0)->user_Ban == true) {
                echo "ban_user";
            } else {
                $user_session = array(
                    'user_id' => $retrieve->row(0)->user_Id,
                    'user_firstName' => $retrieve->row(0)->user_firstName,
                    'user_lastName' => $retrieve->row(0)->user_lastName,
                    'user_Mobile' => $retrieve->row(0)->user_Mobile,
                    'user_userName' => $retrieve->row(0)->user_userName,
                    'user_Password' => $retrieve->row(0)->user_Password,
                    'user_lastLogin' => $retrieve->row(0)->user_lastLogin,
                    'user_Access' => $retrieve->row(0)->user_Access,
                    'user_Ban' => $retrieve->row(0)->user_Ban,
                    'user_Img' => $retrieve->row(0)->user_Img,
                );
                $this->session->set_userdata($user_session);
                if ($remember_Me == "true") {
                    setcookie('userName', $retrieve->row(0)->user_userName, time() + 86400, '/');
                    setcookie('Password', $retrieve->row(0)->user_Password, time() + 86400, '/');
                }
                echo "<a target='_blank' href='" . base_url('Dashboard') . "'>جهت ورود به پنل مدیریت کلیک کنید</a>";
            }
        } else {
            echo "no_user";
        }
    }

    public function Get_User_Email($user_email)
    {
        $retrieve = $this->db->get_where('users', array('P_B_Users_email' => $user_email));
        $count = $retrieve->num_rows();
        if ($count > 0) return true;
        else return false;
    }
}
