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

class m_setting_site extends CI_Model{

	function __construct(){
		parent::__construct();

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



	#---------------------------------------------------------------------------
    # PURPOSE :	site_info select
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function site_info_select(){
        $sql1 = "select * from site_info where idx = 1";
        $res1 = $this->db->query($sql1);
        $row1 = $res1->row();

        $array = json_decode(json_encode($row1), true);

        return $array;

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	site_info insert
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function site_info_insert($req_data){
	    # request
        $homepage_title     = $req_data['homepage_title'];
        $footer_script      = $req_data['footer_script'];
        $webmaster_name     = $req_data['webmaster_name'];
        $webmaster_email    = $req_data['webmaster_email'];
        $admin_logo         = $req_data['admin_logo'];
        $footer_content     = $req_data['footer_content'];

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

        $insert_data = array('idx' => 1,
                             'homepage_title' => $homepage_title,
                             'footer_script' => $footer_script,
                             'webmaster_name' => $webmaster_name,
                             'webmaster_email' => $webmaster_email,
                             'admin_logo' => $admin_logo,
                             'footer_content' => $footer_content,
                             'reg_date' => $now_date,
                             'update_id' => $user_id,
                             'update_date' => $now_date
        );
        $this->db->insert('site_info', $insert_data);

    }




    #---------------------------------------------------------------------------
    # PURPOSE :	site_info update
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function site_info_update($req_data){
	    # request
        $idx                = $req_data['idx'];
        $homepage_title     = $req_data['homepage_title'];
        $footer_script      = $req_data['footer_script'];
        $webmaster_name     = $req_data['webmaster_name'];
        $webmaster_email    = $req_data['webmaster_email'];
        $admin_logo         = $req_data['admin_logo'];

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

        $update_data = array('homepage_title' => $homepage_title,
                             'footer_script' => $footer_script,
                             'webmaster_name' => $webmaster_name,
                             'webmaster_email' => $webmaster_email,
                             'admin_logo' => $admin_logo,
                             'update_id' => $user_id,
                             'update_date' => $now_date
        );
        $this->db->where('idx', $idx);
        $this->db->update('site_info', $update_data);

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	site_info.footer_content update
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function site_info_footer_content_update($req_data){
	    # request
        $idx                = $req_data['idx'];
        $footer_content     = $req_data['footer_content'];

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

        $update_data = array('footer_content' => $footer_content,
                             'update_id' => $user_id,
                             'update_date' => $now_date
        );
        $this->db->where('idx', $idx);
        $this->db->update('site_info', $update_data);

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	site_info.service, privacy, privacy_agreement update
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function site_info_policy_update($req_data){
	    # request
        $idx                = $req_data['idx'];
        $service            = $req_data['service'];
        $privacy            = $req_data['privacy'];
        $privacy_agreement  = $req_data['privacy_agreement'];

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

        $update_data = array('service' => $service,
                             'privacy' => $privacy,
                             'privacy_agreement' => $privacy_agreement,
                             'update_id' => $user_id,
                             'update_date' => $now_date
        );
        $this->db->where('idx', $idx);
        $this->db->update('site_info', $update_data);

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	금칙어 select
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function forbidden_word_select(){
        $sql1 = "select * from forbidden_word order by idx asc";
        $res1 = $this->db->query($sql1);
        $row1 = $res1->result_array();

        return $row1;

    }

    #---------------------------------------------------------------------------
    # PURPOSE : 금칙어 truncate
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function forbidden_word_delete(){
	    $this->db->truncate('forbidden_word');
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	금칙어 insert
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function forbidden_word_insert($req_data){
        $user_id    = $this->session->userdata('Adm_Id');
        $now_date   = date("Y-m-d H:i:s");

        $i = 0;
        $arr_word = array();
        foreach($req_data as $val) {
            $arr_word[$i]['word']        = $val;
            $arr_word[$i]['reg_id']      = $user_id;
            $arr_word[$i]['reg_date']    = $now_date;
            $i++;
        }
        $this->db->insert_batch('forbidden_word', $arr_word);

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	접근권한 select
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function site_access_ip_select(){
        $sql1 = "select * from site_access_ip order by idx asc";
        $res1 = $this->db->query($sql1);
        $row1 = $res1->result_array();

        return $row1;

    }

    #---------------------------------------------------------------------------
    # PURPOSE : 접근권한 truncate
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function site_access_ip_delete(){
	    $this->db->truncate('site_access_ip');
    }

    #---------------------------------------------------------------------------
    # PURPOSE :	접근권한 insert
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function site_access_ip_insert($req_data){
        $user_id    = $this->session->userdata('Adm_Id');
        $now_date   = date("Y-m-d H:i:s");

        $i = 0;
        $arr_access_ip = array();
        foreach ($req_data['access_type_1'] as $val1){
            $arr_access_ip[$i]['access_type']   = 1;
            $arr_access_ip[$i]['ip']            = $val1;
            $arr_access_ip[$i]['reg_id']        = $user_id;
            $arr_access_ip[$i]['reg_date']      = $now_date;
            $i++;
        }

        foreach ($req_data['access_type_2'] as $val2){
            $arr_access_ip[$i]['access_type']   = 2;
            $arr_access_ip[$i]['ip']            = $val2;
            $arr_access_ip[$i]['reg_id']        = $user_id;
            $arr_access_ip[$i]['reg_date']      = $now_date;
            $i++;
        }

        foreach ($req_data['access_type_3'] as $val3){
            $arr_access_ip[$i]['access_type']   = 3;
            $arr_access_ip[$i]['ip']            = $val3;
            $arr_access_ip[$i]['reg_id']        = $user_id;
            $arr_access_ip[$i]['reg_date']      = $now_date;
            $i++;
        }

        $this->db->insert_batch('site_access_ip', $arr_access_ip);

    }






}
?>
