<?php
	//session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	//require_once('inc/check.php');
	$opendb=new mydb();
	
	$cateid=$_GET['cateid'];
	$catename=$_GET['catename'];
	$midcateid=$_GET['midcateid'];
	$midcatename=$_GET['midcatename'];
	$subcateid=$_GET['subcateid'];
	$subcatename=$_GET['subcatename'];

	if ($_GET['ls_msg']=="")
	{
		$ls_msg="管理操作";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$nownum=$_GET['Num'];
	
	$cateid=$_GET['cateid'];
	$catename=$_GET['catename'];
	$midcateid=$_GET['midcateid'];
	$midcatename=$_GET['midcatename'];
	$subcateid=$_GET['subcateid'];
	$subcatename=$_GET['subcatename'];
	$productID=$_GET['productID'];
	$searchproductName=$_POST['searchproductName'];
	
	if($subcateid=="" && $midcateid=="" && $cateid=="")
		{
			$ls_msg2="产品管理 >> 所有产品 ";	
		}
		if($_GET['catename']!="")
		{
			$ls_msg2="<a href=\"".$_SERVER['PHP_SELF']."\">产品管理</a>  >> <a href=\"?cateid=".$cateid."&catename=".$catename."\">".$_GET['catename']."</a> >> 所有产品 "	;
		}
		if($_GET['midcatename']!="")
		{
			$ls_msg2="<a href=\"".$_SERVER['PHP_SELF']."\">产品管理</a>  >> <a href=\"?cateid=".$cateid."&catename=".$catename."\">".$_GET['catename']."</a> >> <a href=\"?cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."\">".$_GET['midcatename']."</a> >> 所有产品 "	;
		}

		if($_GET['subcatename']!="")
		{
			$ls_msg2="<a href=\"".$_SERVER['PHP_SELF']."\">产品管理</a>  >> <a href=\"?cateid=".$cateid."&catename=".$catename."\">".$_GET['catename']."</a> >> <a href=\"?cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."\">".$_GET['midcatename']."</a> >> <a href=\"?cateid=".$cateid."&catename=".$catename."&subcateid=".$subcateid."&subcatename=".$subcatename."\">".$_GET['subcatename']."</a> >> 所有产品 "	;
		}
	
	switch ($ls)
	{
		case "up":
		
			$productID_sql="select * from ls_products where id=".$id." ";
			$productID_query=$opendb->query($productID_sql);
			$productID_row=mysql_fetch_assoc($productID_query);

			$down=$nownum-1;
			$down_sql="update ls_products set Num=".$nownum." where Num=".$down." and productID=".$productID_row['productID'];
			$down_sql2="update ls_products set Num=Num-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$down_query=$opendb->query($down_sql2);
			$ls_msg="上移操作成功！";		
			break;
		case "down":
			$productID_sql="select * from ls_products where id=".$id." ";
			$productID_query=$opendb->query($productID_sql);
			$productID_row=mysql_fetch_assoc($productID_query);
			
			$up=$nownum+1;
			$up_sql="update ls_products set Num=".$nownum." where Num=".$up." and productID=".$productID_row['productID'];
			$up_sql2="update ls_products set Num=Num+1 where id=".$id." ";
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$up_query=$opendb->query($up_sql2);

			$ls_msg="下移操作成功！";

			break;
		case "reserverthiscate":	
			$productID_sql="select * from ls_products where productID=".$productID." ";
			$productID_query=$opendb->query($productID_sql);
			$productID_num=mysql_num_rows($productID_query);
			$update_sql="update ls_products set Num=".$productID_num."-Num+1 where productID=".$productID." ";
			$productID_query=$opendb->query($update_sql);

			break;
		case "resortitemnodesc":	
			$productID_sql="select DISTINCT productID FROM ls_products where productID<>''"; //选择唯一productID
			$productID_query=$opendb->query($productID_sql);
			while($productID_row=mysql_fetch_assoc($productID_query))
			{
				$oneproductID_sql="select * FROM ls_products where productID=".$productID_row['productID']." order by productItemNo desc"; //选择唯一productID
				$oneproductID_query=$opendb->query($oneproductID_sql);
				$oneproductID_num=mysql_num_rows($oneproductID_query);
				$i=0;
				while($oneproductID_row=mysql_fetch_assoc($oneproductID_query))
				{
					$update_num="update ls_products set Num=".($oneproductID_num-$i)." where ID=".$oneproductID_row['ID']." ";
					//echo $update_num;
					$update_num_query=$opendb->query($update_num);

					$i++;
				}				
			}
			break;
		case "resortitemnoasc":	
			$productID_sql="select DISTINCT productID FROM ls_products where productID<>''"; //选择唯一productID
			$productID_query=$opendb->query($productID_sql);
			while($productID_row=mysql_fetch_assoc($productID_query))
			{
				$oneproductID_sql="select * FROM ls_products where productID=".$productID_row['productID']." order by productItemNo asc"; //选择唯一productID
				$oneproductID_query=$opendb->query($oneproductID_sql);
				$oneproductID_num=mysql_num_rows($oneproductID_query);
				$i=0;
				while($oneproductID_row=mysql_fetch_assoc($oneproductID_query))
				{
					$update_num="update ls_products set Num=".($oneproductID_num-$i)." where ID=".$oneproductID_row['ID']." ";
					//echo $update_num;
					$update_num_query=$opendb->query($update_num);

					$i++;
				}				
			}			break;
	 	case "unenable":
			$unenable_sql="update ls_products set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_products set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
	  case "del":
			
			//获取文件目录
			$subcate_sql="select productID from ls_products where ID=".$id." "; 
			$subcate_sql="select * from ls_products where ID=(".$subcate_sql.")";
			$subcate_query=$opendb->query($subcate_sql);
			$subcate_myrows=mysql_fetch_assoc($subcate_query);
			if($subcate_myrows['subcateFolders']!='')
			{
			$pathFoldersProducts=$subcate_myrows['subcateFolders'];

			$productPID=$subcate_myrows['ID'];// 为产生顺序号Num采集变量
			$midcate_sql="select * from ls_products where ID=(".$subcate_myrows['subcateID'].")";
			$midcate_query=$opendb->query($midcate_sql);
			$midcate_myrows=mysql_fetch_assoc($midcate_query);
			$pathFoldersProducts=$midcate_myrows['midcateFolders']."/".$pathFoldersProducts;

			$cate_sql="select * from ls_products where ID=(".$midcate_myrows['midcateID'].")";
			$cate_query=$opendb->query($cate_sql);
			$cate_myrows=mysql_fetch_assoc($cate_query);
			$pathFoldersProducts="../".$cate_myrows['cateFolders']."/".$pathFoldersProducts;

			}
			else // no subcate
			{
			$midcate_sql="select productID from ls_products where ID=".$id." "; 
			$midcate_sql="select * from ls_products where ID=(".$midcate_sql.")";
			$midcate_query=$opendb->query($subcate_sql);
			$midcate_myrows=mysql_fetch_assoc($midcate_query);
			
			if($midcate_myrows['midcateFolders']!='')
			{
				$pathFoldersProducts=$midcate_myrows['midcateFolders'];

				$productPID=$midcate_myrows['ID'];// 为产生顺序号Num采集变量
				$cate_sql="select * from ls_products where ID=(".$midcate_myrows['midcateID'].")";
				$cate_query=$opendb->query($cate_sql);
				$cate_myrows=mysql_fetch_assoc($cate_query);
				$pathFoldersProducts="../".$cate_myrows['cateFolders']."/".$pathFoldersProducts;
			}
			else
			{
				$cate_sql="select productID from ls_products where ID=".$id." "; 
				$cate_sql="select * from ls_products where ID=(".$cate_sql.")";
				$cate_query=$opendb->query($cate_sql);
				$cate_myrows=mysql_fetch_assoc($cate_query);
				$pathFoldersProducts="../".$cate_myrows['cateFolders'];
				$productPID=$cate_myrows['ID'];// 为产生顺序号Num采集变量

			}
		}
	
			$products_sql="select * from ls_products where ID=".$id." ";
			$products_query=$opendb->query($products_sql);
			$products_rows=mysql_fetch_assoc($products_query);
			//获取文件目录
			$Bigpicsrc=$pathFoldersProducts."/".$BigFoldersProducts."/".$products_rows['productPic'];
			$Smallpicsrc=$pathFoldersProducts."/".$SmallFoldersProducts."/".$products_rows['productPic'];
			$Bigpicsrc1=$pathFoldersProducts."/".$BigFoldersProducts;
			$Smallpicsrc1=$pathFoldersProducts."/".$SmallFoldersProducts;
			$pagesrc=$pathFoldersProducts."/".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html";;
			$pagesrc1=$pathFoldersProducts."/".$showproductsFolders;
			//删除文件 
			 
			$products_sql="select productID from ls_products where ID=".$id." ";			
			$products_sql="select * from ls_products where productID=(".$products_sql.") ";	
			$products_query=$opendb->query($products_sql);
			$products_num=mysql_num_rows($products_query);
		  	if($products_num!=1)
			{
				unlink($Bigpicsrc);
				unlink($Smallpicsrc);
				unlink($pagesrc);
			}
			else
			{
				unlink($Bigpicsrc);
				unlink($Smallpicsrc);
				unlink($pagesrc);
				rmdir($Bigpicsrc1);
				rmdir($Smallpicsrc1);
				rmdir($pagesrc1);
			}
			$del_sql="delete from ls_products where ID=".$id."";
	   		//echo $del_sql;
		   	$del_query=$opendb->query($del_sql);
			$num_sql2="update ls_products set Num=Num-1 where productID=".$productPID." and Num>".$products_rows['Num']." ";//all order number-1
			$down_query=$opendb->query($num_sql2);
			
		   	$ls_msg="删除操作成功！";
			
		 	break;
			
	}
	
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="admin.css" rel="stylesheet" type="text/css">
<script language="JavaScript" >
// Creat Date 2008.1.18 Edit by Jia  End
//=========================================================

// Creat Date 2008.1.19 Edit by Jia  Start
// 函数 unselectall  产品取消选择
// 函数 CheckAll  产品全部选择
//		  参数 ： 无
function unselectall()
{
	if(document.del.chkAll.checked){
	document.del.chkAll.checked = document.del.chkAll.checked&0;
	} 	
}

function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
	{
	var e = form.elements[i];
	if (e.Name != "chkAll")
	   e.checked = form.chkAll.checked;
	}
}

</script>
<title>无标题文档</title>
</head>
<body>
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
  <tr>
	<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>产品管理</strong></font></div></td>
  </tr>
  <tr>
	<td height="213" valign="top" bgcolor="#dee7ff"><table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#dee7ff">
	  <tr >
		<td width="40%" height="20" align="left" style="padding-left:6px;"><? echo $ls_msg;?></td>
		<td width="41%" align="right" style="padding-left:6px;"><a href="?ls=resortitemnodesc">按货号降序重排全部产品</a></td>
		<td width="19%" align="right" style="padding-left:6px;"><a href='?ls=resortitemnoasc' >按货升序重排部产品</a></td>
	  </tr>
	</table>
	  <form name="del" method="Post" action="delall.php" onSubmit="return ConfirmDel();">
		<?php
		//大类
		//////////////////////////////////////////////////////////////////////////
		$cate_sql="select * from ls_products where midcateName is null and midcateID is null and subcateName is null and subcateFolders is null and subcateBrief is null and subcateID is null and productPic is null and productItemNo is null and productName is null and productSpecification is null and productID is null  and enable=1 order by Num asc";
		$cate_query=$opendb->query($cate_sql);
		$cate_num=mysql_num_rows($cate_query); 
		if($cate_num!=0)
		{
			$i=1;
			echo "
	 <table width=\"90%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#FFFFFF\">
				<tr bgcolor=\"#A4B6D7\">
					<td>
	 ";
			while($cate_rows=mysql_fetch_assoc($cate_query))
			 {
if($i==1)
{  
	echo 大类.":";
	echo "&nbsp;<a href=\"?cateid=".$cate_rows['ID']."&catename=".$cate_rows['cateName']."\" >";
	if($cateid==$cate_rows['ID'])
	{
		echo "<font color=\"#FF0000\"><b>".$cate_rows['cateName']."</b></font>";
	}
	else
	{
		
		echo $cate_rows['cateName'];
	}
	echo "</a> ";
			 	}
else
{
	echo "| <a href=\"?cateid=".$cate_rows['ID']."&catename=".$cate_rows['cateName']."\" >";
	if($cateid==$cate_rows['ID'])
	{
		echo "<font color=\"#FF0000\"><b>".$cate_rows['cateName']."</b></font>";
	}
	else
	{
		echo $cate_rows['cateName'];
	}
	echo "</a> ";
	}
	$i++;
	}
	 echo "
	 </td>
	</tr>
	 </table>
	";
		
		//中类
		if($cateid!="")
		{
			$midcate_sql="select * from ls_products where cateName is null and cateFolders is null and catePagePic is null and catePagePicWidth is null and catePagePicHeight is null and subcateName is null and subcateID is null and cateBrief is null and productPic is null and productItemNo is null and productName is null and productSpecification is null and productID is null and enable=1 and midcateID=".$cateid." order by Num asc";
			$midcate_query=$opendb->query($midcate_sql);
			$midcate_num=mysql_num_rows($midcate_query); 
			if($midcate_num!=0)
			{
			$i=1;
			echo "
			 <table width=\"90%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#FFFFFF\">
				<tr bgcolor=\"#CCCCCC\">
				<td>
			 ";
		while($midcate_rows=mysql_fetch_assoc($midcate_query))
		 {
		if($i==1)
		{  
		echo   中类.":";
		echo "&nbsp;<a href=\"?midcateid=".$midcate_rows['ID']."&cateid=".$cateid."&catename=".$_GET['catename']."&midcatename=".$midcate_rows['midcateName']."\">";
		$j=0;
		$firstmidcateid=$midcate_rows['ID'];
		if($midcateid==$midcate_rows['ID'])
		{
		echo "<font color=\"#880812\"><b>".$midcate_rows['midcateName']."</b></font>";
		$j++;
	}
	else
	{
		echo $midcate_rows['midcateName'];
	}
			
	echo "</a>";
}
else
{
	echo " | <a href=\"?midcateid=".$midcate_rows['ID']."&cateid=".$cateid."&catename=".$_GET['catename']."&midcatename=".$midcate_rows['midcateName']."\">";
	if($midcateid==$midcate_rows['ID'])
	{
		echo "<font color=\"#880812\"><b>".$midcate_rows['midcateName']."</b></font>";
		$j++;
	}
	else
	{
		echo $midcate_rows['midcateName'];
	}
	echo "</a>";
}
$i++;
			 }
			 if($j==0)
			{
			$midcateid=$firstmidcateid;
			}
			 echo "
			</td>
			</tr>
			 </table>
			";
		}
	}
		
			//小类
		//echo $cateid."--".$midcateid."--".$subcateid;	
		if($cateid!="" && $midcateid!="")
		{
				$subcate_sql="select * from ls_products where cateName is null and cateFolders is null and catePagePic is null and catePagePicWidth is null and catePagePicHeight is null and cateBrief is null and midcateName is null and midcateID is null and productPic is null and productItemNo is null and productName is null and productSpecification is null and productID is null and enable=1 and subcateID=".$midcateid." order by Num asc";
				$subcate_query=$opendb->query($subcate_sql);
				$subcate_num=mysql_num_rows($subcate_query); 
				if($subcate_num!=0)
				{
					$i=1;
					echo "
							 <table width=\"90%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#FFFFFF\">
						<tr bgcolor=\"#E0E0E0\">
							<td>
							 ";
					while($subcate_rows=mysql_fetch_assoc($subcate_query))
					 {
						if($i==1)
						{  
						echo   小类.":";
							echo "&nbsp;<a href=\"?subcateid=".$subcate_rows['ID']."&cateid=".$cateid."&catename=".$catename."&midcatename=".$midcatename."&midcateid=".$midcateid."&subcatename=".$subcate_rows['subcateName']."\">";
							$k=0;
							$firstsubcatetid=$subcate_rows['ID'];
							if($subcateid==$subcate_rows['ID'])
							{
								echo "<font color=\"#880812\"><b>".$subcate_rows['subcateName']."</b></font>";
								$k++;
							}
							else
							{
								echo $subcate_rows['subcateName'];
							}
							echo "</a>";
						}
						else
						{
							echo " | <a href=\"?subcateid=".$subcate_rows['ID']."&cateid=".$cateid."&catename=".$catename."&midcatename=".$midcatename."&midcateid=".$midcateid."&subcatename=".$subcate_rows['subcateName']."\">";
							if($subcateid==$subcate_rows['ID'])
							{
								echo "<font color=\"#880812\"><b>".$subcate_rows['subcateName']."</b></font>";
								$k++;
							}
							else
							{
								echo $subcate_rows['subcateName'];
							}
							echo "</a>";
						}
						$i++;
					 }
					 if($k==0)
					 {
					 	$subcatetid=$firstsubcatetid;
					 }
					 echo "
					 				</td>
					 			</tr>
					 		 </table>
					 			";
				}
		}
		
//////////////////////////////////////////////////////////////////////////
			
?>
		<?php 
if( isset($_GET['page']) ){
	   $page = intval( $_GET['page'] );
	}
	else{
	   $page = 1;
	}
	// 每页数量
	$PageSize = $PageNum;
	
	// 获取总数据量
	/********************************************************************************/
		$sql="select * from ls_products where midcateName is null and cateName is null and cateFolders is null and catePagePic is null and catePagePicWidth is null and catePagePicHeight is null and cateBrief is null and subcateName is null and subcateFolders is null and subcateBrief is null and subcateID is null ";
	
	//大类
	$sqlID="";
	$displaydownup="";//显示上移下移箭头
	if($cateid!=""  && $midcateid=="" && $subcateid=="" && $searchproductName=="")
	{
		//大类下有中类
		$sqlstr="select ID from ls_products where midcateID =".$cateid." ";
		$query1=$opendb->query($sqlstr);
		$mynum=mysql_num_rows($query1);
		if($mynum!=0)
		{
			$i=1;
			while($myrows=mysql_fetch_assoc($query1))			
			{
				$sqlstr2="select ID from ls_products where subcateID =".$myrows['midcateID']." ";
				$query2=$opendb->query($sqlstr2);
				$mynum2=mysql_num_rows($query2);
				
if($mynum2!=0) //中类下有小类
{
	while($myrows2=mysql_fetch_assoc($query2))			
	{
		if($i==1)
		{
			$sqlID.="productID=".$myrows2['ID'];
		}
		else
		{
			$sqlID.=" or productID=".$myrows2['ID'];
		}
		$i++;
	}
	
}
else//中类下没小类
{
	if($i==1)
	{
		$sqlID.="productID=".$myrows['midcateID'];
	}
	else
	{
		$sqlID.=" or productID=".$myrows['midcateID'];
	}
	$i++;
}
			
			}
			
		//	echo $productID."<br>";
		$sql.="and （".$sqlID."）";
	  }
	  else
	  {//大类下没有中类
	  	$displaydownup="ok";
	  	$sql.="and productID=".$cateid;
	  }
	}
	
	//中类
	
	if($midcateid!="" && $subcateid=="" && $searchproductName=="")
	{
		//中类下有小类
		$sqlstr="select ID from ls_products where subcateID =".$midcateid." ";
		$query1=$opendb->query($sqlstr);
		$mynum=mysql_num_rows($query1);
		if($mynum!=0)
		{
			$i=1;
			while($myrows=mysql_fetch_assoc($query1))
			{
				if($i==1)
				{
					$sqlID.="productID=".$myrows['ID'];
				}
				else
				{
					$sqlID.=" or productID=".$myrows['ID'];
				}
				$i++;
			}
		//	echo $productID."<br>";
		$sql.="and (".$sqlID.")";
	  }
	  else
	  {//中类下没有小类
		  	$sql.="and productID=".$midcateid;
  	  		$displaydownup="ok";
	  }
	}
	
	//小类
	if($subcateid!="" && $searchproductName=="")
		{
			$sql.="and productID=".$subcateid;
			$displaydownup="ok";
		}
		
	$products_sql=$sql; // for products list 查询数据库
		
	//查询数据
	if($searchproductName!="")
		{
			$sql.="and productName like '%".$searchproductName."%'";
		}
	
	
	$sql.=" order by Num asc ";	
	
		//echo $sql."<br>";
		//$sql = "select * from ls_products where cateName is null and cateFolders is null and catePagePic is null and catePagePicWidth is null and catePagePicHeight is null and cateBrief is null and subcateName is null and subcateFolders is null and subcateBrief is null and subcateID is null order by Num asc";
		$result=$opendb->query($sql);
	
	/********************************************************************************/
	// 获取总数据量
	
	$row = mysql_num_rows($result);
	$amount = $row;
	
	// 记算总共有多少页
	if( $amount ){
	   if( $amount < $PageSize ){ $page_count = 1; }			   //如果总数据量小于$PageSize，那么只有一页
	   if( $amount % $PageSize ){								  //取总数据量除以每页数的余数
		   $page_count = (int)($amount / $PageSize) + 1;		   //如果有余数，则页数等于总数据量除以每页数的结果取整再加一
	   }else{
		   $page_count = $amount / $PageSize;					  //如果没有余数，则页数等于总数据量除以每页数的结果
	   }
	}
	else{
	   $page_count = 0;
	}
	
	// 翻页链接
	$page_string = '';
	$pagecatestr="subcateid=".$subcateid."&midcateid=".$midcateid."&cateid=".$cateid."&catename=".urlencode($catename)."&midcatename=".urlencode($midcatename)."&subcatename=".urlencode($subcatename);
	if( $page == 1 ){
	   $page_string .= '首页 | 上一页 |';
	}
	else{
	   $page_string .= '<a href=?&page=1&'.$pagecatestr.'><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?&page='.($page-1)."&".$pagecatestr.'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
	}
	if( ($page == $page_count) || ($page_count == 0) ){
	   $page_string .= ' 下一页 | 尾页';
	}
	else{
	   $page_string .= ' <a href=?&page='.($page+1).'&'.$pagecatestr.'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?&page='.$page_count.'&'.$pagecatestr.'><u><font color=\"#0000FF\">尾页</font></u></a>';
	}
		 $page_string .= " &nbsp;&nbsp;页次：<font color='#FF0000'><b>".$page."</b></font>/<b>".$page_count."</b>页";
		 $page_string .= " &nbsp;&nbsp;<b>".$PageSize."</b>个产品每页";
	
	
	echo "<br>
<table border=\"0\" width=\"90%\" align=\"center\">
	<tr>
		<td>".$ls_msg2."</td>
		<td align=\"right\">共 <b>".$row."</b> 个产品</td>
	</tr>
</table>
";	 
		 
		/*\***************************************************************************\*/
		/*\查询数据库	\*/
		/*\***************************************************************************\*/ 

		
	//查询数据
	if($searchproductName!="")
		{
			$products_sql.="and productName like '%".$searchproductName."%'";
		}
	
	
	$products_sql.=" order by Num asc limit ". ($page-1)*$PageSize .",".$PageSize." ";	
	
	//echo $products_sql."<br>";
	$products_query=$opendb->query($products_sql);
		/*\***************************************************************************\*/
		/*\查询数据库	\*/
		/*\***************************************************************************\*/ 			
echo "	
	<table width=\"90%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#FFFFFF\">
				<tr bgcolor=\"#B9DAFF\">
			<td align=\"center\" height=\"25\" width=\"30\">选中</td>
			<td align=\"center\" width=\"16%\">产品编号</td>
			<td align=\"center\" width=\"34%\">产品名称</td>
			<td align=\"center\" >序号</td>
			<td align=\"center\" colspan=\"2\">排序</td>
			<td align=\"center\" colspan=\"2\">操作选项</td>
			<td align=\"center\" width=\"60\">是否显示</td>
		</tr>
	   ";
	
	$i=1;
	while($products_rows=mysql_fetch_assoc($products_query))
	 {
	 	
		 
		 	//查询大类
		 	$search_cate_sql="select subcateID from ls_products where ID = ".$products_rows['productID']."";
		 	$search_cate_sql="select midcateID from ls_products where ID=(".$search_cate_sql.")";
			$search_cate_sql="select * from ls_products where ID=(".$search_cate_sql.")";
		 	$search_cate_query=$opendb->query($search_cate_sql);
		 	$search_cate_rows=mysql_fetch_assoc($search_cate_query);
			
			//查询中类
		 	$search_midcate_sql="select subcateID from ls_products where ID = ".$products_rows['productID']."";
		 	$search_midcate_sql="select * from ls_products where ID=(".$search_midcate_sql.")";
		 	$search_midcate_query=$opendb->query($search_midcate_sql);
		 	$search_midcate_rows=mysql_fetch_assoc($search_midcate_query);
		
		 		//查询小类
		 	$search_subcate_sql="select * from ls_products where ID = ".$products_rows['productID']."";
		 	$search_subcate_query=$opendb->query($search_subcate_sql);
		 	$search_subcate_rows=mysql_fetch_assoc($search_subcate_query);
		 	
		 	//echo $search_subcate_sql."<br>";
		 	//echo $search_cate_sql."<br>";
	 	  //echo "小类".$search_subcate_rows['enable']."<br>";
	 	  //echo "小类".$search_subcate_rows['subcateName']."上大类".$search_cate_rows['cateName'].$search_cate_rows['enable']."<br>";
	 	  if(($search_cate_rows['enable']==1 || $search_cate_rows['enable']=="")&&($search_midcate_rows['enable']==1 || $search_midcate_rows['enable']==""))
	 	  {
	 	  	if($search_subcate_rows['enable']==1)
	 	  	{
	 	  	
 	  echo "<tr bgcolor='#f4f4f4'";
					echo "onMouseOver=";
		echo " 	this.style.backgroundColor='#CCFFCC' ";
		echo "onMouseOut=";
		echo " 	this.style.backgroundColor='#f4f4f4' ";
		echo ">";
		echo "	<td align='center'>";
		echo "		<input name='selectid".$i."' type='checkbox' onclick=\"unselectall()\" id=\"select_id\" value='".$products_rows['ID']."'>";
		echo "	</td>";
	  	echo "	<td style='padding-left:10px;'>";
		echo 		$products_rows['productItemNo'];
		echo "	</td>";
		echo "	<td style='padding-left:10px;'>";
		echo 		$products_rows['productName'];
		echo "	</td>";
		echo "	<td style='padding-left:4px;' align='center'>";
		echo 		$products_rows['Num'];
		echo "	</td>";
		echo "	<td align='center'> ";
		if($i!=1&&$displaydownup=="ok")
		{
		echo "		<a href='?id=".$products_rows['ID']."&Num=".$products_rows['Num']."&ls=up&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' title='向上移动'><img src='images/up.gif' border='0'></a>";
		}
		echo "  </td>";
		echo "	<td align='center'> ";
		if($i!=$amount&&$displaydownup=="ok")
		{
		echo "	 <a href='?id=".$products_rows['ID']."&Num=".$products_rows['Num']."&ls=down&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' title='向下移动'><img src='images/down.gif' border='0'></a>";
		}
		echo "  </td>";
		echo "	<td align='center'> ";
		echo "		<a href='modiproducts.php?id=".$products_rows['ID']."&cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."' title='编辑'><img src='images/b_edit.png' border='0'></a>";
		echo "  </td>";
		echo "	<td align='center'> ";
		echo "		<a href='?id=".$products_rows['ID']."&ls=del&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>";
		echo "  </td>";
		echo "	<td align='center'>";
		  
	  if($products_rows['enable']==1)
		{
		echo "<a href='?id=".$products_rows['ID']."&ls=unenable&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' title='显示'><img src='images/enable.gif' border='0'></a>";
		}
	  if($products_rows['enable']==0)
  		{
		echo "<a href='?id=".$products_rows['ID']."&ls=enable&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' title='不显示'><img src='images/unenable.gif' border='0'></a>";
		}
	
		echo "	</td>";
		echo "</tr>";
		$productID2=$products_rows['productID'];
		 }
	 }
	$i++;
	
	}
	echo "<tr bgcolor=\"#B9DAFF\">";
	echo "<td colspan='9' align='center' height='25'>";
	echo $page_string;
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	
		 
?>
		<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
		  <tr >
		  
			<td width="83%" style="padding-left:6px;"><input name="chkAll" type="checkbox" id="chkAll" onClick="CheckAll(this.form);" value="checkbox">
			  选中本页显示的所有产品
			  <input name="submit" type='submit' value='删除选定的产品'>
			  <input name="Action" type="hidden" id="Action" value="proDel">			</td>
			<td width="17%" style="padding-left:6px;"><a href='?ls=reserverthiscate&productID=<?=$productID2 ?>' >反向排列本类产品</a></td>
		  </tr>
		</table>
	  </form>
	  <form name="searchfm" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
		<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
		  <tr >
			<td style="padding-left:6px;" colspan="8"><strong>查找产品：</strong>
			  <input type="text" name="searchproductName" size="20" maxlength="50">
			  <input type="submit"  value="查 询">
			  &nbsp;&nbsp;请输入产品名称。如果为空，则查找所有产品。 </td>
		  </tr>
		</table>
	  </form>
	  <?php
			//大类
		 }
	?>
	</td>
  </tr>
</table>
</body>
</html>
