<?php
    session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/admin.class.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	date_default_timezone_set('Asia/Shanghai');
?>
<!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">
<title>无标题文档</title>
</head>
<body>
<?php
	
	$admininfo = $admin->getinfo();
	$branchID = $admininfo['branchID'];
	$ls=$_POST['ls'];
	$id=$_POST['id'];
	$ChangecatePagePic=$_POST['ChangecatePagePic'];
	$BigClassName=$_POST['BigClassName'];  // 从addproducts.php 和 modiproducts.php 产品分类下拉列表select获得，实际是BigClassID
	$MiddleClassName=$_POST['MiddleClassName'];
	$SmallClassName=$_POST['SmallClassName'];
	
	$specificationValue=$_POST['specificationValue'];
	$specificationName=$_POST['specificationName'];
	//echo $specificationName[0].$specificationName[1].$specificationName[2];
 	$specificationValueInit=explode(',',$specValue);
	for($i=0;$i<(count($specificationValueInit));$i++)  //循环处理变量处理 变量名
	{	
		if($specificationValueInit[$i]==$specificationValue[$i]) 
		$specificationValue[$i]="";  //默认空值则清空
	}
	$cateid=$_POST['cateid'];
	if(isset($_POST['BigClassName']))$cateid=$_POST['BigClassName'];  //$_POST['BigClassName'] 传了ID
	$midcateid=$_POST['midcateid'];
	if(isset($_POST['MiddleClassName']))$midcateid=$_POST['MiddleClassName'];  //$_POST['MiddleClassName'] 传了ID
	$subcateid=$_POST['subcateid'];
	if(isset($_POST['SmallClassName']))$subcateid=$_POST['SmallClassName'];  //$_POST['SmallClassName'] 传了ID
	$page=$_GET['page'];

	$additionalAttributes=0;
	if(isset($_POST['showonhome'])){
		$additionalAttributes+=1<<intval($_POST['showonhome']);
	}
	if(isset($_POST['hotproduct'])){
		$additionalAttributes+=1<<intval($_POST['hotproduct']);
	}
	if(isset($_POST['newproduct'])){
		$additionalAttributes+=1<<intval($_POST['newproduct']);
	}
	if(isset($_POST['classproduct'])){
		$classproduct =1<<intval($_POST['classproduct']);
		if($classproduct==2){
			$_POST['classproduct']?$classproduct=$_POST['classproduct']:$classproduct=0;
		}
	}
	//echo $_POST['hotproduct']."--".$_POST['newproduct']."--".$additionalAttributes;
	$pic=$_POST['Pic'];
	$No=$_POST['No'];

	$NoClassPro = trim($_POST['NoClassPro']);
	
	$_POST['automationGif']?$automationGif=$_POST['automationGif']:$automationGif=0;

	
	if($SmallClassName=="")
	{
		if($MiddleClassName=="")
		{		
			$productID=$BigClassName;
			$select_BigClassName_sql="select * from ls_products where ID=".$productID." ";
			$select_BigClassName_query=$opendb->query($select_BigClassName_sql);
			$select_BigClassName_rows=mysql_fetch_assoc($select_BigClassName_query);
			$pathFoldersProducts="../".$select_BigClassName_rows['cateFolders'];
			$procateName = $select_BigClassName_rows['cateFolders'];
			$productPID=$select_BigClassName_rows['ID'];// 为产生顺序号Num采集变量
		}
		else
		{
			$productID=$BigClassName;
			$select_BigClassName_sql="select * from ls_products where ID=".$productID." ";
			$select_BigClassName_query=$opendb->query($select_BigClassName_sql);
			$select_BigClassName_rows=mysql_fetch_assoc($select_BigClassName_query);
						
			$productID=$MiddleClassName;
			$select_MiddleClassName_sql="select * from ls_products where ID=".$productID." ";
			$select_MiddleClassName_query=$opendb->query($select_MiddleClassName_sql);
			$select_MiddleClassName_rows=mysql_fetch_assoc($select_MiddleClassName_query);
			$pathFoldersProducts="../".$select_BigClassName_rows['cateFolders']."/".$select_MiddleClassName_rows['midcateFolders'];
			$procateName = $select_MiddleClassName_rows['midcateFolders'];
			$productPID=$select_MiddleClassName_rows['ID'];

		}
    }
	else
	{
		$productID=$BigClassName;
		$select_BigClassName_sql="select * from ls_products where ID=".$productID." ";
		$select_BigClassName_query=$opendb->query($select_BigClassName_sql);
		$select_BigClassName_rows=mysql_fetch_assoc($select_BigClassName_query);
						
		$productID=$MiddleClassName;
		$select_MiddleClassName_sql="select * from ls_products where ID=".$productID." ";
		$select_MiddleClassName_query=$opendb->query($select_MiddleClassName_sql);
		$select_MiddleClassName_rows=mysql_fetch_assoc($select_MiddleClassName_query);
		
		$productID=$SmallClassName;	
		$select_SmallClassName_sql="select * from ls_products where ID=".$productID." ";
		$select_SmallClassName_query=$opendb->query($select_SmallClassName_sql);
		$select_SmallClassName_rows=mysql_fetch_assoc($select_SmallClassName_query);
		
		$pathFoldersProducts="../".$select_BigClassName_rows['cateFolders']."/".$select_MiddleClassName_rows['midcateFolders']."/".$select_SmallClassName_rows['subcateFolders'];
		$procateName = $select_SmallClassName_rows['subcateFolders'];
		$productPID=$select_SmallClassName_rows['ID'];

	}
	
	
	//-------添加新产品   排序代码段
	$place = $_POST['place'];
	$sql = "select * from ls_products where productID=".$productID." order by Num asc";
	$rs = $opendb->query($sql);
	if($place=='first'){
		$num = $i = 1;
		while($row = mysql_fetch_assoc($rs)){
				$sql = "update ls_products set Num=".++$i." where ID=".$row['ID'];
				$opendb->query($sql);
				if($_SESSION['place']!='first'){
					writeconstant('proplace','first','str',$oprconstant="modify",$insertflag="//----insert proNum",$filename="../ls_admin/inc/constant.php");
					$_SESSION['place']='first';
				}
				
		}	
	}else{
		$num = mysql_num_rows($rs)+1;
		$i = 1;
		while($row = mysql_fetch_assoc($rs)){
				$sql = "update ls_products set Num=".$i++." where ID=".$row['ID'];
				$opendb->query($sql);
				if($_SESSION['place']!='last'){
					writeconstant('proplace','last','str',$oprconstant="modify",$insertflag="//----insert proNum",$filename="../ls_admin/inc/constant.php");
					$_SESSION['place']='last';
				}
				
		}	
	}
	
	//-------
	 
	$productItemNo=htmlspecialchars($_POST['productItemNo'], ENT_QUOTES);
	$productName=htmlspecialchars($_POST['productName'], ENT_QUOTES);
	$productSpecification=$_POST['productSpecification'];
	
	//编辑器中的内链与图片转换成相对路径
	$productSpecification = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $productSpecification);//内链
	$productSpecification = editorPath($_SERVER['PHP_SELF'], $productSpecification);//图片
	$productSpecification = addAltTitle($productName, $productName, $productSpecification); //图片添加alt,title

	$characteristics=$_POST['characteristics'];
	
	//编辑器中的内链与图片转换成相对路径
	$characteristics = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $characteristics);//内链
	$characteristics = editorPath($_SERVER['PHP_SELF'], $characteristics);//图片
	$characteristics = addAltTitle($productName, $productName, $characteristics);  //图片添加alt,title
	
	$advantages=$_POST['advantages'];
	
	//编辑器中的内链与图片转换成相对路径
	$advantages = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $advantages);//内链
	$advantages = editorPath($_SERVER['PHP_SELF'], $advantages);//图片
	$advantages = addAltTitle($productName, $productName, $advantages);  //图片添加alt,title
	
	$parameters=$_POST['parameters'];
	
	//编辑器中的内链与图片转换成相对路径
	$parameters = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $parameters);//内链
	$parameters = editorPath($_SERVER['PHP_SELF'], $parameters);//图片
	$parameters = addAltTitle($productName, $productName, $parameters);  //图片添加alt,title

	$in_sql="SELECT * FROM ls_internal where enable=1 order by Num asc"; //count the error by searchtype
	$in_query=$opendb->query($in_sql);
	while ($in_rows=mysql_fetch_assoc($in_query)){
		$productSpecification = internal_keyword_link($productSpecification, $in_rows['title'], $in_rows['url']);
		$characteristics = internal_keyword_link($characteristics, $in_rows['title'], $in_rows['url']);
		$advantages = internal_keyword_link($advantages, $in_rows['title'], $in_rows['url']);
		$parameters = internal_keyword_link($parameters, $in_rows['title'], $in_rows['url']);
	}
	
	$canshu = htmlspecialchars(trim($_POST['canshu']), ENT_QUOTES);
	$basicInfo = htmlspecialchars($_POST['basicInfo'], ENT_QUOTES);
	$additionalInfo = htmlspecialchars($_POST['additionalInfo'], ENT_QUOTES);
	
	$productTitle=$_POST['productTitle'];
	$productDescription = substr(strip_tags(trim(preg_replace("/([\s]{2,})/"," ",$_POST['productSpecification']))), 0, 200);
	$productKeywords=$_POST['productKeywords'];
	$productPicName=$_POST['productPicName'];
	$productPicName_old=$_POST['productPicName_old'];

	$_POST['branchID'] == ''? $branchID = 0 : $branchID = $_POST['branchID'];
	$image=$_FILES['productPic']['name'];   
  	$size=$_FILES['productPic']['size'];   
  	$type=$_FILES['productPic']['type'];
	switch ($ls)
	{
		case "insert":
		
			if ($type == "image/gif" || $type == "image/png" || $type == "image/x-png" || $type == "image/pjpeg" || $type == "image/jpeg" ){
				 if($size < $PicSize){
					 	//开始判断图像大小
						$pathBigPic=$pathFoldersProducts."/".$BigFoldersProducts;
						//echo $pathBigPic."<br>";
						//创建大图文件夹
						createFolder($pathBigPic);
						$pathSmallPic=$pathFoldersProducts."/".$SmallFoldersProducts;
						//echo $pathSmallPic."<br>";
						//创建小图文件夹
						createFolder($pathSmallPic);
						$pathPagePic=$pathFoldersProducts;
						//echo $pathSmallPic."<br>";
						//创建大图浏览（.htm）文件夹
						createFolder($pathPagePic);
															
						$arr=array(" ",".");   
						
						//找出产品表中最大的ID，加1 
						$maxsql = "select * from ls_products as a where ID = (select max(ID) from ls_products as b)";
						$max_query = $opendb->query($maxsql);
						$maxrow = mysql_fetch_assoc($max_query);
						$pid = $maxrow['ID']+1;
						
						$pro_name = $procateName.$pid;
						
						//产生文件名   
						$productPic=str_replace($arr ,"",$pro_name).".".get_extension($image);
													  	
						$pathBigPic=$pathBigPic."/".$productPic;
						//echo  $pathBigPic."--".$_FILES['productPic']['tmp_name'];
						move_uploaded_file($_FILES['productPic']['tmp_name'], $pathBigPic);
						chmod($pathBigPic, 0644);
						$toW=$BigPicW;			//宽度
						$toH=$BigPicH;			//高度
						$toFile=$pathBigPic;	//目标地址
						$srcFile=$pathBigPic;	//目标地址
						
						if(!$_POST['automationGif'])  //是动画则不缩小
						{
							ImageResize($srcFile,$toW,$toH,$toFile);	//resize the big pic width & height to stand size
						}
						chmod($toFile,0644);

						$srcFile=$pathBigPic; //源地址
						$toW=$SmallPicW;			//宽度
						$toH=$SmallPicH;			//高度
						$toFile=$pathSmallPic."/".$productPic; //目标地址
						if(!$_POST['automationGif']) //是动画则不缩小
						{
							ImageResize($srcFile,$toW,$toH,$toFile);
						}
						else
						{
							copy($pathBigPic,$toFile);
						}
						chmod($toFile,0644);
						$select_sql2="select * from ls_products where productID=".$productPID." ";
						$select_query2=$opendb->query($select_sql2);
						$select_rows2=mysql_num_rows($select_query2); //总产品数
						$insert_sql=sprintf("insert into ls_products 															(productPic,productItemNo,productName,productSpecification,productID,Num,No,AdditionalAttributes,AdditionalAttributesClassPro,NoClassPro,canshu,basicInfo,additionalInfo,enable,automationGif,productTitle,productKeywords,productDescription,characteristics,advantages,parameters,isbranch,branchID,date) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ",
						GetSQLValueString($productPic, "text"),
						GetSQLValueString($productItemNo, "text"),
						GetSQLValueString($productName, "text"),
						GetSQLValueString($productSpecification, "text"),
						GetSQLValueString($productID, "int"),
						GetSQLValueString($num, "int"),
						GetSQLValueString($No, "int"),
						GetSQLValueString($additionalAttributes, "int"),
						GetSQLValueString($classproduct, "int"),
						GetSQLValueString($NoClassPro, "int"),
						GetSQLValueString($canshu, "text"),
						GetSQLValueString($basicInfo, "text"),
						GetSQLValueString($additionalInfo, "text"),
						GetSQLValueString("1", "int"),
						GetSQLValueString($automationGif, "int"),
						GetSQLValueString($productTitle, "text"),
						GetSQLValueString($productKeywords, "text"),
						GetSQLValueString($productDescription, "text"),
						GetSQLValueString($characteristics, "text"),
						GetSQLValueString($advantages, "text"),
						GetSQLValueString($parameters, "text"),
						GetSQLValueString($isbranch, "int"),
						GetSQLValueString($branchID, "int"),
						GetSQLValueString(date("Y-m-d H:i:s"), "text")
						);
						//echo $insert_sql;
						//添加数据
						
						$insert_query=$opendb->query($insert_sql);
						writelog($_SERVER['PHP_SELF'],"add product: ".$productName,"ID: ".$opendb->insert_id,"admin");
						
						//增加代码参数 ls_prospec
						$select_sql2="select * from ls_prospec  ";
						$select_query2=$opendb->query($select_sql2);
						$select_rows2=mysql_num_rows($select_query2); //总产品数
						$product_insert_id=$opendb->insert_id();
						//echo $specificationName."ll";
						for($i=0;$i<(count($specificationName));$i++)  //循环处理代码参数变量名和值，代码参数去掉: 
						{	
							$select_rows2++;
							$sql_spec="INSERT INTO `ls_prospec` (`productID`, `specName`, `specValue`, `Num`, `enable`) 
                 VALUES ('$product_insert_id', '".str_replace(':','',$specificationName[$i])."', '$specificationValue[$i]','$select_rows2', '1');";

							$insert_query=$opendb->query($sql_spec);
							
						}

						echo "
						<form name=\"fm\" method=\"post\" action=\"addproducts.php?cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page." \">
						<input type=\"hidden\" value=\"".$BigClassName."\" name=\"BigClassName\">
						<input type=\"hidden\" value=\"".$SmallClassName."\" name=\"SmallClassName\">
						<input type=\"hidden\" value=\"".$MiddleClassName."\" name=\"MiddleClassName\">
						<input type=\"hidden\" value=\"".$productItemNo."\" name=\"productItemNo\">
						<input type=\"hidden\" value=\"".$productName."\" name=\"productName\">
						<input type=\"hidden\" value=\"".$canshu."\" name=\"canshu\">
						
						<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 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>
						";
						if($select_BigClassName_rows['cateName']!="")
						{
						echo " 大类：".$select_BigClassName_rows['cateName'];
						}
						if($select_MiddleClassName_rows['midcateName']!="")
						{
						echo "  中类：".$select_MiddleClassName_rows['midcateName'];
						}
						if($select_SmallClassName_rows['subcateName']!="")
						{
						echo "  小类：".$select_SmallClassName_rows['subcateName'];
						}
						echo "</td>
						</tr>
						<tr bgcolor=\"#f4f4f4\"> 
						<td style=\"padding-left:50px;\" width=\"30%\">产品编号：</td>
						<td>
						".$productItemNo."
						</td>
						</tr>
						<tr bgcolor=\"#f4f4f4\"> 
						<td style=\"padding-left:50px;\" width=\"30%\">产品名称：</td>
						<td>
						".$productName."
						</td>
						</tr>
						<tr bgcolor=\"#f4f4f4\"> 
						<td style=\"padding-left:50px;\" width=\"30%\">产品其他参数：</td>
						<td>
						".str_replace("\n",'<br />',$canshu)."
						</td>
						</tr>
						<tr bgcolor=\"#f4f4f4\"> 
						<td style=\"padding-left:50px;\" >*缩略图：</td>
						<td style=\"padding-left:5px;\" >
						<img src=\" ".$toFile." \" width=\"".$toW."\" height=\"".$toH."\" border=\"1\" >
						</td>
						</tr>
						<tr bgcolor=\"#f4f4f4\"> 
						<td style=\"padding-left:50px;\" width=\"30%\">产品规格：</td>
						<td>
						".htmlspecialchars_decode($productSpecification,ENT_QUOTES)."
						</td>
						 </tr>
						<tr bgcolor=\"#B9DAFF\"> 
						<td height=\"28\" colspan=\"2\" align=\"center\">
						<input type=\"submit\" value=\"继续添加\">
						
						<input type=\"button\" value=\"返回列表\" onclick=\"javascript:location='products.php?cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page."';\">
						</td>
						 </tr>
						</table>
						</td>
						</tr>
						</table>
						</form>
						";
										
					}						
						else
						{
							echo "	<script>alert('图像最大为".$PicSize."！');history.go(-1);</script>";
						}
				
			 }
			else
				{
					 echo "	<script>alert('请选择图片上传，或者你选择的文件不符合要求!\\n只允许格式 .gif .png .jpeg');history.go(-1);</script>";
				}
		break;
		
	case "update":
		
		if($ChangecatePagePic=="yes")
	  	{
	  	//判断图像格式
	  		if ($type == "image/gif" || $type == "image/png" || $type == "image/x-png" || $type == "image/pjpeg" || $type == "image/jpeg" )
				{
					if($size < $PicSize) //开始判断图像大小
						{
							$pathBigPic=$pathFoldersProducts."/".$BigFoldersProducts;
							//echo $pathBigPic."<br>";
							$pathSmallPic=$pathFoldersProducts."/".$SmallFoldersProducts;
							
							$oldbigpic=$pathBigPic."/".$pic;
							unlink($oldbigpic);		//delete old big pic
							
							$oldsmallpic=$pathSmallPic."/".$pic;
							unlink($oldsmallpic);	//delete old small pic

															
							$arr=array(" ",".");   
							//产生文件名   
							$pic=substr($pic,0,(strlen($pic)-4));
							//echo $pic;
							$productPic=$pic.".".substr($image,-3);
												  														  	
							$pathBigPic=$pathBigPic."/".$productPic;
							//echo $pathBigPic;
							//上传文件
							move_uploaded_file($_FILES['productPic']['tmp_name'], $pathBigPic);
							$toW=$BigPicW;			//宽度
							$toH=$BigPicH;			//高度
							$toFile=$pathBigPic;		//目标地址
							$srcFile=$pathBigPic;	//目标地址
							if(!$_POST['automationGif'])  //是动画则不缩小
							{
								ImageResize($srcFile,$toW,$toH,$toFile);	//resize the big pic width & height to stand size
							}

							chmod($toFile,0644);
							//判断是否有图片的备份文件，如果有同时也更新图片的备份文件
							if(file_exists($pathBigPic)){
								copy($pathBigPic,$pathBigPic.".bak");
							}
													  	
							$srcFile=$pathBigPic; //源地址
							$toW=$SmallPicW;			//宽度
							$toH=$SmallPicH;			//高度
							$toFile=$pathSmallPic."/".$productPic; //目标地址
													  	//生成缩略图
							if(!$_POST['automationGif']) //是动画则不缩小
							{
								ImageResize($srcFile,$toW,$toH,$toFile);
							}
							else
							{
								copy( $pathBigPic,$toFile);
							}

							chmod($toFile,0644);
							if(file_exists($toFile)){
								copy($toFile,$toFile.".bak");
							}
				        }
						else
						{
							echo "	<script>alert('图像最大为".$PicSize."！');history.go(-1);</script>";
						}
					}
					else
					{
						echo "	<script>alert('请选择图片上传，或者你选择的文件不符合要求!\\n只允许格式 .gif .png .jpeg');history.go(-1);</script>";
					}
					
					$update_pic_sql=sprintf("update ls_products set productPic=%s where ID=%s",
					GetSQLValueString($productPic, "text"),
					GetSQLValueString($id, "int")
					);
				//更新产品图片
					$update_query=$opendb->query($update_pic_sql);
				} 
	  			   
				$sql = "select * from ls_products where ID='$id'";
				$idlist = $opendb->oneRow($sql);
				
				if($_POST['branchID']==""){
					$branchID = $idlist['branchID'];
				}else{
					$branchID = $_POST['branchID'];	
				}
				
				if($productPicName_old != $productPicName){
					
					if(!file_exists($pathFoldersProducts."/".$BigFoldersProducts."/".$productPicName)){
						$update_pic_sql2=sprintf("update ls_products set productPic=%s where ID=%s",
							GetSQLValueString($productPicName, "text"),
							GetSQLValueString($id, "int")
						);
						//echo $update_sql;
						//更新数据
						if($update_query=$opendb->query($update_pic_sql2)){
							rename($pathFoldersProducts."/".$BigFoldersProducts."/".$productPicName_old, $pathFoldersProducts."/".$BigFoldersProducts."/".$productPicName);
							rename($pathFoldersProducts."/".$SmallFoldersProducts."/".$productPicName_old, $pathFoldersProducts."/".$SmallFoldersProducts."/".$productPicName);
							echo "<script>alert('数据更新成功!\\n');location='modiproducts.php?id=".$id."&cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page."';</script>";
						}
					}else{
						echo "<script>
						alert('文件名重复，请换个名称再试试。".$code."');
						location='modiproducts.php?id=".$id."&cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page."';
						</script>";
					}

				}else{
					$update_sql=sprintf("update ls_products set productItemNo=%s, productName=%s, productSpecification=%s, AdditionalAttributes=%s, AdditionalAttributesClassPro=%s,NoClassPro=%s,No=%s, canshu=%s, basicInfo=%s, additionalInfo=%s, waterMark=%s ,automationGif=%s, productTitle=%s, productKeywords=%s, productDescription=%s, characteristics=%s, advantages=%s, parameters=%s,isbranch=%s,branchID=%s,date=%s where ID=%s",
					GetSQLValueString($productItemNo, "text"),
					GetSQLValueString($productName, "text"),
					GetSQLValueString($productSpecification, "text"),
					GetSQLValueString($additionalAttributes, "int"),
					GetSQLValueString($classproduct, "int"),
					GetSQLValueString($NoClassPro, "int"),
					GetSQLValueString($No, "int"),
					GetSQLValueString($canshu, "text"),
					GetSQLValueString($basicInfo, "text"),
					GetSQLValueString($additionalInfo, "text"),
					GetSQLValueString(0, "int"),
					GetSQLValueString($automationGif, "int"),
					GetSQLValueString($productTitle, "text"),
					GetSQLValueString($productKeywords, "text"),
					GetSQLValueString($productDescription, "text"),
					GetSQLValueString($characteristics, "text"),
					GetSQLValueString($advantages, "text"),
					GetSQLValueString($parameters, "text"),
					GetSQLValueString($isbranch, "int"),
					GetSQLValueString($branchID, "int"),
					GetSQLValueString(date("Y-m-d H:i:s"), "text"),
					GetSQLValueString($id, "int")
					);
					if($update_query=$opendb->query($update_sql)){
						echo "<script>alert('数据更新成功!\\n');location='modiproducts.php?id=".$id."&cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page."';</script>";
					}
				}

				//更新代码参数
					$select_sql2="select * from ls_prospec  ";
					$select_query2=$opendb->query($select_sql2);
					$select_rowsall2=mysql_num_rows($select_query2); //总数

					for($i=0;$i<(count($specificationName));$i++)  //循环处理代码参数变量名和值，代码参数去掉: 
					{	
						$select_sql2="select * from ls_prospec where `specName`='".str_replace(':','',$specificationName[$i])."' and `productID`=$id";
						$select_query2=$opendb->query($select_sql2);
						$select_rows2=mysql_num_rows($select_query2); //总数
						if($select_rows2==0)  //原来有则替换，没有则增加
						{
							$select_rowsall2++;
							$sql_spec="INSERT INTO `ls_prospec` (`productID`, `specName`, `specValue`, `Num`, `enable`) 
                 VALUES ('$id', '".str_replace(':','',$specificationName[$i])."', '$specificationValue[$i]','$select_rowsall2', '1');";				}
						else
						{
							$sql_spec="update `ls_prospec` set `specValue`='$specificationValue[$i]' where productID=$id and `specName`='".str_replace(':','',$specificationName[$i])."';";
						}
						$insert_query=$opendb->query($sql_spec);
							
					}


				//更新类别
				$update_sql="";
				$products_sql="select * from ls_products where ID=".$id." ";
				$products_query=$opendb->query($products_sql);
				$products_rows=mysql_fetch_assoc($products_query);
				$oldfolder=getproductfolder($products_rows['productID']);
				if($BigClassName!=""&&$MiddleClassName==""&&$SmallClassName=="")
				{
					if($BigClassName!=$products_rows['productID']){ $update_sql="update ls_products set productID=".$BigClassName." where ID=".$id." ";
					$newfolder=getproductfolder($BigClassName);
					}
				}
				if($BigClassName!=""&&$MiddleClassName!=""&&$SmallClassName=="")
				{
					if($MiddleClassName!=$products_rows['productID']){ $update_sql="update ls_products set productID=".$MiddleClassName." where ID=".$id." ";
					$newfolder=getproductfolder($MiddleClassName);
					}
				}
				if($BigClassName!=""&&$MiddleClassName!=""&&$SmallClassName!="")
				{
					if($SmallClassName!=$products_rows['productID']){ $update_sql="update ls_products set productID=".$SmallClassName." where ID=".$id." ";
					$newfolder=getproductfolder($SmallClassName);
					}
				}
				
				if($update_sql!="")
				{
					$products_query=$opendb->query($update_sql);
					//echo $update_sql."update";
					if($products_query)//移动产品目录
					{
						if(!file_exists ("../".$newfolder."/".$SmallFoldersProducts)){mkdir ("../".$newfolder."/".$SmallFoldersProducts);}
						if(!file_exists ("../".$newfolder."/".$BigFoldersProducts)){mkdir ("../".$newfolder."/".$BigFoldersProducts);}
						if(!file_exists ("../".$newfolder)){mkdir ("../".$newfolder);}

						copy("../".$oldfolder."/".$SmallFoldersProducts."/".$products_rows['productPic'], "../".$newfolder."/".$SmallFoldersProducts."/".$products_rows['productPic']);
						copy("../".$oldfolder."/".$BigFoldersProducts."/".$products_rows['productPic'], "../".$newfolder."/".$BigFoldersProducts."/".$products_rows['productPic']);
						unlink ("../".$oldfolder."/".$SmallFoldersProducts."/".$products_rows['productPic']);
						unlink ("../".$oldfolder."/".$BigFoldersProducts."/".$products_rows['productPic']);

					}
				}
				writelog($_SERVER['PHP_SELF'],"change products: ".$productName,"ID: ".$id);

				$_SESSION["refreshModi"]=true;
				
		break;
	}
?>
</body>
</html>
