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

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

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

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

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


		//组合sql
		$subsql=' WHERE type = \'mImages\'';
		if($miceSession->get('mi_filecategoryid')){
			$subsql.=' AND filecategory_id = '.$miceSession->get('mi_filecategoryid');
		}
		if($_POST['sdate'] AND $_POST['edate']){
			$subsql.=' AND( createdat > '.Time2Num($_POST['sdate']).' AND createdat < '.Time2Num($_POST['edate'].' 23:59:59').' )';
		}
		if($miceSession->get('mi_keywords')!='标题或简介中的部分文字'){
			$subsql.=' AND (title LIKE \'%'.$miceSession->get('mi_keywords').'%\' OR summary LIKE \'%'.$miceSession->get('mi_keywords').'%\')';
		}
		if($miceSession->get('mi_orders')=='cd'){
			$subsql.=' ORDER BY createdat DESC';
		}else{
			$subsql.=' ORDER BY createdat';
		}

		//echo $subsql;

		

		//查找
		global $conn;
		$file=new model_File();
		$file->setSubsection($subsql);
		$file->setPagenum($miceSession->get('mi_page'));
		$file->setPages(8);
		$filers=$file->Pager();
		$pager=MicePager($file->TotalPages(),$file->Totals(),$file->Page(),5,MICE_URL.'admin.php/mimages/page/');
		
		//分类
		$category=new model_Filecategory();
		$category->setSubsection('WHERE parentid=0 AND type = \'mimages\'');
		$childcount=$category->doCount();

		$ctype=FileCategoryType();

		$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/mimages');
		$smarty->assign('category',MICE_URL.'admin.php/mimages/mimages_id/');
		$smarty->assign('edit',MICE_URL.'admin.php/mimages/edit/mimages_id/');
		$smarty->assign('create',MICE_URL.'admin.php/mimages/mini/mimages_id/');
		$smarty->assign('delete',MICE_URL.'admin.php/mimages/delete/mimages_id/');
		$smarty->assign('update',MICE_URL.'admin.php/mimages/update');

		$smarty->assign('filecategoryid',$miceSession->get('mi_filecategoryid'));
		$smarty->assign('keywords',$miceSession->get('mi_keywords'));
		$smarty->assign('orders',$miceSession->get('mi_orders'));
		$smarty->assign('sdate',$_POST['sdate']);
		$smarty->assign('edate',$_POST['edate']);

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