<!--#include file="conn.asp"-->
<%
if session("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');location.href='index.asp' ;</script>"
response.End
else
if request.cookies("sundxshop")("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');location.href='index.asp' ;</script>"
response.End
end if
end if
%>

<title>快捷管理商品</title>
<%
dim selectm,selectkey,selectid
dim id
plid=SafeRequest("plid",1)
if plid=0 then
  recommend =0
  plidtitle="所有商品"
elseif plid=1 then
   recommend =1
   plidtitle="新品"
elseif plid=2 then
   recommend =2
   plidtitle="推荐"
elseif plid=3 then
   recommend =3
   plidtitle="特价"
elseif plid=4 then
   recommend =4
  plidtitle="赠品"
elseif plid=5 then
   recommend =0
   plidtitle="上架"
elseif plid=6 then
   recommend =0
   plidtitle="下架"
elseif plid=7 then
   recommend =0
   plidtitle="缺货"
elseif plid=8 then
   recommend =0
   plidtitle="销售排行"

else
  recommend =0
  plidtitle="所有商品"
end if

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
conn.execute "delete from sdx_product where id in ("&selectid&")"
response.Redirect "admin_allpro.asp"
response.End
end if
%>
<table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" BGCOLOR="#39867B">
  <tr> 
    <td align="center"><font color="#FFFFFF">商品查询</font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <form name="form2" method="post" action="admin_allpro.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="proname">按商品名称</OPTION>
                <OPTION VALUE="brand">按品牌类别</OPTION>
                <OPTION VALUE="intro">按商品简介</OPTION>
              </select> </td>
            <td width="20%"><input type="submit" name="Submit" value="查 询" onClick="return chkkey();"></td>
          </tr>
        </table></td>
    </form>
  </tr>
</table>
<table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" class=table-xia >
          
        
          
           <tr bgcolor="#FFFFFF" align="left" height="20" class=table-xia> 
 <td height="20" align="right"  >
<font color="#FFFFFF">商品查看与修改----</font><font color="#FF0000"><b>全部商品</b></font></td><td height="20" align="right"><select NAME="select" ONCHANGE="var jmpURL=this.options[this.selectedIndex].value ; if(jmpURL!='') {window.location=jmpURL;} else {this.selectedIndex=0 ;}" ><BASE TARGET=Right> 
<OPTION selected>按属性修改</OPTION>
  <option value="admin_allpro.asp?plid=0">所有</option>
  <option value="admin_allpro.asp?plid=1">新品</option>
  <option value="admin_allpro.asp?plid=2">推荐</option>
  <option value="admin_allpro.asp?plid=3">特价</option>
  <option value="admin_allpro.asp?plid=4">赠品</option>
  <option value="admin_allpro.asp?plid=5">上架</option>
  <option value="admin_allpro.asp?plid=6">下架</option>
  <option value="admin_allpro.asp?plid=7">缺货</option> 
  <option value="admin_allpro.asp?plid=8">销售</option>                        
   
</select> </td><td height="20" align="right" ><select NAME="select" ONCHANGE="var jmpURL=this.options[this.selectedIndex].value ; if(jmpURL!='') {window.location=jmpURL;} else {this.selectedIndex=0 ;}" ><BASE TARGET=Right> 
<OPTION selected>通过分类修改</OPTION>
<%   Dim rs2
	  set rs2= server.CreateObject("adodb.recordset")
	  rs2.open "select categoryid,category from category where first=0 order by categoryorder",conn,1,1
	  if rs2.eof and rs2.bof then
	  response.Write "<tr><td align=center>还没有商品分类</td></tr>"
	  else
	  do while not rs2.eof %>

          
          <OPTION value="admin_allprobc.asp?bid=<% = rs2("categoryid") %>"><% = rs2("category") %></OPTION>
          <% 
	  Dim rs1
	  set rs1 = server.CreateObject("adodb.recordset")
	  rs1.open "select categoryid,sortsid,sorts from sorts where sorts.categoryid="&rs2("categoryid")&" order by sortsorder",conn,1,1
	 do while not rs1.eof %>
          <OPTION value="admin_allprosc.asp?bid=<% = rs1("categoryid") %>&sid=<% = rs1("sortsid") %>">&nbsp;&nbsp;→<% = rs1("sorts") %></OPTION>
 <%
	  rs1.movenext  %>
              <% if rs1.eof then %>
             
   
<%	  rs1.movenext 
	 end if
	  loop
	  rs1.close
	  set rs1 = nothing %>
            <%
	  rs2.movenext
	  loop
	  rs2.close
	  set rs2 = nothing
	  end if
	  %>   
</select>  </td></tr></table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" BGCOLOR="#39867B">
  <tr> 
    <td height="20" align="center"><font color="#FFFFFF">商品查看与修改</font></td>
  </tr>
  <tr> 
    <form name="myform" method="post" action="admin_saveeditall.asp?action=editall">
      <td height="100" bgcolor="#FFFFFF"> 
        <%
				Const MaxPerPage=50
   				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 ""
                            if plid="" or plid=0 then
                           rs.open "select * from product order by adddate desc",conn,1,1
                             elseif plid=1 then
                            rs.open "select * from product where recommend=1 order by adddate desc",conn,1,1
                          
                           elseif plid=2 then
                            rs.open "select * from product where recommend=2 order by adddate desc",conn,1,1 

                          elseif plid=3 then
                            rs.open "select * from product where recommend=3 order by adddate desc",conn,1,1 
                           
                          elseif plid=4 then
                            rs.open "select * from product where recommend=4 order by adddate desc",conn,1,1 
    
                            
                          elseif plid=5 then
                            rs.open "select * from product where proup=0 order by  adddate desc",conn,1,1 

                           
                          elseif plid=6 then
                            rs.open "select * from product where proup=1 order by adddate desc",conn,1,1 

                          elseif plid=7 then
                            rs.open "select * from product where stock<=0 order by adddate desc",conn,1,1 
                           elseif plid=8 then
                            rs.open "select * from product  order by solded desc",conn,1,1 
   
                            else 
                           rs.open "select * from product order by adddate desc",conn,1,1    
                           end if
		       case "0"
			response.write "<center>请返回选择您要查询的方式！<br><br><a href=javascript:history.go(-1)>点击返回上一页</a></center>"
			response.End
		       case "proname"

                           if plid="" or plid=0 then
                           rs.open "select * from product where name like '%"&selectkey&"%' order by adddate desc",conn,1,1
                             elseif plid=1 then
                            rs.open "select * from product where recommend=1 and name like '%"&selectkey&"%' order by adddate desc",conn,1,1
                          
                           elseif plid=2 then
                            rs.open "select * from product where recommend=2 and name like '%"&selectkey&"%' order by adddate desc",conn,1,1 

                          elseif plid=3 then
                            rs.open "select * from product where recommend=3 and name like '%"&selectkey&"%' order by adddate desc",conn,1,1 
                           
                          elseif plid=4 then
                            rs.open "select * from product where recommend=4 and name like '%"&selectkey&"%' order by adddate desc",conn,1,1 
    
                            
                          elseif plid=5 then
                            rs.open "select * from product where proup=0 and name like '%"&selectkey&"%' order by  adddate desc",conn,1,1 

                           
                          elseif plid=6 then
                            rs.open "select * from product where proup=1 and name like '%"&selectkey&"%' order by adddate desc",conn,1,1 

                          elseif plid=7 then
                            rs.open "select * from product where stock<=0 and name like '%"&selectkey&"%' order by adddate desc",conn,1,1 
                           elseif plid=8 then
                            rs.open "select * from product where  name like '%"&selectkey&"%' order by solded desc",conn,1,1 
   
                            else 
                           rs.open "select * from product where  name like '%"&selectkey&"%' order by adddate desc",conn,1,1    
                           end if
			
		       case "brand"
                             if plid="" or plid=0 then
                           rs.open "select * from product where brand like '%"&selectkey&"%' order by adddate desc",conn,1,1
                             elseif plid=1 then
                            rs.open "select * from product where recommend=1 and brand like '%"&selectkey&"%' order by adddate desc",conn,1,1
                          
                           elseif plid=2 then
                            rs.open "select * from product where recommend=2 and brand like '%"&selectkey&"%' order by adddate desc",conn,1,1 

                          elseif plid=3 then
                            rs.open "select * from product where recommend=3 and brand like '%"&selectkey&"%' order by adddate desc",conn,1,1 
                           
                          elseif plid=4 then
                            rs.open "select * from product where recommend=4 and brand like '%"&selectkey&"%' order by adddate desc",conn,1,1 
    
                            
                          elseif plid=5 then
                            rs.open "select * from product where proup=0 and brand like '%"&selectkey&"%' order by  adddate desc",conn,1,1 

                           
                          elseif plid=6 then
                            rs.open "select * from product where proup=1 and brand like '%"&selectkey&"%' order by adddate desc",conn,1,1 

                          elseif plid=7 then
                            rs.open "select * from product where stock<=0 and brand like '%"&selectkey&"%' order by adddate desc",conn,1,1 
                           elseif plid=8 then
                            rs.open "select * from product where  brand like '%"&selectkey&"%' order by solded desc",conn,1,1 
   
                            else 
                           rs.open "select * from product where  brand like '%"&selectkey&"%' order by adddate desc",conn,1,1    
                           end if


			
		       case "intro"
                         if plid="" or plid=0 then
                           rs.open "select * from product where introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1
                             elseif plid=1 then
                            rs.open "select * from product where recommend=1 and introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1
                          
                           elseif plid=2 then
                            rs.open "select * from product where recommend=2 and introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1 

                          elseif plid=3 then
                            rs.open "select * from product where recommend=3 and introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1 
                           
                          elseif plid=4 then
                            rs.open "select * from product where recommend=4 and introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1 
    
                            
                          elseif plid=5 then
                            rs.open "select * from product where proup=0 and introduce like '%"&selectkey&"%' order by  adddate desc",conn,1,1 

                           
                          elseif plid=6 then
                            rs.open "select * from product where proup=1 and introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1 

                          elseif plid=7 then
                            rs.open "select * from product where stock<=0 and introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1 
                           elseif plid=8 then
                            rs.open "select * from product where  introduce like '%"&selectkey&"%' order by solded desc",conn,1,1 
   
                            else 
                           rs.open "select * from product where  introduce like '%"&selectkey&"%' order by adddate desc",conn,1,1    
                           end if

			
		     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,"admin_allpro.asp"
       				else
          				if (currentPage-1)*MaxPerPage<totalPut then
            				rs.move  (currentPage-1)*MaxPerPage
            				dim bookbrand
            				bookbrand=rs.bookbrand
            				showContent
             				showpage totalput,MaxPerPage,"admin_allpro.asp"
        				else
	        				currentPage=1
           					showContent
           					showpage totalput,MaxPerPage,"admin_allpro.asp"
	      				end if
	   				end if
   				   				end if

   				sub showContent
       			dim i
	   			i=0%>
        <table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
          <tr bgcolor="#FFFFFF" align="center" height="20" > 
            <td width="15%">商品名称</td>
            <td width="5%" class=table-youxia>市场价</td>
            <td width="5%"class=table-youxia>网店价</td>
           
            <td width="25%" class=table-youxia>品牌</td>
            <td width="5%" class=table-youxia>已售</td>
            <td width="5%" class=table-youxia>库存</td>
            <td width="10%" class=table-youxia>性质</td>
            <td width="10%" class=table-youxia>上架</td>
            <td width="5%" class=table-youxia >排序</td>
            <td width="5%" class=table-youxia >详细</td>
            <td width="5%" class=table-youxia>选择</td>
        
 </tr>
          <%
		  do while not rs.eof%>
           <tr bgcolor="#FFFFFF" align="left" height="20" class=table-xia  onMouseOver="style.backgroundColor='#C6EBDE'" onmouseout="style.backgroundColor='#ffffff'"> 
  
           <td  align="left" class=table-youxia><input name="name<%=rs("id")%>" type="text" id="name<%=rs("id")%>" size="20" value="<%=trim(rs("name"))%>"></td>
        
           <td class=table-youxia><input name="price1<%=rs("id")%>" type="text" id="price1<%=rs("id")%>" size="5" value="<%=trim(rs("price1"))%>"></td>
           <td  class=table-youxia><input name="price2<%=rs("id")%>" type="text" id="price2<%=rs("id")%>" size="5" value="<%=trim(rs("price2"))%>"></td>
           <td  class=table-youxia><input name="brand<%=rs("id")%>" type="text" id="brand<%=rs("id")%>" size="10" value="<%=trim(rs("brand"))%>">
         <%
set rsbrand=server.createobject("adodb.recordset")
rsbrand.open "select * from sundxbrand order by brandTop ",conn,1,1
%>
              <select name="Selectbrand" onChange="(document.myform.brand<%=rs("id")%>.value=this.options[this.selectedIndex].value)">
                <option selected>请选择品牌</option>
				<% Do While Not rsbrand.Eof %>
                <option value="<% = Trim(rsbrand("brandName")) %>"><% = rsbrand("brandName")%></option>
                <%
rsbrand.movenext
Loop
rsbrand.close
set rsbrand=nothing
%></select>
          </td>
           
           <td  class=table-youxia><input name="solded<%=rs("id")%>" type="text" id="solded<%=rs("id")%>" size="3" value="<%=trim(rs("solded"))%>"></td>
           <td  class=table-youxia><input name="stock<%=rs("id")%>" type="text" id="stock<%=rs("id")%>" size="3" value="<%=trim(rs("stock"))%>"></td>
           <td  class=table-youxia>
                    <select name="recommend<%=rs("id")%>" id="recommend<%=rs("id")%>">
			<option value="0" <% if rs("recommend")=0 Then Response.write("Selected") %>>普通</option>
                        <option value="1" <% if rs("recommend")=1 Then Response.write("Selected") %>>新品</option>
                        <option value="2" <% if rs("recommend")=2 Then Response.write("Selected") %>>推荐</option>
                        <option value="3" <% if rs("recommend")=3 Then Response.write("Selected") %>>特价</option>
                        <option value="4" <% if rs("recommend")=4 Then Response.write("Selected") %>>赠品</option>
                     </select>
          </td>
          <td  class=table-youxia>
                   <select name="proup<%=rs("id")%>" id="proup<%=rs("id")%>">
                   <option value="0" <% if rs("proup")=0 Then Response.write("Selected") %>>上架</option>
                  <option value="1" <% if rs("proup")=1 Then Response.write("Selected") %>>下架</option>
              </select>
          </td>
         <td class=table-youxia><input name="ordernum<%=rs("id")%>" type="text" id="ordernum<%=rs("id")%>" size="3" value="<%=trim(rs("ordernum"))%>"></td>
          <td class=table-youxia><a href=editpro.asp?id=<%=rs("id")%> target="_blank">详细</a></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="14" align="right"><input name="thes" type="button" onclick="javascript:selectall()" value="全选" /> &nbsp;&nbsp; <input type="submit" name="Submit2" value="修 改" >
                &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

if plid<>"" then
  filename="admin_allpro.asp?plid="&plid&"&"
else
  filename="admin_allpro.asp?"

end if
				
				
				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'>转到第：" %> 
<select name="state" onChange="var jmpURL=this.options[this.selectedIndex].value ; if(jmpURL!='') {window.location=jmpURL;} else {this.selectedIndex=0 ;}" > 
             <% 
              For p = 1 To n %>
            <option value="<% = filename %>page=<%=p%>" <% if p=CurrentPage Then Response.write("Selected") %> ><%=p%></option> 
            
           <% next %>      
            
       </select>
	<%End Function  %>
</form>
</p></td>
   
  </tr>

</table>
<br>
<table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" BGCOLOR="#39867B">
  <tr> 
    <td align="center"><font color="#FFFFFF">商品查询</font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <form name="form2" method="post" action="admin_allpro.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="proname">按商品名称</OPTION>
                <OPTION VALUE="brand">按品牌类别</OPTION>
                <OPTION VALUE="intro">按商品简介</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;
   }
}
function selectall() 
{ 
   var a = document.getElementsByTagName("input"); 
   for (var i=0; i<a.length; i++) 
      if (a[i].type == "checkbox") a[i].checked =!a[i].checked; 
  } 


</script>

<script>
	function regInput(obj, reg, inputStr)
	{
		var docSel	= document.selection.createRange()
		if (docSel.parentElement().tagName != "INPUT")	return false
		oSel = docSel.duplicate()
		oSel.text = ""
		var srcRange	= obj.createTextRange()
		oSel.setEndPoint("StartToStart", srcRange)
		var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
		return reg.test(str)
	}
</script>