⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directory.jsp

📁 这是一个用JAVA语言编写的BBS论坛程序
💻 JSP
字号:
<%
/*
 * Copyright:  Copyright (c) 2004 
 * @author http://hi.baidu.com/lael80*/
%>
<%@ page contentType="text/html; charset=gb2312" errorPage=""%>
<%@ include file="head.jsp"%>

<br>
<%
if(!workFC.cNULL(String.valueOf(session.getAttribute("u_name")))){
  response.sendRedirect("result.jsp?errcodes="+workFC.GBtoUni("<li>您还没注册或登录,没权查看地址簿"));
  return;
}
int friend=1,i=0;
String temp1="",temp2="";
try{
 friend=Integer.parseInt(request.getParameter("friend"));
 if(friend!=1&&friend!=2)friend=1;
}catch(Exception e){}

String[] chkarray=request.getParameterValues("chkbox");
String errcodes="";

if(workFC.cNULL(request.getParameter("submit1"))){
  int select1=Integer.parseInt(request.getParameter("select1"));
  if(select1!=friend){
    if(select1==1){
      temp1=","+workDB.queryData("select user_baddy from user_info where user_name='"+session.getAttribute("u_name")+"'");
      temp2=","+workDB.queryData("select user_friend from user_info where user_name='"+session.getAttribute("u_name")+"'");
    }else{
      temp1=","+workDB.queryData("select user_friend from user_info where user_name='"+session.getAttribute("u_name")+"'");
      temp2=","+workDB.queryData("select user_baddy from user_info where user_name='"+session.getAttribute("u_name")+"'");
    }
    try{
      for(i=0;i<chkarray.length;i++){
         temp1=temp1.replaceAll(","+workFC.UnitoGB(chkarray[i])+",",",");
         if(workDB.queryCount("select count(user_id) from user_info where user_name='"+chkarray[i]+"' and user_type>0")!=0){
           response.sendRedirect("result.jsp?errcodes="+workFC.GBtoUni("<li>不能添加管理员或版主入黑名单"));
           return;
         }
         if(temp2.indexOf(","+workFC.UnitoGB(chkarray[i])+",")==-1)temp2+=workFC.UnitoGB(chkarray[i])+",";
      }
      if(select1==1){
        workDB.executeUpdate("update user_info set user_baddy=substring('"+workFC.GBtoUni(temp1)+"',2) where user_name='"+session.getAttribute("u_name")+"'");
        workDB.executeUpdate("update user_info set user_friend=substring('"+workFC.GBtoUni(temp2)+"',2) where user_name='"+session.getAttribute("u_name")+"'");
      }else{
        workDB.executeUpdate("update user_info set user_friend=substring('"+workFC.GBtoUni(temp1)+"',2) where user_name='"+session.getAttribute("u_name")+"'");
        workDB.executeUpdate("update user_info set user_baddy=substring('"+workFC.GBtoUni(temp2)+"',2) where user_name='"+session.getAttribute("u_name")+"'");
      }
    }catch(Exception e){}
  }   
}

if(workFC.cNULL(request.getParameter("submit2"))){
  String temp;
  if(friend==1){
    temp="user_friend";
  }else temp="user_baddy";
  temp1=","+workDB.queryData("select "+temp+" from user_info where user_name='"+session.getAttribute("u_name")+"'");
  try{
    for(i=0;i<chkarray.length;i++){
       temp1=temp1.replaceAll(","+workFC.UnitoGB(chkarray[i])+",",",");
    }
    workDB.executeUpdate("update user_info set "+temp+"=substring('"+temp1+"',2) where user_name='"+session.getAttribute("u_name")+"'");
  }catch(Exception e){}
}

if(workFC.cNULL(request.getParameter("submit3"))){
  if(friend==1){
    workDB.executeUpdate("update user_info set user_friend='' where user_name='"+session.getAttribute("u_name")+"'");
  }else{
    workDB.executeUpdate("update user_info set user_baddy='' where user_name='"+session.getAttribute("u_name")+"'");
  }
}

if(workFC.cNULL(request.getParameter("submit4"))){
  int select2=Integer.parseInt(request.getParameter("select2"));
  String friend_name[]=request.getParameter("friend_name").split(",");
  if(friend_name.length==1&&!workFC.cNULL(friend_name[0])){
    response.sendRedirect("result.jsp?errcodes="+workFC.GBtoUni("<li>至少填写一个姓名"));
    return;
  }else if(friend_name.length>10){
    response.sendRedirect("result.jsp?errcodes="+workFC.GBtoUni("<li>一次最多可以添加10个好友,现在为"+friend_name.length+"个"));
    return;
  }
  for(i=0;i<friend_name.length;i++){
    if(!workFC.CheckStr(workFC.UnitoGB(friend_name[i]))){
      errcodes="<li>好友姓名含有非法字符";
      break;
    }
    if(!workFC.CheckLen(workFC.UnitoGB(friend_name[i]),15)){
      errcodes=errcodes+"<li>好友姓名长度不能超过15字节";
      break;
    }
  }
  for(i=0;i<friend_name.length-1;i++){
    for(int j=i+1;j<friend_name.length;j++){
       if(friend_name[j].equals(friend_name[i])){
         errcodes+="<li>姓名重复,不能多次添加";
         i=friend_name.length;  
         break;
       }
    }  
  }
  if(workFC.cNULL(errcodes)){
    response.sendRedirect("result.jsp?errcodes="+workFC.GBtoUni(errcodes));
    return;
  }   
  if(select2==1){
    temp1=","+workDB.queryData("select user_friend from user_info where user_name='"+session.getAttribute("u_name")+"'");
    temp2=","+workDB.queryData("select user_baddy from user_info where user_name='"+session.getAttribute("u_name")+"'");
    for(i=0;i<friend_name.length;i++){
       if(friend_name[i].equals(session.getAttribute("u_name"))){
         errcodes+="<li>不能添加自己";
       }else if(workDB.queryCount("select count(user_id) from user_info where user_name='"+friend_name[i]+"'")==0){
         errcodes="<li>姓名 "+workFC.UnitoGB(friend_name[i])+" 不存在";
       }else if(temp2.indexOf(","+workFC.UnitoGB(friend_name[i])+",")!=-1){
         errcodes+="<li>"+workFC.UnitoGB(friend_name[i])+" 已经在您的黑名单中,请使用批量转换加为好友";
       }else if(temp1.indexOf(","+workFC.UnitoGB(friend_name[i])+",")!=-1){
         errcodes+="<li>"+workFC.UnitoGB(friend_name[i])+" 已经是您的好友";
       }else if(temp1.indexOf(","+workFC.UnitoGB(friend_name[i])+",")==-1){
         errcodes+="<li>添加好友 "+workFC.UnitoGB(friend_name[i])+" 成功";
         temp1+=workFC.UnitoGB(friend_name[i])+",";
       }
    }
    workDB.executeUpdate("update user_info set user_friend=substring('"+workFC.GBtoUni(temp1)+"',2) where user_name='"+session.getAttribute("u_name")+"'");
  }else{
    temp1=","+workDB.queryData("select user_baddy from user_info where user_name='"+session.getAttribute("u_name")+"'");
    temp2=","+workDB.queryData("select user_friend from user_info where user_name='"+session.getAttribute("u_name")+"'");
    for(i=0;i<friend_name.length;i++){
       if(friend_name[i].equals(session.getAttribute("u_name"))){
         errcodes+="<li>不能添加自己";
       }else if(workDB.queryCount("select count(user_id) from user_info where user_name='"+friend_name[i]+"'")==0){
         errcodes+="<li>姓名 "+workFC.UnitoGB(friend_name[i])+" 不存在";
       }else if(workDB.queryCount("select count(user_id) from user_info where user_name='"+friend_name[i]+"' and user_type>0")!=0){
         errcodes="<li>不能添加管理员或版主入黑名单";
       }else if(temp2.indexOf(","+workFC.UnitoGB(friend_name[i])+",")!=-1){
         errcodes+="<li>"+workFC.UnitoGB(friend_name[i])+" 已经在您的好友名单中,请使用批量转换到黑名单";
       }else if(temp1.indexOf(","+workFC.UnitoGB(friend_name[i])+",")!=-1){
         errcodes+="<li>"+workFC.UnitoGB(friend_name[i])+" 已经在您的黑名单里";
       }else if(temp1.indexOf(","+workFC.UnitoGB(friend_name[i])+",")==-1){
         errcodes+="<li>添加 "+workFC.UnitoGB(friend_name[i])+" 到黑名单成功";
         temp1+=workFC.UnitoGB(friend_name[i])+",";
       }
    }
    workDB.executeUpdate("update user_info set user_baddy=substring('"+workFC.GBtoUni(temp1)+"',2) where user_name='"+session.getAttribute("u_name")+"'");
  }
  if(workFC.cNULL(errcodes)){
     response.sendRedirect("result.jsp?errcodes="+workFC.GBtoUni(errcodes));
     return;
  } 
}

if(friend==1)temp1=workDB.queryData("select user_friend from user_info where user_name='"+session.getAttribute("u_name")+"'");
if(friend==2)temp1=workDB.queryData("select user_baddy from user_info where user_name='"+session.getAttribute("u_name")+"'");
String fdlist[]=temp1.split(",");
urlpath="friend="+friend;
%>
<%=tabletop%>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1">
  <tr>
   <td height="25" colspan="2" class="b1">&nbsp;</td>
  </tr>
  <tr>
   <td align="center" colspan="2">
    <a href="message.jsp"><img src="images/msgbox.gif"></a>&nbsp;
    <a href="message.jsp?send=1"><img src="images/msgsend.gif"></a>&nbsp;
    <a href="directory.jsp"><img src="images/msgdirectory.gif"></a>&nbsp;
    <a href="sendmsg.jsp"><img src="images/msgnew.gif"></a>
   </td>
  </tr>
  <tr height="25" class="style3">
   <td width="14%" align="center" valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="2">
     <tr>
       <td width="100%" height="25" align="center" class="b1">组名</td>
     </tr>
     <tr>
       <td align="center"><strong><a href="directory.jsp?friend=1">我的好友</a></strong></td>
     </tr>
     <tr>
       <td align="center"><strong><a href="directory.jsp?friend=2">黑名单</a></strong></td>
     </tr>
   </table></td>
   <td width="86%" align="center" valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="2">
     <tr height="25" align="center" valign="middle" class="b1">
       <td width="13%">组名</td>
       <td width="22%"><strong>姓名</strong></td>
       <td width="46%"><strong>邮箱</strong></td>
       <td width="10%"><strong>留言</strong></td>
       <td width="9%"><strong>操作</strong></td>
     </tr>
     <form name="form1" method="post" action="directory.jsp?friend=<%=friend%>">
<%
try{
 pageid=Integer.parseInt(request.getParameter("pageid"));
}catch(Exception e){pageid=1;}

int count_all=fdlist.length;
int count_page=(count_all+19)/20;
int count_now=20;
if(count_page==pageid)count_now=count_all-(count_page-1)*20;
if(fdlist.length==1&&!workFC.cNULL(fdlist[0])){count_all=0;count_page=1;count_now=0;}
if(pageid<1||pageid>count_page)pageid=1;

for(i=(pageid-1)*20;i<(pageid)*20;i++){
 if(i==fdlist.length)break;
 if(workFC.cNULL(fdlist[i])){
   String userdata=workDB.queryData("select user_mail from user_info where user_name='"+fdlist[i]+"'");
   out.println("<tr align='center' valign='middle'><td>");
   out.println((friend==1?"我的好友":"黑名单")+"</td><td>");
   out.println("<a href='userinfo.jsp?name="+fdlist[i]+"'>"+fdlist[i]+"</td><td>");
   out.println("<a href='mailto:"+userdata+"'>"+userdata+"</td><td>");
   out.println("<a href='sendmsg.jsp?name="+fdlist[i]+"'>留言</a></td><td>");
   out.println("<input type='checkbox' name='chkbox' value='"+fdlist[i]+"'></td></tr>");
 }
}
%>
     <tr>
       <td height="25" colspan="5">
      <table width="100%" border="0" cellpadding="2" cellspacing="0">
      <tr valign="middle"><td width="50%">
      <%="&nbsp;页次:"+pageid+"/"+count_page+"页&nbsp;本页:"+count_now+"&nbsp;统计:"+count_all%>  
      </td><td align="right">
      <%=workFC.ShowPage(count_page,pageid,"directory.jsp?"+urlpath+"&pageid")%>
    &nbsp;
       </td></tr>
      </table>
       </td>
     </tr>
     <tr align="right" valign="middle" class="style4">
       <td colspan="5">
         <input type="checkbox" name="chkall" value="0" onclick="chkedall();">选中所有显示的记录
         <select name="select1">
           <option value="1" selected>批量转移</option>
           <option value="1">我的好友</option>
           <option value="2">黑名单</option>
         </select>
         <input type="submit" name="submit1" value="转移">
         <input type="submit" name="submit2" value="删除所选">
         <input type="submit" name="submit3" value="清空记录">
         &nbsp;</td>
       </tr>
      </form>
   </table></td>
  </tr>
  <form name="form2" method="post" action="directory.jsp?friend=<%=friend%>">
  <tr align="center">
    <td colspan="2" valign="middle"><input name="friend_name" type="text" size="50" maxlength="160">
      <select name="select2">
        <option value="1" selected>选择分组</option>
        <option value="1">我的好友</option>
        <option value="2">黑名单</option>
      </select>
    <br>
    (使用( , )号隔开,一次最多可添加10个)<br>
    <input type="submit" name="submit4" value="保存">
&nbsp;&nbsp;
<input type="reset" name="submit5" value="清除"></td>
  </tr>
  </form>
</table>
<%=tablebottom%>
<br>
<%@ include file="footer.jsp"%>
<script language="javascript">
<!--
function chkedall(){  
  for(var i=0;i<document.form1.elements.length;i++){  
    if(document.form1.elements[i].name!='chkall')
      document.form1.elements[i].checked=document.form1.chkall.checked;  
  }
}
//-->
</script>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -