<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Rigin extends CI_Controller {

	function __construct(){
		parent::__construct();
        	$this->load->helper('url');
                $this->load->library('session'); //加载session
		$this->load->model('CsdjDB');
		$this->load->model('CsdjAdmin');
		$this->load->model('CsdjSkins');
	        $this->CsdjAdmin->Admin_Login();
                $this->load->helper('file');
	}


	public function index()
	{
            $this->load->view('admin/rigin');
        }

	public function edit()
	{
            $id = $this->security->xss_clean($this->uri->segment(4));   //ID
            $data['id']=$id;
            if($id==1){
                $data['title']="来源";
                $data['neir']=CS_Laiyuan;
            }elseif($id==2){
                $data['title']="地区";
                $data['neir']=CS_Diqu;
            }elseif($id==3){
                $data['title']="语言";
                $data['neir']=CS_Yuyan;
            }elseif($id==4){
                $data['title']="年份";
                $data['neir']=CS_Year;
            }elseif($id==5){
                $data['title']="作者";
                $data['neir']=CS_Zuoz;
            }
            $data['neir']=str_replace("|","\r\n",$data['neir']);
            $this->load->view('admin/rigin_edit',$data);
        }

	public function xuan()
	{
            $ac = $this->input->get('ac', TRUE);
            if($ac=='laiyuan'){
                $data['title']="来源";
                $data['neir']=CS_Laiyuan;
            }elseif($ac=='diqu'){
                $data['title']="地区";
                $data['neir']=CS_Diqu;
            }elseif($ac=='yuyan'){
                $data['title']="语言";
                $data['neir']=CS_Yuyan;
            }elseif($ac=='year'){
                $data['title']="年份";
                $data['neir']=CS_Year;
            }elseif($ac=='zuozhe'){
                $data['title']="作者";
                $data['neir']=CS_Zuoz;
            }
            $this->load->view('admin/rigin_xuan',$data);
        }

	public function editok()
	{
                $this->CsdjAdmin->Admin_Qx('7');
		$id = $this->input->post('id', TRUE);
		$neir = $this->input->post('Content', TRUE);
                $neir = $this->CsdjSkins->str_checkhtml(str_replace("\r\n","|",$neir));

                if(empty($neir)){
                          $this->CsdjAdmin->Admin_Url('<font color=red>数据不能为空！</font>',site_url('admin/rigin/edit/'.$id.'/'));
                }

                //修改文件
	        $dbneir=read_file('./csdj/lib/Cs_Rigin.php');
                if($id==1){
	              $dbneir=preg_replace('/"CS_Laiyuan","(.*?)"/','"CS_Laiyuan","'.$neir.'"',$dbneir);
	        }elseif($id==2){
	              $dbneir=preg_replace('/"CS_Diqu","(.*?)"/','"CS_Diqu","'.$neir.'"',$dbneir);
	        }elseif($id==3){
	              $dbneir=preg_replace('/"CS_Yuyan","(.*?)"/','"CS_Yuyan","'.$neir.'"',$dbneir);
	        }elseif($id==4){
	              $dbneir=preg_replace('/"CS_Year","(.*?)"/','"CS_Year","'.$neir.'"',$dbneir);
	        }elseif($id==5){
	              $dbneir=preg_replace('/"CS_Zuoz","(.*?)"/','"CS_Zuoz","'.$neir.'"',$dbneir);
                }
                //写文件
                if (!write_file('./csdj/lib/Cs_Rigin.php', $dbneir)){
                          $this->CsdjAdmin->Admin_Url('<font color=red>操作失败，文件没有写入权限！</font>',site_url('admin/rigin/'));
                }else{
                          $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，修改成功！</font>',site_url('admin/rigin/'),'ok');
                }
        }
}

