<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class article_indexAction extends security_login {
	function action(){
		//接收参数并放入Session
		ModuleLimit(__CLASS__);
		$miceSession = new session();
		if($this->_getParam('cid')){
			$miceSession->set('ai_categoryid',$this->_getParam('cid'));
		}elseif($_POST['categoryid']){
			$miceSession->set('ai_categoryid',$_POST['categoryid']);
		}elseif($miceSession->get('ai_categoryid')<=0 or $_POST['categoryid']=='0' or $this->_getParam('cid')=='0'){
			$miceSession->set('ai_categoryid',0);
		}

		if($_POST['userid']){
			$miceSession->set('ai_userid',$_POST['userid']);
		}elseif($miceSession->get('ai_userid')<=0 or $_POST['userid']=='0'){
			$miceSession->set('ai_userid',0);
		}

		if($_POST['keywords']){
			$miceSession->set('ai_keywords',$_POST['keywords']);
		}elseif($miceSession->get('ai_keywords')==""){
			$miceSession->set('ai_keywords','标题或正文中的部分文字');
		}

		if($_POST['pages']){
			$miceSession->set('ai_pages',$_POST['pages']);
		}elseif($miceSession->get('ai_pages')<=0 or $_POST['pages']=='15'){
			$miceSession->set('ai_pages',15);
		}

		if($_POST['orders']){
			$miceSession->set('ai_orders',$_POST['orders']);
		}elseif($miceSession->get('ai_orders')<='0'){
			$miceSession->set('ai_orders','cd');
		}

		if($this->_getParam('page')){
			$miceSession->set('ai_page',$this->_getParam('page'));
		}else{
			$miceSession->set('ai_page',1);
		}


		//组合sql
		$subsql=' WHERE type LIKE \'article%\'';
		if($miceSession->get('ai_categoryid')){
			$subsql.=' AND category_id LIKE \'%,'.$miceSession->get('ai_categoryid').',%\'';
		}
		if($miceSession->get('ai_userid')){
			$subsql.=' AND user_id = '.$miceSession->get('ai_userid');
		}
		if($miceSession->get('ai_keywords')!='标题或正文中的部分文字'){
			$subsql.=' AND (title LIKE \'%'.$miceSession->get('ai_keywords').'%\' OR content LIKE \'%'.$miceSession->get('ai_keywords').'%\')';
		}
		if($miceSession->get('ai_orders')=='cd'){
			$subsql.=' ORDER BY createdat DESC';
		}elseif($miceSession->get('ai_orders')=='ca'){
			$subsql.=' ORDER BY createdat';
		}elseif($miceSession->get('ai_orders')=='bd'){
			$subsql.=' ORDER BY browses DESC';
		}elseif($miceSession->get('ai_orders')=='ba'){
			$subsql.=' ORDER BY browses';
		}else{
			$subsql.=' ORDER BY createdat DESC';
		}

		//echo $subsql;

		

		//查找
		global $conn;
		$article=new model_Article();
		$article->setSubsection($subsql);
		$article->setPagenum($miceSession->get('ai_page'));
		$article->setPages($miceSession->get('ai_pages'));
		$articlers=$article->Pager();
		$pager=MicePager($article->TotalPages(),$article->Totals(),$article->Page(),5,MICE_URL.'admin.php/article/page/');
		
		//分类
		$category=new model_Category();
		$category->setSubsection('WHERE parentid=0 AND type LIKE \'article%\'');
		$childcount=$category->doCount();

		//获取当前分类的类别
		if($miceSession->get('ai_categoryid')){
			$category=new model_Category();
			$category->setSubsection('WHERE category_id ='.$miceSession->get('ai_categoryid'));
			$categoryrs=$category->doSelectOne();
			if($categoryrs->getType()=='article1'){
				$create=MICE_URL.'admin.php/article/editProduct/category_id/';
			}elseif($categoryrs->getType()=='article2'){
				$create=MICE_URL.'admin.php/article/editDown/category_id/';
			}elseif($categoryrs->getType()=='article3'){
				$create=MICE_URL.'admin.php/article/editVedio/category_id/';
			}elseif($categoryrs->getType()=='article4'){
				$create=MICE_URL.'admin.php/article/editJob/category_id/';
			}else{
				$create=MICE_URL.'admin.php/article/editArticle/category_id/';
			}
		}
		
		//作者
		$user=new model_User();
		$user->setSubsection(' ORDER BY postnums DESC');
		$userrs=$user->doSelect();
		foreach($userrs as $urs) {
			$username[$urs->getUserId()] = $urs->getLoginname();
		}

		$ctype=CategoryType();

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileAdmin');
		$smarty->assign('username',$username);
		$smarty->assign('userrs',$userrs);
		$smarty->assign('userid',$userid);
		$smarty->assign('categorytype',$ctype);

		$smarty->assign('index',MICE_URL.'admin.php/article');
		$smarty->assign('category',MICE_URL.'admin.php/article/cid/');
		$smarty->assign('edit',MICE_URL.'admin.php/article');
		$smarty->assign('create',$create);
		$smarty->assign('delete',MICE_URL.'admin.php/article/delete/article_id/');
		$smarty->assign('preview',MICE_URL.'index.php/article/');

		$smarty->assign('categoryid',$miceSession->get('ai_categoryid'));
		$smarty->assign('keywords',$miceSession->get('ai_keywords'));
		$smarty->assign('userid',$miceSession->get('ai_userid'));
		$smarty->assign('pages',$miceSession->get('ai_pages'));
		$smarty->assign('orders',$miceSession->get('ai_orders'));

		$smarty->assign('childcount',$childcount);
		$smarty->assign('articlers',$articlers);
		$smarty->assign('pager',$pager);
		$filename = new getTPLFileName(__CLASS__);
		$smarty->display($filename->TPLFileName);
	}
}
?>