<?php
class Log_details_report_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
        $this->services = TBL_SERVICE;
        $this->service_menu = TBL_SERVICE_MENU;
        $this->login = TBL_LOGIN;
        $this->user = TBL_USERS;
        $this->master = TBL_SETTINGS_MASTER;
        $this->inventory = TBL_SETTINGS_INVENTORY;
        $this->statue = TBL_SETTINGS_STATUE;
    }
    
    public function get_data($start_date='',$end_date=''){
        $this->db->select('l.ip_address, l.log_date_time, l.desc, l.service_menu_id, l.menu_type, u.name, CASE l.page_type_id WHEN 2 THEN "Edit" WHEN 4 THEN "Delete" WHEN 8 THEN "Sync" END as page_type',FALSE);
        $this->db->join($this->user . ' as u','u.id = l.user_id');
        if(!empty($start_date) && !empty($end_date)) {
            $this->db->where('l.log_date_time >=',date('Y-m-d 00:00:00',strtotime($start_date)));
            $this->db->where('l.log_date_time <=',date('Y-m-d 23:59:59',strtotime($end_date)));
        } else {
            $this->db->where('l.log_date_time >=',date('Y-m-d 00:00:00'));
            $this->db->where('l.log_date_time <=',date('Y-m-d 23:59:59'));
        }
        $this->db->where('l.status',1);
        $this->db->order_by('l.id','desc');
        return $this->db->get($this->login . ' as l')->result();
    }
    
    public function get_service_name($menu_type,$service_id) {
        if($menu_type == 1) {
            $tbl_name = $this->master;
            $service_name = 'master_name as service_name';
        } else if($menu_type == 3) {
            $tbl_name = $this->inventory;
            $service_name = 'inventory_name as service_name';
        } elseif($menu_type == 4) {
            $tbl_name = $this->service_menu;
            $service_name = 'service_name as service_name';
        } elseif($menu_type == 5) {
            $tbl_name = $this->statue;
            $service_name = 'menu_name as service_name';
        }
        
        if($menu_type != 8) {
            $this->db->select('id,controller_name,' . $service_name ,FALSE);
            $this->db->where('id',$service_id);
            $this->db->where('status',1);
            return $this->db->get($tbl_name)->row();
        }
    }
}
?>