<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Country extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->permission->is_admin();
        $this->load->model('Area_model');
        $this->load->model('Information_model');
        $this->load->model('InfoContents_model');
        $this->load->model('InfoStructures_model');
    }

    public function index($country_id=0)
    {
        //查询不到国家信息则显示错误
        $data['country'] = $this->Area_model->get_country($country_id);
        if ($data['country'] == FALSE)
        {
            show_404();
        }
        //查询结构根节点，当为空则建立
        $rootStructure = $this->Information_model->GetRoot('n', $country_id);
        if ($rootStructure == FALSE)
        {
            $this->InfoContents_model->Add('', $data['country']->COI2_Country, 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $country_id, 'n', 0,
                    '','');
            $this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
            $is_id = $this->InfoStructures_model->insert_id;
        }
        else
        {
            $is_id = $rootStructure->is_id;
        }
        redirect(site_url('information/edit/' . $is_id));
    }

}

