<!-- #include file="include/onlogin.asp" -->
<!-- #INCLUDE FILE="include/conn.asp" -->
<!-- #INCLUDE file="include/functions.asp" -->
<!-- #include file="include/jk_pagecute.asp" -->
<%
dim website_menu,nsort,sql2,rs2,del_temp,data_name,cid,sid,ncid,nsid,nid,id,left_type,now_id,nummer,sqladd,page,rssum,thepages,viewpage,pageurl,pic,ispic
website_menu=vbcrlf & "<a href='?'>源码交易</a>&nbsp;┋&nbsp;" & _
	     vbcrlf & "<a href='?action=add'>添加交易</a>&nbsp;┋&nbsp;" & _
	     vbcrlf & "<a href='admin_nsort.asp?nsort=busin'>交易分类</a>"
response.write header(20,website_menu)
pageurl="?action="&action&"&":nsort="busin":data_name="business":sqladd="":nummer=18
cid=trim(request.querystring("c_id"))
sid=trim(request.querystring("s_id"))
if not(isnumeric(cid)) then cid=0
if not(isnumeric(sid)) then sid=0
cid=int(cid):sid=int(sid)

if trim(request("del_ok"))="ok" then
  response.write del_select(trim(request.form("del_id")))
end if

function del_select(delid)
  on error resume next
  dim del_i,del_num,del_dim,del_sql,fobj,picc
  if delid<>"" and not isnull(delid) then
    delid=replace(delid," ","")
    del_dim=split(delid,",")
    del_num=UBound(del_dim)
    for del_i=0 to del_num
      del_sql="select pic from "&data_name&" where id="&del_dim(del_i)
      set rs=conn.execute(del_sql)
      if not(rs.eof and rs.bof) then
        picc=rs("pic")
      end if
      rs.close
      if len(picc)>3 and picc<>"no_pic.gif" and left(picc,7)<>"http://" then
        if left(picc,1)<>"/" then
          if right(upload_file,1)<>"/" then upload_file=upload_file&"/"
          picc=Server.MapPath(upload_file&picc)
        else
          picc=Server.MapPath(picc)
        end if
        Set fobj = CreateObject("Scripting.FileSystemObject")
        fobj.DeleteFile(picc)
        Set fobj = nothing
      end if
      del_sql="delete from "&data_name&" where id="&del_dim(del_i)
      conn.execute(del_sql)
    next
    Erase del_dim
    del_select=vbcrlf&"<script language=javascript>alert(""共删除了 "&del_num+1&" 条记录！"");</script>"
  end if
end function

if action="isgood" then
  id=trim(request.querystring("id"))
  if isnumeric(id) then
    sql="select isgood from "&data_name&" where id="&id
    set rs=conn.execute(sql)
    if not(rs.eof and rs.bof) then
      if rs("isgood")=true then
        sql="update "&data_name&" set isgood=0 where id="&id
      else
        sql="update "&data_name&" set isgood=1 where id="&id
      end if
      conn.execute(sql)
    end if
    rs.close
  end if
  action=""
end if

id=trim(request.querystring("id"))
if (action="hidden" or action="isgood") and isnumeric(id) then
  sql="select "&action&" from "&data_name&" where id="&id
  set rs=conn.execute(sql)
  if not(rs.eof and rs.bof) then
    if rs(action)=true then
      sql="update "&data_name&" set "&action&"=0 where id="&id
    else
      sql="update "&data_name&" set "&action&"=1 where id="&id
    end if
    conn.execute(sql)
  end if
  rs.close
  action=""
end if

select case action
case "add"
  call news_add()
case "edit"
  if not(isnumeric(id)) then
    call news_main()
  else
    set rs=server.createobject("adodb.recordset")
    sql="select * from "&data_name&" where id="&id
    rs.open sql,conn,1,3
    call news_edit()
  end if
case else
  call news_main()
end select

close_conn()
response.write ender()

function select_type(st1,st2)
  select_type=vbcrlf&"<option"
  if st1=st2 then select_type=select_type&" selected"
  select_type=select_type&">"&st1&"</option>"
end function

sub news_edit()
  dim rs3,sql3,name,csid,remark
  if trim(request.querystring("edit"))="chk" then
    name=code_admin(request.form("name"))
    csid=trim(request.form("csid"))
    remark=request.form("remark")
    pic=trim(request.form("pic"))
    if isnumeric(csid) or len(csid)<1 then
      response.write "<font class=red_2>请选择交易类型！</font><br><br>"&go_back
    elseif len(remark)>250 then
      response.write "<font class=red_2>交易说明不能长于250个字符！</font><br><br>"&go_back
    else
      cid=mid(csid,1,instr(csid,"-")-1)
      sid=mid(csid,instr(csid,"-")+1,len(csid))
      rs("c_id")=cid
      rs("s_id")=sid
      if trim(request.form("username_my"))="yes" then rs("username")=login_username
      rs("name")=name
      rs("url")=code_admin(request.form("url"))
      rs("price")=code_admin(request.form("price"))
      rs("phone")=code_admin(request.form("phone"))
      rs("nname")=code_admin(request.form("nname"))
      rs("email")=code_admin(request.form("email"))
      rs("remark")=remark
      if trim(request.form("hidden"))="yes" then
        rs("hidden")=false
      else
        rs("hidden")=true
      end if
      if len(pic)<1 then
        rs("pic")="no_pic.gif"
      else
        rs("pic")=pic
      end if
      rs("tim")=now_time
      rs.update
      rs.close:set rs=nothing
      response.write "<font class=red>已成功修改了一个交易！</font><br><br><a href='?c_id="&cid&"&s_id="&sid&"'>点击返回</a><br><br>"
    end if
  else
%><table border=0 cellspacing=0 cellpadding=3>
<form action='<%response.write pageurl%>c_id=<%response.write cid%>&s_id=<%response.write sid%>&id=<%response.write id%>&edit=chk' method=post>
  <tr>
    <td width='12%'>交易名称：</td>
    <td width='88%'><input type=text size=60 name=name value='<%response.write rs("name")%>' maxlength=50><%=redx%></td>
  </tr>
  <tr>
    <td>交易类型：</td>
    <td><select name=csid size=1><%
sql3="select c_id,c_name from jk_class where nsort='"&nsort&"' order by c_order,c_id"
set rs3=conn.execute(sql3)
do while not rs3.eof
  nid=int(rs3(0))
  response.write vbcrlf&"<option value='"&nid&"' class=bg_2>"&rs3(1)&"</option>"
  sql2="select s_id,s_name from jk_sort where c_id="&nid&" order by s_order,s_id"
  set rs2=conn.execute(sql2)
  do while not rs2.eof
    now_id=int(rs2(0))
    response.write vbcrlf&"<option value='"&nid&"-"&now_id&"'"
    if cid=nid and sid=now_id then response.write " selected"
    response.write ">　"&rs2(1)&"</option>"
    rs2.movenext
  loop
  rs2.close:set rs2=nothing
  rs3.movenext
loop
rs3.close:set rs3=nothing
pic=rs("pic")
if pic="no_pic.gif" then pic=""
ispic=pic
if Instr(ispic,"/")>0 then
  ispic=right(ispic,len(ispic)-Instr(ispic,"/"))
end if
if Instr(ispic,".")>0 then
  ispic=left(ispic,Instr(ispic,".")-1)
end if
if len(ispic)<1 then ispic="n"&upload_time(now_time)
%></select><%=redx%><input type=checkbox name=hidden<%if rs("hidden")=false then response.write " checked"%> value='yes'>&nbsp;隐藏显示&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox name=username_my value='yes'>&nbsp;修改发布人为我</td></tr>
  <tr><td>演示地址：</td><td><input type=text size=50 name=url value='<%=rs("url")%>' maxlength=100></td></tr>
  <tr><td>交易价格：</td><td><input type=text size=20 name=price value='<%=rs("price")%>' maxlength=20>&nbsp;&nbsp;联 系 人：<input type=text size=20 name=nname value='<%=rs("nname")%>' maxlength=20></td></tr>
  <tr><td>联系电话：</td><td><input type=text size=20 name=phone value='<%=rs("phone")%>' maxlength=20>&nbsp;&nbsp;电子邮件：<input type=text size=20 name=email value='<%=rs("email")%>' maxlength=50></td></tr>
  <tr><td>图片地址：</td><td><input type=test name=pic value='<%response.write pic%>' size=40 maxlength=30 readonly></td></tr>
  <tr><td>上传图片：</td><td><iframe frameborder=0 name=upload_frame width='100%' height=30 scrolling=no src='upload.asp?uppath=website&upname=<%response.write ispic%>&uptext=pic'></iframe></td></tr>
  <tr><td valign=top class=htd><br>交易说明：<br><=250B</td><td><textarea name=remark rows=6 cols=60><%response.write rs("remark")%></textarea></td></tr>
  <tr><td colspan=2 align=center height=25><input type=submit value=' 修 改 交 易 '></td></tr></form></table>
  <%
  end if
end sub

sub news_add()
  if trim(request.querystring("add"))="chk" then
    dim name,csid,remark
    name=code_admin(request.form("name"))
    csid=trim(request.form("csid"))
    remark=request.form("remark")
    pic=trim(request.form("pic"))
    if isnumeric(csid) or len(csid)<1 then
      response.write "<font class=red_2>请选择交易类型！</font><br><br>"&go_back
    elseif len(remark)>250 then
      response.write "<font class=red_2>交易说明不能长于250个字符！</font><br><br>"&go_back
    else
      cid=mid(csid,1,instr(csid,"-")-1)
      sid=mid(csid,instr(csid,"-")+1,len(csid))
      set rs=server.createobject("adodb.recordset")
      sql="select * from "&data_name
      rs.open sql,conn,1,3
      rs.addnew
      rs("c_id")=cid
      rs("s_id")=sid
      rs("username")=login_username
      rs("hidden")=true
      rs("name")=name
      rs("url")=code_admin(request.form("url"))
      rs("price")=code_admin(request.form("price"))
      rs("phone")=code_admin(request.form("phone"))
      rs("nname")=code_admin(request.form("nname"))
      rs("email")=code_admin(request.form("email"))
      rs("remark")=remark
      if len(pic)<1 then
        rs("pic")="no_pic.gif"
      else
        rs("pic")=pic
      end if
      rs("tim")=now_time
      rs.update
      rs.close:set rs=nothing
      response.write "<font class=red>已成功添加了一个交易！</font><br><br><a href='?c_id="&cid&"&s_id="&sid&"'>点击返回</a><br><br>"
    end if
  else
%><table border=0 cellspacing=0 cellpadding=3>
<form action='<%response.write pageurl%>add=chk' method=post>
  <tr>
    <td width='12%'>交易名称：</td>
    <td width='88%'><input type=text size=60 name=name maxlength=50><%=redx%></td>
  </tr>
  <tr>
    <td>交易类型：</td>
    <td><select name=csid size=1><%sql="select c_id,c_name from jk_class where nsort='"&nsort&"' order by c_order,c_id"
set rs=conn.execute(sql)
do while not rs.eof
  nid=int(rs(0))
  response.write vbcrlf&"<option value='"&nid&"' class=bg_2>"&rs(1)&"</option>"
  sql2="select s_id,s_name from jk_sort where c_id="&nid&" order by s_order,s_id"
  set rs2=conn.execute(sql2)
  do while not rs2.eof
    now_id=int(rs2(0))
    response.write vbcrlf&"<option value='"&nid&"-"&now_id&"'"
    if cid=nid and sid=now_id then response.write " selected"
    response.write ">　"&rs2(1)&"</option>"
    rs2.movenext
  loop
  rs2.close:set rs2=nothing
  rs.movenext
loop
rs.close:set rs=nothing
%></select><%=redx%></td></tr>
  <tr><td>演示地址：</td><td><input type=text size=50 name=url value='http://' maxlength=100></td></tr>
  <tr><td>交易价格：</td><td><input type=text size=20 name=price maxlength=20>&nbsp;&nbsp;联 系 人：<input type=text size=20 name=nname maxlength=20></td></tr>
  <tr><td>联系电话：</td><td><input type=text size=20 name=phone maxlength=20>&nbsp;&nbsp;电子邮件：<input type=text size=20 name=email maxlength=50></td></tr>
<% ispic="w"&upload_time(now_time) %>
  <tr><td>图片地址：</td><td><input type=test name=pic size=40 maxlength=30 readonly></td></tr>
  <tr><td>上传图片：</td><td><iframe frameborder=0 name=upload_frame width='100%' height=30 scrolling=no src='upload.asp?uppath=website&upname=<%response.write ispic%>&uptext=pic'></iframe></td></tr>
  <tr><td valign=top class=htd><br>交易说明<br><=250B</td><td><textarea name=remark rows=6 cols=60></textarea></td></tr>
  <tr><td colspan=2 align=center height=25><input type=submit value=' 添 加 交 易 '></td></tr>
</form></table><%
  end if
end sub

sub news_main()
%>
<script language=javascript src='style/admin_del.js'></script>
<table border=0 width='100%' cellpadding=2>
  <tr valign=top height=350>
    <td width='25%' class=htd><br><%
  sql="select c_id,c_name from jk_class where nsort='"&nsort&"' order by c_order,c_id"
  set rs=conn.execute(sql)
  do while not rs.eof
    nid=int(rs(0))
    if cid=nid then
      response.write vbcrlf&img_small("jt1")&"<a href='?c_id="&nid&"'><b><font class=red_3>"&rs(1)&"</b></font></a><br>"
    else
      response.write vbcrlf&img_small("jt0")&"<a href='?c_id="&nid&"'><font class=red_3>"&rs(1)&"</font></a><br>"
    end if
    sql2="select s_id,s_name from jk_sort where c_id="&nid&" order by s_order,s_id"
    set rs2=conn.execute(sql2)
    do while not rs2.eof
      now_id=int(rs2(0))
      if sid=now_id then
        response.write vbcrlf&"　<a href='?c_id="&nid&"&s_id="&now_id&"'><font class=blue_1>"&rs2(1)&"</a></a><br>"
      else
        response.write vbcrlf&"　<a href='?c_id="&nid&"&s_id="&now_id&"'>"&rs2(1)&"</a><br>"
      end if
      rs2.movenext
    loop
    rs2.close:set rs2=nothing
    rs.movenext
  loop
  rs.close
%></td>
    <td width='75%' align=center>
<table border=0 width='98%' cellspacing=0 cellpadding=0>
<form name=del_form action='<%=pageurl%>del_ok=ok' method=post>
<tr><td width='6%'></td><td width='81%'></td><td width='13%'></td></tr>
<%
  if cid<>0 then
    sqladd=" where c_id="&cid
    pageurl=pageurl&"c_id="&cid&"&"
    if sid<>0 then
      sqladd=sqladd&" and s_id="&sid
      pageurl=pageurl&"s_id="&sid&"&"
    end if
  end if
  sql="select id,c_id,s_id,name,hidden from "&data_name&sqladd&" order by id desc"
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,1,1
  if rs.eof and rs.bof then
    rssum=0
  else
    rssum=rs.recordcount
  end if
  if rssum mod nummer > 0 then
    thepages=rssum\nummer+1
  else
    thepages=rssum\nummer
  end if
  page=trim(request.querystring("page"))
  if not(isnumeric(page)) then page=1:viewpage=1
  if int(page)>thepages then
    viewpage=1
  else
    viewpage=page
  end if
  del_temp=nummer
  if rssum=0 then del_temp=0
  if int(page)=int(thepages) then
    del_temp=rssum-nummer*(thepages-1)
  end if
  response.write "<tr><td colspan=3 align=center>" & _
		 vbcrlf & "本栏现有<font class=red>"&rssum&"</font>个交易┋" & _
		 vbcrlf & "共<font class=red>"&thepages&"</font>页┋" & _
		 vbcrlf & "这是第<font class=red>"&viewpage&"</font>页┋<a href='?action=add&c_id="&cid&"&s_id="&sid&"'>添加交易</a></td></tr>" & _
		 vbcrlf & "<tr><td colspan=3 height=25 align=center>分页："&jk_pagecute(nummer,thepages,viewpage,pageurl,6,"#ff0000") & _
		 "　<input type=checkbox name=del_all value=1 onClick=selectall('"&del_temp&"')> 选中所有　<input type=submit value='删除所选' onclick=""return suredel('"&del_temp&"');""></td></tr>" & _
		 vbcrlf & "<tr><td colspan=3 height=1 bgcolor=#ededede></td></tr>"
  if int(viewpage)<>1 then
    rs.move (viewpage-1)*nummer
  end if
  for i=1 to nummer
    if rs.eof then exit for
    now_id=rs("id"):ncid=rs("c_id"):nsid=rs("s_id")
    response.write website_center()
    rs.movenext
  next
  rs.close:set rs=nothing
%></form>
</table>
    </td>
  </tr>
</table>
<%
end sub

function website_center()
  website_center=VbCrLf & "<tr"&mtr&">" & _
		 VbCrLf & "<td>" & i+(viewpage-1)*nummer & ". </td><td>" & _
		 VbCrLf & "<a href='?action=edit&c_id="&ncid&"&s_id="&nsid&"&id=" & now_id & "'>" & rs("name") & "</a></td><td align=right><a href='?action=hidden&c_id="&cid&"&s_id="&sid&"&id="&now_id&"&page="&viewpage&"'>"
  if rs("hidden")=true then
    website_center=website_center&"显"
  else
    website_center=website_center&"<font class=red_2>隐</font>"
  end if
  website_center=website_center&"</a> <input type=checkbox name=del_id value='"&now_id&"'></td></tr>"
end function
%>
