<?
		$listuser -> checklogin($_SESSION["member"]->uid);
		
		switch($act){
				case "add":
						$act = "add";
						break;
				case "delet":
						$act = "delet";
						break;
				case "deletok":
						$act = "deletok";
						break;
				default:
						$act = "show";
						break;
		}
		
		if($act== "show"){
			
				/*自定义数据*/$pagelistsize = 10;//每页显示条数
				$totalfriend = $db->query_num("select friendsid from ".JIEQI_DB_PREFIX."_system_friends where myid = ".$_SESSION["member"]->uid);
				$totalpage = ceil($totalfriend/$pagelistsize);
				$page = isset($page)?intval($page):"1";
				$totalpage = ($totalpage==0)?1:intval($totalpage);
				$page = ($page>$totalpage)?($totalpage):($page);
				$page = ($page<1)?(1):($page);
				$sqlstart = ($page-1)*$pagelistsize;
    		
											
				$smartyObj->assign('getfriend',$db->query_array("select friendsid,yourid,yourname from ".JIEQI_DB_PREFIX."_system_friends where myid = ".$_SESSION["member"]->uid." order by friendsid desc limit ".$sqlstart.",".$pagelistsize));	
										
    		$smartydate = array("pagetitle" => "我的好友",
    											"totalfriend" => $totalfriend,
													"totalpage" => $totalpage,
													"page" => $page,
													"pagelistsize" => $pagelistsize,
													"data" => array(),
														);
    		
				$tplpath = "user/friend.tpl";
				
		}elseif($act == "add"){
				
				$iserror = 0;
				$uid = isset($uid)?intval($uid):0;
				
				$showuserexperience = $listuser->getuserdate("experience",$_SESSION["member"]->uid);
				
				$maxfriendsnum = ($jieqiRight['system']['maxfriends']['honors'][$listuser->getmemberlevel($showuserexperience,"level")]=="") ? ($jieqiConfigs['system']['maxfriends']) : $jieqiRight['system']['maxfriends']['honors'][$listuser->getmemberlevel($showuserexperience,"level")];
				$nowfriendsnum = $db->query_num("select friendsid from ".JIEQI_DB_PREFIX."_system_friends where myid=".$_SESSION["member"]->uid);
				$nowfriendsnum = $nowfriendsnum ? $nowfriendsnum : 0;
				
				if($_SESSION["member"]->uid == $uid and $iserror == 0){
						$iserror = 1;
						$pagecontent = "<b>添加失败</b><br/>";
						$pagecontent .= "您不能添加您自己为好友！<br/>";
						$url = array("uid"=>$uid);
						$tourl = URL_user_space($url);
				}
				
				if($maxfriendsnum <= $nowfriendsnum and $iserror == 0){
						$iserror = 1;
						$pagecontent = "<b>添加失败</b><br/>";
						$pagecontent .= "您的好友已达到当前等级上限".$maxfriendsnum."人！<br/>";
						$url = array("uid"=>$uid);
						$tourl = URL_user_space($url);
				}
				
				if($iserror == 0){
						$isfriend = $db->query_num("select friendsid from ".JIEQI_DB_PREFIX."_system_friends where myid=".$_SESSION["member"]->uid." and yourid=".$uid);
						if($isfriend){
								$iserror = 1;
								$pagecontent = "<b>添加失败</b><br/>";
								$pagecontent .= "对方已经是您的好友！<br/>";
								$url = array("uid"=>$uid);
								$tourl = URL_user_space($url);
						}
				}
				
				if($iserror == 0){
						$showuser = $db->query_object("select * from ".JIEQI_DB_PREFIX."_system_users where uid=".$uid);
						if(!$showuser){
								$iserror = 1;
								$pagecontent = "<b>添加失败！</b><br/>";
								$pagecontent .= "不存在该用户！<br/>";
								$url = array();
								$tourl = URL_user_my_space($url);
						}
				}
		
				if($iserror == 0){
						$db->query_num("INSERT INTO ".JIEQI_DB_PREFIX."_system_friends (adddate,myid,myname,yourid,yourname,teamid,team,fset,state,flag) VALUE('".time()."',".$_SESSION["member"]->uid.",'".$_SESSION["member"]->name."',".$uid.",'".$listuser->getuserdate("name",$uid)."',0,'','',0,0)");
						$pagecontent = "<b>添加成功</b><br/>";
						$pagecontent .= "您已成功添加对方为您的好友！<br/>";
						$url = array("uid"=>$uid);
						$tourl = URL_user_space($url);
				}
				
				$smartydate = array("pagetitle" => "删除信息",
												"pagecontent" => $pagecontent,
												"tourl" => $tourl,
												"redirecturl" => $tourl,
												);
												
				$tplpath = "public.tpl";
				
		}elseif($act == "delet"){
				
				$iserror = 0;
				$uid = isset($uid)?intval($uid):0;
				
				$friend = $db->query_object("select * from ".JIEQI_DB_PREFIX."_system_friends where friendsid=".$uid." and myid=".$_SESSION["member"]->uid);
				
				if(!$friend){
						$iserror = 1;
						$pagecontent = "<b>删除好友失败！</b><br/>";
						$pagecontent .= "对方不是您的好友！<br/>";
						$url = array("act" => "",
												"uid" => "",
												"page" => "",
												);
						$tourl = URL_user_friend($url);
				}else{
					
						$url = array("act" => "deletok",
												"uid" => $uid,
												"page" => "",
						);
						
						$urll = array("act" => "",
												"uid" => "",
												"page" => "",
						);
						
						$tourl = "";
						
						$showwords = "删除确认<br/>";
						$showwords .= "您确定要删除该好友吗<br/>";
						$showwords .= "<a href=\"".URL_user_friend($url)."\">确定</a> - <a href=\"".URL_user_friend($urll)."\">取消</a><br/>";
						
				}
				
				$smartydate = array("pagetitle" => "删除好友",
												"pagecontent" => $showwords,
												"tourl" => $tourl,
												"redirecturl" => $tourl,
												);
												
				$tplpath = "public.tpl";
				
		}elseif($act == "deletok"){
				
				$iserror = 0;
				$uid = isset($uid)?intval($uid):0;
				
				$friend = $db->query_object("select * from ".JIEQI_DB_PREFIX."_system_friends where friendsid=".$uid." and myid=".$_SESSION["member"]->uid);
				
				if(!$friend){
						$iserror = 1;
						$pagecontent = "<b>删除好友失败！</b><br/>";
						$pagecontent .= "对方不是您的好友！<br/>";
						$url = array("act" => "",
												"uid" => "",
												"page" => "",
												);
						$tourl = URL_user_friend($url);
				}else{
						
						$db->query("DELETE from ".JIEQI_DB_PREFIX."_system_friends where myid=".$_SESSION["member"]->uid." and friendsid=".$uid);
						$showwords = "好友删除成功！<br/>";
						
						$url = array("act" => "",
												"uid" => "",
												"page" => "",
						);
						
						$tourl = URL_user_friend($url);
							
				}
				
				$smartydate = array("pagetitle" => "删除好友",
												"pagecontent" => $showwords,
												"tourl" => $tourl,
												"redirecturl" => $tourl,
												);
												
				$tplpath = "public.tpl";
				
		}    
?>