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

		if($_POST['statusid']!=''){
			$miceSession->set('ui_statusid',$_POST['statusid']);
		}elseif($miceSession->get('ui_statusid')<0 or $_POST['statusid']==''){
			$miceSession->set('ui_statusid',-1);
		}

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

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

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

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


		//组合sql
		$subsql=' WHERE 1=1';
		if($miceSession->get('ui_levelid')){
			$subsql.=' AND usergroup_id ='.$miceSession->get('ui_levelid');
		}
		if($miceSession->get('ui_statusid')>=0){
			$subsql.=' AND status = '.$miceSession->get('ui_statusid');
		}
		if($miceSession->get('ui_keywords')){
			$subsql.=' AND loginname LIKE \'%'.$miceSession->get('ui_keywords').'%\'';
		}
		if($miceSession->get('ui_orders')=='rd'){
			$subsql.=' ORDER BY regdate DESC';
		}elseif($miceSession->get('ui_orders')=='ra'){
			$subsql.=' ORDER BY regdate';
		}elseif($miceSession->get('ui_orders')=='ld'){
			$subsql.=' ORDER BY lastlogindate DESC';
		}elseif($miceSession->get('ui_orders')=='la'){
			$subsql.=' ORDER BY lastlogindate';
		}elseif($miceSession->get('ui_orders')=='pd'){
			$subsql.=' ORDER BY postnums DESC';
		}elseif($miceSession->get('ui_orders')=='pa'){
			$subsql.=' ORDER BY postnums';
		}else{
			$subsql.=' ORDER BY regdate desc';
		}

		

		//查找
		global $conn;
		$user=new model_User();
		$user->setSubsection($subsql);
		$user->setPagenum($miceSession->get('ui_page'));
		$user->setPages($miceSession->get('ui_pages'));
		$users=$user->Pager();
		$pager=MicePager($user->TotalPages(),$user->Totals(),$user->Page(),5,MICE_URL.'admin.php/user/page/');

		$usergroup=new model_Usergroup();
		$usergroup->setSubsection('ORDER BY level');
		$usergroups=$usergroup->doSelect();


		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileAdmin');
		
		$smarty->assign('levelid',$miceSession->get('ui_levelid'));
		$smarty->assign('statusid',$miceSession->get('ui_statusid'));
		$smarty->assign('keywords',$miceSession->get('ui_keywords'));
		$smarty->assign('pages',$miceSession->get('ui_pages'));
		$smarty->assign('orders',$miceSession->get('ui_orders'));

		$smarty->assign('results',$users);
		$smarty->assign('usergroups',$usergroups);
		$smarty->assign('pager',$pager);

		$smarty->assign('index',MICE_URL.'admin.php/user');
		$smarty->assign('create',MICE_URL.'admin.php/user/edit');
		$smarty->assign('edit',MICE_URL.'admin.php/user/edit/user_id/');
		$smarty->assign('delete',MICE_URL.'admin.php/user/delete/user_id/');

		$filename = new getTPLFileName(__CLASS__);
		$smarty->display($filename->TPLFileName);
	}
}
?>