<?php
defined('CML_PATH') || exit();
class PicController extends CmlController {
	//图集管理
	public function pic(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	    $PicModel = new PicModel();
	    $picdata=$PicModel->pv();
	    CmlView::assign('picdata',$picdata);
	    CmlView::display();
	}
	//添加图集
	public function addpic(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	  $picdata=array(
	  "0"=>array(
	  "id"=>"",
	  "title"=>"",
	  "url"=>"",
	  "info"=>"",
	  "tags"=>"",
	  "seo"=>""
	  ));
	  CmlView::assign('picdata',$picdata);
	    CmlView::display();
	}
	//保存图集
	public function addpicsave(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){
			$title=getGp('gcmstitle',2);
			$url=getGp('gcmsurl',2);
			$info=getGp('gcmsinfo',2);
			$tags=getGp('gcmstags',2);
			$seo=getGp('gcmsseo',2);
	    $PicModel = new PicModel();
	    $picok=$PicModel->addpic($title,$url,$tags,$seo,$info,0,0);
	    if ($picok == true){
	    	$this->success('添加图集成功','pic/pic');
			} else {
				$this->error('添加图集失败','pic/addpic');
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
	}
	
	//修改图集
	public function editpic(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
		$id=getGp('id');
	  $PicModel = new PicModel();
		$picdata=$PicModel->editpic($id);
	  CmlView::assign('picdata',$picdata);
		CmlView::display('addpic');
	}
	//保存修改图集
	public function editpicsave(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){
		$id=getGp('id',2);
			$title=getGp('gcmstitle',2);
			$url=getGp('gcmsurl',2);
			$info=getGp('gcmsinfo',2);
			$tags=getGp('gcmstags',2);
			$seo=getGp('gcmsseo',2);
	    $PicModel = new PicModel();
	    $picok=$PicModel->editpicsave($id,$title,$url,$tags,$seo,$info,0,0);
	    if ($picok == true){
	    	$this->success('修改图集成功','pic/pic');
			} else {
				$this->error('修改图集失败','pic/pic');
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
	}
	
	//删除图集
	public function delPic(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		$id=getGp('id');
	    $PicModel = new PicModel();
	    $picok=$PicModel->delpic($id);
		if ($picok == true){
			$this->success('删除成功','pic/pic');
		} else {
			$this->error('删除失败','pic/pic');
		}
	}		
	
	//图片管理
	public function pics(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		
		$classid=getGp('classid');
	  $PicModel = new PicModel();
		$picdata=$PicModel->editpic($classid);
	  CmlView::assign('picdata',$picdata);
	  
	    $picsdata=$PicModel->pvs($classid);
	    CmlView::assign('picsdata',$picsdata);
	    CmlView::display();
	}
	//添加图片
	public function addpics(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	  $picdata=array(
	  "0"=>array(
	  "id"=>"",
	  "title"=>"",
	  "url"=>"",
	  "info"=>"",
	  "tags"=>"",
	  "seo"=>"",
	  "class"=>""
	  ));
	  CmlView::assign('picdata',$picdata);
	  CmlView::display();
	}
	//保存图片
	public function addpicssave(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){
		$classid=getGp('classid',2);
			$title=getGp('gcmstitle',2);
			$url=getGp('gcmsurl',2);
			$info=getGp('gcmsinfo',2);
			$tags=getGp('gcmstags',2);
			$seo=getGp('gcmsseo',2);
	    $PicModel = new PicModel();
	    $picok=$PicModel->addpic($title,$url,$tags,$seo,$info,$classid,0);
	    if ($picok == true){
	    	$this->success('添加图片成功','pic/pics&classid='.$classid);
			} else {
				$this->error('添加图片失败','pic/addpics');
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
	}
	
	//修改图片
	public function editpics(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		$id=getGp('id');
	  $PicModel = new PicModel();
		$picdata=$PicModel->editpic($id);
	  CmlView::assign('picdata',$picdata);
		CmlView::display('addpics');
	}
	//保存修改图片
	public function editpicssave(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){
		$id=getGp('id',2);
		$classid=getGp('classid',2);
			$title=getGp('gcmstitle',2);
			$url=getGp('gcmsurl',2);
			$info=getGp('gcmsinfo',2);
			$tags=getGp('gcmstags',2);
			$seo=getGp('gcmsseo',2);
	    $PicModel = new PicModel();
	    $picok=$PicModel->editpicsave($id,$title,$url,$tags,$seo,$info,$classid,0);
	    if ($picok == true){
	    	$this->success('修改图片成功','pic/pics&classid='.$classid);
			} else {
				$this->error('修改图片失败','pic/pics&classid='.$classid);
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
}
