<?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 ProController extends AdminController {

    public function _initialize () {

        parent::_initialize();

        $this->leftmain=4;

         $this->PROSTATUS=C('PROSTATUS');

    }

    //新闻管理

    public function index(){

        $this->topmain=1;

    	$pro=M('Pro');

    	$prefix=C('DB_PREFIX');

        if(I('get.action')=="del"){

            $delpro=$pro->where(array('id'=>I('get.id')))->delete();

            if($delpro!==false){

                $this->success('删除成功',U('index',array('p'=>I('get.p'))));

            }else{

                $this->error('删除失败');

            }

            exit;

        }

        $p=empty($_GET['p'])?'1':$_GET['p'];

        $this->list = $pro->field('title,timeline,name,money,hot,status,procount,paycount,'.$prefix.'pro.id')->join('__PRO_CLS__ ON __PRO_CLS__.id = __PRO__.type','LEFT')->order($prefix.'pro.id desc')->page($p.',10')->select();

        $count=$pro->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();

    }



    //新闻增加

   public function add(){

        $this->topmain=4;

        if(IS_POST){

            $data            = I('post.');

            $data['content'] = I('post.content','',false);
            $data['timeline']= time();
            //如果get_magic_quotes_gpc()是打开的
            if(get_magic_quotes_gpc()){
                $data['content']=stripslashes($data['content']);
            }

            $savepro=M('pro')->add($data);

             if($savepro!==false){

                $this->success('新增成功',U('index'));

            }else{

                $this->error('新增失败');

            }

        }else{

            $this->list = M('pro_cls')->select();

           $this->show();

        }

    }



    //新闻修改

   public function edit(){

        $this->topmain=2;

        $id=I('get.id');

        $p=I('get.p');

        if(IS_POST){

            $data            = I('post.');

            $data['content'] = I('post.content','',false);
            //如果get_magic_quotes_gpc()是打开的
            if(get_magic_quotes_gpc()){
                $data['content']=stripslashes($data['content']);
            }

            $savepro=M('pro')->where('id='.$id)->save($data);

             if($savepro!==false){

                $this->success('修改成功',U('index',array('p'=>$p)));

            }else{

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

            }

        }else{

            $this->pro = M('pro')->where('id='.$id)->find();

            $this->list = M('pro_cls')->select();

            $this->p= $p;

           $this->show();

        }

    }

  

           //类型管理

    public function cls(){

        $this->topmain=3;

        $proclsMonde=M('pro_cls');

        if(IS_POST){

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

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

            if(I('post.ind')==1){

                $type="显示";

            }else{

                $type="不显示";

            }

            if(I('get.id')!=''){

                $savetitle="更新";

                $savecls=$proclsMonde->where(array('id'=>I('get.id')))->save($data);

            }else{

                $savetitle="新增";

                $savecls=$proclsMonde->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['name']."');

                        parent.$('#ty".I('get.id')."').css('color','red');

                        parent.$('#ty".I('get.id')."').text('".$type."');

                        var index = parent.layer.getFrameIndex(window.name);

                        parent.layer.close(index);

                        </script>"; 

                    exit;

                }else{

                    $this->success($savetitle.'成功',U('cls'));

                }

            }else{

                $this->error($savetitle.'失败');

            }

        }else{

            //判断是否删除操作

            if(I('get.action')=="del"){

                $deladmin=$proclsMonde->where(array('id'=>I('get.id')))->delete();

                if($deladmin!==false){

                    $this->success('删除成功',U('cls'));

                }else{

                    $this->error('删除失败');

                }

            }else{

                if(I('get.do')=='edit'){

                    $this->admin=$proclsMonde->where('id='.I('get.id'))->find();

                    $this->display('clsedit');

                    exit;

                }

                $this->dodo=I('get.do');

                $list=$proclsMonde->select();

                $this->list=$list;

                $this->show();

            }

        }

    }

}