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



    public function _initialize () {

        parent::_initialize();

        $this->leftmain=9;

    }



    //案例管理

    public function index(){



        $this->topmain=1;



    	$Case=M('Case');



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



            $delCase=$Case->where(array('id'=>I('get.id')))->delete();



            if($delCase!==false){



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



            }else{



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



            }



            exit;



        }



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



        $this->list = $Case->field('title,hot,timeline,img,id')->where('type=0')->order('id desc')->page($p.',10')->select();



        $count=$Case->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=array(



                'title'      => I('post.title'),



                'hot'        => I('post.hot'),



                'url'        => I('post.url'),



                'img'        => I('post.img'),



            	'type'		 => 0,



                'content'    => I('post.content','',false),



                'timeline'   => time(),



            );

            //如果get_magic_quotes_gpc()是打开的

            if(get_magic_quotes_gpc()){

                $data['content']=stripslashes($data['content']);

            }



            $saveCase=M('Case')->add($data);



             if($saveCase!==false){



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



            }else{



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



            }



        }else{



           $this->show();



        }



    }







    //案例修改



   public function edit(){



        $this->topmain=2;



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



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



        if(IS_POST){



            $data=array(



                'title'      => I('post.title'),



                'hot'        => I('post.hot'),



                'url'        => I('post.url'),



                'img'        => I('post.img'),



                'content'    => I('post.content','',false),



            );



            //如果get_magic_quotes_gpc()是打开的

            if(get_magic_quotes_gpc()){

                $data['content']=stripslashes($data['content']);

            }

            

            $saveCase=M('Case')->where('id='.$id)->save($data);



             if($saveCase!==false){



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



            }else{



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



            }



        }else{



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



            $this->p= $p;



           $this->show();



        }



    }



}