<?php
class UserModel extends CI_Model {
    
    public function check_user($username,$password){
        $table='users';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where("mobile",$username);
        $this->db->where("password",$password);
        $info=$this->db->get()->result_array();
        return $info;    
    }    
    // public function add_new_emp($data_array,$table){
        // $this->db->insert($table,$data_array);
        // return $this->db->insert_id();    
    // }

    public function add_log($data_array){
        $table='login_history';    
        $this->db->insert($table,$data_array);
        return $this->db->insert_id();        
    }

    public function start_day($data_array,$table){
        $this->db->insert($table,$data_array);
        return $this->db->insert_id();       
    }


    public function check_day_attendance($date,$eid){
        $table='staff_attendence';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where("markInDate",$date);
        $this->db->where("userId",$eid);
        $this->db->where("status",1);
        // $this->db->where("is_markout",0);
        $info=$this->db->get()->result_array();
        return $info;     
    }

    public function new_check_in($data_array,$table){
        $this->db->insert($table,$data_array);
        return $this->db->insert_id();     
    }

    public function check_active_checkin($eid,$date){
        $table='activities';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where("checkin_date",$date);
        $this->db->where("eid",$eid);
        $this->db->where("status",0);
        $info=$this->db->get()->result_array();
        return $info;      
    }

    public function checkout($activity,$eid,$date,$data_array,$table){
        $info =array();	
        $this->db->where("id",$activity);
        $this->db->where("eid",$eid);
        $this->db->where("checkin_date",$date);
        // $data_array = array("status"=>1,"checkout_time"=>$checkout_time,);
        $info= $this->db->update($table,$data_array);
        return $info;    
    }


    public function daily_log($date,$eid){
        $table='activities';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where("checkin_date",$date);
        $this->db->where("eid",$eid);
        // $this->db->where("status",0);
        $info=$this->db->get()->result_array();
        return $info;        
    }

    public function markout($activity,$eid,$date,$data_array,$table){
        $info =array();	
        $this->db->where("id",$activity);
        $this->db->where("userId",$eid);
        $this->db->where("markInDate",$date);
        // $data_array = array("status"=>1,"checkout_time"=>$checkout_time,);
        $info= $this->db->update($table,$data_array);
        return $info;        
    }


    public function check_user_password($old_password,$user_id){
        $table='users';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where("id",$user_id);
        $this->db->where("password",$old_password);
        $this->db->where("status",1);
        $info=$this->db->get()->result_array();
        return $info;   
    }

    public function change_password($user_id,$new_password){
        $table='users';
        $info =array();	
        $this->db->where("id",$user_id);
        // $this->db->where("password",$old_password);
        $data_array = array("password"=>$new_password);
        $info= $this->db->update($table,$data_array);
        return $info;         
    }

    public function day_checkins($date,$emp_id){
        $table='activities';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where("eid",$emp_id);
        $this->db->where("checkin_date",$date);
        $info=$this->db->get()->result_array();
        return $info;     
    }
    public function get_attendance($table1,$emp_id,$date){
        $info=array();
        $this->db->select('*');
        $this->db->from($table1);
        $this->db->where("userId",$emp_id);
        $this->db->where("markInDate",$date);
        $info=$this->db->get()->result_array();
        return $info;    
    }
    public function get_user_markin_location_data($table,$eid,$date){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where("userId",$eid);
        $this->db->where("markInDate",$date);
        $info=$this->db->get()->result_array();
        return $info;     
    }
}