<?php
	session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	
	if ($_GET['ls_msg']=="")
	{
		$ls_msg="产品类别设置操作";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}

	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$nownum=$_GET['Num'];
	$whichcate=$_GET['whichcate'];

	
	
	$opendb=new mydb();
	
	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);
			$up=$nownum+1;

			switch($whichcate)
			{
				case "cate";
				$up_sql="update ls_products set Num=".$nownum." where Num=".$up."  and cateName<>''";
				break;
				
				case "midcate";
				$up_sql="update ls_products set Num=".$nownum." where Num=".$up."  and midcateID=".$productID_row['midcateID']." ";
				break;
				
				case "subcate";
				$up_sql="update ls_products set Num=".$nownum." where Num=".$up."  and subcateID=".$productID_row['subcateID']." ";
				break;
			
			}
			
			$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 "down":
			$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;

			switch($whichcate)
			{
				case "cate";
				$down_sql="update ls_products set Num=".$nownum." where Num=".$down."  and cateName<>''";
				break;
				
				case "midcate";
				$down_sql="update ls_products set Num=".$nownum." where Num=".$down."  and midcateID=".$productID_row['midcateID']." ";
				break;
				
				case "subcate";
				$down_sql="update ls_products set Num=".$nownum." where Num=".$down."  and subcateID=".$productID_row['subcateID']." ";
				break;
			
			}
			
			
			$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 "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;
	}
	
?>
<!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=gb2312">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<script language="JavaScript" src="js/ls.js"></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"><br>
					<table border="0" width="90%" align="center">
						<tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right"><img src="images/shao.gif">&nbsp;<a href="addcate.php"><u>添加产品大类</u></a></td>
						</tr>
					</table>
					<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
				
						<tr bgcolor="#B9DAFF">
							<td align="center" height="25" width="50%">栏目名称</td>
							<td align="center" colspan="2">排序</td>
							<td align="center" colspan="3">操作选项</td>
   							<td align="center" width="60">批量导入</td>
							<td align="center" width="60">是否显示</td
						></tr>
						<?php
						$i=1;
							$cate_sql="select * from ls_products where 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 midcateName is null and productSpecification is null and productID is null order by Num desc";
							$cate_query=$opendb->query($cate_sql);
							$cate_myrows=mysql_num_rows($cate_query); 
							while($cate_rows=mysql_fetch_assoc($cate_query))
							 {
							  echo "<tr bgcolor='#A4B6D7'";
							echo "onMouseOver=";
								echo " 	this.style.backgroundColor='#CCFFCC' ";
								echo "onMouseOut=";
								echo " 	this.style.backgroundColor='#A4B6D7' ";
								echo ">";
							  echo "	<td>";
							  echo "		<img src='images/tree_cate.gif'>";
							  echo 			$cate_rows['cateName'];
							  echo "	</td>";
							  echo "	<td align='center'> ";
							  if($i!=1)
							  {
								echo "		<a href='?id=".$cate_rows['ID']."&Num=".$cate_rows['Num']."&ls=up&whichcate=cate' title='向上移动'><img src='images/up.gif' border='0'></a>";
								}
								echo "  </td>";
								echo "	<td align='center'> ";
								if($i!=$cate_myrows)
							  {
								echo "	 <a href='?id=".$cate_rows['ID']."&Num=".$cate_rows['Num']."&ls=down&whichcate=cate' title='向下移动'><img src='images/down.gif' border='0'></a>";
								}
								
								$i++;
								echo "  </td>";
								echo "	<td align='center'> ";
								if($cate_rows['enable']==0)
								{
								echo "		<img src='images/b_add.gif' border='0'>";
								}
								if($cate_rows['enable']==1)
								{
								echo "		<a href='addmidcate.php?id=".$cate_rows['ID']." ' title='添加产品中类'><img src='images/b_add.gif' border='0'></a>";
								}
								echo "  </td>";
								echo "	<td align='center'> ";
								echo "		<a href='modicate.php?id=".$cate_rows['ID']."' title='编辑'><img src='images/b_edit.png' border='0'></a>";
								echo "  </td>";
								echo "	<td align='center'> ";
								
								$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 cateBrief 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 midcateID=".$cate_rows['ID']." order by Num desc";
								$midcate_query=$opendb->query($midcate_sql);
								$midcate_myrows=mysql_num_rows($midcate_query); 
								if($midcate_myrows==0)
								{
									$midcate2_sql="select * from ls_products where productID=".$cate_rows['ID']." order by Num desc";
									$midcate2_query=$opendb->query($midcate2_sql);
									$midcate2_myrows2=mysql_num_rows($midcate2_query);
									if($midcate2_myrows2==0)
									{
									echo "		<a href='savecate.php?id=".$cate_rows['ID']."&ls=del' onclick='return ConfirmDelCate();' title='删除'><img src='images/b_drop.png' border='0'></a>";
									}
									else
									{
									echo "		<img src='images/b_undrop.png' border='0' alt='大类下面有产品。&#10请先删除产品。'>";
									}
								}
								else
								{
								echo "		<img src='images/b_undrop.png' border='0' alt='大类下面还有中类。&#10请先删除中类。'>";
								}
								
								echo "  </td>";
								echo "	<td align='center'>";
						  
								  if($midcate_myrows==0)
									{
										echo "<a href=batchadd.php?id=".$cate_rows['ID']."&name=".$cate_rows['cateName']."&ls=batchadd title='导入'><=</a>";
									}
															
								echo "	</td>";
								echo "	<td align='center'>";
						  
								  if($cate_rows['enable']==1)
									{
										echo "<a href='?id=".$cate_rows['ID']."&ls=unenable' title='显示'><img src='images/enable.gif' border='0'></a>";
									}
								  if($cate_rows['enable']==0)
								  	{
										echo "<a href='?id=".$cate_rows['ID']."&ls=enable' title='不显示'><img src='images/unenable.gif' border='0'></a>";
									}
															
								echo "	</td>";
							  echo "</tr>";
							  
							  
							  if($cate_rows['enable']==1)
									{
													$j=1;
									
										  			while($midcate_rows=mysql_fetch_assoc($midcate_query))
													  {
															  echo "<tr bgcolor='#f4f4f4'";
															echo "onMouseOver=";
																echo " 	this.style.backgroundColor='#CCFFCC' ";
																echo "onMouseOut=";
																echo " 	this.style.backgroundColor='#f4f4f4' ";
																echo ">";
															  echo "	<td style='padding-left:15px;'>";
															  echo "		<img src='images/tree_cate.gif'>";
															  echo 			$midcate_rows['midcateName'];
															  echo "	</td>";
															  echo "	<td align='center'> ";
															 echo $midcate_rows['Num'];
															  if($j!=1)
															  {
																echo "		<a href='?id=".$midcate_rows['ID']."&Num=".$midcate_rows['Num']."&ls=up&whichcate=midcate' title='向上移动'><img src='images/up.gif' border='0'></a>";
																}
																echo "  </td>";
																echo "	<td align='center'> ";
															if($j!=$midcate_myrows)
															  {
																echo "	 <a href='?id=".$midcate_rows['ID']."&Num=".$midcate_rows['Num']."&ls=down&whichcate=midcate' title='向下移动'><img src='images/down.gif' border='0'></a>";
																}
																$j++;

																echo "  </td>";
																echo "	<td align='center'> ";
																echo "		<a href='addsubcate.php?id=".$midcate_rows['ID']." ' title='添加产品小类'><img src='images/b_add.gif' border='0'></a>";
																echo "  </td>";
																echo "	<td align='center'> ";
																echo "		<a href='modimidcate.php?id=".$midcate_rows['ID']."' title='编辑'><img src='images/b_edit.png' border='0'></a>";
																echo "  </td>";
																echo "	<td align='center'> ";
																
																$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 subcateID=".$midcate_rows['ID']." order by Num desc";
																$subcate_query=$opendb->query($subcate_sql);
																$subcate_myrows=mysql_num_rows($subcate_query); 
																 
																
						
																if($subcate_myrows==0)
																{
																	$subcate2_sql="select * from ls_products where productID=".$midcate_rows['ID']." order by Num desc";
																	$subcate2_query=$opendb->query($subcate2_sql);
																	$subcate_myrows2=mysql_num_rows($subcate2_query);
																	if($subcate_myrows2==0)
																	{
																	echo "		<a href='savecate.php?id=".$midcate_rows['ID']."&ls=del' onclick='return ConfirmDelCate();' title='删除'><img src='images/b_drop.png' border='0'></a>";
																	}
																	else
																	{
																	echo "		<img src='images/b_undrop.png' border='0' alt='中类下面有产品。&#10请先删除产品。'>";
																	}
																}
																else
																{
																echo "		<img src='images/b_undrop.png' border='0' alt='中类下面还有小类。&#10请先删除小类。'>";
																}

																echo "  </td>";
								echo "	<td align='center'>";
						  
								  if($subcate_myrows==0)
									{
										echo "<a href=batchadd.php?id=".$midcate_rows['ID']."&name=".urlencode($midcate_rows['midcateName'])."&ls=batchadd title='导入'><=</a>";
									}
															
								echo "	</td>";
																echo "	<td align='center'>";

															  if($midcate_rows['enable']==1)
																{
																echo "<a href='?id=".$midcate_rows['ID']."&ls=unenable' title='显示'><img src='images/enable.gif' border='0'></a>";
																}
															  if($midcate_rows['enable']==0)
															  	{
																echo "<a href='?id=".$midcate_rows['ID']."&ls=enable' title='不显示'><img src='images/unenable.gif' border='0'></a>";
																}
															
																echo "	</td>";
																  echo "</tr>";
								
															  

																if($cate_rows['enable']==1)
																{
																	$k=1;
														  			while($subcate_rows=mysql_fetch_assoc($subcate_query))
																	  {
																		  echo "<tr bgcolor='#f4f4f4'";
																		echo "onMouseOver=";
																		echo " 	this.style.backgroundColor='#CCFFCC' ";
																		echo "onMouseOut=";
																		echo " 	this.style.backgroundColor='#f4f4f4' ";
																		echo ">";
																		  echo "	<td style='padding-left:15px;'>";
																		  echo "		= <img src='images/tree_cate.gif'>";
																		  echo 			$subcate_rows['subcateName'];
																		  echo "	</td>";
																		  echo "	<td align='center'> ";
																		  echo 			$subcate_rows['Num'];
																		   if($k!=1)
															 				 {
																			echo "		<a href='?id=".$subcate_rows['ID']."&Num=".$subcate_rows['Num']."&ls=up&whichcate=subcate' title='向上移动'><img src='images/up.gif' border='0'></a>";
																			}
																			echo "  </td>";
																			echo "	<td align='center'> ";
																			if($k!=$subcate_myrows)
															 				 {
																			echo "	 <a href='?id=".$subcate_rows['ID']."&Num=".$subcate_rows['Num']."&ls=down&whichcate=subcate' title='向下移动'><img src='images/down.gif' border='0'></a>";
																			}
																			
																			$k++;
																			echo "  </td>";
																			echo "	<td align='center'> ";
																			echo "";
																			echo "  </td>";
																			echo "	<td align='center'> ";
																			echo "		<a href='modisubcate.php?id=".$subcate_rows['ID']."' title='编辑'><img src='images/b_edit.png' border='0'></a>";
																			echo "  </td>";
																			echo "	<td align='center'> ";
																
																	
																			$products_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 and midcateName is null and midcateID is null and productID=".$subcate_rows['ID']." order by Num desc ";													
																			$products_query=$opendb->query($products_sql);
																			$products_num=mysql_num_rows($products_query);
																			if($products_num!=0)
																			{
																				echo "		<img src='images/b_undrop.png' border='0' alt='小类下面还有产品。&#10请先删除产品。'>";
																			}
																			else
																			{
																			  echo "		 <a href='savesubcate.php?id=".$subcate_rows['ID']."&ls=del' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>";
																			}
																			echo "  </td>";
								echo "	<td align='center'>";
										echo "<a href=batchadd.php?id=".$subcate_rows['ID']."&ls=batchadd title='导入'><=</a>";
								echo "	</td>";
																			echo "	<td align='center'>";
																			  if($subcate_rows['enable']==1)
																			{
																			echo "<a href='?id=".$subcate_rows['ID']."&ls=unenable' title='显示'><img src='images/enable.gif' border='0'></a>";
																			}
																		  if($subcate_rows['enable']==0)
																		  	{
																			echo "<a href=batchadd?id=".$subcate_rows['ID']."&name=".$subcate_rows['subcateName']."&ls=enable title='不显示'><img src='images/unenable.gif' border='0'></a>";
																			}
																			echo "	</td>";
																		  echo "</tr>";
															  
													}
						
						
						
									}
															  
															  
															  
							}
			}
							
							  
							  
} 
						
						
						
						
						
						
						
						?>
						
					</table>
					<br>				
				</td>
			</tr>
	</table>
	<br>
	<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 valign="top" bgcolor="#dee7ff"><br>
					<table border="0" width="90%" align="center">
						<tr>
							<td>
											<ul>
												<li>
														<img src="images/b_add.gif"> 添加产品小类 
														<img src="images/b_unadd.gif"> 不能添加产品小类
												</li>
												<li>
														<img src="images/b_edit.png"> 修改/编辑
												</li>
												<li>
														<img src="images/b_drop.png"> 删除
														<img src="images/b_undrop.png"> 不能删除
												</li> 
												<li>
														<=  &nbsp;批量导入产品图片
												</li>
												<li>
														<img src="images/enable.gif"> 显示<br>
														<img src="images/unenable.gif"> 不显示 大类不显示后，大类下的小类及产品都不显示。
												</li>
											</ul>
							</td>
						</tr>
					</table>
					<br>
				</td>
			</tr>
	</table>
						
 </body>
</html>