<?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();
	$ls_msg="修改产品信息操作";
	$id=$_GET['id'];
	
	
	$products_sql="select * from ls_products where ID=".$id." ";
	$products_query=$opendb->query($products_sql);
	$products_rows=mysql_fetch_assoc($products_query);
	
	//获取文件目录
	$cate_sql="select productID from ls_products where ID=".$id." "; 
	$cate_sql="select subcateID from ls_products where ID=(".$cate_sql.")";
	$cate_sql="select midcateID from ls_products where ID=(".$cate_sql.") "; 
	$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'];
	
	$midcate_sql="select productID from ls_products where ID=".$id." "; 
	$midcate_sql="select subcateID from ls_products where ID=(".$midcate_sql.") "; 
	$midcate_sql="select * from ls_products where ID=(".$midcate_sql.")";
	$midcate_query=$opendb->query($midcate_sql);
	$midcate_myrows=mysql_fetch_assoc($midcate_query);
	$pathFoldersProducts=$pathFoldersProducts."/".$midcate_myrows['midcateFolders'];
	
	$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);
	$pathFoldersProducts=$pathFoldersProducts."/".$subcate_myrows['subcateFolders'];
	
	//获取文件目录
	if($cate_myrows['cateFolders']=="")
	{
		$cate1_sql="select * from ls_products where ID=".$products_rows['productID']."";
		$cate1_query=$opendb->query($cate1_sql);
		$cate1_myrows=mysql_fetch_assoc($cate1_query);
		$picsrc="../".$cate1_myrows['cateName']."/".$SmallFoldersProducts."/".$products_rows['productPic'];
	}
	else
	{
		$picsrc=$pathFoldersProducts."/".$SmallFoldersProducts."/".$products_rows['productPic'];
  }
	//echo $picsrc."<br>";
?>
<!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">
		<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>
				 <form name="myform" enctype="multipart/form-data" method="post" action="saveproducts.php" onSubmit="return Checkaddproducts()">
					<input type="hidden" value="update" name="ls">
					<input type="hidden" value="<?php echo $id;?>" name="id">
					<input type="hidden" value="<?php echo $products_rows['productPic'];?>" name="Pic">
					<input type="hidden" name="ChangecatePagePic" value="no">
					<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="products.php"><u>返回</u></a></td>
						</tr>
					</table>
					<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
					 
					  <tr bgcolor="#B9DAFF"> 
						<td height="28" colspan="2"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="30%">所属类别：</td>
						<td>
								
								<?php
									$subcate_sql="select * from ls_products where cateName is null and midcateName is null and cateFolders is null and catePagePic is null and catePagePicWidth is null and catePagePicHeight 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 order by Num desc";
									$subcate_query=$opendb->query($subcate_sql);
									
									echo "<script language = 'JavaScript'>" ;
									echo " var onecount; " ;
									echo " subcat = new Array(); " ;
									$count=0;
									while($subcate_rows=mysql_fetch_assoc($subcate_query))
									{
										echo " subcat[".$count."] = new Array(\"" ;
										echo 			trim($subcate_rows['subcateName'])."\",\"" ;
										echo 			trim($subcate_rows['subcateID'])."\",\"" ;
										echo 			trim($subcate_rows['ID'])."\"); " ;
											
										$count++	;
									}
									echo "onecount=".$count.";"	;
								 	
									echo "function changelocation(locationid) "	;
								  echo "  {"	;
								  echo "  document.myform.SmallClassName.length = 1; ";
								  echo "  var locationid=locationid;";
								  echo "  var i;";
								  echo "  for (i=0;i < onecount; i++)";
								  echo "      {";
								  echo "          if (subcat[i][1] == locationid)";
								  echo "          { ";
								  echo "              document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);";
								  echo "          } ";       
								  echo "      }";
								  echo "  }"; 
								  
								  echo "</script>";   
								   
								  $cate_bigclass_sql="select * from ls_products where cateName 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 desc";
									$cate_bigclass_query=$opendb->query($cate_bigclass_sql);
									$cate_bigclass_num=mysql_num_rows($cate_bigclass_query); 
									if($cate_bigclass_num==0)
									{
										echo "请先添加大类!";
									}
									else
									{
									echo "<select name='BigClassName' onChange='changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)' size='1'>" ;
									
									while($cate_bigclass_rows=mysql_fetch_assoc($cate_bigclass_query))
									 {
									 	 
									 	  echo "	<option ";
									 	  if ($cate_myrows['ID']==$cate_bigclass_rows['ID'])
									 	  {
									 	  	echo "selected";
									 	  }
									 	  if($cate1_myrows['ID']==$cate_bigclass_rows['ID'])
									 	  {
									 	  	echo "selected";
									 	  }
									 	  echo " value=".trim($cate_bigclass_rows['ID']).">".trim($cate_bigclass_rows['midcateName'])."</option>";
									 	
									 }
									echo "</select>";
									
									
									echo "<select name='SmallClassName'>";
								  
								  $subcate_smallclass_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 productPic is null and productItemNo is null and productName is null and productSpecification is null and productID is null and enable=1 ";
									//echo $subcate_smallclass_sql."<br>";
									$subcate_smallclass_query=$opendb->query($subcate_smallclass_sql);
									$subcate_bigclass_num=mysql_num_rows($subcate_smallclass_query);
									//$subcate_smallclass_rows=mysql_fetch_assoc($subcate_smallclass_query);
									 echo "<option value=''";
									 if($subcate_myrows['ID']=="")
										{
											echo " selected";
										}
										
										echo ">请选择小类</option>";
										while($subcate_smallclass_rows=mysql_fetch_assoc($subcate_smallclass_query))
								  	{
								  		echo "<option ";
								  		if($subcate_myrows['ID']==$subcate_smallclass_rows['ID'])
								  		{
												echo "selected";
											}
								  		echo " value=".$subcate_smallclass_rows['ID'].">".$subcate_smallclass_rows['subcateName']."</option>";
								    }
								  	//echo "<option ";
								  	//if($subcate_myrows['ID']==$subcate_smallclass_rows['ID'])
										//{
										//	echo "selected";
										//}
								  	//echo " value=".$subcate_smallclass_rows['ID'].">".$subcate_smallclass_rows['subcateName']."</option>";
								    echo "</select>";
								  }
								?>
								
								
						</td>
					  </tr>
					  
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="30%">产品编号：</td>
						<td><input type="text" name="productItemNo" value="<?php echo $products_rows['productItemNo'];?>"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="30%">产品名称：</td>
						<td><input type="text" name="productName" value="<?php echo $products_rows['productName'];?>"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" >*缩略图：</td>
						<td style="padding-left:5px;" >
							<img src="<?php echo $picsrc;?>" width="<?php echo $SmallPicW ?>" height="<?php echo $SmallPicH?>" border="1" name="pic" style="float:left;">
							<br><br><br><br>
							图片宽度应在200-400点、高度在200-300点，格式为jpg，大小不要超过50KB
						</td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" >产品图片：</td>
						<td><input type="file" name="productPic" style="width:300px;" onBlur="document.pic.src=myform.productPic.value;" onChange="myform.ChangecatePagePic.value='yes';"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="30%">产品规格：</td>
						<td><textarea name="productSpecification" style="width:300px; height:50px;" ><?php echo trim($products_rows['productSpecification']);?></textarea></td>
					  </tr>
					  <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="2" align="center"><input type="submit" value="修改产品" >
							<input type="button" value="刷新本页" onClick="JavaScript:history.go(0);">
							</td>
					  </tr>
					 </table>
					</form>
				</td>
			</tr>
		</table>
	</body>
</html>