<!--#include file="conn.asp"-->
<%
if session("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');history.go(-1);</script>"
response.End
else
if request.cookies("timesshop")("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');history.go(-1);</script>"
response.End
end if
end if
%>
<title>管理商品</title>
<script language="JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<%
dim selectm,selectkey,selectid
selectkey=trim(request.form(trim("selectkey")))
selectm=trim(request.form("selectm"))
if selectkey="" then
selectkey=FormatSQL(request.QueryString("selectkey"))
end if
if selectm="" then
selectm=FormatSQL(request.QueryString("selectm"))
end if

selectid=request.form("selectid")
if selectid<>"" then
if session("rank")>2 then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('你无权管理商品！');history.go(-1);</script>"
response.End
end if
path = "../"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set rs= Server.CreateObject("ADODB.Recordset")
	sql="select id,pic from product where id in ("&selectid&")"
	rs.open sql,conn,1
	if not rs.eof then
	response.write "总共删除记录和文件"&rs.recordcount&"个。<br>"
	do while not rs.eof
		
		F_filename=path&rs("pic")
		IF F_filename = "../images/TimesShop.gif" Then
		F_filename = ""
		End If
		if objFSO.fileExists(Server.MapPath(F_filename)) then
		objFSO.DeleteFile(Server.MapPath(F_filename))
		end if
		conn.Execute("delete from product where id="&rs(0))
		response.write "已经删除文件"&F_filename&" ！<br>"
	rs.movenext
	loop
	end if
	rs.close
	set rs=nothing
set objFSO=nothing


response.Redirect "chkpro.asp"
response.End
end if

CID=Request.QueryString("CID")
If CID<> "" Then
strCat = "Where categoryid= "&CID&" order by adddate desc"
Else
strCat = "order by adddate desc"
End if
%>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#6699cc">
  <tr>  
    <td height="20" align="center">
	
	 <font color="#FFFFFF">商品查看与修改&nbsp;&nbsp;&nbsp;&nbsp;
	分类过滤</font>     

		

<select name="state" onChange="var jmpURL=this.options[this.selectedIndex].value ; if(jmpURL!='') {window.location=jmpURL;} else {this.selectedIndex=0 ;}">  
		  <option value="-1" selected >--请选择商品分类--</option>
<%
sort(0)
dim ii
ii=0
sub sort(selec)
	sql="select * from category where ParentID = "&selec&" order by categoryorder"
	Set Rs1=Conn.Execute(sql)
	do while not rs1.eof
if selec=0 then
%>
<option value="chkpro.asp?cid=<%=int(rs1("categoryid"))%>" <% if int(rs1("categoryid"))="&CID&" Then Response.write("Selected") %>><%=rs1("category")%></option>
<%
else
%>
<option value="chkpro.asp?cid=<%=int(rs1("categoryid"))%>" <% if int(rs1("categoryid"))="&CID&" Then Response.write("Selected") %>><%=string(ii*2,"　")%><%=rs1("category")%></option>
<%
end if
ii=ii+1
	sort rs1("categoryid")
ii=ii-1
	rs1.movenext
	loop
rs1.close
Set Rs1 = Nothing
end sub

%>
		</select> 
		  </td>
  </tr>
  <tr> 
    <form name="form1" method="post" action="">
      <td height="100" bgcolor="#FFFFFF"> 
        <%
				Const MaxPerPage=10
   				dim totalPut   
   				dim CurrentPage
   				dim TotalPages
   				dim j
   				dim sql
    				if Not isempty(SafeRequest("page",1)) then
      				currentPage=Cint(SafeRequest("page",1))
   				else
      				currentPage=1
   				end if 
			set rs=server.CreateObject("adodb.recordset")
			select case selectm
			case ""
            rs.open "select id,name,adddate,introduce from product " & strCat & " ",conn,1,1
		    case "0"
			response.write "<center>请返回选择您要查询的方式！<br><br><a href=javascript:history.go(-1)>点击返回上一页</a></center>"
			response.End
			case "name"
			rs.open "select id,name,adddate,introduce from product where name like '%"&selectkey&"%' order by adddate desc",conn,1,1
			case "zuozhe"
			rs.open "select id,name,adddate,introduce from product where mark like '%"&selectkey&"%' order by adddate desc",conn,1,1
			case "chubanshe"
			rs.open "select id,name,adddate,introduce from product where introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1
		  end select
		   	if err.number<>0 then
				response.write "数据库中暂时无数据"
				end if
				
  				if rs.eof And rs.bof then
       				Response.Write "<p align='center' class='contents'> 数据库中暂时无数据！</p>"
   				else
	  				totalPut=rs.recordcount

      				if currentpage<1 then
          				currentpage=1
      				end if

      				if (currentpage-1)*MaxPerPage>totalput then
	   					if (totalPut mod MaxPerPage)=0 then
	     					currentpage= totalPut \ MaxPerPage
	   					else
	      					currentpage= totalPut \ MaxPerPage + 1
	   					end if
      				end if

       				if currentPage=1 then
            			showContent
            			showpage totalput,MaxPerPage,"chkpro.asp"
       				else
          				if (currentPage-1)*MaxPerPage<totalPut then
            				rs.move  (currentPage-1)*MaxPerPage
            				dim bookmark
            				bookmark=rs.bookmark
            				showContent
             				showpage totalput,MaxPerPage,"chkpro.asp"
        				else
	        				currentPage=1
           					showContent
           					showpage totalput,MaxPerPage,"chkpro.asp"
	      				end if
	   				end if
   				   				end if

   				sub showContent
       			dim i
	   			i=0%>
        <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
          <tr bgcolor="#FFFFFF" align="center" height="20"> 
            <td width="30%">商品名称</td>
            <td width="45%">商品简介</td>
            <td width="17%">加入时间</td>
            <td width="8%">选 择</td>
          </tr>
          <%
		  do while not rs.eof%>
          <tr bgcolor="#FFFFFF" align="center"> 
            <td align="left">&nbsp;<a href=editpro.asp?id=<%=rs("id")%>> 
                <% if len(trim(rs("name")))>20 then
			response.write left(trim(rs("name")),18)&"..."
			else
			response.write trim(rs("name"))
			end if%>
                </a></td>
            <td align="left">&nbsp;
              <%if len(trim(rs("introduce")))>30 then
			response.write left(trim(rs("introduce")),28)&"..."
			else 
			response.write trim(rs("introduce"))
			end if%>
            </td>
            <td nowrap><%=rs("adddate")%></td>
            <td align="center"><input name="selectid" type="checkbox" id="selectid" value="<%=rs("id")%>"></td>
          </tr>
          <%i=i+1
			if i>=MaxPerPage then Exit Do
			rs.movenext
		  loop
		  rs.close
		  set rs=nothing%>
          <tr bgcolor="#FFFFFF"> 
            <td height="30" colspan="4" align="right">全选 <input type="checkbox" name="checkbox2" value="Check All" onClick="mm()">&nbsp;<input type="submit" name="Submit" value="删 除" onClick="return test();">
                &nbsp;&nbsp; </td>
          </tr>
        </table>
        <%  
				End Sub   
  
				Function showpage(totalnumber,maxperpage,filename)  
  				Dim n
  				
				If totalnumber Mod maxperpage=0 Then  
					n= totalnumber \ maxperpage  
				Else
					n= totalnumber \ maxperpage+1  
				End If
				
				Response.Write "<form method=Post action="&filename&"?selectm="&selectm&"&selectkey="&selectkey&" >"  
				Response.Write "<p align='center' class='contents'> "  
				If CurrentPage<2 Then  
					Response.Write "<font class='contents'>首 页 上一页</font> "  
				Else  
					Response.Write "<a href="&filename&"?page=1&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>首 页</a> "  
					Response.Write "<a href="&filename&"?page="&CurrentPage-1&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>上一页</a> "  
				End If
				
				If n-currentpage<1 Then  
					Response.Write "<font class='contents'>下一页 末 页</font>"  
				Else  
					Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>"  
					Response.Write "下一页</a> <a href="&filename&"?page="&n&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>末 页</a>"  
				End If  
					Response.Write "<font class='contents'> 页次：</font><font class='contents'>"&CurrentPage&"</font><font class='contents'>/"&n&"页</font> "  
					Response.Write "<font class='contents'> 共有"&totalnumber&"种商品 " 
					Response.Write "<font class='contents'>转到第：</font><input type='text' name='page' size=2 maxlength=10 class=smallInput value="&currentpage&">页"  
					Response.Write "&nbsp;<input type='submit'  class='contents' value='跳转' name='cndok' ></form>"  
				End Function  
			%></td>
    </form>
  </tr>
</table>
<br>
<table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6699cc">
  <tr> 
    <td align="center"><font color="#FFFFFF">商品查询</font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <form name="form2" method="post" action="chkpro.asp">
      <td>
	  <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
          <tr bgcolor="#FFFFFF" align="center"> 
            <td width="35%"> <input name="selectkey" type="text" id="selectkey" onFocus="this.value=''" value="请输入关健字"> 
            </td>
            <td width="45%"> <select name="selectm" id="select">
                <OPTION VALUE="name">按商品名称</OPTION>
                <OPTION VALUE="zuozhe">按商品品牌</OPTION>
                <OPTION VALUE="chubanshe">按商品简介</OPTION>
              </select> </td>
            <td width="20%"><input type="submit" name="Submit" value="查 询" onClick="return chkkey();"></td>
          </tr>
        </table></td>
    </form>
  </tr>
</table>

<!--#include file="footer.asp"-->
<script language=javascript>
function test()
{
  if(!confirm('确认删除吗？')) return false;
}

function chkkey()
{
	if(checkspace(document.form2.selectkey.value.length=0)){
	document.form2.selectkey.focus();
	alert("请输入查询关键字")
	return false;
	}
}
 
function mm()
{
   var a = document.getElementsByTagName("input");
   if(a[0].checked==true){
   for (var i=0; i<a.length; i++)
      if (a[i].type == "checkbox") a[i].checked = false;
   }
   else
   {
   for (var i=0; i<a.length; i++)
      if (a[i].type == "checkbox") a[i].checked = true;
   }
}
</script>