<?php defined('BASEPATH') OR exit('No direct script access allowed');
header("Content-Type: text/html; charset=UTF-8");
/**
 * 인클루드 class
 *
 * cm_controller: 부모 Class(CI_Controller 확장한 custome class)
 */
include_once(APPPATH.'core/admin/cm_controller.php');

class member extends cm_Controller {

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원가입설정
    # CREATE  :	2018-02-25
    #---------------------------------------------------------------------------
	function fn_member_setting_reg() {

	    # model - select
        $this->load->model('admin/member/m_member_setting');
        $result = $this->m_member_setting->m_member_setting_list();

        if(count($result) == 0) {
            gf_alert("잘못된 접근입니다.", '/admin/main');
            exit;
        }

        $return_data['list']              = $result;

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

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원가입설정 - 저장
    # CREATE  :	2018-02-27
    #---------------------------------------------------------------------------
	function fn_member_setting_reg_proc() {
        # request
        $arr_idx          = $this->input->get_post('idx', TRUE);
        $arr_item_title   = $this->input->get_post('item_title', TRUE);
        $arr_is_use       = $this->input->get_post('is_use', TRUE);
        $arr_is_required  = $this->input->get_post('is_required', TRUE);

        $req_data =  array();
        $z = 0;
        for($i=8; $i<=14; $i++) {
            $req_data[$z]['idx']    = $arr_idx[$i];
            $req_data[$z]['item_title']  = $arr_item_title[$i];
            if($req_data[$z]['item_title'] == '') {
                $req_data[$z]['is_use'] = 'N';
            } else {
                if(isset($arr_is_use[$i])== true) {
                    $req_data[$z]['is_use'] = $arr_is_use[$i];
                } else {
                    $req_data[$z]['is_use'] = 'N';
                }
            }
            if(isset($arr_is_required[$i])== true) {
                $req_data[$z]['is_required'] = $arr_is_required[$i];
            } else {
                $req_data[$z]['is_required'] = 'N';
            }
            $z++;

        }

        # model - update
        $this->load->model('admin/member/m_member_setting');
        $result = $this->m_member_setting->m_member_setting_update($req_data);

        if(!$result) {
            gf_alert("저장에 실패했습니다. 다시시도해 주세요.", '/admin/member/member_setting_reg/4');
            exit;
        }


        gf_alert("저장되었습니다.", '/admin/member/member_setting_reg/4');


    }



    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원그룹설정
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_member_group_list() {
        # request
        $page = $this->uri->segment(5);
        $member_type       = trim($this->input->get_post('member_type', TRUE));   // 회원타입 (1:일반, 2:파트너)

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

        if($member_type == '' || $member_type==0)  $member_type = 1;

        $req_data['member_type']= $member_type;
        $req_data['offset']     = $offset;
        $req_data['limit']      = $limit;

	    # model - 회원그룹 select
        $this->load->model('admin/member/m_member_group');
        $total_count    = $this->m_member_group->member_group_total_count($req_data);
        $result         = $this->m_member_group->member_group_list($req_data);



        # pagination
        $req_data = array();
        $req_data['total_count']    = $total_count;
        $req_data['limit']          = $limit;
        $req_data['base_url']       =  '/admin/member/member_group_list/4' ;
        $req_data['suffix']         = '?'.$_SERVER['QUERY_STRING'];

        $this->load->library('comm_admin');
        $pagination = $this->comm_admin->fn_pagination($req_data);



        $return_data['member_type'] = $member_type;
        $return_data['list'] = $result;
		$return_data['pagination']	= $pagination;
        $return_data['page']        = $page;
        # view
        return $this->load->view('/admin/member/member_group_list', $return_data, true);

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원그룹설정 > 그룹등록/수정
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_member_group_reg_proc() {
        # request
        $mode                   = trim($this->input->get_post('mode', TRUE));               // add or edit
        $member_group_idx       = trim($this->input->get_post('member_group_idx', TRUE));   // 수정일 경우 idx
        $member_group_name      = trim($this->input->get_post('member_group_name', TRUE));  // 회원그룹명
        $member_type            = trim($this->input->get_post('member_type', TRUE));        // 회원타입 (1:일반, 2:파트너)

        if($mode == 'add') {
            $req_data['member_group_name']  = $member_group_name;
            $req_data['member_type']        = $member_type;

            # model - insert
            $this->load->model('admin/member/m_member_group');
            $result = $this->m_member_group->member_group_insert($req_data);


            $req_data['member_group_idx'] = $result;        // last idx

            // 그룹등록시 기본 권한 넣어주기
            require_once(APPPATH.'inc/member_group_menu_auth_inc.php');
            $req_data['menu_list'] = $def_arr_member_group_menu_auth[$member_type];
            $this->m_member_group->member_group_menu_auth_insert($req_data);
            

        } else if($mode == 'edit') {
            $req_data['idx']                = $member_group_idx;
            $req_data['member_group_name']  = $member_group_name;

            # model - update
            $this->load->model('admin/member/m_member_group');
            $result = $this->m_member_group->member_group_update($req_data);

            $result_code = array('result_code' => '0000');

        }

        gf_alert("저장되었습니다.", '/admin/member/member_group_list/4?member_type='.$member_type);
    }



    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원그룹설정 > 사용안함 처리
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_member_group_status_proc() {
        # request
        $arr_member_group_idx   = $this->input->get_post('member_group_status', TRUE);   // 사용안함 처리할 idx
        $member_type            = trim($this->input->get_post('member_type', TRUE));


        # model - update
        $this->load->model('admin/member/m_member_group');
        $this->m_member_group->member_group_status_update($arr_member_group_idx);

        gf_alert("저장되었습니다.", '/admin/member/member_group_list/4?member_type='.$member_type);

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원그룹설정 > 삭제 처리
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_member_group_del_proc() {
        # request
        $arr_member_group_idx   = $this->input->get_post('is_del', TRUE);   // 삭제할 idx
        $member_type            = trim($this->input->get_post('member_type', TRUE));

        # model - update
        $this->load->model('admin/member/m_member_group');
        $this->m_member_group->member_group_is_del_update($arr_member_group_idx);

        gf_alert("삭제되었습니다.", '/admin/member/member_group_list/4?member_type='.$member_type);

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원그룹설정 > 메뉴권한 설정
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_member_group_menu_auth_reg() {
        # request
	    $member_group_idx   = trim($this->input->get_post('member_group_idx', TRUE));   //  idx
        $member_type        = trim($this->input->get_post('member_type', TRUE));        // 회원타입 (0:비회원, 1:일반, 2:파트너)
        $page               = $this->uri->segment(5);                                   // page

        # model - select
        $this->load->model('admin/member/m_member_group');
        $result = $this->m_member_group->member_group_join_member_group_menu_auth_select($member_group_idx);

        $return_data['result']              = $result;
        $return_data['page']                = $page;
        $return_data['member_type']         = $member_type;
        $return_data['member_group_idx']    = $member_group_idx;

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

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 회원설정 > 회원그룹설정 > 메뉴권한 설정 - 저장
    # CREATE  :	2018-02-20
    #---------------------------------------------------------------------------
	function fn_member_group_menu_auth_reg_proc() {
        # request
	    $member_group_idx       = trim($this->input->get_post('member_group_idx', TRUE));   //  idx
        $member_type            = trim($this->input->get_post('member_type', TRUE));        // 회원타입 (0:비회원, 1:일반, 2:파트너)
        $page                   = trim($this->input->get_post('page', TRUE));               // page
        $arr_menu_auth_status   = $this->input->get_post('menu_auth_status', TRUE);


        # model - update
        $this->load->model('admin/member/m_member_group');
        $result1 = $this->m_member_group->member_group_menu_auth_menu_auth_status_reset($member_group_idx);
        if(!$result1) {
            gf_alert("저장에 실패했습니다. 다시시도해 주세요.", '/admin/member/member_group_menu_auth_reg/4/'.$page.'?member_type='.$member_type.'&member_group_idx='.$member_group_idx);
            exit;
        }

        if(count($arr_menu_auth_status) > 0){
            $result2 = $this->m_member_group->member_group_menu_auth_menu_auth_status_update($arr_menu_auth_status);
            if(!$result2) {
                gf_alert("저장에 실패했습니다. 다시시도해 주세요.", '/admin/member/member_group_menu_auth_reg/4/'.$page.'?member_type='.$member_type.'&member_group_idx='.$member_group_idx);
                exit;
            }
        }


        gf_alert("저장되었습니다.", '/admin/member/member_group_list/4/'.$page.'?member_type='.$member_type);


    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 일반회원
    # CREATE  :	2018-02-21
    #---------------------------------------------------------------------------
	function fn_member_list() {
        # request
	    $page                   = $this->uri->segment(5);
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_member_group    = trim($this->input->get_post('search_member_group', TRUE));
        $search_member_gender   = trim($this->input->get_post('search_member_gender', TRUE));
        $search_member_age      = trim($this->input->get_post('search_member_age', TRUE));
        $search_member_new      = trim($this->input->get_post('search_member_new', TRUE));

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

        # 검색
        $req_data['search_type']            = $search_type;
        $req_data['search_keyword']         = addslashes($search_keyword);
        $req_data['search_member_group']    = $search_member_group;
        $req_data['search_member_gender']   = $search_member_gender;
        $req_data['search_member_age']      = $search_member_age;
        $req_data['search_member_new']      = $search_member_new;
        $req_data['offset']                 = $offset;
        $req_data['limit']                  = $limit;

	    # model - 회원 select
        $this->load->model('admin/member/m_member');
        // 통계용
        $total_count        = $this->m_member->member_total_count();
        $member_gender      = $this->m_member->member_group_by_member_gender();
        $member_group       = $this->m_member->member_group_by_member_group();
        $member_new_count   = $this->m_member->member_count_member_new();
        $member_age         = $this->m_member->member_group_by_member_age();

        // 리스트용
        $total_rows         = $this->m_member->member_list_total_count($req_data);
        $result1            = $this->m_member->member_list($req_data);

        # model - 회원그룹 select
        $req_data['member_type']= 1;

	    # model - 회원그룹 select
        $this->load->model('admin/member/m_member_group');
        $result2    = $this->m_member_group->member_group_all_list($req_data);



        $arr_member_gender = array();
        foreach($member_gender as $val) {
            $arr_member_gender[$val['member_gender']] = $val['cnt'];
        }

        $arr_member_group = array();
        foreach($member_group as $val) {
            $arr_member_group[$val['member_group_idx']] = $val['cnt'];
        }

        $arr_member_age = array();
        foreach($member_age as $val) {
            $arr_member_age[$val['member_age']] = $val['cnt'];
        }

        # pagination
        $req_data = array();
        $req_data['total_count']    = $total_count;
        $req_data['limit']          = $limit;
        $req_data['base_url']       =  '/admin/member/member_list/4' ;
        $req_data['suffix']         = '?'.$_SERVER['QUERY_STRING'];

        $this->load->library('comm_admin');
        $pagination = $this->comm_admin->fn_pagination($req_data);



        # view data
		$return_data['pagination']	        = $pagination;
        $return_data['page']                = $page;
        $return_data['limit']               = $limit;
        $return_data['total_count']         = $total_count;
        $return_data['arr_member_gender']   = $arr_member_gender;
        $return_data['arr_member_group']    = $arr_member_group;
        $return_data['member_new_count']    = $member_new_count;
        $return_data['arr_member_age']      = $arr_member_age;
        $return_data['total_rows']          = $total_rows;
        $return_data['search_type']         = $search_type;
        $return_data['search_keyword']      = $search_keyword;
        $return_data['search_member_group'] = $search_member_group;
        $return_data['search_member_gender']= $search_member_gender;
        $return_data['search_member_age']   = $search_member_age;
        $return_data['search_member_new']   = $search_member_new;
        $return_data['list']                = $result1;
        $return_data['group_list']          = $result2;


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

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 일반회원관리 > 회원수정
    # CREATE  :	2018-02-21
    #---------------------------------------------------------------------------
	function fn_member_edit() {
        # request
	    $member_idx             = trim($this->input->get_post('member_idx', TRUE));   //  idx
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_member_group    = trim($this->input->get_post('search_member_group', TRUE));
        $search_member_gender   = trim($this->input->get_post('search_member_gender', TRUE));
        $search_member_age      = trim($this->input->get_post('search_member_age', TRUE));
        $search_member_new      = trim($this->input->get_post('search_member_new', TRUE));

        # model - 회원 select
        $this->load->model('admin/member/m_member');
        $result1    = $this->m_member->member_select($member_idx);

        # model - 회원그룹 select
        $req_data['member_type'] = 1;   // 일반회원
        $this->load->model('admin/member/m_member_group');
        $result2    = $this->m_member_group->member_group_all_list($req_data);


        # model - 회원가입 셋팅
        $this->load->model('admin/member/m_member_setting');
        $result3    = $this->m_member_setting->m_member_setting_list();


        if(count($result1) == 0){
            gf_alert("잘못된 접근입니다.", '/admin/main');
            exit;
        }
        $return_data['result']              = $result1[0];
        $return_data['group_list']          = $result2;
        $return_data['page']                = $page;
        $return_data['search_type']         = $search_type;
        $return_data['search_keyword']      = $search_keyword;
        $return_data['search_member_group'] = $search_member_group;
        $return_data['search_member_gender']= $search_member_gender;
        $return_data['search_member_age']   = $search_member_age;
        $return_data['search_member_new']   = $search_member_new;
        $return_data['member_setting_list'] = $result3;

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

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 일반회원관리 > 회원수정 저장
    # CREATE  :	2018-02-21
    #---------------------------------------------------------------------------
	function fn_member_edit_proc() {
        # request
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_member_group    = trim($this->input->get_post('search_member_group', TRUE));
        $search_member_gender   = trim($this->input->get_post('search_member_gender', TRUE));
        $search_member_age      = trim($this->input->get_post('search_member_age', TRUE));
        $search_member_new      = trim($this->input->get_post('search_member_new', TRUE));

        $member_idx             = trim($this->input->get_post('member_idx', TRUE));   //  idx
        $member_email1          = trim($this->input->get_post('member_email1', TRUE));
        $member_email2          = trim($this->input->get_post('member_email2', TRUE));
        $member_birth1          = trim($this->input->get_post('member_birth1', TRUE));
        $member_birth2          = trim($this->input->get_post('member_birth2', TRUE));
        $member_birth3          = trim($this->input->get_post('member_birth3', TRUE));
        $member_calendar        = trim($this->input->get_post('member_calendar', TRUE));
        $member_gender          = trim($this->input->get_post('member_gender', TRUE));
        $member_church          = trim($this->input->get_post('member_church', TRUE));
        $member_dong            = trim($this->input->get_post('member_dong', TRUE));
        $member_pastor          = trim($this->input->get_post('member_pastor', TRUE));
        $member_group_idx       = trim($this->input->get_post('member_group_idx', TRUE));
        $is_agree_sms           = trim($this->input->get_post('is_agree_sms', TRUE));
        $is_agree_mail          = trim($this->input->get_post('is_agree_mail', TRUE));
        $is_agree_info_open     = trim($this->input->get_post('is_agree_info_open', TRUE));
        $is_del_member_img      = trim($this->input->get_post('is_del_member_img', TRUE));
        $org_member_img         = trim($this->input->get_post('org_member_img', TRUE));

        $member_email   = $member_email1.'@'.$member_email2;
        $member_birth   = $member_birth1.'-'.$member_birth2.'-'.$member_birth3;

        if($is_agree_sms!='Y')          $is_agree_sms = 'N';
        if($is_agree_mail!='Y')         $is_agree_mail = 'N';
        if($is_agree_info_open!='Y')    $is_agree_info_open = 'N';

        $now_year = date("Y");
        $member_age = floor((($now_year+1)-$member_birth1)/10)*10;

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

        # 이미지업로드
        if($_FILES['member_img']['name']!='') {
             # image upload
            $upload_path = './files/profile/'.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('member_img')) {
                $error = array('error' => $this->upload->display_errors());
                gf_alert("이미지 업로드에 실패했습니다.", 'back');
                exit;
            }
            $arr_upload_data = $this->upload->data();
            $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '', $arr_upload_data['full_path']);

        } else {
            $filename = $org_member_img;
        }


        # update data
        $req_data['idx']                = $member_idx;
        $req_data['member_email']       = $member_email;
        $req_data['member_age']         = $member_age;
        $req_data['member_birth']       = $member_birth;
        $req_data['member_calendar']    = $member_calendar;
        $req_data['member_gender']      = $member_gender;
        $req_data['member_group_idx']   = $member_group_idx;
        $req_data['member_church']      = $member_church;
        $req_data['member_dong']        = $member_dong;
        $req_data['member_pastor']      = $member_pastor;
        $req_data['is_agree_sms']       = $is_agree_sms;
        $req_data['is_agree_mail']      = $is_agree_mail;
        $req_data['is_agree_info_open'] = $is_agree_info_open;
        $req_data['member_img']         = $filename;

        # model
        $this->load->model('admin/member/m_member');
        $return_data    = $this->m_member->member_update($req_data);
        if(!$return_data) {
            gf_alert("회원수정에 실패했습니다.", 'back');
            exit;
        }

        gf_alert("저장되었습니다.", '/admin/member/member_list/4/'.$page.'?search_type='.$search_type.'&search_keyword='.$search_keyword.'&search_member_group='.$search_member_group.'&search_member_gender='.$search_member_gender.'&search_member_age='.$search_member_age.'&search_member_new='.$search_member_new);
    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 일반회원관리 > 탈퇴 처리
    # CREATE  :	2018-02-21
    #---------------------------------------------------------------------------
	function fn_member_del_proc() {
        # request
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_member_group    = trim($this->input->get_post('search_member_group', TRUE));
        $search_member_gender   = trim($this->input->get_post('search_member_gender', TRUE));
        $search_member_age      = trim($this->input->get_post('search_member_age', TRUE));
        $search_member_new      = trim($this->input->get_post('search_member_new', TRUE));

        $member_idx             = trim($this->input->get_post('member_idx', TRUE));   //  idx

        # model - update
        $this->load->model('admin/member/m_member');
        $this->m_member->member_member_status_update($member_idx);

        gf_alert("탈퇴처리되었습니다.", '/admin/member/member_list/4/'.$page.'?search_type='.$search_type.'&search_keyword='.$search_keyword.'&search_member_group='.$search_member_group.'&search_member_gender='.$search_member_gender.'&search_member_age='.$search_member_age.'&search_member_new='.$search_member_new);

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 일반회원관리 > 모든글 삭제
    # CREATE  :	2018-02-21
    #---------------------------------------------------------------------------
	function fn_member_comment_all_del_proc() {
        # request
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_member_group    = trim($this->input->get_post('search_member_group', TRUE));
        $search_member_gender   = trim($this->input->get_post('search_member_gender', TRUE));
        $search_member_age      = trim($this->input->get_post('search_member_age', TRUE));
        $search_member_new      = trim($this->input->get_post('search_member_new', TRUE));

        $member_id              = trim($this->input->get_post('member_id', TRUE));   //  idx
        
        # 삭제문구 가져오기
        $this->load->model('admin/setting/m_comment_setting');
        $result = $this->m_comment_setting->comment_setting_list();

        $arr_comment_setting = array();
        foreach($result as $val) {
            $arr_comment_setting[$val['setting_type']] = $val['block_del_conent'];
        }

        $req_data = array();
        $req_data['write_id']       = $member_id;
        $req_data['comment_status'] = '6';  // 관리자삭제

        # news comment 삭제
        $req_data['content_type']   = DEF_NEWS_CODE;
        $req_data['comment']        = $arr_comment_setting[1];
        $this->load->model('admin/comm/m_comment');
        $this->m_comment->comment_is_del_where_write_id_update($req_data);

        # column comment 삭제
        $req_data['content_type']   = DEF_COLUMN_CODE;
        $req_data['comment']        = $arr_comment_setting[2];
        $this->m_comment->comment_is_del_where_write_id_update($req_data);

        # life comment 삭제
        $req_data['content_type']   = DEF_LIFE_CODE;
        $req_data['comment']        = $arr_comment_setting[3];
        $this->m_comment->comment_is_del_where_write_id_update($req_data);

        gf_alert("삭제되었습니다..", '/admin/member/member_list/4/'.$page.'?search_type='.$search_type.'&search_keyword='.$search_keyword.'&search_member_group='.$search_member_group.'&search_member_gender='.$search_member_gender.'&search_member_age='.$search_member_age.'&search_member_new='.$search_member_new);

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 파트너리스트
    # CREATE  :	2018-02-21
    #---------------------------------------------------------------------------
	function fn_popup_member_comment_list() {
        # request
	    $page                 = $this->uri->segment(5);
        $member_id            = trim($this->input->get_post('member_id', TRUE));

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

        # 검색
        $req_data['offset']                 = $offset;
        $req_data['limit']                  = $limit;
        $req_data['write_id']               = $member_id;

        # comment
        $this->load->model('admin/comm/m_comment');
        $result         = $this->m_comment->comment_where_write_id_list($req_data);
        $total_count    = $this->m_comment->comment_where_write_id_list_total_count($req_data);

        # pagination
        $req_data = array();
        $req_data['total_count']    = $total_count;
        $req_data['limit']          = $limit;
        $req_data['base_url']       =  '/admin/member/member_comment_list/4' ;
        $req_data['suffix']         = '?'.$_SERVER['QUERY_STRING'];

        $this->load->library('comm_admin');
        $pagination = $this->comm_admin->fn_pagination($req_data);


        # view data
		$return_data['pagination']	        = $pagination;
        $return_data['page']                = $page;
        $return_data['limit']               = $limit;
        $return_data['total_count']         = $total_count;
        $return_data['list']                = $result;
        # view
        return $this->load->view('/admin/member/member_comment_list', $return_data, true);

    }




    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 에디터
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_editor_list() {
        # request
	    $page                   = $this->uri->segment(5);
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_category_code1  = trim($this->input->get_post('search_category_code1', TRUE));
        $search_category_code2  = trim($this->input->get_post('search_category_code2', TRUE));
        $sort                   = trim($this->input->get_post('sort', TRUE));
        $member_group_idx       = 6;


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

        # 관리자만 가능
        $admin_type = $this->session->userdata('Adm_Type');
        if($admin_type != '0') {
            gf_alert("잘못된 접근입니다.", '/admin/main');
            exit;
        }

        if($sort=='')   $sort ='1';
        switch ($sort) {
            case '1': $sort_column = 'reg_date'; break;
            case '2': $sort_column = 'article_count'; break;
            default : $sort_column = 'reg_date'; break;
        }

        # 검색
        $req_data['search_type']            = $search_type;
        $req_data['search_keyword']         = addslashes($search_keyword);
        $req_data['search_category_code1']  = $search_category_code1;
        $req_data['search_category_code2']  = $search_category_code2;
        $req_data['member_group_idx']       = $member_group_idx;
        $req_data['sort_column']            = $sort_column;
        $req_data['offset']                 = $offset;
        $req_data['limit']                  = $limit;

	    # model - 회원 select
        $this->load->model('admin/member/m_partner');

        // 리스트용
        $total_count            = $this->m_partner->partner_list_total_count($req_data);
        $list                   = $this->m_partner->partner_list($req_data);


        # 카테고리 리스트
        $this->load->model('admin/life/m_life_category');
        $arr_category1   = $this->m_life_category->category_all_list();

        # 카테고리 리스트
        $this->load->model('admin/life/m_life_channel');
        $arr_category2   = $this->m_life_channel->channel_all_list();

        # pagination
        $req_data = array();
        $req_data['total_count']    = $total_count;
        $req_data['limit']          = $limit;
        $req_data['base_url']       =  '/admin/member/editor_list/4' ;
        $req_data['suffix']         = '?'.$_SERVER['QUERY_STRING'];

        $this->load->library('comm_admin');
        $pagination = $this->comm_admin->fn_pagination($req_data);


        # view data
		$return_data['pagination']	            = $pagination;
        $return_data['page']                    = $page;
        $return_data['limit']                   = $limit;
        $return_data['total_count']             = $total_count;
        $return_data['search_type']             = $search_type;
        $return_data['search_keyword']          = $search_keyword;
        $return_data['search_category_code1']   = $search_category_code1;
        $return_data['search_category_code2']   = $search_category_code2;
        $return_data['member_group_idx']        = $member_group_idx;
        $return_data['list']                    = $list;
        $return_data['arr_category1']           = $arr_category1;
        $return_data['arr_category2']           = $arr_category2;
        $return_data['sort']                    = $sort;


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

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 에디터
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_editor_reg() {
        # request
        $mode                   = trim($this->input->get_post('mode', TRUE));
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_channel         = trim($this->input->get_post('search_channel', TRUE));
        $idx                    = trim($this->input->get_post('idx', TRUE));
        $sort                   = trim($this->input->get_post('sort', TRUE));

        # 에디터일경우
        $admin_type = $this->session->userdata('Adm_Type');
        $admin_idx = $this->session->userdata('Adm_Idx');
        if($admin_type == '1') {
            $mode = 'edit';
            $idx = $admin_idx;
        }


        # model - 카테고리
        $this->load->model('admin/life/m_life_category');
        $arr_category   = $this->m_life_category->category_all_list();

        # model - 채널
        $this->load->model('admin/life/m_life_channel');
        $arr_channel   = $this->m_life_channel->channel_all_list();


	    if($mode == 'edit') {
            $req_data = array();
            $req_data['idx']    = $idx;

	        # model
            $this->load->model('admin/member/m_partner');
            $result = $this->m_partner->partner_select($idx);
            if(!$result){
                gf_alert("잘못된 접근입니다.", '/admin/main');
                exit;
            }
            $return_data['result'] = $result[0];

        }

        # 에디터일경우
        if($admin_type == '1') {
            # 카테고리 리스트
            $category_idx = $result[0]['category_idx'];
            $arr_category   = $this->m_life_category->category_select($category_idx);

            # 채널 리스트
            $channel_idx    = $result[0]['channel_idx'];
            $arr_channel   = $this->m_life_channel->channel_select($channel_idx);
        }

        $return_data['mode']                    = $mode;
        $return_data['page']                    = $page;
        $return_data['search_type']             = $search_type;
        $return_data['search_keyword']          = $search_keyword;
        $return_data['search_channel']          = $search_channel;
        $return_data['arr_category']            = $arr_category;
        $return_data['arr_channel']             = $arr_channel;
        $return_data['idx']                     = $idx;
        $return_data['sort']                    = $sort;

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



    }

    #---------------------------------------------------------------------------
    # PURPOSE :	파트너 아이디체크
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_ajax_partner_id_check_proc() {
        # request
        $partner_id             = trim($this->input->get_post('partner_id', TRUE));

        # 어드민 체크
        $this->load->model('admin/admin_member/m_admin_member');
        $admin_count   = $this->m_admin_member->admin_where_partner_id_count($partner_id);

        # partner 체크
        $this->load->model('admin/member/m_partner');
        $partner_count   = $this->m_partner->partner_where_partner_id_count($partner_id);

        $total_count = $admin_count + $partner_count;
        if($total_count == 0) {
            $return_data['result'] = array('result_code' => '0000');
        } else {
            $return_data['result'] = array('result_code' => '9999');
        }

        # view
        return $this->load->view('/admin/comm/result_json', $return_data);


    }



    #---------------------------------------------------------------------------
    # PURPOSE :	에디터 저장
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_editor_reg_proc() {
        # request
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $search_channel         = trim($this->input->get_post('search_channel', TRUE));
        $mode                   = trim($this->input->get_post('mode', TRUE));
        $sort                   = trim($this->input->get_post('sort', TRUE));

        $idx                    = trim($this->input->get_post('idx', TRUE));
        $partner_name           = trim($this->input->get_post('partner_name', TRUE));
        $partner_id             = trim($this->input->get_post('partner_id', TRUE));
        $partner_pwd            = trim($this->input->get_post('partner_pwd', TRUE));
        $partner_gender         = trim($this->input->get_post('partner_gender', TRUE));
        $partner_mobile1        = trim($this->input->get_post('partner_mobile1', TRUE));
        $partner_mobile2        = trim($this->input->get_post('partner_mobile2', TRUE));
        $partner_mobile3        = trim($this->input->get_post('partner_mobile3', TRUE));
        $sns_id1                = trim($this->input->get_post('sns_id1', TRUE));
        $sns_id2                = trim($this->input->get_post('sns_id2', TRUE));
        $sns_id3                = trim($this->input->get_post('sns_id3', TRUE));
        $sns_id4                = trim($this->input->get_post('sns_id4', TRUE));
        $sns_id5                = trim($this->input->get_post('sns_id5', TRUE));
        $partner_intro          = trim($this->input->get_post('partner_intro', TRUE));
        $partner_real_name      = trim($this->input->get_post('partner_real_name', TRUE));
        $category_idx           = trim($this->input->get_post('category_idx', TRUE));
        $channel_idx            = trim($this->input->get_post('channel_idx', TRUE));
        $display_sort           = trim($this->input->get_post('display_sort', TRUE));
        $partner_email1         = trim($this->input->get_post('partner_email1', TRUE));
        $partner_email2         = trim($this->input->get_post('partner_email2', TRUE));

        $is_del_img             = trim($this->input->get_post('is_del_partner_img', TRUE));
        $org_partner_img        = trim($this->input->get_post('org_partner_img', TRUE));

        $is_del_main_img        = trim($this->input->get_post('is_del_main_img', TRUE));
        $org_main_img           = trim($this->input->get_post('org_main_img', TRUE));
        $member_group_idx       = 6;

        if($mode == '') $mode = 'add';
        if($mode=='add') {
            # 어드민 체크
            $this->load->model('admin/admin_member/m_admin_member');
            $admin_count = $this->m_admin_member->admin_where_partner_id_count($partner_id);

            # partner 체크
            $this->load->model('admin/member/m_partner');
            $partner_count = $this->m_partner->partner_where_partner_id_count($partner_id);

            $total_count = $admin_count + $partner_count;
            if ($total_count > 0) {
                gf_alert("사용할수 없는 아이디입니다.", 'back');
                exit;
            }
        }

        if($sns_id1!='') {
            $sns_id1 = str_replace('https://', '', $sns_id1);
            $sns_id1 = str_replace('http://', '', $sns_id1);
            $sns_id1 = str_replace('www.facebook.com/', '', $sns_id1);
        }
        if($sns_id2!='') {
            $sns_id2 = str_replace('https://', '', $sns_id2);
            $sns_id2 = str_replace('http://', '', $sns_id2);
            $sns_id2 = str_replace('instagram.com/', '', $sns_id2);
        }
        if($sns_id3!='') {
            $sns_id3 = str_replace('https://', '', $sns_id3);
            $sns_id3 = str_replace('http://', '', $sns_id3);
            $sns_id3 = str_replace('band.us/band/', '', $sns_id3);
        }
        if($sns_id4!='') {
            $sns_id4 = str_replace('https://', '', $sns_id4);
            $sns_id4 = str_replace('http://', '', $sns_id4);
            $sns_id4 = str_replace('story.kakao.com/ch/', '', $sns_id4);
        }
        if($sns_id5!='') {
            $sns_id5 = str_replace('https://', '', $sns_id5);
            $sns_id5 = str_replace('http://', '', $sns_id5);
            $sns_id5 = str_replace('story.kakao.com/', '', $sns_id5);
        }

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

        # 이미지업로드
        if($_FILES['partner_img']['name']!='') {
             # image upload
            $upload_path = './files/partner/'.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('partner_img')) {
                $error = array('error' => $this->upload->display_errors());
                gf_alert("이미지 업로드에 실패했습니다.", 'back');
                exit;
            }
            $arr_upload_data = $this->upload->data();
            $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '', $arr_upload_data['full_path']);

        } else {
            $filename = $org_partner_img;
        }


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


        # 이미지업로드
        if($_FILES['main_img']['name']!='') {
             # image upload
            $upload_path = './files/editor/'.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('main_img')) {
                $error = array('error' => $this->upload->display_errors());
                gf_alert("이미지 업로드에 실패했습니다.", 'back');
                exit;
            }
            $arr_upload_data = $this->upload->data();
            $filename2 = str_replace($_SERVER['DOCUMENT_ROOT'], '', $arr_upload_data['full_path']);

        } else {
            $filename2 = $org_main_img;
        }

        $partner_mobile = $partner_mobile1.'-'.$partner_mobile2.'-'.$partner_mobile3;
        $partner_email  = $partner_email1.'@'.$partner_email2;


        # req data
        $req_data = array();
        $req_data['partner_name']       = $partner_name;
        $req_data['partner_id']         = $partner_id;
        $req_data['partner_pwd']        = MD5($partner_pwd);
        $req_data['partner_gender']     = $partner_gender;
        $req_data['partner_mobile']     = $partner_mobile;
        $req_data['sns_id1']            = $sns_id1;
        $req_data['sns_id2']            = $sns_id2;
        $req_data['sns_id3']            = $sns_id3;
        $req_data['sns_id4']            = $sns_id4;
        $req_data['sns_id5']            = $sns_id5;
        $req_data['partner_intro']      = $partner_intro;
        $req_data['partner_real_name']  = $partner_real_name;
        $req_data['category_idx']       = $category_idx;
        $req_data['channel_idx']        = $channel_idx;
        $req_data['display_sort']       = $display_sort;
        $req_data['partner_email']      = $partner_email;
        $req_data['member_group_idx']   = $member_group_idx;
        $req_data['partner_img']        = $filename;
        $req_data['main_img']           = $filename2;

        if($mode=='add') {
            # model
            $this->load->model('admin/member/m_partner');
            $result = $this->m_partner->partner_insert($req_data);
            if(!$result) {
                gf_alert("에디터등록에 실패했습니다.", 'back');
                exit;
            }

            $url = '/admin/member/editor_list/4';

        } else if($mode=='edit') {

            $req_data['idx']     = $idx;

            # model
            $this->load->model('admin/member/m_partner');
            $result = $this->m_partner->partner_update($req_data);

            if(!$result) {
                gf_alert("에디터수정에 실패했습니다.", 'back');
                exit;
            }

            # 에디터일경우
            $admin_type = $this->session->userdata('Adm_Type');
            if($admin_type == '1') {
                $url = '/admin/member/editor_reg/4';
            } else {
                $url = '/admin/member/editor_list/4/'.$page.'?search_type='.$search_type.'&search_keyword='.$search_keyword.'&search_channel='.$search_channel.'&sort='.$sort;
            }

        }

        gf_alert("저장되었습니다.", $url);



    }




    #---------------------------------------------------------------------------
    # PURPOSE :	파트너 삭제
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_partner_del_proc() {
        # request
        $idx                    = trim($this->input->get_post('idx', TRUE));
        $member_group_idx       = trim($this->input->get_post('member_group_idx', TRUE));

        # model
        $this->load->model('admin/member/m_partner');

        // 이미지 삭제
        $result1 = $this->m_partner->partner_select($idx);
        if(count($result1) > 0){
            if($result1[0]['partner_img']!=''){
                unlink('.'.$result1[0]['partner_img']);
            }
            if($result1[0]['main_img']!=''){
                unlink('.'.$result1[0]['main_img']);
            }
        }
        $req_date[] = $idx;

        # model - update
        $this->m_partner->partner_is_del_update($req_date);


        if($member_group_idx=='6') {
            $url='/admin/member/editor_list/4';
        } else {
            $url='/admin/member/columnist_list/4';
        }
        gf_alert("삭제되었습니다.", $url);

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	파트너 - 삭제 (다중)
    # CREATE  :	2018-03-06
    #---------------------------------------------------------------------------
	function fn_partner_del_arr_del_proc() {
        # request
        $arr_idx                = $this->input->get_post('is_del', TRUE);   // 삭제할 idx
        $member_group_idx       = trim($this->input->get_post('member_group_idx', TRUE));

        # model
        $this->load->model('admin/member/m_partner');

        // 이미지 삭제
        $result1 = $this->m_partner->partner_select_in_idx($arr_idx);
        if(count($result1) > 0){
            foreach ($result1 as $val) {
                if($val['partner_img']!=''){
                    unlink('.'.$val['partner_img']);
                }
            }
        }

        # model - update
        $this->m_partner->partner_is_del_update($arr_idx);

        if($member_group_idx=='6') {
            $url='/admin/member/editor_list/4';
        } else {
            $url='/admin/member/columnist_list/4';
        }
        gf_alert("삭제되었습니다.", $url);

    }




    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 칼럼리스트
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_columnist_list() {
        # request
	    $page                   = $this->uri->segment(5);
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $sort                   = trim($this->input->get_post('sort', TRUE));
        $member_group_idx       = 7;

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

        # 관리자만 가능
        $admin_type = $this->session->userdata('Adm_Type');
        if($admin_type != '0') {
            gf_alert("잘못된 접근입니다.", '/admin/main');
            exit;
        }


        if($sort=='')   $sort ='1';
        switch ($sort) {
            case '1': $sort_column = 'reg_date'; break;
            case '2': $sort_column = 'article_count'; break;
            default : $sort_column = 'reg_date'; break;
        }

        # 검색
        $req_data['search_type']            = $search_type;
        $req_data['search_keyword']         = addslashes($search_keyword);
        $req_data['member_group_idx']       = $member_group_idx;
        $req_data['search_channel']         = '';
        $req_data['sort_column']            = $sort_column;
        $req_data['offset']                 = $offset;
        $req_data['limit']                  = $limit;

	    # model - 회원 select
        $this->load->model('admin/member/m_partner');

        // 리스트용
        $total_count            = $this->m_partner->partner_list_total_count($req_data);
        $list                   = $this->m_partner->partner_list($req_data);

        # pagination
        $req_data = array();
        $req_data['total_count']    = $total_count;
        $req_data['limit']          = $limit;
        $req_data['base_url']       =  '/admin/member/columnist_list/4' ;
        $req_data['suffix']         = '?'.$_SERVER['QUERY_STRING'];

        $this->load->library('comm_admin');
        $pagination = $this->comm_admin->fn_pagination($req_data);



        # view data
		$return_data['pagination']	        = $pagination;
        $return_data['page']                = $page;
        $return_data['limit']               = $limit;
        $return_data['total_count']         = $total_count;
        $return_data['search_type']         = $search_type;
        $return_data['search_keyword']      = $search_keyword;
        $return_data['member_group_idx']    = $member_group_idx;
        $return_data['sort']                = $sort;
        $return_data['list']                = $list;


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

    }

    #---------------------------------------------------------------------------
    # PURPOSE :	회원관리 > 칼럼니스트
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_columnist_reg() {
        # request
        $mode                   = trim($this->input->get_post('mode', TRUE));
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $sort                   = trim($this->input->get_post('sort', TRUE));
        $idx                    = trim($this->input->get_post('idx', TRUE));


        # 에디터일경우
        $admin_type = $this->session->userdata('Adm_Type');
        $admin_idx = $this->session->userdata('Adm_Idx');
        if($admin_type == '2') {
            $mode = 'edit';
            $idx = $admin_idx;
        }


	    if($mode == 'edit') {

            $req_data = array();
            $req_data['idx']    = $idx;

	        # model
            $this->load->model('admin/member/m_partner');
            $result = $this->m_partner->partner_select($idx);
            $return_data['result'] = $result[0];

        }

        $return_data['mode']                    = $mode;
        $return_data['page']                    = $page;
        $return_data['search_type']             = $search_type;
        $return_data['search_keyword']          = $search_keyword;
        $return_data['sort']                    = $sort;
        $return_data['idx']                     = $idx;

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

    }


    #---------------------------------------------------------------------------
    # PURPOSE :	에디터 저장
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_columnist_reg_proc() {
        # request
        $page                   = trim($this->input->get_post('page', TRUE));
        $search_type            = trim($this->input->get_post('search_type', TRUE));
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $mode                   = trim($this->input->get_post('mode', TRUE));
        $sort                   = trim($this->input->get_post('sort', TRUE));

        $idx                    = trim($this->input->get_post('idx', TRUE));
        $partner_name           = trim($this->input->get_post('partner_name', TRUE));
        $partner_id             = trim($this->input->get_post('partner_id', TRUE));
        $partner_pwd            = trim($this->input->get_post('partner_pwd', TRUE));
        $partner_gender         = trim($this->input->get_post('partner_gender', TRUE));
        $partner_mobile1        = trim($this->input->get_post('partner_mobile1', TRUE));
        $partner_mobile2        = trim($this->input->get_post('partner_mobile2', TRUE));
        $partner_mobile3        = trim($this->input->get_post('partner_mobile3', TRUE));
        $partner_real_name      = trim($this->input->get_post('partner_real_name', TRUE));
        $partner_email1         = trim($this->input->get_post('partner_email1', TRUE));
        $partner_email2         = trim($this->input->get_post('partner_email2', TRUE));
        $display_sort           = trim($this->input->get_post('display_sort', TRUE));

        $is_del_img             = trim($this->input->get_post('is_del_partner_img', TRUE));
        $org_main_img           = trim($this->input->get_post('org_partner_img', TRUE));
        $member_group_idx       = 7;

        if($mode=='add') {
            # 어드민 체크
            $this->load->model('admin/admin_member/m_admin_member');
            $admin_count = $this->m_admin_member->admin_where_partner_id_count($partner_id);

            # partner 체크
            $this->load->model('admin/member/m_partner');
            $partner_count = $this->m_partner->partner_where_partner_id_count($partner_id);

            $total_count = $admin_count + $partner_count;
            if ($total_count > 0) {
                gf_alert("사용할수 없는 아이디입니다.", 'back');
                exit;
            }
        }

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

        # 이미지업로드
        if($_FILES['partner_img']['name']!='') {
             # image upload
            $upload_path = './files/partner/'.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('partner_img')) {
                $error = array('error' => $this->upload->display_errors());
                gf_alert("이미지 업로드에 실패했습니다.", 'back');
                exit;
            }
            $arr_upload_data = $this->upload->data();
            $filename = str_replace($_SERVER['DOCUMENT_ROOT'], '', $arr_upload_data['full_path']);

        } else {
            $filename = $org_main_img;
        }


        $partner_mobile = $partner_mobile1.'-'.$partner_mobile2.'-'.$partner_mobile3;
        $partner_email  = $partner_email1.'@'.$partner_email2;


        # req data
        $req_data = array();
        $req_data['partner_name']       = $partner_name;
        $req_data['partner_id']         = $partner_id;
        $req_data['partner_pwd']        = $partner_pwd;
        $req_data['partner_gender']     = $partner_gender;
        $req_data['partner_mobile']     = $partner_mobile;
        $req_data['sns_id1']            = '';
        $req_data['sns_id2']            = '';
        $req_data['partner_intro']      = '';
        $req_data['partner_real_name']  = $partner_real_name;
        $req_data['category_idx']       = '';
        $req_data['channel_idx']        = '';
        $req_data['display_sort']       = '';
        $req_data['partner_email']      = $partner_email;
        $req_data['member_group_idx']   = $member_group_idx;
        $req_data['partner_img']        = $filename;
        $req_data['display_sort']       = $display_sort;

        if($mode=='add') {
            # model
            $this->load->model('admin/member/m_partner');
            $result = $this->m_partner->partner_insert($req_data);
            if(!$result) {
                gf_alert("칼럼리스트등록에 실패했습니다.", 'back');
                exit;
            }

            $url = '/admin/member/columnist_list/4';

        } else if($mode=='edit') {

            $req_data['idx']     = $idx;

            # model
            $this->load->model('admin/member/m_partner');
            $result = $this->m_partner->partner_update($req_data);

            if(!$result) {
                gf_alert("칼럼리스트수정에 실패했습니다.", 'back');
                exit;
            }


            # 에디터일경우
            $admin_type = $this->session->userdata('Adm_Type');
            if($admin_type == '2') {
                $url = '/admin/member/columnist_reg/4';
            } else {
                $url = '/admin/member/columnist_list/4/'.$page.'?search_type='.$search_type.'&search_keyword='.$search_keyword.'&sort='.$sort;
            }



        }



        gf_alert("저장되었습니다.", $url);
    }


    #---------------------------------------------------------------------------
    # PURPOSE :	파트너글 모두 지우기
    # CREATE  :	2018-03-14
    #---------------------------------------------------------------------------
	function fn_partner_article_del_proc() {
        # request
        $partner_idx            = trim($this->input->get_post('idx', TRUE));
        $member_group_idx       = trim($this->input->get_post('member_group_idx', TRUE));

        if($member_group_idx=='6') {
            # model
            $this->load->model('admin/life/m_life');
            $this->m_life->life_is_del_where_partner_idx_update($partner_idx);

            $url='/admin/member/editor_list/4';
        } else {
            # model
            $this->load->model('admin/column/m_column');
            $this->m_column->column_is_del_where_partner_idx_update($partner_idx);

            $url='/admin/member/columnist_list/4';
        }
        gf_alert("삭제되었습니다.", $url);

    }

}