<?php
	require_once('_approot.php');	
	require_once('inc/admin.class.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">
<link rel="stylesheet" href="css/style2.css" />
<title>保存产品</title>
</head>
<body>
<?php
	
	 
	$_SESSION['savepost']=$_POST;
	$_SESSION['saveget']=$_GET;
	$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);
	$matealt=clearname($_POST['matealt']);
	$matetitle=clearname($_POST['matetitle']);
	//$matetitle=($_POST['matetitle']==""?$matealt:$_POST['matetitle']);
	
	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=mysqli_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=mysqli_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=mysqli_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=mysqli_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=mysqli_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=mysqli_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 = mysqli_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 = mysqli_num_rows($rs)+1;
		$i = 1;
		while($row = mysqli_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=clearname($_POST['productItemNo']);
	$productName=clearname($_POST['productName']);
	//$productName=htmlspecialchars(clearname($_POST['productName']), ENT_QUOTES);
	//$productSpecification=htmlspecialchars($_POST['productSpecification'], ENT_QUOTES);
	$productSpecification=editorprocess($_POST['productSpecification'],$_SERVER['PHP_SELF'],$matealt==""?$productName:$matealt,$matetitle==""?$productName:$matetitle); 

/*	$productSpecification = strreppattern($productSpecification ); //video
	//编辑器中的内链与图片转换成相对路径
	$productSpecification = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $productSpecification);//内链
	$productSpecification = editorPath($_SERVER['PHP_SELF'], $productSpecification);//图片
	$productSpecification = addAltTitle($productName, $productName, $productSpecification); //图片添加alt,title
	$productSpecification = editorsrcset($productSpecification); //图片分级处理
*/
	//编辑器中的内链与图片转换成相对路径
	$characteristics = strreppattern($_POST['characteristics'] ); //video
	$characteristics = editorprocess($characteristics,$_SERVER['PHP_SELF'],$matealt==""?$productName:$matealt,$matetitle==""?$productName:$matetitle); 
	
	$advantages	 = strreppattern($_POST['advantages'] ); //video
	//编辑器中的内链与图片转换成相对路径
	$advantages = editorprocess($advantages,$_SERVER['PHP_SELF'],$matealt==""?$productName:$matealt,$matetitle==""?$productName:$matetitle); 
	
	$parameters=  strreppattern($_POST['parameters'] ); //video
	$parameters = editorprocess($parameters,$_SERVER['PHP_SELF'],$matealt==""?$productName:$matealt,$matetitle==""?$productName:$matetitle); 

	$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=mysqli_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 = strreppattern(trim($_POST['canshu'])); // video 处理
	$canshu = editorprocess($canshu,$_SERVER['PHP_SELF'],$matealt==""?$productName:$matealt,$matetitle==""?$productName:$matetitle); 
	$basicInfo =  trim($_POST['basicInfo']);
	$basicInfo = editorprocess($basicInfo,$_SERVER['PHP_SELF'],$matealt==""?$productName:$matealt,$matetitle==""?$productName:$matetitle); 
	$additionalInfo = trim($_POST['additionalInfo']);
	$additionalInfo = editorprocess($additionalInfo,$_SERVER['PHP_SELF'],$matealt==""?$productName:$matealt,$matetitle==""?$productName:$matetitle); 
	 
	$productTitle=clearname($_POST['productTitle']);
	 
	$productDescription = clearname(substr(strip_tags(trim(preg_replace("/([\s]{2,})/"," ",$_POST['productDescription']))), 0, 200));
	$productKeywords=clearname($_POST['productKeywords']);
	$productPicName=$_POST['productPicName'];
	$productPicName_old=$_POST['productPicName_old'];

	$_POST['branchID'] == ''? $branchID = 0 : $branchID = $_POST['branchID']; //productVideo
	$image=$_FILES['productPic']['name'];   
  	$size=$_FILES['productPic']['size'];   
  	$type=$_FILES['productPic']['type'];
	
	
	$videoname=$_FILES['productVideo']['name'];   
  	$videosize=$_FILES['productVideo']['size']/1000000;   
  	$videotype=$_FILES['productVideo']['type'];
	// echo $_FILES['productVideo']['name']."--".$videotype."---" .$_FILES['productPic']['tmp_name'];exit;
	$pathBig=$pathFoldersProducts."/".$BigFoldersProducts;
	 
	switch ($ls)
	{
		case "insert":
			if (!(strpos($imagetypes,$type)===false) ){
				 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 = mysqli_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;	//目标地址
						$bigPicPath = $toFile;  //多图使用 _muti_pic_insert.php

						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; //目标地址
						$thumbPicPath = $toFile;  //多图使用 _muti_pic_insert.php
						
						if(!$_POST['automationGif']) //是动画则不缩小
						{
							ImageResize($srcFile,$toW,$toH,$toFile);
						}
						else
						{
							copy($pathBigPic,$toFile);
						}
						chmod($toFile,0644);
						
						
						if (!(strpos($videotypes,$videotype)===false) ){ //视频处理, constant
							 if($videosize < $videoSizeMax){
																		
									$arr=array(" ",".");   
									
									//产生文件名   
									$productVideo=str_replace($arr ,"",$pro_name).".".get_extension($videoname);
																	
									$pathBigVdo=$pathBig."/".$productVideo;
									//echo  $pathBigVdo."--".$_FILES['productPic']['tmp_name'];exit;
									move_uploaded_file($_FILES['productVideo']['tmp_name'], $pathBigVdo);
									chmod($pathBigVdo, 0644);
								}						
								else
								{
									echo "	<script>alert('主视频最大为".($videoSizeMax)." M！');history.go(-1);</script>";
								}
						
							}
							else
							{
								if($videoname!="")	 echo "	<script>alert('请选合适的视频上传，文件格式不符合要求!\\n允许格式 ".$videotypess." ');history.go(-1);</script>"  ;
						}//视频处理
						
						$select_sql2="select * from ls_products where productID=".$productPID." ";
						$select_query2=$opendb->query($select_sql2);
						$select_rows2=mysqli_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,	matealt,matetitle,productVideo,wholepath) 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,%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"),
						GetSQLValueString($matealt, "text"),
						GetSQLValueString($matetitle, "text"),
						GetSQLValueString($productVideo, "text"),
						GetSQLValueString($wholepath, "text")

						);
						//echo $insert_sql;
						//添加数据
						
						$insert_query=$opendb->query($insert_sql);
						$addid=$opendb->insert_id();
						writelog($_SERVER['PHP_SELF'],"add product: ".$productName,"ID: ".$addid,"admin");
						$updatefilename="update ls_products set filename='".pathProName($productName)."-".$addid.".html"."' where ID=".$addid." "; //记录文件名
						 
						$insert_query1=$opendb->query($updatefilename); //add filename
					
						if($ifmutipic) include("widget/_saveproducts_insert_muti.php"); //
						unset($_SESSION['savepost']);
						unset($_SESSION['saveget']);
						
						//增加代码参数 ls_prospec
						$select_sql2="select * from ls_prospec  ";
						$select_query2=$opendb->query($select_sql2);
						$select_rows2=mysqli_num_rows($select_query2); //总产品数
						$product_insert_id=$opendb->insert_id();
						//echo $specificationName."ll";
						for($i=0;$i<(count((array)$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=\"". $SmallPicW  ."\"   border=\"1\" >
						</td>
						</tr>";
						if($productVideo!=""){
							echo "<tr bgcolor=\"f4f4f4\"> 
							<td style=\"padding-left:50px;\" >视频：</td>
							<td style=\"padding-left:5px;\" >
							<video  width=\"". $SmallPicW  ."\"  id=\"vdo\" style=\"float:left;\" border=\"1\" poster=\"".$pathBigVdo."\" autoplay=\"\" preload=\"Metadata\" controls=\"controls\"><source src=\"images/picture.gif\" /></video>
							</td>
							</tr>";
						}
						echo "
						<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/1024)."K！');history.go(-1);</script>";
						}
				
			 }
			else
				{
					 echo "	<script>alert('请选择合适图片上传，你选择的文件不符合要求!\\n允许格式 ".$imagetypess."');history.go(-1);</script>";
				}
		break;
		
	case "update":
		$filename=trim($_POST['filename']);
		$wholepath=trim($_POST['wholepath']);
		$deletevideo=$_POST['deletevideo'];
		$products_sql="select * from ls_products where ID=".$id." ";
		$products_query=$opendb->query($products_sql);
		$products_rows=mysqli_fetch_assoc($products_query);
		$thisVdo=$products_rows['productVideo']==""?(substr($pic,0,(strlen($pic)-4)).".".get_extension($videoname)):$products_rows['productVideo'];
		$pathBigVdo=$pathBig."/".$thisVdo;
		
		
		if($deletevideo=="deletevideo"){
			//$products_sql."--".$pathBigVdo; 
			unlink($pathBigVdo);	//delete old small pic
			$update_vdo_sql="update `ls_products` set `productVideo`='' where ID=$id "; //clear productVideo
			$update_query=$opendb->query($update_vdo_sql);
			echo "<script>alert('视频已删除!\\n');location='modiproducts.php?id=".$id."&cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page."';</script>";
			
		}
		
		if($ChangecatePagePic=="yes")
	  	{
	  	//判断图像格式
	  		if (!(strpos($imagetypes,$type)===false) )
				{
					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,strpos($pic,"."));
							 
							$productPic=$pic.".".get_extension($image);
												  														  	
							$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/1024)."K！');history.go(-1);</script>";
						}
					}
					else
					{
						echo "	<script>alert('请选择合适的图片上传，选择的文件格式不符合要求!\\n允许格式".$imagetypess."');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);
				} 
		 
				if (!(strpos($videotypes,$videotype)===false) ){ //视频处理
				   if($videosize < $videoSizeMax){
															  

						  //echo  $pathBigVdo."--".$_FILES['productPic']['tmp_name']."==";exit;
						  move_uploaded_file($_FILES['productVideo']['tmp_name'], $pathBigVdo);
						  chmod($pathBigVdo, 0644);
						  
						  $update_pic_sql=sprintf("update ls_products set   productVideo=%s  where ID=%s",
		   
						  GetSQLValueString($thisVdo, "text"),
						  GetSQLValueString($id, "int"));
		   
						  $update_query=$opendb->query($update_pic_sql);

					  }						
					  else
					  {
						  echo "	<script>alert('主视频最大为".($videoSizeMax)." M！');history.go(-1);</script>";
					  }
			  
				  }
				  else
				  {
						 if($videoname!="")	  echo "	<script>alert('请选择合适的视频上传，选择的文件格式不符合要求!\\n允许格式 ".$videotypess." ');history.go(-1);</script>";
			  }//视频处理
				  
				$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,matealt=%s,matetitle=%s,wholepath=%s,filename=%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($matealt, "text"),
					GetSQLValueString($matetitle, "text"),
					GetSQLValueString($wholepath, "text"),
					GetSQLValueString($filename, "text"),
					GetSQLValueString($id, "int")
					);
					if($update_query=$opendb->query($update_sql)){
						echo "<script> location='products.php?id=".$id."&cateid=".$cateid."&midcateid=".$midcateid."&subcateid=".$subcateid."&page=".$page."&ls_msg=No.".$id."产品已更新';</script>";
					}
				}

				if($ifmutipic) include("widget/_saveproducts_modi_a_muti.php"); //

				//更新代码参数
					$select_sql2="select * from ls_prospec  ";
					$select_query2=$opendb->query($select_sql2);
					$select_rowsall2=mysqli_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=mysqli_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);
							
					}

				if($ifmutipic) include("widget/_saveproducts_modi_b_muti.php"); //

				//更新类别
				$update_sql="";
				$products_sql="select * from ls_products where ID=".$id." ";
				$products_query=$opendb->query($products_sql);
				$products_rows=mysqli_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);
				
				if($ifmutipic) include("widget/_saveproducts_update_insert_muti.php"); //
				unset($_SESSION['savepost']);
				unset($_SESSION['saveget']);


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