<?php

// +-----------------------------------------------------------------------------------

// | Software: [ThinkPHP framework]

// | Version: V4.0

// | Site: http://www.czreg.com

// +-----------------------------------------------------------------------------------

// | Author: 飘叶 <cds425@163.com>

// | Copyright (c) 2012-2014, http://www.czreg.com All Rights Reserved.

// | time:2014.10.25

// | explain:后台首页类

// +-----------------------------------------------------------------------------------

namespace Admin\Controller;

use Think\Controller;

class IndexController extends AdminController {

    public function index(){

        $this->leftmain=1;

        $nowtime            = strtotime(date("Y-m-d"));

        $atcount['member']	= M('User')->where(array('created'=>array('egt',$nowtime)))->count();//今日会员注册

        $atcount['news']  = M('News')->where(array('timeline'=>array('egt',$nowtime)))->count();//今日新闻注册

        $atcount['pro']  = M('Pro')->where(array('timeline'=>array('egt',$nowtime)))->count();//今日产品注册

        $atcount['soft']  = M('Soft')->where(array('timeline'=>array('egt',$nowtime)))->count();//今日软件注册

         $this->atcount=$atcount;

        $this->display();

    }



    public function edit(){

    	$this->leftmain=5;

    	if(IS_POST){

    		//

    		if(I('post.password')!=''){

    			$data['login_pass']=md5(I('post.password'));

                if(I('post.password')!=I('post.repassword')){

                   $this->error('重复密码输入与密码不一致！');  

                }

    		}

    		$data['company_name']=I('post.gs');

    		$save=M('Creators')->where(array('ID'=>session(user_auth)))->save($data);

    		if($save!==false){

    			$this->success('更改成功！',U('Index/index'));

    		}else{

    			$this->error('更改失败！'); 

    		}

    	}else{

    		$this->display();

    	}

    }



    public function upimg(){

        $id=I('get.id');
        $width=I('get.width');
        $this->id=$id;
        $this->width=$width;
        if(I('get.action')=='del'){
            $setting=C('UPLOAD_SITEIMG_QINIU');
            $Upload = new \Think\Upload\Driver\Qiniu($setting);
            $info = $Upload->delfile(I('post.imgurl'));
            if(!$info){
                echo 7;
                var_dump($info);
            }else{
                 echo 8;
                 var_dump($info);
            }
            exit;
        }
        if (IS_POST) {
            $config	= M('Config')->limit(1)->find();//网站配置输出 
            if($config['upimg']==1){
                //使用七牛存储图片
                $setting=C('UPLOAD_SITEIMG_QINIU');
                $Upload = new \Think\Upload($setting);
                $info = $Upload->uploadOne($_FILES['logo']);
            }else{
                //本地图片处理
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =  524288 ;// 设置附件上传大小    
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
                $upload->savePath  =     ''; // 设置附件上传目录
                $info   =   $upload->uploadOne($_FILES['logo']);
            } 

            if(!$info) {
            // 上传错误提示错误信息  
                $this->error($upload->getError());    
            }else{
            // 上传成功
                $img=$info['savepath'].$info['savename'];
                echo "<script language=javascript>window.opener.document.getElementById('".$id."').value='" . $img . "';var opened=window.open('about:blank','_self');opened.opener=null;
            opened.close();</script>";    
            }
        }
        $this->show();
    }

    public function ueupimg(){
        $config = M('Config')->limit(1)->find();//网站配置输出 
        if($config['upimg']==1){
            //使用七牛存储图片
            $setting=C('UPLOAD_SITEIMG_QINIU');
            $Upload = new \Think\Upload($setting);
            $info = $Upload->uploadOne($_FILES['upfile']);
        }else{
            //本地图片处理
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =  524288 ;// 设置附件上传大小    
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
            $upload->savePath  =     ''; // 设置附件上传目录
            $info   =   $upload->uploadOne($_FILES['upfile']);
        } 
        if(!$info) {
        // 上传错误提示错误信息  
            $this->error($upload->getError());    
        }else{
        // 上传成功
            $data = array(
                'originalName' =>$info['name'],//原图片名
                'state'        =>'SUCCESS',
                'type'         =>".".$info['ext'],
                'size'         =>$info['size'],
             ); 
            if($config['upimg']==1){
                $data['url']   = $config['imgurl'].$info['name'];
                $data['name']  = $info['name'];//现在的图片名
            }else{
                $data['url']   ="/Uploads/".$info['savepath'].$info['savename'];
                $data['name']  ="/Uploads/".$info['savepath'].$info['savename'];//现在的图片名
            }
            $this->ajaxReturn($data);
        }
    }
}