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

    #---------------------------------------------------------------------------
    # PURPOSE : 모바일 메인
    # CREATE  :
    #---------------------------------------------------------------------------
	function fn_index() {

	



      $now_date  = date("Y-m-d");
        


      # 오늘의 말씀
      $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 (데일리큐티)
      # 16 = 상단(2) , 17 = 라이프(3) , 18 = 은혜의샘(6), 19(3) = 하늘양식, 20=상단_빅원(1), 21=중상단(6)
      $this->load->model('web/m_theme');
      $req_data = array();
      $req_data['theme_types'] = array('1','16', '17', '18','19','20','21','8', '3','6');
      $arr_theme = $this->m_theme->theme_join_vw_content_where_in_theme_type_list($req_data);
//      echo $this->db->last_query();

      $arr_headline_news  = array();
      $arr_life_home      = array();
      $arr_daily_cutie    = array();
      $arr_grace_top    = array();
      $arr_grace_life    = array();
      $arr_grace_well    = array();
      $arr_grace_sky    = array();
      $arr_grace_bigone    = array();
      $arr_grace_middle    = array();
      $arr_headline_column = array();
      $arr_p_video = array();
$a = array();
      $i = 0;
      foreach ($arr_theme as $val) {
        if($val['theme_type'] == 1)      $arr_headline_news[$val['rank']] = $val;
        if($val['theme_type'] == 16)     $arr_grace_top[$val['rank']] = $val;
        if($val['theme_type'] == 17)     $arr_grace_life[$val['rank']] = $val;

        if($val['theme_type'] == 18)     $arr_grace_well[$val['rank']] = $val;
        if($val['theme_type'] == 19)     $arr_grace_sky[$val['rank']] = $val;
        if($val['theme_type'] == 20)     $arr_grace_bigone[$val['rank']] = $val;
        if($val['theme_type'] == 21)     $arr_grace_middle[$val['rank']] = $val;
        if($val['theme_type'] == 8)      $arr_headline_column[$val['rank']] = $val;
      }



        # 기타섹션 - 인기영상 1 / 인기포토 2
        $this->load->model('web/m_etc_section');
        $req_data = array();
        $req_data['etc_section_types'] = array('3');
        $arr_etc_section = $this->m_etc_section->etc_section_where_in_etc_section_type_list($req_data);

        
        $arr_p_photo    = array();
        $arr_p_video    = array();
        foreach ($arr_etc_section as $val) {
            if($val['etc_section_type'] == 3)     $arr_etc_video[$val['rank']]  = $val;
        }

         

      # 카드뉴스 - 기타섹션 테마
      $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();



		#상단채널
		$this->load->model('web/m_life_etc_section');
		$arr_chanel = $this->m_life_etc_section->life_etc_section_join_channel_list(array(3,4,5,6));

		#임의 체널
		$arr_random_chanel    = $this->m_life_etc_section->life_etc_section_detail_list(34);



		foreach ($arr_chanel as $val) {
			switch ($val['etc_section_type']){

				#하단인기베스트
				case 3:
					$arr_p_best = $val;
					break;


				#추천에디터
				case 6:
					$arr_recom_editor = $val;
					break;

			}
		}

      $return_data = array();
      
      /*
      메인 화면 출력용 데이터
      */

		$this->load->model('admin/etc_section/m_life_etc_section');
//		$total_count         = $this->m_life_etc_section->life_editor_etc_section_list_total_count($req_data);
		$rd = array(
		"search_type" => "","search_keyword"=>"","search_category"=>"",
		"search_etc_section_type"=>5,
		"sort_column"=>"reg_date",
		"offset"=>"0",
  		"limit"=>"1");


		$aa              = $this->m_life_etc_section->life_editor_etc_section_list($rd);

      $arr_mid_bigone =     $this->m_life_etc_section->life_etc_section_detail_list($aa[0]['idx']);
//      echo $this->db->last_query();

		$return_data['bigone_main'] = $aa[0];
      $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;
      #탑6
      $return_data['arr_grace_top']  =   $arr_grace_top;
      #라이프 테마
      $return_data['arr_grace_life']  =   $arr_grace_life;
      #은혜의 샘
      $return_data['arr_grace_well']  =   $arr_grace_well;
      #하늘양식
      $return_data['arr_grace_sky']  =   $arr_grace_sky;
      #빅원
      $return_data['arr_grace_bigone']  =   $arr_grace_bigone;
      #중상단
      $return_data['arr_grace_middle']  =   $arr_grace_middle;
      #컬럼
      $return_data['arr_headline_column'] = $arr_headline_column;
      #은혜로운 영상
      $return_data['arr_etc_video'] = $arr_etc_video;

		#임의 채널
		$return_data['arr_random_chanel'] = $arr_random_chanel;

		#임의 채널
		$return_data['arr_p_best'] = $arr_p_best;
		#임의 채널
		$return_data['arr_mid_bigone'] = $arr_mid_bigone;
		#임의 채널
		$return_data['arr_recom_editor'] = $arr_recom_editor;


    
      # 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);


//		$this->load->model('admin/etc_section/m_life_etc_section');

		$req_data = array("etc_section_type"=>4);
		$return_data['arr_etc_section']        = $this->m_life_etc_section->life_etc_section_type_list($req_data);


		$arr_life_etc_section_detail_rank = array();
		$arr_etc_section_detail = $this->m_life_etc_section->life_etc_section_detail_type_list($req_data);

//		var_dump($arr_etc_section_detail);
		foreach ($arr_etc_section_detail as $val) {
			$arr_life_etc_section_detail_rank[$val['life_etc_section_idx']][$val['rank']] = array('main_img'=> $val['main_img'], 'head_title'=> $val['head_title'], 'title'=> $val['title'], 'content_idx'=> $val['content_idx'], 'hit_count'=>$val['hit_count'], 'editor_name'=>$val['editor_name']);
//			print_r($val);
		}



//		$result2    = $this->m_life_etc_section->life_etc_section_detail_list($idx);
		$return_data['arr_etc_section_detail'] = $arr_life_etc_section_detail_rank;


      $return_data['life'] = $result;



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


		$this->load->model('web/m_contents_setting');
		$return_data['arr_news_setting']   = $this->m_contents_setting->contents_setting_select(1);
        return $this->load->view('/m/m_index', $return_data, true);
        // return $this->load->view('/m/common/footer');
    }




}

?>
