<?php
defined('CML_PATH') || exit();
class ArticleController extends CmlController {		
	//文章分类
	public function indexclass(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	    $IndexModel = new AclassModel();
	    $classdata=$IndexModel->indexclass();
	    CmlView::assign('classdata',$classdata);
	    CmlView::display();
	}		
		
	public function addclasssave(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){
		$classname=getGp('classname',2);
		$classseo=getGp('classseo',2);
	    $AclassModel = new AclassModel();
	    $classok=$AclassModel->addclass($classname,$classseo);
	    if ($classok == true){
	    	$this->success('添加分类成功','Article/indexclass');
			} else {
				$this->error('添加分类失败','Article/addclass');;
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
	}		
		
	public function editclass(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){
		$classid=getGp('classid',2);
		$classcid=getGp('classcid',2);
		$classname=getGp('classname',2);
		$classseo=getGp('classseo',2);
	    $AclassModel = new AclassModel();
	    $classok=$AclassModel->editclass($classid,$classcid,$classname,$classseo);
	    if ($classok == true){
	    	$this->success('修改分类成功','Article/indexclass');
			} else {
				$this->error('修改分类失败','Article/indexclass');;
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
	}		
	
	public function delclass(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		$classid=getGp('id');
		$AclassModel = new AclassModel();
		$classok=$AclassModel->delclass($classid);
		if ($classok == true){
			$this->success('删除分类成功','Article/indexclass');
		} else {
			$this->error('删除分类失败','Article/indexclass');;
		}
	}		
	
	public function addclass(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	    CmlView::display();
	}		
	//文章管理
	public function addarticle(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	  $IndexModel = new AclassModel();
	  $classdata=$IndexModel->indexclass();
	  CmlView::assign('classdata',$classdata);
	  $articledata=array(
	  "0"=>array(
	  "id"=>"",
	  "gcmsclass"=>"",
	  "gcmstitle"=>"",
	  "gcmstags"=>"",
	  "gcmsdesc"=>"",
	  "gcmscontent"=>"",
	  "gcmspic"=>"",
	  "gcmsauthor"=>"",
	  "status"=>"0"
	  ));
	  CmlView::assign('articledata',$articledata);
		CmlView::display();
	}
	
	public function addarticlesave(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){	
		list($gcmsclass,$gcmsclassseo) = explode(",",getGp('gcmsclass',2));//讲接收到的数据用explode函数分割开
		$gcmstitle=getGp('gcmstitle',2);
		$gcmstags=getGp('gcmstags',2);
		$gcmsdesc=getGp('gcmsdesc',2);
		$gcmscontent=getGp('gcmscontent',2);
		$gcmspic=getGp('gcmspic',2);
		$gcmsauthor=getGp('gcmsauthor',2);
		$status=getGp('status',2);
		$gcmstime = date('YmdHis');
	  $ArticleModel = new ArticleModel();
	  $articleok=$ArticleModel->addarticle($gcmsclass,$gcmsclassseo,$gcmstitle,$gcmstags,$gcmsdesc,$gcmscontent,$gcmspic,$gcmsauthor,$gcmstime,$status);
	    if ($articleok == true){
	    	$this->success('添加成功','Article/article');
			} else {
				$this->error('添加失败','Article/addarticle');;
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
	}	
	
	public function editarticle(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		$id=getGp('id');
	    $IndexModel = new AclassModel();
	    $classdata=$IndexModel->indexclass();
	    CmlView::assign('classdata',$classdata);
	  $ArticleModel = new ArticleModel();
		$articledata=$ArticleModel->editarticle($id);
	  CmlView::assign('articledata',$articledata);
		CmlView::display('addarticle');
	}
	
	public function editarticlesave(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		if(isset($_POST['submit']) && CmlSecure::checkToken()==true){
		$id=getGp('id',2);
		list($gcmsclass,$gcmsclassseo) = explode(",",getGp('gcmsclass',2));//讲接收到的数据用explode函数分割开
		$gcmstitle=getGp('gcmstitle',2);
		$gcmstags=getGp('gcmstags',2);
		$gcmsdesc=getGp('gcmsdesc',2);
		$gcmscontent=getGp('gcmscontent',2);
		$gcmspic=getGp('gcmspic',2);
		$gcmsauthor=getGp('gcmsauthor',2);
		$status=getGp('status',2);
	  $ArticleModel = new ArticleModel();
	  $articleok=$ArticleModel->editarticlesave($id,$gcmsclass,$gcmsclassseo,$gcmstitle,$gcmstags,$gcmsdesc,$gcmscontent,$gcmspic,$gcmsauthor,$status);
	    if ($articleok == true){
	    	$this->success('修改成功','Article/article');
			} else {
				$this->error('修改失败','Article/article');
			}
		}else
		{ 
				$this->error('非法提交','Index/logout');
		}
		CmlView::display();
	}
	
	public function delarticle(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
		$id=getGp('id');
	  $ArticleModel = new ArticleModel();
		$articleok=$ArticleModel->delarticle($id);
		if ($articleok == true){
			$this->success('删除成功','Article/article');
		} else {
			$this->error('删除失败','Article/article');;
		}
	}
	
	public function statusarticle(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		$id=getGp('id');
		$status=getGp('status');
	  $ArticleModel = new ArticleModel();
		$articleok=$ArticleModel->statusarticle($id,$status);
		if ($articleok == true){
			$this->success('操作成功','Article/article');
		} else {
			$this->error('操作失败','Article/article');;
		}
	}
			
		
	public function article(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
	  $AclassModel = new AclassModel();
	  $classdata=$AclassModel->indexclass();
	  CmlView::assign('classdata',$classdata);
		if(getGp('id')){
			$classid=getGp('id');
			}else $classid='';
	  $ArticleModel = new ArticleModel();
		$countdata=$ArticleModel->countarticle($classid);
		$pagesize=C('SITE_PAGESIZE'); //每页显示的页数
		$page = new page($countdata['0'],$pagesize);
		$pageer=$page->getPage(U('Admin/Article/article',array('id'=>$classid,'p'=>''),true,0));
		if(getGp('p')){
			$pagenum=getGp('p');
			}else $pagenum=1;
		$sqlfirst=($pagenum-1)*$pagesize;
		$articledata=$ArticleModel->indexarticle($classid,$sqlfirst,$pagesize);
		CmlView::assign('articledata',$articledata);
	    CmlView::assign('ccpages',$pageer);
		CmlView::display();
	}
	
	public function article1(){
		
		if (check_login() != true){
			$this->error('没有登陆','Index/login');
			return;
			}
			
		
	  $ArticleModel = new ArticleModel();
		$articleok=$ArticleModel->articleqq('2222222222222222');
		echo $articleok['0']['id'];
		print_r($articleok);
	}
	
}
