<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Qiniu 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');
			require_once CSCMSPATH.'lib/Cs_Qiniu.php';
	}


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

	public function save()
	{

		    $CS_Qn_Mode = intval($this->input->post('CS_Qn_Mode', TRUE));
		    $CS_Qn_Bk = $this->input->post('CS_Qn_Bk', TRUE);
		    $CS_Qn_Ak = $this->input->post('CS_Qn_Ak', TRUE);
		    $CS_Qn_Sk = $this->input->post('CS_Qn_Sk', TRUE);


            if($CS_Qn_Mode==1 && (empty($CS_Qn_Bk)||empty($CS_Qn_Ak)||empty($CS_Qn_Sk))){
                $this->CsdjAdmin->Admin_Url('<font color=red>请把数据填写完整！</font>',site_url('admin/qiniu'));
            }

            //修改文件
	        $strs="<?php"."\r\n";
	        $strs.="define(\"CS_Qn_Mode\",".$CS_Qn_Mode.");  //开关  \r\n";
	        $strs.="define(\"CS_Qn_Bk\",\"".$CS_Qn_Bk."\"); //空间名称  \r\n";
	        $strs.="define(\"CS_Qn_Ak\",\"".$CS_Qn_Ak."\"); //AK  \r\n";
	        $strs.="define(\"CS_Qn_Sk\",\"".$CS_Qn_Sk."\"); //SK";

            //写文件
            if (!write_file('./csdj/lib/Cs_Qiniu.php', $strs)){
                $this->CsdjAdmin->Admin_Url('<font color=red>操作失败，文件没有写入权限！</font>',site_url('admin/qiniu'));
            }else{
                $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，修改成功！</font>',site_url('admin/qiniu'),'ok');
            }
	}
}
