<?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();
	require_once('inc/char_set.php');
	$ls_msg="修改产品信息操作";
	$id=$_GET['id'];
	$cateid=$_GET['cateid'];
	$midcateid=$_GET['midcateid'];
	$subcateid=$_GET['subcateid'];

	
	$products_sql="select * from ls_products where ID=".$id." ";
	$products_query=$opendb->query($products_sql);
	$products_rows=mysql_fetch_assoc($products_query);
	
	//获取文件目录
	$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);
	if($subcate_myrows['subcateFolders']!="")
	{
		$pathFoldersProducts=$subcate_myrows['subcateFolders'];

		$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);
		
		if($midcate_myrows['midcateFolders']!="")
		{
			$pathFoldersProducts=$midcate_myrows['midcateFolders']."/".$pathFoldersProducts;
			
			$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']."/".$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($midcate_sql);
		$midcate_myrows=mysql_fetch_assoc($midcate_query);
		
		if($midcate_myrows['midcateFolders']!="")
		{
			$pathFoldersProducts=$midcate_myrows['midcateFolders'];
		
			$cate_sql="select * from ls_products where ID=".$midcate_myrows['midcateID']." "; 
			$cate_query=$opendb->query($cate_sql);
			$cate_myrows=mysql_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=mysql_fetch_assoc($cate_query);
			
			$pathFoldersProducts="../".$cate_myrows['cateFolders'];
			
		}
	
	}
	

	

	
	//获取文件目录
	$picsrc=$pathFoldersProducts."/".$SmallFoldersProducts."/".$products_rows['productPic'];
	//echo $picsrc."<br>";
	$picsrcnopath=$products_rows['productPic'];
?>
<!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>
	<link rel="stylesheet" href="kindeditor/themes/default/default.css" />
	<link rel="stylesheet" href="kindeditor/plugins/code/prettify.css" />
	<script charset="utf-8" src="kindeditor/kindeditor.js"></script>
	<script charset="utf-8" src="kindeditor/lang/zh_CN.js"></script>
	<script charset="utf-8" src="kindeditor/plugins/code/prettify.js"></script>
	<script>
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="productSpecification"]', {
				cssPath : 'kindeditor/plugins/code/prettify.css',
				uploadJson : 'kindeditor/php/upload_json.php',
				fileManagerJson : 'kindeditor/php/file_manager_json.php',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						K('form[name=myform]')[0].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						K('form[name=myform]')[0].submit();
					});
				}
			});
			prettyPrint();
		});
	</script>
</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?cateid=<? echo $cateid?>&midcateid=<? echo $midcateid?>&subcateid=<? echo $subcateid?>" 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="94%" 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?cateid=<? echo $cateid?>&midcateid=<? echo $midcateid?>&subcateid=<? echo $subcateid?>"><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 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)
									 	 {
									 	 	
									 	 	echo " <option ";
									 	 	if($cate_myrows['ID']==$cate_bigclass_rows['ID'] || $_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($cate_myrows['ID']==$cate_bigclass_rows['ID'] || $_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($midcate_myrows['ID']==""&&$_POST['MiddleClassName']==""||$midcate_myrows['midcateName']==""&&$_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=''";
									}
									else
									{
										if($midcate_myrows['ID']!="")
										{
											$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=".$cate_myrows['ID']."";
										}
										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'>" ;
									
								  	while($midcate_middleclass_rows=mysql_fetch_assoc($midcate_middleclass_query))
								  	{
								  		echo "<option ";
								  		if($midcate_myrows['ID']==$midcate_middleclass_rows['ID']||$_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($_POST['SmallClassName']==""&&$subcate_myrows['ID']==""||$_POST['SmallClassName']==""&&$subcate_myrows['subcateName']=="")
										{
									  		$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=''";
										}
										else
										{
											if($subcate_myrows['ID']!="")
											{
												echo $subcate_myrows['ID'];
												$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=".$midcate_myrows['ID']."";
											}
											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);

									  	while($subcate_smallclass_rows=mysql_fetch_assoc($subcate_smallclass_query))
									  	{
									  		echo "<option ";
									  		if($_POST['SmallClassName']==$subcate_smallclass_rows['ID']||$subcate_myrows['ID']==$subcate_smallclass_rows['ID'])
									  		{
												echo "selected";
											}
									  		echo " value=".$subcate_smallclass_rows['ID'].">".$subcate_smallclass_rows['subcateName']."</option>";
										}
									
								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 htmlspecialchars_decode($products_rows['productItemNo'],ENT_QUOTES);?>" 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 htmlspecialchars_decode($products_rows['productName'],ENT_QUOTES);?>" size="36">
					    <label  style="padding-left:1em;">
					      <input type="button" name="button" id="button" value="SEO"  onclick="
document.myform.productTitle.value=this.form.productName.value;document.myform.productKeywords.value=this.form.productName.value+', <?=$seoFrefix1?> '+this.form.productName.value+' <?=$seoSufix1?>, <?=$seoFrefix2?> '+this.form.productName.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?> suppliers'+', '+document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].text+' <?=$seoFrefix2?> <?=$seoSufix2?>';"  />
					    </label></td>
						<td width="56%" style="padding-left:3em;"><? 
						if(intval($products_rows['AdditionalAttributes'])&1){
							 echo "<input id=\"showonhome\" name=\"showonhome\" type=\"checkbox\" value=\"0\" checked /><label for=\"showonhome\" style=\"margin-right:10px;\">首页显示</label>首页显示位置<input type=\"text\" size=\"6\" name=\"No\" value=\"{$products_rows[No]}\" />";
						}else{
							 echo "<input id=\"showonhome\" name=\"showonhome\" type=\"checkbox\" value=\"0\" /><label for=\"showonhome\" style=\"margin-right:10px;\">首页显示</label>首页显示位置<input type=\"text\" size=\"6\" name=\"No\" value=\"{$products_rows[No]}\" />";
						}
						if(intval($products_rows['AdditionalAttributes'])&2)
						{
							 echo "<input id=\"hotproduct\" name=\"hotproduct\" type=\"checkbox\" value=\"1\" checked /><label for=\"hotproduct\" style=\"margin-right:10px;\">热点产品</label>";
						}
						else
						{
							 echo "<input id=\"hotproduct\" name=\"hotproduct\" type=\"checkbox\" value=\"1\" /><label for=\"hotproduct\" style=\"margin-right:10px;\">热点产品</label>";
						}
						if(intval($products_rows['AdditionalAttributes'])&4)
						{
							 echo "<input id=\"newproduct\" name=\"newproduct\" type=\"checkbox\" value=\"2\" checked /><label for=\"newproduct\" style=\"margin-right:10px;\">新产品</label>";
						}
						else
						{
							 echo "<input id=\"newproduct\" name=\"newproduct\" type=\"checkbox\" value=\"2\" /><label for=\"newproduct\" style=\"margin-right:10px;\">新产品</label>";
						}
						?></td>
					</tr>
					<tr bgcolor="#f4f4f4">
						<td rowspan="2" style="padding-left:12px;" >产品图片：</td>
						<td style="padding-left:3em;" >
						
						<? if($picsrcnopath=="")
						{?>
							<img src="<?php echo $picsrc;?>" width="<?php echo $SmallPicW ?>" height="<?php echo $SmallPicH?>" border="1" name="pic" style="float:left;">
							<? }else{  // 动画 gif
							if($products_rows['automationGif']==1){
							?>
							<img src="<?php echo $picsrc;?>"  width="<?php echo $SmallPicW ?>" height="<?php echo $SmallPicH?>" border="1" name="pic" id="showproductpic" style="float:left;">
							<? }
							else  //不是 动画 gif
							{?>
							<img src="<?php echo $picsrc;?>"   name="pic" id="showproductpic" width="<?php echo $SmallPicW ?>" height="<?php echo $SmallPicH?>" border="1" style="float:left;">
							<? } }?>
							<br>
							<br>
							<br>
							<br></td>
						<td style="padding-left:3em;" ><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 $products_rows['productTitle'];?>" size="70" /></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4" >本页关键字 Keywords</td>
						    <td><input name="productKeywords" id="productKeywords" type="text" value="<?php echo $products_rows['productKeywords'];?>" size="70" /></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4"  >本页描述 Description</td>
						    <td><textarea name="productDescription" cols="72" rows="3" id="productDescription"><?php echo $products_rows['productDescription'];?></textarea></td>
					      </tr>
					    </table></td>
					</tr>
					<tr bgcolor="#f4f4f4">
					  <td colspan="2" style="padding-left:3em;" >
			            <input type="file" name="productPic" style="width:300px;"  onchange="myform.ChangecatePagePic.value='yes';document.pic.src=myform.productPic.value;" />
				        
					    <input id="automationGif" name="automationGif" type="checkbox" value="1"  <?=($products_rows['automationGif']==1)?'checked':''?>/>
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:12px;"><div align="right">
					    <input name="submit2" type="submit" value="修改产品" />
					    </div></td>
				  </tr>
					<tr bgcolor="#f4f4f4">
						<td style="padding-left:15px;">产品属性：</td>
						<td colspan="2" style="padding-left:3em;">
							<p style="color:red">
								<? $encode_canshu=htmlspecialchars_decode($products_rows['canshu'],ENT_QUOTES); ?>
                              <textarea name="canshu" id="canshu" style="width:450px;height:150px;font-size:12px;line-height:20px; color:  <?=($encode_canshu!=""?"#000":"#BBB")?>" onfocus="<?=($encode_canshu!=""?"":"this.value='';")?>"><?=($encode_canshu!=""?$encode_canshu:"额定电压    220VAC/380VAC
频率    50HZ&plusmn;10%")?>
						    </textarea>
                              <span style="color:red"><span style="color:red;"><span style="padding-left:12px;">&nbsp; &nbsp; &nbsp;注：属性名与属性</span>值用 空格 分割 ，每个属性对占一行。
				          </span></span> </p></td>
					</tr>
					<tr bgcolor="#f4f4f4">
						<td colspan="3" style="padding-left:12px;">&nbsp;</td>
					</tr>
					<tr bgcolor="#f4f4f4">
						<td style="padding-left:15px;" width="10%">产品说明</span>：</td>
						<td colspan="2" ><textarea name="productSpecification" style="width:800px;height:350px;visibility:hidden;"><?php echo htmlspecialchars_decode($products_rows['productSpecification'],ENT_QUOTES); ?></textarea></td>
					</tr>
					<tr bgcolor="#f4f4f4">
					  <td style="padding-left:15px;">&nbsp;</td>
					  <td colspan="2" align="center" ><div align="middle">
					    <input name="submit" type="submit" value="修改产品" />
				        <label>
				          <input type="reset" name="button2" id="button2" value="重置" />
			            </label>
					  </div></td>
				  </tr>
					<tr bgcolor="#B9DAFF">
						<td height="25" colspan="3" align="center">&nbsp;</td>
					</tr>
				</table>
			</form></td>
	</tr>
</table>
<?  if($_SESSION["refreshModi"]){?>
<script> document.execCommand('Refresh') ;</script>
<? 
$_SESSION["refreshModi"]=false;
}?>
</body>
</html>