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

class m_design extends CI_Model{

	// 생성자, 해당 모델이 생성될때 항상 실행되는 초기화작업
	function __construct(){
		parent::__construct();

        $this->load->database();
        $this->load->library('session');
	}

	#---------------------------------------------------------------------------
    # PURPOSE :	popup - list
    # CREATE  :	2018-02-22
    #---------------------------------------------------------------------------
	function popup_list($req_data){
        # request
        $offset                 = $req_data['offset'];
        $limit                  = $req_data['limit'];

        $search_type            = $req_data['search_type'];
        $search_keyword         = $req_data['search_keyword'];
        $search_menu_code       = $req_data['search_menu_code'];

        if($search_type!='' && $search_keyword!=''){
            $this->db->like($search_type, $search_keyword);
        }
        if($search_menu_code!='')    $this->db->where('menu_code', $search_menu_code);
        $this->db->where('is_del', 'N');
        $this->db->from('popup');
        $this->db->limit($limit, $offset);
        $this->db->order_by('reg_date',  'desc');
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }

    #---------------------------------------------------------------------------
    # PURPOSE :	popup - list용 - total count
    # CREATE  :	2018-02-21
    #---------------------------------------------------------------------------
	function popup_list_total_count($req_data){
	    # request
	    $search_type            = $req_data['search_type'];
        $search_keyword         = $req_data['search_keyword'];
        $search_menu_code       = $req_data['search_menu_code'];

        if($search_type!='' && $search_keyword!=''){
            $this->db->like($search_type, $search_keyword);
        }
        if($search_menu_code!='')    $this->db->where('menu_code', $search_menu_code);
        $this->db->where('is_del', 'N');
        $this->db->from('popup');
        $row = $this->db->count_all_results();

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	popup - select
    # CREATE  :	2018-02-26
    #---------------------------------------------------------------------------
	function popup_select($req_data){
	    # request
	    $idx            = $req_data;

        $this->db->where('idx', $idx);
        $this->db->where('is_del', 'N');
        $this->db->from('popup');
        $res = $this->db->get();
        $row = $res->result_array();

        return $row;
    }

    #---------------------------------------------------------------------------
    # PURPOSE :	popup - insert
    # CREATE  :	2018-02-26
    #---------------------------------------------------------------------------
	function popup_insert($req_data){

        $user_id        = $this->session->userdata('Adm_Id');
        $now_date       = date("Y-m-d H:i:s");

        $req_data['reg_id']      = $user_id;
        $req_data['reg_date']    = $now_date;
        $req_data['update_id']   = $user_id;
        $req_data['update_date'] = $now_date;
        
        $row = $this->db->insert('popup', $req_data);

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	popup - update
    # CREATE  :	2018-02-26
    #---------------------------------------------------------------------------
	function popup_update($req_data){
	    # request
	    $idx            = $req_data['idx'];
        unset($req_data['idx']);
        
        $user_id        = $this->session->userdata('Adm_Id');
        $now_date       = date("Y-m-d H:i:s");

        $req_data['update_id']      = $user_id;
        $req_data['update_date']    = $now_date;

        $this->db->where('idx', $idx);
        $row = $this->db->update('popup', $req_data);

        return $row;
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	popup.is_del update
    # CREATE  :	2018-02-26
    #---------------------------------------------------------------------------
	function popup_is_del_update($req_data){
        $user_id    = $this->session->userdata('Adm_Id');
        $now_date   = date("Y-m-d H:i:s");

        $arr_update_data = array();
        foreach($req_data as $key=>$val) {
            $arr_update_data[$key]['idx']           = $val;
            $arr_update_data[$key]['is_del']        = 'Y';
            $arr_update_data[$key]['update_id']     = $user_id;
            $arr_update_data[$key]['update_date']   = $now_date;
        }
        $this->db->update_batch('popup', $arr_update_data, 'idx');

    }

}
?>
