<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.sql.*"%> 
<%@ page import="java.util.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%@ include file="checkbbsuser.jsp"%>
<%@ include file="../inc/conn.jsp"%>
<%!String sql,username,smscontent,msg,str,postusera;%>
<%
  String postuser = new String(request.getParameter("postuser").getBytes("iso-8859-1"));
  sql="select * from clubuser where clubuser_name='"+session.getAttribute("name")+"'";
  ResultSet rs=stmt.executeQuery(sql);
     rs.next();
	 String strdb=rs.getString("friend"); 
	 String strdbx=rs.getString("friend");
	 if(strdb!=null)
	    {
         int i; 
         while((i=strdb.indexOf("|"))!=-1){
         int b = strdb.lastIndexOf("|");
         int len = strdb.length();
         username=strdb.substring(b+1,len);
         strdb=strdb.substring(0,b);

		 if(postuser.indexOf(username)!=-1){
           out.print("<script language='javascript'>");
           out.print("alert('你已经加入了该用户为好友!');");
           out.print("history.go(-1);");
           out.print("</script>");
           out.close();
		   return;
           }
		 }
       }
	 
	   if(strdbx!=null){
	       postuser=strdbx+"|"+postuser;
	    }
		else{
		   postuser=session.getAttribute("bbsuser")+"|"+postuser;
		}
         msg=session.getAttribute("bbsuser")+"请求加为好友！";
         smscontent=session.getAttribute("bbsuser")+"请求加为好友！";
		 str="update clubuser set friend='"+postuser+"' where clubuser_name='"+session.getAttribute("name")+"'";

		 stmt.executeUpdate(str);
         sql="insert into sms(title,content,sender,accepter,bbssystem) values('"+msg+"','"+smscontent+"','"+session.getAttribute("name")+"','"+postuser+"',2)";
         stmt.executeUpdate(sql);
         out.print("<script language='javascript'>");
         out.print("alert('加入成功,但必须等你的好友确认!');");
         out.print("history.go(-1);");
         out.print("</script>");
         out.close();		   
	 stmt.close(); 
     conn.close();
%>