<?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="添加产品操作";
	
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	
	$opendb=new mydb();
	
	
?>
<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" 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="insert" name="ls">
					<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="3"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="28%">所属类别：</td>
						<td colspan="2">
									<?php
									//cate change
									$midcate_sql="select * from ls_products where subcateName 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 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";
									$midcate_query=$opendb->query($midcate_sql);
									echo "<script language = 'JavaScript'>" ;
									echo " var onecount; " ;
									echo " midcat = new Array(); " ;
									$count=0;
									while($midcate_rows=mysql_fetch_assoc($midcate_query))
									{
										echo " midcat[".$count."] = new Array(\"" ;
										echo 			trim($midcate_rows['midcateName'])."\",\"" ;
										echo 			trim($midcate_rows['midcateID'])."\",\"" ;
										echo 			trim($midcate_rows['ID'])."\"); " ;
										$count++	;
									}
									echo "onecount=".$count.";"	;

									
									
									$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 order by Num desc";
									$subcate_query=$opendb->query($subcate_sql);
									
									echo " var onecount2; " ;
									echo " subcat = new Array(); " ;
									$count2=0;
									while($subcate_rows=mysql_fetch_assoc($subcate_query))
									{
										echo " subcat[".$count2."] = new Array(\"" ;
										echo 			trim($subcate_rows['subcateName'])."\",\"" ;
										echo 			trim($subcate_rows['subcateID'])."\",\"" ;
										echo 			trim($subcate_rows['ID'])."\"); " ;
											
										$count2++	;
									}
									echo "onecount2=".$count2.";"	;
								 	
									
									echo "function changelocation_big(locationid) "	;
								  echo "  {"	;
								  echo "  document.myform.MiddleClassName.length = 0; ";
								  echo "  var locationid=locationid;";
								  echo "  var i;";
								  echo "  var j=1;";
								  echo "  for (i=0;i < onecount; i++)";
								  echo "      {";
								  echo "          if (midcat[i][1] == locationid)";
								  echo "          { ";
								  echo "              document.myform.MiddleClassName.options[document.myform.MiddleClassName.length] = new Option(midcat[i][0], midcat[i][2]);";
								  echo "          	  if (j == 1)";
								  echo "          	  	{";
								  echo "          	  	changelocation_middle(midcat[i][2]);";
								  echo "          	  	j++;";
								  echo "          	  	}";
								  echo "          } ";       
								  echo "       	  if (j == 1)";
								  echo "	   	  {";
								  echo " 	 	  	changelocation_middle(-1);";//clear smallclass select
								  echo "	   	  }";
								  echo "      }";
								  echo "  }"; 
								   
								   //midcate change
									echo "function changelocation_middle(locationid) "	;
								  echo "  {"	;
								  echo "  document.myform.SmallClassName.length = 0; ";
								  echo "  var locationid=locationid;";
								  echo "  var i;";
								  echo "  for (i=0;i < onecount2; 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 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 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_big(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)' size='1'>" ;
									$i=1;
									while($cate_bigclass_rows=mysql_fetch_assoc($cate_bigclass_query))
									 {
									 	 if($i==1)
									 	 {
									 	 	$selclass=$cate_bigclass_rows['ID'];
									 	 	
									 	 	echo " <option ";
									 	 	if($_POST['BigClassName']=="" || $_POST['BigClassName']==$cate_bigclass_rows['ID'])
									 	 	{
									 	 		echo "selected";
									 	 	}
									 	 	echo " value=".trim($cate_bigclass_rows['ID']).">".trim($cate_bigclass_rows['cateName'])."</option>";
									 	 }
									 	 else
									 	 {
									 	  echo "	<option ";
									 	  if($_POST['BigClassName']==$cate_bigclass_rows['ID'])
									 	 	{
									 	 		echo "selected";
									 	 	}
									 	  echo " value=".trim($cate_bigclass_rows['ID']).">".trim($cate_bigclass_rows['cateName'])."</option>";
									 	 }
									 	  $i++;
									 }
									echo "</select>";


									

								  
								 	if($_POST['MiddleClassName']=="")
								  	{
								  		$midcate_middleclass_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 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 and midcateID=".$selclass."";
									}
									else
									{
										$midcate_middleclass_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 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 and midcateID=".$_POST['BigClassName']."";
									}
									$midcate_middleclass_query=$opendb->query($midcate_middleclass_sql);
									$midcate_middleclass_num=mysql_num_rows($midcate_middleclass_query);
									
									
									echo " 中类: <select name='MiddleClassName'onChange='changelocation_middle(document.myform.MiddleClassName.options[document.myform.MiddleClassName.selectedIndex].value)' size='1'>" ;
									
									if($midcate_middleclass_num!=0)
									{
										$j=1;
										echo "<option value='' ";
										
										if($_POST['MiddleClassName']=="")
								  		{
											echo "selected";
										}
										echo ">请选择中类</option>";
									}
									

									
								  	while($midcate_middleclass_rows=mysql_fetch_assoc($midcate_middleclass_query))
								  	{
										if($j==1)
										{
										 	$selmidclass=$midcate_middleclass_rows['ID'];

										}
										$j++;
								  		echo "<option ";
								  		if($_POST['MiddleClassName']==$midcate_middleclass_rows['ID'])
								  		{
												echo "selected";
										}
								  		echo " value=".$midcate_middleclass_rows['ID'].">".$midcate_middleclass_rows['midcateName']."</option>";
								    }
								    echo "</select>";
									
									

									echo " 小类: <select name='SmallClassName'>";
								  	if($midcate_middleclass_num!=0)
									{
									    if($_POST['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 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=".$selmidclass."";
										}
										else
										{
											$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 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=".$_POST['MiddleClassName']."";
										}
										$subcate_smallclass_query=$opendb->query($subcate_smallclass_sql);
										$subcate_smallclass_num=mysql_num_rows($subcate_smallclass_query);

										if($subcate_smallclass_num!=0)
										{
											echo "<option value='' ";
											if($_POST['SmallClassName']=="")
									  		{
												echo "selected";
											}
											echo ">请选择小类</option>";
										}
									  	while($subcate_smallclass_rows=mysql_fetch_assoc($subcate_smallclass_query))
									  	{
									  		echo "<option ";
									  		if($_POST['SmallClassName']==$subcate_smallclass_rows['ID'])
									  		{
												echo "selected";
											}
									  		echo " value=".$subcate_smallclass_rows['ID'].">".$subcate_smallclass_rows['subcateName']."</option>";
									    }
									
								  	}//	if($midcate_middleclass_num==0)
								echo "</select>";
							}//if($cate_bigclass_num==0)
							
								?>
								
								
						</td>
					  </tr>
					  
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="28%">产品编号：</td>
						<td colspan="2"><input type="text" name="productItemNo" value="<?php echo $_POST['productItemNo'];?>"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="28%">产品名称：</td>
						<td width="24%"><input type="text" name="productName" value="<?php echo $_POST['productName'];?>"></td>
					    <td width="48%"> 
				        显示在首页	
			            <input name="showonhome" type="checkbox" value="1" ></td>
						
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" >*缩略图：</td>
						<td colspan="2" style="padding-left:5px;" >
							<img src="images/picture.gif" 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 colspan="2"><input type="file" name="productPic" style="width:300px;" onBlur="document.pic.src=myform.productPic.value;"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:50px;" width="28%">产品规格：</td>
						<td colspan="2"><textarea name="productSpecification" style="width:300px; height:50px;" ><?php echo $_POST['productSpecification'];?></textarea></td>
					  </tr>
					  <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="3" align="center"><input type="submit" value="添加产品"></td>
					  </tr>
					 </table>
				  </form>
				</td>
			</tr>
		</table>
	</body>
</html>