<?php defined('BASEPATH') OR exit('No direct script access allowed');
header("Content-Type: text/html; charset=UTF-8");

include_once(APPPATH.'core/web/cm_exceptions.php');
class main_bak2 extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this->load->library('session');
        $this->load->library('user_agent');
        $this->load->helper('crossmap/tool_helper');
        $this->load->helper('crossmap/exception_helper');

    }

    public function index()
    {
        /*
        from _remap
        */
        $this->load->helper('cookie');
        $session_id = get_cookie('crossmap_save_id');
        # session
        $SES_MEMBER_ID  = $this->session->userdata('C_Member_Id');
        if($session_id != '' && $SES_MEMBER_ID=='') {
            # model - session 가져오기
            $this->load->model('web/m_ci_sessions');
            $session_result    = $this->m_ci_sessions->ci_sessions_select($session_id);
            session_decode($session_result['data']);
        }
        
        if($SES_MEMBER_ID!='') {
            $expire_date = date("Y-m-d H:i:s", strtotime("+10 minutes"));
            
            # model - 중복로그인 체크용
            $req_data = array();
            $req_data['member_id']      = $SES_MEMBER_ID;
            $req_data['member_ip']      = $_SERVER['REMOTE_ADDR'];
            $req_data['expire_date']    = $expire_date;
            $this->load->model('web/m_member_login');
            $this->m_member_login->member_login_member_id_member_ip_update($req_data);
        }
        
        # model - 사이트 정보
        $this->load->model('web/m_site_info');
        $site_info    = $this->m_site_info->site_info_select(1);

        $controller     = $this->uri->segment(2);
        
        /*
        from fn_index()
         */
        $now_date  = date("Y-m-d");
        
        # 영적기상도
        $this->load->model('web/m_weather');
        $arr_weather = $this->m_weather->weather_join_relation_article_join_news_list();

        # 오늘의 말씀
        $this->load->model('web/m_today_word');
        $arr_today_word = $this->m_today_word->today_word_where_display_date_select($now_date);

        # 테마
        # theme_type = 1 (헤드라인뉴스), theme_type = 8 (오늘의칼럼), theme_type = 11 (라이프홈), theme_type = 12 (데일리큐티)
        $this->load->model('web/m_theme');
        $req_data = array();
        $req_data['theme_types'] = array('1', '11', '12');
        $arr_theme = $this->m_theme->theme_join_vw_content_where_in_theme_type_list($req_data);

        $arr_headline_news  = array();
        $arr_life_home      = array();
        $arr_daily_cutie    = array();
        foreach ($arr_theme as $val) {
            if($val['theme_type'] == 1)     $arr_headline_news[$val['rank']] = array('title' => $val['title'], 'sub_content' => $val['sub_content'], 'theme_img' => $val['theme_img'], 'content_idx' => $val['content_idx']);
            if($val['theme_type'] == 11)    $arr_life_home[$val['rank']] = array('title' => $val['title'], 'sub_title'=> $val['sub_title'], 'sub_content' => $val['sub_content'], 'theme_img' => $val['theme_img'], 'content_idx' => $val['content_idx']);
            if($val['theme_type'] == 12)    $arr_daily_cutie[$val['rank']] = array('title' => $val['title'], 'sub_content' => $val['sub_content'], 'theme_img' => $val['theme_img'], 'content_idx' => $val['content_idx']);
        }

        // 오늘의 칼럼
        $req_data['theme_types'] = array('8');
        $arr_today_column = $this->m_theme->theme_join_vw_content_where_in_theme_type_list($req_data);        

        # 카드뉴스 - 기타섹션 테마
        $this->load->model('web/m_etc_section');
        $etc_section_type     = 4;
        $arr_card_news = $this->m_etc_section->etc_section_where_theme_type_list($etc_section_type);

        # 언론
        $this->load->model('web/m_press');
        $arr_press = $this->m_press->press_all_list();

        # 카테고리별
        $this->load->model('web/m_main_category_company');
        $arr_company = $this->m_main_category_company->main_category_company_all_list();

        $arr_content    = array();
        $content_idx    = $this->uri->segment(4);
        
        // 모아보기
        // 말씀과 묵상
        $req_data = array();
        $req_data['search_type']            = '';
        $req_data['search_keyword']         = '';
        $req_data['search_life_type']       = '';
        $req_data['search_category_code1']  = 6;
        $req_data['search_category_code2']  = '';
        $req_data['search_click1']          = '';
        $req_data['search_click2']          = '';
        $req_data['sort_column']            = 'a.reg_date';
        $req_data['search_write_id']        = '';
        $req_data['offset']                 = 0;
        $req_data['limit']                  = 7;
        $this->load->model('admin/life/m_life');

        //찬양
        $arr_praise             = $this->m_life->life_list($req_data);
        //말씀
        $req_data['search_category_code1']  = 5;
        $this->load->model('admin/life/m_life');
        $arr_gospel             = $this->m_life->life_list($req_data);
        //지식인
        $req_data['search_category_code1']  = 10;
        $this->load->model('admin/life/m_life');
        $arr_knowledge             = $this->m_life->life_list($req_data);

        // 2.크로스맵TV
        // 2-1.말씀영상
        $req_data['search_category_code1'] = 22;
        $req_data['search_category_code2'] = 42;
        $req_data['limit']                 = 8;
        $this->load->model('admin/life/m_life');
        $arr_tv_gospel             = $this->m_life->life_list($req_data);        
        // 2-2.찬양영상
        $req_data['search_category_code2'] = 43;
        $this->load->model('admin/life/m_life');
        $arr_tv_praise             = $this->m_life->life_list($req_data);  
        // 2-3.간증
        $req_data['search_category_code2'] = 44;
        $this->load->model('admin/life/m_life');
        $arr_tv_testimony             = $this->m_life->life_list($req_data); 
        // 2-4.토크쇼
        $req_data['search_category_code2'] = 45;
        $this->load->model('admin/life/m_life');
        $arr_tv_talkshow             = $this->m_life->life_list($req_data); 

        // 3.이런건 어때?
        // 3-1.은혜
        $req_data['search_category_code1'] = 18;
        $req_data['search_category_code2'] = '';
        $req_data['limit'] = 7;
        $this->load->model('admin/life/m_life');
        $arr_grace = $this->m_life->life_list($req_data);
        // 3-2.사랑
        $req_data['search_category_code1'] = 19;
        $this->load->model('admin/life/m_life');
        $arr_love = $this->m_life->life_list($req_data);
        // 3-3.크리스마스
        $req_data['search_category_code1'] = 20;
        $this->load->model('admin/life/m_life');
        $arr_christmas = $this->m_life->life_list($req_data);
        // 3-4.마무리
        $req_data['search_category_code1'] = 21;
        $this->load->model('admin/life/m_life');
        $arr_completion = $this->m_life->life_list($req_data);

        // 1-1. 이야기QT
        $req_data['search_category_code1']  = 8;
        $req_data['search_category_code2']  = 5;
        $this->load->model('admin/life/m_life');
        $arr_heart_opening_story   = $this->m_life->life_list($req_data);
        $req_data['search_category_code2']  = '';

        $melon_json = file_get_contents('http://35.224.33.187/melon.json');
        if($melon_json!='')
            $melon_arr = json_decode($melon_json,true);
        else
            $melon_arr = array();

        // 3-4. 함께 기도해요
        $req_data['search_category_code1']  = 9;
        $req_data['search_category_code2']  = '';
        $req_data['search_click2']          = 1;
        $req_data['limit'] = 24;
        $this->load->model('admin/life/m_life');
        $arr_Prayer                = $this->m_life->life_list($req_data);

         // 1-3. 은혜한구절
         $req_data['search_category_code1']  = 10;
         $req_data['search_category_code2']  = 7;
         $this->load->model('admin/life/m_life');
         $arr_gracious_verse        = $this->m_life->life_list($req_data);
         $req_data['search_category_code2']  = '';

         // 3-1.운율이 있는 묵상
        $req_data['search_category_code1'] = 8;
        $req_data['search_category_code2'] = 6;
        $req_data['limit'] = 24;
        $this->load->model('admin/life/m_life');
        $arr_meditation_contemplation = $this->m_life->life_list($req_data);

        // 3-2.말씀엽서
        $req_data['search_category_code1'] = 5;
        $req_data['search_category_code2'] = 3;
        $req_data['limit'] = 24;
        $this->load->model('admin/life/m_life');
        $arr_bible_postcard = $this->m_life->life_list($req_data);

        // 3-3.책 읽는 크리스천
        $req_data['search_category_code1'] = 17;
        $req_data['search_category_code2'] = 26;
        $req_data['limit'] = 24;
        $this->load->model('admin/life/m_life');
        $arr_christian_reading = $this->m_life->life_list($req_data);
 

        # view data
        $return_data = array();
        $return_data['site_info']   = $site_info;
        $return_data['arr_weather']         = $arr_weather;
        $return_data['arr_today_word']      = $arr_today_word;
        $return_data['arr_headline_news']   = $arr_headline_news;
        $return_data['arr_life_home']       = $arr_life_home;
        $return_data['arr_daily_cutie']     = $arr_daily_cutie;
        $return_data['arr_card_news']       = $arr_card_news;
        $return_data['arr_press']           = $arr_press;
        $return_data['arr_company']         = $arr_company;
        $return_data['arr_praise']          = $arr_praise;
        $return_data['arr_gospel']          = $arr_gospel;
        $return_data['arr_knowledge']       = $arr_knowledge;
        $return_data['arr_tv_gospel']       = $arr_tv_gospel;
        $return_data['arr_tv_praise']       = $arr_tv_praise;
        $return_data['arr_tv_testimony']    = $arr_tv_testimony;
        $return_data['arr_tv_talkshow']     = $arr_tv_talkshow;
        $return_data['arr_grace']           = $arr_grace;
        $return_data['arr_love']            = $arr_love;
        $return_data['arr_christmas']       = $arr_christmas;
        $return_data['arr_completion']      = $arr_completion;
        $return_data['arr_today_column']    = $arr_today_column;
        $return_data['arr_heart_opening_story']      = $arr_heart_opening_story;
        $return_data['arr_Prayer']                   = $arr_Prayer;
        $return_data['arr_gracious_verse']           = $arr_gracious_verse;
        $return_data['arr_meditation_contemplation'] = $arr_meditation_contemplation;
        $return_data['arr_bible_postcard']           = $arr_bible_postcard;
        $return_data['arr_christian_reading']        = $arr_christian_reading;
        $return_data['arr_melon_ccm']       = $melon_arr;

        $this->load->library('user_agent');
        if($this->agent->is_mobile()) {
            $return_data['is_mobile'] = true;
        } else {
            $return_data['is_mobile'] = false;
        }

        $this->load->view('/web/index2', $return_data);
    }
}
