<?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/web/cm_controller.php');
class life extends cm_Controller {


    #---------------------------------------------------------------------------
    # PURPOSE : 메인
    # CREATE  :	2018-04-10
    #---------------------------------------------------------------------------
	function fn_index() {
        $this->load->library('user_agent');
        if ($this->agent->is_mobile()){
            $this->load->helper('url');
            redirect($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/m/life/', 'refresh');
        }

        # Request
        $search_date    = trim($this->input->get_post('search_date', TRUE));
        $search_sort    = trim($this->input->get_post('search_sort', TRUE));
        $popular_page   = trim($this->input->get_post('popular_page', TRUE));
        $search_popular = trim($this->input->get_post('search_popular', TRUE));

        # default setting
        if($search_sort == '')  $search_sort = '1';
        if($search_date=='')    $search_date = date('Y-m');
        if($search_popular=='') $search_popular = '1';


        # 해당월의 마지막 날짜
        $end_day = date("t", strtotime($search_date));
        $start_date = $search_date.'-01';
        $end_date   = $search_date.'-'.$end_day;

        # 년월 구하기
        $month      = date('m', strtotime($start_date));
        $month_txt  = date("Y", strtotime($start_date)).'년 '.(int)$month.'월';

        # 이전달
        $prev_date      = date('Y-m', strtotime($start_date." -1 month"));

        # 다음달
        $next_date      = date('Y-m', strtotime($start_date." +1 month"));


        # sort
        switch ($search_sort) {
            case '1': $sort_column = 'display_date'; break;
            case '2': $sort_column = 'popular_count'; break;
            default : $sort_column = 'display_date'; break;
        }

        # paging 설정
        $limit  = 15;
        $offset = 0;

        # 라이프
        $req_data = array();
        $req_data['start_date']         = $start_date;
        $req_data['end_date']           = $end_date;
        $req_data['sort_column']        = $sort_column;
        $req_data['offset']             = $offset;
        $req_data['limit']              = $limit;

        # model - list
        $this->load->model('web/m_life');
        $result         = $this->m_life->life_list($req_data);
        $total_count    = $this->m_life->life_list_total_count($req_data);

        # 인기채널
        # paging 설정
        if($popular_page=='')   $popular_page = '1';
        $popular_limit  = 8;
        $popular_offset     = ($popular_page-1) * $popular_limit;


        $req_data = array();
        $req_data['offset']             = $popular_offset;
        $req_data['limit']              = $popular_limit;
        $req_data['sort_column']        = 'popular_count';

        if($search_popular == 1) {
            # model - channel
            $this->load->model('web/m_channel');
            $arr_popular            = $this->m_channel->channel_list($req_data);
            $popular_total_count    = $this->m_channel->channel_list_total_count();
        } if($search_popular == 2) {

            $req_data['member_group_idx']       = 6;

            # model - editor
            $this->load->model('web/m_partner');
            $arr_popular            = $this->m_partner->partner_list($req_data);
            $popular_total_count    = $this->m_partner->partner_list_total_count($req_data);

        }
        $popular_max_page   = ceil($popular_total_count / $popular_limit);

        # channel_page
        $this->load->helper('crossmap/tool_helper');


        $pagination =  gf_paging($popular_limit, $popular_page, $popular_max_page, '/web/life/?search_date='.$search_date.'&search_sort='.$search_sort.'&search_popular='.$search_popular.'&popular_page=');

        # view data
        $return_data = array();
        $return_data['limit']                       = $limit;
        $return_data['total_count']                 = $total_count;
        $return_data['start_date']                  = $start_date;
        $return_data['end_date']                    = $end_date;
        $return_data['search_date']                 = $search_date; 
        $return_data['search_sort']                 = $search_sort;
        $return_data['search_popular']              = $search_popular;
        $return_data['month_txt']                   = $month_txt;
        $return_data['prev_date']                   = $prev_date;
        $return_data['next_date']                   = $next_date;
        $return_data['list']                        = $result;
        $return_data['arr_popular']                 = $arr_popular;
        $return_data['popular_total_count']         = $popular_total_count;
        $return_data['pagination']	                = $pagination;


        # view
        return $this->load->view('/web/life/index', $return_data, true);


    }



    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 뷰
    # CREATE  :	2018-04-11
    #---------------------------------------------------------------------------
	function fn_life_view() {
        # Request
	    $idx                = $this->uri->segment(4);
        $SES_MEMBER_ID      = $this->session->userdata('C_Member_Id');
        $content_type       = '3';

        $this->load->library('user_agent');
        if ($this->agent->is_mobile()){
            $this->load->helper('url');
            redirect($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/m/life/life_view/'.$idx, 'refresh');
        }
        
        # model - list
        $this->load->model('web/m_life');
        $result         = $this->m_life->life_join_editor_category_channel_select($idx);
        if(count($result)==0) {
            gf_alert("잘못된 접근입니다.", '/web/life');
            exit;
        }
        

        $bookmark_count = 0;
        if($SES_MEMBER_ID !='') {
            # 게시물 열람 불가 체크
            $req_data = array();
            $req_data['member_id']  = $SES_MEMBER_ID;
            $req_data['limit_type'] = '2';

            # model
            $this->load->model('web/m_blind_limit');
            $arr_blind = $this->m_blind_limit->blind_limit_where_member_id_limit_type_select($req_data);
            if(count($arr_blind) > 0) {
                $return_data['arr_blind'] = $arr_blind;
                $return_data['url'] = '/web/life/';

                # view
                return $this->load->view('/web/comm/blind_view_alert', $return_data, true);
            }

            # model - bookmark
            $req_data = array();
            $req_data['member_id']      = $SES_MEMBER_ID;
            $req_data['content_type']   = $content_type;
            $req_data['content_idx']    = $idx;

            $this->load->model('web/m_bookmark');
            $bookmark_count   = $this->m_bookmark->bookmark_member_id_content_idx_count($req_data);

        }

        # hit count update
        $req_data = array();
        $req_data['content_type']   = $content_type;
        $req_data['content_idx']    = $idx;
        $req_data['member_id']      = $SES_MEMBER_ID;

        $this->load->library('comm');
        $this->comm->fn_hit_count_update($req_data);


        # 이전글
        $arr_prev   = $this->m_life->life_prev_select($idx);

        # 이후글
        $arr_next   = $this->m_life->life_next_select($idx);
        


        # view data
        $return_data = array();
        $return_data['idx']                     = $idx;
        $return_data['arr_prev']                = $arr_prev;
        $return_data['arr_next']                = $arr_next;
        $return_data['bookmark_count']          = $bookmark_count;
        $return_data['result']                  = $result;

        $this->load->library('user_agent');
        if ($this->agent->is_mobile()){
            return $this->load->view('/m/life/life_view', $return_data, true);
        }else{
            # view
            return $this->load->view('/web/life/life_view', $return_data, true);
        }
    }

    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 뷰
    # CREATE  : 2018-04-11
    #---------------------------------------------------------------------------
    function fn_life_view2() {
        # Request
        $idx                = $this->uri->segment(4);
        $SES_MEMBER_ID      = $this->session->userdata('C_Member_Id');
        $content_type       = '3';

        # model - list
        $this->load->model('web/m_life');
        $result         = $this->m_life->life_join_editor_category_channel_select($idx);
        if(count($result)==0) {
            gf_alert("잘못된 접근입니다.", '/web/life');
            exit;
        }
        

        $bookmark_count = 0;
        if($SES_MEMBER_ID !='') {
            # 게시물 열람 불가 체크
            $req_data = array();
            $req_data['member_id']  = $SES_MEMBER_ID;
            $req_data['limit_type'] = '2';

            # model
            $this->load->model('web/m_blind_limit');
            $arr_blind = $this->m_blind_limit->blind_limit_where_member_id_limit_type_select($req_data);
            if(count($arr_blind) > 0) {
                $return_data['arr_blind'] = $arr_blind;
                $return_data['url'] = '/web/life/';

                # view
                return $this->load->view('/web/comm/blind_view_alert', $return_data, true);
            }

            # model - bookmark
            $req_data = array();
            $req_data['member_id']      = $SES_MEMBER_ID;
            $req_data['content_type']   = $content_type;
            $req_data['content_idx']    = $idx;

            $this->load->model('web/m_bookmark');
            $bookmark_count   = $this->m_bookmark->bookmark_member_id_content_idx_count($req_data);

        }

        # hit count update
        $req_data = array();
        $req_data['content_type']   = $content_type;
        $req_data['content_idx']    = $idx;
        $req_data['member_id']      = $SES_MEMBER_ID;

        $this->load->library('comm');
        $this->comm->fn_hit_count_update($req_data);


        # 이전글
        $arr_prev   = $this->m_life->life_prev_select($idx);

        # 이후글
        $arr_next   = $this->m_life->life_next_select($idx);
        


        # view data
        $return_data = array();
        $return_data['idx']                     = $idx;
        $return_data['arr_prev']                = $arr_prev;
        $return_data['arr_next']                = $arr_next;
        $return_data['bookmark_count']          = $bookmark_count;
        $return_data['result']                  = $result;

        $this->load->library('user_agent');
        if ($this->agent->is_mobile()){
            $this->load->helper('url');
            redirect($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/m/life/life_view/'.$idx, 'refresh');
        }else{
            # view
            return $this->load->view('/web/life/life_view', $return_data, true);
        }


    }

    #---------------------------------------------------------------------------
    # PURPOSE :	댓글 삭제
    # CREATE  :	2018-05-07
    #---------------------------------------------------------------------------
	function fn_ajax_user_comment_refresh_proc() {
        $ci=& get_instance();
        $ci->load->library('comm');
        
        # request
        $idx            = trim($this->input->get_post('idx', TRUE));
        $write_id       = trim($this->input->get_post('write_id', TRUE));
        $content_type   = trim($this->input->get_post('content_type', TRUE));

        # model

        $req_data = array();
        $req_data['content_type']   = $content_type;
        $req_data['content_idx']    = $idx;
        $req_data['offset']         = 0;
        $req_data['limit']          = 15;
        $req_data['sort_column']    = 'reg_date';
        $req_data['sort_type']      = 'desc';
        $req_data['write_id']       = $write_id;
        
        $arr_comment_result = $ci->comm->fn_comment($req_data);
        
        $comment_my_delete_count    = $arr_comment_result['comment_my_delete_count'];

        if(count($arr_comment_result) == 0) {
            throw new Cm_Exception('json', '9999', '알 수 없는 오류가 발생하였습니다.');
        }

        if($arr_comment_result) {
            $return_data['result'] = array('code' => '0000');
        } else {
            $return_data['result'] = array('code' => '9999');
        }
        
        $return_data['delete_cnt'] = $comment_my_delete_count;

        # view
        echo json_encode($return_data);

    }   


    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 댓글
    # CREATE  :	2018-04-29
    #---------------------------------------------------------------------------
	function fn_life_comment() {
        # Request
	    $idx                   = $this->uri->segment(4);
        $SES_MEMBER_ID          = $this->session->userdata('C_Member_Id');
        $content_type           = '3';

        # model - list
        $this->load->model('web/m_life');
        $result         = $this->m_life->life_join_editor_category_channel_select($idx);
        if(count($result)==0) {
            gf_alert("잘못된 접근입니다.", '/web/life');
            exit;
        }
        

        # 북마크
        $bookmark_count = 0;
        if($SES_MEMBER_ID !='') {
            # model - bookmark
            $req_data = array();
            $req_data['member_id']      = $SES_MEMBER_ID;
            $req_data['content_type']   = $content_type;
            $req_data['content_idx']    = $idx;

            $this->load->model('web/m_bookmark');
            $bookmark_count   = $this->m_bookmark->bookmark_member_id_content_idx_count($req_data);

        }



        # view data
        $return_data = array();
        $return_data['idx']                     = $idx;
        $return_data['bookmark_count']          = $bookmark_count;
        $return_data['result']                  = $result;

        # view
        return $this->load->view('/web/life/life_comment', $return_data, true);


    }



    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 랭킹
    # CREATE  :	2018-04-29
    #---------------------------------------------------------------------------
	function fn_ranking() {
        # Request
        $page           = trim($this->input->get_post('page', TRUE));
        $ranking_type   = trim($this->input->get_post('ranking_type', TRUE));
        $content_type   = 3;

        # default setting
        if($ranking_type == '')     $ranking_type = '1';
        if($page=='')               $page = '1';

        # paging 설정
        $limit  = 10;
        $offset = ($page-1) * $limit;

        $req_data = array();
        $req_data['ranking_type']   = $ranking_type;
        $req_data['content_type']   = $content_type;
        $req_data['offset']         = $offset;
        $req_data['limit']          = $limit;
        $this->load->model('web/m_ranking');
        $result                 = $this->m_ranking->ranking_join_life_list($req_data);
        $total_count            = $this->m_ranking->ranking_join_life_total_count($req_data);

        # page
        $max_page   = ceil($total_count / $limit);
        $pagination =  gf_paging($limit, $page, $max_page, '/web/life/ranking?ranking_type='.$ranking_type.'&page=');


        # right
        $theme_types = array('13', '14');
        $this->load->library('comm');
        $arr_life_right_comm = $this->comm->fn_life_right_comm($theme_types);


        $arr_life_style         = $arr_life_right_comm['arr_life_style'];
        $arr_boomup_life        = $arr_life_right_comm['arr_boomup_life'];
        $arr_life_ranking       = $arr_life_right_comm['arr_life_ranking'];

        if(count($arr_life_style) > 0) {
            array_splice($arr_life_style, 2, count($arr_life_style));
        }
        

        # view data
        $return_data = array();
        $return_data['total_count']                 = $total_count;
        $return_data['list']                        = $result;
        $return_data['arr_life_style']              = $arr_life_style;
        $return_data['arr_boomup_life']             = $arr_boomup_life;
        $return_data['arr_life_ranking']            = $arr_life_ranking;
        $return_data['pagination']	                = $pagination;
        $return_data['ranking_type']	            = $ranking_type;

        # view
        return $this->load->view('/web/life/ranking', $return_data, true);


    }


    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 채널 홈
    # CREATE  :	2018-04-30
    #---------------------------------------------------------------------------
	function fn_channel() {
        # Request
        $search_sort        = trim($this->input->get_post('search_sort', TRUE));
        $idx                = $this->uri->segment(4);
        $SES_MEMBER_ID      = $this->session->userdata('C_Member_Id');
        $content_type       = '3';

        # channel 정보
        $this->load->model('web/m_channel');
        $result = $this->m_channel->channel_join_category_select($idx);
        if(count($result)==0) {
            gf_alert("잘못된 접근입니다.", '/web/life');
            exit;
        }

        if($search_sort == '')  $search_sort = '1';

        # sort
        switch ($search_sort) {
            case '1': $sort_column = 'display_date'; break;
            case '2': $sort_column = 'popular_count'; break;
            default : $sort_column = 'display_date'; break;
        }

        # 배달여부
        $this->load->model('web/m_delivery');
        $channel_delivery_count = 0;
        if($SES_MEMBER_ID != '') {
            $req_data = array();
            $req_data['content_type']   = $content_type;
            $req_data['main_idx']       = $idx;
            $req_data['member_id']      = $SES_MEMBER_ID;

            $arr_column_delivery = $this->m_delivery->delivery_where_member_id_main_idx_select($req_data);
            $channel_delivery_count = count($arr_column_delivery);

        }

        # 채널글
        $req_data = array();
        $req_data['sort_column']        = $sort_column;
        $req_data['offset']             = 0;
        $req_data['limit']              = 15;
        $req_data['search_type']        = 'channel_idx';
        $req_data['search_key']         = $idx;

        # model - list
        $this->load->model('web/m_life');
        $list           = $this->m_life->life_list($req_data);
        $total_count    = $this->m_life->life_list_total_count($req_data);

        # 배달수
        $req_data = array();
        $req_data['content_type']   = $content_type;
        $req_data['main_idx']       = $idx;
        $channel_delivery_total_count = $this->m_delivery->delivery_where_main_idx_count($req_data);


        # view data
        $return_data = array();
        $return_data['idx']                             = $idx;
        $return_data['search_sort']                     = $search_sort;
        $return_data['channel_delivery_count']          = $channel_delivery_count;
        $return_data['result']                          = $result;
        $return_data['list']                            = $list;
        $return_data['total_count']                     = $total_count;
        $return_data['channel_delivery_total_count']    = $channel_delivery_total_count;


        # view
        return $this->load->view('/web/life/channel', $return_data, true);


    }


    #---------------------------------------------------------------------------
    # PURPOSE :	life_list_more
    # CREATE  :	2018-04-30
    #---------------------------------------------------------------------------
	function fn_ajax_life_list_more() {
	    # request
        $sort                   = trim($this->input->get_post('sort', TRUE));
        $page                   = trim($this->input->get_post('page', TRUE));
        $channel_idx            = trim($this->input->get_post('channel_idx', TRUE));
        $partner_idx            = trim($this->input->get_post('partner_idx', TRUE));
        $type                   = trim($this->input->get_post('type', TRUE));
        $start_date             = trim($this->input->get_post('start_date', TRUE));
        $end_date               = trim($this->input->get_post('end_date', TRUE));


        switch ($sort) {
            case '1': $sort_column = 'display_date';    break;
            case '2': $sort_column = 'popular_count';   break;
            default : $sort_column = 'display_date';    break;
        }

        if($type == 'main') {

            $limit  = 15;
            $offset = ($page-1) * $limit;

            # 라이프
            $req_data = array();
            $req_data['start_date']         = $start_date;
            $req_data['end_date']           = $end_date;
            $req_data['sort_column']        = $sort_column;
            $req_data['offset']             = $offset;
            $req_data['limit']              = $limit;


            $view_url  = '/web/life/life_main_list_more';



        } else {
            if($partner_idx!='') {
                $search_type    = 'partner_idx';
                $search_key     = $partner_idx;
                $limit  = 8;
                $offset = ($page-1) * $limit;

                $view_url  = '/web/life/editor_life_list_more';

            } else {
                $search_type    = 'channel_idx';
                $search_key     = $channel_idx;
                $limit  = 15;
                $offset = ($page-1) * $limit;

                $view_url  = '/web/life/life_list_more';

            }
            $req_data = array();
            $req_data['sort_column']        = $sort_column;
            $req_data['offset']             = $offset;
            $req_data['limit']              = $limit;
            $req_data['search_type']        = $search_type;
            $req_data['search_key']         = $search_key;



        }

        # model - list
        $this->load->model('web/m_life');
        $list           = $this->m_life->life_list($req_data);
        $total_count    = $this->m_life->life_list_total_count($req_data);




        $more_list = 'N';
        if(($total_count-($page*$limit)) > 0){
            $more_list = 'Y';
        }

        if(count($list) > 0) {
            $return_data['result_code']         = '0000';
            $return_data['total_count']         = $total_count;
            $return_data['list']                = $list;
            $return_data['more_list']           = $more_list;
            $return_data['page']                = $page;

        } else {
            $return_data['result_code'] = '9999';
        }

        # view
        return $this->load->view($view_url, $return_data);

    }



    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 에디터 홈
    # CREATE  :	2018-04-30
    #---------------------------------------------------------------------------
	function fn_editor() {
        # Request
        $search_sort        = trim($this->input->get_post('search_sort', TRUE));
        $idx                = $this->uri->segment(4);

        # editor 정보
        $this->load->model('web/m_partner');
        $result = $this->m_partner->partner_join_category_channel_select($idx);
        if(count($result)==0) {
            gf_alert("잘못된 접근입니다.", '/web/life');
            exit;
        }

        if($search_sort == '')  $search_sort = '1';

        # sort
        switch ($search_sort) {
            case '1': $sort_column = 'display_date'; break;
            case '2': $sort_column = 'popular_count'; break;
            default : $sort_column = 'display_date'; break;
        }


        # 에디터글
        $req_data = array();
        $req_data['sort_column']        = $sort_column;
        $req_data['offset']             = 0;
        $req_data['limit']              = 8;
        $req_data['search_type']        = 'partner_idx';
        $req_data['search_key']         = $idx;

        # model - list
        $this->load->model('web/m_life');
        $list           = $this->m_life->life_list($req_data);
        $total_count    = $this->m_life->life_list_total_count($req_data);


        # view data
        $return_data = array();
        $return_data['idx']                             = $idx;
        $return_data['search_sort']                     = $search_sort;
        $return_data['result']                          = $result;
        $return_data['list']                            = $list;
        $return_data['total_count']                     = $total_count;


        # view
        return $this->load->view('/web/life/editor', $return_data, true);


    }




    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 추천채널
    # CREATE  :	2018-04-30
    #---------------------------------------------------------------------------
	function fn_channel_recommend() {

        # 추천채널
        $etc_section_type = 1;
        $this->load->model('web/m_life_etc_section');
        $arr_etc_section = $this->m_life_etc_section->life_etc_section_join_channel_list($etc_section_type);

        $result = $this->m_life_etc_section->life_etc_section_detail_join_life_list($etc_section_type);
        $arr_etc_section_detail = array();
        foreach ($result as $val) {
            $arr_etc_section_detail[$val['life_etc_section_idx']][$val['rank']]  = array('head_title'=>$val['head_title'], 'title'=>$val['title'], 'partner_idx' => $val['partner_idx'], 'editor_name' => $val['editor_name'], 'main_img' => $val['main_img'], 'content_idx' => $val['content_idx']);
        }


        # view data
        $return_data = array();
        $return_data['arr_etc_section']                 = $arr_etc_section;
        $return_data['arr_etc_section_detail']          = $arr_etc_section_detail;

        # view
        return $this->load->view('/web/life/channel_recommend', $return_data, true);


    }



    #---------------------------------------------------------------------------
    # PURPOSE : 라이프 카테고리
    # CREATE  :	2018-04-30
    #---------------------------------------------------------------------------
	function fn_category() {
	    # Request
        $search_sort        = trim($this->input->get_post('search_sort', TRUE));
        $category_idx       = $this->uri->segment(4);

        if($search_sort == '')  $search_sort = '1';

        # sort
        switch ($search_sort) {
            case '1': $sort_column = 'reg_date'; break;
            case '2': $sort_column = 'popular_count'; break;
            default : $sort_column = 'reg_date'; break;
        }

        # 카테고리
        $this->load->model('web/m_category');
        $arr_category = $this->m_category->category_all_list();
        if(count($arr_category)==0) {
            gf_alert("등록된 카테고리가 없습니다.", '/web/life');
            exit;
        }

	    if($category_idx == '') {
	        $category_idx   = $arr_category[0]['idx'];
	        $category_name  = $arr_category[0]['category_name'];
            $swiper_page = 0;
        } else {

            foreach($arr_category as $key => $val) {
                if($val['idx'] == $category_idx) {
                    $swiper_page = $key;
                    $category_name = $val['category_name'];
                    break;
                }
            }

        }

        $req_data = array();
        $req_data['sort_column']        = $sort_column;
        $req_data['offset']             = 0;
        $req_data['limit']              = 8;
        $req_data['search_type']        = 'category_idx';
        $req_data['search_key']         = $category_idx;
        $req_data['member_group_idx']   = '6';

        # editor list
        $this->load->model('web/m_partner');
        $result = $this->m_partner->partner_life_aritcle_count_list($req_data);
        $total_count = $this->m_partner->partner_list_total_count($req_data);


        # view data
        $return_data = array();
        $return_data['list']            = $result;
        $return_data['total_count']     = $total_count;
        $return_data['search_sort']     = $search_sort;
        $return_data['arr_category']    = $arr_category;
        $return_data['category_idx']    = $category_idx;
        $return_data['category_name']   = $category_name;
        $return_data['swiper_page']     = $swiper_page;

        # view
        return $this->load->view('/web/life/category', $return_data, true);


    }




    #---------------------------------------------------------------------------
    # PURPOSE :	editor_list_more
    # CREATE  :	2018-05-01
    #---------------------------------------------------------------------------
	function fn_ajax_editor_list_more() {
	    # request
        $sort                   = trim($this->input->get_post('sort', TRUE));
        $page                   = trim($this->input->get_post('page', TRUE));
        $category_idx           = trim($this->input->get_post('category_idx', TRUE));

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


        $limit  = 8;
        $offset = ($page-1) * $limit;

        $req_data = array();
        $req_data['sort_column']        = $sort_column;
        $req_data['offset']             = $offset;
        $req_data['limit']              = $limit;
        $req_data['search_type']        = 'category_idx';
        $req_data['search_key']         = $category_idx;
        $req_data['member_group_idx']   = '6';

        # editor list
        $this->load->model('web/m_partner');
        $list = $this->m_partner->partner_life_aritcle_count_list($req_data);
        $total_count = $this->m_partner->partner_list_total_count($req_data);

        $more_list = 'N';
        if(($total_count-($page*$limit)) > 0){
            $more_list = 'Y';
        }

        if(count($list) > 0) {
            $return_data['result_code']         = '0000';
            $return_data['total_count']         = $total_count;
            $return_data['list']                = $list;
            $return_data['more_list']           = $more_list;

        } else {
            $return_data['result_code'] = '9999';
        }

        # view
        return $this->load->view("/web/life/editor_list_more", $return_data);

    }



    #---------------------------------------------------------------------------
    # PURPOSE : tag
    # CREATE  :	2018-05-01
    #---------------------------------------------------------------------------
	function fn_tag() {
	    # Request
        $tag            = $this->uri->segment(4);
        $content_type   = '3';
        $SES_MEMBER_ID  = $this->session->userdata('C_Member_Id');

        $tag = urldecode($tag);

        # tag
        $req_data = array();
        $req_data['content_type']   = $content_type;
        $req_data['tag']            = $tag;

        $this->load->model('web/m_tag');
        $total_count    = $this->m_tag->tag_join_life_list_total_count($req_data);
        if($total_count == 0) {
            gf_alert("등록된 태그가 없습니다.", '/web/life');
            exit;
        }

        # 배달여부
        $this->load->model('web/m_delivery');
        $tag_delivery_count = 0;
        if($SES_MEMBER_ID != '') {
            $req_data = array();
            $req_data['content_type']   = '9';
            $req_data['main_idx']       = $tag;
            $req_data['member_id']      = $SES_MEMBER_ID;

            $arr_column_delivery = $this->m_delivery->delivery_where_member_id_main_idx_select($req_data);
            $tag_delivery_count = count($arr_column_delivery);
        }


        $this->load->model('web/m_tag');

        # 연관태그
        $req_data = array();
        $req_data['content_type']   = $content_type;
        $req_data['tag']            = $tag;
        $arr_relation_tag     = $this->m_tag->tag_join_tag_list($req_data);
        

        # 태그글
        $req_data = array();
        $req_data['content_type']   = $content_type;
        $req_data['tag']            = $tag;
        $req_data['offset']             = 0;
        $req_data['limit']              = 9;
        $result     = $this->m_tag->tag_join_life_list($req_data);

        # view data
        $return_data = array();
        $return_data['list']                = $result;
        $return_data['total_count']         = $total_count;
        $return_data['tag_delivery_count']  = $tag_delivery_count;
        $return_data['tag']                 = $tag;
        $return_data['arr_relation_tag']    = $arr_relation_tag;

        # view
        return $this->load->view('/web/life/tag', $return_data, true);


    }


    #---------------------------------------------------------------------------
    # PURPOSE :	tag_list_more
    # CREATE  :	2018-05-01
    #---------------------------------------------------------------------------
	function fn_ajax_tag_list_more() {
	    # request
        $page           = trim($this->input->get_post('page', TRUE));
        $tag            = trim($this->input->get_post('tag', TRUE));
        $content_type   = '3';

        $limit  = 9;
        $offset = ($page-1) * $limit;

        $req_data = array();
        $req_data['offset']             = $offset;
        $req_data['limit']              = $limit;
        $req_data['tag']                = $tag;
        $req_data['content_type']       = $content_type;
        
        $this->load->model('web/m_tag');
        $list           = $this->m_tag->tag_join_life_list($req_data);
        $total_count    = $this->m_tag->tag_join_life_list_total_count($req_data);

        $more_list = 'N';
        if(($total_count-($page*$limit)) > 0){
            $more_list = 'Y';
        }

        if(count($list) > 0) {
            $return_data['result_code']         = '0000';
            $return_data['total_count']         = $total_count;
            $return_data['list']                = $list;
            $return_data['more_list']           = $more_list;

        } else {
            $return_data['result_code'] = '9999';
        }

        # view
        return $this->load->view("/web/life/tag_list_more", $return_data);

    }























}

?>