<!--#include file="../Include/Class_Conn.asp" -->
<!--#include file="../Public/Person_Cookies.asp" -->
<!--#include file="../Include/Class_Main.asp" -->
<% 
Dim Param,Ncid,Rs,SQL,Re
Dim Perid,UserName

'//获取个人用户的登陆标记
If IsArray(Session("Person")) Then
 Perid = Session("Person")(2)
 UserName = Session("Person")(0)
Else
 Session.Abandon() 
 Response.write "<script>alert('-登录后才能进行该操作！-');window.close();</script>"
 Response.End()
End if
Param    = Replace_Text(Request("param"))
Ncid     = Replace_Text(Request("ncid"))
'//判断参数是否有效
If Param = "" Then
 Response.write "<script language=JavaScript>alert('操作错误！');window.close();</script>"
 Response.End()
End if

If Ncid = "" Then
 Response.write "<script language=JavaScript>alert('您没有选择记录！');window.close();</script>"
 Response.End()
Else
 Ncid  = Split(Ncid,",")
End if

'//判断操作分支
Select Case Param
 Case "fav":Call Fav_Submit()                       '加入收藏夹
 Case "keeps":Call Keeps_Submit()                     '屏蔽企业
 Case "delinbox":Call DelInBox_Submit()             '彻底删除个人的收件夹信件
 Case "delrecycle":Call DelRecycle_Submit()         '删除信件到回收站
 Case "delfav":Call DelFav_Submit()             '彻底删除个人的收藏记录
 Case "delfavrecycle":Call DelFavRecycle_Submit()         '删除个人的收藏记录到回收站 
 Case "deloutbox":Call DelOutBox_Submit()         '删除个人的发件夹记录
 Case "del":Call Del_Submit()             '彻底删除
 Case "undel":Call UnDel_Submit()         '还原记录
 Case "video":Call Video_Submit()         '申请视频面试
 
End Select

'//功能函数
'--------------------------------------加入收藏夹----------------------------------------------------------
Sub Fav_Submit() '加入收藏夹
 For i = 0 To Ubound(Ncid)
  '查看是否已经保存该收藏记录
  SQL = "Select Ncid From [Ph_Person_Favouriate] Where Perid='"&Perid&"' And Jobid="&Cstr(Ncid(i))
  Set Rs = Conn.Execute(SQL)
  If Rs.Eof Then
   Comid = ""
   '查找企业的标记
   Set Re = Conn.Execute("Select Comid From [pH_Job_Base] Where Jobid="&Cstr(Ncid(i)))
   If Not Re.Eof Then Comid = Re(0)
   Re.Close
   '保存数据
   SQL = "Insert Into [pH_Person_Favouriate] (Perid,Jobid,Comid,AddDate) Values ('"&Perid&"',"&Ncid(i)&",'"&Comid&"',GetDate())"
   Conn.Execute(SQL)
  End if
  Rs.Close
 Next
 Response.write "<script language=JavaScript>alert('收藏成功！');window.opener.location.reload();window.close();</script>"
End Sub
'--------------------------------------彻底删除个人的收件夹信件----------------------------------------------
Sub DelInBox_Submit() '彻底删除个人的收件夹信件
 For i = 0 To Ubound(Ncid)
   '彻底删除收件夹表中的记录
   SQL = "Delete From [Ph_Person_InBox] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
   Conn.Execute(SQL)
 Next
 Response.write "<script language=JavaScript>alert('删除成功！');window.opener.location.reload();window.close();</script>"
End Sub

'--------------------------------------删除信件到回收站----------------------------------------------
Sub DelRecycle_Submit() '删除信件到回收站
 For i = 0 To Ubound(Ncid)
  '查看用户的信件
  SQL = "Select * From [Ph_Person_InBox] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
  Set Rs = Conn.Execute(SQL)
  If Not Rs.Eof Then
   '获取信件数据
   Perid        = Rs("Perid")
   Jobid        = Rs("Jobid")
   Comid        = Rs("Comid")
   AddDate      = Rs("AddDate")
   Title        = Rs("Title")
   Memo         = Rs("Memo")
   Flag         = Rs("Flag")
   If Flag = True Then
    Flag = 1
   Else
    Flag = 0
   End if
   SQL = "Insert Into [pH_Person_RecycleBox] (Perid,Jobid,Comid,AddDate,Title,Memo,Flag,Item_Source,DelDate) Values ('"&Perid&"',"&Jobid&",'"&Comid&"','"&AddDate&"','"&Title&"','"&Memo&"',"&Flag&",1,GetDate())"
   Conn.Execute(SQL)
   '删除收件夹表中的该条记录
   SQL = "Delete From [Ph_Person_InBox] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
   Conn.Execute(SQL)
  End if
  Rs.Close
 Next
 Response.write "<script language=JavaScript>alert('信件已经成功地被删除到回收站！');window.opener.location.reload();window.close();</script>"

End Sub

'--------------------------------------彻底删除个人的收藏记录----------------------------------------------
Sub DelFav_Submit() 
 For i = 0 To Ubound(Ncid)
   '彻底删除收件夹表中的记录
   SQL = "Delete From [Ph_Person_Favouriate] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
   Conn.Execute(SQL)
 Next
 Response.write "<script language=JavaScript>alert('删除成功！');window.opener.location.reload();window.close();</script>"
End Sub
'--------------------------------------删除个人的收藏记录到回收站----------------------------------------------
Sub DelFavRecycle_Submit() 
 For i = 0 To Ubound(Ncid)
  '查看用户的收藏信息
  SQL = "Select * From [Ph_Person_Favouriate] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
  Set Rs = Conn.Execute(SQL)
  If Not Rs.Eof Then
   '获取信件数据
   Perid        = Rs("Perid")
   Jobid        = Rs("Jobid")
   Comid        = Rs("Comid")
   AddDate      = Rs("AddDate")
   '转移到回收站
   SQL = "Insert Into [pH_Person_RecycleBox] (Perid,Jobid,Comid,AddDate,Item_Source,DelDate) Values ('"&Perid&"',"&Jobid&",'"&Comid&"','"&AddDate&"',2,GetDate())"
   Conn.Execute(SQL)
   '删除收藏夹表中的该条记录
   SQL = "Delete From [Ph_Person_Favouriate] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
   Conn.Execute(SQL)
  End if
  Rs.Close
 Next
 Response.write "<script language=JavaScript>alert('收藏记录已经成功地被删除到回收站！');window.opener.location.reload();window.close();</script>"

End Sub

'--------------------------------------删除个人的发件夹记录----------------------------------------------
Sub DelOutBox_Submit()
 For i = 0 To Ubound(Ncid)
   '彻底删除发件夹表中的记录
   SQL = "Delete From [Ph_Person_OutBox] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
   Conn.Execute(SQL)
 Next
 Response.write "<script language=JavaScript>alert('删除成功！');window.opener.location.reload();window.close();</script>"
End Sub

'--------------------------------------彻底删除----------------------------------------------
Sub Del_Submit() 
 For i = 0 To Ubound(Ncid)
   '彻底删除
   SQL = "Delete From [Ph_Person_RecycleBox] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
   Conn.Execute(SQL)
 Next
 Response.write "<script language=JavaScript>alert('删除成功！');window.opener.location.reload();window.close();</script>"
End Sub

'--------------------------------------还原记录----------------------------------------------
Sub UnDel_Submit()
 For i = 0 To Ubound(Ncid)
  '查找回收站记录
  SQL = "Select * From [Ph_Person_RecycleBox] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
  Set Rs = Conn.Execute(SQL)
  If Not Rs.Eof Then
   '获取数据
   Perid        = Rs("Perid")
   Jobid        = Rs("Jobid")
   Comid        = Rs("Comid")
   AddDate      = Rs("AddDate")
   Title        = Rs("Title")
   Memo         = Rs("Memo")
   Flag         = Rs("Flag")
   Item_Source  = Rs("Item_Source")
   If Flag = True Then
    Flag = 1
   Elseif Flag = False Then
    Flag = 0
   End if
   '判断还原的目标表
   If Item_Source = 1 Then
    '还原到收件夹
    SQL = "Insert Into [pH_Person_InBox] (Perid,Jobid,Comid,AddDate,Title,Memo,Flag) Values ('"&Perid&"',"&Jobid&",'"&Comid&"','"&AddDate&"','"&Title&"','"&Memo&"',"&Flag&")"
   Else
    '还原到收藏夹
	SQL = "Insert Into [pH_Person_Favouriate] (Perid,Jobid,Comid,AddDate) Values ('"&Perid&"',"&Jobid&",'"&Comid&"','"&AddDate&"')"
   End if
   Conn.Execute(SQL)
   '删除收件夹表中的该条记录
   SQL = "Delete From [Ph_Person_RecycleBox] Where Perid='"&Perid&"' And Ncid="&Cstr(Ncid(i))
   Conn.Execute(SQL)
  End if
  Rs.Close
 Next
 Response.write "<script language=JavaScript>alert('还原成功！');window.opener.location.reload();window.close();</script>"

End Sub

'--------------------------------------申请视频面试----------------------------------------------------------
Sub Video_Submit() 
 For i = 0 To Ubound(Ncid)
   '查找企业的标记
   Comid = ""
   Set Re = Conn.Execute("Select Comid From [pH_Job_Base] Where Jobid="&Cstr(Ncid(i)))
   If Not Re.Eof Then Comid = Re(0)
   Re.Close
  '查看是否已经保存
  SQL = "Select Ncid From [Ph_Company_VideoInBox] Where Perid='"&Perid&"' And Jobid="&Cstr(Ncid(i))
  Set Rs = Conn.Execute(SQL)
  If Rs.Eof Then
   '插入数据
   SQL = "Insert Into [Ph_Company_VideoInBox] (Perid,Jobid,Comid,AddDate,Flag,Click) Values ('"&Perid&"',"&Ncid(i)&",'"&Comid&"',GetDate(),0,1)"
  Else
   '更新数据
   SQL = "Update [Ph_Company_VideoInBox] Set Click=Click+1,AddDate=GetDate() Where Perid='"&Perid&"' And Jobid="&Cstr(Ncid(i))
  End if
  Conn.Execute(SQL)
  Rs.Close
  
 Next
 Response.write "<script language=JavaScript>alert('申请成功！');window.opener.location.reload();window.close();</script>"
End Sub

'--------------------------------------屏蔽企业----------------------------------------------
Sub Keeps_Submit() '彻底删除个人的收件夹信件
 Set Rs = Conn.Execute("Select Count(*) From [Ph_Person_Keeps] Where Perid='"&Perid&"'")
 If Rs(0) > 20 Then
  Response.write "<script language=JavaScript>alert('操作失败！您的企业屏蔽数目已经超过系统值');window.close();</script>"
  Response.End()
 End if
 For i = 0 To Ubound(Ncid)

   SQL = "Insert Into [Ph_Person_Keeps] (Perid,Comid,AddDate) Values ('"&Perid&"','"&Trim(Ncid(i))&"',Getdate())"
   Conn.Execute(SQL)
 Next
 Response.write "<script language=JavaScript>alert('操作成功！');window.opener.location.reload();window.close();</script>"
End Sub

'//关闭数据库连接
Set Rs = Nothing
Set Re = Nothing
CloseDB
 %>
