<?
	//	require('inc/constant.php');
	//	require_once('inc/ls_syscode.php');
			$j=0;
			if($getcate!="") {
				$pasefilename=$getcate;
				$title_sql = "select * from ls_products where cateName='".$pasefilename."'";
				
			}else 
			{
				$pasefilename=$val['catemidname'];
				$title_sql = "select * from ls_products where midcateName='".$pasefilename."'";
			
			}
			$opendb = new mydb();
			$title_query = $opendb->query($title_sql);
			$title_value = mysql_fetch_assoc($title_query);
			$productID = $title_value['ID'];

			foreach(glob($pasefilename.'/*') as $single)
			{
				$allsub=count($single);
				if(!is_dir($single)){
					$j++;
					if(strtolower(substr($single,-4))==".doc"||strtolower(substr($single,-5))==".docx"){
						if(strpos($single,"title")===false||strpos($single,"标题")===false){$text_path=getdoc($single);}
						else{$productTitle=getdoc($single);}
					}
				
					if(strtolower(substr($single,-4))==".txt"){
						if(strpos($single,"title")===false||strpos($single,"标题")===false){$text_path=gettxt($single);}
						else{$productTitle=gettxt($single);}
					}
					
					if(strtolower(substr($single,-4))==".jpg"||strtolower(substr($single,-4))==".png"||strtolower(substr($single,-4))==".gif"){
						$val[]=$single;
						
					}
				
			 }
 		}
		if( $val[0]!="" && $text_path!="" ){}
		else
		{if($j>=1){include_once("automidcate.php");}
		
		}  //是分类
		
					
					
					$catefolderspro = $title_value['cateFolders'];
					
					$productItemNo=htmlspecialchars($allcate.$numi, ENT_QUOTES);
					$productName=htmlspecialchars($allcate, ENT_QUOTES);
					$num = $numi;
					
					// 写入产品描述
				 
					$productSpecification=text($text_path,$allcate,$allcate.$numi,$allcate,$allcate,$allcate);
					
					/* 产品详细页内关键词加链接程序   开始 */
					$text_key = getSubstr1($productSpecification, "<tt>", "</tt>");
					$text_keywords = $text_key;
					$array_keywords = explode("; ", $text_keywords);
					$array_keys = array();
					foreach($array_keywords as $keywords){
						$array_keys[]['key_a'] = 0;
						$array_keys[]['keyword'] = $keywords;
					}
					$i = 0;
					$bool = false;
					foreach($array_keys as $key){
						$i++;
						if($i%2 == 0){
							$select_sql="select * from ls_products where cateName='".$key['keyword']."'";
							$select_query=$opendb->query($select_sql);
							$select_rows=mysql_num_rows($select_query);
							if($select_rows != 0){
								$select_value = mysql_fetch_assoc($select_query);
								$mid_sql="select * from ls_products where midcateID='".$select_value['ID']."'";
								$mid_query=$opendb->query($mid_sql);
								$mid_rows=mysql_num_rows($mid_query);
								if($mid_rows == 0){
									$text_keywords = str_replace($key['keyword'],"<a href='../../".$select_value['cateFolders']."/index.html'>".$key['keyword']."</a>",$text_keywords);
									$bool = true;
								}
							}
						}
						if($i%2 != 0){
							if($bool){
								$key['key_a'] = 1;
								$bool = false;
							}
						}
					}
					
					foreach($array_keys as $keys){
						if($keys['key_a'] == 0){
							$i++;
							if($i%2 == 0){
								$midcate_sql="select * from ls_products where midcateName='".$keys['keyword']."'";
								$midcate_query=$opendb->query($midcate_sql);
								$midcate_rows=mysql_num_rows($midcate_query);
								if($midcate_rows != 0){
									$midcate_value = mysql_fetch_assoc($midcate_query);
									$cate_sql="select * from ls_products where ID='".$midcate_value['midcateID']."'";
									$cate_query=$opendb->query($cate_sql);
									$cate_rows=mysql_fetch_assoc($cate_query);
									$text_keywords = str_replace($keys['keyword'],"<a href='../../../".$cate_rows['cateFolders']."/".$midcate_value['midcateFolders']."/index.html'>".$keys['keyword']."</a>",$text_keywords);
									$bool = true;
								}
							}
							if($i%2 != 0){
								if($bool){
									$keys['key_a'] = 1;
									$bool = false;
								}
							}
						}
					}
					$productSpecification = str_replace("<tt>".$text_key."</tt>", $text_keywords, $productSpecification);
					/* 产品详细页内关键词加链接程序   结束 */
					
					$characteristics=$_POST['characteristics'];
					$advantages=$_POST['advantages'];
					$parameters=$_POST['parameters'];
					
					$canshu = htmlspecialchars(trim($_POST['canshu']), ENT_QUOTES);
					//$productTitle=$allcate;
					$productDescription=$allcate;
					$productKeywords=$allcate;
					$_POST['branchID'] == ''? $branchID = 0 : $branchID = $_POST['branchID'];
					$image=basename($val[0]);
					$type=exif_imagetype($val);
					
					$ls = "insert";
					
					switch ($ls)
					{
						case "insert":
						
							if ($type == "1" || $type == "2" || $type == "3"){
								$pathBigPic="../".$catefolderspro."/".$BigFoldersProducts;
								//echo $pathBigPic."<br>";
								//创建大图文件夹
								createFolder($pathBigPic);
								$pathSmallPic="../".$catefolderspro."/".$SmallFoldersProducts;
								//echo $pathSmallPic."<br>";
								//创建小图文件夹
								createFolder($pathSmallPic);
								$pathPagePic="../".$catefolderspro."/".$showproductsFolders;
								//echo $pathSmallPic."<br>";
								//创建大图浏览（.htm）文件夹
								createFolder($pathPagePic);
																	
								$arr=array(" ",".");
								//产生文件名
								$productPic=str_replace($arr,"",time()+rand(100,1000)).".".substr($image,-3);
																
								$pathBigPic=$pathBigPic."/".$productPic;
								//echo  $pathBigPic."--".$_FILES['productPic']['tmp_name'];
								if(copyfiles($val, $pathBigPic)){
								//copy($val, $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=".$productID." ";
									$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,enable,automationGif,productTitle,productKeywords,productDescription,characteristics,advantages,parameters,isbranch,branchID) values (%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("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")
									);
									//echo $insert_sql;
									//添加数据
									
									echo "添加大类产品".$val."成功<br />";
									
									$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);
										
									}
								}

						 }
						else
						{
							 echo "请选择图片上传，或者你选择的文件不符合要求!只允许格式 .gif .png .jpeg<br />";
						}
						break;
					}
?>