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

    #---------------------------------------------------------------------------
    # PURPOSE : 기사검색
    # CREATE  :	2018-03-06
    #---------------------------------------------------------------------------
	function fn_ajax_search_article_list() {
        # request
	    $article_keyword        = trim($this->input->get_post('article_keyword', TRUE));
	    $content_type           = trim($this->input->get_post('content_type', TRUE));
	    $sort                   = trim($this->input->get_post('sort', TRUE));
	    $type                   = trim($this->input->get_post('type', TRUE));
	    $category1              = trim($this->input->get_post('category1', TRUE));
	    $category2              = trim($this->input->get_post('category2', TRUE));
	    $category3              = trim($this->input->get_post('category3', TRUE));

        if($sort=='')   $sort = '1';
        switch ($sort) {
            case '1': $sort_column = 'display_date'; $sort_type = 'desc'; break;
            case '2': $sort_column = 'display_date'; $sort_type = 'asc';  break;
            default : $sort_column = 'display_date'; $sort_type = 'desc'; break;
        }

        # 검색
        $req_data['article_keyword']        = addslashes($article_keyword);
        $req_data['sort_column']            = $sort_column;
        $req_data['sort_type']              = $sort_type;
        $req_data['category1']              = $category1;
        $req_data['category2']              = $category2;
        $req_data['category3']              = $category3;

        if($content_type == 'all') {
            # model -  list
            $this->load->model('admin/comm/m_search');
            $result         = $this->m_search->all_list_limit100($req_data);
        } else {
            if($content_type == '1') {  // 뉴스
                # model -  list
                $this->load->model('admin/news/m_news');
                $result         = $this->m_news->news_list_limit100($req_data);
            } else if($content_type == '2') {  // 칼럼
                # model -  list
                $this->load->model('admin/column/m_column');
                $result         = $this->m_column->column_list_limit100($req_data);
            } else if($content_type == '3') {   // 라이프
                # model -  list
                $this->load->model('admin/life/m_life');
                $result         = $this->m_life->life_list_limit100($req_data);
            }
        }


        # view data
        $return_data['list']                = $result;
        $return_data['count']               = count($result);
        $return_data['sort']                = $sort;

        if($type=='JSON') {
            $return_data['result'] = array('result_code' => '0000', 'result_data'=>$return_data);
            $view_url = '/admin/comm/result_json';
        } else {
            $view_url = '/admin/search/search_article_list';
        }


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



    }





}

?>




