<?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();
	require_once('inc/char_set.php');
	
	$cateid=$_GET['cateid'];
	if(isset($_POST['BigClassName']))$cateid=$_POST['BigClassName'];  //$_POST['BigClassName'] 传了ID
	$catename=$_GET['catename'];
	$midcateid=$_GET['midcateid'];
	if(isset($_POST['MiddleClassName']))$midcateid=$_POST['MiddleClassName'];  //$_POST['MiddleClassName'] 传了ID
	$midcatename=$_GET['midcatename'];
	$subcateid=$_GET['subcateid'];
	if(isset($_POST['SmallClassName']))$subcateid=$_POST['SmallClassName'];  //$_POST['SmallClassName'] 传了ID
	$subcatename=$_GET['subcatename'];
	$productID=$_GET['productID'];

?>
<!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="insert" name="ls">
			  <table border="0" width="94%" align="center">
					<tr>
						<td width="56%">提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
						<td width="26%" align="right"><input  type="button" style="cursor:hand;color:#0000FF;" value="生成全部产品页" onClick="JavaScript:location='temp_index.php?ls=products&productsall=ok'"></td>
						<td width="18%" align="right"><img src="images/shao.gif">&nbsp;<a href="<? echo "products.php?cateid=".$cateid."&catename=".$catename."&midcateid=".$midcateid."&midcatename=".$midcatename."&subcateid=".$subcateid."&subcatename=".$subcatename; ?>"><u>返回</u></a></td>
					</tr>
				</table>
				<table width="94%" 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:15px;" width="10%">产品类别：</td>
						<td colspan="2" style="padding-left:3em;" ><?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 asc";
									$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 asc";
									$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 asc";
									$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($cateid=="" || $cateid==$cate_bigclass_rows['ID'])
									 	 	{
									 	 		echo "selected";
									 	 	}
									 	 	echo " value=".trim($cate_bigclass_rows['ID']).">".trim($cate_bigclass_rows['cateName'])."</option>";
									 	 }
									 	 else
									 	 {
									 	  echo "	<option ";
									 	  if($cateid==$cate_bigclass_rows['ID'])
									 	 	{
									 	 		echo "selected";
									 	 	}
									 	  echo " value=".trim($cate_bigclass_rows['ID']).">".trim($cate_bigclass_rows['cateName'])."</option>";
									 	 }
									 	  $i++;
									 }
									echo "</select>";


									

								  
								 	if($midcateid=="")
								  	{
								  		$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=".$cateid."";
									}
									$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($midcateid=="")
								  		{
											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($midcateid==$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($subcateid=="")
										{
									  		$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=".$midcateid."";
										}
										$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($subcateid=="")
									  		{
												echo "selected";
											}
											echo ">请选择小类</option>";
										}
									  	while($subcate_smallclass_rows=mysql_fetch_assoc($subcate_smallclass_query))
									  	{
									  		echo "<option ";
									  		if($subcateid==$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:15px;" width="10%">产品货号：</td>
						<td colspan="2" style="padding-left:3em;" ><input name="productItemNo" type="text" value="<?php echo $_POST['productItemNo'];?>" size="36"></td>
					</tr>
					<tr bgcolor="#f4f4f4">
						<td style="padding-left:15px;" width="10%">产品名称：</td>
						<td width="34%" style="padding-left:3em;" ><input name="productName" type="text" value="<?php echo $_POST['productName'];?>" size="36" onblur="
document.myform.productTitle.value=this.value;document.myform.productKeywords.value=this.value+', <?=$seoFrefix1?> '+this.value+' <?=$seoSufix1?>, <?=$seoFrefix2?> '+this.value+' <?=$seoSufix2?> '+', '+document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].text;document.myform.productDescription.value=document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].text+' <?=$seoFrefix1?> <?=$seoSufix2?>'+', '+document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].text+' <?=$seoFrefix2?> <?=$seoSufix2?>';"></td>
						<td width="56%" style="padding-left:3em;"><input id="showonhome" name="showonhome" type="checkbox" value="0"  />
							<label for="showonhome" style="margin-right:10px;">首页显示，
							位置
                              <input type="text" value="1" size="3" name="No" > &nbsp; <input id="hotproduct" name="hotproduct" type="checkbox" value="1" /> 
							<label for="hotproduct" style="margin-right:10px;">热点产品</label>
							<input id="newproduct" name="newproduct" type="checkbox" value="2" />
							<label for="newproduct" style="margin-right:10px;">新产品</label></td>
					</tr>
					<tr bgcolor="#f4f4f4">
						<td style="padding-left:12px;" >产品图片：</td>
						<td style="padding-left:3em;" ><img src="images/picture.gif" width="<?php echo $SmallPicW ?>" height="<?php echo $SmallPicH?>" border="1" name="pic" style="float:left;"> <br>
							<br>
							<br>
							<br></td>
						<td style="padding-left:2em;" ><table width="531" border="0">
						  <tr>
						    <td width="131" bgcolor="#f4f4f4"   >本页标题 Title</td>
						    <td width="383"><input name="productTitle" id="productTitle" type="text" value="<?php echo $_POST['productTitle'];?>" size="70" /></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4" >本页关键字 Keywords</td>
						    <td><input name="productKeywords" id="productKeywords" type="text" value="<?php echo $_POST['productKeywords'];?>" size="70" /></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4"  >本页描述 Description</td>
						    <td><textarea name="productDescription" cols="72" rows="3" id="productDescription"><?php echo $_POST['productDescription'];?></textarea></td>
					      </tr>
					    </table></td>
					</tr>
					<tr bgcolor="#f4f4f4">
						<td style="padding-left:15px;" >产品图片：</td>
						<td colspan="2" style="padding-left:3em;" ><input type="file" name="productPic" style="width:300px;" onBlur="document.pic.src=myform.productPic.value;">
						  <input id="automationGif" name="automationGif" type="checkbox" value="1"  />
						  GIF动画
						  <br />
					    图片宽度应在200-600点、高度在200-600点，格式为jpg、gif、png，大小不要超过<?php echo $PicSize/1000; ?>KB</td>
					</tr>
					<tr bgcolor="#f4f4f4">
					  <td colspan="3" style="padding-left:10px;"><div align="right">
					    <input name="submit3" type="submit" value="添加产品" />
					    </div></td>
				  </tr>
					<tr bgcolor="#f4f4f4">
					  <td height="166" style="padding-left:15px;">产品属性：</td>
					  <td colspan="2" style="padding-left:3em;" >
						  <p style="color:red;">
						    <textarea name="canshu" id="canshu" style="width:450px;height:150px;font-size:12px;line-height:20px; color:<?=($_POST['canshu']!=""?"#000;":"#BBB;")?>" onfocus="<?=($_POST['canshu']!=""?"":("this.style.color!='black'?this.value='':this.value=this.value;"))?>" onchange="this.style.color='black';this.value=this.value;"><?=($_POST['canshu']!=""?$_POST['canshu']:"额定电压    220VAC/380VAC
频率    50HZ&plusmn;10%")?>
						    </textarea>
				      &nbsp; &nbsp; &nbsp;注：<span style="padding-left:12px;">属性名与属性</span>值用 空格 分割 ，每个属性对占一行。                        </p></td>
				  </tr>
					<tr bgcolor="#f4f4f4">
					  <td colspan="3" style="padding-left:10px;"><div align="right">
					    <input name="submit" type="submit" value="添加产品" />
					    </div></td>
				  </tr>
					<tr bgcolor="#f4f4f4">
						<td style="padding-left:15px;" width="10%">产品说明：</td>
						<td colspan="2" ><?php
								require_once('fckeditor/fckeditor.php');
								$sBasePath=$_SERVER['PHP_SELF'];
								$sBasePath=substr($sBasePath,0,strpos($sBasePath,"ls_admin"));
								$sBasePath.="ls_admin/fckeditor/";
									
								$oFCKeditor=new FCKeditor('productSpecification');
								$oFCKeditor->BasePath=$sBasePath;
								$oFCKeditor->Config['SkinPath']=$sBasePath.'editor/skins/silver/';
								$oFCKeditor->Config['AutoDetectLanguage']=true;
								$oFCKeditor->ToolbarSet='Default';
								$oFCKeditor->Height='350';
								$oFCKeditor->Value=htmlspecialchars_decode($_POST['productSpecification'],ENT_QUOTES);
								$oFCKeditor->Create();
							?></td>
					</tr>
					<tr bgcolor="#B9DAFF">
						<td height="25" colspan="3" align="center"><input name="submit2" type="submit" value="添加产品"></td>
					</tr>
				</table>
			</form></td>
	</tr>
</table>
</body>
</html>