<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class User_list extends HC_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load_lang('adminsys/user_list');
		$this -> load('admin'); 
		$this -> admin -> online_admin();
		$this -> load_db();
	}
	
	function info_list(  )
	{
		
		$page_size = 20 ;		
		$keywordval 	= $this -> input ->  funpost("keyword");
		$page_num_val 	= $this -> input ->  req["page_num"];
		$searchtypeval 	= $this -> input ->  req["searchtype"];
		
		//var_dump( $searchtypeval );
		
		if( $page_num_val > 1 )
		{
			$page_num  = $page_num_val;
			$limit_num = ceil( ( $page_num_val -1 ) * $page_size );
		}else{
			$page_num  = 1;
			$limit_num = 0 ;
		}

		
		if($this -> input ->  get["keyword"] !='')
		{   
			$keywordval 	= $this -> input ->  get["keyword"];
			$keywordval  	= urldecode($keywordval); 
		}
		if($keywordval!='')
		{ 	
			//$endArray["keyword"] =$keywordval;
			$endurl 	   .= '&keyword='.urlencode($keywordval);
			
			//$whereadd .= " AND (  use_name LIKE  '%".$keywordval."%' )";
			
			if( $searchtypeval =='' )
			{
				$whereadd .= " AND (  use_name LIKE  '%".$keywordval."%' )"; 
				$searchtypeval['0'] = 'use_name';
				//$endArray["searchtype[0]"] = 'use_name';
			}else if($searchtypeval[0] !='' and $searchtypeval[1] !='')
			{
				$whereadd .= " AND  (  ".$searchtypeval[0]." LIKE  '%".$keywordval."%' OR ".$searchtypeval[1]." LIKE  '%".$keywordval."%' )";
				//$endArray["searchtype[0]"] =$searchtypeval[0];
				//$endArray["searchtype[1]"] =$searchtypeval[1];
			}else if($searchtypeval[0] !='' and $searchtypeval[1] =='')
			{
				$whereadd .= " AND  (  ".$searchtypeval[0]." LIKE  '%".$keywordval."%' )";
				//$endArray["searchtype[0]"] =$searchtypeval[0];
			}else if( $searchtypeval[0] =='' and $searchtypeval[1] !='')
			{
				$whereadd .= " AND  (  ".$searchtypeval[1]." LIKE  '%".$keywordval."%' )";
				//$endArray["searchtype[1]"] =$searchtypeval[1];
			}

			
		}
		
		
		//echo $whereadd;
		//exit();

		$listval  = $this -> input ->  get["listval"];
		$listtype = $this -> input ->  get["listtype"];

		$orderbyval = "";
		if($listval!='' and $listtype =='DESC' )
		{
			//$endArray["listtype"] = 'DESC';
			//$endArray["listval"]  = $listval;
			$orderbyval = $listval ."  DESC ";
			$listhtml = '';	//反向排序参数
			
		}elseif($listval!='' )
		{
			$orderbyval = $listval;
			$listhtml = 'DESC';
			
			//$endArray["listtype"] = '';
			//$endArray["listval"]  = $listval;

		}else{
			//$endArray["listtype"] = 'DESC';
			//$endArray["listval"]  = 'use_id';
			$orderbyval = " `use_id` DESC , `use_regtime` DESC ";	
		}
		

		//var_dump( $searchtypeval );

		 //["searchtype"]=> array(5) { [0]=> string(9) "user_name" [3]=> string(10) "userd_nick" [4]=> string(8) "userd_qq" [5]=> string(12) "userd_mobile" [6]=> string(5) "phone" }
		
		//帐号 	真实姓名 	Email地址 	登录次数 	加入时间 	最后登录时间
		
		echo $sql_query = " SELECT use_id, use_name,  use_email, use_locked, use_logcount ,use_reg_time ,use_login_time  FROM  ".$this -> db -> prefix."users  WHERE 1  $whereadd  GROUP BY use_id ORDER BY  $orderbyval LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."user  WHERE 1 $whereadd  ORDER BY `use_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=user&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"], $endArray );
		
		
		$this -> view -> assign('searchtype',$searchtypeval);
		
		$this -> view -> assign('listval',$listval);
		$this -> view -> assign('listtype',$listtype);
 
		$this -> view -> assign('keywordval',$keywordval);
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('user.tpl');
		
		
	}
	
	function select_user(  )
	{

		$page_size = 20 ;		
		$keywordval 	= $this -> input ->  funpost("keyword");
		$page_num_val 	= $this -> input ->  req["page_num"];
		$searchtypeval 	= $this -> input ->  req["searchtype"];
		
		//var_dump( $searchtypeval );
		
		if( $page_num_val > 1 )
		{
			$page_num  = $page_num_val;
			$limit_num = ceil( ( $page_num_val -1 ) * $page_size );
		}else{
			$page_num  = 1;
			$limit_num = 0 ;
		}

		
		if($this -> input ->  get["keyword"] !='')
		{   
			$keywordval 	= $this -> input ->  get["keyword"];
			$keywordval  	= urldecode($keywordval); 
		}
		if($keywordval!='')
		{ 	
			//$endArray["keyword"] =$keywordval;
			$endurl 	   .= '&keyword='.urlencode($keywordval);
			
			//$whereadd .= " AND (  use_name LIKE  '%".$keywordval."%' )";
			
			if( $searchtypeval =='' )
			{
				$whereadd .= " AND (  use_name LIKE  '%".$keywordval."%' )"; 
				$searchtypeval['0'] = 'use_name';
				//$endArray["searchtype[0]"] = 'use_name';
			}else if($searchtypeval[0] !='' and $searchtypeval[1] !='')
			{
				$whereadd .= " AND  (  ".$searchtypeval[0]." LIKE  '%".$keywordval."%' OR ".$searchtypeval[1]." LIKE  '%".$keywordval."%' )";
				//$endArray["searchtype[0]"] =$searchtypeval[0];
				//$endArray["searchtype[1]"] =$searchtypeval[1];
			}else if($searchtypeval[0] !='' and $searchtypeval[1] =='')
			{
				$whereadd .= " AND  (  ".$searchtypeval[0]." LIKE  '%".$keywordval."%' )";
				//$endArray["searchtype[0]"] =$searchtypeval[0];
			}else if( $searchtypeval[0] =='' and $searchtypeval[1] !='')
			{
				$whereadd .= " AND  (  ".$searchtypeval[1]." LIKE  '%".$keywordval."%' )";
				//$endArray["searchtype[1]"] =$searchtypeval[1];
			}

			
		}
		
		
		//echo $whereadd;
		//exit();

		$listval  = $this -> input ->  get["listval"];
		$listtype = $this -> input ->  get["listtype"];

		$orderbyval = "";
		if($listval!='' and $listtype =='DESC' )
		{
			//$endArray["listtype"] = 'DESC';
			//$endArray["listval"]  = $listval;
			$orderbyval = $listval ."  DESC ";
			$listhtml = '';	//反向排序参数
			
		}elseif($listval!='' )
		{
			$orderbyval = $listval;
			$listhtml = 'DESC';
			
			//$endArray["listtype"] = '';
			//$endArray["listval"]  = $listval;

		}else{
			//$endArray["listtype"] = 'DESC';
			//$endArray["listval"]  = 'use_id';
			$orderbyval = " `use_id` DESC , `use_regtime` DESC ";	
		}
		

		//var_dump( $searchtypeval );

		 //["searchtype"]=> array(5) { [0]=> string(9) "user_name" [3]=> string(10) "userd_nick" [4]=> string(8) "userd_qq" [5]=> string(12) "userd_mobile" [6]=> string(5) "phone" }
		
		//帐号 	真实姓名 	Email地址 	登录次数 	加入时间 	最后登录时间
		
		echo $sql_query = " SELECT use_id, use_name,  use_email, use_locked, use_log_count ,use_reg_time ,use_login_time  FROM  ".$this -> db -> prefix."users  WHERE 1  $whereadd  GROUP BY use_id ORDER BY  $orderbyval LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."user  WHERE 1 $whereadd  ORDER BY `use_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=user&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"], $endArray );
		
		
		$this -> view -> assign('searchtype',$searchtypeval);
		
		$this -> view -> assign('listval',$listval);
		$this -> view -> assign('listtype',$listtype);
 
		$this -> view -> assign('keywordval',$keywordval);
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);


		$this -> view -> display('select_user.tpl');
	}
	
	
	
	
	
}

