<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * 인클루드 class
 *
 * cm_controller: 부모 Class(CI_Controller 확장한 custome class)
 */

include_once (APPPATH.'core/admin/cm_controller.php');

class service extends cm_controller {

	#---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 기본정보
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function fn_service_authorization_reg() {

//        # model
//        $this->load->model('admin/setting/m_setting_site');
//        $return_data    = $this->m_setting_site->site_info_select();
//        if($return_data == '') {
//            $return_data['homepage_title'] = '';
//            $return_data['admin_logo'] = '';
//            $return_data['footer_script'] = '';
//            $return_data['webmaster_name'] = '';
//            $return_data['webmaster_email'] = '';
//        }
//
//        # view
//        return $this->load->view('/admin/setting/setting_site_reg', $return_data, true);

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 기본정보 저장
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function fn_setting_site_reg_proc() {

	    $homepage_title     = trim($this->input->get_post('homepage_title', TRUE));     // 홈페이지제목
        $footer_script      = trim($this->input->get_post('footer_script', FALSE));      // 하단스크립트
        $webmaster_name     = trim($this->input->get_post('webmaster_name', TRUE));     // 웹마스터이름
        $webmaster_email    = trim($this->input->get_post('webmaster_email', TRUE));    // 웹마스터이메일
        $is_del_admin_logo  = trim($this->input->get_post('is_del_admin_log', TRUE));   // 관리자페이지로고 - 삭제여부

        # valid check
        $this->load->library('form_validation');
        $this->form_validation->set_rules('homepage_title', '홈페이지 제목', 'required');
        $this->form_validation->set_rules('webmaster_name', '웹마스터 이름', 'required');
        $this->form_validation->set_rules('webmaster_email', '웹마스터 이메일주소', 'required');

        if($this->form_validation->run() == false){
            gf_alert("정보를 정확히 입력해주세요.", '/admin/main');
            exit;
        }

        $footer_script = htmlspecialchars($footer_script);

        # model
        $this->load->model('admin/setting/m_setting_site');
        $return_data    = $this->m_setting_site->site_info_select();
        $org_filename = '';
        if($return_data != '') {
            $org_filename   = $return_data['admin_logo'];
            $footer_content = $return_data['footer_content'];
        }

        # 이미지 삭제
        if($is_del_admin_logo=='Y') {
            unlink('.'.$org_filename);
            $org_filename = '';
        }

        if($_FILES['admin_logo']['name']!='') {
             # image upload
            $upload_path = './files/'.date("Y")."/".date("m");
            if (!is_dir($upload_path)) {
                mkdir($upload_path, 0777, TRUE);
            }
            $config['upload_path']      = $upload_path;
            $config['allowed_types']    = 'gif|jpg|png';
            $config['encrypt_name']     = TRUE;

            $this->load->library('upload');
            $this->upload->initialize($config);

            if ( ! $this->upload->do_upload('admin_logo')) {
                $error = array('error' => $this->upload->display_errors());
                gf_alert("이미지 업로드에 실패했습니다.", '/admin/setting/setting_site_reg/1');
                exit;
            }
            $arr_upload_data = $this->upload->data();
            $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '', $arr_upload_data['full_path']);

        } else {
            $filename = $org_filename;
        }

        $req_data['homepage_title']     = $homepage_title;
        $req_data['admin_logo']         = $filename;
        $req_data['footer_script']      = $footer_script;
        $req_data['webmaster_name']     = $webmaster_name;
        $req_data['webmaster_email']    = $webmaster_email;

        if($return_data != '') {    // 수정
            $idx          = $return_data['idx'];
            $req_data['idx']   = $idx;

            # model - update
            $this->load->model('admin/setting/m_setting_site');
            $this->m_setting_site->site_info_update($req_data);

        } else {    // 등록
            # model - update
            $this->load->model('admin/setting/m_setting_site');
            $this->m_setting_site->site_info_insert($req_data);

        }

        gf_alert("저장되었습니다.", '/admin/setting/setting_site_reg/1');

    }



    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 접근기능
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function fn_setting_site_access_reg() {

        # model
        $this->load->model('admin/setting/m_setting_site');
        $return_data    = $this->m_setting_site->site_access_ip_select();

        $arr_return_data['access_type_1'] = '';
        $arr_return_data['access_type_2'] = '';
        $arr_return_data['access_type_3'] = '';
        if($return_data != '') {
            foreach($return_data as $val) {
                $key = 'access_type_'.$val['access_type'];
                $arr_return_data[$key] .= $val['ip']."\r\n";;
            }
        }

        # view
        return $this->load->view('/admin/setting/setting_site_access_reg', $arr_return_data, true);

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 접근기능 저장
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_setting_site_access_reg_proc() {

	    $access_type_1  = trim($this->input->get_post('access_type_1', TRUE));  // 관리자 페이지 접근가능 IP
	    $access_type_2  = trim($this->input->get_post('access_type_2', TRUE));  // 사이트 접근불가 IP
	    $access_type_3  = trim($this->input->get_post('access_type_3', TRUE));  // 사이트 접근가능 IP

        $arr_access_type_1 = explode("\r\n", $access_type_1);
        $arr_access_type_1 = array_values(array_filter(array_map('trim',$arr_access_type_1)));

        $arr_access_type_2 = explode("\r\n", $access_type_2);
        $arr_access_type_2 = array_values(array_filter(array_map('trim',$arr_access_type_2)));

        $arr_access_type_3 = explode("\r\n", $access_type_3);
        $arr_access_type_3 = array_values(array_filter(array_map('trim',$arr_access_type_3)));

        $req_data['access_type_1'] = $arr_access_type_1;
        $req_data['access_type_2'] = $arr_access_type_2;
        $req_data['access_type_3'] = $arr_access_type_3;

        # model - 접근기능 삭제
        $this->load->model('admin/setting/m_setting_site');
        $this->m_setting_site->site_access_ip_delete();

        # model - 금칙접근기능어 입력
        $this->load->model('admin/setting/m_setting_site');
        $this->m_setting_site->site_access_ip_insert($req_data);

        gf_alert("저장되었습니다.", '/admin/setting/setting_site_access_reg/1');

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 하단푸터관리
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function fn_setting_footer_reg() {

        # model
        $this->load->model('admin/setting/m_setting_site');
        $return_data    = $this->m_setting_site->site_info_select();
        if($return_data == '') {
            $return_data['footer_content'] = '';
        }

        # view
        return $this->load->view('/admin/setting/setting_footer_reg', $return_data, true);

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 하단푸터관리 저장
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function fn_setting_footer_reg_proc() {

	    $footer_content    = trim($this->input->get_post('footer_content', TRUE));     // 사이트 하단 정보입력

        # valid check
        $this->load->library('form_validation');
        $this->form_validation->set_rules('footer_content', '사이트 하단 정보입력', 'required');

        if($this->form_validation->run() == false){
            gf_alert("정보를 정확히 입력해주세요.", '/admin/main');
            exit;
        }

        $footer_content = htmlspecialchars($footer_content);


        # model
        $this->load->model('admin/setting/m_setting_site');
        $return_data    = $this->m_setting_site->site_info_select();

        $req_data['footer_content']     = $footer_content;

        if($return_data != '') {    // 수정
            $idx          = $return_data['idx'];
            $req_data['idx']   = $idx;

            # model - update
            $this->load->model('admin/setting/m_setting_site');
            $this->m_setting_site->site_info_footer_content_update($req_data);

        } else {    // 등록
            # model - update
            $this->load->model('admin/setting/m_setting_site');
            $this->m_setting_site->site_info_insert($req_data);

        }

        gf_alert("저장되었습니다.", '/admin/setting/setting_footer_reg/1');

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 금칙어설정
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function fn_setting_forbidden_word_reg() {

        # model
        $this->load->model('admin/setting/m_setting_site');
        $return_data    = $this->m_setting_site->forbidden_word_select();
        if($return_data == '') {
            $return_data['forbidden_word'] = '';
        } else {
            $forbidden_word = '';
            foreach($return_data as $val) {
                $forbidden_word.= $val['word']."\r\n";
            }
            $return_data['forbidden_word'] = $forbidden_word;

        }

        # view
        return $this->load->view('/admin/setting/setting_forbidden_word_reg', $return_data, true);

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 금칙어설정 저장
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_setting_forbidden_word_reg_proc() {

	    $forbidden_word    = trim($this->input->get_post('forbidden_word', TRUE));     // 단어 필터링

        # valid check
        $this->load->library('form_validation');
        $this->form_validation->set_rules('forbidden_word', '단어 필터링', 'required');

        if($this->form_validation->run() == false){
            gf_alert("정보를 정확히 입력해주세요.", '/admin/main');
            exit;
        }
        $arr_forbidden_word = explode("\r\n", $forbidden_word);
        $req_data = array_values(array_filter(array_map('trim',$arr_forbidden_word)));


        # model - 금칙어 삭제
        $this->load->model('admin/setting/m_setting_site');
        $this->m_setting_site->forbidden_word_delete();

        # model - 금칙어 입력
        $this->load->model('admin/setting/m_setting_site');
        $this->m_setting_site->forbidden_word_insert($req_data);



        gf_alert("저장되었습니다.", '/admin/setting/setting_forbidden_word_reg/1');

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 이용약관개인정보 취급방침
    # CREATE  :	2018-02-19
    #---------------------------------------------------------------------------
	function fn_setting_policy_reg() {

        # model
        $this->load->model('admin/setting/m_setting_site');
        $return_data    = $this->m_setting_site->site_info_select();
        if($return_data == '') {
            $return_data['service'] = '';
            $return_data['privacy'] = '';
            $return_data['privacy_agreement'] = '';
        }

        # view
        return $this->load->view('/admin/setting/setting_policy_reg', $return_data, true);


    }

    #---------------------------------------------------------------------------
    # PURPOSE :	사이트정보설정 - 이용약관개인정보 취급방침 저장
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_setting_policy_reg_proc() {

	    $service            = trim($this->input->get_post('service', TRUE));            // 이용약관
	    $privacy            = trim($this->input->get_post('privacy', TRUE));            // 개인정보 취급방침
	    $privacy_agreement  = trim($this->input->get_post('privacy_agreement', TRUE));  // 개인정보 수집 이용동의

        # valid check
        $this->load->library('form_validation');
        $this->form_validation->set_rules('service', '이용약관', 'required');
        $this->form_validation->set_rules('privacy', '개인정보 취급방침', 'required');
        $this->form_validation->set_rules('privacy_agreement', '개인정보 수집 이용동의', 'required');

        if($this->form_validation->run() == false){
            gf_alert("정보를 정확히 입력해주세요.", '/admin/main');
            exit;
        }

        $service            = htmlspecialchars($service);
        $privacy            = htmlspecialchars($privacy);
        $privacy_agreement  = htmlspecialchars($privacy_agreement);

        # model
        $this->load->model('admin/setting/m_setting_site');
        $return_data    = $this->m_setting_site->site_info_select();

        $req_data['service']            = $service;
        $req_data['privacy']            = $privacy;
        $req_data['privacy_agreement']  = $privacy_agreement;

        if($return_data != '') {    // 수정
            $idx          = $return_data['idx'];
            $req_data['idx']   = $idx;

            # model - update
            $this->load->model('admin/setting/m_setting_site');
            $this->m_setting_site->site_info_policy_update($req_data);

        } else {    // 등록
            # model - update
            $this->load->model('admin/setting/m_setting_site');
            $this->m_setting_site->site_info_insert($req_data);

        }

        gf_alert("저장되었습니다.", '/admin/setting/setting_policy_reg/1');

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	신고관리 - 블라인드리스트
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_setting_blind_list() {
        # request
        $page = $this->uri->segment(5);




        # paging 설정
        if($page == '') $page = 1;
        $limit  = PAGE_SIZE;
        $offset = ($page-1) * $limit;




//		$this->load->model('shop/shopinfo');
//		$data['arrRtnShopInfo']			= $this->shopinfo->getShopInfo($Shop_No);
//		$data['arrRtnShopMenuInfo']		= $this->shopinfo->getShopMenuInfo($Shop_No);
//		$data['arrRtnShopReviewList']	= $this->shopinfo->getShopReviewList($Shop_No, $reqData['offset'], $reqData['limit']);
//		$data['url']                  = $reqData['url'];
//
//
//
//
//        # model
//        $this->load->model('admin/setting/m_setting_site');
//        $return_data    = $this->m_setting_site->site_info_select();
//        if($return_data == '') {
//            $return_data['service'] = '';
//            $return_data['privacy'] = '';
//            $return_data['privacy_agreement'] = '';
//        }
//
//        # view
//        return $this->load->view('/admin/setting/setting_policy_reg', $return_data, true);


    }









}

?>