<?php

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

/**
 * 
 * 交换链接
 * 
 */ 
class Link 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');
        //$this->output->enable_profiler(TRUE);
    }

    public function index()
    {
		$link_id=1;
        //查询结构根节点，当为空则建立
        $rootStructure = $this->Information_model->GetRoot('k', $link_id);
        if ($rootStructure == FALSE)
        {
            $this->InfoContents_model->Add('', 'Links', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $link_id, 'k', 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));
    }
    
    /*
    //导入数据
    public function add()
    {
        $is_id = $this->input->post('is_id');
        $lnk_txt = $this->input->post('lnk_txt');
        
        if (!empty($lnk_txt))
        {
            eval($lnk_txt);
            //print_r($links);return;
        }
        
        if (!empty($is_id)&&isset($links)) 
        {
            foreach ($links as $k1=>$v1)
            {
                if (!empty($v1)) 
                {
                    //第一维
                    $l_url = '';
                    $l_name = str_replace('div-','',$k1);
                    $l_des = '';
                    $this->InfoContents_model->Add(
                    $l_url, //ic_url
                    $l_name, //ic_url_title
                    'none', //ic_type
                    $l_name, //ic_title
                    $l_des, //ic_content
                    '', //ic_summary
                    '', //ic_seo_title
                    '', //ic_seo_description
                    '', //ic_seo_keywords
                    0, //ic_show_bread_crumbs
                    1, //ic_status
                    '', //ic_template
                    '', //ic_photo
                    0, //ic_photo_width
                    0, //ic_photo_height
                    '', //ic_recommend_tours
                    '', //ic_recommend_packages
                    0, //ic_ht_area_id
                    'k', //ic_ht_area_type
                    0, //ic_ht_product_id
                    '', //ic_ht_product_type
                    'lmr'); //ic_author
                    $this->InfoStructures_model->Add($is_id, $this->InfoContents_model->insert_id);
                    $lv1_is_id = $this->InfoStructures_model->insert_id;
                    //第二维
                    foreach ($v1 as $k2=>$v2)
                    {
                        $k2 .= '$$$';
                        $k2 = str_replace('http://','',$k2);
                        $k2 = str_replace('/$$$','',$k2);
                        $k2 = str_replace('$$$','',$k2);
                        $l_url = $k2;
                        $v2 = explode('@@@',$v2);
                        $l_name = $v2[1];
                        $l_des = $v2[0];
                        $this->InfoContents_model->Add(
                        $l_url, //ic_url
                        $l_name, //ic_url_title
                        'none', //ic_type
                        $l_name, //ic_title
                        $l_des, //ic_content
                        '', //ic_summary
                        '', //ic_seo_title
                        '', //ic_seo_description
                        '', //ic_seo_keywords
                        0, //ic_show_bread_crumbs
                        1, //ic_status
                        '', //ic_template
                        '', //ic_photo
                        0, //ic_photo_width
                        0, //ic_photo_height
                        '', //ic_recommend_tours
                        '', //ic_recommend_packages
                        0, //ic_ht_area_id
                        'k', //ic_ht_area_type
                        0, //ic_ht_product_id
                        '', //ic_ht_product_type
                        'lmr'); //ic_author
                        $this->InfoStructures_model->Add($lv1_is_id, $this->InfoContents_model->insert_id);
                    }
                }
            }
        }
        
        $this->load->view('data_import/link_add');
    }
    */
}

