<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class form_indexAction extends security_login {
	function action(){
		//接收参数并放入Session
		ModuleLimit(__CLASS__);
		$miceSession = new session();

		if($_POST['view']<>'' and ($_POST['view']==0 or $_POST['view']==1 or $_POST['view']==2)){
			$miceSession->set('fi_view',$_POST['view']);
		}else{
			$miceSession->set('fi_view',3);
		}

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

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

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

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


		//组合sql
		$subsql=' WHERE (type=\'guestbook\') ';
		if($miceSession->get('fi_keywords')!='标题或正文中的部分文字'){
			$subsql.=' AND (title LIKE \'%'.$miceSession->get('fi_keywords').'%\' OR content LIKE \'%'.$miceSession->get('fi_keywords').'%\')';
		}
		if($miceSession->get('fi_view')==0 or $miceSession->get('fi_view')==1 or $miceSession->get('fi_view')==2){
			$subsql.=' AND isopen='.$miceSession->get('fi_view');
		}
		if($miceSession->get('fi_orders')=='cd'){
			$subsql.=' ORDER BY createdat DESC';
		}elseif($miceSession->get('fi_orders')=='ca'){
			$subsql.=' ORDER BY createdat';
		}else{
			$subsql.=' ORDER BY createdat DESC';
		}

		

		//查找
		global $conn;
		$form=new model_Form();
		$form->setSubsection($subsql);
		$form->setPagenum($miceSession->get('fi_page'));
		$form->setPages($miceSession->get('fi_pages'));
		$formrs=$form->Pager();
		$pager=MicePager($form->TotalPages(),$form->Totals(),$form->Page(),5,MICE_URL.'admin.php/form/page/');

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileAdmin');

		$smarty->assign('index',MICE_URL.'admin.php/form');
		$smarty->assign('view',MICE_URL.'admin.php/form/view/form_id/');
		$smarty->assign('status',MICE_URL.'admin.php/form/status/form_id/');
		$smarty->assign('edit',MICE_URL.'admin.php/form/edit/form_id/');
		$smarty->assign('delete',MICE_URL.'admin.php/form/delete/form_id/');
		$smarty->assign('open',MICE_URL.'admin.php/form/open/form_id/');
		$smarty->assign('notopen',MICE_URL.'admin.php/form/notopen/form_id/');

		$smarty->assign('keywords',$miceSession->get('fi_keywords'));
		$smarty->assign('pages',$miceSession->get('fi_pages'));
		$smarty->assign('orders',$miceSession->get('fi_orders'));
		$smarty->assign('view',$miceSession->get('fi_view'));

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