<?php
	require_once('_approot.php');
	
	$admininfo = $admin->getInfo();
	
	if ($_GET['ls_msg']==""){
		$ls_msg="管理操作";
	}else{
		$ls_msg=$_GET['ls_msg'];	
	}
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$nownum=$_GET['Num'];
	if($_GET['skipup1']>1){
		$skipup=$_GET['skipup1'];	
	}else{
		$skipup=$_GET['skipup'];	
	}//编号排序时用到的数字索引	升序
	
	if($_GET['skipdown1']>1){
		$skipdown=$_GET['skipdown1'];
	}else{
		$skipdown=$_GET['skipdown']	;
	}//编号排序时用到的数字索引	降序

	//print_r($_GET);
	$cateid=$_GET['cateid'];
	$catename=$_GET['catename'];
	$midcateid=$_GET['midcateid'];
	$midcatename=$_GET['midcatename'];
	$subcateid=$_GET['subcateid'];
	$subcatename=$_GET['subcatename'];
	$productID=$_GET['productID'];
	$searchproductName=trim(($_POST['searchproductName']==""?$_GET['searchproductName']:$_POST['searchproductName']));
	$searchRange=$_POST['searchrange'];
	//var_dump($HTTP_POST_VARS);
	//修正分类指示
	if(($cateid!="")&&($catename=="")){
		$getNameSql="select cateName from ls_products where ID=".$cateid;
		$getNameQuery=$opendb->query($getNameSql);
		$getNameRow=mysqli_fetch_assoc($getNameQuery);
		$catename=$getNameRow['cateName'];
	}
	if(($midcateid!="")&&($midcatename=="")){
		$getNameSql="select midcateName from ls_products where ID=".$midcateid;
		$getNameQuery=$opendb->query($getNameSql);
		$getNameRow=mysqli_fetch_assoc($getNameQuery);
		$midcatename=$getNameRow['midcateName'];
	}
	if(($subcateid!="")&&($subcatename=="")){
		$getNameSql="select subcateName from ls_products where ID=".$subcateid;
		$getNameQuery=$opendb->query($getNameSql);
		$getNameRow=mysqli_fetch_assoc($getNameQuery);
		$subcatename=$getNameRow['subcateName'];
	}
	//获取并定义排序用参数
	$sortKind=$_POST['SortKind'];
	$sortMethod=$_POST['SortMethod'];
	$sortIgnoreCate=($_POST['IgnoreCate']=="Ignore")?true:false;
	$sortCateOnly=($_POST['onlyGrandCate']=="OnlyCate")?true:false;
		
	if(isset($_GET['page'])&&$_GET['page']!=0){
	   $page = intval( $_GET['page'] );
	}else{
		$page = 1;
	}
	if($_POST['gopage']!=""){$page =(ctype_digit($_POST['gopage'])?$_POST['gopage']:1);}
		//更新的产品类别指示
		if($subcateid=="" && $midcateid=="" && $cateid==""){
			$ls_msg2="产品管理 >> 所有产品 ";	
		}
		if(($_GET['catename']!="")||($catename!="")){
			$ls_msg2="<a href=\"".$_SERVER['PHP_SELF']."\">产品管理</a>  >> <a href=\"?cateid=".$cateid."&catename=".$catename."\">".(($_GET['catename']!="")?$_GET['catename']:$catename)."</a> >> 所有产品 "	;
		}
		if(($_GET['midcatename']!="")||($midcatename!="")){
			$ls_msg2="<a href=\"".$_SERVER['PHP_SELF']."\">产品管理</a>  >> <a href=\"?cateid=".$cateid."&catename=".$catename."\">".(($_GET['catename']!="")?$_GET['catename']:$catename)."</a> >> <a href=\"?cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."\">".(($_GET['midcatename']!="")?$_GET['midcatename']:$midcatename)."</a> >> 所有产品 "	;
		}

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

			$allnum_sql="select * from ls_products where productID=".$productID_row['productID'];
			$allnum_query=$opendb->query($allnum_sql);
			$allnum=mysqli_num_rows($allnum_query);
			
			if($skipup>$nownum-1){
				//如果向上移动的值 大于 当前记录索引-1   则 向上移动的值 = 当前记录索引-1
				$skipup=$nownum-1;
			}
			if($skipup==0){
				//如果向上移动的值为0  则 向上移动的值为1
				$skipup=1;
			}
			
			$up=$nownum-$skipup;
			//echo $skipup."======";
			$up_sql="update ls_products set Num=Num+1 where Num>=".$up." and Num<".$nownum." and productID=".$productID_row['productID'];
			$up_sql2="update ls_products set Num=Num-".$skipup." where ID=".$id;
			$up_query=$opendb->query($up_sql);
			$up_query=$opendb->query($up_sql2);
			$ls_msg="下移操作成功！";		
			break;
		case "down":
			$productID_sql="select * from ls_products where ID=".$id." ";
			$productID_query=$opendb->query($productID_sql);
			$productID_row=mysqli_fetch_assoc($productID_query);

			$allnum_sql="select * from ls_products where productID=".$productID_row['productID'];
			$allnum_query=$opendb->query($allnum_sql);
			$allnum=mysqli_num_rows($allnum_query);
			
			if($skipdown>$allnum-$nownum){
				//如果向下移动的值 大于 总记录数-当前记录索引   则 向下移动的值 = 总记录数-当前记录索引
				$skipdown=$allnum-$nownum;
			}
			//echo $skipdown;exit;
			if($skipdown==0){
				//如果向下移动的值为0  则 向下移动的值为1
				$skipdown=1;
			}
			
			$down=$nownum+$skipdown;

			$down_sql="update ls_products set Num=Num-1 where Num<=".$down." and Num>".$nownum." and productID=".$productID_row['productID'];
			$down_sql2="update ls_products set Num=Num+".$skipdown." where ID=".$id;
			$down_query=$opendb->query($down_sql);
			$down_query=$opendb->query($down_sql2);

			$ls_msg="上移操作成功！";
			break;
		case "reserverthiscate":	
			$productID_sql="select * from ls_products where productID=".$productID." ";
			$productID_query=$opendb->query($productID_sql);
			$productID_num=mysqli_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 "restcate":
			$productID_sql="select * from ls_products where productID=".$productID." order by Num asc";
			$productID_query=$opendb->query($productID_sql);
			$i=1;
			while($row = mysqli_fetch_assoc($productID_query)){
				$sql = "update ls_products set Num=$i where ID=".$row['ID'];
				$opendb->query($sql);
				$i++;
			}
			$ls_msg="排序完成！";
			break;

		//全新群体排序模块
		case "sorting":
			SortPros($cateid,$midcateid,$subcateid,$sortKind,$sortMethod,$sortIgnoreCate,$sortCateOnly);
			$ls_msg="批量排序完成！";
			break;
	 	case "unenable":
			$unenable_sql="update ls_products set enable=0 where id=".$id." ";
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_products set enable=1 where id=".$id." ";
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
		case "del":
			//获取文件目录，采集序号Num变量
			$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=mysqli_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=mysqli_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=mysqli_fetch_assoc($cate_query);
				$pathFoldersProducts="../".$cate_myrows['cateFolders']."/".$pathFoldersProducts;
			}else{
				$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=mysqli_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=mysqli_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=mysqli_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=mysqli_fetch_assoc($products_query);
			//获取文件路径
			$Bigpicsrc=$pathFoldersProducts."/".$BigFoldersProducts."/".$products_rows['productPic'];
			$Smallpicsrc=$pathFoldersProducts."/".$SmallFoldersProducts."/".$products_rows['productPic'];
			$pagesrc=$pathFoldersProducts."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html";
			//获取大图，缩略图，网页文件所在目录
			$Bigpicsrc1=$pathFoldersProducts."/".$BigFoldersProducts;
			$Smallpicsrc1=$pathFoldersProducts."/".$SmallFoldersProducts;
			$pagesrc1=$pathFoldersProducts;
			//删除文件 
			//删除文件 
			 
			 
			$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=mysqli_num_rows($products_query);
		  	if($products_num!=1){
				unlink($Bigpicsrc);
				@unlink($Bigpicsrc.".bak");//同时删除大图的备份文件
				unlink($Smallpicsrc);
				@unlink($Smallpicsrc.".bak");//同时删除缩略图的备份文件
				@unlink($pagesrc);
			}else{
				unlink($Bigpicsrc);
				@unlink($Bigpicsrc.".bak");//同时删除大图的备份文件
				unlink($Smallpicsrc);
				@unlink($Smallpicsrc.".bak");//同时删除缩略图的备份文件
				@unlink($pagesrc);
				rmdir($Bigpicsrc1);		//如果是最后一个产品，同时删除大图目录
				rmdir($Smallpicsrc1);	//如果是最后一个产品，同时删除缩略图目录
				rmdir($pagesrc1);		//如果是最后一个产品，同时删除网页文件目录
			}
			//删除数据库中该条产品的记录
			$del_sql="DELETE FROM `ls_products` WHERE ID=".$id;
		   	$del_query=$opendb->query($del_sql);
			//更新剩下的产品序号
			$num_sql2="UPDATE `ls_products` SET Num=Num-1 where productID=".$productPID." and Num>".$products_rows['Num'];
			$down_query=$opendb->query($num_sql2);
			//将操作写入系统日志
			
			//删除属性
			$del_sql="DELETE FROM `ls_prospec` WHERE productID=".$id;
		   	$del_query=$opendb->query($del_sql);

			//删除评论
			$del_comments_sql="DELETE FROM `ls_comments` WHERE proID=".$id;
		   	$del_comments_query=$opendb->query($del_comments_sql);
			
			if($ifmutipic) include("widget/_products_del_muti.php"); // 多角度图片删除

			
			writelog($_SERVER['PHP_SELF'],"Delete products: ".$products_rows['productName'],"ID: ".$id);
		   	$ls_msg="删除操作成功！";
		 	break;
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>无标题文档</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script   language="JavaScript" src="js/ls.js" ></script>
<script   language="JavaScript" src="js/ls2.js" ></script>
<link href="css/admin.css" rel="stylesheet" type="text/css">
 <link rel="stylesheet" href="css/style2.css" />
 <style>
 button {
    padding:5px 15px;
    cursor: pointer;
    background-color: #00c0ef;
    border-color: #00acd6;
    border-radius: 5px;
    border: 1px;
    color: #fff;
}
 </style>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">产品管理</font></div>
				</td>
  </tr>
  <tr>
    <td height="213" valign="top"><table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" >
      
    </table>
      <form name="del" method="Post" action="delall.php" onSubmit="return ConfirmDel();">
        <br />
        <?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=mysqli_num_rows($cate_query); 
		if($cate_num!=0)
		{
			$i=1;
			?>
	 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" >
        		<tr>
        			<td>
	<?php
			while($cate_rows=mysqli_fetch_assoc($cate_query))
			 {
if($i==1)
{  
    ?> 大类: <?php
	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++;
	}
?>
	 
    | <a href="<?=$_SERVER['PHP_SELF']?>">全部</a>
     
     </td>
	</tr>
	 </table>
<?php
		
		//中类/////////////////////////////////////////////////////////////////////////
		if($cateid!="")
		{
			$midcate_sql="select * from ls_products where cateName is null and cateFolders 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_query2=$opendb->query($midcate_sql);
			$midcate_num=mysqli_num_rows($midcate_query);
			$midcate_id = mysqli_fetch_assoc($midcate_query2);
			if($midcateid == '')
				$midcateid = $midcate_id['ID'];
			if($midcate_num!=0)
			{
			$i=1;
			?>
			 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
		    	<tr>
		    	<td>
		<?php
		while($midcate_rows=mysqli_fetch_assoc($midcate_query))
		 {
		if($i==1)
		{  
		?>   中类 : 
        <?php
		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;
			}
			 ?>
			</td>
			</tr>
			 </table>
			<?php
		}
	}
		
			//小类///////////////////////////////////////////////////////////////////////////////
		//echo $cateid."--".$midcateid."--".$subcateid;	
		if($cateid!="" && $midcateid!="")
		{
				$subcate_sql="select * from ls_products where cateName is null and cateFolders 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_query2=$opendb->query($subcate_sql);
				$subcate_num=mysqli_num_rows($subcate_query); 
				$subcate_id=mysqli_fetch_assoc($subcate_query2);
				if($subcateid =='')
					$subcateid = $subcate_id['ID'];
				if($subcate_num!=0)
				{
					$i=1;
				?>
						<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
		        		<tr>
		        			<td>
				<?php
					while($subcate_rows=mysqli_fetch_assoc($subcate_query))
					 {
						if($i==1)
						{  
						?>   小类 : 
                        <?php
							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;
					 }
					?>				 			  <a href="addproducts.php" target="right"></a></td>
                                </tr>
					 		 </table>
				<?php
				}
		}
		
			
?>
        <?php 
	// 每页数量
	$PageSize = $PageNum;
	
	// 获取总数据量
	/********************************************************************************/
		$sql="select * from ls_products where midcateName is null and cateName is null and cateFolders is null  and cateBrief is null and subcateName is null and subcateFolders is null and subcateBrief is null and subcateID is null ";
	if($admininfo['branchID']==0){
			
		}else{
			$sql .= " and branchID=".$admininfo['branchID']." ";
		}
	//大类
	$sqlID="";
	$displaydownup="";//显示上移下移箭头
	if($cateid!=""  && $midcateid=="" && $subcateid=="" && $searchproductName=="")
	{
		//大类下有中类
		$sqlstr="select ID from ls_products where midcateID =".$cateid." ";
		$query1=$opendb->query($sqlstr);
		$mynum=mysqli_num_rows($query1);
		if($mynum!=0)
		{
			$i=1;
			while($myrows=mysqli_fetch_assoc($query1))			
			{
				$sqlstr2="select ID from ls_products where subcateID =".$myrows['midcateID']." ";
				$query2=$opendb->query($sqlstr2);
				$mynum2=mysqli_num_rows($query2);
				
if($mynum2!=0) //中类下有小类
{
	while($myrows2=mysqli_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=mysqli_num_rows($query1);
		if($mynum!=0)
		{
			$i=1;
			while($myrows=mysqli_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!=""){
		switch($searchRange){
			case 'productname':
				$sql.="and productName like '%".$searchproductName."%'";
				$searchsql ="and productName like '%".$searchproductName."%'";
				break;
			case 'productno':
				$sql.="and productItemNo like '%".$searchproductName."%'";
				$searchsql ="and productItemNo like '%".$searchproductName."%'";
				break;
			case 'both':
				$sql.="and (productItemNo like '%".$searchproductName."%' or productName like '%".$searchproductName."%' or ID like '%".$searchproductName."%' or productSpecification like '%".$searchproductName."%' or productDescription  like '%".$searchproductName."%' or canshu  like '%".$searchproductName."%' or basicInfo like '%".$searchproductName."%' or additionalInfo  like '%".$searchproductName."%' or productKeywords  like '%".$searchproductName."%' or productTitle  like '%".$searchproductName."%' or parameters  like '%".$searchproductName."%' or advantages  like '%".$searchproductName."%' or characteristics  like '%".$searchproductName."%' or date  like '%".$searchproductName."%' or productVideo  like '%".$searchproductName."%' or wholepath  like '%".$searchproductName."%' or filename like '%".$searchproductName."%'  )";
				$searchsql ="and (productItemNo like '%".$searchproductName."%' or productName like '%".$searchproductName."%'  or ID like '%".$searchproductName."%' or productSpecification like '%".$searchproductName."%' or productDescription  like '%".$searchproductName."%' or canshu  like '%".$searchproductName."%' or basicInfo like '%".$searchproductName."%' or additionalInfo  like '%".$searchproductName."%' or productKeywords  like '%".$searchproductName."%' or productTitle  like '%".$searchproductName."%' or parameters  like '%".$searchproductName."%' or advantages  like '%".$searchproductName."%' or characteristics  like '%".$searchproductName."%' or date  like '%".$searchproductName."%' or productVideo  like '%".$searchproductName."%' or wholepath  like '%".$searchproductName."%' or filename like '%".$searchproductName."%')";
				break;
			default:
				$sql.="and productName like '%".$searchproductName."%'";
				$searchsql ="and productName like '%".$searchproductName."%'";
		}
	}
	
	
	$sql.=" order by Num asc ";	

		$result=$opendb->query($sql);
	
	/********************************************************************************/
	// 获取总数据量
	
	$row = mysqli_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)."&searchproductName=".urlencode($searchproductName);
	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>个产品每页";
		 $page_string .= "&nbsp; &nbsp;共 <b style='color:red;'>".$row."</b> 个产品";
	
	
	?>
    <br>
<table border="0" width="98%" align="center">
	<tr>
		<td width="86%"><?=$ls_msg2?></td>
		<td width="14%" align="right"><a href="<?php echo "addproducts.php?cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page; ?>" target="right">添加产品</a> &nbsp; &nbsp; <?php if(!(strpos($_SERVER['HTTP_REFERER'],"managearticle")===false)){ ?> <a href="managearticle.php">返回</a><?php } ?></td>
	</tr>
</table>
<?php
		 
		/*\***************************************************************************\*/
		/*\查询数据库	\*/
		/*\***************************************************************************\*/ 
	$sort='Num';
	
		
	//查询数据
	if($searchproductName!=""){$products_sql.= $searchsql;}
	$products_sql.=" order by $sort asc limit ". ($page-1)*$PageSize .",".$PageSize." ";	
	
	//echo $products_sql."<br>";
	$products_query=$opendb->query($products_sql);
		/*\***************************************************************************\*/
		/*\查询数据库	\*/
		/*\***************************************************************************\*/ 			
?>
	<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" style="background-color: #f0f0ee;">
        <tr height="37">
			<td align="center" width="3%"></td>
			<td align="center" width="6%">编号</td>
			<td align="center"  width="10%">产品名称</td>
            <td align="center"  width="16%">Title</td>
            <td align="center"  width="10%">date</td>
            <td align="center"  width="20%">Description</td>
			<td align="center" width="8%">图片</td>
			<td align="center" width="4%">序号</td>
			<td align="center" width="4%">点击</td>
			<td align="center" colspan="2">排序</td>
			<td align="center" colspan="2">操作</td>
			<td align="center" width="3%">允许</td>
		</tr>
<?php
	
	$i=1;
	while($products_rows=mysqli_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=mysqli_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=mysqli_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=mysqli_fetch_assoc($search_subcate_query);
		 	
		 	//echo $search_subcate_sql."<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 class=\"preview\" bgcolor='#f9f9f9'height='37' ";
			echo "onMouseOver=\"";
			echo "this.style.backgroundColor='#e5e5e5';\"";
			echo " onMouseOut=";
			echo "this.style.backgroundColor='#f9f9f9' ";
			echo ">";
			echo "<td align='center'>";
			echo $products_rows['ID']."	<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'];
			if($products_rows['isbranch']!=0){
					echo "<span style='color:red'>(会员产品)</span>";
				}
			echo "</td>";
			echo "<td style='padding-left:10px;'>";
			echo $products_rows['productName'];
			echo "</td>";
			echo "<td><a class='proTil' href='javascript:void(0);' title='".$products_rows['productTitle']."' >";
			echo $products_rows['productTitle'];
			echo "</a></td>";
			echo "<td><a class='proKey' href='javascript:void(0);' title='".$products_rows['productKeywords']."' >";
			echo $products_rows['date'];
			echo "</a></td>";
			echo "<td><a class='proDesc' href='javascript:void(0);' title='".strip_tags($products_rows['productDescription'])."' >";
			echo strip_tags($products_rows['productDescription']);
			echo "</a></td>";
			echo "<td style='padding-left:4px;' align='center'>\n"; 
			echo "<img src='".$_SESSION['dda']."../".getproductfolder($products_rows['productID'])."/".$SmallFoldersProducts."/".$products_rows['productPic']."?i=".rand()."' width=".($SmallPicW/3)." height=".($SmallPicH/3)." border='0'>";
			echo "</td>";
			echo "<td style='padding-left:4px;' align='center'>\n";
			echo $products_rows['Num'];
			echo "</td>";
			echo "<td style='padding-left:4px;' align='center'>\n";
			echo $products_rows['hits'];
			echo "</td>";
			
			echo "<td align='center'> ";
			if(($i+($PageNum*($page-1)))!=$amount&&$displaydownup=="ok"){
				echo "<a id='dpp".$products_rows['ID']."' href='?skipdown=1&id=".$products_rows['ID']."&Num=".$products_rows['Num']."&ls=down&page=".$page."&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' title='向下移动'><img src='images/down.gif' border='0'></a>\n";
				echo "<input type=\"text\" name=\"down".$products_rows['ID']."\" size=\"1\" maxlength=\"5\" value=1        onblur=\"document.getElementById('dpp".$products_rows['ID']."').href=document.getElementById('dpp".$products_rows['ID']."').href+'&skipdown1='+this.value\">";
			}
			echo "</td>";
			
			echo "<td align='center'> ";
			if(($i+($PageNum*($page-1)))!=1&&$displaydownup=="ok"){
				echo "<a id='upp".$products_rows['ID']."' href='?skipup=1&id=".$products_rows['ID']."&Num=".$products_rows['Num']."&ls=up&cateid=".$cateid."&page=".$page."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' title='向上移动'><img src='images/up.gif' border='0'></a>";
				echo "<input type=\"text\" name=\"up".$products_rows['ID']."\" size=\"1\" maxlength=\"5\" value=1          onblur=\"document.getElementById('upp".$products_rows['ID']."').href=document.getElementById('upp".$products_rows['ID']."').href+'&skipup1='+this.value\">";
			}
			echo "</td>";
			
			echo "<td align='center'>";
			echo ($i!="1"?"":"! " ). " <a href='modiproducts.php?id=".$products_rows['ID']."&page=".$page."&cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&pp=".$i."' 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&page=".$page."&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' onclick='return ConfirmDelSubCate(\"".$products_rows['productItemNo']."\",\"".$products_rows['productName']."\");' 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&page=".$page."&cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename."' title='显示'><img src='images/enable.gif' border='0'></a>";
			}else{
				echo "<a href='?id=".$products_rows['ID']."&ls=enable&page=".$page."&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>";
	echo "<td colspan='14' align='center' height='37'>";

	echo $page_string;
	if($productID2!=''){ echo "  ||  <a href='?ls=restcate&productID=$productID2&$pagecatestr'  >重新排列（<span style='color:red;'>序号重复后使用</span>）</a>";}
	echo "</td>";
	echo "</tr>";
	?>
	</table>
        <table width="98%" border="0" align="center" cellpadding="5" cellspacing="0">
          <tr bgcolor="#f0f0ee">
            <td width="25%" style="padding-left:6px;"><input name="chkAll" type="checkbox" id="chkAll" onClick="CheckAll(this.form);" value="checkbox">
              所有
                <button name="submitdel" type='submit' value='删除'>删除</button>
              <input name="Action" type="hidden" id="Action" value="proDel" ></td>
            <td width="35%" style="padding-left:6px;"><input type="text" name="searchproductName" size="16" maxlength="50"  value="<?=$searchproductName?>" />
              <select name="searchrange" id="searchrange">
                <option value="both">综合查询</option>
                <option value="productname">查找产品名称</option>
                <option value="productno">查找产品编号</option>
              </select>
              <button type="button"  value="查询"   onclick="document.del.action='<?=$_SERVER['PHP_SELF'];?>';document.del.submit();" />查询</button>
              <button name="重置" type="reset"   onclick="this.form.searchproductName.value='';document.del.action='<?=$_SERVER['PHP_SELF'];?>';document.del.submit();"  value="重置" />重置</button></td>
            <td width="15%" style="padding-left:6px;"><input name="gopage" id="gopage" type="text" size="3" />
页
  <button type="button" name="Submit" value="GO"   onclick="document.del.action='<?=$_SERVER['PHP_SELF'];?>';document.del.submit();" />GO</button></td>
            <td width="13%" style="padding-left:6px;"><?php if( ($cateid!=""||$midcateid!="" ||$subcateid!="" ) && isset($productID2) ){?>
              <a href='?ls=reserverthiscate&amp;productID=<?=$productID2?>&amp;cateid=<?=$cateid?>&amp;midcateid=<?=$midcateid?>&amp;subcateid=<?=$subcateid?>' onclick='return ConfirmRun("确认重新排吗？");' >产品反向排序</a>
            <?php }?></td>
          </tr>
        </table>
      </form>
      <br/>
     <?php 
	 //echo $cateid."--".$midcateid."--".$subcateid;
	 if($cateid!=""||$midcateid!="" ||$subcateid!=""){?>
      <form name="SortForm" id="SortForm" action="?ls=sorting&cateid=<?php echo $cateid; ?>&midcateid=<?php echo $midcateid; ?>&subcateid=<?php echo $subcateid; ?>" method="post">
        <table width="98%" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor='#f4f4f4'>
        <tr >
<td  width="12%">
	<span style="padding-left:6px;">批量排序：</span>
</td>
<td style="text-align:center;" width="23%">
    <!-- <input name="onlyGrandCate" type="checkbox" id="onlyGrandCate"  style=" height:10px; margin-bottom:2px; " value="OnlyCate" checked="checked">仅对大类下产品排序    -->
	
    <select name="SortKind" id="SortKind">
      <option value="productItemNo">产品编号</option>
      <option value="productName">产品名称</option>
    </select>
&nbsp;
<select name="SortMethod" id="SortMethod">
  <option value="desc">升序</option>
  <option value="asc">降序</option>
</select></td>
<td style="text-align:center;" width="13%">
    <!--
    <input type="checkbox" name="IgnoreCate" id="IgnoreCate" value="Ignore"  style="height:10px; margin-bottom:2px;">包含全部子类别
    -->
    <button type="button" name="SortButton" id="SortButton" value="确认" onclick="SortSubmit();" />确认</button></td>
<td style="text-align:center;"><span style="padding-left:6px;">排序：
选择排序项目和方向，点击“开始”。</span></td>
</tr>
	    </table>
    </form>
	<?php }?>
      <?php
			//大类
		 }
	?>
    <br /></td>
  </tr>
</table>
</body>
</html>
