<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Employee
{
	function Employee()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
	}
	
	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"]  = 'u.use_id';
			$orderbyval = " u.`use_id` DESC , u.`use_regtime` DESC ";	
		}
		
		//帐号 	真实姓名 	Email地址 	登录次数 	加入时间 	最后登录时间
		//adminsys` (`use_id` , `dep_id`,`emp_occupation`
		
		
		$sql_query = " SELECT u.use_id, u.use_name,  u.use_email, u.use_locked, u.use_logcount ,u.use_regtime ,u.use_logintime,e.emp_occupation ,d.dep_name FROM  ".$this -> db -> prefix."user as u left join  ".$this -> db -> prefix."employee as e  on   e.use_id = u.use_id left join ".$this -> db -> prefix."dept  as d on d.dep_id = e.dep_id  WHERE 1 and u.use_type = 'e'  $whereadd  GROUP BY u.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 as u  WHERE 1 $whereadd  ORDER BY u.`use_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=employee&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('employee.tpl');
		
		
	}
	
	function add(  )
	{
		
		//$this -> view ->  caching = true;
		//$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24

		$sql_query = " SELECT dep_id,dep_name, dep_parentid, dep_list  FROM  ".$this -> db -> prefix."dept  WHERE dep_enabled = 1 GROUP BY dep_id ORDER BY dep_list,`dep_id` LIMIT 0, 200 ";
		
		$infosm 		= $this -> db -> select_info($sql_query);

		$depInfo = array();
		   foreach ($infosm as $rowkey => $rowval)
		   {
		   		if($rowval["dep_parentid"] == 0)
				{
				
					$depInfo[$rowval["dep_id"]]['dep_id'] 		 = $rowval["dep_id"] ;
					$depInfo[$rowval["dep_id"]]['dep_name'] 	 = $rowval["dep_name"] ;
					$depInfo[$rowval["dep_id"]]['dep_parentid']  = $rowval["dep_parentid"] ;
					//$depInfo[$rowval["dep_id"]]['dep_enabled']   = $rowval["dep_enabled"] ;
					//$depInfo[$rowval["dep_id"]]['dep_locked']    = $rowval["dep_locked"] ;
					$depInfo[$rowval["dep_id"]]['dep_list'] 	 = $rowval["dep_list"] ;
				}else{
					$depInfo[$rowval["dep_parentid"]]['array'][] = $rowval;	
				}
		   }
		 
		// var_dump($depInfo);
		  
		$this -> view -> assign('depInfo',$depInfo);

		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=employee&act=add_info");
		$this -> view -> display('employeeadd.tpl');
	}
	
	function add_info()
	{
		
		$use_idval 			= $this -> input ->  funpost("use_id");
		$use_nameval 		= $this -> input ->  funpost("use_name");
		$use_emailval 		= $this -> input ->  funpost("use_email");
		$usd_truenameval 	= $this -> input ->  funpost("usd_truename");
		$usd_mobileval 		= $this -> input ->  funpost("usd_mobile");
		$dep_idval 			= $this -> input ->  funpost("dep_id");
		$emp_occupationval 	= $this -> input ->  funpost("emp_occupation");
		
		if($use_idval =='' and $use_nameval =='' and $use_emailval =='' and $usd_truenameval == '' and $usd_mobileval == '' )
		{
 
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=add");
			$this -> view ->  display('suggestion.tpl');
			
		}else{
			
			$addstruser = '';
			
			if($use_idval!='')
			{
				$addstruser .= " and use_id = '".$use_idval."'";
			}
			
			if($use_nameval!='')
			{
				$addstruser .= " and use_name = '".$use_nameval."' ";
			}
			
			if($use_emailval!='')
			{
				$addstruser .= " and use_email = '".$use_emailval."' ";
			}
			
			if($addstruser != ''){
				$sql_query = " SELECT use_id  FROM  ".$this -> db -> prefix."user  WHERE 1  ".$addstruser." ORDER BY `use_id` ";
				$info = $this -> db -> select_one($sql_query);
			}
			
			
			$addstruserdetail = '';
			
			if($usd_truenameval!='')
			{
				$addstruserdetail .= " and usd_truename = ".$usd_truenameval;
			}
			
			if($usd_mobileval!='')
			{
				$addstruserdetail .= " and usd_mobile = '".$usd_mobileval."' ";
			}

			
			if($addstruserdetail != ''){
				$sql_querydetail = " SELECT use_id  FROM  ".$this -> db -> prefix."userdetail  WHERE 1  ".$addstruserdetail."  ORDER BY `use_id` ";
				$infodetail = $this -> db -> select_one($sql_querydetail);
			}
			
			if( $info["use_id"] > 0)
			{
				$adduse_idval = $info["use_id"];
			}elseif($infodetail["use_id"]){
				$adduse_idval = $infodetail["use_id"];
			}
			
			if( $adduse_idval > 0 )
			{
				//MD5加密码！！
				$insertuser ="UPDATE  `".$this -> db -> prefix."user` SET use_type = 'e' WHERE  use_id =".$info["use_id"];
				$this -> db -> query_sql($insertuser);
				
				
				$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."employee  WHERE use_id = '".$adduse_idval."' ";
				
				$infoNUM = $this -> db -> select_one($sql_query);
				
				//添加或者修改部门信息
				if( $infoNUM["CNUM"] < 1 )
				{
					$insertsql ="INSERT INTO `".$this -> db -> prefix."employee` (`use_id` , `dep_id`,`emp_occupation`) VALUES ( '".$info["use_id"]."', '$dep_idval','$emp_occupationval')";
					$this -> db -> query_sql( $insertsql );	
				}else{
					$updateuserdetail = "UPDATE `".$this -> db -> prefix."employee` SET    dep_id = '".$dep_idval."',emp_occupation = '".$emp_occupationval."' WHERE  use_id = '".$use_idval."' ";
					$this -> db -> query_sql( $updateuserdetail );
				}

				
				$this -> view ->  assign('info_title',$this->lang['add_success']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=info_list");
				$this -> view ->  display('suggestion.tpl');
				
			}else{
				
				$this -> view ->  assign('info_title',$_LANG['bd_norealyerror']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=add");
				$this -> view ->  display('suggestion.tpl');	
			}
			
		}
			//var_dump($_REQUEST);
	}
 
 
	
	function delpower( )
	{
		$infoid = $this -> input ->  get["id"];
		
		//查询一下是否超级帐号
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."user  WHERE `use_id` in ( $infoid ) and use_name = '".EMPLOYEE_BASEUSER."'   ";
			
		$infocnum = $this -> db -> select_one( $sql_query );

		
		if($infocnum["CNUM"]> 0 )
		{
			$this -> view ->  assign('info_title',$_LANG['bd_deladminerror']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=info_list");
			$this -> view ->  display('suggestion.tpl');
			
		}else{
			
			$updateuser = " UPDATE `".$this -> db -> prefix."user` SET    use_type = 'u'   WHERE  use_id = '".$infoid."' ";
			$this -> db -> query_sql( $updateuser );
			
			
			$this -> view ->  assign('info_title',$this->lang['del_success']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=info_list");
			$this -> view ->  display('suggestion.tpl');
		}
		

		
	}
	
	
	function info(  )
	{
		$infoid = $this -> input ->  get["id"];
		
		$sql_query = " SELECT u.use_id ,u.use_name, u.use_email ,d.usd_truename,d.usd_sex,d.usd_nick,d.usd_birthday,d.usd_salt ,d.usd_msn,d.usd_qq,d.usd_officephone,d.usd_homephone ,d.usd_mobile,d.usd_province,d.usd_address  FROM  ".$this -> db -> prefix."user as u  left join  ".$this -> db -> prefix."userdetail as d  on d.use_id = u.use_id  WHERE u.use_id = '".$infoid."' ORDER BY u.`use_id` ";
		$info = $this -> db -> select_one( $sql_query );
		
		//var_dump( $info );
		
		//$this -> view ->  caching = true;
		//$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24 
		
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=employee&act=edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('useredit.tpl');
	
	}
	
	function infopwd(  )
	{
		$infoid = $this -> input ->  get["id"];
		
		$sql_query = " SELECT use_id ,use_name  FROM  ".$this -> db -> prefix."user   WHERE use_id = '".$infoid."' ORDER BY `use_id` ";
		$info = $this -> db -> select_one($sql_query);
		
		//$this -> view ->  caching = true;
		//$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24 
		
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=employee&act=edit_infopwd");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('usereditpwd.tpl');
	
	}
	
	function edit_info( )
	{	
	
		$use_idval 	= $this -> input ->  funpost("use_id");
				
		//$use_nameval 	= $this -> input ->  funpost("use_name"); //不可修改
		
		$use_emailval 	 = $this -> input ->  funpost("use_email");


		$addsetUp = '';
		if($use_idval !='' and $use_emailval !='' )
		{
		
			$updateuser = "UPDATE `".$this -> db -> prefix."user` SET    use_email = '".$use_emailval."'   WHERE  use_id = '".$use_idval."' ";
			
			$this -> db -> query_sql( $updateuser );
			
			$usd_truenameval 	= $this -> input ->  funpost("usd_truename");
			$usd_sexval 	 	= $this -> input ->  funpost("usd_sex");
			
			$usd_nickval 	 	= $this -> input ->  funpost("usd_nick");
			$usd_birthdayval 	= $this -> input ->  funpost("usd_birthday");
			
			$usd_saltval 	 	= $this -> input ->  funpost("usd_salt");
			$usd_msnval 	 	= $this -> input ->  funpost("usd_msn");

			$usd_qqval 			= $this -> input ->  funpost("usd_qq");
			$usd_officephoneval = $this -> input ->  funpost("usd_officephone");
			
			$usd_homephoneval 	= $this -> input ->  funpost("usd_homephone");
			$usd_mobileval 		= $this -> input ->  funpost("usd_mobile");
			
			$usd_provinceval 	= $this -> input ->  funpost("usd_province");
			$usd_addressval  	= $this -> input ->  funpost("usd_address");
			
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."userdetail  WHERE use_id = '".$use_idval."' ";
			
			$infoNUM = $this -> db -> select_one($sql_query);
			
			if( $infoNUM["CNUM"] < 1 )
			{
				
				$insertsql ="INSERT INTO `".$this -> db -> prefix."userdetail` (`use_id` , `usd_truename` , `usd_sex` , `usd_nick` , `usd_birthday` , `usd_salt` , `usd_msn` , `usd_qq` , `usd_officephone` , `usd_homephone` , `usd_mobile` , `usd_province` , `usd_address`  ) VALUES (  '$use_idval', '$usd_truenameval', '$usd_sexval', '$usd_nickval', '$usd_birthdayval', '$usd_saltval', '$usd_msnval', '$usd_qqval', '$usd_officephoneval', '$usd_homephoneval', '$usd_mobileval','$usd_provinceval','$usd_addressval')";
				$this -> db -> query_sql( $insertsql );	
				
			}else{
				
				$updateuserdetail = "UPDATE `".$this -> db -> prefix."userdetail` SET    usd_truename = '".$usd_truenameval."',usd_sex = '".$usd_sexval."',usd_nick = '".$usd_nickval."',usd_birthday = '".$usd_birthdayval."',usd_salt = '".$usd_saltval."',usd_msn = '".$usd_msnval."',usd_qq = '".$usd_qqval."',usd_officephone = '".$usd_officephoneval."',usd_homephone = '".$usd_homephoneval."',usd_mobile = '".$usd_mobileval."',usd_province = '".$usd_provinceval."',usd_address = '".$usd_addressval."'   WHERE  use_id = '".$use_idval."' ";
				$this -> db -> query_sql( $updateuserdetail );
			}
			
			

			$this -> view ->  assign('info_title',$this->lang['edit_success']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=info_list");
			$this -> view ->  display('suggestion.tpl');
				
		}else{
		
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=info&id=".$use_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}

	function edit_infopwd( )
	{	
	
		$use_idval 		 = $this -> input ->  funpost("use_id");		
		$use_pwdval 	 = $this -> input ->  funpost("use_pwd");
		$use_repwdval 	 = $this -> input ->  funpost("use_repwd");

		$addsetUp 		 = '';
		
		if($use_idval !='' and $use_pwdval !='' and  $use_repwdval !='' )
		{
			
			if($use_pwdval == $use_repwdval)
			{
				$updateuser = "UPDATE  `".$this -> db -> prefix."user` SET    use_email = '".$use_emailval."'   WHERE  use_id = '".$use_idval."' ";
			
				$this -> db -> query_sql( $updateuser );
				
				$this -> view ->  assign('info_title',$this->lang['edit_success']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=info_list");
				$this -> view ->  display('suggestion.tpl');		
					
			}else{
				
				$this -> view ->  assign('info_title',$_LANG['js_repwd']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=infopwd&id=".$use_idval);
				$this -> view ->  display('suggestion.tpl');	

			}

		}else{
		
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=infopwd&id=".$use_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}

	function powerinfo(   )
	{
		$infoid = $this -> input ->  get["id"];
		
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."user  WHERE use_id = '".$infoid."' and use_type = 'e'  ORDER BY `use_id` ";
		
		$info = $this -> db -> select_one($sql_query);
		
		
		if(EMPLOYEE_BASEUSER == $info["use_name"] ) //and EMPLOYEE_BASEUSER != $_SESSION["webAdmin"]["use_name"]
		{
			$this -> view ->  assign('info_title',$_LANG['adminbaseuser']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=info_list");
			$this -> view ->  display('suggestion.tpl');
			exit();
		}
		
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=employee&act=editpowerinfo");
		$this -> view ->  assign('info',$info);

		//一般情况是添加，修改，删除。
		$powerForm = array( 
			'companyweb' => array( 
					'product' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					'prosort' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					'article' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					'artsort' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
						'ad'  => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				 'adposition' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					 'invite' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					 'employ' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					'webmenu' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					   'vote' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false,'item'=>false),
					  'links' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					  
				   'employee' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				   'picture' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				   'picsort' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				     'video' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				   'vidsort' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				  'download' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					   'msg' => array('info_list'=>false, 'del'=>false,'replyinfo'=>false), //查看回复
					'config' => array('info_list'=>false, 'edit_info'=>false),//查看修改
					  'user' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					 
				   'employee' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				       'dept' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				 'userconfig' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				   	   'user' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				    'address' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					'message' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					
				  'bbsconfig' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				      'forum' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				  'moderator' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				     'thread' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
				      'reply' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false), 
					 
					   'book' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					  'order' => array('info_list'=>false, 'add_info'=>false,'del'=>false,'edit_info'=>false),
					  'login' => array('actpwd'=>false) //登录，登出，修改密码
								)
						);
						
/*					
$_LANG['powerArray']  = array( 'product'=>'商品管理','prosort'=>'商品分类','article'=>'文章管理' , 'artsort'=>'文章分类', 'ad'=>'广告管理','adposition' =>'广告位置',
								 'invite'=>'招聘管理','employ'=>'应聘管理' , 'webmenu'=>'网站菜单', 'vote'=>'投票调查','book' =>'预订管理','links'=>'友情连接' , 'admins'=>'管理员管理',
								  'config'=>'网站设置', 'login'=>'个人信息',
								  
								  
								  'picture'=>'图库管理','picsort'=>'图库分类',
								 'video'=>'视频管理','vidsort'=>'视频分类','download'=>'下载管理','employee'=>'职工管理','dept'=>'部门管理','userconfig'=>'注册设置','user'=>'会员管理',
								 'address'=>'客户资料','msg'=>'留言管理' ,'bbsconfig'=>'论坛信息设置','forum'=>'版块管理','moderator'=>'版主管理','thread'=>'主题管理','reply'=>'回复管理',
								 'book'=>'预订管理','order'=>'订单管理',
								 'login'=>'个人信息');
*/			
						
						
						
	 	$sql_query 	= " SELECT * FROM  ".$this -> db -> prefix."userpower  WHERE use_id = '".$infoid."' ORDER BY `use_id` ";			
		$infoclass 	= $this -> db -> select_info( $sql_query );
 		$usp_actionval = base64_decode($infoclass[0]["usp_action"]);
		
		@eval($usp_actionval);
		
		//base64_decode($addstrval);
		
		foreach($powerForm["companyweb"] as $keykey => $valval)
		{
			//echo $keykey;
			if($companywebArray[$keykey])
			{
				
				$fillArray = array_fill_keys( $companywebArray[$keykey], true);
				 
				$powerForm["companyweb"][$keykey] = array_merge( $valval ,$fillArray);
				
			}
		}
		
		//var_dump($powerForm);
		
		$this -> view ->  assign('powerForm',$powerForm);
		$this -> view ->  display('userpowerinfo.tpl');
		
	}
	
	//第一为组权限名称
	//第二为文件名称
	//第三为文件处理方法名称（数组）
	
	function editpowerinfo(  )
	{
		$use_idval 		= $this -> input ->  funpost("use_id");
		$menuval 		= $this -> input ->  funpost("menu");
		$menuitemval 	= $this -> input ->  funpost("menuitem");
		
		//echo $use_idval ;
		$usp_formval = 'companyweb';
		
		if(is_array($menuitemval))
		{

			$addstr = "\$companywebArray =  array( ";
			
			$ff = 0; 
			foreach( $menuitemval as $key => $val )
			{
				if($ff==0){
					$addstr .= "'".$key."'=> array( ";  // implode(',',$val);
				}else{
					$addstr .= ",'".$key."'=> array( ";  // implode(',',$val);
				}
				$vv = 0;
				foreach($val as $vkey =>$vval)
				{
					
					if($vv==0)
					{
						$addstr = $addstr."'".$vval."'";
					}else{
						$addstr = $addstr.",'".$vval."'";
					}
					$vv++;
				}
				$addstr .= " ) ";
				
				$ff++;
				
			}
			$addstr .= " ); ";
			
	   }

		$sql_query 	= " SELECT count(1) as CNUM   FROM  ".$this -> db -> prefix."userpower  WHERE use_id = '".$use_idval."' and usp_form = '".$usp_formval."' ORDER BY `use_id` ";
				
		$infoclass 	= $this -> db -> select_one( $sql_query );

		$addstrval = base64_encode($addstr);
		

		
		if( $infoclass["CNUM"] < 1 )
		{
			$insertsql ="INSERT INTO `".$this -> db -> prefix."userpower` (`use_id` , `usp_form` ,  `usp_action`  ) VALUES (  '$use_idval', '$usp_formval', '".$addstrval."')";
			$this -> db -> query_sql( $insertsql );		
		}else{
					
			$updatesql = "UPDATE `".$this -> db -> prefix."userpower` SET  usp_action = '".$addstrval."'  WHERE  use_id = '".$use_idval."' and  usp_form = '".$usp_formval."' ";
			$this -> db -> query_sql( $updatesql );
		}
			
		$this -> view ->  assign('info_title',$this->lang['edit_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=employee&act=powerinfo&id=".$use_idval);
		$this -> view ->  display('suggestion.tpl');
		
	}

	
	function actlogout()
	{
		$GLOBALS['WebSe'] -> dropSession();
		header("location:".ADMIN_WEBURL."/index.php?load=employee&act=act");
		exit();
	}
	
	function pwd()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		$this -> view ->  caching = true;
		$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24	
		$this -> view ->  assign('use_name',$_SESSION["emplyeeUser"]["use_name"]);
		$this -> view ->  assign('act_url',ADMIN_WEBURL."/?load=user&act=actpwd");
		$this -> view ->  display('pwd.tpl');
		//exit();
	}
	
	function actpwd()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		
		$oldpwdval  	= $this -> input ->  funpost("oldpwd");
		$use_pwdval		= $this -> input ->  funpost("use_pwd");
		$reuse_pwdval 	= $this -> input ->  funpost("reuse_pwd");
		$use_idval 		= $_SESSION["emplyeeUser"]["use_id"];
		
		$sql = " SELECT use_id  FROM ".$this -> db -> prefix."user WHERE use_id= '".$use_idval."' AND  use_pwd = '".md5($oldpwdval)."' LIMIT 1 ";
		
		$User = $this -> db -> select_one($sql);
		
		if($User["use_id"]!='')
		{
			//修改成功！
			$sqlup = " UPDATE ".$this -> db -> prefix."user  set  use_pwd = '".md5($use_pwdval)."'  WHERE  use_id= ".$use_idval;
			$this -> db -> query_sql($sqlup);
			$this -> view ->  assign('info_title',$_LANG['LA_pwdsusse']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/?load=user&act=pwd");
			$this -> view ->  display('suggestion.tpl');
			//exit();
		}else{
			//修改有误!
			$this -> view ->  assign('info_title',$_LANG['LA_pwderror']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/?load=user&act=pwd");	
			$this -> view ->  display('suggestion.tpl');
			
		}
		
		//exit();
	}
	
}

$Employee = new Employee();

?>