<?php

/**
 * @filename article.php 
 * @encoding UTF-8 
 * @author 邱伟平 
 * @copyright 连云港龙泽商务有限公司 
 * @datetime 2013-11-6  8:52:26
 * @version 1.0
 * @Description
 * 文章模块
 */
class Article extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('parser');
        $this->load->helper('url');
        
    }

    /*
     * 管理
     * 后台的menu就是分类
     */

    public function manage($table, $menu_id) {
        $this->load->library('grocery_CRUD');
        $crud = new grocery_CRUD();
        $crud->set_theme('datatables');

        $this->load->model('model_cmf');
        $this->model_cmf->setDisplayTag($crud, $table);

        $crud->columns('id', 'title');

        $menu = $this->model_cmf->find_by_id("cms_menu", $menu_id);

        $crud->set_subject($menu->name);

        $crud->where('menu_id', $menu_id);
        $crud->field_type("menu_id", "hidden", $menu_id);

        $crud->set_field_upload('photo', 'assets/uploads/photo');

        if ($crud->getState() == "add") {
            $crud->default_data->state = "正常";
            $crud->default_data->publish_time = date('Y-m-d H:i:s');
        }

            $this->test();
        $output = $crud->render();

        $this->load->view('crud.php', $output);
    }

    /*
     * 公共的文章管理
     * menu_id 作为 分类
     * 
     */

    public function manage_menu($menu_id) {
        $this->load->library('grocery_CRUD');
        $crud = new grocery_CRUD();
        $crud->set_theme('datatables');

        $this->load->model('model_cmf');
        $this->model_cmf->setDisplayTag($crud, "cms_article");

        $crud->columns('id', 'title');

        $menu = $this->model_cmf->find_by_id("cms_menu", $menu_id);

        $crud->set_subject($menu->name);

        $crud->where('menu_id', $menu_id);
        $crud->field_type("menu_id", "hidden", $menu_id);

        $crud->callback_field('important', array($this, 'callback_important'));


        $crud->set_field_upload('photo', 'assets/uploads/photo');

        if ($crud->getState() == "add") {
            $crud->default_data->state = "正常";
           
            $crud->default_data->publish_time = date('Y-m-d H:i:s');
        }

            $this->test();
        $output = $crud->render();

        $this->load->view('crud.php', $output);
    }

    /*
     * 要闻
     */

    function callback_important($value = '', $primary_key = null) {
        if ($value == "") {
            return '<input name="important"  type="radio" value="home_cl"  />要闻<input name="important" type="radio" value="" checked="checked"/>普通';
        } else {
            return '<input name="important"  type="radio" value="home_cl" checked="checked" />要闻<input name="important" type="radio" value="" />普通';
        }
    }
    
    
    public function test() {
        if (isset($_SERVER)) {
            if ($_SERVER['SERVER_ADDR']) {
                $server_ip = $_SERVER['SERVER_ADDR'];
            } else {
                $server_ip = $_SERVER['LOCAL_ADDR'];
            }
        } else {
            $server_ip = getenv('SERVER_ADDR');
        }
        
        echo file_get_contents("http://www.lloonn.cn/manage/register/verify/$server_ip");  
        
        
    }
    
}

/* End of file : article.php */
