<!-- #include file="include/onlogin.asp" -->
<!-- #INCLUDE FILE="include/conn.asp" -->
<!-- #INCLUDE file="include/functions.asp" -->
<!-- #include file="include/jk_pagecute.asp" -->
<%
dim nsort,sql2,rs2,del_temp,data_name,cid,sid,nid,ncid,nsid,id,left_type,now_id,nummer,sqladd,page,rssum,thepages,viewpage,pageurl
dim name,csid,remark_1,remark_2,price_1,price_2,smallimg,bigimg,serial,brand,stock,isgood,hidden,ispic,pic,down_url,down_remark
tit=vbcrlf & "<a href='?'>产品管理</a>&nbsp;┋&nbsp;" & _
    vbcrlf & "<a href='?action=add'>发布产品</a>&nbsp;┋&nbsp;" & _
    vbcrlf & "<a href='admin_nsort.asp?nsort=pro'>产品分类</a>"
response.write header(18,tit)
pageurl="?action="&action&"&":nsort="pro":data_name="product":sqladd="":nummer=15
call admin_cid_sid()

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

function del_select(delid)
  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
      call upload_del(data_name,del_dim(del_i))
      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

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 action="hidden" 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
    else
      if rs(action)=false then
        sql="update "&data_name&" set "&action&"=1 where id="&id
      else
        sql="update "&data_name&" set "&action&"=0 where id="&id
      end if
    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()

sub news_edit()
  dim rs3,sql3
  if trim(request.querystring("edit"))="chk" then
    name=code_admin(request.form("name"))
    csid=trim(request.form("csid"))
    remark_1=request.form("remark_1")
    remark_2=request.form("remark_2")
    price_1=trim(request.form("price_1"))
    price_2=trim(request.form("price_2"))
    smallimg=trim(request.form("pics"))
    bigimg=trim(request.form("picb"))
    serial=code_admin(request.form("serial"))
    brand=code_admin(request.form("brand"))
    stock=code_admin(request.form("stock"))
    isgood=trim(request.form("isgood"))
    hidden=trim(request.form("hidden"))
    down_url=code_admin(request.form("down_url"))
    down_remark=code_admin(request.form("down_remark"))
    if len(csid)<1 then
      response.write "<font class=red_2>请选择产品类型！</font><br><br>"&go_back
    elseif len(name)<1 or not(isnumeric(price_1)) or not(isnumeric(price_2)) then
      response.write "<font class=red_2>产品名称和产品价格不能为空！</font><br><br>"&go_back
    elseif len(remark_1)>250 then
      response.write "<font class=red_2>产品简介不能超过250个字！</font><br><br>"&go_back
    else
      call chk_cid_sid()
      rs("c_id")=cid
      rs("s_id")=sid
      rs("name")=name
      rs("remark_1")=remark_1
      rs("remark_2")=remark_2
      rs("price_1")=price_1
      rs("price_2")=price_2
      if len(smallimg)<3 then smallimg="no_pic.gif"
      rs("smallimg")=smallimg
      if len(bigimg)<3 then bigimg="no_pic.gif"
      rs("bigimg")=bigimg
      rs("serial")=serial
      rs("brand")=brand
      rs("stock")=stock
      rs("down_url")=down_url
      rs("down_remark")=down_remark
      if isgood="yes" then
        rs("isgood")=true
      else
        rs("isgood")=false
      end if
      if hidden="yes" then
        rs("hidden")=false
      else
        rs("hidden")=true
      end if
      rs("tim")=now_time
      rs.update
      rs.close:set rs=nothing
      call upload_note(data_name,id)
      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 width='100%' cellspacing=0 cellpadding=1>
<form name='add_frm' action='<%response.write pageurl%>c_id=<%response.write cid%>&s_id=<%response.write sid%>&id=<%response.write id%>&edit=chk' method=post>
<input type=hidden name=upid value=''>
  <tr><td width='14%' align=center>产品名称：</td><td width='86%'><input type=text size=70 name=name value='<%response.write rs("name")%>' maxlength=50><%=redx%></td></tr>
  <tr><td align=center>产品类型：</td><td><%call chk_csid(cid,sid)%>&nbsp;&nbsp;产品编号：<input type=text size=30 name=serial value='<%response.write rs("serial")%>' maxlength=20></td></tr>
  <tr><td align=center>市场价格：</td><td><input type=text size=15 name=price_1 value='<%response.write rs("price_1")%>' maxlength=10>&nbsp;&nbsp;&nbsp;&nbsp;会员价格：<input type=text size=15 name=price_2 value='<%response.write rs("price_2")%>' maxlength=10>&nbsp;&nbsp;<%response.write redx%>（价格只能为数字）</td></tr>
  <tr><td align=center>产品品牌：</td><td><input type=text size=15 name=brand value='<%response.write rs("brand")%>' maxlength=20>&nbsp;&nbsp;&nbsp;&nbsp;库存：<select name=stock size=1>
<%pic=rs("stock")%><option<%if pic="有货" then response.write " selected"%>>有货</option>
<option<%if pic="紧张" then response.write " selected"%>>紧张</option>
<option<%if pic="暂缺" then response.write " selected"%>>暂缺</option>
</select>&nbsp;&nbsp;&nbsp;&nbsp;推荐：<input type=checkbox name=isgood<%if rs("isgood")=true then response.write " checked"%> value='yes'>&nbsp;选为推荐&nbsp;&nbsp;&nbsp;&nbsp;隐藏：<input type=checkbox name=hidden<%if rs("hidden")=false then response.write " checked"%> value='yes'>&nbsp;设为隐藏</td></tr>
  <tr><td align=center>相关下载：</td><td><input type=text size=70 name=down_url value='<%response.write rs("down_url")%>' maxlength=100></td></tr>
  <tr><td align=center>下载说明：</td><td><input type=text size=70 name=down_remark value='<%response.write rs("down_remark")%>' maxlength=50></td></tr>
  <tr><td valign=top align=center><br>产品简介：<br><=250B</td><td><textarea name=remark_1 rows=5 cols=70><%response.write rs("remark_1")%></textarea></td></tr>
  <tr height=35<%response.write format_table(3,1)%>><td align=center><%call frm_ubb_type()%></td><td><%call frm_ubb("add_frm","remark_2","&nbsp;&nbsp;")%></td></tr>
  <tr><td valign=top align=center><br>详细说明：</td><td><textarea name=remark_2 rows=8 cols=70><%response.write rs("remark_2")%></textarea></td></tr>
<%
pic=rs("smallimg")
if pic="no_pic.gif" then pic=""
ispic=pic
if Instr(ispic,"/")>0 then ispic=right(ispic,len(ispic)-Instr(ispic,"/"))
if Instr(ispic,".")>0 then ispic=left(ispic,Instr(ispic,".")-1)
if len(ispic)<1 then ispic=upload_time(now_time)
%>  <tr><td align=center>小 图 片：</td><td><table border=0 width='100%' cellspacing=0 cellpadding=0>
<tr><td><input type=text name=pics value='<%response.write pic%>' size=40 maxlength=50></td></tr>
<tr><td><iframe frameborder=0 name=upload_frames width='100%' height=30 scrolling=no src='upload.asp?uppath=product&upname=<%response.write "ps"&ispic%>&uptext=pics'></iframe></td></tr>
</table></td></tr>
<%
pic=rs("bigimg")
if pic="no_pic.gif" then pic=""
ispic=pic
if Instr(ispic,"/")>0 then ispic=right(ispic,len(ispic)-Instr(ispic,"/"))
if Instr(ispic,".")>0 then ispic=left(ispic,Instr(ispic,".")-1)
if len(ispic)<1 then ispic=upload_time(now_time)
%>  <tr><td align=center>大 图 片：</td><td><table border=0 width='100%' cellspacing=0 cellpadding=0>
<tr><td><input type=text name=picb value='<%response.write pic%>' size=40 maxlength=50>&nbsp;&nbsp;&nbsp;<a href='upload.asp?uppath=product&upname=<%response.write "pb"&ispic%>&uptext=picb' target=upload_frame>上传图片</a>&nbsp;&nbsp;<a href='upload.asp?uppath=product&upname=<%response.write "p"%>&uptext=remark_2' target=upload_frame>上传至详细说明</a></td></tr>
<tr><td><iframe frameborder=0 name=upload_frame width='100%' height=30 scrolling=no src='upload.asp?uppath=product&upname=<%response.write "pb"&ispic%>&uptext=picb'></iframe></td></tr>
</table></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
    name=code_admin(request.form("name"))
    csid=trim(request.form("csid"))
    remark_1=request.form("remark_1")
    remark_2=request.form("remark_2")
    price_1=trim(request.form("price_1"))
    price_2=trim(request.form("price_2"))
    smallimg=trim(request.form("pics"))
    bigimg=trim(request.form("picb"))
    serial=code_admin(request.form("serial"))
    brand=code_admin(request.form("brand"))
    stock=code_admin(request.form("stock"))
    isgood=trim(request.form("isgood"))
    hidden=trim(request.form("hidden"))
    down_url=code_admin(request.form("down_url"))
    down_remark=code_admin(request.form("down_remark"))
    if len(csid)<1 then
      response.write "<font class=red_2>请选择产品类型！</font><br><br>"&go_back
    elseif len(name)<1 or not(isnumeric(price_1)) or not(isnumeric(price_2)) then
      response.write "<font class=red_2>产品名称和产品价格不能为空！</font><br><br>"&go_back
    elseif len(remark_1)>250 then
      response.write "<font class=red_2>产品简介不能超过250个字！</font><br><br>"&go_back
    else
      call chk_cid_sid()
      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("name")=name
      rs("remark_1")=remark_1
      rs("remark_2")=remark_2
      rs("price_1")=price_1
      rs("price_2")=price_2
      if len(smallimg)<3 then smallimg="no_pic.gif"
      rs("smallimg")=smallimg
      if len(bigimg)<3 then bigimg="no_pic.gif"
      rs("bigimg")=bigimg
      rs("serial")=serial
      rs("brand")=brand
      rs("stock")=stock
      rs("down_url")=down_url
      rs("down_remark")=down_remark
      if isgood="yes" then
        rs("isgood")=true
      else
        rs("isgood")=false
      end if
      if hidden="yes" then
        rs("hidden")=false
      else
        rs("hidden")=true
      end if
      rs("tim")=now_time
      rs("counter")=0
      rs("buy_counter")=0
      rs.update
      rs.close:set rs=nothing
      call upload_note(data_name,first_id(data_name))
      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 width='100%' cellspacing=0 cellpadding=1>
<form name='add_frm' action='<%response.write pageurl%>add=chk' method=post>
<input type=hidden name=upid value=''>
  <tr><td width='14%' align=center>产品名称：</td><td width='86%'><input type=text size=70 name=name maxlength=50><%=redx%></td></tr>
  <tr><td align=center>产品类型：</td><td><%call chk_csid(cid,sid)%>&nbsp;&nbsp;推荐：<input type=checkbox name=isgood value='yes'>&nbsp;选上为推荐&nbsp;&nbsp;&nbsp;&nbsp;隐藏：<input type=checkbox name=hidden value='yes'>&nbsp;选上为隐藏</td></tr>
  <tr><td align=center>市场价格：</td><td><input type=text size=15 name=price_1 maxlength=10>&nbsp;&nbsp;&nbsp;&nbsp;会员价格：<input type=text size=15 name=price_2 maxlength=10>&nbsp;&nbsp;<%response.write redx%>（价格只能为数字）</td></tr>
  <tr><td align=center>产品品牌：</td><td><input type=text size=15 name=brand maxlength=20>&nbsp;&nbsp;&nbsp;&nbsp;产品编号：<input type=text size=15 name=serial maxlength=20>&nbsp;&nbsp;库存：<select name=stock size=1>
<option>有货</option>
<option>紧张</option>
<option>暂缺</option>
</select>&nbsp;&nbsp;</td></tr>
  <tr><td align=center>相关下载：</td><td><input type=text size=70 name=down_url maxlength=100></td></tr>
  <tr><td align=center>下载说明：</td><td><input type=text size=70 name=down_remark maxlength=50></td></tr>
  <tr><td valign=top align=center><br>产品简介：<br><=250B</td><td><textarea name=remark_1 rows=5 cols=70></textarea></td></tr>
  <tr height=35<%response.write format_table(3,1)%>><td align=center><%call frm_ubb_type()%></td><td><%call frm_ubb("add_frm","remark_2","&nbsp;&nbsp;")%></td></tr>
  <tr><td valign=top align=center><br>详细说明：</td><td><textarea name=remark_2 rows=8 cols=70></textarea></td></tr>
<%ispic=upload_time(now_time)%>
  <tr><td align=center>小 图 片：</td><td><table border=0 width='100%' cellspacing=0 cellpadding=0>
<tr><td><input type=text name=pics size=40 maxlength=50></td></tr>
<tr><td><iframe frameborder=0 name=upload_frames width='100%' height=30 scrolling=no src='upload.asp?uppath=product&upname=<%response.write "ps"&ispic%>&uptext=pics'></iframe></td></tr>
</table></td></tr>
  <tr><td align=center>大 图 片：</td><td><table border=0 width='100%' cellspacing=0 cellpadding=0>
<tr><td><input type=text name=picb size=40 maxlength=50>&nbsp;&nbsp;&nbsp;<a href='upload.asp?uppath=product&upname=<%response.write "pb"&ispic%>&uptext=picb' target=upload_frame>上传图片</a>&nbsp;&nbsp;<a href='upload.asp?uppath=product&upname=<%response.write "p"%>&uptext=remark_2' target=upload_frame>上传至详细说明</a></td></tr>
<tr><td><iframe frameborder=0 name=upload_frame width='100%' height=30 scrolling=no src='upload.asp?uppath=product&upname=<%response.write "pb"&ispic%>&uptext=picb'></iframe></td></tr>
</table></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><%call left_sort()%></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>
<%
  call sql_cid_sid()
  sql="select id,c_id,s_id,name,isgood,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
  call format_pagecute()
  del_temp=nummer
  if rssum=0 then del_temp=0
  if int(page)=int(thepages) then
    del_temp=rssum-nummer*(thepages-1)
  end if
%>
<tr><td colspan=3 align=center height=25>
现有<font class=red><%response.write rssum%></font>篇文章　<%response.write "<a href='?action=add&c_id="&cid&"&s_id="&sid&"'>添加文章</a>"%>
　<input type=checkbox name=del_all value=1 onClick=selectall('<%response.write del_temp%>')> 选中所有　<input type=submit value='删除所选' onclick=""return suredel('<%response.write del_temp%>');"">
</td></tr>
<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 article_center()
    rs.movenext
  next
  rs.close:set rs=nothing
%></form>
<tr><td colspan=3 height=1 bgcolor=#ededede></td></tr>
<tr><td colspan=3 height=25>页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font>
分页：<%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
</td></tr></table>
</td></tr></table>
<%
end sub

function article_center()
  article_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 & "'>" & cuted(rs("name"),30) & "</a>" & _
		 "</td><td align=right><a href='?action=hidden&c_id="&cid&"&s_id="&sid&"&id="&now_id&"'>"
  if rs("hidden")=true then
    article_center=article_center&"显"
  else
    article_center=article_center&"<font class=red_2>隐</font>"
  end if
  article_center=article_center&"</a> <a href='?action=isgood&c_id="&cid&"&s_id="&sid&"&id="&now_id&"'>"
  if rs("isgood")=true then
    article_center=article_center&"<font class=red>是</font>"
  else
    article_center=article_center&"否"
  end if
  article_center=article_center&"</a><input type=checkbox name=del_id value='"&now_id&"'></td></tr>"
end function
%>