<?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.11.08
// | explain:网站配置类
// +-----------------------------------------------------------------------------------

namespace Admin\Controller;
use Think\Controller;
class WebController extends AdminController {

    public function _initialize () {
        parent::_initialize();
        $this->leftmain=7;
    }

    //菜单配置
    public function index(){
        $this->topmain=1;
        $mainMonde=M('Main');
        if(IS_POST){
            $data=I('post.');
            if(I('get.id')!=''){
                $savetitle="更新";
                $savecls=$mainMonde->where(array('id'=>I('get.id')))->save($data);
            }else{
                $savetitle="新增";
                $savecls=$mainMonde->add($data);
            }

            if($savecls!==false){
                if(I('get.id')!=''){
                    echo "<script language=javascript>
                        parent.showlog();
                        parent.$('#name".I('get.id')."').css('color','red');
                        parent.$('#name".I('get.id')."').text('".$data['title']."');
                        parent.$('#url".I('get.id')."').css('color','red');
                        parent.$('#url".I('get.id')."').text('".$data['url']."');
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        </script>"; 
                    exit;
                }else{
                    $this->success($savetitle.'成功',U('index'));
                }
            }else{
                $this->error($savetitle.'失败');
            }
        }else{

            //判断是否删除操作
            if(I('get.action')=="del"){
                $deladmin=$mainMonde->where(array('id'=>I('get.id')))->delete();
                if($deladmin!==false){
                    $this->success('删除成功',U('index'));
                }else{
                    $this->error('删除失败');
                }
            }else{
                if(I('get.do')=='edit'){
                    $this->admin=$mainMonde->where('id='.I('get.id'))->find();
                    $this->display('indexedit');
                    exit;
                }
                $this->dodo=I('get.do');
                $list=$mainMonde->select();
                $this->list=$list;
                $this->show();
            }
        }
    }

    //广告管理
    public function ad(){
        $this->topmain=2;
        $adMonde=M('ad');
        if(IS_POST){
            $data['content']=I('post.content','',false);
            $data['isshow']=I('post.isshow');
            if(I('get.id')!=''){
                $savetitle="更新";
                $savecls=$adMonde->where(array('id'=>I('get.id')))->save($data);
            }
            if($savecls!==false){
                if(I('get.id')!=''){
                    echo "<script language=javascript>
                        parent.showlog();
                        parent.$('#name".I('get.id')."').css('color','blue');
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        </script>"; 
                    exit;
                }else{
                    $this->success($savetitle.'成功',U('ad'));
                }
            }else{
                $this->error($savetitle.'失败');
            }
        }else{
            if(I('get.do')=='edit'){
                $this->admin=$adMonde->where('id='.I('get.id'))->find();
                $this->display('adedit');
                exit;
            }

            $this->dodo=I('get.do');
            $p = empty($_GET['p'])?'1':$_GET['p'];
            $this->list = $adMonde->order('id asc')->page($p.',10')->select();
            $count=$adMonde->field('id')->count();
            $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
            $Page->rollPage=5;//页码每页显示数量
            $Page->lastSuffix = false;//尾页是否显示总页数
            $Page->setConfig('header','条记录');
            $Page->setConfig('prev','上一页');
            $Page->setConfig('next','下一页');
            $Page->setConfig('first','首页');
            $Page->setConfig('last','尾页');
            $Page->setConfig('theme','<div class="digg">%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% </div>');
            $show       = $Page->show();// 分页显示输出
            $this->assign('page',$show);// 赋值分页输出
            $this->p=$p;
            $this->show();
        }
    }

    //幻灯片管理
    public function flash(){
        $this->topmain=3;
        $flashMonde=M('Flash');
        if(IS_POST){
            $data=I('post.');
            if(I('get.id')!=''){
                $savetitle="更新";
                $savecls=$flashMonde->where(array('id'=>I('get.id')))->save($data);
            }else{
                $savetitle="新增";
                $savecls=$flashMonde->add($data);
            }

            if($savecls!==false){
                $configset  = M('Config')->field('imgurl,upimg')->limit(1)->find();//网站配置输出
                if($configset['upimg']==1){
                    $IMGURL =$configset['imgurl'];//图片远程地址
                }else{
                    $IMGURL ='/Uploads/';//图片本地地址
                }
                if(I('get.id')!=''){
                	 $seeimg='<img src="'.$IMGURL.$data['image'].'" width="150px">';
                    echo "<script language=javascript>
                        parent.showlog();
                        parent.$('#name".I('get.id')."').css('color','red');
                        parent.$('#name".I('get.id')."').text('".$data['title']."');
                        parent.$('#url".I('get.id')."').css('color','red');
                        parent.$('#url".I('get.id')."').text('".$data['url']."');
                        parent.$('#image".I('get.id')."').html('".$seeimg."');
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        </script>"; 
                    exit;
                }else{
                    $this->success($savetitle.'成功',U('flash'));
                }
            }else{
                $this->error($savetitle.'失败');
            }
        }else{
            //判断是否删除操作
            if(I('get.action')=="del"){
                $deladmin=$flashMonde->where(array('id'=>I('get.id')))->delete();
                if($deladmin!==false){
                    $this->success('删除成功',U('flash'));
                }else{
                    $this->error('删除失败');
                }
            }else{
                if(I('get.do')=='edit'){
                    $this->admin = $flashMonde->where(array('id'=>I('get.id')))->find();
                    $this->display('flashedit');
                    exit;
                }
                $this->dodo=I('get.do');
                $list=$flashMonde->select();
                $this->list=$list;
                $this->show();
            }
        }
    }

    //友链管理
    public function link(){
        $this->topmain=4;
        $flashMonde=M('Link');
        if(IS_POST){
            $data=I('post.');
            if(I('get.id')!=''){
                $savetitle="更新";
                $savecls=$flashMonde->where(array('id'=>I('get.id')))->save($data);
            }else{
                $savetitle="新增";
                $savecls=$flashMonde->add($data);
            }

            if($savecls!==false){
                $configset  = M('Config')->field('imgurl,upimg')->limit(1)->find();//网站配置输出
                   if($configset['upimg']==1){
                        $IMGURL =$configset['imgurl'];//图片远程地址
                    }else{
                        $IMGURL ='/Uploads/';//图片本地地址
                    }

                if(I('get.id')!=''){
                	if($data['img']==''){
                		$seeimg='文字链接';
                	}else{	
                	 	$seeimg='<img src="'.$IMGURL.$data['img'].'" width="150px">';
                	}
                    echo "<script language=javascript>
                        parent.showlog();
                        parent.$('#name".I('get.id')."').css('color','red');
                        parent.$('#name".I('get.id')."').text('".$data['name']."');
                        parent.$('#url".I('get.id')."').css('color','red');
                        parent.$('#url".I('get.id')."').text('".$data['url']."');
                        parent.$('#image".I('get.id')."').html('".$seeimg."');
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        </script>"; 
                    exit;
                }else{
                    $this->success($savetitle.'成功',U('link'));
                }
            }else{
                $this->error($savetitle.'失败');
            }
        }else{

            //判断是否删除操作
            if(I('get.action')=="del"){
                $deladmin=$flashMonde->where(array('id'=>I('get.id')))->delete();
                if($deladmin!==false){
                    $this->success('删除成功',U('link'));
                }else{
                    $this->error('删除失败');
                }
            }else{
                if(I('get.do')=='edit'){
                    $this->admin = $flashMonde->where(array('id'=>I('get.id')))->find();
                    $this->display('linkedit');
                    exit;
                }
                $this->dodo = I('get.do');
                $p = empty($_GET['p'])?'1':$_GET['p'];
		        $this->list = $flashMonde->order('id desc')->page($p.',10')->select();
		        $count=$flashMonde->field('id')->count();
        		$Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        		$Page->rollPage=5;//页码每页显示数量
        		$Page->lastSuffix = false;//尾页是否显示总页数
		        $Page->setConfig('header','条记录');
		        $Page->setConfig('prev','上一页');
		        $Page->setConfig('next','下一页');
		        $Page->setConfig('first','首页');
		        $Page->setConfig('last','尾页');
		        $Page->setConfig('theme','<div class="digg">%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% </div>');
		        $show       = $Page->show();// 分页显示输出
		        $this->assign('page',$show);// 赋值分页输出
		        $this->p=$p;
		        $this->display();
            }
        }
    }
}