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

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

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

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

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


		//组合sql
		$subsql=' WHERE type = \'mFile\'';
		if($miceSession->get('mf_filecategoryid')){
			$subsql.=' AND filecategory_id = '.$miceSession->get('mf_filecategoryid');
		}
		if($_POST['sdate'] AND $_POST['edate']){
			$subsql.=' AND( createdat > '.Time2Num($_POST['sdate']).' AND createdat < '.Time2Num($_POST['edate'].' 23:59:59').' )';
		}
		if($miceSession->get('mf_keywords')!='标题或简介中的部分文字'){
			$subsql.=' AND (title LIKE \'%'.$miceSession->get('mf_keywords').'%\' OR summary LIKE \'%'.$miceSession->get('mf_keywords').'%\')';
		}
		if($miceSession->get('mf_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('mf_page'));
		$file->setPages(18);
		$filers=$file->Pager();
		$pager=MicePager($file->TotalPages(),$file->Totals(),$file->Page(),5,MICE_URL.'admin.php/mfile/page/');
		
		//分类
		$category=new model_Filecategory();
		$category->setSubsection('WHERE parentid=0 AND type = \'mfile\'');
		$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/mfile');
		$smarty->assign('category',MICE_URL.'admin.php/mfile/mfile_id/');
		$smarty->assign('edit',MICE_URL.'admin.php/mfile/edit/mfile_id/');
		$smarty->assign('create',MICE_URL.'admin.php/mfile/mini/mfile_id/');
		$smarty->assign('delete',MICE_URL.'admin.php/mfile/delete/mfile_id/');
		$smarty->assign('update',MICE_URL.'admin.php/mfile/update');

		$smarty->assign('filecategoryid',$miceSession->get('mf_filecategoryid'));
		$smarty->assign('keywords',$miceSession->get('mf_keywords'));
		$smarty->assign('orders',$miceSession->get('mf_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);
	}
}
?>