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

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

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

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

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


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

		$smarty->assign('filecategoryid',$miceSession->get('mv_filecategoryid'));
		$smarty->assign('keywords',$miceSession->get('mv_keywords'));
		$smarty->assign('orders',$miceSession->get('mv_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);
	}
}
?>