<?php 
require "../Run.php";
require "view/list.view.php";

if($login!=1){
 header("location: http://".$_SERVER['HTTP_HOST']."/login.php?&backurl=".url_info_zm($_SERVER['HTTP_HOST'].'/user/myfriend.php',1));
}
$css='<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	min-width:320px;
}
.f_sub {
	font-family: "微软雅黑";
	background-color: #efefef;
	padding-top: 5px;
	padding-bottom: 5px;
	padding-left: 10px;
}
.f_list{
	list-style:none;
	margin:0px;
	padding:0px;
	}
.f_list li {
	height:50px;
	border-bottom:1px solid #ccc;
	background-color:#FFF;
	}
.left{
	height:50px;
	width:50px;
	}
.right{

	height:50px;
	}
.right a{
	float:left;
	width:100%;
	}
.f_list li img {
	margin:5px;
	width:40px;
	height:40px;
	border :none;
	}
.f_list li h2{
	margin:0px;
	padding:0px;
	font-size:17px;
	margin-top:5px;
	color:#222;
	
	}
.f_list li h3{
	
	padding:0px;
	margin:0px;
	clear:both;
	font-size:14px;
	color:#ccc;
	margin-bottom:5px;
	}
table.top_bar{
	clear:both;
	height:40px;
	width:100%;
	line-height:40px;
	}
table.top_bar tr td.left{
	width:80px;
	height:40px;
	text-align:center;
	}
table.top_bar tr td.right{
	width:80px;
	height:40px;
	text-align:center;
	}
table.topbar tr td.center {
	text-align:center;
	}
#my_f_sel{
	height:30px;
	width:160px;
	border:1px solid #328cc9;
	text-align:center;
	clear:both;
	line-height:30px;
	}
#my_f_sel tr td{
	width:50%;
	}
#sell{
	background-color:#328cc9}
.my_sub_bar{
  width:100%;
  border-bottom:1px solid #ccc; 
  clear:both;
  }
.my_sub_bar tr td{
 width:25%;
 text-align:center;
 color:#ccc;
 font-size:15px;
 }
 .my_sub_bar tr td img {
 width:50px;
 height:50px;
 text-align:center;
 margin-top:10px;
 }
</style>';
$type=$_GET['type'];
echo head('我的好友',$css);
if($type=='add'){
 if($_POST['add']=='yes'){
    
 //向数据库添加好友
 if($_POST['userid']!=''&&$_POST['userid']!=$xid){//检查提交的数据是否为空
 $sql="SELECT xid,site_u,id FROM user WHERE xid='{$_POST['userid']}' AND site_u='{$wapid}'";
    $info = mysql_query($sql);
    if($info && mysql_num_rows($info)>0){//检查是否存在提交的数据，并将虚拟id转换成实际id；
    list($ser_xid,$ser_siteid,$ser_id) = mysql_fetch_row($info);
	     $sql = 'SELECT `userid`,`friendid` FROM `my_friend` WHERE friendid=\''.$ser_id.'\'';
         $cfxx = mysql_query($sql);
         if($cfxx && mysql_num_rows($cfxx) > 0){//检测是否已经添加了此好友		 
		     echo '<div class="tip">您要添加的好友已经存在喽</div>';
			}else{
			$time=time();
            $sqladd = 'INSERT INTO my_friend(userid,friendid,groid,siteid,yz,time,remarks,black) VALUES (\''.$id.'\',\''.$ser_id.'\', \''.$_POST['groid'].'\',\''.$wapid.'\', \'1\',\''.$time.'\',\' \',\'0\');'; 
            $mf = mysql_query($sqladd);
                if($mf && mysql_affected_rows()>0){
	                echo '<div class="tip">添加好友成功</div>';
	                    }else{
	                    echo '<div class="tip">添加好友失败</div>';
	                            } 
							}
		               }else{
		             echo '<div class="tip">您好，您要添加的好友不存在</div>';
		           }
		    }else{
		echo '<div class="tip">出错喽，您要添加的号码不能为空且不能添加自己哦！</div>';
		}
 }
 
require "view/addf.view.php";
}else{
require "view/myfui.view.php";
}
echo footer(1);