<?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 cs extends cm_Controller {

    #---------------------------------------------------------------------------
    # PURPOSE : 공지사항
    # CREATE  :	2018-05-04
    #---------------------------------------------------------------------------
	function fn_notice() {
        # Request
        $page           = trim($this->input->get_post('page', TRUE));
        $search_keyword = trim($this->input->get_post('search_keyword', TRUE));

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

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

        # 공지사항
        $req_data = array();
        $req_data['search_type']        = 'total';
        $req_data['search_keyword']     = $search_keyword;
        $req_data['offset']             = $offset;
        $req_data['limit']              = $limit;

        # model - list
        $this->load->model('web/m_bbs_notice');
        $result         = $this->m_bbs_notice->bbs_notice_list($req_data);
        $total_count    = $this->m_bbs_notice->bbs_notice_list_total_count($req_data);
        $row            = $this->m_bbs_notice->bbs_notice_order_by_reg_date_limit1_select();


        # page
        $max_page   = ceil($total_count / $limit);
        $pagination =  gf_paging($limit, $page, $max_page, '/web/cs/notice?search_keyword='.$search_keyword.'&page=');

        $data_num = ($total_count + $limit)-($page*$limit);

        # view data
        $return_data = array();
        $return_data['total_count']                 = $total_count;
        $return_data['search_keyword']              = $search_keyword;
        $return_data['list']                        = $result;
        $return_data['row']                         = $row;
        $return_data['pagination']	                = $pagination;
        $return_data['data_num']	                = $data_num;

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


    }


    #---------------------------------------------------------------------------
    # PURPOSE : 공지사항 뷰
    # CREATE  :	2018-04-16
    #---------------------------------------------------------------------------
	function fn_notice_view() {
        # Request
	    $idx                    = $this->uri->segment(4);
        $search_keyword         = trim($this->input->get_post('search_keyword', TRUE));
        $data_num               = trim($this->input->get_post('data_num', TRUE));

        # model - list
        $this->load->model('web/m_bbs_notice');
        $result         = $this->m_bbs_notice->bbs_notice_select($idx);
        $row            = $this->m_bbs_notice->bbs_notice_order_by_reg_date_limit1_select();

        # total count
        $req_data = array();
        $req_data['search_type']        = 'total';
        $req_data['search_keyword']     = $search_keyword;
        $total_count    = $this->m_bbs_notice->bbs_notice_list_total_count($req_data);

        $next_list = array();
        if($data_num == '' || $data_num == '0') {
            $data_num = 1;
        } else {
            # next_list
            $req_data = array();
            $req_data['search_type']        = 'total';
            $req_data['search_keyword']     = $search_keyword;
            $req_data['offset']             = 0;
            $req_data['limit']              = 4;
            $req_data['idx']                = $idx;

            $next_list      = $this->m_bbs_notice->bbs_notice_next_list($req_data);
        }

        # view data
        $return_data = array();
        $return_data['idx']                     = $idx;
        $return_data['result']                  = $result;
        $return_data['next_list']               = $next_list;
        $return_data['row']                     = $row;
        $return_data['search_keyword']          = $search_keyword;
        $return_data['total_count']             = $total_count;
        $return_data['data_num']                = $data_num;


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


    }




    #---------------------------------------------------------------------------
    # PURPOSE : faq
    # CREATE  :	2018-05-04
    #---------------------------------------------------------------------------
	function fn_faq() {
        # Request
        $page               = trim($this->input->get_post('page', TRUE));
        $search_keyword     = trim($this->input->get_post('search_keyword', TRUE));
        $search_category1   = trim($this->input->get_post('search_category1', TRUE));
        $search_category2   = trim($this->input->get_post('search_category2', TRUE));

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


        # 카테고리 가져오기
        $this->load->model('web/m_bbs_faq_category');
        $arr_category   = $this->m_bbs_faq_category->bbs_faq_category_all_list();
        $arr_category1 = array();   $arr_category2 = array();
        foreach ($arr_category as $val) {
            if($val['depth']=='1')  $arr_category1[] = array('category_code'=>$val['category_code'], 'category_name'=>$val['category_name'], 'idx'=> $val['idx']);
            if($val['depth']=='2')  $arr_category2[$val['p_category_code']][] = array('category_code'=>$val['category_code'], 'category_name'=>$val['category_name'], 'idx'=> $val['idx']);
        }
        if($search_category1 == '') $search_category1 = $arr_category1[0]['category_code'];

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

        # faq
        $req_data = array();
        $req_data['search_type']        = 'title';
        $req_data['search_keyword']     = $search_keyword;
        $req_data['faq_category_code1'] = $search_category1;
        $req_data['faq_category_code2'] = $search_category2;
        $req_data['offset']             = $offset;
        $req_data['limit']              = $limit;

        # model - list
        $this->load->model('web/m_bbs_faq');
        $result         = $this->m_bbs_faq->bbs_faq_list($req_data);
        $total_count    = $this->m_bbs_faq->bbs_faq_list_total_count($req_data);


        # page
        $max_page   = ceil($total_count / $limit);
        $pagination =  gf_paging($limit, $page, $max_page, '/web/cs/faq?search_keyword='.$search_keyword.'&search_category1='.$search_category1.'&search_category2='.$search_category2.'&page=');

        $data_num = ($total_count + $limit)-($page*$limit);


        # view data
        $return_data = array();
        $return_data['total_count']                 = $total_count;
        $return_data['search_keyword']              = $search_keyword;
        $return_data['search_category1']            = $search_category1;
        $return_data['search_category2']            = $search_category2;
        $return_data['list']                        = $result;
        $return_data['arr_category1']               = $arr_category1;
        $return_data['arr_category2']               = $arr_category2;
        $return_data['pagination']	                = $pagination;
        $return_data['data_num']	                = $data_num;

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


    }


    #---------------------------------------------------------------------------
    # PURPOSE : faq 뷰
    # CREATE  :	2018-04-16
    #---------------------------------------------------------------------------
	function fn_faq_view() {
        # Request
	    $idx                = $this->uri->segment(4);
	    $search_keyword     = trim($this->input->get_post('search_keyword', TRUE));
        $search_category1   = trim($this->input->get_post('search_category1', TRUE));
        $search_category2   = trim($this->input->get_post('search_category2', TRUE));
        $data_num           = trim($this->input->get_post('data_num', TRUE));

        # 카테고리 가져오기
        $this->load->model('web/m_bbs_faq_category');
        $arr_category   = $this->m_bbs_faq_category->bbs_faq_category_all_list();
        $arr_category1 = array();   $arr_category2 = array();
        foreach ($arr_category as $val) {
            if($val['depth']=='1')  $arr_category1[] = array('category_code'=>$val['category_code'], 'category_name'=>$val['category_name'], 'idx'=> $val['idx']);
            if($val['depth']=='2')  $arr_category2[$val['p_category_code']][] = array('category_code'=>$val['category_code'], 'category_name'=>$val['category_name'], 'idx'=> $val['idx']);
        }
        if($search_category1 == '') $search_category1 = $arr_category1[0]['category_code'];

        # model - list
        $this->load->model('web/m_bbs_faq');
        $result         = $this->m_bbs_faq->bbs_faq_select($idx);

        # faq
        $req_data = array();
        $req_data['search_type']        = 'title';
        $req_data['search_keyword']     = $search_keyword;
        $req_data['faq_category_code1'] = $search_category1;
        $req_data['faq_category_code2'] = $search_category2;
        $req_data['offset']             = 0;
        $req_data['limit']              = 4;
        $req_data['idx']                = $idx;

        $next_list      = $this->m_bbs_faq->bbs_faq_next_list($req_data);
        $total_count    = $this->m_bbs_faq->bbs_faq_list_total_count($req_data);

        # view data
        $return_data = array();
        $return_data['idx']                     = $idx;
        $return_data['result']                  = $result;
        $return_data['next_list']               = $next_list;
        $return_data['search_keyword']          = $search_keyword;
        $return_data['search_category1']        = $search_category1;
        $return_data['search_category2']        = $search_category2;
        $return_data['arr_category1']           = $arr_category1;
        $return_data['arr_category2']           = $arr_category2;
        $return_data['total_count']             = $total_count;
        $return_data['data_num']                = $data_num;


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


    }





}

?>